dolibarr  7.0.0-beta
treeview.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
3  * Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
26 // ------------------------------- Used by ajax tree view -----------------
27 
36 function tree_showpad(&$fulltree,$key,$silent=0)
37 {
38  $pos=1;
39 
40  // Loop on each pos, because we will output an img for each pos
41  while ($pos <= $fulltree[$key]['level'] && $fulltree[$key]['level'] > 0)
42  {
43  // Process for column $pos
44 
45  $atleastoneofthislevelafter=0;
46  $nbofdirinsub=0;
47  $nbofdocinsub=0;
48  $found=0;
49  //print 'x'.$key;
50  foreach($fulltree as $key2 => $val2)
51  {
52  //print "x".$pos." ".$key2." ".$found." ".$fulltree[$key2]['level'];
53  if ($found == 1) // We are after the entry to show
54  {
55  if ($fulltree[$key2]['level'] > $pos)
56  {
57  $nbofdirinsub++;
58  if (isset($fulltree[$key2]['cachenbofdoc']) && $fulltree[$key2]['cachenbofdoc'] > 0) $nbofdocinsub+=$fulltree[$key2]['cachenbofdoc'];
59  }
60  if ($fulltree[$key2]['level'] == $pos)
61  {
62  $atleastoneofthislevelafter=1;
63  }
64  if ($fulltree[$key2]['level'] <= $pos)
65  {
66  break;
67  }
68  }
69  if ($key2 == $key) // We found ourself, so now every lower level will be counted
70  {
71  $found=1;
72  }
73  }
74  //print $atleastoneofthislevelafter;
75 
76  if (! $silent)
77  {
78  if ($atleastoneofthislevelafter)
79  {
80  if ($fulltree[$key]['level'] == $pos) print img_picto_common('','treemenu/branch.gif');
81  else print img_picto_common('','treemenu/line.gif');
82  }
83  else
84  {
85  if ($fulltree[$key]['level'] == $pos) print img_picto_common('','treemenu/branchbottom.gif');
86  else print img_picto_common('','treemenu/linebottom.gif');
87  }
88  }
89  $pos++;
90  }
91 
92  return array($atleastoneofthislevelafter,$nbofdirinsub,$nbofdocinsub);
93 }
94 
95 
96 
97 // ------------------------------- Used by menu editor, category view, ... -----------------
98 
116 function tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree', $donoresetalreadyloaded=0, $showfk=0)
117 {
118  global $tree_recur_alreadyadded;
119 
120  if ($rang == 0 && empty($donoresetalreadyloaded)) $tree_recur_alreadyadded=array();
121 
122  if ($rang == 0)
123  {
124  // Test also done with jstree and dynatree (not able to have <a> inside label)
125  print '<script type="text/javascript" language="javascript">
126  $(document).ready(function(){
127  $("#'.$iddivjstree.'").treeview({
128  collapsed: true,
129  animated: "fast",
130  persist: "cookie",
131  control: "#'.$iddivjstree.'control",
132  toggle: function() {
133  /* window.console && console.log("%o was toggled", this); */
134  }
135  });
136  })
137  </script>';
138 
139  print '<ul id="'.$iddivjstree.'">';
140  }
141 
142  if ($rang > 50)
143  {
144  return; // Protect against infinite loop. Max 50 depth
145  }
146 
147  //ballayage du tableau
148  $sizeoftab=count($tab);
149  $ulprinted=0;
150  for ($x=0; $x < $sizeoftab; $x++)
151  {
152  //var_dump($tab[$x]);exit;
153  // If an element has $pere for parent
154  if ($tab[$x]['fk_menu'] != -1 && $tab[$x]['fk_menu'] == $pere['rowid'])
155  {
156  //print 'rang='.$rang.'-x='.$x." rowid=".$tab[$x]['rowid']." tab[x]['fk_leftmenu'] = ".$tab[$x]['fk_leftmenu']." leftmenu pere = ".$pere['leftmenu']."<br>\n";
157  if (empty($ulprinted) && ! empty($pere['rowid']))
158  {
159  if (! empty($tree_recur_alreadyadded[$tab[$x]['rowid']]))
160  {
161  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);
162  continue;
163  }
164 
165  print '<ul'.(empty($pere['rowid'])?' id="treeData"':'').'>'; $ulprinted++;
166  }
167  print "\n".'<li '.($tab[$x]['statut']?' class="liuseractive"':'class="liuserdisabled"').'>';
168  if ($showfk)
169  {
170  print '<table class="nobordernopadding centpercent"><tr><td>';
171  print '<strong> &nbsp; ';
172  print $tab[$x]['title'];
173  print '&nbsp; (fk_mainmenu='.$tab[$x]['fk_mainmenu'].' fk_leftmenu='.$tab[$x]['fk_leftmenu'].')';
174  print '</td><td align="right">';
175  print $tab[$x]['buttons'];
176  print '</td></tr></table>';
177  }
178  else
179  {
180  print $tab[$x]['entry'];
181  }
182  //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";
183  $tree_recur_alreadyadded[$tab[$x]['rowid']]=($rang + 1);
184  // And now we search all its sons of lower level
185  tree_recur($tab, $tab[$x], $rang+1, 'iddivjstree', 0, $showfk);
186  print '</li>';
187  }
188  elseif (! empty($tab[$x]['rowid']) && $tab[$x]['fk_menu'] == -1 && $tab[$x]['fk_mainmenu'] == $pere['mainmenu'] && $tab[$x]['fk_leftmenu'] == $pere['leftmenu'])
189  {
190  //print 'rang='.$rang.'-x='.$x." rowid=".$tab[$x]['rowid']." tab[x]['fk_leftmenu'] = ".$tab[$x]['fk_leftmenu']." leftmenu pere = ".$pere['leftmenu']."<br>\n";
191  if (empty($ulprinted) && ! empty($pere['rowid']))
192  {
193  if (! empty($tree_recur_alreadyadded[$tab[$x]['rowid']]))
194  {
195  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);
196  //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.';
197  continue;
198  }
199 
200  print '<ul'.(empty($pere['rowid'])?' id="treeData"':'').'>'; $ulprinted++;
201  }
202  print "\n".'<li '.($tab[$x]['statut']?' class="liuseractive"':'class="liuserdisabled"').'>';
203  if ($showfk)
204  {
205  print '<table class="nobordernopadding centpercent"><tr><td>';
206  print '<strong> &nbsp; <a href="edit.php?menu_handler='.$menu_handler_to_search.'&action=edit&menuId='.$menu['rowid'].'">';
207  print $tab[$x]['title'];
208  print '</a></strong>';
209  print '&nbsp; (mainmenu='.$tab[$x]['mainmenu'].' leftmenu='.$tab[$x]['leftmenu'].' - fk_mainmenu='.$tab[$x]['fk_mainmenu'].' fk_leftmenu='.$tab[$x]['fk_leftmenu'].')';
210  print '</td><td align="right">';
211  print $tab[$x]['buttons'];
212  print '</td></tr></table>';
213  }
214  else
215  {
216  print $tab[$x]['entry'];
217  }
218  //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";
219  $tree_recur_alreadyadded[$tab[$x]['rowid']]=($rang + 1);
220  // And now we search all its sons of lower level
221  //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";
222  tree_recur($tab, $tab[$x], $rang+1, 'iddivjstree', 0, $showfk);
223  print '</li>';
224  }
225  }
226  if (! empty($ulprinted) && ! empty($pere['rowid'])) { print '</ul>'."\n"; }
227 
228  if ($rang == 0) print '</ul>';
229 }
230 
img_picto_common($titlealt, $picto, $moreatt= '', $pictoisfullpath=0)
Show picto (generic function)
tree_showpad(&$fulltree, $key, $silent=0)
Show indent and picto of a tree line.
tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree', $donoresetalreadyloaded=0, $showfk=0)
Recursive function to output a tree.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
print
Draft customers invoices.
Definition: index.php:91