function add() { if (!$this->haveAccessTo('edit')) { return $this->showAccessDenied(); } $nParentID = Func::POSTGET('pid', false, true); $aData = array('title' => '', 'pid' => $nParentID, 'keyword' => '', 'keyword' => '', 'menu_link' => '', 'menu_target' => '', 'mkeywords' => '', 'mdescription' => ''); if (Func::isPostMethod()) { Func::setSESSION('pid', $nParentID); $sKeyword = Func::POST('keyword', true); $sMenuTarget = Func::POST('target'); if (!in_array($sMenuTarget, array('_self', '_blank'))) { $sMenuTarget = '_self'; } $sType = Func::POST('type'); switch ($sType) { case 'menu_type': $sMenuTitle = Func::POST('menu_title4', true); $sMetaKeywords = Func::POST('mkeywords4', true); $sMetaDescription = Func::POST('mdescription4', true); $sMenuLink = '#'; break; case 'page': $nPageID = Func::POST('page_id', false, true); $aPageInfo = $this->db->one_array('SELECT * FROM ' . TABLE_PAGES . ' WHERE id=' . $nPageID . ' LIMIT 1'); if (!$aPageInfo) { $this->adminRedirect(Errors::IMPOSSIBLE); } $sMenuTitle = Func::POST('menu_title3', true); if (!$sMenuTitle) { $sMenuTitle = $aPageInfo['title']; } $sMetaKeywords = $aPageInfo['mkeywords']; $sMetaDescription = $aPageInfo['mdescription']; $sMenuLink = $aPageInfo['filename'] . PAGES_EXTENSION; break; case 'link': default: $sMenuTitle = Func::POST('menu_title2', true); $sMenuLink = Func::POST('menu_link2', true); $sMetaDescription = Func::POST('mdescription2', true); $sMetaKeywords = Func::POST('mkeywords2', true); } $_POST['menu_title'] = $sMenuTitle; $_POST['menu_link'] = $sMenuLink; $_POST['mdescription'] = $sMetaDescription; $_POST['mkeywords'] = $sMetaKeywords; if (!$sMenuTitle || !trim($sMenuTitle)) { $this->errors->set('empty:title'); } if ($this->errors->no()) { $nNodeID = $this->tree_insertNode($nParentID); $this->addItem($nNodeID, $sMenuTitle, $sKeyword, $sMenuLink, $sMetaKeywords, $sMetaDescription, $sMenuTarget); $this->adminRedirect(Errors::SUCCESS); } $aData = $_POST; } if (!$nParentID) { $nParentID = Func::SESSION('pid'); } //parent options $sParentOptions = ''; $aItems = $this->db->select('SELECT I.menu_title, T.id, T.numlevel, I.keyword FROM ' . TABLE_SITEMAP_TREE . ' T, ' . TABLE_SITEMAP . ' I WHERE T.id=I.node_id AND T.numlevel<=2 ORDER BY T.numleft'); foreach ($aItems as $v) { if (!empty($v['keyword'])) { $sParentOptions .= '<option value="' . $v['id'] . '" style="padding-left:' . $v['numlevel'] * 18 . 'px;" ' . ($nParentID == $v['id'] ? ' selected' : '') . '>' . $v['menu_title'] . '</option>'; } } $this->tplAssign('aData', $aData); $this->tplAssign('pid_options', $sParentOptions); $this->tplAssign('target_options', $this->getTargetsOptions($this->aTargets, $aData['menu_target'])); $this->tplAssign('pages_options', func::MakeOptionsListEx($this->db->select('SELECT * FROM ' . TABLE_PAGES), Func::POSTGET('page_id', false, true), 'title', 'id')); return $this->tplFetch('admin.add.tpl'); }
function getTargetsOptions($aTargets, $sCurTarget = '_self') { return func::MakeOptionsListEx($aTargets, $sCurTarget, 'text', 'value'); }