FIX Infinite loop on menu tree output for edition
FIX Can show tree of entries added by external modules using fk_mainmenu and fk_leftmenu instead of fk_menu.
This commit is contained in:
parent
ee420b79b1
commit
bf5fbd3a80
@ -289,17 +289,18 @@ if ($conf->use_javascript_ajax)
|
||||
- la chaine a afficher
|
||||
ie: data[]= array (index, index parent, chaine )
|
||||
*/
|
||||
|
||||
//il faut d'abord declarer un element racine de l'arbre
|
||||
|
||||
$data[] = array('rowid'=>0,'fk_menu'=>-1,'title'=>"racine",'mainmenu'=>'','leftmenu'=>'','fk_mainmenu'=>'','fk_leftmenu'=>'');
|
||||
|
||||
$data[] = array('rowid'=>0,'fk_menu'=>-1,'title'=>"racine",'mainmenu'=>'','leftmenu'=>'','fk_mainmenu'=>'','fk_leftmenu'=>'');
|
||||
|
||||
//puis tous les elements enfants
|
||||
|
||||
$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, m.module";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."menu as m";
|
||||
$sql.= " WHERE menu_handler = '".$menu_handler_to_search."'";
|
||||
$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)
|
||||
|
||||
$res = $db->query($sql);
|
||||
@ -314,9 +315,10 @@ if ($conf->use_javascript_ajax)
|
||||
$titre = $langs->trans($menu['titre']);
|
||||
$data[] = array(
|
||||
'rowid'=>$menu['rowid'],
|
||||
'module'=>$menu['module'],
|
||||
'fk_menu'=>$menu['fk_menu'],
|
||||
'title'=>$titre,
|
||||
'mainmenu'=>$menu['mainmenu'],
|
||||
'mainmenu'=>$menu['mainmenu'],
|
||||
'leftmenu'=>$menu['leftmenu'],
|
||||
'fk_mainmenu'=>$menu['fk_mainmenu'],
|
||||
'fk_leftmenu'=>$menu['fk_leftmenu'],
|
||||
@ -334,17 +336,54 @@ if ($conf->use_javascript_ajax)
|
||||
}
|
||||
}
|
||||
|
||||
global $tree_recur_alreadyadded; // This var was def into tree_recur
|
||||
|
||||
// Appelle de la fonction recursive (ammorce)
|
||||
// avec recherche depuis la racine.
|
||||
//var_dump($data);
|
||||
tree_recur($data,$data[0],0);
|
||||
tree_recur($data, $data[0], 0, 'iddivjstree'); // $data[0] is virtual record 'racine'
|
||||
|
||||
|
||||
print '</td>';
|
||||
|
||||
|
||||
print '</tr>';
|
||||
|
||||
|
||||
print '</table>';
|
||||
|
||||
|
||||
|
||||
// Process remaining records (records that are not linked to root by any path)
|
||||
$remainingdata = array();
|
||||
foreach($data as $datar)
|
||||
{
|
||||
if (empty($datar['rowid']) || $tree_recur_alreadyadded[$datar['rowid']]) continue;
|
||||
$remainingdata[] = $datar;
|
||||
}
|
||||
|
||||
if (count($remainingdata))
|
||||
{
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("NotTopTreeMenuPersonalized").'</td>';
|
||||
print '<td align="right"></td>';
|
||||
print '</tr>';
|
||||
|
||||
print '<tr>';
|
||||
print '<td colspan="2">';
|
||||
|
||||
foreach($remainingdata as $datar)
|
||||
{
|
||||
$father = array('rowid'=>$datar['rowid'],'title'=>"???",'mainmenu'=>$datar['fk_mainmenu'],'leftmenu'=>$datar['fk_leftmenu'],'fk_mainmenu'=>'','fk_leftmenu'=>'');
|
||||
//print 'Start with rowid='.$datar['rowid'].' mainmenu='.$father ['mainmenu'].' leftmenu='.$father ['leftmenu'].'<br>'."\n";
|
||||
tree_recur($data, $father, 0, 'iddivjstree'.$datar['rowid'], 1, 1);
|
||||
}
|
||||
|
||||
print '</td>';
|
||||
|
||||
print '</tr>';
|
||||
|
||||
print '</table>';
|
||||
}
|
||||
|
||||
print '</div>';
|
||||
|
||||
|
||||
@ -109,15 +109,17 @@ function tree_showpad(&$fulltree,$key,$silent=0)
|
||||
* @param int $pere Array with parent ids ('rowid'=>,'mainmenu'=>,'leftmenu'=>,'fk_mainmenu=>,'fk_leftmenu=>)
|
||||
* @param int $rang Level of element
|
||||
* @param string $iddivjstree Id to use for parent ul element
|
||||
* @param int $donoresetalreadyloaded Do not reset global array $donoresetalreadyloaded used to avoid to go down on an aleady processed record
|
||||
* @param int $showfk Show fk links to parent into label
|
||||
* @return void
|
||||
*/
|
||||
function tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree')
|
||||
function tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree', $donoresetalreadyloaded=0, $showfk=0)
|
||||
{
|
||||
global $tree_recur_alreadyadded;
|
||||
|
||||
if ($rang == 0) $tree_recur_alreadyadded=array();
|
||||
if ($rang == 0 && empty($donoresetalreadyloaded)) $tree_recur_alreadyadded=array();
|
||||
|
||||
if (empty($pere['rowid']))
|
||||
if ($rang == 0)
|
||||
{
|
||||
// Test also done with jstree and dynatree (not able to have <a> inside label)
|
||||
print '<script type="text/javascript" language="javascript">
|
||||
@ -161,7 +163,9 @@ function tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree')
|
||||
}
|
||||
print "\n".'<li '.($tab[$x]['statut']?' class="liuseractive"':'class="liuserdisabled"').'>';
|
||||
print $tab[$x]['entry'];
|
||||
$tree_recur_alreadyadded[$tab[$x]['rowid']]=$rang;
|
||||
if ($showfk) print ' (fk_mainmenu='.$tab[$x]['fk_mainmenu'].' fk_leftmenu='.$tab[$x]['fk_leftmenu'].')';
|
||||
//print ' -> A '.$tab[$x]['rowid'].' mainmenu='.$tab[$x]['mainmenu'].' leftmenu='.$tab[$x]['leftmenu'].' fk_mainmenu='.$tab[$x]['fk_mainmenu'].' fk_leftmenu='.$tab[$x]['fk_leftmenu'].'<br>'."\n";
|
||||
$tree_recur_alreadyadded[$tab[$x]['rowid']]=($rang + 1);
|
||||
// And now we search all its sons of lower level
|
||||
tree_recur($tab,$tab[$x],$rang+1);
|
||||
print '</li>';
|
||||
@ -173,7 +177,8 @@ function tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree')
|
||||
{
|
||||
if (! empty($tree_recur_alreadyadded[$tab[$x]['rowid']]))
|
||||
{
|
||||
dol_syslog('Error, record with id '.$tab[$x]['rowid'].' seems to be a child of record with id '.$pere['rowid'].' but it was already output. Complete field "leftmenu" and "mainmenu" on ALL records to avoid ambiguity.', LOG_WARNING);
|
||||
dol_syslog('Error, record with id '.$tab[$x]['rowid'].' seems to be a child of record with id '.$pere['rowid'].' but it was already output. Complete field "leftmenu" and "mainmenu" on ALL records to avoid ambiguity.', LOG_WARNING);
|
||||
//print 'Error, record with id '.$tab[$x]['rowid'].' seems to be a child of record with id '.$pere['rowid'].' but it was already output. Complete field "leftmenu" and "mainmenu" on ALL records to avoid ambiguity.';
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -181,15 +186,17 @@ function tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree')
|
||||
}
|
||||
print "\n".'<li '.($tab[$x]['statut']?' class="liuseractive"':'class="liuserdisabled"').'>';
|
||||
print $tab[$x]['entry'];
|
||||
$tree_recur_alreadyadded[$tab[$x]['rowid']]=$rang;
|
||||
if ($showfk) print ' (fk_mainmenu='.$tab[$x]['fk_mainmenu'].' fk_leftmenu='.$tab[$x]['fk_leftmenu'].')';
|
||||
//print ' -> B '.$tab[$x]['rowid'].' mainmenu='.$tab[$x]['mainmenu'].' leftmenu='.$tab[$x]['leftmenu'].' fk_mainmenu='.$tab[$x]['fk_mainmenu'].' fk_leftmenu='.$tab[$x]['fk_leftmenu'].'<br>'."\n";
|
||||
$tree_recur_alreadyadded[$tab[$x]['rowid']]=($rang + 1);
|
||||
// And now we search all its sons of lower level
|
||||
//print 'Appel de tree_recur pour x='.$x.' rowid='.$tab[$x]['rowid']." fk_mainmenu pere = ".$tab[$x]['fk_mainmenu']." fk_leftmenu pere = ".$tab[$x]['fk_leftmenu']."<br>\n";
|
||||
//print 'Call tree_recur for x='.$x.' rowid='.$tab[$x]['rowid']." fk_mainmenu pere = ".$tab[$x]['fk_mainmenu']." fk_leftmenu pere = ".$tab[$x]['fk_leftmenu']."<br>\n";
|
||||
tree_recur($tab,$tab[$x],$rang+1);
|
||||
print '</li>';
|
||||
}
|
||||
}
|
||||
if (! empty($ulprinted) && ! empty($pere['rowid'])) { print '</ul>'."\n"; }
|
||||
|
||||
if (empty($pere['rowid'])) print '</ul>';
|
||||
if ($rang == 0) print '</ul>';
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user