Skip to content
Snippets Groups Projects
Commit ee420b79 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

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.
parent 0d277083
Branches
Tags
No related merge requests found
......@@ -113,6 +113,10 @@ function tree_showpad(&$fulltree,$key,$silent=0)
*/
function tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree')
{
global $tree_recur_alreadyadded;
if ($rang == 0) $tree_recur_alreadyadded=array();
if (empty($pere['rowid']))
{
// Test also done with jstree and dynatree (not able to have <a> inside label)
......@@ -144,19 +148,42 @@ function tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree')
// If an element has $pere for parent
if ($tab[$x]['fk_menu'] != -1 && $tab[$x]['fk_menu'] == $pere['rowid'])
{
if (empty($ulprinted) && ! empty($pere['rowid'])) { print '<ul'.(empty($pere['rowid'])?' id="treeData"':'').'>'; $ulprinted++; }
//print 'rang='.$rang.'-x='.$x." rowid=".$tab[$x]['rowid']." tab[x]['fk_leftmenu'] = ".$tab[$x]['fk_leftmenu']." leftmenu pere = ".$pere['leftmenu']."<br>\n";
if (empty($ulprinted) && ! empty($pere['rowid']))
{
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);
continue;
}
print '<ul'.(empty($pere['rowid'])?' id="treeData"':'').'>'; $ulprinted++;
}
print "\n".'<li '.($tab[$x]['statut']?' class="liuseractive"':'class="liuserdisabled"').'>';
print $tab[$x]['entry'];
$tree_recur_alreadyadded[$tab[$x]['rowid']]=$rang;
// And now we search all its sons of lower level
tree_recur($tab,$tab[$x],$rang+1);
print '</li>';
}
elseif (! empty($tab[$x]['rowid']) && $tab[$x]['fk_menu'] == -1 && $tab[$x]['fk_mainmenu'] == $pere['mainmenu'] && $tab[$x]['fk_leftmenu'] == $pere['leftmenu'])
{
if (empty($ulprinted) && ! empty($pere['rowid'])) { print '<ul'.(empty($pere['rowid'])?' id="treeData"':'').'>'; $ulprinted++; }
//print 'rang='.$rang.'-x='.$x." rowid=".$tab[$x]['rowid']." tab[x]['fk_leftmenu'] = ".$tab[$x]['fk_leftmenu']." leftmenu pere = ".$pere['leftmenu']."<br>\n";
if (empty($ulprinted) && ! empty($pere['rowid']))
{
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);
continue;
}
print '<ul'.(empty($pere['rowid'])?' id="treeData"':'').'>'; $ulprinted++;
}
print "\n".'<li '.($tab[$x]['statut']?' class="liuseractive"':'class="liuserdisabled"').'>';
print $tab[$x]['entry'];
$tree_recur_alreadyadded[$tab[$x]['rowid']]=$rang;
// 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";
tree_recur($tab,$tab[$x],$rang+1);
print '</li>';
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment