dolibarr  13.0.2
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 $type = GETPOST('type', 'aZ09'); // Can be int or string
39 $action = (GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'edit');
40 $confirm = GETPOST('confirm');
41 $cancel = GETPOST('cancel', '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 if ($id > 0) {
60  $result = $object->fetch($id);
61 }
62 
63 $extrafields = new ExtraFields($db);
64 $extrafields->fetch_name_optionals_label($object->table_element);
65 
66 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array
67 $hookmanager->initHooks(array('categorycard'));
68 
69 $error = 0;
70 
71 
72 /*
73  * Actions
74  */
75 
76 if ($cancel) {
77  header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
78  exit;
79 }
80 
81 // Action mise a jour d'une categorie
82 if ($action == 'update' && $user->rights->categorie->creer) {
83  $object->oldcopy = dol_clone($object);
84  $object->label = $label;
85  $object->description = dol_htmlcleanlastbr($description);
86  $object->color = $color;
87  $object->socid = ($socid > 0 ? $socid : 0);
88  $object->visible = $visible;
89  $object->fk_parent = $parent != -1 ? $parent : 0;
90 
91 
92  if (empty($object->label)) {
93  $error++;
94  $action = 'edit';
95  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
96  }
97  if (!$error && empty($object->error)) {
98  $ret = $extrafields->setOptionalsFromPost(null, $object);
99  if ($ret < 0) $error++;
100 
101  if (!$error && $object->update($user) > 0) {
102  header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
103  exit;
104  } else {
105  setEventMessages($object->error, $object->errors, 'errors');
106  }
107  } else {
108  setEventMessages($object->error, $object->errors, 'errors');
109  }
110 }
111 
112 
113 
114 /*
115  * View
116  */
117 
118 $form = new Form($db);
119 $formother = new FormOther($db);
120 
121 llxHeader("", "", $langs->trans("Categories"));
122 
123 print load_fiche_titre($langs->trans("ModifCat"));
124 
125 $object->fetch($id);
126 
127 
128 print "\n";
129 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
130 print '<input type="hidden" name="token" value="'.newToken().'">';
131 print '<input type="hidden" name="action" value="update">';
132 print '<input type="hidden" name="id" value="'.$object->id.'">';
133 print '<input type="hidden" name="type" value="'.$type.'">';
134 
136 
137 print '<table class="border centpercent">';
138 
139 // Ref
140 print '<tr><td class="titlefieldcreate fieldrequired">';
141 print $langs->trans("Ref").'</td>';
142 print '<td><input type="text" size="25" id="label" name ="label" value="'.$object->label.'" />';
143 print '</tr>';
144 
145 // Description
146 print '<tr>';
147 print '<td>'.$langs->trans("Description").'</td>';
148 print '<td>';
149 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
150 $doleditor = new DolEditor('description', $object->description, '', 200, 'dolibarr_notes', '', false, true, $conf->fckeditor->enabled, ROWS_6, '90%');
151 $doleditor->Create();
152 print '</td></tr>';
153 
154 // Color
155 print '<tr>';
156 print '<td>'.$langs->trans("Color").'</td>';
157 print '<td>';
158 print $formother->selectColor($object->color, 'color');
159 print '</td></tr>';
160 
161 // Parent category
162 print '<tr><td>'.$langs->trans("In").'</td><td>';
163 print $form->select_all_categories($type, $object->fk_parent, 'parent', 64, $object->id);
164 print '</td></tr>';
165 
166 $parameters = array();
167 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
168 print $hookmanager->resPrint;
169 if (empty($reshook)) {
170  print $object->showOptionals($extrafields, 'edit', $parameters);
171 }
172 
173 print '</table>';
174 
175 
177 
178 
179 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>';
180 
181 print '</form>';
182 
183 // End of page
184 llxFooter();
185 $db->close();
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=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
Class to manage categories.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
Classe permettant la generation de composants html autre Only common components are here...
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
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.
Class to manage a WYSIWYG editor.
llxFooter()
Empty footer.
Definition: wrapper.php:59