dolibarr  19.0.0-dev
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
3  * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
4  * Copyright (C) 2006-2016 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
6  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
7  * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
8  * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
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/treeview.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
35 
36 // Load translation files required by the page
37 $langs->load("categories");
38 
39 $id = GETPOST('id', 'int');
40 $type = (GETPOST('type', 'aZ09') ? GETPOST('type', 'aZ09') : Categorie::TYPE_PRODUCT);
41 $catname = GETPOST('catname', 'alpha');
42 $nosearch = GETPOST('nosearch', 'int');
43 
44 $categstatic = new Categorie($db);
45 if (is_numeric($type)) {
46  $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
47 }
48 
49 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array
50 $hookmanager->initHooks(array('categoryindex'));
51 
52 if (!$user->hasRight('categorie', 'lire')) {
54 }
55 
56 
57 /*
58  * View
59  */
60 
61 $form = new Form($db);
62 
63 $moreparam = ($nosearch ? '&nosearch=1' : '');
64 
65 $typetext = $type;
66 if ($type == Categorie::TYPE_ACCOUNT) {
67  $title = $langs->trans('AccountsCategoriesArea');
68 } elseif ($type == Categorie::TYPE_WAREHOUSE) {
69  $title = $langs->trans('StocksCategoriesArea');
70 } elseif ($type == Categorie::TYPE_ACTIONCOMM) {
71  $title = $langs->trans('ActionCommCategoriesArea');
72 } elseif ($type == Categorie::TYPE_WEBSITE_PAGE) {
73  $title = $langs->trans('WebsitePagesCategoriesArea');
74 } else {
75  $title = $langs->trans(ucfirst($type).'sCategoriesArea');
76 }
77 
78 $arrayofjs = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
79 $arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
80 
81 llxHeader('', $title, '', '', 0, 0, $arrayofjs, $arrayofcss);
82 
83 $newcardbutton = '';
84 if (!empty($user->rights->categorie->creer)) {
85  $newcardbutton .= dolGetButtonTitle($langs->trans('NewCategory'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/categories/card.php?action=create&type='.$type.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?type='.$type.$moreparam).$moreparam);
86 }
87 
88 print load_fiche_titre($title, $newcardbutton, 'object_category');
89 
90 // Search categories
91 if (empty($nosearch)) {
92  print '<div class="fichecenter"><div class="fichehalfleft">';
93 
94 
95  print '<form method="post" action="index.php?type='.$type.'">';
96  print '<input type="hidden" name="token" value="'.newToken().'">';
97  print '<input type="hidden" name="type" value="'.$type.'">';
98  print '<input type="hidden" name="nosearch" value="'.$nosearch.'">';
99 
100 
101  print '<table class="noborder nohover centpercent">';
102  print '<tr class="liste_titre">';
103  print '<td colspan="3">'.$langs->trans("Search").'</td>';
104  print '</tr>';
105  print '<tr class="oddeven nohover"><td>';
106  print $langs->trans("Name").':</td><td><input class="flat inputsearch" type="text" name="catname" value="'.dol_escape_htmltag($catname).'"></td>';
107  print '<td><input type="submit" class="button small" value="'.$langs->trans("Search").'"></td></tr>';
108  print '</table></form>';
109 
110 
111  print '</div><div class="fichehalfright">';
112 
113 
114  /*
115  * Categories found
116  */
117  if ($catname || $id > 0) {
118  $cats = $categstatic->rechercher($id, $catname, $typetext);
119 
120  print '<table class="noborder centpercent">';
121  print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("FoundCats").'</td></tr>';
122 
123  foreach ($cats as $cat) {
124  $categstatic->id = $cat->id;
125  $categstatic->ref = $cat->label;
126  $categstatic->label = $cat->label;
127  $categstatic->type = $cat->type;
128  $categstatic->color = $cat->color;
129  $color = $categstatic->color ? ' style="background: #'.sprintf("%06s", $categstatic->color).';"' : ' style="background: #bbb"';
130 
131  print "\t".'<tr class="oddeven">'."\n";
132  print "\t\t<td>";
133  print '<span class="noborderoncategories"'.$color.'>';
134  print $categstatic->getNomUrl(1, '');
135  print '</span>';
136  print "</td>\n";
137  print "\t\t<td>";
138  $text = dolGetFirstLineOfText(dol_string_nohtmltag($cat->description, 1));
139  $trunclength = 48;
140  print $form->textwithtooltip(dol_trunc($text, $trunclength), $cat->description);
141  print "</td>\n";
142  print "\t</tr>\n";
143  }
144  print "</table>";
145  } else {
146  print '&nbsp;';
147  }
148 
149  print '</div></div>';
150 }
151 
152 print '<div class="fichecenter"><br>';
153 
154 
155 // Charge tableau des categories
156 $cate_arbo = $categstatic->get_full_arbo($typetext);
157 
158 // Define fulltree array
159 $fulltree = $cate_arbo;
160 
161 // Load possible missing includes
162 if (!empty($conf->global->CATEGORY_SHOW_COUNTS)) {
163  if ($type == Categorie::TYPE_MEMBER) {
164  require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
165  }
166  if ($type == Categorie::TYPE_ACCOUNT) {
167  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
168  }
169  if ($type == Categorie::TYPE_PROJECT) {
170  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
171  }
172  if ($type == Categorie::TYPE_USER) {
173  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
174  }
175 }
176 
177 // Define data (format for treeview)
178 $data = array();
179 $data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
180 foreach ($fulltree as $key => $val) {
181  $categstatic->id = $val['id'];
182  $categstatic->ref = $val['label'];
183  $categstatic->color = $val['color'];
184  $categstatic->type = $type;
185  $desc = dol_htmlcleanlastbr($val['description']);
186 
187  $counter = '';
188  if (!empty($conf->global->CATEGORY_SHOW_COUNTS)) {
189  // we need only a count of the elements, so it is enough to consume only the id's from the database
190  $elements = $type == Categorie::TYPE_ACCOUNT
191  ? $categstatic->getObjectsInCateg("account", 1) // Categorie::TYPE_ACCOUNT is "bank_account" instead of "account"
192  : $categstatic->getObjectsInCateg($type, 1);
193 
194  $counter = "<td class='left' width='40px;'>".(is_array($elements) ? count($elements) : '0')."</td>";
195  }
196 
197  $color = $categstatic->color ? ' style="background: #'.sprintf("%06s", $categstatic->color).';"' : ' style="background: #bbb"';
198  $li = $categstatic->getNomUrl(1, '', 60, '&backtolist='.urlencode($_SERVER["PHP_SELF"].'?type='.$type.$moreparam));
199 
200  $entry = '<table class="nobordernopadding centpercent">';
201  $entry .= '<tr>';
202 
203  $entry .= '<td>';
204  $entry .= '<span class="noborderoncategories" '.$color.'>'.$li.'</span>';
205  $entry .= '</td>';
206 
207  $entry .= $counter;
208 
209  $entry .= '<td class="right" width="20px;">';
210  $entry .= '<a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.$val['id'].'&type='.$type.$moreparam.'&backtolist='.urlencode($_SERVER["PHP_SELF"].'?type='.$type).'">'.img_view().'</a>';
211  $entry .= '</td>';
212  $entry .= '<td class="right" width="20px;">';
213  if ($user->rights->categorie->creer) {
214  $entry .= '<a class="editfielda" href="' . DOL_URL_ROOT . '/categories/edit.php?id=' . $val['id'] . '&type=' . $type . $moreparam . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?type=' . $type) . '">' . img_edit() . '</a>';
215  }
216  $entry .= '</td>';
217  $entry .= '<td class="right" width="20px;">';
218  if ($user->rights->categorie->supprimer) {
219  $entry .= '<a class="deletefilelink" href="' . DOL_URL_ROOT . '/categories/viewcat.php?action=delete&token=' . newToken() . '&id=' . $val['id'] . '&type=' . $type . $moreparam . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?type=' . $type . $moreparam) . '&backtolist=' . urlencode($_SERVER["PHP_SELF"] . '?type=' . $type . $moreparam) . '">' . img_delete() . '</a>';
220  }
221  $entry .= '</td>';
222 
223  $entry .= '</tr>';
224  $entry .= '</table>';
225 
226  $data[] = array('rowid' => $val['rowid'], 'fk_menu' => $val['fk_parent'], 'entry' => $entry);
227 }
228 
229 
230 $nbofentries = (count($data) - 1);
231 
232 $morethan1level = 0;
233 foreach ($data as $record) {
234  if (!empty($record['fk_menu']) && $record['fk_menu'] > 0) {
235  $morethan1level = 1;
236  }
237 }
238 
239 
240 print '<table class="liste nohover centpercent">';
241 print '<tr class="liste_titre"><td>'.$langs->trans("Categories").'</td><td></td><td class="right">';
242 if ($morethan1level && !empty($conf->use_javascript_ajax)) {
243  print '<div id="iddivjstreecontrol">';
244  print '<a class="notasortlink" href="#">'.img_picto('', 'folder', 'class="paddingright"').'<span class="hideonsmartphone">'.$langs->trans("UndoExpandAll").'</span></a>';
245  print ' | ';
246  print '<a class="notasortlink" href="#">'.img_picto('', 'folder-open', 'class="paddingright"').'<span class="hideonsmartphone">'.$langs->trans("ExpandAll").'</span></a>';
247  print '</div>';
248 }
249 print '</td></tr>';
250 
251 if ($nbofentries > 0) {
252  print '<tr class="oddeven"><td colspan="3">';
253  tree_recur($data, $data[0], 0);
254  print '</td></tr>';
255 } else {
256  print '<tr class="oddeven">';
257  print '<td colspan="3"><table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('', 'treemenu/branchbottom.gif').'</td>';
258  print '<td class="valignmiddle">';
259  print $langs->trans("NoCategoryYet");
260  print '</td>';
261  print '<td>&nbsp;</td>';
262  print '</table></td>';
263  print '</tr>';
264 }
265 
266 print "</table>";
267 
268 print '</div>';
269 
270 // End of page
271 llxFooter();
272 $db->close();
Class to manage categories.
Class to manage generation of HTML components Only common components must be here.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
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.
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.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
llxFooter()
Footer empty.
Definition: index.php:71
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
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.