0251 / 590 837 15
info@a-coding-project.de
;

Menüumzug ins neue Backend (CMS)

Derzeit ist das Erstellen, Bearbeiten und Löschen von Menüs nur im alten Backend möglich. Das wird sich heute ändern. Wir werden die komplette Funktionalotät übertragen.

Fangen wir an mit dem Erstellen des Menüs in der Klasse /system/classes/menucreatorpage.php:

<?PHP
  class MenuCreatorPage extends Editor{
    function __construct($page){
      $this->page = $page;
    }

    public function display(){
      $template = new Template();
      $template->load("menu_new");
      $template->show_if("NOTSUCCEEDED",!$_POST['name']);
      $template->assign_var("URL",Settings::getInstance()->get("host")."admin/newmenu.html");
      if($_POST['name']){
        $template->show_if("SUCCEEDED");
        $id = Menu::create($_POST['name'],$_SESSION['dir']);
        if($id){
          $template->assign_var("EDITURL",Settings::getInstance()->get("host")."admin/editmenu.html?menu=".$id);
        }
        else{
          $template->load("message");
          $template->assign_var("MESSAGE",$language->getString("MENU_NOT_CREATED"));
        }
      }
      $template->output();
    }
    function getHeader(){
    }

    public function getEditableCode(){
      return "<input name="save" type="submit" value="&Auml;ndern" onclick="form.action='".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."' ; target='_self' ; return true" />";
    }

    public function save($newPage,$oldPage){
    }
  }
?>

Weiter geht’s mit dem Bearbeiten der Einträge. Das geschieht im /system/classes/menueditor.php:

<?PHP
  class MenuEditor extends Editor{
    function __construct($page){
      $this->page = $page;
    }

    public function display(){
      $template = new Template();
      $template->load("menu_edit");
      if($_POST['add']){
        if(trim($_POST['newtitle']) != ""){
          if(trim($_POST['newurl']) != ""){
            $entry        = new MenuEntry();
            $entry->menu  = $_GET['menu'];
            $entry->title = $_POST['newtitle'];
            $entry->type  = $_POST['type'];
            if($entry->type == 0){
              $entry->href  = $_POST['newPage'];
            }
            else if($entry->type == 1){
              $entry->href  = $_POST['newurl'];
            }
            else{
              $entry->href  = $_POST['newMenu'];
            }
            $res = $entry->save();
            if($res){
              $template->assign_var("MESSAGE",$GLOBALS['language']->getString("ENTRY_ADDED"));
            }
            else{
              $template->assign_var("MESSAGE",$GLOBALS['language']->getString("ENTRY_NOT_ADDED"));
            }
          }
          else{
            $template->assign_var("MESSAGE",$GLOBALS['language']->getString("ENTER_LINK_TARGET"));
          }
        }
        else{
            $template->assign_var("MESSAGE",$GLOBALS['language']->getString("ENTER_LINK_TITLE"));
        }
      }
      else if($_POST['save']){
        foreach($_POST as $param=>$value){
          if(strlen($param) >= 6){
            if(substr($param,-5,5) == "_href"){
              $entries[substr($param,0,-5)][href] = $value;
            }
            else if(strlen($param) >= 7 && substr($param,-6,6) == "_title"){
              $entries[substr($param,0,-6)][title] = $value;
            }
            else if(substr($param,-5,5) == "_type"){
              $entries[substr($param,0,-5)][type] = $value;
            }
          }
        }
        foreach($entries as $id=>$params){
          $entry        = new MenuEntry();
          $entry->id    = $id;
          $entry->menu  = $_GET['menu'];
          $entry->title = $params['title'];
          $entry->href  = $params['href'];
          $entry->type  = $params['type'];
          $entry->save();
        }
      }
      else{
        foreach($_POST as $param=>$value){
          if(strlen($param) >= 8){
            if(substr($param,-7,7) == "_delete"){
              Menu::deleteEntry($GLOBALS['db']->EscapeString($_GET['menu']),
                                $GLOBALS['db']->EscapeString(substr($param,0,-7)));
            }
          }
        }
      }

      $template->assign_var("URL",Settings::getInstance()->get("host").$this->page->alias.".html?menu=".urlencode($_GET['menu']));
      $template->assign_var("EDITABLEMENU",Menu::getEditableCode($GLOBALS['db']->EscapeString($_GET['menu'])));

      $selector = new MenueSelector();
      $selector->name  = 'newMenu';
      $selector->value = -1;
      $selector->style = 'width:200px;position:relative;left:-210px;visibility:hidden';
      $template->assign_var("MENUSELECTOR", $selector->getCode());

      $selector = new PageSelector();
      $selector->name  = 'newPage';
      $selector->value = -1;
      $selector->style = 'width:200px;position:relative;left:-415px;';
      $template->assign_var("PAGESELECTOR", $selector->getCode());

      $template->assign_var("MESSAGE","");
      $template->output();
    }
    function getHeader(){
    }

    public function getEditableCode(){
      return "<input name="save" type="submit" value="&Auml;ndern" onclick="form.action='".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."' ; target='_self' ; return true" />";
    }

    public function save($newPage,$oldPage){
    }
}
?>

Der letzte Seitentyp ist die /system/classes/menudeletepage.php. Hier werden die Menüs gelöscht:

<?PHP
  class MenuDeletePage extends Editor{
    function __construct($page){
      $this->page = $page;
    }

    public function display(){
      $template = new Template();
      if(!$_GET['delete']){
        $template->load("menu_delete");
        $template->assign_var("CANCELURL","javascript:history.back()");
        $template->assign_var("DELETEURL",Settings::getInstance()->get("host").$this->page->alias.".html?menu=".urlencode($_GET['menu'])."&delete=true");
      }
      else{
        $template->load("message");
        if(Menu::delete($GLOBALS['db']->EscapeString($_GET['menu']))){
            $template->assign_var("MESSAGE",$GLOBALS['language']->getString("MENU_DELETED"));
        }
        else{
          $template->assign_var("MESSAGE",$GLOBALS['language']->getString("MENU_NOT_DELETED"));
        }
      }
      $template->output();
    }

    function getHeader(){
    }

    public function getEditableCode(){
      return "<input name="save" type="submit" value="&Auml;ndern" onclick="form.action='".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."' ; target='_self' ; return true" />";
    }

    public function save($newPage,$oldPage){
    }
}
?>

Das erstellen von Menüs im Backend war bisher nur ohne Ordner möglich. Das ändert die Funktion create der Klasse /system/classes/menu.php:

  function create($name,$dir = ""){
    $name = $GLOBALS['db']->EscapeString($name);
    $dir = $GLOBALS['db']->EscapeString($dir);
    $res = $GLOBALS['db']->Execute("INSERT INTO {'dbprefix'}menu_names (name, dir) VALUES ('".$name."', '".$dir."')");
    if($res){
      $args['name']  = $name;
      EventManager::raiseEvent("menu_created","../",$args);
    }
    return $GLOBALS['db']->InsertID();
  }

Um die Funktion nutzen zu können müssen folgende SQL-Queries ausgeführt werden:

INSERT INTO `cms_menu` VALUES (14, 8, 'Menü', '16', 0);
INSERT INTO `cms_pages` VALUES (16, 'admin/newmenu', 'Neues Menü', 7, 0, 'menucreatorpage');
INSERT INTO `cms_pages` VALUES (17, 'admin/editmenu', 'Menü Bearbeiten', 7, 0, 'menueditor');
INSERT INTO `cms_pages` VALUES (18, 'admin/deletemenu', 'Menü Löschen', 7, 0, 'menuedeletepage');
INSERT INTO `cms_role_rights` VALUES (2,16);
INSERT INTO `cms_role_rights` VALUES (2,17);
INSERT INTO `cms_role_rights` VALUES (2,18);

Alle Änderungen stehen in den Revisonen 51, 52, 53, 54, 55 und 56.