Viewing file: module.php (6.22 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<? class LeftMenu { var $UserMode = false; var $AdminMode = true; var $SearchMode = false; var $PanelMode = true; var $AdminAsynchMode = true; var $Table; var $PagesTable; var $Directory; var $ClassName = 'LeftMenu'; var $Tree; var $StandardTree; function LeftMenu() { $this->Directory = dirname(__FILE__); $this->Table = new AMTable2('AMCMS_leftmenu'); $this->Table->AddIndexField('item_id'); $this->Table->Module($this->ClassName); $this->Table->AddPositionField("item_position"); $this->Table->SetParentField('item_parent_id'); $this->Table->CreateTree(0); foreach ($this->Table->tree as $key => $value) { $this->Table->tree[$key]["title"] = $value['preffix']. $this->Table->tree[$key]["item_title_".GetParam("DefaultLanguage")]; $this->StandardTree[] = $value; } $this->Tree = $this->Table->tree; } function Menu() { global $ALANG; return array( array('title' => $ALANG['MenuMenuItems'], 'link' => '?mod='.$this->ClassName.'&list'), array('title' => $ALANG['MenuMenuAdd'], 'link' => '?mod='.$this->ClassName.'&add') ); } function Admin() { global $ALANG, $alang; $smarty = GetAdminSmarty($this->ClassName); $smarty->assign("module", $this->ClassName); $smarty->assign("table", $this->Table->TableName); if (isset($_GET['mod']) && ($_GET['mod'] == $this->ClassName)) { /*if (isset($_GET['UpdateLinks'])) { for ($i = 0; $i < count($this->ItemsTree); $i++) { preg_match("/index.php\?page_id=([0-9]{1,9})/", $this->ItemsTree[$i]['item_link'],$mathces); if ($mathces[1] > 0) $this->ItemsTree[$i]['item_link'] = "/pages/p".$mathces[1]; preg_match("/index.php\?chapter_id=([0-9]{1,9})/", $this->ItemsTree[$i]['item_link'],$mathces); if ($mathces[1] > 0) $this->ItemsTree[$i]['item_link'] = "/pages/c".$mathces[1]; $this->Table->UpdateRecord($this->ItemsTree[$i], array('item_link'), $this->ItemsTree[$i]['item_id']); } }*/ if (isset($_GET['list'])) { $fields = array("item_id", "title"); $captions = array($ALANG['Menu_item_id'], $ALANG['Menu_item_title']); $order = "item_position ASC"; $links = array("checkbox", "delete", "edit", "up", "down"); $params = array("id" => "items", "tree" => "item_title_".GetParam("DefaultLanguage"), "postfix" => array( array("title" => "создать подпункт", "preffix" => "add", "class" => "menu-add-item" ))); $multiple = array("delete"); $html = $this->Table->GetAdminTable($fields, $captions, $conditions, $order, $links, $multiple, $params); $result['Title'] = $ALANG['MenuItems']; $result['Content'] = $html.$smarty->fetch("items-list.tpl"); return $result; } if (isset($_GET['add'])) { if (isset($_POST['add'])) { $id = $this->Table->Insert($_POST); header("Location: ?mod=".$this->ClassName."&list"); } $smarty->assign('oper', 'add'); $smarty->assign('items', $this->Tree); if (isset($_GET['item_id'])) $smarty->assign('item_parent_id', $_GET['item_id']); $result['Title'] = $ALANG['MenuAdd']; $result['Content'] = $smarty->fetch('item.tpl'); return $result; } if (isset($_GET['edit']) && isset($_GET['item_id'])) { if (isset($_POST['edit'])) { $item_parent_id = $_POST['item_parent_id']; $this->Table->Update($_POST, $_GET['item_id']); header("Location: ?mod=".$this->ClassName."&list"); } if ($_GET['item_id'] == 1) header("Location: ?mod=".$this->ClassName."&list"); $row = $this->Table->GetRowById($_GET['item_id']); foreach($row as $key => $value) $smarty->assign($key, $value); $smarty->assign($key, $value); $smarty->assign('oper', 'edit'); $smarty->assign('items', $this->Tree); $result['Title'] = $ALANG['MenuItemEdit']; $result['Content'] = $smarty->fetch('item.tpl'); return $result; } } } function AdminAsynch() { global $alang, $ALANG; if (isset($_GET['items']) && isset($_GET['getadmintable'])) { $fields = array("item_id", "title"); $captions = array($ALANG['Menu_item_id'], $ALANG['Menu_item_title']); $order = "item_position ASC"; $links = array("checkbox", "delete", "edit", "up", "down"); $params = array("id" => "items", "tree" => "item_title_".GetParam("DefaultLanguage"), "postfix" => array( array("title" => "создать подпункт", "preffix" => "add", "class" => "menu-add-item" ))); $multiple = array("delete"); echo $this->Table->GetAdminTable($fields, $captions, $conditions, $order, $links, $multiple, $params); die; } $this->Table->Run($_POST); } function Panel() { global $ULANG, $ulang; $html .= "<ul id=\"{$this->ClassName}Root\" class=\"menulist\">"; $ul = 1; $li = 0; for($i = 1; $i < count($this->StandardTree); $i++) { $img = ""; $file = "data/leftmenu/{$this->StandardTree[$i]['item_id']}.png"; //if (file_exists($file)) // $img = "<img src=\"/{$file}\" align=\"absmiddle\" /> "; $link = $this->StandardTree[$i]['item_link']; if (strlen(trim($link)) > 0) $html .= "<li><a href=\"".$link."\" target=\"".$this->StandardTree[$i]['item_target']."\">".$img.$this->StandardTree[$i]['item_title_'.$ulang]."</a>"; else $html .= "<li><a>".$img.$this->StandardTree[$i]['item_title_'.$ulang]."</a>"; $li++; if ($i == count($this->StandardTree) - 1) continue; if ($this->StandardTree[$i]['depth'] >= $this->StandardTree[$i + 1]['depth']) { $html .= "</li>"; $li--; } if ($this->StandardTree[$i]['depth'] < $this->StandardTree[$i + 1]['depth']) { $html .= "<ul>"; $ul++; } for ($k = 0; $k < $this->StandardTree[$i]['depth'] - $this->StandardTree[$i + 1]['depth']; $k ++) { $html .= "</ul></li>"; $ul--; $li--; } } $html .= "</li></ul>"; $result[$this->ClassName] = array( 'Content' => $html, 'Title' => "", 'Module' => $this->ClassName, ); return $result; } } $Modules ['LeftMenu'] = new LeftMenu(); ?>
|