clear_sys("menus_");
}
$menus_equery = explode('.', e_QUERY);
if (isset($_POST['custom_select']))
{
$menus_equery[1] = $_POST['custom_select'];
//header("location:".e_SELF."?".$_POST['custom_select']);
//exit;
}
else if (!isset($menus_equery[1]))
{
$menus_equery[1] = '';
}
if ($menus_equery[1] == '' || $menus_equery[1] == 'default_layout')
{
$menus_header = $HEADER;
$menus_footer = $FOOTER;
}
else if ($menus_equery[1] == 'custom_layout')
{
$menus_header = $CUSTOMHEADER ? $CUSTOMHEADER :
$HEADER;
$menus_footer = $CUSTOMFOOTER ? $CUSTOMFOOTER :
$FOOTER;
}
else if ($menus_equery[1] == 'newsheader_layout')
{
$menus_header = $NEWSHEADER ? $NEWSHEADER :
$HEADER;
$menus_footer = $FOOTER;
}
else
{
$menus_header = $CUSTOMHEADER[$menus_equery[1]] ? $CUSTOMHEADER[$menus_equery[1]] :
$HEADER;
$menus_footer = $CUSTOMFOOTER[$menus_equery[1]] ? $CUSTOMFOOTER[$menus_equery[1]] :
$FOOTER;
}
$layouts_str = $HEADER.$FOOTER;
if ($NEWSHEADER)
{
$layouts_str .= $NEWSHEADER;
}
if ($CUSTOMPAGES)
{
if (is_array($CUSTOMPAGES))
{
foreach ($CUSTOMPAGES as $custom_extract_key => $custom_extract_value)
{
if ($CUSTOMHEADER[$custom_extract_key])
{
$layouts_str .= $CUSTOMHEADER[$custom_extract_key];
}
if ($CUSTOMFOOTER[$custom_extract_key])
{
$layouts_str .= $CUSTOMFOOTER[$custom_extract_key];
}
}
}
else
{
if ($CUSTOMHEADER)
{
$layouts_str .= $CUSTOMHEADER;
}
if ($CUSTOMFOOTER)
{
$layouts_str .= $CUSTOMFOOTER;
}
}
}
$menu_array = parseheader($layouts_str, 'check');
sort($menu_array, SORT_NUMERIC);
$menu_check = 'set';
foreach ($menu_array as $menu_value)
{
if ($menu_value != $menu_check)
{
$menu_areas[] = $menu_value;
}
$menu_check = $menu_value;
}
// Cams Bit ----------- Activate Multiple Menus ---
if($_POST['menuActivate'])
{
foreach ($_POST['menuActivate'] as $k => $v)
{
if (trim($v))
{
$location = $k;
}
}
$menu_count = $sql->db_Count("menus", "(*)", " WHERE menu_location=".$location);
foreach($_POST['menuselect'] as $sel_mens)
{
//Get info from menu being activated
if($sql->db_Select("menus", 'menu_name, menu_path' , 'menu_id = '.$sel_mens))
{
$row=$sql->db_Fetch();
//If menu is not already activated in that area, add the record.
if(!$sql->db_Select('menus', 'menu_id', "menu_name='{$row['menu_name']}' AND menu_location = $location"))
{
$qry = "
INSERT into #menus
(`menu_name`, `menu_location`, `menu_order`, `menu_pages`, `menu_path`)
VALUES ('{$row['menu_name']}', {$location}, {$menu_count}, '', '{$row['menu_path']}')
";
$sql->db_Select_gen($qry);
$admin_log->log_event('MENU_01',$row['menu_name'].'[!br!]'.$location.'[!br!]'.$menu_count.'[!br!]'.$row['menu_path'],E_LOG_INFORMATIVE,'');
$menu_count++;
}
}
}
}
// =============
if (isset($_POST['menuAct']))
{
foreach ($_POST['menuAct'] as $k => $v)
{
if (trim($v))
{
$id = $k;
list($menu_act, $location, $position, $newloc) = explode(".", $_POST['menuAct'][$k]);
}
}
}
if ($menu_act == 'config')
{
if($newloc)
{
$newloc = ".".$newloc;
}
$newurl = $PLUGINS_DIRECTORY.$location."/{$position}{$newloc}.php";
$newurl = SITEURL.str_replace("//", "/", $newurl);
echo " ";
exit;
}
if ($menu_act == "adv")
{
require_once(e_HANDLER."userclass_class.php");
$sql->db_Select("menus", "*", "menu_id=".$id);
$row = $sql->db_Fetch();
$listtype = substr($row['menu_pages'], 0, 1);
$menu_pages = substr($row['menu_pages'], 2);
$menu_pages = str_replace("|", "\n", $menu_pages);
$text = "
";
$caption = MENLAN_7." ".$row['menu_name'];
$ns->tablerender($caption, $text);
}
unset($message);
if ($menu_act == "sv")
{
$pagelist = explode("\r\n", $_POST['pagelist']);
for ($i = 0 ; $i < count($pagelist) ; $i++)
{
$pagelist[$i] = trim($pagelist[$i]);
}
$plist = implode("|", $pagelist);
$pageparms = $_POST['listtype'].'-'.$plist;
$pageparms = preg_replace("#\|$#", "", $pageparms);
$pageparms = (trim($_POST['pagelist']) == '') ? '' : $pageparms;
$sql->db_Update("menus", "menu_class='".$_POST['menu_class']."', menu_pages='{$pageparms}' WHERE menu_id=".intval($id));
$admin_log->log_event('MENU_02',$_POST['menu_class'].'[!br!]'.$pageparms.'[!br!]'.$id,E_LOG_INFORMATIVE,'');
$message = " ".MENLAN_8." ";
}
if ($menu_act == "move")
{
// Get current menu name
if($sql->db_Select('menus', 'menu_name', 'menu_id='.$id, 'default'))
{
$row = $sql->db_Fetch();
//Check to see if menu is already active in the new area, if not then move it
if(!$sql->db_Select('menus', 'menu_id', "menu_name='{$row['menu_name']}' AND menu_location = ".$newloc))
{
$menu_count = $sql->db_Count("menus", "(*)", " WHERE menu_location=".$newloc);
$sql->db_Update("menus", "menu_location='{$newloc}', menu_order=".($menu_count+1)." WHERE menu_id=".$id);
$sql->db_Update("menus", "menu_order=menu_order-1 WHERE menu_location='{$location}' AND menu_order > {$position}");
}
$admin_log->log_event('MENU_03',$row['menu_name'].'[!br!]'.$newloc.'[!br!]'.$id,E_LOG_INFORMATIVE,'');
}
}
if ($menu_act == "deac")
{
// Get current menu name
if($sql->db_Select('menus', 'menu_name', 'menu_id='.$id, 'default'))
{
$row = $sql->db_Fetch();
//Check to see if there is already a menu with location = 0 (to maintain BC)
if($sql->db_Select('menus', 'menu_id', "menu_name='{$row['menu_name']}' AND menu_location = 0"))
{
//menu_location=0 already exists, we can just delete this record
$sql->db_Delete('menus', 'menu_id='.$id);
}
else
{
//menu_location=0 does NOT exist, let's just convert this to it
$sql->db_Update("menus", "menu_location=0, menu_order=0, menu_class=0, menu_pages='' WHERE menu_id=".$id);
}
//Move all other menus up
$sql->db_Update("menus", "menu_order=menu_order-1 WHERE menu_location={$location} AND menu_order > {$position}");
$admin_log->log_event('MENU_04',$row['menu_name'].'[!br!]'.$location.'[!br!]'.$position.'[!br!]'.$id,E_LOG_INFORMATIVE,'');
}
}
if ($menu_act == "bot")
{
$menu_count = $sql->db_Count("menus", "(*)", " WHERE menu_location='{$location}' ");
$sql->db_Update("menus", "menu_order=".($menu_count+1)." WHERE menu_order='{$position}' AND menu_location='{$location}' ");
$sql->db_Update("menus", "menu_order=menu_order-1 WHERE menu_location='{$location}' AND menu_order > {$position}");
$admin_log->log_event('MENU_06',$location.'[!br!]'.$position.'[!br!]'.$id,E_LOG_INFORMATIVE,'');
}
if ($menu_act == "top")
{
$sql->db_Update("menus", "menu_order=menu_order+1 WHERE menu_location='{$location}' AND menu_order < {$position}");
$sql->db_Update("menus", "menu_order=1 WHERE menu_id='{$id}' ");
$admin_log->log_event('MENU_05',$location.'[!br!]'.$position.'[!br!]'.$id,E_LOG_INFORMATIVE,'');
}
if ($menu_act == "dec")
{
$sql->db_Update("menus", "menu_order=menu_order-1 WHERE menu_order='".($position+1)."' AND menu_location='{$location}' ");
$sql->db_Update("menus", "menu_order=menu_order+1 WHERE menu_id='{$id}' AND menu_location='{$location}' ");
$admin_log->log_event('MENU_08',$location.'[!br!]'.$position.'[!br!]'.$id,E_LOG_INFORMATIVE,'');
}
if ($menu_act == "inc")
{
$sql->db_Update("menus", "menu_order=menu_order+1 WHERE menu_order='".($position-1)."' AND menu_location='{$location}' ");
$sql->db_Update("menus", "menu_order=menu_order-1 WHERE menu_id='{$id}' AND menu_location='{$location}' ");
$admin_log->log_event('MENU_07',$location.'[!br!]'.$position.'[!br!]'.$id,E_LOG_INFORMATIVE,'');
}
if (strpos(e_QUERY, 'configure') === FALSE)
{ // Scan plugin directories to see if menus to add
$efile = new e_file;
$fileList = $efile->get_files(e_PLUGIN,"_menu\.php$",'standard',1);
foreach($fileList as $file)
{
list($parent_dir) = explode('/',str_replace(e_PLUGIN,"",$file['path']));
$file['path'] = str_replace(e_PLUGIN,"",$file['path']);
$file['fname'] = str_replace(".php","",$file['fname']);
$valid_menu = FALSE;
$existing_menu = $sql->db_Count("menus", "(*)", "WHERE menu_name='{$file['fname']}'");
if (file_exists(e_PLUGIN.$parent_dir."/plugin.xml") ||
file_exists(e_PLUGIN.$parent_dir."/plugin.php"))
{
// include(e_PLUGIN.$parent_dir."/plugin.php");
if (isset($pref['plug_installed'][$parent_dir]))
// if ($sql->db_Select("plugin", "*", "plugin_path='".$eplug_folder."' AND plugin_installflag='1' "))
{ // Its a 'new style' plugin with a plugin.php file, or an even newer one with plugin.xml file - only include if plugin installed
$valid_menu = TRUE; // Whether new or existing, include in list
}
}
else
{ // Just add the menu anyway
$valid_menu = TRUE;
}
if ($valid_menu)
{
$menustr .= "&".str_replace(".php", "", $file['fname']);
if (!$existing_menu)
{ // New menu to add to list
$sql->db_Insert("menus", " 0, '{$file['fname']}', 0, 0, 0, '' ,'{$file['path']}'");
// Could do admin logging here - but probably not needed
$message .= "".MENLAN_10." - ".$file['fname']." ";
}
}
}
//Reorder all menus into 1...x order
if (!is_object($sql2)) $sql2 = new db; // Shouldn't be needed
foreach ($menu_areas as $menu_act)
{
if ($sql->db_Select("menus", "menu_id", "menu_location={$menu_act} ORDER BY menu_order ASC"))
{
$c = 1;
while ($row = $sql->db_Fetch())
{
$sql2->db_Update("menus", "menu_order={$c} WHERE menu_id=".$row['menu_id']);
$c++;
}
}
}
$sql->db_Select("menus", "*", "menu_path NOT REGEXP('[0-9]+') ");
while (list($menu_id, $menu_name, $menu_location, $menu_order) = $sql->db_Fetch())
{
if (stristr($menustr, $menu_name) === FALSE)
{
$sql2->db_Delete("menus", "menu_name='$menu_name'");
$message .= "".MENLAN_11." - ".$menu_name." ";
}
}
}
if ($message != "")
{
echo $ns -> tablerender('Updated', "
".$message."
");
}
if (strpos(e_QUERY, 'configure') === FALSE)
{
$cnt = $sql->db_Select("menus", "*", "menu_location='1' ORDER BY menu_name "); // calculate height to remove vertical scroll-bar.
$text = "";
echo $ns -> tablerender(MENLAN_35, $text, 'menus_config');
}
else
{
if ($CUSTOMPAGES)
{
if ($menu_act != 'adv')
{
$text = "";
$ns->tablerender(MENLAN_29, $text);
}
}
parseheader($menus_header);
echo "