2
0
forked from Wavyzz/dolibarr

Qual: Some change to prepare speed enhancement in menu management.

This commit is contained in:
Laurent Destailleur
2011-02-16 22:46:01 +00:00
parent e7b4d34bc9
commit cb7534d4aa
5 changed files with 109 additions and 70 deletions

View File

@@ -353,16 +353,18 @@ class Menubase
/** /**
* Complete this->newmenu with menu entry found in $tab * Complete this->newmenu with menu entry found in $tab
* *
* @param string $tab * @param $tab
* @param string $pere * @param $pere
* @param string $rang * @param $rang
* @param $myleftmenu Value for left that defined leftmenu
*/ */
function recur($tab, $pere, $rang) function recur($tab, $pere, $rang, $myleftmenu)
{ {
global $leftmenu; // To be exported in dol_eval function global $leftmenu; // To be exported in dol_eval function
//print "xx".$pere; //print "xx".$pere;
$leftmenu = $this->leftmenu; $leftmenu = $myleftmenu;
//ballayage du tableau //ballayage du tableau
for ($x = 0; $x < count($tab); $x++) for ($x = 0; $x < count($tab); $x++)
{ {
@@ -382,7 +384,7 @@ class Menubase
//print 'name='.$tab[$x][3].' pere='.$pere." ".$tab[$x][6]; //print 'name='.$tab[$x][3].' pere='.$pere." ".$tab[$x][6];
$this->newmenu->add((! preg_match("/^(http:\/\/|https:\/\/)/i",$tab[$x][2])) ? $tab[$x][2] : $tab[$x][2], $tab[$x][3], $rang -1, $tab[$x][4], $tab[$x][5], $tab[$x][8]); $this->newmenu->add((! preg_match("/^(http:\/\/|https:\/\/)/i",$tab[$x][2])) ? $tab[$x][2] : $tab[$x][2], $tab[$x][3], $rang -1, $tab[$x][4], $tab[$x][5], $tab[$x][8]);
$this->recur($tab, $tab[$x][0], $rang +1); $this->recur($tab, $tab[$x][0], $rang +1, $lelfmenu);
} }
} }
} }
@@ -432,21 +434,35 @@ class Menubase
* @return array Return array with menu entries for top menu * @return array Return array with menu entries for top menu
* TODO Mutualize menuTopCharger and menuLeftCharger * TODO Mutualize menuTopCharger and menuLeftCharger
*/ */
function menuTopCharger($type_user, $mainmenu, $menu_handler) function menuTopCharger($mainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu=array())
{ {
global $langs, $user, $conf; global $langs, $user, $conf;
global $rights; // To export to dol_eval function global $leftmenu,$rights; // To export to dol_eval function
// Load datas into tabMenu
/*if (sizeof($tabMenu) == 0)
{
$this->menuLoad($leftmenu, $type_user, $menu_handler, $tabMenu);
//var_dump($tabMenu);
}
else
{
// TODO Just try to find menutopid from tabMenu and mainmenu
$this->menuLoad($leftmenu, $type_user, $menu_handler, $tabMenu);
}*/
$tabMenu=array(); $tabMenu=array();
$sql = "SELECT m.rowid, m.mainmenu, m.titre, m.url, m.langs, m.perms, m.enabled, m.target"; $sql = "SELECT m.rowid, m.mainmenu, m.titre, m.url, m.langs, m.perms, m.enabled, m.target";
$sql.= " FROM ".MAIN_DB_PREFIX."menu as m"; $sql.= " FROM ".MAIN_DB_PREFIX."menu as m";
$sql.= " WHERE m.type = 'top'"; $sql.= " WHERE m.entity = ".$conf->entity;
$sql.= " AND m.entity = ".$conf->entity;
$sql.= " AND m.menu_handler in('".$menu_handler."','all')"; $sql.= " AND m.menu_handler in('".$menu_handler."','all')";
if ($type_user == 0) $sql.= " AND m.usertype in (0,2)"; if ($type_user == 0) $sql.= " AND m.usertype in (0,2)";
if ($type_user == 1) $sql.= " AND m.usertype in (1,2)"; if ($type_user == 1) $sql.= " AND m.usertype in (1,2)";
// If type_user == 2, no test requires // If type_user == 2, no test requires
$sql.= " AND m.type = 'top'";
$sql.= " ORDER BY m.position"; $sql.= " ORDER BY m.position";
dol_syslog("Menubase::menuTopCharger sql=".$sql); dol_syslog("Menubase::menuTopCharger sql=".$sql);
@@ -502,9 +518,6 @@ class Menubase
$enabled = verifCond($objm->enabled); $enabled = verifCond($objm->enabled);
} }
if ($objm->rowid != $oldrowid && $oldrowid) $b++; // Break on new entry
$oldrowid=$objm->rowid;
$tabMenu[$b]['rowid'] = $objm->rowid; $tabMenu[$b]['rowid'] = $objm->rowid;
$tabMenu[$b]['mainmenu'] = $objm->mainmenu; $tabMenu[$b]['mainmenu'] = $objm->mainmenu;
$tabMenu[$b]['titre'] = $chaine; // Title $tabMenu[$b]['titre'] = $chaine; // Title
@@ -517,7 +530,8 @@ class Menubase
$tabMenu[$b]['lang'] = $objm->langs; $tabMenu[$b]['lang'] = $objm->langs;
//var_dump($tabMenu); //var_dump($tabMenu);
$a++; $b++;
$a++;
} }
$this->db->free($resql); $this->db->free($resql);
} }
@@ -532,29 +546,72 @@ class Menubase
/** /**
* Load entries found in database in a menu array * Load entries found in database in a menu array
* @param $newmenu Menu array to complete * @param $newmenu Menu array to complete
* @param $mainmenu Value for mainmenu that defined top menu * @param $mainmenu Value for mainmenu that defined top menu of left menu
* @param $myleftmenu Value that defined leftmenu
* @param $type_user 0=Internal,1=External,2=All
* @param $menu_handler Name of menu_handler used (auguria, eldy...)
* @param $tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty)
* @return array Menu array for particular mainmenu value or full tabArray
*/
function menuLeftCharger($newmenu, $mainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu=array())
{
global $langs, $user, $conf; // To export to dol_eval function
global $leftmenu,$rights; // To export to dol_eval function
$leftmenu=$myleftmenu; // To export to dol_eval function
$this->newmenu = $newmenu;
// Load datas into tabMenu
if (sizeof($tabMenu) == 0)
{
$this->menuLoad($leftmenu, $type_user, $menu_handler, $tabMenu);
//var_dump($tabMenu);
}
else
{
// TODO Just try to find menutopid from tabMenu and mainmenu
$this->menuLoad($leftmenu, $type_user, $menu_handler, $tabMenu);
}
// Define menutopid
$menutopid='';
foreach($tabMenu as $val)
{
if ($val[9] == 'top' && $val[8] == $mainmenu)
{
$menutopid=$val[0];
break;
}
}
// Now edit this->newmenu to add entries found into tabMenu that are in childs of mainmenu claimed
$this->recur($tabMenu, $menutopid, 1, $leftmenu);
return $this->newmenu;
}
/**
* Load entries found in database in a menu array
* @param $myleftmenu Value for left that defined leftmenu * @param $myleftmenu Value for left that defined leftmenu
* @param $type_user 0=Internal,1=External,2=All * @param $type_user 0=Internal,1=External,2=All
* @param $menu_handler Name of menu_handler used (auguria, eldy...) * @param $menu_handler Name of menu_handler used (auguria, eldy...)
* @return array Menu array completed * @param $tabMenu If array with menu entries already load, we put this array here (in most cases, it's empty)
* @return int >0 if OK, <0 if KO
*/ */
function menuLeftCharger($newmenu, $mainmenu, $myleftmenu, $type_user, $menu_handler) function menuLoad($myleftmenu, $type_user, $menu_handler, &$tabMenu=array())
{ {
global $langs, $user, $conf, $leftmenu; // To export to dol_eval function global $langs, $user, $conf; // To export to dol_eval function
global $rights; // To export to dol_eval function global $leftmenu, $rights; // To export to dol_eval function
$menutopid=''; $menutopid=0;
$leftmenu=$myleftmenu; $leftmenu=$myleftmenu; // To export to dol_eval function
$this->newmenu = $newmenu;
$this->leftmenu = $leftmenu;
$tabMenu = array ();
$sql = "SELECT m.rowid, m.type, m.fk_menu, m.url, m.titre, m.langs, m.perms, m.enabled, m.target, m.mainmenu, m.leftmenu"; $sql = "SELECT m.rowid, m.type, m.fk_menu, m.url, m.titre, m.langs, m.perms, m.enabled, m.target, m.mainmenu, m.leftmenu";
$sql.= " FROM ".MAIN_DB_PREFIX."menu as m"; $sql.= " FROM ".MAIN_DB_PREFIX."menu as m";
$sql.= " WHERE m.menu_handler in('".$menu_handler."','all')"; $sql.= " WHERE m.entity = ".$conf->entity;
$sql.= " AND m.entity = ".$conf->entity; $sql.= " AND m.menu_handler in('".$menu_handler."','all')";
if ($type_user == 0) $sql.= " AND m.usertype in (0,2)"; if ($type_user == 0) $sql.= " AND m.usertype in (0,2)";
if ($type_user == 1) $sql.= " AND m.usertype in (1,2)"; if ($type_user == 1) $sql.= " AND m.usertype in (1,2)";
// If type_user == 2, no test required // If type_user == 2, no test required
@@ -574,9 +631,6 @@ class Menubase
//$objm = $this->db->fetch_object($resql); //$objm = $this->db->fetch_object($resql);
$menu = $this->db->fetch_array($resql); $menu = $this->db->fetch_array($resql);
// Detect if it's top menu line
if ($menu['type'] == 'top' && $menu['mainmenu'] == $mainmenu) $menutopid=$menu['rowid'];
// Define $chaine // Define $chaine
$chaine=""; $chaine="";
$title = $langs->trans($menu['titre']); $title = $langs->trans($menu['titre']);
@@ -588,10 +642,10 @@ class Menubase
} }
if (preg_match("/\//",$menu['titre'])) // To manage translation when title is string1/string2 if (preg_match("/\//",$menu['titre'])) // To manage translation when title is string1/string2
{ {
$tab_titre = explode("/",$menu['titre']); $tab_titre = explode("/",$menu['titre']);
$chaine = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]); $chaine = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]);
} }
else else
{ {
$chaine = $langs->trans($menu['titre']); $chaine = $langs->trans($menu['titre']);
@@ -614,14 +668,12 @@ class Menubase
$enabled = true; $enabled = true;
if ($menu['enabled']) if ($menu['enabled'])
{ {
$enabled = verifCond($menu['enabled']); $enabled = verifCond($menu['enabled']);
if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_ACCORDION && preg_match('/^\$leftmenu/',$menu['enabled'])) $enabled=1; if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_ACCORDION && preg_match('/^\$leftmenu/',$menu['enabled'])) $enabled=1;
//print "verifCond chaine=".$chaine." rowid=".$menu['rowid']." ".$menu['enabled'].":".$enabled."<br>\n"; //print "verifCond chaine=".$chaine." rowid=".$menu['rowid']." ".$menu['enabled'].":".$enabled."<br>\n";
} }
if ($menu['rowid'] != $oldrowid && $oldrowid) $b++; // Break on new entry // 0=rowid, 1=fk_menu, 2=url, 3=text, 4=perms, 5=target, 8=mainmenu
$oldrowid=$menu['rowid'];
$tabMenu[$b][0] = $menu['rowid']; $tabMenu[$b][0] = $menu['rowid'];
$tabMenu[$b][1] = $menu['fk_menu']; $tabMenu[$b][1] = $menu['fk_menu'];
$tabMenu[$b][2] = $menu['url']; $tabMenu[$b][2] = $menu['url'];
@@ -638,39 +690,19 @@ class Menubase
if (! isset($tabMenu[$b][7])) $tabMenu[$b][7] = $enabled; if (! isset($tabMenu[$b][7])) $tabMenu[$b][7] = $enabled;
else $tabMenu[$b][7] = ($tabMenu[$b][7] && $enabled); else $tabMenu[$b][7] = ($tabMenu[$b][7] && $enabled);
$tabMenu[$b][8] = $menu['mainmenu']; $tabMenu[$b][8] = $menu['mainmenu'];
$tabMenu[$b][9] = $menu['type'];
$b++;
$a++; $a++;
} }
$this->db->free($resql); $this->db->free($resql);
return 1;
} }
else else
{ {
dol_print_error($this->db); dol_print_error($this->db);
return -1;
} }
// Get menutopid
/*$sql = "SELECT m.rowid, m.titre, m.type";
$sql.= " FROM " . MAIN_DB_PREFIX . "menu as m";
$sql.= " WHERE m.mainmenu = '".$mainmenu."'";
$sql.= " AND m.menu_handler in('".$menu_handler."','all')";
$sql.= " AND m.entity = ".$conf->entity;
if ($type_user == 0) $sql.= " AND m.usertype in (0,2)";
if ($type_user == 1) $sql.= " AND m.usertype in (1,2)";
$sql.= " AND type = 'top'";
dol_syslog("Menubase::menuLeftCharger sql=".$sql);
// It should have only one response
$resql = $this->db->query($sql);
$menutop = $this->db->fetch_object($resql);
if ($menutop) $menutopid=$menutop->rowid;
$this->db->free($resql);
//print "menutopid=".$menutopid." sql=".$sql;
*/
// Now edit this->newmenu to add entries in tabMenu that are in childs
$this->recur($tabMenu, $menutopid, 1);
return $this->newmenu;
} }
} }

View File

@@ -42,9 +42,15 @@ function print_smartphone_menu($db,$atarget,$type_user)
$menutop = new Menubase($db,'smartphone','top'); $menutop = new Menubase($db,'smartphone','top');
$menuleft = new Menubase($db,'smartphone','left'); $menuleft = new Menubase($db,'smartphone','left');
$tabMenu = $menutop->menuTopCharger($type_user, '', 'smartphone'); $tabMenu = $menutop->menuTopCharger('', '', $type_user, 'smartphone');
$numTabMenu = count($tabMenu); $numTabMenu = count($tabMenu);
/*$newmenu = new Menu();
$leftmenu = $menuleft->menuLeftCharger($newmenu,'','',($user->societe_id?1:0),'smartphone');
$menus = $leftmenu->liste;
var_dump($menus);
*/
print_start_menu_array(); print_start_menu_array();
for($i=0; $i<$numTabMenu; $i++) for($i=0; $i<$numTabMenu; $i++)
{ {

View File

@@ -45,7 +45,7 @@ function print_auguria_menu($db,$atarget,$type_user)
$_SESSION["leftmenuopened"]=""; $_SESSION["leftmenuopened"]="";
$menuArbo = new Menubase($db,'auguria','top'); $menuArbo = new Menubase($db,'auguria','top');
$tabMenu = $menuArbo->menuTopCharger($type_user,$_SESSION['mainmenu'], 'auguria'); $tabMenu = $menuArbo->menuTopCharger($_SESSION['mainmenu'], '', $type_user, 'auguria');
print_start_menu_array_auguria(); print_start_menu_array_auguria();
@@ -276,7 +276,7 @@ function print_left_auguria_menu($db,$menu_array_before,$menu_array_after)
// Add mainmenu in GET url. This make to go back on correct menu even when using Back on browser. // Add mainmenu in GET url. This make to go back on correct menu even when using Back on browser.
$url=dol_buildpath($menu_array[$i]['url'],1); $url=dol_buildpath($menu_array[$i]['url'],1);
if (! preg_match('/mainmenu=/i',$menu_array[$i]['url'])) if (! preg_match('/mainmenu=/i',$menu_array[$i]['url']))
{ {
if (! preg_match('/\?/',$url)) $url.='?'; if (! preg_match('/\?/',$url)) $url.='?';

View File

@@ -436,7 +436,7 @@ function print_eldy_menu($db,$atarget,$type_user)
$menuArbo = new Menubase($db,'eldy','top'); $menuArbo = new Menubase($db,'eldy','top');
$tabMenu = $menuArbo->menuTopCharger($type_user,$_SESSION['mainmenu'],'eldy'); $tabMenu = $menuArbo->menuTopCharger($_SESSION['mainmenu'],'',$type_user,'eldy');
for($i=0; $i<count($tabMenu); $i++) for($i=0; $i<count($tabMenu); $i++)
{ {

View File

@@ -3652,7 +3652,8 @@ function verifCond($strRights)
} }
/** /**
* Replace eval function to add more security * Replace eval function to add more security.
* This function is called by verifCond().
* *
* @param string $s * @param string $s
* @return int 1 * @return int 1