dolibarr  7.0.0-beta
index.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  * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@capnetworks.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
26 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
29 
30 $langs->load("other");
31 $langs->load("admin");
32 
33 if (! $user->admin) accessforbidden();
34 
35 $dirstandard = array();
36 $dirsmartphone = array();
37 $dirmenus=array_merge(array("/core/menus/"),(array) $conf->modules_parts['menus']);
38 foreach($dirmenus as $dirmenu)
39 {
40  $dirstandard[]=$dirmenu.'standard';
41  $dirsmartphone[]=$dirmenu.'smartphone';
42 }
43 
44 $action=GETPOST('action','alpha');
45 $confirm=GETPOST('confirm','alpha');
46 
47 $menu_handler_top=$conf->global->MAIN_MENU_STANDARD;
48 $menu_handler_smartphone=$conf->global->MAIN_MENU_SMARTPHONE;
49 $menu_handler_top=preg_replace('/(_backoffice\.php|_menu\.php)/i','',$menu_handler_top);
50 $menu_handler_top=preg_replace('/(_frontoffice\.php|_menu\.php)/i','',$menu_handler_top);
51 $menu_handler_smartphone=preg_replace('/(_backoffice\.php|_menu\.php)/i','',$menu_handler_smartphone);
52 $menu_handler_smartphone=preg_replace('/(_frontoffice\.php|_menu\.php)/i','',$menu_handler_smartphone);
53 
54 $menu_handler=$menu_handler_top;
55 
56 if (GETPOST("handler_origine")) $menu_handler=GETPOST("handler_origine");
57 if (GETPOST("menu_handler")) $menu_handler=GETPOST("menu_handler");
58 
59 $menu_handler_to_search=preg_replace('/(_backoffice|_frontoffice|_menu)?(\.php)?/i','',$menu_handler);
60 
61 
62 /*
63  * Actions
64  */
65 
66 if ($action == 'up')
67 {
68  $current=array();
69  $previous=array();
70 
71  // Get current position
72  $sql = "SELECT m.rowid, m.position, m.type, m.fk_menu";
73  $sql.= " FROM ".MAIN_DB_PREFIX."menu as m";
74  $sql.= " WHERE m.rowid = ".GETPOST("menuId","int");
75  dol_syslog("admin/menus/index.php ".$sql);
76  $result = $db->query($sql);
77  $num = $db->num_rows($result);
78  $i = 0;
79  while($i < $num)
80  {
81  $obj = $db->fetch_object($result);
82  $current['rowid'] = $obj->rowid;
83  $current['order'] = $obj->position;
84  $current['type'] = $obj->type;
85  $current['fk_menu'] = $obj->fk_menu;
86  $i++;
87  }
88 
89  // Menu before
90  $sql = "SELECT m.rowid, m.position";
91  $sql.= " FROM ".MAIN_DB_PREFIX."menu as m";
92  $sql.= " WHERE (m.position < ".($current['order'])." OR (m.position = ".($current['order'])." AND rowid < ".GETPOST("menuId","int")."))";
93  $sql.= " AND m.menu_handler='".$db->escape($menu_handler_to_search)."'";
94  $sql.= " AND m.entity = ".$conf->entity;
95  $sql.= " AND m.type = '".$db->escape($current['type'])."'";
96  $sql.= " AND m.fk_menu = '".$db->escape($current['fk_menu'])."'";
97  $sql.= " ORDER BY m.position, m.rowid";
98  dol_syslog("admin/menus/index.php ".$sql);
99  $result = $db->query($sql);
100  $num = $db->num_rows($result);
101  $i = 0;
102  while($i < $num)
103  {
104  $obj = $db->fetch_object($result);
105  $previous['rowid'] = $obj->rowid;
106  $previous['order'] = $obj->position;
107  $i++;
108  }
109 
110  $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
111  $sql.= " SET m.position = ".$previous['order'];
112  $sql.= " WHERE m.rowid = ".$current['rowid']; // Up the selected entry
113  dol_syslog("admin/menus/index.php ".$sql);
114  $db->query($sql);
115  $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
116  $sql.= " SET m.position = ".($current['order']!=$previous['order']?$current['order']:$current['order']+1);
117  $sql.= " WHERE m.rowid = ".$previous['rowid']; // Descend celui du dessus
118  dol_syslog("admin/menus/index.php ".$sql);
119  $db->query($sql);
120 }
121 
122 elseif ($action == 'down')
123 {
124  $current=array();
125  $next=array();
126 
127  // Get current position
128  $sql = "SELECT m.rowid, m.position, m.type, m.fk_menu";
129  $sql.= " FROM ".MAIN_DB_PREFIX."menu as m";
130  $sql.= " WHERE m.rowid = ".GETPOST("menuId","int");
131  dol_syslog("admin/menus/index.php ".$sql);
132  $result = $db->query($sql);
133  $num = $db->num_rows($result);
134  $i = 0;
135  while($i < $num)
136  {
137  $obj = $db->fetch_object($result);
138  $current['rowid'] = $obj->rowid;
139  $current['order'] = $obj->position;
140  $current['type'] = $obj->type;
141  $current['fk_menu'] = $obj->fk_menu;
142  $i++;
143  }
144 
145  // Menu after
146  $sql = "SELECT m.rowid, m.position";
147  $sql.= " FROM ".MAIN_DB_PREFIX."menu as m";
148  $sql.= " WHERE (m.position > ".($current['order'])." OR (m.position = ".($current['order'])." AND rowid > ".GETPOST("menuId","int")."))";
149  $sql.= " AND m.menu_handler='".$db->escape($menu_handler_to_search)."'";
150  $sql.= " AND m.entity = ".$conf->entity;
151  $sql.= " AND m.type = '".$db->escape($current['type'])."'";
152  $sql.= " AND m.fk_menu = '".$db->escape($current['fk_menu'])."'";
153  $sql.= " ORDER BY m.position, m.rowid";
154  dol_syslog("admin/menus/index.php ".$sql);
155  $result = $db->query($sql);
156  $num = $db->num_rows($result);
157  $i = 0;
158  while($i < $num)
159  {
160  $obj = $db->fetch_object($result);
161  $next['rowid'] = $obj->rowid;
162  $next['order'] = $obj->position;
163  $i++;
164  }
165 
166  $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
167  $sql.= " SET m.position = ".($current['order']!=$next['order']?$next['order']:$current['order']+1); // Down the selected entry
168  $sql.= " WHERE m.rowid = ".$current['rowid'];
169  dol_syslog("admin/menus/index.php ".$sql);
170  $db->query($sql);
171  $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m"; // Up the next entry
172  $sql.= " SET m.position = ".$current['order'];
173  $sql.= " WHERE m.rowid = ".$next['rowid'];
174  dol_syslog("admin/menus/index.php ".$sql);
175  $db->query($sql);
176 }
177 
178 elseif ($action == 'confirm_delete' && $confirm == 'yes')
179 {
180  $db->begin();
181 
182  $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu";
183  $sql.= " WHERE rowid = ".GETPOST('menuId','int');
184  $resql=$db->query($sql);
185  if ($resql)
186  {
187  $db->commit();
188 
189  setEventMessages($langs->trans("MenuDeleted"), null, 'mesgs');
190 
191  header("Location: ".DOL_URL_ROOT.'/admin/menus/index.php?menu_handler='.$menu_handler);
192  exit ;
193  }
194  else
195  {
196  $db->rollback();
197 
198  $reload = 0;
199  $action='';
200  }
201 }
202 
203 
204 /*
205  * View
206  */
207 
208 $form=new Form($db);
209 $formadmin=new FormAdmin($db);
210 
211 $arrayofjs=array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
212 $arrayofcss=array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
213 
214 llxHeader('',$langs->trans("Menus"),'','',0,0,$arrayofjs,$arrayofcss);
215 
216 
217 print load_fiche_titre($langs->trans("Menus"),'','title_setup');
218 
219 
220 $h = 0;
221 
222 $head[$h][0] = DOL_URL_ROOT."/admin/menus.php";
223 $head[$h][1] = $langs->trans("MenuHandlers");
224 $head[$h][2] = 'handler';
225 $h++;
226 
227 $head[$h][0] = DOL_URL_ROOT."/admin/menus/index.php";
228 $head[$h][1] = $langs->trans("MenuAdmin");
229 $head[$h][2] = 'editor';
230 $h++;
231 
232 $head[$h][0] = DOL_URL_ROOT."/admin/menus/other.php";
233 $head[$h][1] = $langs->trans("Miscellaneous");
234 $head[$h][2] = 'misc';
235 $h++;
236 
237 dol_fiche_head($head, 'editor', $langs->trans("Menus"), -1);
238 
239 print $langs->trans("MenusEditorDesc")."<br>\n";
240 print "<br>\n";
241 
242 
243 // Confirmation for remove menu entry
244 if ($action == 'delete')
245 {
246  $sql = "SELECT m.titre";
247  $sql.= " FROM ".MAIN_DB_PREFIX."menu as m";
248  $sql.= " WHERE m.rowid = ".GETPOST('menuId','int');
249  $result = $db->query($sql);
250  $obj = $db->fetch_object($result);
251 
252  print $form->formconfirm("index.php?menu_handler=".$menu_handler."&menuId=".GETPOST('menuId','int'),$langs->trans("DeleteMenu"),$langs->trans("ConfirmDeleteMenu",$obj->titre),"confirm_delete");
253 }
254 
255 
256 print '<form name="newmenu" class="nocellnopadd" action="'.$_SERVER["PHP_SELF"].'">';
257 print '<input type="hidden" action="change_menu_handler">';
258 print $langs->trans("MenuHandler").': ';
259 print $formadmin->select_menu_families($menu_handler.(preg_match('/_menu/',$menu_handler)?'':'_menu'),'menu_handler',array_merge($dirstandard,$dirsmartphone));
260 print ' &nbsp; <input type="submit" class="button" value="'.$langs->trans("Refresh").'">';
261 print '</form>';
262 
263 print '<br>';
264 
265 print '<table class="noborder centpercent">';
266 
267 print '<tr class="liste_titre">';
268 print '<td>'.$langs->trans("TreeMenuPersonalized").'</td>';
269 print '<td align="right"><div id="iddivjstreecontrol"><a href="#">'.img_picto('','object_category').' '.$langs->trans("UndoExpandAll").'</a>';
270 print ' | <a href="#">'.img_picto('','object_category-expanded').' '.$langs->trans("ExpandAll").'</a></div></td>';
271 print '</tr>';
272 
273 print '<tr>';
274 print '<td colspan="2">';
275 
276 // ARBORESCENCE
277 
278 $rangLast = 0;
279 $idLast = -1;
280 if ($conf->use_javascript_ajax)
281 {
282  /*-------------------- MAIN -----------------------
283  tableau des elements de l'arbre:
284  c'est un tableau a 2 dimensions.
285  Une ligne represente un element : data[$x]
286  chaque ligne est decomposee en 3 donnees:
287  - l'index de l'élément
288  - l'index de l'élément parent
289  - la chaine a afficher
290  ie: data[]= array (index, index parent, chaine )
291  */
292 
293  //il faut d'abord declarer un element racine de l'arbre
294 
295  $data[] = array('rowid'=>0,'fk_menu'=>-1,'title'=>"racine",'mainmenu'=>'','leftmenu'=>'','fk_mainmenu'=>'','fk_leftmenu'=>'');
296 
297  //puis tous les elements enfants
298 
299  $sql = "SELECT m.rowid, m.titre, m.langs, m.mainmenu, m.leftmenu, m.fk_menu, m.fk_mainmenu, m.fk_leftmenu, m.position, m.module";
300  $sql.= " FROM ".MAIN_DB_PREFIX."menu as m";
301  $sql.= " WHERE menu_handler = '".$db->escape($menu_handler_to_search)."'";
302  $sql.= " AND entity = ".$conf->entity;
303  //$sql.= " AND fk_menu >= 0";
304  $sql.= " ORDER BY m.position, m.rowid"; // Order is position then rowid (because we need a sort criteria when position is same)
305 
306  $res = $db->query($sql);
307  if ($res)
308  {
309  $num = $db->num_rows($res);
310 
311  $i = 1;
312  while ($menu = $db->fetch_array($res))
313  {
314  if (! empty($menu['langs'])) $langs->load($menu['langs']);
315  $titre = $langs->trans($menu['titre']);
316 
317  $data[] = array(
318  'rowid'=>$menu['rowid'],
319  'module'=>$menu['module'],
320  'fk_menu'=>$menu['fk_menu'],
321  'title'=>$titre,
322  'mainmenu'=>$menu['mainmenu'],
323  'leftmenu'=>$menu['leftmenu'],
324  'fk_mainmenu'=>$menu['fk_mainmenu'],
325  'fk_leftmenu'=>$menu['fk_leftmenu'],
326  'position'=>$menu['position'],
327  'entry'=>'<table class="nobordernopadding centpercent"><tr><td>'.
328  '<strong> &nbsp; <a href="edit.php?menu_handler='.$menu_handler_to_search.'&action=edit&menuId='.$menu['rowid'].'">'.$titre.'</a></strong>'.
329  '</td><td align="right">'.
330  '<a href="edit.php?menu_handler='.$menu_handler_to_search.'&action=edit&menuId='.$menu['rowid'].'">'.img_edit('default',0,'class="menuEdit" id="edit'.$menu['rowid'].'"').'</a> '.
331  '<a href="edit.php?menu_handler='.$menu_handler_to_search.'&action=create&menuId='.$menu['rowid'].'">'.img_edit_add('default').'</a> '.
332  '<a href="index.php?menu_handler='.$menu_handler_to_search.'&action=delete&menuId='.$menu['rowid'].'">'.img_delete('default').'</a> '.
333  '&nbsp; &nbsp; &nbsp;'.
334  '<a href="index.php?menu_handler='.$menu_handler_to_search.'&action=up&menuId='.$menu['rowid'].'">'.img_picto("Up","1uparrow").'</a><a href="index.php?menu_handler='.$menu_handler_to_search.'&action=down&menuId='.$menu['rowid'].'">'.img_picto("Down","1downarrow").'</a>'.
335  '</td></tr></table>',
336  'buttons'=>'<a href="edit.php?menu_handler='.$menu_handler_to_search.'&action=edit&menuId='.$menu['rowid'].'">'.img_edit('default',0,'class="menuEdit" id="edit'.$menu['rowid'].'"').'</a> '.
337  '<a href="edit.php?menu_handler='.$menu_handler_to_search.'&action=create&menuId='.$menu['rowid'].'">'.img_edit_add('default').'</a> '.
338  '<a href="index.php?menu_handler='.$menu_handler_to_search.'&action=delete&menuId='.$menu['rowid'].'">'.img_delete('default').'</a> '.
339  '&nbsp; &nbsp; &nbsp;'.
340  '<a href="index.php?menu_handler='.$menu_handler_to_search.'&action=up&menuId='.$menu['rowid'].'">'.img_picto("Up","1uparrow").'</a><a href="index.php?menu_handler='.$menu_handler_to_search.'&action=down&menuId='.$menu['rowid'].'">'.img_picto("Down","1downarrow").'</a>'
341  );
342  $i++;
343  }
344  }
345 
346  global $tree_recur_alreadyadded; // This var was def into tree_recur
347 
348  //var_dump($data);
349 
350  // Appelle de la fonction recursive (ammorce) avec recherche depuis la racine.
351  //tree_recur($data, $data[0], 0, 'iddivjstree', 0, 1); // use this to get info on name and foreign keys of menu entry
352  tree_recur($data, $data[0], 0, 'iddivjstree', 0, 0); // $data[0] is virtual record 'racine'
353 
354 
355  print '</td>';
356 
357  print '</tr>';
358 
359  print '</table>';
360 
361 
362  // Process remaining records (records that are not linked to root by any path)
363  $remainingdata = array();
364  foreach($data as $datar)
365  {
366  if (empty($datar['rowid']) || $tree_recur_alreadyadded[$datar['rowid']]) continue;
367  $remainingdata[] = $datar;
368  }
369 
370  if (count($remainingdata))
371  {
372  print '<table class="noborder centpercent">';
373 
374  print '<tr class="liste_titre">';
375  print '<td>'.$langs->trans("NotTopTreeMenuPersonalized").'</td>';
376  print '<td align="right"></td>';
377  print '</tr>';
378 
379  print '<tr>';
380  print '<td colspan="2">';
381  foreach($remainingdata as $datar)
382  {
383  $father = array('rowid'=>$datar['rowid'],'title'=>"???",'mainmenu'=>$datar['fk_mainmenu'],'leftmenu'=>$datar['fk_leftmenu'],'fk_mainmenu'=>'','fk_leftmenu'=>'');
384  //print 'Start with rowid='.$datar['rowid'].' mainmenu='.$father ['mainmenu'].' leftmenu='.$father ['leftmenu'].'<br>'."\n";
385  tree_recur($data, $father, 0, 'iddivjstree'.$datar['rowid'], 1, 1);
386  }
387 
388  print '</td>';
389 
390  print '</tr>';
391 
392  print '</table>';
393  }
394 
395  print '</div>';
396 
397 
398  /*
399  * Boutons actions
400  */
401  print '<div class="tabsAction">';
402  print '<a class="butAction" href="'.DOL_URL_ROOT.'/admin/menus/edit.php?menuId=0&amp;action=create&amp;menu_handler='.urlencode($menu_handler).'">'.$langs->trans("NewMenu").'</a>';
403  print '</div>';
404 }
405 else
406 {
407  $langs->load("errors");
408  setEventMessages($langs->trans("ErrorFeatureNeedJavascript"), null, 'errors');
409 }
410 
411 print '<br>';
412 
413 llxFooter();
414 
415 $db->close();
llxFooter()
Footer empty.
Definition: index.php:43
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to generate html code for admin pages.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree', $donoresetalreadyloaded=0, $showfk=0)
Recursive function to output a tree.
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
llxHeader()
Header empty.
Definition: index.php:37
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_delete($titlealt= 'default', $other= 'class="pictodelete"')
Show delete logo.
img_edit_add($titlealt= 'default', $other= '')
Show logo +.
print
Draft customers invoices.
Definition: index.php:91
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
img_edit($titlealt= 'default', $float=0, $other= 'class="pictoedit"')
Show logo editer/modifier fiche.