dolibarr  9.0.0
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
3  * Copyright (C) 2006-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2014 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
6  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
7  * Copyright (C) 2015 RaphaĆ«l Doursenaud <rdoursenaud@gpcsolutions.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
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 // Security check
38 $socid=GETPOST('socid','int');
39 if (!$user->rights->categorie->lire) accessforbidden();
40 
41 $action = GETPOST('action','alpha');
42 $cancel = GETPOST('cancel','alpha');
43 $origin = GETPOST('origin','alpha');
44 $catorigin = GETPOST('catorigin','int');
45 $type = GETPOST('type','alpha');
46 $urlfrom = GETPOST('urlfrom','alpha');
47 $backtopage = GETPOST('backtopage','alpha');
48 
49 $socid=GETPOST('socid','int');
50 $label=GETPOST('label');
51 $description=GETPOST('description');
52 $color=GETPOST('color');
53 $visible=GETPOST('visible');
54 $parent=GETPOST('parent');
55 
56 if ($origin)
57 {
58  if ($type == Categorie::TYPE_PRODUCT) $idProdOrigin = $origin;
59  if ($type == Categorie::TYPE_SUPPLIER) $idSupplierOrigin = $origin;
60  if ($type == Categorie::TYPE_CUSTOMER) $idCompanyOrigin = $origin;
61  if ($type == Categorie::TYPE_MEMBER) $idMemberOrigin = $origin;
62  if ($type == Categorie::TYPE_CONTACT) $idContactOrigin = $origin;
63  if ($type == Categorie::TYPE_PROJECT) $idProjectOrigin = $origin;
64 }
65 
66 if ($catorigin && $type == Categorie::TYPE_PRODUCT) $idCatOrigin = $catorigin;
67 
68 $object = new Categorie($db);
69 
70 $extrafields = new ExtraFields($db);
71 $extralabels=$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 
77 /*
78  * Actions
79  */
80 
81 // Add action
82 if ($action == 'add' && $user->rights->categorie->creer)
83 {
84  // Action ajout d'une categorie
85  if ($cancel)
86  {
87  if ($urlfrom)
88  {
89  header("Location: ".$urlfrom);
90  exit;
91  }
92  else if ($idProdOrigin)
93  {
94  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProdOrigin.'&type='.$type);
95  exit;
96  }
97  else if ($idCompanyOrigin)
98  {
99  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCompanyOrigin.'&type='.$type);
100  exit;
101  }
102  else if ($idSupplierOrigin)
103  {
104  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idSupplierOrigin.'&type='.$type);
105  exit;
106  }
107  else if ($idMemberOrigin)
108  {
109  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$type);
110  exit;
111  }
112  else if ($idContactOrigin)
113  {
114  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&type='.$type);
115  exit;
116  }
117  else if ($idProjectOrigin)
118  {
119  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProjectOrigin.'&type='.$type);
120  exit;
121  }
122  else
123  {
124  header("Location: ".DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type);
125  exit;
126  }
127  }
128 
129 
130 
131  $object->label = $label;
132  $object->color = $color;
133  $object->description = dol_htmlcleanlastbr($description);
134  $object->socid = ($socid ? $socid : 'null');
135  $object->visible = $visible;
136  $object->type = $type;
137 
138  if ($parent != "-1") $object->fk_parent = $parent;
139 
140  $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
141  if ($ret < 0) $error++;
142 
143  if (! $object->label)
144  {
145  $error++;
146  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
147  $action = 'create';
148  }
149 
150  // Create category in database
151  if (! $error)
152  {
153  $result = $object->create($user);
154  if ($result > 0)
155  {
156  $action = 'confirmed';
157  $_POST["addcat"] = '';
158  }
159  else
160  {
161  setEventMessages($object->error, $object->errors, 'errors');
162  }
163  }
164 }
165 
166 // Confirm action
167 if (($action == 'add' || $action == 'confirmed') && $user->rights->categorie->creer)
168 {
169  // Action confirmation de creation categorie
170  if ($action == 'confirmed')
171  {
172  if ($urlfrom)
173  {
174  header("Location: ".$urlfrom);
175  exit;
176  }
177  elseif ($backtopage)
178  {
179  header("Location: ".$backtopage);
180  exit;
181  }
182  else if ($idProdOrigin)
183  {
184  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProdOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
185  exit;
186  }
187  else if ($idCompanyOrigin)
188  {
189  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCompanyOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
190  exit;
191  }
192  else if ($idSupplierOrigin)
193  {
194  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idSupplierOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
195  exit;
196  }
197  else if ($idMemberOrigin)
198  {
199  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
200  exit;
201  }
202  else if ($idContactOrigin)
203  {
204  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
205  exit;
206  }
207  else if ($idProjectOrigin)
208  {
209  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProjectOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
210  exit;
211  }
212 
213  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$result.'&type='.$type);
214  exit;
215  }
216 }
217 
218 
219 /*
220  * View
221  */
222 
223 $form = new Form($db);
224 $formother = new FormOther($db);
225 
226 $helpurl='';
227 llxHeader("",$langs->trans("Categories"),$helpurl);
228 
229 if ($user->rights->categorie->creer)
230 {
231  // Create or add
232  if ($action == 'create' || $_POST["addcat"] == 'addcat')
233  {
234  dol_set_focus('#label');
235 
236  print '<form action="'.$_SERVER['PHP_SELF'].'?type='.$type.'" method="POST">';
237  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
238  print '<input type="hidden" name="urlfrom" value="'.$urlfrom.'">';
239  print '<input type="hidden" name="action" value="add">';
240  print '<input type="hidden" name="addcat" value="addcat">';
241  print '<input type="hidden" name="id" value="'.GETPOST('origin','alpha').'">';
242  print '<input type="hidden" name="type" value="'.$type.'">';
243  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
244  if ($origin) print '<input type="hidden" name="origin" value="'.$origin.'">';
245  if ($catorigin) print '<input type="hidden" name="catorigin" value="'.$catorigin.'">';
246 
247  print load_fiche_titre($langs->trans("CreateCat"));
248 
249  dol_fiche_head('');
250 
251  print '<table width="100%" class="border">';
252 
253  // Ref
254  print '<tr>';
255  print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td><input id="label" class="minwidth100" name="label" value="'.$label.'">';
256  print'</td></tr>';
257 
258  // Description
259  print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
260  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
261  $doleditor=new DolEditor('description',$description,'',200,'dolibarr_notes','',false,true,$conf->global->FCKEDITOR_ENABLE_PRODUCTDESC,ROWS_6,'90%');
262  $doleditor->Create();
263  print '</td></tr>';
264 
265  // Color
266  print '<tr><td>'.$langs->trans("Color").'</td><td>';
267  print $formother->selectColor($color,'color');
268  print '</td></tr>';
269 
270  // Parent category
271  print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
272  print $form->select_all_categories($type, $catorigin, 'parent');
273  print ajax_combobox('parent');
274  print '</td></tr>';
275 
276  $parameters=array();
277  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
278  print $hookmanager->resPrint;
279  if (empty($reshook))
280  {
281  print $object->showOptionals($extrafields,'edit');
282  }
283 
284  print '</table>';
285 
286  dol_fiche_end('');
287 
288  print '<div class="center">';
289  print '<input type="submit" class="button" value="'.$langs->trans("CreateThisCat").'" name="creation" />';
290  print '&nbsp; &nbsp; &nbsp;';
291  print '<input type="submit" class="button" value="'.$langs->trans("Cancel").'" name="cancel" />';
292  print '</div>';
293 
294  print '</form>';
295  }
296 }
297 
298 // End of page
299 llxFooter();
300 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:374
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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
if($_POST["cancel"]==$langs->trans("Cancel") &&! $id) if($action=='add' && $_POST["cancel"]<> $langs->trans("Cancel")) if($action=='delete') if($id) $form
Actions.
Definition: card.php:153
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
Class to manage a WYSIWYG editor.
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of &#39;autofocus&#39; HTML5 tag)
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
$parameters
Actions.
Definition: card.php:114