dolibarr 21.0.0-beta
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
3 * Copyright (C) 2006-2021 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2014 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
6 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
7 * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
8 * Copyright (C) 2020-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/class/extrafields.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
36
45// Load translation files required by the page
46$langs->load("categories");
47
48// Security check
49$socid = GETPOSTINT('socid');
50if (!$user->hasRight('categorie', 'lire')) {
52}
53
54$action = GETPOST('action', 'alpha');
55$cancel = GETPOST('cancel', 'alpha');
56$origin = GETPOST('origin', 'alpha');
57$catorigin = GETPOSTINT('catorigin');
58$type = GETPOST('type', 'aZ09');
59$urlfrom = GETPOST('urlfrom', 'alpha');
60$backtopage = GETPOST('backtopage', 'alpha');
61
62$label = (string) GETPOST('label', 'alphanohtml');
63$description = (string) GETPOST('description', 'restricthtml');
64$color = preg_replace('/[^0-9a-f#]/i', '', (string) GETPOST('color', 'alphanohtml'));
65$position = GETPOSTINT('position');
66$visible = GETPOSTINT('visible');
67$parent = GETPOSTINT('parent');
68
69$idProdOrigin = 0;
70$idSupplierOrigin = 0;
71$idCompanyOrigin = 0;
72$idMemberOrigin = 0;
73$idContactOrigin = 0;
74$idProjectOrigin = 0;
75$idProdOrigin = 0;
76
77if ($origin) {
78 if ($type == Categorie::TYPE_PRODUCT) {
79 $idProdOrigin = $origin;
80 }
81 if ($type == Categorie::TYPE_SUPPLIER) {
82 $idSupplierOrigin = $origin;
83 }
84 if ($type == Categorie::TYPE_CUSTOMER) {
85 $idCompanyOrigin = $origin;
86 }
87 if ($type == Categorie::TYPE_MEMBER) {
88 $idMemberOrigin = $origin;
89 }
90 if ($type == Categorie::TYPE_CONTACT) {
91 $idContactOrigin = $origin;
92 }
93 if ($type == Categorie::TYPE_PROJECT) {
94 $idProjectOrigin = $origin;
95 }
96}
97
98if ($catorigin && $type == Categorie::TYPE_PRODUCT) {
99 $idCatOrigin = $catorigin;
100}
101if (!GETPOSTISSET('parent') && $catorigin) {
102 $parent = $catorigin;
103}
104
105$object = new Categorie($db);
106
107$extrafields = new ExtraFields($db);
108$extrafields->fetch_name_optionals_label($object->table_element);
109
110// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array array
111$hookmanager->initHooks(array('categorycard'));
112
113$error = 0;
114
115
116/*
117 * Actions
118 */
119
120$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);
121// Note that $action and $object may be modified by some hooks
122$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
123if ($reshook < 0) {
124 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
125}
126
127if (empty($reshook)) {
128 // Add action
129 if ($action == 'add' && $user->hasRight('categorie', 'creer')) {
130 // Action add a category
131 if ($cancel) {
132 if ($urlfrom) {
133 header("Location: ".$urlfrom);
134 exit;
135 } elseif ($backtopage) {
136 header("Location: ".$backtopage);
137 exit;
138 } elseif ($idProdOrigin) {
139 header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProdOrigin.'&type='.$type);
140 exit;
141 } elseif ($idCompanyOrigin) {
142 header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCompanyOrigin.'&type='.$type);
143 exit;
144 } elseif ($idSupplierOrigin) {
145 header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idSupplierOrigin.'&type='.$type);
146 exit;
147 } elseif ($idMemberOrigin) {
148 header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$type);
149 exit;
150 } elseif ($idContactOrigin) {
151 header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&type='.$type);
152 exit;
153 } elseif ($idProjectOrigin) {
154 header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProjectOrigin.'&type='.$type);
155 exit;
156 } else {
157 header("Location: ".DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type);
158 exit;
159 }
160 }
161 $object->label = $label;
162 $object->color = $color;
163 $object->position = $position;
164 $object->description = dol_htmlcleanlastbr($description);
165 $object->socid = ($socid > 0 ? $socid : 0);
166 $object->visible = $visible;
167 $object->type = $type;
168
169 if ($parent != "-1") {
170 $object->fk_parent = $parent;
171 }
172
173 $ret = $extrafields->setOptionalsFromPost(null, $object);
174 if ($ret < 0) {
175 $error++;
176 }
177
178 if (!$object->label) {
179 $error++;
180 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
181 $action = 'create';
182 }
183
184 // Create category in database
185 if (!$error) {
186 $result = $object->create($user);
187 if ($result > 0) {
188 $action = 'confirmed';
189 } else {
190 setEventMessages($object->error, $object->errors, 'errors');
191 }
192 }
193 }
194 // Action confirmation of creation category
195 if ($action == 'confirmed' && $user->hasRight('categorie', 'creer')) {
196 if ($urlfrom) {
197 header("Location: ".$urlfrom);
198 exit;
199 } elseif ($backtopage) {
200 header("Location: ".$backtopage);
201 exit;
202 } elseif ($idProdOrigin) {
203 header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProdOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
204 exit;
205 } elseif ($idCompanyOrigin) {
206 header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCompanyOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
207 exit;
208 } elseif ($idSupplierOrigin) {
209 header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idSupplierOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
210 exit;
211 } elseif ($idMemberOrigin) {
212 header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
213 exit;
214 } elseif ($idContactOrigin) {
215 header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
216 exit;
217 } elseif ($idProjectOrigin) {
218 header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProjectOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
219 exit;
220 }
221
222 header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$result.'&type='.$type);
223 exit;
224 }
225}
226
227
228/*
229 * View
230 */
231
232$form = new Form($db);
233$formother = new FormOther($db);
234
235$help_url = 'EN:Module_Categories|FR:Module_Catégories|DE:Modul_Kategorien';
236
237llxHeader("", $langs->trans("Categories"), $help_url);
238
239if ($user->hasRight('categorie', 'creer')) {
240 // Create or add
241 if ($action == 'create' || $action == 'add') {
242 dol_set_focus('#label');
243
244 print '<form action="'.$_SERVER['PHP_SELF'].'?type='.$type.'" method="POST">';
245 print '<input type="hidden" name="token" value="'.newToken().'">';
246 print '<input type="hidden" name="urlfrom" value="'.$urlfrom.'">';
247 print '<input type="hidden" name="action" value="add">';
248 print '<input type="hidden" name="id" value="'.GETPOST('origin', 'alpha').'">';
249 print '<input type="hidden" name="type" value="'.$type.'">';
250 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
251 if ($origin) {
252 print '<input type="hidden" name="origin" value="'.$origin.'">';
253 }
254 if ($catorigin) {
255 print '<input type="hidden" name="catorigin" value="'.$catorigin.'">';
256 }
257
258 print load_fiche_titre($langs->trans("CreateCat"));
259
260 print dol_get_fiche_head();
261
262 print '<table class="border centpercent">';
263
264 // Ref
265 print '<tr>';
266 print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td><input id="label" class="minwidth100" name="label" value="'.dol_escape_htmltag($label).'">';
267 print'</td></tr>';
268
269 // Description
270 print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
271 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
272 $doleditor = new DolEditor('description', $description, '', 160, 'dolibarr_notes', '', false, true, isModEnabled('fckeditor') && getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_5, '90%');
273 $doleditor->Create();
274 print '</td></tr>';
275
276 // Color
277 print '<tr><td>'.$langs->trans("Color").'</td><td>';
278 print $formother->selectColor($color, 'color');
279 print '</td></tr>';
280
281 // Position
282 print '<tr>';
283 print '<td class="titlefieldcreate">'.$langs->trans("Position").'</td><td><input id="position" type="number" class="minwidth50 maxwidth50" name="position" value="'.$position.'">';
284 print'</td></tr>';
285
286 // Parent category
287 print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
288 print img_picto($langs->trans("ParentCategory"), 'category', 'class="pictofixedwidth"');
289 print $form->select_all_categories($type, $parent, 'parent');
290 print ajax_combobox('parent');
291 print '</td></tr>';
292
293 $parameters = array();
294 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
295 print $hookmanager->resPrint;
296 if (empty($reshook)) {
297 print $object->showOptionals($extrafields, 'create', $parameters);
298 }
299
300 print '</table>';
301
302 print dol_get_fiche_end();
303
304 print '<div class="center">';
305 print '<input type="submit" class="button b" value="'.$langs->trans("CreateThisCat").'" name="creation" />';
306 print '&nbsp; &nbsp; &nbsp;';
307 print '<input type="submit" class="button button-cancel" value="'.$langs->trans("Cancel").'" name="cancel" />';
308 print '</div>';
309
310 print '</form>';
311 }
312}
313
314// End of page
315llxFooter();
316$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:459
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 a WYSIWYG editor.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation de composants html autre Only common components are 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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
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_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...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.