-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathcard.php
More file actions
339 lines (290 loc) · 11.4 KB
/
card.php
File metadata and controls
339 lines (290 loc) · 11.4 KB
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<?php
/* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
* Copyright (C) 2006-2021 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2014 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2020-2026 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
*
* 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/card.php
* \ingroup category
* \brief Page to create a new category
*/
// Load Dolibarr environment
require '../main.inc.php';
/**
* @var Conf $conf
* @var DoliDB $db
* @var ExtraFields $extrafields
* @var HookManager $hookmanager
* @var Translate $langs
* @var User $user
*/
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
// Load translation files required by the page
$langs->load("categories");
// Security check
$socid = GETPOSTINT('socid');
if (!$user->hasRight('categorie', 'lire')) {
accessforbidden();
}
$action = GETPOST('action', 'alpha');
$cancel = GETPOST('cancel', 'alpha');
$origin = GETPOST('origin', 'alpha');
$catorigin = GETPOSTINT('catorigin');
$type = GETPOST('type', 'aZ09');
$urlfrom = GETPOST('urlfrom', 'alpha');
$backtopage = GETPOST('backtopage', 'alpha');
$label = (string) GETPOST('label', 'alphanohtml');
$description = (string) GETPOST('description', 'restricthtml');
$color = preg_replace('/[^0-9a-f#]/i', '', (string) GETPOST('color', 'alphanohtml'));
$position = GETPOSTISSET('position') ? GETPOSTINT('position') : 1;
$visible = GETPOSTINT('visible');
$parent = GETPOSTINT('parent');
$idProdOrigin = 0;
$idSupplierOrigin = 0;
$idCompanyOrigin = 0;
$idMemberOrigin = 0;
$idContactOrigin = 0;
$idProjectOrigin = 0;
$idProdOrigin = 0;
if ($origin) {
if ($type == Categorie::TYPE_PRODUCT) {
$idProdOrigin = $origin;
}
if ($type == Categorie::TYPE_SUPPLIER) {
$idSupplierOrigin = $origin;
}
if ($type == Categorie::TYPE_CUSTOMER) {
$idCompanyOrigin = $origin;
}
if ($type == Categorie::TYPE_MEMBER) {
$idMemberOrigin = $origin;
}
if ($type == Categorie::TYPE_CONTACT) {
$idContactOrigin = $origin;
}
if ($type == Categorie::TYPE_PROJECT) {
$idProjectOrigin = $origin;
}
}
if ($catorigin && $type == Categorie::TYPE_PRODUCT) {
$idCatOrigin = $catorigin;
}
if (!GETPOSTISSET('parent') && $catorigin) {
$parent = $catorigin;
}
$object = new Categorie($db);
$extrafields->fetch_name_optionals_label($object->table_element);
// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('categorycard'));
$error = 0;
/*
* Actions
*/
$parameters = array('socid' => $socid, 'origin' => $origin, 'catorigin' => $catorigin, 'type' => $type, 'urlfrom' => $urlfrom, 'backtopage' => $backtopage, 'label' => $label, 'description' => $description, 'color' => $color, 'position' => $position, 'visible' => $visible, 'parent' => $parent);
// Note that $action and $object may be modified by some hooks
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook)) {
$result = 0;
// Add action
if ($action == 'add' && $user->hasRight('categorie', 'creer')) {
// Action add a category
if ($cancel) {
if ($urlfrom) {
header("Location: ".$urlfrom);
exit;
} elseif ($backtopage) {
header("Location: ".$backtopage);
exit;
} elseif ($idProdOrigin) {
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProdOrigin.'&type='.$type);
exit;
} elseif ($idCompanyOrigin) {
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCompanyOrigin.'&type='.$type);
exit;
} elseif ($idSupplierOrigin) {
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idSupplierOrigin.'&type='.$type);
exit;
} elseif ($idMemberOrigin) {
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$type);
exit;
} elseif ($idContactOrigin) {
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&type='.$type);
exit;
} elseif ($idProjectOrigin) {
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProjectOrigin.'&type='.$type);
exit;
} else {
header("Location: ".DOL_URL_ROOT.'/categories/categorie_list.php?leftmenu=cat&type='.$type);
exit;
}
}
$object->label = $label;
$object->color = $color;
$object->position = $position;
$object->description = dol_htmlcleanlastbr($description);
$object->socid = ($socid > 0 ? $socid : 0);
$object->visible = $visible;
$object->type = $type;
if ($parent != "-1") {
$object->fk_parent = $parent;
}
$ret = $extrafields->setOptionalsFromPost(null, $object);
if ($ret < 0) {
$error++;
}
if (!$object->label) {
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
$action = 'create';
}
// Create category in database
if (!$error) {
$result = $object->create($user);
if ($result > 0) {
$action = 'confirmed';
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
}
}
// Action confirmation of creation category
if ($action == 'confirmed' && $user->hasRight('categorie', 'creer')) {
if ($urlfrom) {
header("Location: ".$urlfrom);
exit;
} elseif ($backtopage) {
header("Location: ".$backtopage);
exit;
} elseif ($idProdOrigin) {
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProdOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
exit;
} elseif ($idCompanyOrigin) {
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCompanyOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
exit;
} elseif ($idSupplierOrigin) {
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idSupplierOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
exit;
} elseif ($idMemberOrigin) {
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
exit;
} elseif ($idContactOrigin) {
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
exit;
} elseif ($idProjectOrigin) {
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProjectOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
exit;
}
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$result.'&type='.$type);
exit;
}
}
/*
* View
*/
$form = new Form($db);
$formother = new FormOther($db);
$help_url = 'EN:Module_Categories|FR:Module_Catégories|DE:Modul_Kategorien';
llxHeader("", $langs->trans("Categories"), $help_url);
if ($user->hasRight('categorie', 'creer')) {
// Create or add
if ($action == 'create' || $action == 'add') {
dol_set_focus('#label');
print '<form action="'.$_SERVER['PHP_SELF'].'?type='.$type.'" method="POST">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="urlfrom" value="'.$urlfrom.'">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="id" value="'.GETPOST('origin', 'alpha').'">';
print '<input type="hidden" name="type" value="'.$type.'">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
if ($origin) {
print '<input type="hidden" name="origin" value="'.$origin.'">';
}
if ($catorigin) {
print '<input type="hidden" name="catorigin" value="'.$catorigin.'">';
}
print load_fiche_titre($langs->trans("CreateCat"), '', 'category');
print dol_get_fiche_head();
print '<table class="border centpercent">';
// Type
$typeLabel = '';
if (!empty($type) && !empty(Categorie::$MAP_TYPE_TITLE_AREA[$type])) {
$typeLabel = $langs->trans(Categorie::$MAP_TYPE_TITLE_AREA[$type]);
}
if (!empty($typeLabel)) {
print '<tr>';
print '<td class="titlefieldcreate">'.$langs->trans("Type").'</td>';
print '<td>'.$typeLabel;
print '<input type="hidden" name="type" value="'.dol_escape_htmltag($type).'">';
print '</td>';
print '</tr>';
}
// Ref
print '<tr>';
print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td>';
print '<td><input id="label" class="minwidth100" name="label" value="'.dol_escape_htmltag($label).'" placeholder="'.$langs->trans("MyTag").'">';
print'</td></tr>';
// Description
print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor = new DolEditor('description', $description, '', 160, 'dolibarr_notes', '', false, true, isModEnabled('fckeditor') && getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_5, '90%');
$doleditor->Create();
print '</td></tr>';
// Color
print '<tr><td>'.$langs->trans("Color").'</td><td>';
print $formother->selectColor($color, 'color');
print '</td></tr>';
// Position
print '<tr>';
print '<td class="titlefieldcreate">'.$langs->trans("Position").'</td><td><input id="position" type="number" class="minwidth50 maxwidth50" name="position" value="'.$position.'">';
print'</td></tr>';
$htmlselect = $form->select_all_categories($type, $parent, 'parent');
// Parent category
if ($form->num > 0) {
print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
print img_picto($langs->trans("ParentCategory"), 'category', 'class="pictofixedwidth"');
print $htmlselect;
print ajax_combobox('parent');
print '</td></tr>';
}
$parameters = array();
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
if (empty($reshook)) {
print $object->showOptionals($extrafields, 'create', $parameters);
}
print '</table>';
print dol_get_fiche_end();
print '<div class="center">';
print '<input type="submit" class="button b" value="'.$langs->trans("CreateThisCat").'" name="creation" />';
print ' ';
print '<input type="submit" class="button button-cancel" value="'.$langs->trans("Cancel").'" name="cancel" />';
print '</div>';
print '</form>';
}
}
// End of page
llxFooter();
$db->close();