dolibarr  18.0.6
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 Frédéric France <frederic.france@netlogic.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
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
32 require_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 = GETPOST('id', 'int');
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 = (int) GETPOST('socid', 'int');
45 $label = (string) GETPOST('label', 'alphanohtml');
46 $description = (string) GETPOST('description', 'restricthtml');
47 $color = preg_replace('/[^0-9a-f#]/i', '', (string) GETPOST('color', 'alphanohtml'));
48 $visible = (int) GETPOST('visible', 'int');
49 $parent = (int) GETPOST('parent', 'int');
50 
51 if ($id == "") {
52  dol_print_error('', 'Missing parameter id');
53  exit();
54 }
55 
56 // Security check
57 $result = restrictedArea($user, 'categorie', $id, '&category');
58 
59 $object = new Categorie($db);
60 $result = $object->fetch($id, $label);
61 if ($result <= 0) {
62  dol_print_error($db, $object->error); exit;
63 }
64 
65 $type = $object->type;
66 if (is_numeric($type)) {
67  $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
68 }
69 
70 $extrafields = new ExtraFields($db);
71 $extrafields->fetch_name_optionals_label($object->table_element);
72 
73 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array
74 $hookmanager->initHooks(array('categorycard'));
75 
76 $error = 0;
77 
78 
79 /*
80  * Actions
81  */
82 $parameters = array('id' => $id, 'ref' => $ref, 'cancel'=> $cancel, 'backtopage' => $backtopage, 'socid' => $socid, 'label' => $label, 'description' => $description, 'color' => $color, 'visible' => $visible, 'parent' => $parent);
83 // Note that $action and $object may be modified by some hooks
84 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
85 if ($reshook < 0) {
86  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
87 }
88 
89 if (empty($reshook)) {
90  if ($cancel) {
91  if ($backtopage) {
92  header("Location: ".$backtopage);
93  exit;
94  } else {
95  header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
96  exit;
97  }
98  }
99 
100  // Action mise a jour d'une categorie
101  if ($action == 'update' && $user->rights->categorie->creer) {
102  $object->oldcopy = dol_clone($object);
103  $object->label = $label;
104  $object->description = dol_htmlcleanlastbr($description);
105  $object->color = $color;
106  $object->socid = ($socid > 0 ? $socid : 0);
107  $object->visible = $visible;
108  $object->fk_parent = $parent != -1 ? $parent : 0;
109 
110  if (empty($object->label)) {
111  $error++;
112  $action = 'edit';
113  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
114  }
115  if (!$error && empty($object->error)) {
116  $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
117  if ($ret < 0) {
118  $error++;
119  }
120 
121  if (!$error && $object->update($user) > 0) {
122  if ($backtopage) {
123  header("Location: ".$backtopage);
124  exit;
125  } else {
126  header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
127  exit;
128  }
129  } else {
130  setEventMessages($object->error, $object->errors, 'errors');
131  }
132  } else {
133  setEventMessages($object->error, $object->errors, 'errors');
134  }
135  }
136 }
137 
138 
139 
140 /*
141  * View
142  */
143 
144 $form = new Form($db);
145 $formother = new FormOther($db);
146 
147 llxHeader("", "", $langs->trans("Categories"));
148 
149 print load_fiche_titre($langs->trans("ModifCat"));
150 
151 $object->fetch($id);
152 
153 
154 print "\n";
155 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
156 print '<input type="hidden" name="token" value="'.newToken().'">';
157 print '<input type="hidden" name="action" value="update">';
158 print '<input type="hidden" name="id" value="'.$object->id.'">';
159 print '<input type="hidden" name="type" value="'.$type.'">';
160 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
161 
162 print dol_get_fiche_head('');
163 
164 print '<table class="border centpercent">';
165 
166 // Ref
167 print '<tr><td class="titlefieldcreate fieldrequired">';
168 print $langs->trans("Ref").'</td>';
169 print '<td><input type="text" size="25" id="label" name ="label" value="'.$object->label.'" />';
170 print '</tr>';
171 
172 // Description
173 print '<tr>';
174 print '<td>'.$langs->trans("Description").'</td>';
175 print '<td>';
176 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
177 $doleditor = new DolEditor('description', $object->description, '', 200, 'dolibarr_notes', '', false, true, isModEnabled('fckeditor'), ROWS_6, '90%');
178 $doleditor->Create();
179 print '</td></tr>';
180 
181 // Color
182 print '<tr>';
183 print '<td>'.$langs->trans("Color").'</td>';
184 print '<td>';
185 print $formother->selectColor($object->color, 'color');
186 print '</td></tr>';
187 
188 // Parent category
189 print '<tr><td>'.$langs->trans("In").'</td><td>';
190 print img_picto('', 'category', 'class="pictofixedwidth"');
191 print $form->select_all_categories($type, $object->fk_parent, 'parent', 64, $object->id);
192 print ajax_combobox('parent');
193 print '</td></tr>';
194 
195 $parameters = array();
196 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
197 print $hookmanager->resPrint;
198 if (empty($reshook)) {
199  print $object->showOptionals($extrafields, 'edit', $parameters);
200 }
201 
202 print '</table>';
203 
204 
205 print dol_get_fiche_end();
206 
207 
208 print '<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>';
209 
210 print '</form>';
211 
212 // End of page
213 llxFooter();
214 $db->close();
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:449
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
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.
Classe permettant la generation de composants html autre Only common components are here.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
isModEnabled($module)
Is Dolibarr module enabled.
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.