Viewing file: module.php (6.58 KB) -rwxrwxrwx Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?
class TopMenu
{
var $UserMode = false;
var $AdminMode = true;
var $SearchMode = false;
var $PanelMode = true;
var $AdminAsynchMode = true;
var $Table;
var $PagesTable;
var $Directory;
var $ClassName = 'TopMenu';
var $Tree;
var $StandardTree;
function TopMenu()
{
$this->Directory = dirname(__FILE__);
$this->Table = new AMTable2('AMCMS_topmenu');
$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_horiz\">";
$ul = 1;
$li = 0;
for($i = 1; $i < count($this->StandardTree); $i++)
{
$link = $this->StandardTree[$i]['item_link'];
$cl = "";
$cl3 = "";
if ($ul == 1)
{
$cl = "class=\"top\"";
$cl3 = "class=\"top_link\"";
}
$cl2 = "";
if ($this->StandardTree[$i]['depth'] < $this->StandardTree[$i + 1]['depth'])
$cl2 = "class=\"down\"";
if (strlen(trim($link)) > 0)
$html .= "<li $cl><a $cl3 href=\"".$link."\" target=\"".$this->StandardTree[$i]['item_target']."\"><span $cl2>".$this->StandardTree[$i]['item_title_'.$ulang]."</span></a>";
else
$html .= "<li $cl><a $cl3 style=\"cursor:default\"><span>".$this->StandardTree[$i]['item_title_'.$ulang]."</span></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 class=\"sub\">";
$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' => /*GetParam("Module".$this->ClassName, $ulang)*/"",
'Module' => $this->ClassName,
);
return $result;
}
}
$Modules ['TopMenu'] = new TopMenu();
?>
|