dolibarr  7.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@capnetworks.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 $langs->load("categories");
33 
34 $id=GETPOST('id','int');
35 $ref=GETPOST('ref');
36 $type=GETPOST('type');
37 $action=GETPOST('action','aZ09');
38 $confirm=GETPOST('confirm');
39 $cancel=GETPOST('cancel','alpha');
40 
41 $socid=GETPOST('socid','int');
42 $label=GETPOST('label');
43 $description=GETPOST('description');
44 $color=GETPOST('color','alpha');
45 $visible=GETPOST('visible');
46 $parent=GETPOST('parent');
47 
48 if ($id == "")
49 {
50  dol_print_error('','Missing parameter id');
51  exit();
52 }
53 
54 // Security check
55 $result = restrictedArea($user, 'categorie', $id, '&category');
56 
57 $object = new Categorie($db);
58 if ($id > 0)
59 {
60  $result=$object->fetch($id);
61 }
62 
63 $extrafields = new ExtraFields($db);
64 $extralabels=$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 
70 /*
71  * Actions
72  */
73 
74 if ($cancel)
75 {
76  header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
77  exit;
78 }
79 
80 // Action mise a jour d'une categorie
81 if ($action == 'update' && $user->rights->categorie->creer)
82 {
83  $object->label = $label;
84  $object->description = dol_htmlcleanlastbr($description);
85  $object->color = $color;
86  $object->socid = ($socid ? $socid : 'null');
87  $object->visible = $visible;
88 
89  if ($parent != "-1")
90  $object->fk_parent = $parent;
91  else
92  $object->fk_parent = "";
93 
94 
95  if (empty($object->label))
96  {
97  $error++;
98  $action = 'edit';
99  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
100  }
101  if (! $error && empty($object->error))
102  {
103  $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
104  if ($ret < 0) $error++;
105 
106  if (! $error && $object->update($user) > 0)
107  {
108  header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
109  exit;
110  }
111  else
112  {
113  setEventMessages($object->error, $object->errors, 'errors');
114  }
115  }
116  else
117  {
118  setEventMessages($object->error, $object->errors, 'errors');
119  }
120 }
121 
122 
123 
124 /*
125  * View
126  */
127 
128 $form = new Form($db);
129 $formother = new FormOther($db);
130 
131 llxHeader("","",$langs->trans("Categories"));
132 
133 print load_fiche_titre($langs->trans("ModifCat"));
134 
135 $object->fetch($id);
136 
137 
138 print "\n";
139 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
140 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
141 print '<input type="hidden" name="action" value="update">';
142 print '<input type="hidden" name="id" value="'.$object->id.'">';
143 print '<input type="hidden" name="type" value="'.$type.'">';
144 
145 dol_fiche_head('');
146 
147 print '<table class="border" width="100%">';
148 
149 // Ref
150 print '<tr><td class="titlefieldcreate fieldrequired">';
151 print $langs->trans("Ref").'</td>';
152 print '<td><input type="text" size="25" id="label" name ="label" value="'.$object->label.'" />';
153 print '</tr>';
154 
155 // Description
156 print '<tr>';
157 print '<td>'.$langs->trans("Description").'</td>';
158 print '<td >';
159 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
160 $doleditor=new DolEditor('description',$object->description,'',200,'dolibarr_notes','',false,true,$conf->fckeditor->enabled,ROWS_6,'90%');
161 $doleditor->Create();
162 print '</td></tr>';
163 
164 // Color
165 print '<tr>';
166 print '<td>'.$langs->trans("Color").'</td>';
167 print '<td >';
168 print $formother->selectColor($object->color, 'color');
169 print '</td></tr>';
170 
171 // Parent category
172 print '<tr><td>'.$langs->trans("In").'</td><td>';
173 print $form->select_all_categories($type,$object->fk_parent,'parent',64,$object->id);
174 print '</td></tr>';
175 
176 $parameters=array();
177 $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
178 print $hookmanager->resPrint;
179 if (empty($reshook) && ! empty($extrafields->attribute_label))
180 {
181  print $object->showOptionals($extrafields,'edit');
182 }
183 
184 print '</table>';
185 
186 
187 dol_fiche_end();
188 
189 
190 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>';
191 
192 print '</form>';
193 
194 
195 
196 llxFooter();
197 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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...
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
print
Draft customers invoices.
Definition: index.php:91
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
Class to manage a WYSIWYG editor.
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.