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