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