dolibarr  21.0.0-alpha
viewcat.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
3  * Copyright (C) 2006-2020 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
5  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
7  * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
8  * Copyright (C) 2020 Josep Lluís Amador <joseplluis@lliuretic.cat>
9  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <https://www.gnu.org/licenses/>.
23  */
24 
31 // Load Dolibarr environment
32 require '../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
37 
38 // Load translation files required by the page
39 $langs->loadLangs(array("categories", "compta"));
40 
41 $id = GETPOSTINT('id');
42 $label = GETPOST('label', 'alpha');
43 $removeelem = GETPOSTINT('removeelem');
44 $elemid = GETPOSTINT('elemid');
45 
46 $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
47 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
48 $show_files = GETPOSTINT('show_files'); // Show files area generated by bulk actions ?
49 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
50 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
51 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
52 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'categorylist'; // To manage different context of search
53 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
54 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
55 
56 
57 // Load variable for pagination
58 $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
59 $sortfield = GETPOST('sortfield', 'aZ09comma');
60 $sortorder = GETPOST('sortorder', 'aZ09comma');
61 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
62 if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
63  $page = 0;
64 } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
65 $offset = $limit * $page;
66 $pageprev = $page - 1;
67 $pagenext = $page + 1;
68 
69 if ($id == "" && $label == "") {
70  dol_print_error(null, 'Missing parameter id');
71  exit();
72 }
73 
74 // Security check
75 $result = restrictedArea($user, 'categorie', $id, '&category');
76 
77 $object = new Categorie($db);
78 $result = $object->fetch($id, $label);
79 if ($result <= 0) {
80  dol_print_error($db, $object->error);
81  exit;
82 }
83 
84 $type = $object->type;
85 if (is_numeric($type)) {
86  $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
87 }
88 
89 $extrafields = new ExtraFields($db);
90 $extrafields->fetch_name_optionals_label($object->table_element);
91 
92 // Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array array
93 $hookmanager->initHooks(array('categorycard', 'globalcard'));
94 
95 /*
96  * Actions
97  */
98 
99 if ($confirm == 'no') {
100  if ($backtopage) {
101  header("Location: ".$backtopage);
102  exit;
103  }
104 }
105 
106 $parameters = array('type' => $type, 'id' => $id, 'label' => $label);
107 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
108 // Remove element from category
109 if ($id > 0 && $removeelem > 0 && $action == 'unlink') {
110  if ($type == Categorie::TYPE_PRODUCT && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
111  require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
112  $tmpobject = new Product($db);
113  $result = $tmpobject->fetch($removeelem);
114  $elementtype = 'product';
115  } elseif ($type == Categorie::TYPE_SUPPLIER && $user->hasRight('societe', 'creer')) {
116  $tmpobject = new Societe($db);
117  $result = $tmpobject->fetch($removeelem);
118  $elementtype = 'supplier';
119  } elseif ($type == Categorie::TYPE_CUSTOMER && $user->hasRight('societe', 'creer')) {
120  $tmpobject = new Societe($db);
121  $result = $tmpobject->fetch($removeelem);
122  $elementtype = 'customer';
123  } elseif ($type == Categorie::TYPE_MEMBER && $user->hasRight('adherent', 'creer')) {
124  require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
125  $tmpobject = new Adherent($db);
126  $result = $tmpobject->fetch($removeelem);
127  $elementtype = 'member';
128  } elseif ($type == Categorie::TYPE_CONTACT && $user->hasRight('societe', 'creer')) {
129  require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
130  $tmpobject = new Contact($db);
131  $result = $tmpobject->fetch($removeelem);
132  $elementtype = 'contact';
133  } elseif ($type == Categorie::TYPE_ACCOUNT && $user->hasRight('banque', 'configurer')) {
134  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
135  $tmpobject = new Account($db);
136  $result = $tmpobject->fetch($removeelem);
137  $elementtype = 'account';
138  } elseif ($type == Categorie::TYPE_PROJECT && $user->hasRight('projet', 'creer')) {
139  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
140  $tmpobject = new Project($db);
141  $result = $tmpobject->fetch($removeelem);
142  $elementtype = 'project';
143  } elseif ($type == Categorie::TYPE_USER && $user->hasRight('user', 'user', 'creer')) {
144  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
145  $tmpobject = new User($db);
146  $result = $tmpobject->fetch($removeelem);
147  $elementtype = 'user';
148  } elseif ($type == Categorie::TYPE_TICKET && $user->hasRight('ticket', 'write')) {
149  require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
150  $tmpobject = new Ticket($db);
151  $result = $tmpobject->fetch($removeelem);
152  $elementtype = 'ticket';
153  }
154 
155  $result = $object->del_type($tmpobject, $elementtype);
156  if ($result < 0) {
157  dol_print_error(null, $object->error);
158  }
159 }
160 
161 if ($user->hasRight('categorie', 'supprimer') && $action == 'confirm_delete' && $confirm == 'yes') {
162  if ($object->delete($user) >= 0) {
163  if ($backtopage) {
164  header("Location: ".$backtopage);
165  exit;
166  } else {
167  header("Location: ".DOL_URL_ROOT.'/categories/index.php?type='.$type);
168  exit;
169  }
170  } else {
171  setEventMessages($object->error, $object->errors, 'errors');
172  }
173 }
174 
175 if ($elemid && $action == 'addintocategory' &&
176  (
177  ($type == Categorie::TYPE_PRODUCT && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) ||
178  ($type == Categorie::TYPE_CUSTOMER && $user->hasRight('societe', 'creer')) ||
179  ($type == Categorie::TYPE_SUPPLIER && $user->hasRight('societe', 'creer')) ||
180  ($type == Categorie::TYPE_TICKET && $user->hasRight('ticket', 'write')) ||
181  ($type == Categorie::TYPE_PROJECT && $user->hasRight('projet', 'creer')) ||
182  ($type == Categorie::TYPE_MEMBER && $user->hasRight('adherent', 'creer')) ||
183  ($type == Categorie::TYPE_CONTACT && $user->hasRight('societe', 'creer')) ||
184  ($type == Categorie::TYPE_USER && $user->hasRight('user', 'user', 'creer')) ||
185  ($type == Categorie::TYPE_ACCOUNT && $user->hasRight('banque', 'configurer'))
186  )) {
187  if ($type == Categorie::TYPE_PRODUCT) {
188  require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
189  $newobject = new Product($db);
190  $elementtype = 'product';
191  } elseif ($type == Categorie::TYPE_CUSTOMER) {
192  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
193  $newobject = new Societe($db);
194  $elementtype = 'customer';
195  } elseif ($type == Categorie::TYPE_SUPPLIER) {
196  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
197  $newobject = new Societe($db);
198  $elementtype = 'supplier';
199  } elseif ($type == Categorie::TYPE_TICKET) {
200  require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
201  $newobject = new Ticket($db);
202  $elementtype = 'ticket';
203  } elseif ($type == Categorie::TYPE_PROJECT) {
204  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
205  $newobject = new Project($db);
206  $elementtype = 'project';
207  } elseif ($type == Categorie::TYPE_MEMBER) {
208  require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
209  $newobject = new Adherent($db);
210  $elementtype = 'member';
211  } elseif ($type == Categorie::TYPE_CONTACT) {
212  require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
213  $newobject = new Contact($db);
214  $elementtype = 'contact';
215  } elseif ($type == Categorie::TYPE_USER) {
216  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
217  $newobject = new User($db);
218  $elementtype = 'user';
219  } elseif ($type == Categorie::TYPE_ACCOUNT) {
220  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
221  $newobject = new Account($db);
222  $elementtype = 'bank_account';
223  } else {
224  dol_print_error(null, "Not supported value of type = ".$type);
225  }
226  $result = $newobject->fetch($elemid);
227 
228  // Add into category
229  $result = $object->add_type($newobject, $elementtype);
230  if ($result >= 0) {
231  setEventMessages($langs->trans("WasAddedSuccessfully", $newobject->ref), null, 'mesgs');
232  } else {
233  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
234  setEventMessages($langs->trans("ObjectAlreadyLinkedToCategory"), null, 'warnings');
235  } else {
236  setEventMessages($object->error, $object->errors, 'errors');
237  }
238  }
239 }
240 
241 
242 /*
243  * View
244  */
245 
246 $form = new Form($db);
247 $formother = new FormOther($db);
248 
249 $arrayofjs = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
250 $arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
251 
252 $help_url = '';
253 
254 llxHeader("", $langs->trans("Categories"), $help_url, '', 0, 0, $arrayofjs, $arrayofcss);
255 
256 $title = Categorie::$MAP_TYPE_TITLE_AREA[$type];
257 
258 $head = categories_prepare_head($object, $type);
259 print dol_get_fiche_head($head, 'card', $langs->trans($title), -1, 'category');
260 
261 $backtolist = (GETPOST('backtolist') ? GETPOST('backtolist') : DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.urlencode($type));
262 $linkback = '<a href="'.dol_sanitizeUrl($backtolist).'">'.$langs->trans("BackToList").'</a>';
263 $object->next_prev_filter = 'type = '.((int) $object->type);
264 $object->ref = $object->label;
265 $morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.urlencode($type).'">'.$langs->trans("Root").'</a> >> ';
266 $ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
267 foreach ($ways as $way) {
268  $morehtmlref .= $way."<br>\n";
269 }
270 $morehtmlref .= '</div>';
271 
272 dol_banner_tab($object, 'label', $linkback, ($user->socid ? 0 : 1), 'label', 'label', $morehtmlref, '&type='.urlencode($type), 0, '', '', 1);
273 
274 
275 /*
276  * Confirmation suppression
277  */
278 
279 if ($action == 'delete') {
280  if ($backtopage) {
281  print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.$type.'&backtopage='.urlencode($backtopage), $langs->trans('DeleteCategory'), $langs->trans('ConfirmDeleteCategory'), 'confirm_delete', '', '', 2);
282  } else {
283  print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.$type, $langs->trans('DeleteCategory'), $langs->trans('ConfirmDeleteCategory'), 'confirm_delete', '', '', 1);
284  }
285 }
286 
287 print '<br>';
288 
289 print '<div class="fichecenter">';
290 print '<div class="underbanner clearboth"></div>';
291 print '<table class="border centpercent tableforfield">';
292 
293 // Description
294 print '<tr><td class="titlefield notopnoleft tdtop">';
295 print $langs->trans("Description").'</td><td>';
296 print dol_htmlentitiesbr($object->description);
297 print '</td></tr>';
298 
299 // Color
300 print '<tr><td class="notopnoleft">';
301 print $langs->trans("Color").'</td><td>';
302 print $formother->showColor($object->color);
303 print '</td></tr>';
304 
305 // Position
306 print '<tr><td class="titlefield notopnoleft">';
307 print $langs->trans("Position").'</td><td>';
308 print $object->position;
309 print '</td></tr>';
310 
311 // Other attributes
312 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
313 
314 print '</table>';
315 print '</div>';
316 
317 print dol_get_fiche_end();
318 
319 
320 /*
321  * Boutons actions
322  */
323 
324 print "<div class='tabsAction'>\n";
325 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
326 if ($reshook < 0) {
327  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
328 }
329 if (empty($reshook)) {
330  if ($user->hasRight('categorie', 'creer')) {
331  $socid = ($object->socid ? "&socid=".$object->socid : "");
332  print '<a class="butAction" href="edit.php?id='.$object->id.$socid.'&type='.$type.'">'.$langs->trans("Modify").'</a>';
333  }
334 
335  if ($user->hasRight('categorie', 'supprimer')) {
336  print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id.'&type='.$type.'&backtolist='.urlencode($backtolist).'">'.$langs->trans("Delete").'</a>';
337  }
338 }
339 
340 print "</div>";
341 
342 $newcardbutton = '';
343 if ($user->hasRight('categorie', 'creer')) {
344  $link = DOL_URL_ROOT.'/categories/card.php';
345  $link .= '?action=create';
346  $link .= '&type='.$type;
347  $link .= '&catorigin='.$object->id;
348  $link .= '&backtopage='.urlencode($_SERVER["PHP_SELF"].'?type='.$type.'&id='.$id);
349 
350  $newcardbutton = '<div class="right">';
351  $newcardbutton .= dolGetButtonTitle($langs->trans('NewCategory'), '', 'fa fa-plus-circle', $link);
352  $newcardbutton .= '</div>';
353 }
354 
355 
356 /*
357  * Sub-category tree view of this category
358  */
359 
360 print '<div class="fichecenter">';
361 
362 print load_fiche_titre($langs->trans("SubCats"), $newcardbutton, 'object_category');
363 
364 
365 print '<table class="liste nohover centpercent borderbottom">';
366 
367 print '<tr class="liste_titre">';
368 print '<td>'.$langs->trans("SubCats").'</td>';
369 print '<td></td>';
370 print '<td class="right">';
371 
372 if (!empty($conf->use_javascript_ajax)) {
373  print '<div id="iddivjstreecontrol">';
374  print '<a class="notasortlink" href="#">'.img_picto('', 'folder').' '.$langs->trans("UndoExpandAll").'</a>';
375  print " | ";
376  print '<a class="notasortlink" href="#">'.img_picto('', 'folder-open').' '.$langs->trans("ExpandAll").'</a>';
377  print '</div>';
378 }
379 
380 print '</td>';
381 print '</tr>';
382 
383 $cats = $object->get_filles();
384 if ($cats < 0) {
385  dol_print_error($db, $object->error, $object->errors);
386 } elseif (count($cats) < 1) {
387  print '<tr class="oddeven nobottom">';
388  print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("NoSubCat").'</span></td>';
389  print '</tr>';
390 } else {
391  $categstatic = new Categorie($db);
392 
393  $fulltree = $categstatic->get_full_arbo($type, $object->id, 1);
394 
395  // Load possible missing includes
396  if (getDolGlobalString('CATEGORY_SHOW_COUNTS')) {
397  if ($type == Categorie::TYPE_MEMBER) {
398  require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
399  }
400  if ($type == Categorie::TYPE_ACCOUNT) {
401  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
402  }
403  if ($type == Categorie::TYPE_PROJECT) {
404  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
405  }
406  if ($type == Categorie::TYPE_USER) {
407  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
408  }
409  }
410 
411  // Define data (format for treeview)
412  $data = array();
413  $data[] = array('rowid' => 0, 'fk_menu' => -1, 'title' => "racine", 'mainmenu' => '', 'leftmenu' => '', 'fk_mainmenu' => '', 'fk_leftmenu' => '');
414  foreach ($fulltree as $key => $val) {
415  $categstatic->id = $val['id'];
416  $categstatic->ref = $val['label'];
417  $categstatic->color = $val['color'];
418  $categstatic->type = $type;
419  $desc = dol_htmlcleanlastbr($val['description']);
420 
421  $counter = '';
422  if (getDolGlobalString('CATEGORY_SHOW_COUNTS')) {
423  // we need only a count of the elements, so it is enough to consume only the id's from the database
424  $elements = $categstatic->getObjectsInCateg($type, 1);
425 
426  $counter = "<td class='left' width='40px;'>".(is_array($elements) ? count($elements) : '0')."</td>";
427  }
428 
429  $color = $categstatic->color ? ' style="background: #'.sprintf("%06s", $categstatic->color).';"' : ' style="background: #bbb"';
430  $li = $categstatic->getNomUrl(1, '', 60, '&backtolist='.urlencode($_SERVER["PHP_SELF"].'?id='.$id.'&type='.$type));
431 
432  $entry = '<table class="nobordernopadding centpercent">';
433  $entry .= '<tr>';
434 
435  $entry .= '<td>';
436  $entry .= '<span class="noborderoncategories" '.$color.'>'.$li.'</span>';
437  $entry .= '</td>';
438 
439  $entry .= $counter;
440 
441  $entry .= '<td class="right" width="20px;">';
442  $entry .= '<a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.$val['id'].'&type='.$type.'&backtolist='.urlencode($_SERVER["PHP_SELF"].'?id='.$id.'&type='.$type).'">'.img_view().'</a>';
443  $entry .= '</td>';
444  $entry .= '<td class="right" width="20px;">';
445  $entry .= '<a class="editfielda" href="'.DOL_URL_ROOT.'/categories/edit.php?id='.$val['id'].'&type='.$type.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$id.'&type='.$type).'">'.img_edit().'</a>';
446  $entry .= '</td>';
447  $entry .= '<td class="right" width="20px;">';
448  $entry .= '<a class="deletefilelink" href="'.DOL_URL_ROOT.'/categories/viewcat.php?action=delete&token='.newToken().'&id='.$val['id'].'&type='.$type.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$id.'&type='.$type).'&backtolist='.urlencode($_SERVER["PHP_SELF"].'?id='.$id.'&type='.$type).'">'.img_delete().'</a>';
449  $entry .= '</td>';
450 
451  $entry .= '</tr>';
452  $entry .= '</table>';
453 
454  $data[] = array('rowid' => $val['rowid'], 'fk_menu' => $val['fk_parent'], 'entry' => $entry);
455  }
456 
457  $nbofentries = (count($data) - 1);
458  if ($nbofentries > 0) {
459  require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
460  print '<tr class="pair">';
461  print '<td colspan="3">';
462 
463  // $data[0] is the current shown category, to don'T show the current category use $data[1] instead
464  tree_recur($data, $data[1], 0);
465 
466  print '</td>';
467  print '</tr>';
468  } else {
469  print '<tr class="pair">';
470  print '<td colspan="3">';
471  print '<table class="nobordernopadding">';
472 
473  print '<tr class="nobordernopadding">';
474  print '<td>'.img_picto_common('', 'treemenu/branchbottom.gif').'</td>';
475  print '<td class="valignmiddle"><span class="opacitymedium">'.$langs->trans("NoCategoryYet").'</span></td>';
476  print '<td>&nbsp;</td>';
477  print '</tr>';
478 
479  print '</table>';
480  print '</td>';
481  print '</tr>';
482  }
483 }
484 
485 print "</table>";
486 print "</div>";
487 
488 // List of mass actions available
489 $arrayofmassactions = array(
490  //'validate'=>$langs->trans("Validate"),
491  //'generate_doc'=>$langs->trans("ReGeneratePDF"),
492  //'builddoc'=>$langs->trans("PDFMerge"),
493  //'presend'=>$langs->trans("SendByMail"),
494 );
495 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
496 
497 $typeid = $type;
498 
499 
500 // List of products or services (type is type of category)
501 if ($type == Categorie::TYPE_PRODUCT) {
502  if ($user->hasRight("product", "read") || $user->hasRight("service", "read")) {
503  $permission = ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'));
504 
505  $prods = $object->getObjectsInCateg($type, 0, $limit, $offset);
506  if ($prods < 0) {
507  dol_print_error($db, $object->error, $object->errors);
508  } else {
510  '@phan-var-force Product[] $prods';
511  // Form to add record into the category
512  $showclassifyform = 1;
513  if ($showclassifyform) {
514  print '<br>';
515  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
516  print '<input type="hidden" name="token" value="'.newToken().'">';
517  print '<input type="hidden" name="typeid" value="'.$typeid.'">';
518  print '<input type="hidden" name="type" value="'.$typeid.'">';
519  print '<input type="hidden" name="id" value="'.$object->id.'">';
520  print '<input type="hidden" name="action" value="addintocategory">';
521  print '<table class="noborder centpercent">';
522  print '<tr class="liste_titre"><td>';
523  print $langs->trans("AddProductServiceIntoCategory").' &nbsp;';
524  $form->select_produits('', 'elemid', '', 0, 0, -1, 2, '', 1, array(), 0, 1, 0, '', 0, '', null);
525  print '<input type="submit" class="button buttongen" value="'.$langs->trans("ClassifyInCategory").'"></td>';
526  print '</tr>';
527  print '</table>';
528  print '</form>';
529  }
530 
531  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
532  print '<input type="hidden" name="token" value="'.newToken().'">';
533  print '<input type="hidden" name="typeid" value="'.$typeid.'">';
534  print '<input type="hidden" name="type" value="'.$typeid.'">';
535  print '<input type="hidden" name="id" value="'.$object->id.'">';
536  print '<input type="hidden" name="action" value="list">';
537 
538  print '<br>';
539  $param = '&limit='.$limit.'&id='.$id.'&type='.$type;
540  $num = count($prods);
541  $nbtotalofrecords = '';
542  $newcardbutton = dolGetButtonTitle($langs->trans("AddProduct"), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/card.php?action=create&categories[]='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id), '', $user->rights->societe->creer);
543 
544  // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
545  print_barre_liste($langs->trans("ProductsAndServices"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'products', 0, $newcardbutton, '', $limit);
546 
547 
548  print '<table class="noborder centpercent">'."\n";
549  print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Ref").'</td></tr>'."\n";
550 
551  if (count($prods) > 0) {
552  $i = 0;
553  foreach ($prods as $prod) {
554  $i++;
555  if ($i > $limit) {
556  break;
557  }
558 
559  print "\t".'<tr class="oddeven">'."\n";
560  print '<td class="nowrap" valign="top">';
561  print $prod->getNomUrl(1);
562  print "</td>\n";
563  print '<td class="tdtop">'.$prod->label."</td>\n";
564  // Link to delete from category
565  print '<td class="right">';
566  if ($permission) {
567  print '<a class="reposition" href= "'.$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".((int) $object->id)."&type=".urlencode($typeid)."&action=unlink&token=".newToken()."&removeelem=".$prod->id.'">';
568  print $langs->trans("DeleteFromCat");
569  print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');
570  print "</a>";
571  }
572  print '</td>';
573  print "</tr>\n";
574  }
575  } else {
576  print '<tr class="oddeven"><td colspan="2"><span class="opacitymedium">'.$langs->trans("ThisCategoryHasNoItems").'</span></td></tr>';
577  }
578  print "</table>\n";
579 
580  print '</form>'."\n";
581  }
582  } else {
583  print_barre_liste($langs->trans("ProductsAndServices"), null, $_SERVER["PHP_SELF"], '', '', '', '', '', '', 'products');
584  accessforbidden("NotEnoughPermissions", 0, 0);
585  }
586 }
587 
588 // List of customers
589 if ($type == Categorie::TYPE_CUSTOMER) {
590  if ($user->hasRight("societe", "read")) {
591  $permission = $user->hasRight('societe', 'creer');
592 
593  $socs = $object->getObjectsInCateg($type, 0, $limit, $offset);
594  if ($socs < 0) {
595  dol_print_error($db, $object->error, $object->errors);
596  } else {
598  '@phan-var-force Societe[] $socs';
599  // Form to add record into a category
600  $showclassifyform = 1;
601  if ($showclassifyform) {
602  print '<br>';
603  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
604  print '<input type="hidden" name="token" value="'.newToken().'">';
605  print '<input type="hidden" name="typeid" value="'.$typeid.'">';
606  print '<input type="hidden" name="type" value="'.$typeid.'">';
607  print '<input type="hidden" name="id" value="'.$object->id.'">';
608  print '<input type="hidden" name="action" value="addintocategory">';
609  print '<table class="noborder centpercent">';
610  print '<tr class="liste_titre"><td>';
611  print $langs->trans("AddCustomerIntoCategory").' &nbsp;';
612  $filter = '(s.client:IN:1,3)';
613  print $form->select_company('', 'elemid', $filter);
614  print '<input type="submit" class="button buttongen" value="'.$langs->trans("ClassifyInCategory").'"></td>';
615  print '</tr>';
616  print '</table>';
617  print '</form>';
618  }
619 
620  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
621  print '<input type="hidden" name="token" value="'.newToken().'">';
622  print '<input type="hidden" name="typeid" value="'.$typeid.'">';
623  print '<input type="hidden" name="type" value="'.$typeid.'">';
624  print '<input type="hidden" name="id" value="'.$object->id.'">';
625  print '<input type="hidden" name="action" value="list">';
626 
627  print '<br>';
628  $param = '&limit='.$limit.'&id='.$id.'&type='.$type;
629  $num = count($socs);
630  $nbtotalofrecords = '';
631  $newcardbutton = dolGetButtonTitle($langs->trans("AddThirdParty"), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/societe/card.php?action=create&client=3&custcats[]='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id), '', $user->rights->societe->creer);
632 
633  // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
634  print_barre_liste($langs->trans("Customers"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'companies', 0, $newcardbutton, '', $limit);
635 
636  print '<table class="noborder centpercent">'."\n";
637  print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Name").'</td></tr>'."\n";
638 
639  if (count($socs) > 0) {
640  $i = 0;
641  foreach ($socs as $key => $soc) {
642  $i++;
643  if ($i > $limit) {
644  break;
645  }
646 
647  print "\t".'<tr class="oddeven">'."\n";
648  print '<td class="nowrap tdtop">';
649  print $soc->getNomUrl(1);
650  print "</td>\n";
651  // Link to delete from category
652  print '<td class="right">';
653  if ($permission) {
654  print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&type=".$typeid."&action=unlink&token=".newToken()."&removeelem=".$soc->id."'>";
655  print $langs->trans("DeleteFromCat");
656  print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');
657  print "</a>";
658  }
659  print '</td>';
660  print "</tr>\n";
661  }
662  } else {
663  print '<tr class="oddeven"><td colspan="2"><span class="opacitymedium">'.$langs->trans("ThisCategoryHasNoItems").'</span></td></tr>';
664  }
665  print "</table>\n";
666 
667  print '</form>'."\n";
668  }
669  } else {
670  print_barre_liste($langs->trans("Customers"), null, $_SERVER["PHP_SELF"], '', '', '', '', '', '', 'companies');
671  accessforbidden("NotEnoughPermissions", 0, 0);
672  }
673 }
674 
675 // List of suppliers
676 if ($type == Categorie::TYPE_SUPPLIER) {
677  if ($user->hasRight("fournisseur", "read")) {
678  $permission = $user->hasRight('societe', 'creer');
679 
680  $socs = $object->getObjectsInCateg($type, 0, $limit, $offset);
681 
682  if ($socs < 0) {
683  dol_print_error($db, $object->error, $object->errors);
684  } else {
686  '@phan-var-force Fournisseur[] $socs';
687  // Form to add record into a category
688  $showclassifyform = 1;
689  if ($showclassifyform) {
690  print '<br>';
691  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
692  print '<input type="hidden" name="token" value="'.newToken().'">';
693  print '<input type="hidden" name="typeid" value="'.$typeid.'">';
694  print '<input type="hidden" name="type" value="'.$typeid.'">';
695  print '<input type="hidden" name="id" value="'.$object->id.'">';
696  print '<input type="hidden" name="action" value="addintocategory">';
697  print '<table class="noborder centpercent">';
698  print '<tr class="liste_titre"><td>';
699  print $langs->trans("AddSupplierIntoCategory").' &nbsp;';
700  $filter = '(s.fournisseur:=:1)';
701  print $form->select_company('', 'elemid', $filter);
702  print '<input type="submit" class="button buttongen" value="'.$langs->trans("ClassifyInCategory").'"></td>';
703  print '</tr>';
704  print '</table>';
705  print '</form>';
706  }
707 
708  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
709  print '<input type="hidden" name="token" value="'.newToken().'">';
710  print '<input type="hidden" name="typeid" value="'.$typeid.'">';
711  print '<input type="hidden" name="type" value="'.$typeid.'">';
712  print '<input type="hidden" name="id" value="'.$object->id.'">';
713  print '<input type="hidden" name="action" value="list">';
714 
715  print '<br>';
716  $param = '&limit='.$limit.'&id='.$id.'&type='.$type;
717  $num = count($socs);
718  $nbtotalofrecords = '';
719  $newcardbutton = dolGetButtonTitle($langs->trans("AddSupplier"), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/societe/card.php?action=create&fournisseur=1&suppcats[]='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id), '', $user->rights->societe->creer);
720 
721  // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
722  print_barre_liste($langs->trans("Suppliers"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'companies', 0, $newcardbutton, '', $limit);
723 
724  print '<table class="noborder centpercent">'."\n";
725  print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Name")."</td></tr>\n";
726 
727  if (count($socs) > 0) {
728  $i = 0;
729  foreach ($socs as $soc) {
730  $i++;
731  if ($i > $limit) {
732  break;
733  }
734 
735  print "\t".'<tr class="oddeven">'."\n";
736  print '<td class="nowrap tdtop">';
737  print $soc->getNomUrl(1);
738  print "</td>\n";
739  // Link to delete from category
740  print '<td class="right">';
741  if ($permission) {
742  print '<a class="reposition" href="'.$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&type=".$typeid."&action=unlink&token=".newToken()."&removeelem=".$soc->id.($limit?'&limit='.$limit:'').'">';
743  print $langs->trans("DeleteFromCat");
744  print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');
745  print "</a>";
746  }
747  print '</td>';
748 
749  print "</tr>\n";
750  }
751  } else {
752  print '<tr class="oddeven"><td colspan="2"><span class="opacitymedium">'.$langs->trans("ThisCategoryHasNoItems").'</span></td></tr>';
753  }
754  print "</table>\n";
755 
756  print '</form>'."\n";
757  }
758  } else {
759  print_barre_liste($langs->trans("Suppliers"), null, $_SERVER["PHP_SELF"], '', '', '', '', '', '', 'companies');
760  accessforbidden("NotEnoughPermissions", 0, 0);
761  }
762 }
763 
764 // List of members
765 if ($type == Categorie::TYPE_MEMBER) {
766  if ($user->hasRight("adherent", "read")) {
767  require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
768 
769  $permission = $user->hasRight('adherent', 'creer');
770 
771  $members = $object->getObjectsInCateg($type, 0, $limit, $offset);
772  if ($members < 0) {
773  dol_print_error($db, $object->error, $object->errors);
774  } else {
776  '@phan-var-force Adherent[] $members';
777  // Form to add record into a category
778  $showclassifyform = 1;
779  if ($showclassifyform) {
780  print '<br>';
781  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
782  print '<input type="hidden" name="token" value="'.newToken().'">';
783  print '<input type="hidden" name="typeid" value="'.$typeid.'">';
784  print '<input type="hidden" name="type" value="'.$typeid.'">';
785  print '<input type="hidden" name="id" value="'.$object->id.'">';
786  print '<input type="hidden" name="action" value="addintocategory">';
787  print '<table class="noborder centpercent">';
788  print '<tr class="liste_titre"><td>';
789  print $langs->trans("AssignCategoryTo").' &nbsp;';
790  print $form->selectMembers('', 'elemid');
791  print '<input type="submit" class="button buttongen" value="'.$langs->trans("Save").'"></td>';
792  print '</tr>';
793  print '</table>';
794  print '</form>';
795  }
796 
797  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
798  print '<input type="hidden" name="token" value="'.newToken().'">';
799  print '<input type="hidden" name="typeid" value="'.$typeid.'">';
800  print '<input type="hidden" name="type" value="'.$typeid.'">';
801  print '<input type="hidden" name="id" value="'.$object->id.'">';
802  print '<input type="hidden" name="action" value="list">';
803 
804  print '<br>';
805  $param = '&limit='.$limit.'&id='.$id.'&type='.$type;
806  $num = count($members);
807  $nbtotalofrecords = '';
808  $newcardbutton = dolGetButtonTitle($langs->trans("AddMember"), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/adherents/card.php?action=create&memcats[]='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id), '', $user->hasRight('adherent', 'creer'));
809 
810  // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
811  print_barre_liste($langs->trans("Member"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'members', 0, $newcardbutton, '', $limit);
812 
813  print '<table class="noborder centpecent">'."\n";
814  print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Name").'</td></tr>'."\n";
815 
816  if (count($members) > 0) {
817  $i = 0;
818  foreach ($members as $key => $member) {
819  $i++;
820  if ($i > $limit) {
821  break;
822  }
823 
824  print "\t".'<tr class="oddeven">'."\n";
825  print '<td class="nowrap tdtop">';
826  $member->ref = $member->login;
827  print $member->getNomUrl(1, 0);
828  print "</td>\n";
829  print '<td class="tdtop">'.$member->lastname."</td>\n";
830  print '<td class="tdtop">'.$member->firstname."</td>\n";
831  // Link to delete from category
832  print '<td class="right">';
833  if ($permission) {
834  print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&type=".$typeid."&action=unlink&token=".newToken()."&removeelem=".$member->id."'>";
835  print $langs->trans("DeleteFromCat");
836  print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');
837  print "</a>";
838  }
839  print '</td>';
840  print "</tr>\n";
841  }
842  } else {
843  print '<tr class="oddeven"><td colspan="4"><span class="opacitymedium">'.$langs->trans("ThisCategoryHasNoItems").'</span></td></tr>';
844  }
845  print "</table>\n";
846 
847  print '</form>'."\n";
848  }
849  } else {
850  print_barre_liste($langs->trans("Member"), null, $_SERVER["PHP_SELF"], '', '', '', '', '', '', 'members');
851  accessforbidden("NotEnoughPermissions", 0, 0);
852  }
853 }
854 
855 // List of contacts
856 if ($type == Categorie::TYPE_CONTACT) {
857  if ($user->hasRight("societe", "read")) {
858  $permission = $user->hasRight('societe', 'creer');
859 
860  $contacts = $object->getObjectsInCateg($type, 0, $limit, $offset);
861  if (is_numeric($contacts) && $contacts < 0) {
862  dol_print_error($db, $object->error, $object->errors);
863  } else {
865  '@phan-var-force Contact[] $contacts';
866  // Form to add record into a category
867  $showclassifyform = 1;
868  if ($showclassifyform) {
869  print '<br>';
870  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
871  print '<input type="hidden" name="token" value="'.newToken().'">';
872  print '<input type="hidden" name="typeid" value="'.$typeid.'">';
873  print '<input type="hidden" name="type" value="'.$typeid.'">';
874  print '<input type="hidden" name="id" value="'.$object->id.'">';
875  print '<input type="hidden" name="action" value="addintocategory">';
876  print '<table class="noborder centpercent">';
877  print '<tr class="liste_titre"><td>';
878  print $langs->trans("AssignCategoryTo").' &nbsp;';
879  //print $form->selectcontacts('', '', 'elemid');
880  print $form->select_contact(0, '', 'elemid', '', '', '', 0, 'maxwidth300 widthcentpercentminusx');
881  print '<input type="submit" class="button buttongen" value="'.$langs->trans("ClassifyInCategory").'"></td>';
882  print '</tr>';
883  print '</table>';
884  print '</form>';
885  }
886  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
887  print '<input type="hidden" name="token" value="'.newToken().'">';
888  print '<input type="hidden" name="typeid" value="'.$typeid.'">';
889  print '<input type="hidden" name="type" value="'.$typeid.'">';
890  print '<input type="hidden" name="id" value="'.$object->id.'">';
891  print '<input type="hidden" name="action" value="list">';
892 
893  print '<br>';
894  $param = '&limit='.$limit.'&id='.$id.'&type='.$type;
895  $num = count($contacts);
896  $nbtotalofrecords = '';
897  $newcardbutton = dolGetButtonTitle($langs->trans("AddContact"), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/contact/card.php?action=create&contcats[]='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id), '', $user->rights->societe->creer);
898 
899  // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
900  print_barre_liste($langs->trans("Contact"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'contact', 0, $newcardbutton, '', $limit);
901 
902  $objsoc = new Societe($db);
903 
904  print '<table class="noborder centpercent">'."\n";
905  print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Ref").'</td></tr>'."\n";
906 
907  if (is_array($contacts) && count($contacts) > 0) {
908  $i = 0;
909  foreach ($contacts as $key => $contact) {
910  $i++;
911  if ($i > $limit) {
912  break;
913  }
914 
915  print "\t".'<tr class="oddeven">'."\n";
916  print '<td class="nowrap tdtop">';
917  print $contact->getNomUrl(1, 'category');
918  if ($contact->socid > 0) {
919  $objsoc->fetch($contact->socid);
920  print ' - ';
921  print $objsoc->getNomUrl(1, 'contact');
922  }
923  print "</td>\n";
924  // Link to delete from category
925  print '<td class="right">';
926  if ($permission) {
927  print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&type=".$typeid."&action=unlink&token=".newToken()."&removeelem=".$contact->id."'>";
928  print $langs->trans("DeleteFromCat");
929  print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');
930  print "</a>";
931  }
932  print '</td>';
933  print "</tr>\n";
934  }
935  } else {
936  print '<tr class="oddeven"><td colspan="2"><span class="opacitymedium">'.$langs->trans("ThisCategoryHasNoItems").'</span></td></tr>';
937  }
938  print "</table>\n";
939 
940  print '</form>'."\n";
941  }
942  } else {
943  print_barre_liste($langs->trans("Contact"), null, $_SERVER["PHP_SELF"], '', '', '', '', '', '', 'contact');
944  accessforbidden("NotEnoughPermissions", 0, 0);
945  }
946 }
947 
948 // List of bank accounts
949 if ($type == Categorie::TYPE_ACCOUNT) {
950  if ($user->hasRight("banque", "read")) {
951  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
952 
953  $permission = $user->hasRight('banque', 'creer');
954 
955  $accounts = $object->getObjectsInCateg($type, 0, $limit, $offset);
956  if ($accounts < 0) {
957  dol_print_error($db, $object->error, $object->errors);
958  } else {
960  '@phan-var-force Account[] $accounts';
961  // Form to add record into a category
962  $showclassifyform = 1;
963  if ($showclassifyform) {
964  print '<br>';
965  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
966  print '<input type="hidden" name="token" value="'.newToken().'">';
967  print '<input type="hidden" name="typeid" value="'.$typeid.'">';
968  print '<input type="hidden" name="type" value="'.$typeid.'">';
969  print '<input type="hidden" name="id" value="'.$object->id.'">';
970  print '<input type="hidden" name="action" value="addintocategory">';
971  print '<table class="noborder centpercent">';
972  print '<tr class="liste_titre"><td>';
973  print $langs->trans("AddObjectIntoCategory").' &nbsp;';
974  print $form->select_comptes('', 'elemid', 0, '', 0, '', 0, '', 1);
975  print '<input type="submit" class="button buttongen" value="'.$langs->trans("ClassifyInCategory").'"></td>';
976  print '</tr>';
977  print '</table>';
978  print '</form>';
979  }
980 
981  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
982  print '<input type="hidden" name="token" value="'.newToken().'">';
983  print '<input type="hidden" name="typeid" value="'.$typeid.'">';
984  print '<input type="hidden" name="type" value="'.$typeid.'">';
985  print '<input type="hidden" name="id" value="'.$object->id.'">';
986  print '<input type="hidden" name="action" value="list">';
987 
988  print '<br>';
989  $param = '&limit='.$limit.'&id='.$id.'&type='.$type;
990  $num = count($accounts);
991  $nbtotalofrecords = '';
992  $newcardbutton = '';
993 
994  // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
995  print_barre_liste($langs->trans("Account"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'bank_account', 0, $newcardbutton, '', $limit);
996 
997  print '<table class="noborder centpecent">'."\n";
998  print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Ref").'</td></tr>'."\n";
999 
1000  if (count($accounts) > 0) {
1001  $i = 0;
1002  foreach ($accounts as $key => $account) {
1003  $i++;
1004  if ($i > $limit) {
1005  break;
1006  }
1007 
1008  print "\t".'<tr class="oddeven">'."\n";
1009  print '<td class="nowrap tdtop">';
1010  print $account->getNomUrl(1, 0);
1011  print "</td>\n";
1012  print '<td class="tdtop">'.$account->bank."</td>\n";
1013  print '<td class="tdtop">'.$account->number."</td>\n";
1014  // Link to delete from category
1015  print '<td class="right">';
1016  if ($permission) {
1017  print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&type=".$typeid."&action=unlink&token=".newToken()."&removeelem=".$account->id."'>";
1018  print $langs->trans("DeleteFromCat");
1019  print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');
1020  print "</a>";
1021  }
1022  print '</td>';
1023  print "</tr>\n";
1024  }
1025  } else {
1026  print '<tr class="oddeven"><td colspan="4"><span class="opacitymedium">'.$langs->trans("ThisCategoryHasNoItems").'</span></td></tr>';
1027  }
1028  print "</table>\n";
1029 
1030  print '</form>'."\n";
1031  }
1032  } else {
1033  print_barre_liste($langs->trans("Banque"), null, $_SERVER["PHP_SELF"], '', '', '', '', '', '', 'bank');
1034  accessforbidden("NotEnoughPermissions", 0, 0);
1035  }
1036 }
1037 
1038 // List of Project
1039 if ($type == Categorie::TYPE_PROJECT) {
1040  if ($user->hasRight("project", "read")) {
1041  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1042 
1043  $permission = $user->hasRight('projet', 'creer');
1044 
1045  $objects = $object->getObjectsInCateg($type, 0, $limit, $offset);
1046  if ($objects < 0) {
1047  dol_print_error($db, $object->error, $object->errors);
1048  } else {
1050  '@phan-var-force Project $object';
1051  // Form to add record into a category
1052  $showclassifyform = 1;
1053  if ($showclassifyform) {
1054  print '<br>';
1055  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
1056  print '<input type="hidden" name="token" value="'.newToken().'">';
1057  print '<input type="hidden" name="typeid" value="'.$typeid.'">';
1058  print '<input type="hidden" name="type" value="'.$typeid.'">';
1059  print '<input type="hidden" name="id" value="'.$object->id.'">';
1060  print '<input type="hidden" name="action" value="addintocategory">';
1061  print '<table class="noborder centpercent">';
1062  print '<tr class="liste_titre"><td>';
1063  print $langs->trans("AddObjectIntoCategory").' &nbsp;';
1064  $form->selectProjects('', 'elemid');
1065  print '<input type="submit" class="button buttongen" value="'.$langs->trans("ClassifyInCategory").'"></td>';
1066  print '</tr>';
1067  print '</table>';
1068  print '</form>';
1069  }
1070 
1071  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
1072  print '<input type="hidden" name="token" value="'.newToken().'">';
1073  print '<input type="hidden" name="typeid" value="'.$typeid.'">';
1074  print '<input type="hidden" name="type" value="'.$typeid.'">';
1075  print '<input type="hidden" name="id" value="'.$object->id.'">';
1076  print '<input type="hidden" name="action" value="list">';
1077 
1078  print '<br>';
1079  $param = '&limit='.$limit.'&id='.$id.'&type='.$type;
1080  $num = count($objects);
1081  $nbtotalofrecords = '';
1082  $newcardbutton = '';
1083 
1084  // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1085  print_barre_liste($langs->trans("Project"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'project', 0, $newcardbutton, '', $limit);
1086 
1087  print '<table class="noborder centpecent">'."\n";
1088  print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Ref").'</td></tr>'."\n";
1089 
1090  if (count($objects) > 0) {
1091  $i = 0;
1092  foreach ($objects as $key => $project) {
1093  $i++;
1094  if ($i > $limit) {
1095  break;
1096  }
1097 
1098  print "\t".'<tr class="oddeven">'."\n";
1099  print '<td class="nowrap tdtop">';
1100  print $project->getNomUrl(1);
1101  print "</td>\n";
1102  print '<td class="tdtop">'.$project->ref."</td>\n";
1103  print '<td class="tdtop">'.$project->title."</td>\n";
1104  // Link to delete from category
1105  print '<td class="right">';
1106  if ($permission) {
1107  print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&type=".$typeid."&action=unlink&token=".newToken()."&removeelem=".$project->id."'>";
1108  print $langs->trans("DeleteFromCat");
1109  print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');
1110  print "</a>";
1111  }
1112  print '</td>';
1113  print "</tr>\n";
1114  }
1115  } else {
1116  print '<tr class="oddeven"><td colspan="4"><span class="opacitymedium">'.$langs->trans("ThisCategoryHasNoItems").'</span></td></tr>';
1117  }
1118  print "</table>\n";
1119 
1120  print '</form>'."\n";
1121  }
1122  } else {
1123  print_barre_liste($langs->trans("Project"), null, $_SERVER["PHP_SELF"], '', '', '', '', '', '', 'project');
1124  accessforbidden("NotEnoughPermissions", 0, 0);
1125  }
1126 }
1127 
1128 // List of users
1129 if ($type == Categorie::TYPE_USER) {
1130  if ($user->hasRight("user", "user", "read")) {
1131  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1132 
1133  $users = $object->getObjectsInCateg($type);
1134  if ($users < 0) {
1135  dol_print_error($db, $object->error, $object->errors);
1136  } else {
1138  '@phan-var-force User[] $users';
1139  // Form to add record into a category
1140  $showclassifyform = 1;
1141  if ($showclassifyform) {
1142  print '<br>';
1143  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
1144  print '<input type="hidden" name="token" value="'.newToken().'">';
1145  print '<input type="hidden" name="typeid" value="'.$typeid.'">';
1146  print '<input type="hidden" name="type" value="'.$typeid.'">';
1147  print '<input type="hidden" name="id" value="'.$object->id.'">';
1148  print '<input type="hidden" name="action" value="addintocategory">';
1149  print '<table class="noborder centpercent">';
1150  print '<tr class="liste_titre"><td>';
1151  $force_entity = getEntity($object->element); // So we will get same filter than the getObjectsInCateg()
1152  print img_picto('', $type, 'class="pictofixedwidth"');
1153  print $form->select_dolusers('', 'elemid', 1, null, 0, '', '', $force_entity);
1154  print '<input type="submit" class="button buttongen" value="'.$langs->trans("ClassifyInCategory").'"></td>';
1155  print '</tr>';
1156  print '</table>';
1157  print '</form>';
1158  }
1159  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
1160  print '<input type="hidden" name="token" value="'.newToken().'">';
1161  print '<input type="hidden" name="typeid" value="'.$typeid.'">';
1162  print '<input type="hidden" name="type" value="'.$typeid.'">';
1163  print '<input type="hidden" name="id" value="'.$object->id.'">';
1164  print '<input type="hidden" name="action" value="list">';
1165 
1166  print '<br>';
1167 
1168  $param = '&limit='.$limit.'&id='.$id.'&type='.$type;
1169  $num = count($users);
1170  $nbtotalofrecords = '';
1171  $newcardbutton = '';
1172 
1173  // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1174  print_barre_liste($langs->trans("Users"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'user', 0, '', '', $limit);
1175 
1176  print '<table class="noborder centpecent">'."\n";
1177  print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Users").' <span class="badge">'.$num.'</span></td></tr>'."\n";
1178 
1179  if (count($users) > 0) {
1180  // Use "$userentry" here, because "$user" is the current user
1181  foreach ($users as $key => $userentry) {
1182  print "\t".'<tr class="oddeven">'."\n";
1183  print '<td class="nowrap tdtop">';
1184  print $userentry->getNomUrl(-1);
1185  print "</td>\n";
1186  print '<td class="tdtop">'.$userentry->job."</td>\n";
1187 
1188  // Link to delete from category
1189  print '<td class="right">';
1190  if ($user->hasRight('user', 'user', 'creer')) {
1191  print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&type=".$typeid."&action=unlink&token=".newToken()."&removeelem=".$userentry->id."'>";
1192  print $langs->trans("DeleteFromCat");
1193  print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');
1194  print "</a>";
1195  }
1196  print '</td>';
1197  print "</tr>\n";
1198  }
1199  } else {
1200  print '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans("ThisCategoryHasNoItems").'</span></td></tr>';
1201  }
1202  print "</table>\n";
1203 
1204  print '</form>'."\n";
1205  }
1206  } else {
1207  print_barre_liste($langs->trans("Users"), null, $_SERVER["PHP_SELF"], '', '', '', '', '', '', 'user');
1208  accessforbidden("NotEnoughPermissions", 0, 0);
1209  }
1210 }
1211 
1212 
1213 // List of warehouses
1214 if ($type == Categorie::TYPE_WAREHOUSE) {
1215  if ($user->hasRight("stock", "read")) {
1216  $permission = $user->hasRight('stock', 'creer');
1217 
1218  require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
1219 
1220  $objects = $object->getObjectsInCateg($type, 0, $limit, $offset);
1221  if ($objects < 0) {
1222  dol_print_error($db, $object->error, $object->errors);
1223  } else {
1225  '@phan-var-force Entrepot[] $objects';
1226  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
1227  print '<input type="hidden" name="token" value="'.newToken().'">';
1228  print '<input type="hidden" name="typeid" value="'.$typeid.'">';
1229  print '<input type="hidden" name="type" value="'.$typeid.'">';
1230  print '<input type="hidden" name="id" value="'.$object->id.'">';
1231  print '<input type="hidden" name="action" value="list">';
1232 
1233  print '<br>';
1234  $param = '&limit='.$limit.'&id='.$id.'&type='.$type;
1235  $num = count($objects);
1236  $nbtotalofrecords = '';
1237  $newcardbutton = '';
1238 
1239  // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1240  print_barre_liste($langs->trans("Warehouses"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'stock', 0, $newcardbutton, '', $limit);
1241 
1242  print '<table class="noborder centpecent">'."\n";
1243  print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Ref").'</td></tr>'."\n";
1244 
1245  if (count($objects) > 0) {
1246  $i = 0;
1247  foreach ($objects as $key => $warehouse) {
1248  $i++;
1249  if ($i > $limit) {
1250  break;
1251  }
1252 
1253  print "\t".'<tr class="oddeven">'."\n";
1254  print '<td class="nowrap tdtop">';
1255  print $warehouse->getNomUrl(1);
1256  print "</td>\n";
1257  print '<td class="tdtop">'.$warehouse->ref."</td>\n";
1258  print '<td class="tdtop">'.$warehouse->lieu."</td>\n";
1259  // Link to delete from category
1260  print '<td class="right">';
1261  if ($permission) {
1262  print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&type=".$typeid."&action=unlink&token=".newToken()."&removeelem=".$warehouse->id."'>";
1263  print $langs->trans("DeleteFromCat");
1264  print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');
1265  print "</a>";
1266  }
1267  print '</td>';
1268  print "</tr>\n";
1269  }
1270  } else {
1271  print '<tr class="oddeven"><td colspan="4"><span class="opacitymedium">'.$langs->trans("ThisCategoryHasNoItems").'</span></td></tr>';
1272  }
1273  print "</table>\n";
1274 
1275  print '</form>'."\n";
1276  }
1277  } else {
1278  print_barre_liste($langs->trans("Warehouse"), null, $_SERVER["PHP_SELF"], '', '', '', '', '', '', 'stock');
1279  accessforbidden("NotEnoughPermissions", 0, 0);
1280  }
1281 }
1282 
1283 // List of tickets
1284 if ($type == Categorie::TYPE_TICKET) {
1285  if ($user->hasRight("ticket", "read")) {
1286  $permission = ($user->rights->categorie->creer || $user->rights->categorie->creer);
1287 
1288  $tickets = $object->getObjectsInCateg($type, 0, $limit, $offset);
1289  if ($tickets < 0) {
1290  dol_print_error($db, $object->error, $object->errors);
1291  } else {
1293  '@phan-var-force Ticket[] $tickets';
1294  // Form to add record into a category
1295  $showclassifyform = 1;
1296  if ($showclassifyform) {
1297  print '<br>';
1298  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
1299  print '<input type="hidden" name="token" value="'.newToken().'">';
1300  print '<input type="hidden" name="typeid" value="'.$typeid.'">';
1301  print '<input type="hidden" name="type" value="'.$typeid.'">';
1302  print '<input type="hidden" name="id" value="'.$object->id.'">';
1303  print '<input type="hidden" name="action" value="addintocategory">';
1304  print '<table class="noborder centpercent">';
1305  print '<tr class="liste_titre"><td>';
1306  print $langs->trans("AddTicketIntoCategory").' &nbsp;';
1307  $form->selectTickets('', 'elemid');
1308  print '<input type="submit" class="button buttongen" value="'.$langs->trans("ClassifyInCategory").'"></td>';
1309  print '</tr>';
1310  print '</table>';
1311  print '</form>';
1312  }
1313 
1314  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
1315  print '<input type="hidden" name="token" value="'.newToken().'">';
1316  print '<input type="hidden" name="typeid" value="'.$typeid.'">';
1317  print '<input type="hidden" name="type" value="'.$typeid.'">';
1318  print '<input type="hidden" name="id" value="'.$object->id.'">';
1319  print '<input type="hidden" name="action" value="list">';
1320 
1321  print '<br>';
1322  $param = '&limit='.$limit.'&id='.$id.'&type='.$type;
1323  $num = count($tickets);
1324  $nbtotalofrecords = '';
1325  $newcardbutton = '';
1326 
1327  // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1328  print_barre_liste($langs->trans("Ticket"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'ticket', 0, $newcardbutton, '', $limit);
1329 
1330 
1331  print '<table class="noborder centpercent">'."\n";
1332  print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Ref").'</td></tr>'."\n";
1333 
1334  if (count($tickets) > 0) {
1335  $i = 0;
1336  foreach ($tickets as $ticket) {
1337  $i++;
1338  if ($i > $limit) {
1339  break;
1340  }
1341 
1342  print "\t".'<tr class="oddeven">'."\n";
1343  print '<td class="nowrap tdtop">';
1344  print $ticket->getNomUrl(1);
1345  print "</td>\n";
1346  print '<td class="tdtop">'.$ticket->label."</td>\n";
1347  // Link to delete from category
1348  print '<td class="right">';
1349  if ($permission) {
1350  print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&type=".$typeid."&action=unlink&token=".newToken()."&removeelem=".$ticket->id."'>";
1351  print $langs->trans("DeleteFromCat");
1352  print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');
1353  print "</a>";
1354  }
1355  print '</td>';
1356  print "</tr>\n";
1357  }
1358  } else {
1359  print '<tr class="oddeven"><td colspan="2"><span class="opacitymedium">'.$langs->trans("ThisCategoryHasNoItems").'</span></td></tr>';
1360  }
1361  print "</table>\n";
1362 
1363  print '</form>'."\n";
1364  }
1365  } else {
1366  print_barre_liste($langs->trans("Ticket"), null, $_SERVER["PHP_SELF"], '', '', '', '', '', '', 'ticket');
1367  accessforbidden("NotEnoughPermissions", 0, 0);
1368  }
1369 }
1370 
1371 // Note that $action and $object may have been modified by some hooks
1372 $parameters = array('type' => $type, 'id' => $id, 'label' => $label);
1373 $reshook = $hookmanager->executeHooks('addMoreCategoriesList', $parameters, $object, $action);
1374 
1375 // End of page
1376 llxFooter();
1377 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:55
llxFooter()
Empty footer.
Definition: wrapper.php:69
categories_prepare_head(Categorie $object, $type)
Prepare array with list of tabs.
Class to manage bank accounts.
Class to manage members of a foundation.
Class to manage categories.
Class to manage contact/addresses.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation de composants html autre Only common components are here.
Class to manage products or services.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
Definition: user.class.php:50
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_view($titlealt='default', $float=0, $other='class="valignmiddle"')
Show logo view card.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
Class to generate the form for creating a new ticket.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree', $donoresetalreadyloaded=0, $showfk=0, $moreparam='')
Recursive function to output a tree.