Fix: Menu editor

This commit is contained in:
Laurent Destailleur 2013-02-19 15:23:25 +01:00
parent 7367a2472c
commit 95098a9b59
2 changed files with 40 additions and 28 deletions

View File

@ -77,14 +77,21 @@ if ($action == 'update' && empty($_POST["cancel"]))
// Define list of menu handlers to initialize // Define list of menu handlers to initialize
$listofmenuhandler=array(); $listofmenuhandler=array();
$listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i','',$_POST["MAIN_MENU_STANDARD"])]=1;
$listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i','',$_POST["MAIN_MENUFRONT_STANDARD"])]=1;
if (isset($_POST["MAIN_MENU_SMARTPHONE"])) $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i','',$_POST["MAIN_MENU_SMARTPHONE"])]=1;
if (isset($_POST["MAIN_MENUFRONT_SMARTPHONE"])) $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i','',$_POST["MAIN_MENUFRONT_SMARTPHONE"])]=1;
// Initialize menu handlers // Initialize menu handlers
foreach ($listofmenuhandler as $key => $val) foreach ($listofmenuhandler as $key => $val)
{ {
// Load sql init_menu_handler.sql file // Load sql init_menu_handler.sql file
$dir = "/core/menus/"; $dirmenus=array_merge(array("/core/menus/"),(array) $conf->modules_parts['menus']);
foreach($dirmenus as $dirmenu)
{
$file='init_menu_'.$key.'.sql'; $file='init_menu_'.$key.'.sql';
$fullpath=dol_buildpath($dir.$file); $fullpath=dol_buildpath($dirmenu.$file);
//print 'action='.$action.' Search menu into fullpath='.$fullpath.'<br>';exit;
if (file_exists($fullpath)) if (file_exists($fullpath))
{ {
@ -103,6 +110,7 @@ if ($action == 'update' && empty($_POST["cancel"]))
} }
} }
} }
}
if (! $error) if (! $error)
{ {

View File

@ -47,16 +47,20 @@ $mesg=GETPOST('mesg');
$menu_handler_top=$conf->global->MAIN_MENU_STANDARD; $menu_handler_top=$conf->global->MAIN_MENU_STANDARD;
$menu_handler_smartphone=$conf->global->MAIN_MENU_SMARTPHONE; $menu_handler_smartphone=$conf->global->MAIN_MENU_SMARTPHONE;
$menu_handler_top=preg_replace('/_backoffice.php/i','',$menu_handler_top); $menu_handler_top=preg_replace('/(_backoffice\.php|_menu\.php)/i','',$menu_handler_top);
$menu_handler_top=preg_replace('/_frontoffice.php/i','',$menu_handler_top); $menu_handler_top=preg_replace('/(_frontoffice\.php|_menu\.php)/i','',$menu_handler_top);
$menu_handler_smartphone=preg_replace('/_backoffice.php/i','',$menu_handler_smartphone); $menu_handler_smartphone=preg_replace('/(_backoffice\.php|_menu\.php)/i','',$menu_handler_smartphone);
$menu_handler_smartphone=preg_replace('/_frontoffice.php/i','',$menu_handler_smartphone); $menu_handler_smartphone=preg_replace('/(_frontoffice\.php|_menu\.php)/i','',$menu_handler_smartphone);
$menu_handler=$menu_handler_top; $menu_handler=$menu_handler_top;
if (GETPOST("handler_origine")) $menu_handler=GETPOST("handler_origine"); if (GETPOST("handler_origine")) $menu_handler=GETPOST("handler_origine");
if (GETPOST("menu_handler")) $menu_handler=GETPOST("menu_handler"); if (GETPOST("menu_handler")) $menu_handler=GETPOST("menu_handler");
$menu_handler_to_search=preg_replace('/(_backoffice|_menu)?(\.php)?/i','',$menu_handler);
$menu_handler_to_search=preg_replace('/(_frontoffice|_menu)?(\.php)?/i','',$menu_handler);
/* /*
* Actions * Actions
@ -89,7 +93,7 @@ if ($action == 'up')
$sql = "SELECT m.rowid, m.position"; $sql = "SELECT m.rowid, m.position";
$sql.= " FROM ".MAIN_DB_PREFIX."menu as m"; $sql.= " FROM ".MAIN_DB_PREFIX."menu as m";
$sql.= " WHERE (m.position < ".($current['order'])." OR (m.position = ".($current['order'])." AND rowid < ".$_GET["menuId"]."))"; $sql.= " WHERE (m.position < ".($current['order'])." OR (m.position = ".($current['order'])." AND rowid < ".$_GET["menuId"]."))";
$sql.= " AND m.menu_handler='".$menu_handler."'"; $sql.= " AND m.menu_handler='".$menu_handler_to_search."'";
$sql.= " AND m.entity = ".$conf->entity; $sql.= " AND m.entity = ".$conf->entity;
$sql.= " AND m.type = '".$current['type']."'"; $sql.= " AND m.type = '".$current['type']."'";
$sql.= " AND m.fk_menu = '".$current['fk_menu']."'"; $sql.= " AND m.fk_menu = '".$current['fk_menu']."'";
@ -145,7 +149,7 @@ elseif ($action == 'down')
$sql = "SELECT m.rowid, m.position"; $sql = "SELECT m.rowid, m.position";
$sql.= " FROM ".MAIN_DB_PREFIX."menu as m"; $sql.= " FROM ".MAIN_DB_PREFIX."menu as m";
$sql.= " WHERE (m.position > ".($current['order'])." OR (m.position = ".($current['order'])." AND rowid > ".$_GET["menuId"]."))"; $sql.= " WHERE (m.position > ".($current['order'])." OR (m.position = ".($current['order'])." AND rowid > ".$_GET["menuId"]."))";
$sql.= " AND m.menu_handler='".$menu_handler."'"; $sql.= " AND m.menu_handler='".$menu_handler_to_search."'";
$sql.= " AND m.entity = ".$conf->entity; $sql.= " AND m.entity = ".$conf->entity;
$sql.= " AND m.type = '".$current['type']."'"; $sql.= " AND m.type = '".$current['type']."'";
$sql.= " AND m.fk_menu = '".$current['fk_menu']."'"; $sql.= " AND m.fk_menu = '".$current['fk_menu']."'";
@ -255,7 +259,7 @@ if ($action == 'delete')
print '<form name="newmenu" class="nocellnopadd" action="'.$_SERVER["PHP_SELF"].'">'; print '<form name="newmenu" class="nocellnopadd" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" action="change_menu_handler">'; print '<input type="hidden" action="change_menu_handler">';
print $langs->trans("MenuHandler").': '; print $langs->trans("MenuHandler").': ';
print $formadmin->select_menu_families($menu_handler,'menu_handler',array_merge($dirstandard,$dirsmartphone)); print $formadmin->select_menu_families($menu_handler.(preg_match('/_menu/',$menu_handler)?'':'_menu'),'menu_handler',array_merge($dirstandard,$dirsmartphone));
print ' &nbsp; <input type="submit" class="button" value="'.$langs->trans("Refresh").'">'; print ' &nbsp; <input type="submit" class="button" value="'.$langs->trans("Refresh").'">';
print '</form>'; print '</form>';
@ -294,7 +298,7 @@ if ($conf->use_javascript_ajax)
$sql = "SELECT m.rowid, m.titre, m.langs, m.mainmenu, m.leftmenu, m.fk_menu, m.fk_mainmenu, m.fk_leftmenu"; $sql = "SELECT m.rowid, m.titre, m.langs, m.mainmenu, m.leftmenu, m.fk_menu, m.fk_mainmenu, m.fk_leftmenu";
$sql.= " FROM ".MAIN_DB_PREFIX."menu as m"; $sql.= " FROM ".MAIN_DB_PREFIX."menu as m";
$sql.= " WHERE menu_handler = '".$menu_handler."'"; $sql.= " WHERE menu_handler = '".$menu_handler_to_search."'";
$sql.= " AND entity = ".$conf->entity; $sql.= " AND entity = ".$conf->entity;
$sql.= " AND fk_menu >= 0"; $sql.= " AND fk_menu >= 0";
$sql.= " ORDER BY m.position, m.rowid"; // Order is position then rowid (because we need a sort criteria when position is same) $sql.= " ORDER BY m.position, m.rowid"; // Order is position then rowid (because we need a sort criteria when position is same)