Viewing file: module.php (7.42 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); AMCMS_Cache::ClearCache("menu"); 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']); AMCMS_Cache::ClearCache("menu"); 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; AMCMS_Cache::ClearCache("menu"); 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=\"left-menu\">"; $ul = 1; $li = 0; $pages = new Pages(); $chapters = array(); if (isset($_GET['page_id'])) { $page = $pages->PagesTable->GetRowById($_GET['page_id']); $chapters[] = $page['page_chapter_id']; $chapter_id = $page['page_chapter_id']; } if (isset($_GET['chapter_id'])) { $chapter_id = $_GET['chapter_id']; $chapters[] = $chapter_id; } if (isset($chapter_id)) { $cnt = 0; while($chapter_id != 1) { $chapter_id = $pages->ChaptersTree[$chapter_id]['chapter_parent_id']; $chapters [] = $chapter_id; $cnt++; if ($cnt > 10) break; } } // var_dump($chapters); for($i = 1; $i < count($this->StandardTree); $i++) { $link = $this->StandardTree[$i]['item_link']; $class = ""; if (strlen(trim($link)) > 0 and strpos($_SERVER['REDIRECT_URL']."", $link."") === 0 and $t == 0 and strpos($_SERVER['REDIRECT_URL'], "/pages") === false) { $class = "vis"; $t = 1;} for($k = 0; $k < count($chapters); $k++) { if (strlen(trim($link)) > 0 and strpos($_SERVER['REDIRECT_URL']." ", $link." ") === 0 and $t == 0) { $class = "vis"; $t = 1;} if (strlen(trim($link)) > 0 and strpos("/pages/c{$chapters[$k]} ", $link." ") === 0 and $t == 0) { $class = "vis"; $t = 1;} } if (strlen(trim($link)) > 0) $html .= "<li class=\"{$class}\"><a href=\"".$link."\" target=\"".$this->StandardTree[$i]['item_target']."\">".$this->StandardTree[$i]['item_title_'.$ulang]."</a>"; else $html .= "<li class=\"{$class}\"><a style=\"\">".$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>"; AMCMS_Cache::Save("menu", $_SERVER['REDIRECT_URL'], "", $html); $result[$this->ClassName] = array( 'Content' => $html, 'Title' => "Головне меню", 'Module' => $this->ClassName, ); return $result; } } $Modules ['LeftMenu'] = new LeftMenu(); ?>
|