dolibarr  16.0.5
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 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
32 
33 // Load translation files required by the page
34 $langs->load("categories");
35 
36 $id = GETPOST('id', 'int');
37 $ref = GETPOST('ref', 'alphanohtml');
38 $action = (GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'edit');
39 $confirm = GETPOST('confirm');
40 $cancel = GETPOST('cancel', 'alpha');
41 $backtopage = GETPOST('backtopage', 'alpha');
42 
43 $socid = (int) GETPOST('socid', 'int');
44 $label = (string) GETPOST('label', 'alphanohtml');
45 $description = (string) GETPOST('description', 'restricthtml');
46 $color = preg_replace('/[^0-9a-f#]/i', '', (string) GETPOST('color', 'alphanohtml'));
47 $visible = (int) GETPOST('visible', 'int');
48 $parent = (int) GETPOST('parent', 'int');
49 
50 if ($id == "") {
51  dol_print_error('', 'Missing parameter id');
52  exit();
53 }
54 
55 // Security check
56 $result = restrictedArea($user, 'categorie', $id, '&category');
57 
58 $object = new Categorie($db);
59 $result = $object->fetch($id, $label);
60 if ($result <= 0) {
61  dol_print_error($db, $object->error); exit;
62 }
63 
64 $type = $object->type;
65 if (is_numeric($type)) {
66  $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
67 }
68 
69 $extrafields = new ExtraFields($db);
70 $extrafields->fetch_name_optionals_label($object->table_element);
71 
72 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array
73 $hookmanager->initHooks(array('categorycard'));
74 
75 $error = 0;
76 
77 
78 /*
79  * Actions
80  */
81 
82 if ($cancel) {
83  if ($backtopage) {
84  header("Location: ".$backtopage);
85  exit;
86  } else {
87  header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
88  exit;
89  }
90 }
91 
92 // Action mise a jour d'une categorie
93 if ($action == 'update' && $user->rights->categorie->creer) {
94  $object->oldcopy = dol_clone($object);
95  $object->label = $label;
96  $object->description = dol_htmlcleanlastbr($description);
97  $object->color = $color;
98  $object->socid = ($socid > 0 ? $socid : 0);
99  $object->visible = $visible;
100  $object->fk_parent = $parent != -1 ? $parent : 0;
101 
102  if (empty($object->label)) {
103  $error++;
104  $action = 'edit';
105  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
106  }
107  if (!$error && empty($object->error)) {
108  $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
109  if ($ret < 0) {
110  $error++;
111  }
112 
113  if (!$error && $object->update($user) > 0) {
114  if ($backtopage) {
115  header("Location: ".$backtopage);
116  exit;
117  } else {
118  header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
119  exit;
120  }
121  } else {
122  setEventMessages($object->error, $object->errors, 'errors');
123  }
124  } else {
125  setEventMessages($object->error, $object->errors, 'errors');
126  }
127 }
128 
129 
130 
131 /*
132  * View
133  */
134 
135 $form = new Form($db);
136 $formother = new FormOther($db);
137 
138 llxHeader("", "", $langs->trans("Categories"));
139 
140 print load_fiche_titre($langs->trans("ModifCat"));
141 
142 $object->fetch($id);
143 
144 
145 print "\n";
146 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
147 print '<input type="hidden" name="token" value="'.newToken().'">';
148 print '<input type="hidden" name="action" value="update">';
149 print '<input type="hidden" name="id" value="'.$object->id.'">';
150 print '<input type="hidden" name="type" value="'.$type.'">';
151 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
152 
153 print dol_get_fiche_head('');
154 
155 print '<table class="border centpercent">';
156 
157 // Ref
158 print '<tr><td class="titlefieldcreate fieldrequired">';
159 print $langs->trans("Ref").'</td>';
160 print '<td><input type="text" size="25" id="label" name ="label" value="'.$object->label.'" />';
161 print '</tr>';
162 
163 // Description
164 print '<tr>';
165 print '<td>'.$langs->trans("Description").'</td>';
166 print '<td>';
167 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
168 $doleditor = new DolEditor('description', $object->description, '', 200, 'dolibarr_notes', '', false, true, $conf->fckeditor->enabled, ROWS_6, '90%');
169 $doleditor->Create();
170 print '</td></tr>';
171 
172 // Color
173 print '<tr>';
174 print '<td>'.$langs->trans("Color").'</td>';
175 print '<td>';
176 print $formother->selectColor($object->color, 'color');
177 print '</td></tr>';
178 
179 // Parent category
180 print '<tr><td>'.$langs->trans("In").'</td><td>';
181 print img_picto('', 'category', 'class="pictofixedwidth"');
182 print $form->select_all_categories($type, $object->fk_parent, 'parent', 64, $object->id);
183 print ajax_combobox('parent');
184 print '</td></tr>';
185 
186 $parameters = array();
187 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
188 print $hookmanager->resPrint;
189 if (empty($reshook)) {
190  print $object->showOptionals($extrafields, 'edit', $parameters);
191 }
192 
193 print '</table>';
194 
195 
196 print dol_get_fiche_end();
197 
198 
199 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>';
200 
201 print '</form>';
202 
203 // End of page
204 llxFooter();
205 $db->close();
ajax_combobox
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:438
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
FormOther
Classe permettant la generation de composants html autre Only common components are here.
Definition: html.formother.class.php:39
Categorie
Class to manage categories.
Definition: categorie.class.php:47
dol_clone
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
Definition: functions.lib.php:1158
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_htmlcleanlastbr
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
Definition: functions.lib.php:7036
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
DolEditor
Class to manage a WYSIWYG editor.
Definition: doleditor.class.php:30