New: Uniformize code to manage menus handler provided by external
modules
This commit is contained in:
parent
d78192040b
commit
acef131833
@ -28,6 +28,7 @@ require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/class/html.formadmin.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
|
||||
|
||||
$action=GETPOST('action');
|
||||
|
||||
$langs->load("companies");
|
||||
$langs->load("products");
|
||||
@ -38,9 +39,13 @@ $langs->load("other");
|
||||
// Security check
|
||||
if (!$user->admin) accessforbidden();
|
||||
|
||||
$dirtop = "/core/menus/standard";
|
||||
$dirleft = "/core/menus/standard";
|
||||
$dirsmartphone = "/core/menus/smartphone";
|
||||
$dirstandard = array("/core/menus/standard");
|
||||
$dirsmartphone = array("/core/menus/smartphone");
|
||||
foreach($conf->menus_modules as $dir)
|
||||
{
|
||||
$dirstandard[]=$dir.'/standard';
|
||||
$dirsmartphone[]=$dir.'/standard';
|
||||
}
|
||||
|
||||
|
||||
// Cette page peut etre longue. On augmente le delai autorise.
|
||||
@ -56,7 +61,7 @@ error_reporting($err);
|
||||
* Actions
|
||||
*/
|
||||
|
||||
if (isset($_POST["action"]) && $_POST["action"] == 'update' && empty($_POST["cancel"]))
|
||||
if ($action == 'update' && empty($_POST["cancel"]))
|
||||
{
|
||||
$_SESSION["mainmenu"]="home"; // Le gestionnaire de menu a pu changer
|
||||
|
||||
@ -85,7 +90,7 @@ if (isset($_POST["action"]) && $_POST["action"] == 'update' && empty($_POST["can
|
||||
if (file_exists($fullpath))
|
||||
{
|
||||
$db->begin();
|
||||
|
||||
|
||||
$result=run_sql($fullpath,1,'',1,$key,'none');
|
||||
if ($result > 0)
|
||||
{
|
||||
@ -103,7 +108,7 @@ if (isset($_POST["action"]) && $_POST["action"] == 'update' && empty($_POST["can
|
||||
if (! $error)
|
||||
{
|
||||
$db->close();
|
||||
|
||||
|
||||
// We make a header redirect because we need to change menu NOW.
|
||||
header("Location: ".$_SERVER["PHP_SELF"]);
|
||||
exit;
|
||||
@ -116,15 +121,13 @@ if (isset($_POST["action"]) && $_POST["action"] == 'update' && empty($_POST["can
|
||||
*/
|
||||
|
||||
$form=new Form($db);
|
||||
$htmladmin=new FormAdmin($db);
|
||||
$formadmin=new FormAdmin($db);
|
||||
|
||||
$wikihelp='EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
|
||||
llxHeader('',$langs->trans("Setup"),$wikihelp);
|
||||
|
||||
print_fiche_titre($langs->trans("Menus"),'','setup');
|
||||
|
||||
print $langs->trans("MenusDesc")."<br>\n";
|
||||
print "<br>\n";
|
||||
|
||||
$h = 0;
|
||||
|
||||
@ -146,6 +149,9 @@ $h++;
|
||||
|
||||
dol_fiche_head($head, 'handler', $langs->trans("Menus"));
|
||||
|
||||
print $langs->trans("MenusDesc")."<br>\n";
|
||||
print "<br>\n";
|
||||
|
||||
|
||||
if (isset($_GET["action"]) && $_GET["action"] == 'edit')
|
||||
{
|
||||
@ -172,10 +178,10 @@ if (isset($_GET["action"]) && $_GET["action"] == 'edit')
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'><td>'.$langs->trans("DefaultMenuManager").'</td>';
|
||||
print '<td>';
|
||||
print $htmladmin->select_menu(empty($conf->global->MAIN_MENU_STANDARD_FORCED)?$conf->global->MAIN_MENU_STANDARD:$conf->global->MAIN_MENU_STANDARD_FORCED, 'MAIN_MENU_STANDARD', $dirtop, empty($conf->global->MAIN_MENU_STANDARD_FORCED)?'':' disabled="disabled"');
|
||||
print $formadmin->select_menu(empty($conf->global->MAIN_MENU_STANDARD_FORCED)?$conf->global->MAIN_MENU_STANDARD:$conf->global->MAIN_MENU_STANDARD_FORCED, 'MAIN_MENU_STANDARD', $dirstandard, empty($conf->global->MAIN_MENU_STANDARD_FORCED)?'':' disabled="disabled"');
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
print $htmladmin->select_menu(empty($conf->global->MAIN_MENUFRONT_STANDARD_FORCED)?$conf->global->MAIN_MENUFRONT_STANDARD:$conf->global->MAIN_MENUFRONT_STANDARD_FORCED, 'MAIN_MENUFRONT_STANDARD', $dirtop, empty($conf->global->MAIN_MENUFRONT_STANDARD_FORCED)?'':' disabled="disabled"');
|
||||
print $formadmin->select_menu(empty($conf->global->MAIN_MENUFRONT_STANDARD_FORCED)?$conf->global->MAIN_MENUFRONT_STANDARD:$conf->global->MAIN_MENUFRONT_STANDARD_FORCED, 'MAIN_MENUFRONT_STANDARD', $dirstandard, empty($conf->global->MAIN_MENUFRONT_STANDARD_FORCED)?'':' disabled="disabled"');
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
@ -183,10 +189,10 @@ if (isset($_GET["action"]) && $_GET["action"] == 'edit')
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'><td>'.$langs->trans("DefaultMenuSmartphoneManager").'</td>';
|
||||
print '<td>';
|
||||
print $htmladmin->select_menu(empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED)?$conf->global->MAIN_MENU_SMARTPHONE:$conf->global->MAIN_MENU_SMARTPHONE_FORCED, 'MAIN_MENU_SMARTPHONE', array($dirtop,$dirsmartphone), empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED)?'':' disabled="disabled"');
|
||||
print $formadmin->select_menu(empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED)?$conf->global->MAIN_MENU_SMARTPHONE:$conf->global->MAIN_MENU_SMARTPHONE_FORCED, 'MAIN_MENU_SMARTPHONE', array_merge($dirstandard,$dirsmartphone), empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED)?'':' disabled="disabled"');
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
print $htmladmin->select_menu(empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)?$conf->global->MAIN_MENUFRONT_SMARTPHONE:$conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED, 'MAIN_MENUFRONT_SMARTPHONE', array($dirtop,$dirsmartphone), empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)?'':' disabled="disabled"');
|
||||
print $formadmin->select_menu(empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)?$conf->global->MAIN_MENUFRONT_SMARTPHONE:$conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED, 'MAIN_MENUFRONT_SMARTPHONE', array_merge($dirstandard,$dirsmartphone), empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)?'':' disabled="disabled"');
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
|
||||
@ -30,14 +30,12 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/menubase.class.php");
|
||||
|
||||
$langs->load("admin");
|
||||
|
||||
if (! $user->admin)
|
||||
accessforbidden();
|
||||
if (! $user->admin) accessforbidden();
|
||||
|
||||
$dirtop = "/core/menus/standard";
|
||||
$dirleft = "/core/menus/standard";
|
||||
$dirstandard = "/core/menus/standard";
|
||||
$dirsmartphone = "/core/menus/smartphone";
|
||||
|
||||
$dirmenu = array($dirleft,$dirsmartphone);
|
||||
$dirmenu = array($dirstandard,$dirsmartphone);
|
||||
|
||||
$action=GETPOST('action');
|
||||
$mesg=GETPOST('mesg');
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
|
||||
* Copyright (C) 2007-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2009-2011 Regis Houssin <regis@dolibarr.fr>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -30,14 +30,15 @@ require_once(DOL_DOCUMENT_ROOT."/core/lib/treeview.lib.php");
|
||||
$langs->load("other");
|
||||
$langs->load("admin");
|
||||
|
||||
if (! $user->admin)
|
||||
accessforbidden();
|
||||
if (! $user->admin) accessforbidden();
|
||||
|
||||
$dirtop = "/core/menus/standard";
|
||||
$dirleft = "/core/menus/standard";
|
||||
$dirsmartphone = "/core/menus/smartphone";
|
||||
|
||||
$dirmenu = array($dirleft,$dirsmartphone);
|
||||
$dirstandard = array("/core/menus/standard");
|
||||
$dirsmartphone = array("/core/menus/smartphone");
|
||||
foreach($conf->menus_modules as $dir)
|
||||
{
|
||||
$dirstandard[]=$dir.'/standard';
|
||||
$dirsmartphone[]=$dir.'/standard';
|
||||
}
|
||||
|
||||
$mesg=$_GET["mesg"];
|
||||
|
||||
@ -207,9 +208,6 @@ llxHeader('',$langs->trans("Menus"),'','',0,0,$arrayofjs);
|
||||
|
||||
print_fiche_titre($langs->trans("Menus"),'','setup');
|
||||
|
||||
print $langs->trans("MenusEditorDesc")."<br>\n";
|
||||
print "<br>\n";
|
||||
|
||||
|
||||
dol_htmloutput_mesg($mesg);
|
||||
|
||||
@ -233,6 +231,10 @@ $h++;
|
||||
|
||||
dol_fiche_head($head, 'editor', $langs->trans("Menus"));
|
||||
|
||||
print $langs->trans("MenusEditorDesc")."<br>\n";
|
||||
print "<br>\n";
|
||||
|
||||
|
||||
// Confirmation for remove menu entry
|
||||
if ($_GET["action"] == 'delete')
|
||||
{
|
||||
@ -250,7 +252,7 @@ if ($_GET["action"] == 'delete')
|
||||
print '<form name="newmenu" class="nocellnopadd" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
print '<input type="hidden" action="change_menu_handler">';
|
||||
print $langs->trans("MenuHandler").': ';
|
||||
print $formadmin->select_menu_families($menu_handler,'menu_handler',$dirmenu);
|
||||
print $formadmin->select_menu_families($menu_handler,'menu_handler',array_merge($dirstandard,$dirsmartphone));
|
||||
print ' <input type="submit" class="button" value="'.$langs->trans("Refresh").'">';
|
||||
print '</form>';
|
||||
|
||||
|
||||
@ -71,7 +71,6 @@ llxHeader('',$langs->trans("Setup"));
|
||||
|
||||
print_fiche_titre($langs->trans("Menus"),'','setup');
|
||||
|
||||
print "<br>\n";
|
||||
|
||||
$h = 0;
|
||||
|
||||
|
||||
@ -63,7 +63,8 @@ class Conf
|
||||
public $modules = array(); // List of modules
|
||||
public $css_modules = array();
|
||||
public $tabs_modules = array();
|
||||
public $triggers_modules = array('/core/triggers');
|
||||
public $triggers_modules = array('/core/triggers'); // TODO default triggers should not be into the module list
|
||||
public $menus_modules = array();
|
||||
public $hooks_modules = array();
|
||||
public $login_method_modules = array();
|
||||
|
||||
@ -149,6 +150,12 @@ class Conf
|
||||
$params=explode(':',$value,2);
|
||||
$this->tabs_modules[$params[0]][]=$value;
|
||||
}
|
||||
// If this is constant for a new tab page activated by a module
|
||||
elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)_MENUS/i',$key,$reg))
|
||||
{
|
||||
$modulename = strtolower($reg[1]);
|
||||
$this->menus_modules[] = '/'.$modulename.'/core/menus';
|
||||
}
|
||||
// If this is constant for triggers activated by a module
|
||||
elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)_TRIGGERS$/i',$key,$reg))
|
||||
{
|
||||
@ -175,18 +182,15 @@ class Conf
|
||||
elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)_SMS$/i',$key,$reg))
|
||||
{
|
||||
$module=strtolower($reg[1]);
|
||||
// Add this module in list of modules that provide SMS
|
||||
$this->sms_engine[$module]=$module;
|
||||
$this->sms_engine[$module]=$module; // Add this module in list of modules that provide SMS
|
||||
}
|
||||
// If this is a module constant
|
||||
elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)$/i',$key,$reg))
|
||||
{
|
||||
$module=strtolower($reg[1]);
|
||||
//print "Module ".$module." is enabled<br>\n";
|
||||
$this->$module=(object) array();
|
||||
$this->$module->enabled=true;
|
||||
// Add this module in list of enabled modules
|
||||
$this->modules[]=$module;
|
||||
$this->modules[]=$module; // Add this module in list of enabled modules
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,24 +128,27 @@ class FormAdmin
|
||||
*
|
||||
* @param string $selected Preselected menu value
|
||||
* @param string $htmlname Name of html select
|
||||
* @param string $dirmenu Directory to scan or array of directories to scan
|
||||
* @param array $dirmenuarray Array of directories to scan
|
||||
* @param string $moreattrib More attributes on html select tag
|
||||
* @return void
|
||||
*/
|
||||
function select_menu($selected, $htmlname, $dirmenu, $moreattrib='')
|
||||
function select_menu($selected, $htmlname, $dirmenuarray, $moreattrib='')
|
||||
{
|
||||
global $langs,$conf;
|
||||
|
||||
// Clean parameters
|
||||
if ($selected == 'eldy.php') $selected='eldy_backoffice.php'; // For compatibility
|
||||
|
||||
// Check parameters
|
||||
if (! is_array($dirmenuarray)) return -1;
|
||||
|
||||
$menuarray=array();
|
||||
foreach ($conf->file->dol_document_root as $dirroot)
|
||||
{
|
||||
if (is_array($dirmenu)) $dirmenus=$dirmenu;
|
||||
else $dirmenus=array($dirmenu);
|
||||
foreach($dirmenus as $dirtoscan)
|
||||
foreach($dirmenuarray as $dirtoscan)
|
||||
{
|
||||
$dir=$dirroot.$dirtoscan;
|
||||
//print $dir.'<br>';
|
||||
if (is_dir($dir))
|
||||
{
|
||||
$handle=opendir($dir);
|
||||
|
||||
@ -1130,17 +1130,26 @@ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $a
|
||||
/*
|
||||
* Top menu
|
||||
*/
|
||||
$top_menu=isset($conf->browser->phone)?$conf->smart_menu:$conf->top_menu;
|
||||
$top_menu=empty($conf->browser->phone)?$conf->top_menu:$conf->smart_menu;
|
||||
if (GETPOST('menu')) $top_menu=GETPOST('menu'); // menu=eldy_backoffice.php
|
||||
|
||||
// Load the top menu manager
|
||||
$result=dol_include_once("/core/menus/standard/".$top_menu);
|
||||
if (! $result) // If failed to include, we try with standard
|
||||
{
|
||||
$top_menu='eldy_backoffice.php';
|
||||
include_once(DOL_DOCUMENT_ROOT."/core/menus/standard/".$top_menu);
|
||||
}
|
||||
|
||||
// Load the top menu manager (only if not already done)
|
||||
if (! class_exists('MenuTop'))
|
||||
{
|
||||
$menufound=0;
|
||||
$dirmenus=array_merge(array("/core/menus"),$conf->menus_modules);
|
||||
foreach($dirmenus as $dirmenu)
|
||||
{
|
||||
$menufound=dol_include_once($dirmenu."/standard/".$top_menu);
|
||||
if ($menufound) break;
|
||||
}
|
||||
if (! $menufound) // If failed to include, we try with standard
|
||||
{
|
||||
$top_menu='eldy_backoffice.php';
|
||||
include_once(DOL_DOCUMENT_ROOT."/core/menus/standard/".$top_menu);
|
||||
}
|
||||
}
|
||||
|
||||
print "\n".'<!-- Start top horizontal menu '.$top_menu.' -->'."\n";
|
||||
|
||||
@ -1321,16 +1330,25 @@ function left_menu($menu_array_before, $helppagename='', $moresearchform='', $me
|
||||
$bookmarks=printBookmarksList($db, $langs);
|
||||
}
|
||||
|
||||
$left_menu=isset($conf->browser->phone)?$conf->smart_menu:$conf->top_menu;
|
||||
$left_menu=empty($conf->browser->phone)?$conf->top_menu:$conf->smart_menu;
|
||||
if (GETPOST('menu')) $left_menu=GETPOST('menu'); // menu=eldy_backoffice.php
|
||||
|
||||
// Load the left menu manager
|
||||
$result=dol_include_once("/core/menus/standard/".$left_menu);
|
||||
if (! $result) // If menu manager removed or not found
|
||||
{
|
||||
$left_menu='eldy_backoffice.php';
|
||||
include_once(DOL_DOCUMENT_ROOT ."/core/menus/standard/".$left_menu);
|
||||
}
|
||||
// Load the top menu manager (only if not already done)
|
||||
if (! class_exists('MenuLeft'))
|
||||
{
|
||||
$menufound=0;
|
||||
$dirmenus=array_merge(array("/core/menus"),$conf->menus_modules);
|
||||
foreach($dirmenus as $dirmenu)
|
||||
{
|
||||
$menufound=dol_include_once($dirmenu."/standard/".$left_menu);
|
||||
if ($menufound) break;
|
||||
}
|
||||
if (! $menufound) // If failed to include, we try with standard
|
||||
{
|
||||
$top_menu='eldy_backoffice.php';
|
||||
include_once(DOL_DOCUMENT_ROOT."/core/menus/standard/".$top_menu);
|
||||
}
|
||||
}
|
||||
|
||||
// Left column
|
||||
print '<!-- Begin left area - menu '.$left_menu.' -->'."\n";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user