$categstatic->ref = $val['label']; $categstatic->type = $type; $li = $categstatic->getNomUrl(1, '', 60); $desc = dol_htmlcleanlastbr($val['description']); $data[] = array('rowid' => $val['rowid'], 'fk_menu' => $val['fk_parent'], 'entry' => '<table class="nobordernopadding centpercent"><tr><td>' . $li . '</td><td width="50%">' . dolGetFirstLineOfText($desc) . '</td>' . '<td align="right" width="20px;"><a href="' . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $val['id'] . '&type=' . $type . '">' . img_view() . '</a></td>' . '</tr></table>'); } print '<table class="liste nohover" width="100%">'; print '<tr class="liste_titre"><td>' . $langs->trans("Categories") . '</td><td></td><td align="right">'; if (!empty($conf->use_javascript_ajax)) { print '<div id="iddivjstreecontrol"><a href="#">' . img_picto('', 'object_category') . ' ' . $langs->trans("UndoExpandAll") . '</a> | <a href="#">' . img_picto('', 'object_category-expanded') . ' ' . $langs->trans("ExpandAll") . '</a></div>'; } print '</td></tr>'; $nbofentries = count($data) - 1; if ($nbofentries > 0) { print '<tr ' . $bc[0] . '><td colspan="3">'; tree_recur($data, $data[0], 0); print '</td></tr>'; } else { print '<tr ' . $bc[0] . '>'; print '<td colspan="3"><table class="nobordernopadding"><tr class="nobordernopadding"><td>' . img_picto_common('', 'treemenu/branchbottom.gif') . '</td>'; print '<td valign="middle">'; print $langs->trans("NoCategoryYet"); print '</td>'; print '<td> </td>'; print '</table></td>'; print '</tr>'; } print "</table>"; print '</div>'; llxFooter(); $db->close();
$num = $db->num_rows($res); $i = 1; while ($menu = $db->fetch_array ($res)) { if (! empty($menu['langs'])) $langs->load($menu['langs']); $titre = $langs->trans($menu['titre']); $data[] = array($menu['rowid'],$menu['fk_menu'],$titre); $i++; } } // Appelle de la fonction recursive (ammorce) // avec recherche depuis la racine. // array($menu['rowid'],$menu['fk_menu'],$titre); tree_recur($data,0,0); print '</td>'; print '</tr>'; print '</table>'; print '</div>'; /* * Boutons actions */ print '<div class="tabsAction">';
/** * Recursive function to output menu tree * * @param array $tab Array of elements * @param int $pere Id of parent * @param int $rang Level of element * @return void */ function tree_recur($tab, $pere, $rang) { if ($pere == 0) { print '<ul class="arbre">'; } if ($rang > 10) { return; } // Protection contre boucle infinie //ballayage du tableau $sizeoftab = count($tab); for ($x = 0; $x < $sizeoftab; $x++) { // If an element has $pere for parent if ($tab[$x][1] == $pere) { // We shot it with an offset tree_showline($tab[$x], $rang); // And now we search all its sons of lower level tree_recur($tab, $tab[$x][0], $rang + 1); } } if ($pere == 0) { print '</ul>'; } }
/** * Recursive function to output menu tree. <ul id="iddivjstree"><li>...</li></ul> * Note: To have this function working, check you have loaded the js and css for treeview. * $arrayofjs=array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', * '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js'); * $arrayofcss=array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css'); * TODO Replace with jstree plugin instead of treeview plugin. * * @param array $tab Array of all elements * @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 * @return void */ function tree_recur($tab, $pere, $rang, $iddivjstree = 'iddivjstree') { if (empty($pere['rowid'])) { // Test also done with jstree and dynatree (not able to have <a> inside label) print '<script type="text/javascript" language="javascript"> $(document).ready(function(){ $("#' . $iddivjstree . '").treeview({ collapsed: true, animated: "fast", persist: "cookie", control: "#' . $iddivjstree . 'control", toggle: function() { /* window.console && console.log("%o was toggled", this); */ } }); }) </script>'; print '<ul id="' . $iddivjstree . '">'; } if ($rang > 10) { return; } // Protection contre boucle infinie //ballayage du tableau $sizeoftab = count($tab); $ulprinted = 0; for ($x = 0; $x < $sizeoftab; $x++) { //var_dump($tab[$x]);exit; // 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 "\n" . '<li ' . ($tab[$x]['statut'] ? ' class="liuseractive"' : 'class="liuserdisabled"') . '>'; print $tab[$x]['entry']; // 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 "\n" . '<li ' . ($tab[$x]['statut'] ? ' class="liuseractive"' : 'class="liuserdisabled"') . '>'; print $tab[$x]['entry']; // And now we search all its sons of lower level tree_recur($tab, $tab[$x], $rang + 1); print '</li>'; } } if (!empty($ulprinted) && !empty($pere['rowid'])) { print '</ul>' . "\n"; } if (empty($pere['rowid'])) { print '</ul>'; } }