New: An external module can add its own menu manager

This commit is contained in:
Laurent Destailleur
2011-01-23 15:08:21 +00:00
parent 6e77cede0e
commit 24ffac6bb6
7 changed files with 70 additions and 56 deletions

View File

@@ -1,5 +1,11 @@
English Dolibarr ChangeLog English Dolibarr ChangeLog
***** ChangeLog for 3.1 compared to 3.0 *****
For developers:
- New: External modules can add their menu manager
***** ChangeLog for 3.0 compared to 2.9 ***** ***** ChangeLog for 3.0 compared to 2.9 *****
For users: For users:

View File

@@ -40,9 +40,9 @@ $langs->load("other");
// Security check // Security check
if (!$user->admin) accessforbidden(); if (!$user->admin) accessforbidden();
$dirtop = "../includes/menus/standard"; $dirtop = "/includes/menus/standard";
$dirleft = "../includes/menus/standard"; $dirleft = "/includes/menus/standard";
$dirsmartphone = "../includes/menus/smartphone"; $dirsmartphone = "/includes/menus/smartphone";
// Cette page peut etre longue. On augmente le delai autorise. // Cette page peut etre longue. On augmente le delai autorise.
@@ -78,13 +78,14 @@ if (isset($_POST["action"]) && $_POST["action"] == 'update' && empty($_POST["can
// Initialize menu handlers // Initialize menu handlers
foreach ($listofmenuhandler as $key => $val) foreach ($listofmenuhandler as $key => $val)
{ {
$dir = DOL_DOCUMENT_ROOT."/includes/menus/";
// Load sql init_menu_handler.sql file // Load sql init_menu_handler.sql file
$dir = "/includes/menus/";
$file='init_menu_'.$key.'.sql'; $file='init_menu_'.$key.'.sql';
if (file_exists($dir.$file)) $fullpath=dol_buildpath($dir.$file);
if (file_exists($fullpath))
{ {
$result=run_sql($dir.$file,1,'',1,$key); $result=run_sql($fullpath,1,'',1,$key);
} }
} }

View File

@@ -35,9 +35,9 @@ $langs->load("admin");
if (! $user->admin) if (! $user->admin)
accessforbidden(); accessforbidden();
$dirtop = "../../includes/menus/standard"; $dirtop = "/includes/menus/standard";
$dirleft = "../../includes/menus/standard"; $dirleft = "/includes/menus/standard";
$dirsmartphone = "../../includes/menus/smartphone"; $dirsmartphone = "/includes/menus/smartphone";
$dirmenu = array($dirleft,$dirsmartphone); $dirmenu = array($dirleft,$dirsmartphone);

View File

@@ -35,9 +35,9 @@ $langs->load("admin");
if (! $user->admin) if (! $user->admin)
accessforbidden(); accessforbidden();
$dirtop = "../../includes/menus/standard"; $dirtop = "/includes/menus/standard";
$dirleft = "../../includes/menus/standard"; $dirleft = "/includes/menus/standard";
$dirsmartphone = "../../includes/menus/smartphone"; $dirsmartphone = "/includes/menus/smartphone";
$dirmenu = array($dirleft,$dirsmartphone); $dirmenu = array($dirleft,$dirsmartphone);

View File

@@ -134,12 +134,15 @@ class FormAdmin
if ($selected == 'eldy.php') $selected='eldy_backoffice.php'; // For compatibility if ($selected == 'eldy.php') $selected='eldy_backoffice.php'; // For compatibility
$menuarray=array(); $menuarray=array();
$handle=opendir($dirmenu); foreach ($conf->file->dol_document_root as $dirroot)
{
$dir=$dirroot.$dirmenu;
$handle=opendir($dir);
if (is_resource($handle)) if (is_resource($handle))
{ {
while (($file = readdir($handle))!==false) while (($file = readdir($handle))!==false)
{ {
if (is_file($dirmenu."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
{ {
if (preg_match('/lib\.php$/i',$file)) continue; // We exclude library files if (preg_match('/lib\.php$/i',$file)) continue; // We exclude library files
$filelib=preg_replace('/\.php$/i','',$file); $filelib=preg_replace('/\.php$/i','',$file);
@@ -158,6 +161,7 @@ class FormAdmin
} }
} }
closedir($handle); closedir($handle);
}
} }
ksort($menuarray); ksort($menuarray);
@@ -199,12 +203,15 @@ class FormAdmin
foreach($dirmenuarray as $dirmenu) foreach($dirmenuarray as $dirmenu)
{ {
$handle=opendir($dirmenu); foreach ($conf->file->dol_document_root as $dirroot)
{
$dir=$dirroot.$dirmenu;
$handle=opendir($dir);
if (is_resource($handle)) if (is_resource($handle))
{ {
while (($file = readdir($handle))!==false) while (($file = readdir($handle))!==false)
{ {
if (is_file($dirmenu."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
{ {
$filelib=preg_replace('/(_backoffice|_frontoffice)?\.php$/i','',$file); $filelib=preg_replace('/(_backoffice|_frontoffice)?\.php$/i','',$file);
if (preg_match('/^default/i',$filelib)) continue; if (preg_match('/^default/i',$filelib)) continue;
@@ -218,6 +225,7 @@ class FormAdmin
} }
closedir($handle); closedir($handle);
} }
}
} }
ksort($menuarray); ksort($menuarray);

View File

@@ -87,7 +87,7 @@ function dol_getprefix()
function dol_include_once($relpath) function dol_include_once($relpath)
{ {
global $conf,$langs,$user,$mysoc; // Other global var must be retreived with $GLOBALS['var'] global $conf,$langs,$user,$mysoc; // Other global var must be retreived with $GLOBALS['var']
return include_once(dol_buildpath($relpath)); return @include_once(dol_buildpath($relpath));
} }

View File

@@ -951,7 +951,6 @@ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $a
if (! $conf->top_menu) $conf->top_menu ='eldy_backoffice.php'; if (! $conf->top_menu) $conf->top_menu ='eldy_backoffice.php';
// For backward compatibility with old modules // For backward compatibility with old modules
if (empty($conf->headerdone)) top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); if (empty($conf->headerdone)) top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
@@ -1051,7 +1050,7 @@ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $a
if (GETPOST('menu')) $top_menu=GETPOST('menu'); // menu=eldy_backoffice.php if (GETPOST('menu')) $top_menu=GETPOST('menu'); // menu=eldy_backoffice.php
// Load the top menu manager // Load the top menu manager
$result=@include_once(DOL_DOCUMENT_ROOT ."/includes/menus/standard/".$top_menu); $result=dol_include_once("/includes/menus/standard/".$top_menu);
if (! $result) // If failed to include, we try with standard if (! $result) // If failed to include, we try with standard
{ {
$top_menu='eldy_backoffice.php'; $top_menu='eldy_backoffice.php';
@@ -1243,7 +1242,7 @@ function left_menu($menu_array_before, $helppagename='', $moresearchform='', $me
if (GETPOST('menu')) $left_menu=GETPOST('menu'); // menu=eldy_backoffice.php if (GETPOST('menu')) $left_menu=GETPOST('menu'); // menu=eldy_backoffice.php
// Load the left menu manager // Load the left menu manager
$result=@include_once(DOL_DOCUMENT_ROOT ."/includes/menus/standard/".$left_menu); $result=dol_include_once("/includes/menus/standard/".$left_menu);
if (! $result) // If menu manager removed or not found if (! $result) // If menu manager removed or not found
{ {
$left_menu='eldy_backoffice.php'; $left_menu='eldy_backoffice.php';