dolibarr 21.0.0-alpha
edit.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
3 * Copyright (C) 2006-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
6 * Copyright (C) 2020-2024 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
33
34// Load translation files required by the page
35$langs->load("categories");
36
37$id = GETPOSTINT('id');
38$ref = GETPOST('ref', 'alphanohtml');
39$action = (GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'edit');
40$confirm = GETPOST('confirm');
41$cancel = GETPOST('cancel', 'alpha');
42$backtopage = GETPOST('backtopage', 'alpha');
43
44$socid = GETPOSTINT('socid');
45$label = (string) GETPOST('label', 'alphanohtml');
46$description = (string) GETPOST('description', 'restricthtml');
47$color = preg_replace('/^#/', '', preg_replace('/[^0-9a-f#]/i', '', (string) GETPOST('color', 'alphanohtml')));
48$position = GETPOSTINT('position');
49$visible = GETPOSTINT('visible');
50$parent = GETPOSTINT('parent');
51
52if ($id == "") {
53 dol_print_error(null, 'Missing parameter id');
54 exit();
55}
56
57// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array array
58$hookmanager->initHooks(array('categorycard'));
59
60// Security check
61$result = restrictedArea($user, 'categorie', $id, '&category');
62
63$object = new Categorie($db);
64$result = $object->fetch($id, $label);
65if ($result <= 0) {
66 dol_print_error($db, $object->error);
67 exit;
68}
69
70$type = $object->type;
71if (is_numeric($type)) {
72 $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
73}
74
75$extrafields = new ExtraFields($db);
76$extrafields->fetch_name_optionals_label($object->table_element);
77
78$error = 0;
79
80
81/*
82 * Actions
83 */
84$parameters = array('id' => $id, 'ref' => $ref, 'cancel'=> $cancel, 'backtopage' => $backtopage, 'socid' => $socid, 'label' => $label, 'description' => $description, 'color' => $color, 'position' => $position, 'visible' => $visible, 'parent' => $parent);
85// Note that $action and $object may be modified by some hooks
86$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
87if ($reshook < 0) {
88 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
89}
90
91if (empty($reshook)) {
92 if ($cancel) {
93 if ($backtopage) {
94 header("Location: ".$backtopage);
95 exit;
96 } else {
97 header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
98 exit;
99 }
100 }
101
102 // Action mise a jour d'une categorie
103 if ($action == 'update' && $user->hasRight('categorie', 'creer')) {
104 $object->oldcopy = dol_clone($object, 2);
105
106 $object->label = $label;
107 $object->description = dol_htmlcleanlastbr($description);
108 $object->color = $color;
109 $object->position = $position;
110 $object->socid = ($socid > 0 ? $socid : 0);
111 $object->visible = $visible;
112 $object->fk_parent = $parent != -1 ? $parent : 0;
113
114 if (empty($object->label)) {
115 $error++;
116 $action = 'edit';
117 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
118 }
119 if (!$error && empty($object->error)) {
120 $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
121 if ($ret < 0) {
122 $error++;
123 }
124
125 if (!$error && $object->update($user) > 0) {
126 if ($backtopage) {
127 header("Location: ".$backtopage);
128 exit;
129 } else {
130 header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
131 exit;
132 }
133 } else {
134 setEventMessages($object->error, $object->errors, 'errors');
135 }
136 } else {
137 setEventMessages($object->error, $object->errors, 'errors');
138 }
139 }
140}
141
142
143/*
144 * View
145 */
146
147$form = new Form($db);
148$formother = new FormOther($db);
149
150llxHeader("", "", $langs->trans("Categories"));
151
152print load_fiche_titre($langs->trans("ModifCat"));
153
154$object->fetch($id);
155
156
157print "\n";
158print '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
159print '<input type="hidden" name="token" value="'.newToken().'">';
160print '<input type="hidden" name="action" value="update">';
161print '<input type="hidden" name="id" value="'.$object->id.'">';
162print '<input type="hidden" name="type" value="'.$type.'">';
163print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
164
165print dol_get_fiche_head([]);
166
167print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
168print '<table class="border centpercent">';
169
170// Ref
171print '<tr><td class="titlefieldcreate fieldrequired">';
172print $langs->trans("Ref").'</td>';
173print '<td><input type="text" size="25" id="label" name ="label" value="'.$object->label.'" />';
174print '</tr>';
175
176// Description
177print '<tr>';
178print '<td>'.$langs->trans("Description").'</td>';
179print '<td>';
180require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
181$doleditor = new DolEditor('description', $object->description, '', 200, 'dolibarr_notes', '', false, true, isModEnabled('fckeditor'), ROWS_6, '90%');
182$doleditor->Create();
183print '</td></tr>';
184
185// Color
186print '<tr>';
187print '<td>'.$langs->trans("Color").'</td>';
188print '<td>';
189print $formother->selectColor($object->color, 'color');
190print '</td></tr>';
191
192// Position
193print '<tr><td>';
194print $langs->trans("Position").'</td>';
195print '<td><input type="text" class="width50" id="position" name ="position" value="'.$object->position.'" />';
196print '</tr>';
197
198// Parent category
199print '<tr><td>'.$langs->trans("In").'</td><td>';
200print img_picto('', 'category', 'class="pictofixedwidth"');
201print $form->select_all_categories($type, $object->fk_parent, 'parent', 64, $object->id, 0, 0, 'widthcentpercentminusx maxwidth500');
202print ajax_combobox('parent');
203print '</td></tr>';
204
205$parameters = array();
206$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
207print $hookmanager->resPrint;
208if (empty($reshook)) {
209 print $object->showOptionals($extrafields, 'edit', $parameters);
210}
211
212print '</table>';
213print '</div>';
214
215print dol_get_fiche_end();
216
217
218print '<div class="center"><input type="submit" class="button" name"submit" value="'.$langs->trans("Modify").'"> &nbsp; <input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'"></div>';
219
220print '</form>';
221
222// End of page
223llxFooter();
224$db->close();
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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:457
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:70
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.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.