/
index.php
273 lines (220 loc) · 10 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php
/* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
* Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2006-2016 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/categories/index.php
* \ingroup category
* \brief Home page of category area
*/
// Load Dolibarr environment
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
// Load translation files required by the page
$langs->load("categories");
$id = GETPOSTINT('id');
$type = (GETPOST('type', 'aZ09') ? GETPOST('type', 'aZ09') : Categorie::TYPE_PRODUCT);
$catname = GETPOST('catname', 'alpha');
$nosearch = GETPOSTINT('nosearch');
$categstatic = new Categorie($db);
if (is_numeric($type)) {
$type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
}
// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('categoryindex'));
if (!$user->hasRight('categorie', 'lire')) {
accessforbidden();
}
/*
* View
*/
$form = new Form($db);
$moreparam = ($nosearch ? '&nosearch=1' : '');
$typetext = $type;
if ($type == Categorie::TYPE_ACCOUNT) {
$title = $langs->trans('AccountsCategoriesArea');
} elseif ($type == Categorie::TYPE_WAREHOUSE) {
$title = $langs->trans('StocksCategoriesArea');
} elseif ($type == Categorie::TYPE_ACTIONCOMM) {
$title = $langs->trans('ActionCommCategoriesArea');
} elseif ($type == Categorie::TYPE_WEBSITE_PAGE) {
$title = $langs->trans('WebsitePagesCategoriesArea');
} else {
$title = $langs->trans(ucfirst($type).'sCategoriesArea');
}
$arrayofjs = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
$arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
llxHeader('', $title, '', '', 0, 0, $arrayofjs, $arrayofcss);
$newcardbutton = '';
if ($user->hasRight('categorie', 'creer')) {
$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);
}
print load_fiche_titre($title, $newcardbutton, 'object_category');
// Search categories
if (empty($nosearch)) {
print '<div class="fichecenter"><div class="fichehalfleft">';
print '<form method="post" action="index.php?type='.$type.'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="type" value="'.$type.'">';
print '<input type="hidden" name="nosearch" value="'.$nosearch.'">';
print '<table class="noborder nohover centpercent">';
print '<tr class="liste_titre">';
print '<td colspan="3">'.$langs->trans("Search").'</td>';
print '</tr>';
print '<tr class="oddeven nohover"><td>';
print $langs->trans("Name").':</td><td><input class="flat inputsearch" type="text" name="catname" value="'.dol_escape_htmltag($catname).'"></td>';
print '<td><input type="submit" class="button small" value="'.$langs->trans("Search").'"></td></tr>';
print '</table></form>';
print '</div><div class="fichehalfright">';
/*
* Categories found
*/
if ($catname || $id > 0) {
$cats = $categstatic->rechercher($id, $catname, $typetext);
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("FoundCats").'</td></tr>';
foreach ($cats as $cat) {
$categstatic->id = $cat->id;
$categstatic->ref = $cat->label;
$categstatic->label = $cat->label;
$categstatic->type = $cat->type;
$categstatic->color = $cat->color;
$color = $categstatic->color ? ' style="background: #'.sprintf("%06s", $categstatic->color).';"' : ' style="background: #bbb"';
print "\t".'<tr class="oddeven">'."\n";
print "\t\t<td>";
print '<span class="noborderoncategories"'.$color.'>';
print $categstatic->getNomUrl(1, '');
print '</span>';
print "</td>\n";
print "\t\t<td>";
$text = dolGetFirstLineOfText(dol_string_nohtmltag($cat->description, 1));
$trunclength = 48;
print $form->textwithtooltip(dol_trunc($text, $trunclength), $cat->description);
print "</td>\n";
print "\t</tr>\n";
}
print "</table>";
} else {
print ' ';
}
print '</div></div>';
}
print '<div class="fichecenter"><br>';
// Charge tableau des categories
$cate_arbo = $categstatic->get_full_arbo($typetext);
// Define fulltree array
$fulltree = $cate_arbo;
// Load possible missing includes
if (getDolGlobalString('CATEGORY_SHOW_COUNTS')) {
if ($type == Categorie::TYPE_MEMBER) {
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
}
if ($type == Categorie::TYPE_ACCOUNT) {
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
}
if ($type == Categorie::TYPE_PROJECT) {
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
}
if ($type == Categorie::TYPE_USER) {
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
}
}
// Define data (format for treeview)
$data = array();
$data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
foreach ($fulltree as $key => $val) {
$categstatic->id = $val['id'];
$categstatic->ref = $val['label'];
$categstatic->color = $val['color'];
$categstatic->type = $type;
$desc = dol_htmlcleanlastbr($val['description']);
$counter = '';
if (getDolGlobalString('CATEGORY_SHOW_COUNTS')) {
// we need only a count of the elements, so it is enough to consume only the id's from the database
$elements = $type == Categorie::TYPE_ACCOUNT
? $categstatic->getObjectsInCateg("account", 1) // Categorie::TYPE_ACCOUNT is "bank_account" instead of "account"
: $categstatic->getObjectsInCateg($type, 1);
$counter = "<td class='left' width='40px;'>".(is_array($elements) ? count($elements) : '0')."</td>";
}
$color = $categstatic->color ? ' style="background: #'.sprintf("%06s", $categstatic->color).';"' : ' style="background: #bbb"';
$li = $categstatic->getNomUrl(1, '', 60, '&backtolist='.urlencode($_SERVER["PHP_SELF"].'?type='.$type.$moreparam));
$entry = '<table class="nobordernopadding centpercent">';
$entry .= '<tr>';
$entry .= '<td>';
$entry .= '<span class="noborderoncategories" '.$color.'>'.$li.'</span>';
$entry .= '</td>';
// Add column counter
$entry .= $counter;
$entry .= '<td class="right" width="20px;">';
$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>';
$entry .= '</td>';
$entry .= '<td class="right" width="20px;">';
if ($user->hasRight('categorie', 'creer')) {
$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>';
}
$entry .= '</td>';
$entry .= '<td class="right" width="20px;">';
if ($user->hasRight('categorie', 'supprimer')) {
$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>';
}
$entry .= '</td>';
$entry .= '</tr>';
$entry .= '</table>';
$data[] = array('rowid' => $val['rowid'], 'fk_menu' => $val['fk_parent'], 'entry' => $entry);
}
$nbofentries = (count($data) - 1);
$morethan1level = 0;
foreach ($data as $record) {
if (!empty($record['fk_menu']) && $record['fk_menu'] > 0) {
$morethan1level = 1;
}
}
print '<table class="liste nohover centpercent">';
print '<tr class="liste_titre"><td>'.$langs->trans("Categories").'</td><td></td><td class="right">';
if ($morethan1level && !empty($conf->use_javascript_ajax)) {
print '<div id="iddivjstreecontrol">';
print '<a class="notasortlink" href="#">'.img_picto('', 'folder', 'class="paddingright"').'<span class="hideonsmartphone">'.$langs->trans("UndoExpandAll").'</span></a>';
print ' | ';
print '<a class="notasortlink" href="#">'.img_picto('', 'folder-open', 'class="paddingright"').'<span class="hideonsmartphone">'.$langs->trans("ExpandAll").'</span></a>';
print '</div>';
}
print '</td></tr>';
if ($nbofentries > 0) {
print '<tr class="oddeven"><td colspan="3">';
tree_recur($data, $data[0], 0);
print '</td></tr>';
} else {
print '<tr class="oddeven">';
print '<td colspan="3"><table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('', 'treemenu/branchbottom.gif').'</td>';
print '<td class="valignmiddle">';
print $langs->trans("NoCategoryYet");
print '</td>';
print '<td> </td>';
print '</table></td>';
print '</tr>';
}
print "</table>";
print '</div>';
// End of page
llxFooter();
$db->close();