dolibarr  9.0.0
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  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
31 
32 // Load translation files required by the page
33 $langs->load("categories");
34 
35 $id=GETPOST('id','int');
36 $ref=GETPOST('ref');
37 $type=GETPOST('type');
38 $action=(GETPOST('action','aZ09')?GETPOST('action','aZ09'):'edit');
39 $confirm=GETPOST('confirm');
40 $cancel=GETPOST('cancel','alpha');
41 
42 $socid=GETPOST('socid','int');
43 $label=GETPOST('label');
44 $description=GETPOST('description');
45 $color=GETPOST('color','alpha');
46 $visible=GETPOST('visible');
47 $parent=GETPOST('parent');
48 
49 if ($id == "")
50 {
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 {
61  $result=$object->fetch($id);
62 }
63 
64 $extrafields = new ExtraFields($db);
65 $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
66 
67 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array
68 $hookmanager->initHooks(array('categorycard'));
69 
70 
71 /*
72  * Actions
73  */
74 
75 if ($cancel)
76 {
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 {
84  $object->label = $label;
85  $object->description = dol_htmlcleanlastbr($description);
86  $object->color = $color;
87  $object->socid = ($socid ? $socid : 'null');
88  $object->visible = $visible;
89 
90  if ($parent != "-1")
91  $object->fk_parent = $parent;
92  else
93  $object->fk_parent = "";
94 
95 
96  if (empty($object->label))
97  {
98  $error++;
99  $action = 'edit';
100  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
101  }
102  if (! $error && empty($object->error))
103  {
104  $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
105  if ($ret < 0) $error++;
106 
107  if (! $error && $object->update($user) > 0)
108  {
109  header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
110  exit;
111  }
112  else
113  {
114  setEventMessages($object->error, $object->errors, 'errors');
115  }
116  }
117  else
118  {
119  setEventMessages($object->error, $object->errors, 'errors');
120  }
121 }
122 
123 
124 
125 /*
126  * View
127  */
128 
129 $form = new Form($db);
130 $formother = new FormOther($db);
131 
132 llxHeader("","",$langs->trans("Categories"));
133 
134 print load_fiche_titre($langs->trans("ModifCat"));
135 
136 $object->fetch($id);
137 
138 
139 print "\n";
140 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
141 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
142 print '<input type="hidden" name="action" value="update">';
143 print '<input type="hidden" name="id" value="'.$object->id.'">';
144 print '<input type="hidden" name="type" value="'.$type.'">';
145 
146 dol_fiche_head('');
147 
148 print '<table class="border" width="100%">';
149 
150 // Ref
151 print '<tr><td class="titlefieldcreate fieldrequired">';
152 print $langs->trans("Ref").'</td>';
153 print '<td><input type="text" size="25" id="label" name ="label" value="'.$object->label.'" />';
154 print '</tr>';
155 
156 // Description
157 print '<tr>';
158 print '<td>'.$langs->trans("Description").'</td>';
159 print '<td >';
160 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
161 $doleditor=new DolEditor('description',$object->description,'',200,'dolibarr_notes','',false,true,$conf->fckeditor->enabled,ROWS_6,'90%');
162 $doleditor->Create();
163 print '</td></tr>';
164 
165 // Color
166 print '<tr>';
167 print '<td>'.$langs->trans("Color").'</td>';
168 print '<td >';
169 print $formother->selectColor($object->color, 'color');
170 print '</td></tr>';
171 
172 // Parent category
173 print '<tr><td>'.$langs->trans("In").'</td><td>';
174 print $form->select_all_categories($type,$object->fk_parent,'parent',64,$object->id);
175 print '</td></tr>';
176 
177 $parameters=array();
178 $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
179 print $hookmanager->resPrint;
180 if (empty($reshook))
181 {
182  print $object->showOptionals($extrafields,'edit');
183 }
184 
185 print '</table>';
186 
187 
188 dol_fiche_end();
189 
190 
191 print '<div class="center"><input type="submit" class="button" name"submit" value="'.$langs->trans("Modify").'"> &nbsp; <input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></div>';
192 
193 print '</form>';
194 
195 // End of page
196 llxFooter();
197 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
Class to manage categories.
dol_fiche_end($notab=0)
Show tab footer of a card.
Classe permettant la generation de composants html autre Only common components are here...
llxHeader()
Empty header.
Definition: wrapper.php:44
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
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.
Class to manage a WYSIWYG editor.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.