dolibarr 21.0.0-beta
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-2024 Frédéric France <frederic.france@free.fr>
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
32require '../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
36
45// Load translation files required by the page
46$langs->load("categories");
47
48$id = GETPOSTINT('id');
49$type = (GETPOST('type', 'aZ09') ? GETPOST('type', 'aZ09') : Categorie::TYPE_PRODUCT);
50$catname = GETPOST('catname', 'alpha');
51$nosearch = GETPOSTINT('nosearch');
52
53$categstatic = new Categorie($db);
54if (is_numeric($type)) {
55 $type = Categorie::$MAP_ID_TO_CODE[(int) $type]; // For backward compatibility
56}
57
58// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array array
59$hookmanager->initHooks(array('categoryindex'));
60
61if (!$user->hasRight('categorie', 'lire')) {
63}
64
65
66/*
67 * View
68 */
69
70$form = new Form($db);
71
72$moreparam = ($nosearch ? '&nosearch=1' : '');
73
74$typetext = $type;
75if ($type == Categorie::TYPE_ACCOUNT) {
76 $title = $langs->trans('AccountsCategoriesArea');
77} elseif ($type == Categorie::TYPE_WAREHOUSE) {
78 $title = $langs->trans('StocksCategoriesArea');
79} elseif ($type == Categorie::TYPE_ACTIONCOMM) {
80 $title = $langs->trans('ActionCommCategoriesArea');
81} elseif ($type == Categorie::TYPE_WEBSITE_PAGE) {
82 $title = $langs->trans('WebsitePagesCategoriesArea');
83} else {
84 $title = $langs->trans(ucfirst($type).'sCategoriesArea');
85}
86
87$arrayofjs = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
88$arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
89
90llxHeader('', $title, '', '', 0, 0, $arrayofjs, $arrayofcss);
91
92$newcardbutton = '';
93if ($user->hasRight('categorie', 'creer')) {
94 $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);
95}
96
97print load_fiche_titre($title, $newcardbutton, 'object_category');
98
99// Search categories
100if (empty($nosearch)) {
101 print '<div class="fichecenter"><div class="fichehalfleft">';
102
103
104 print '<form method="post" action="index.php?type='.$type.'">';
105 print '<input type="hidden" name="token" value="'.newToken().'">';
106 print '<input type="hidden" name="type" value="'.$type.'">';
107 print '<input type="hidden" name="nosearch" value="'.$nosearch.'">';
108
109
110 print '<table class="noborder nohover centpercent">';
111 print '<tr class="liste_titre">';
112 print '<td colspan="3">'.$langs->trans("Search").'</td>';
113 print '</tr>';
114 print '<tr class="oddeven nohover"><td>';
115 print $langs->trans("Name").':</td><td><input class="flat inputsearch" type="text" name="catname" value="'.dol_escape_htmltag($catname).'"></td>';
116 print '<td><input type="submit" class="button small" value="'.$langs->trans("Search").'"></td></tr>';
117 print '</table></form>';
118
119
120 print '</div><div class="fichehalfright">';
121
122
123 /*
124 * Categories found
125 */
126 if ($catname || $id > 0) {
127 $cats = $categstatic->rechercher($id, $catname, $typetext);
128
129 print '<table class="noborder centpercent">';
130 print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("FoundCats").'</td></tr>';
131
132 foreach ($cats as $cat) {
133 $categstatic->id = $cat->id;
134 $categstatic->ref = $cat->label;
135 $categstatic->label = $cat->label;
136 $categstatic->type = $cat->type;
137 $categstatic->color = $cat->color;
138 $color = $categstatic->color ? ' style="background: #'.sprintf("%06s", $categstatic->color).';"' : ' style="background: #bbb"';
139
140 print "\t".'<tr class="oddeven">'."\n";
141 print "\t\t<td>";
142 print '<span class="noborderoncategories"'.$color.'>';
143 print $categstatic->getNomUrl(1, '');
144 print '</span>';
145 print "</td>\n";
146 print "\t\t<td>";
147 $text = dolGetFirstLineOfText(dol_string_nohtmltag($cat->description, 1));
148 $trunclength = 48;
149 print $form->textwithtooltip(dol_trunc($text, $trunclength), $cat->description);
150 print "</td>\n";
151 print "\t</tr>\n";
152 }
153 print "</table>";
154 } else {
155 print '&nbsp;';
156 }
157
158 print '</div></div>';
159}
160
161print '<div class="fichecenter"><br>';
162
163
164// Charge tableau des categories
165$cate_arbo = $categstatic->get_full_arbo($typetext);
166
167// Define fulltree array
168$fulltree = $cate_arbo;
169
170// Load possible missing includes
171if (getDolGlobalString('CATEGORY_SHOW_COUNTS')) {
172 if ($type == Categorie::TYPE_MEMBER) {
173 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
174 }
175 if ($type == Categorie::TYPE_ACCOUNT) {
176 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
177 }
178 if ($type == Categorie::TYPE_PROJECT) {
179 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
180 }
181 if ($type == Categorie::TYPE_USER) {
182 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
183 }
184}
185
186// Define data (format for treeview)
187$data = array();
188$data[] = array('rowid' => 0, 'fk_menu' => -1, 'title' => 'racine', 'mainmenu' => '', 'leftmenu' => '', 'fk_mainmenu' => '', 'fk_leftmenu' => '');
189foreach ($fulltree as $key => $val) {
190 $categstatic->id = $val['id'];
191 $categstatic->ref = $val['label'];
192 $categstatic->color = $val['color'];
193 $categstatic->type = $type;
194 $desc = dol_htmlcleanlastbr($val['description']);
195
196 $counter = '';
197 if (getDolGlobalString('CATEGORY_SHOW_COUNTS')) {
198 // we need only a count of the elements, so it is enough to consume only the id's from the database
199 $elements = $type == Categorie::TYPE_ACCOUNT
200 ? $categstatic->getObjectsInCateg("account", 1) // Categorie::TYPE_ACCOUNT is "bank_account" instead of "account"
201 : $categstatic->getObjectsInCateg($type, 1);
202
203 $counter = "<td class='left' width='40px;'>".(is_array($elements) ? count($elements) : '0')."</td>";
204 }
205
206 $color = $categstatic->color ? ' style="background: #'.sprintf("%06s", $categstatic->color).';"' : ' style="background: #bbb"';
207 $li = $categstatic->getNomUrl(1, '', 60, '&backtolist='.urlencode($_SERVER["PHP_SELF"].'?type='.$type.$moreparam));
208
209 $entry = '<table class="nobordernopadding centpercent">';
210 $entry .= '<tr>';
211
212 $entry .= '<td>';
213 $entry .= '<span class="noborderoncategories" '.$color.'>'.$li.'</span>';
214 $entry .= '</td>';
215
216 // Add column counter
217 $entry .= $counter;
218
219 $entry .= '<td class="right" width="30px;">';
220 $entry .= '<a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.$val['id'].'&type='.urlencode($type).$moreparam.'&backtolist='.urlencode($_SERVER["PHP_SELF"].'?type='.urlencode($type)).'">'.img_view().'</a>';
221 $entry .= '</td>';
222 $entry .= '<td class="right" width="30px;">';
223 if ($user->hasRight('categorie', 'creer')) {
224 $entry .= '<a class="editfielda" href="' . DOL_URL_ROOT . '/categories/edit.php?id=' . $val['id'] . '&type=' . urlencode($type) . $moreparam . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?type=' . urlencode($type)) . '">' . img_edit() . '</a>';
225 }
226 $entry .= '</td>';
227 $entry .= '<td class="right" width="30px;">';
228 if ($user->hasRight('categorie', 'supprimer')) {
229 $entry .= '<a class="deletefilelink" href="' . DOL_URL_ROOT . '/categories/viewcat.php?action=delete&token=' . newToken() . '&id=' . $val['id'] . '&type=' . urlencode($type) . $moreparam . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?type=' . urlencode($type) . $moreparam) . '&backtolist=' . urlencode($_SERVER["PHP_SELF"] . '?type=' . urlencode($type) . $moreparam) . '">' . img_delete() . '</a>';
230 }
231 $entry .= '</td>';
232
233 $entry .= '</tr>';
234 $entry .= '</table>';
235
236 $data[] = array('rowid' => $val['rowid'], 'fk_menu' => $val['fk_parent'], 'entry' => $entry);
237}
238
239
240$nbofentries = (count($data) - 1);
241
242$morethan1level = 0;
243foreach ($data as $record) {
244 if (!empty($record['fk_menu']) && $record['fk_menu'] > 0) {
245 $morethan1level = 1;
246 }
247}
248
249
250print '<table class="liste nohover centpercent noborder">';
251print '<tr class="liste_titre"><td>'.$langs->trans("Categories").'</td><td></td><td class="right">';
252if ($morethan1level && !empty($conf->use_javascript_ajax)) {
253 print '<div id="iddivjstreecontrol">';
254 print '<a class="notasortlink" href="#">'.img_picto('', 'folder', 'class="paddingright"').'<span class="hideonsmartphone">'.$langs->trans("UndoExpandAll").'</span></a>';
255 print ' | ';
256 print '<a class="notasortlink" href="#">'.img_picto('', 'folder-open', 'class="paddingright"').'<span class="hideonsmartphone">'.$langs->trans("ExpandAll").'</span></a>';
257 print '</div>';
258}
259print '</td></tr>';
260
261if ($nbofentries > 0) {
262 print '<tr class="oddeven"><td colspan="3">';
263 tree_recur($data, $data[0], 0);
264 print '</td></tr>';
265} else {
266 print '<tr class="oddeven">';
267 print '<td colspan="3"><table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('', 'treemenu/branchbottom.gif').'</td>';
268 print '<td class="valignmiddle">';
269 print $langs->trans("NoCategoryYet");
270 print '</td>';
271 print '<td>&nbsp;</td>';
272 print '</table></td>';
273 print '</tr>';
274}
275
276print "</table>";
277
278print '</div>';
279
280// End of page
281llxFooter();
282$db->close();
$id
Definition account.php:48
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage categories.
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify 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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.