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