dolibarr  7.0.0-beta
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@capnetworks.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 $langs->load("categories");
35 
36 // Security check
37 $socid=GETPOST('socid','int');
38 if (!$user->rights->categorie->lire) accessforbidden();
39 
40 $action = GETPOST('action','alpha');
41 $cancel = GETPOST('cancel','alpha');
42 $origin = GETPOST('origin','alpha');
43 $catorigin = GETPOST('catorigin','int');
44 $type = GETPOST('type','alpha');
45 $urlfrom = GETPOST('urlfrom','alpha');
46 
47 $socid=GETPOST('socid','int');
48 $label=GETPOST('label');
49 $description=GETPOST('description');
50 $color=GETPOST('color');
51 $visible=GETPOST('visible');
52 $parent=GETPOST('parent');
53 
54 if ($origin)
55 {
56  if ($type == Categorie::TYPE_PRODUCT) $idProdOrigin = $origin;
57  if ($type == Categorie::TYPE_SUPPLIER) $idSupplierOrigin = $origin;
58  if ($type == Categorie::TYPE_CUSTOMER) $idCompanyOrigin = $origin;
59  if ($type == Categorie::TYPE_MEMBER) $idMemberOrigin = $origin;
60  if ($type == Categorie::TYPE_CONTACT) $idContactOrigin = $origin;
61  if ($type == Categorie::TYPE_PROJECT) $idProjectOrigin = $origin;
62 }
63 
64 if ($catorigin && $type == Categorie::TYPE_PRODUCT) $idCatOrigin = $catorigin;
65 
66 $object = new Categorie($db);
67 
68 $extrafields = new ExtraFields($db);
69 $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
70 
71 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array
72 $hookmanager->initHooks(array('categorycard'));
73 
74 
75 /*
76  * Actions
77  */
78 
79 // Add action
80 if ($action == 'add' && $user->rights->categorie->creer)
81 {
82  // Action ajout d'une categorie
83  if ($cancel)
84  {
85  if ($urlfrom)
86  {
87  header("Location: ".$urlfrom);
88  exit;
89  }
90  else if ($idProdOrigin)
91  {
92  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProdOrigin.'&type='.$type);
93  exit;
94  }
95  else if ($idCompanyOrigin)
96  {
97  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCompanyOrigin.'&type='.$type);
98  exit;
99  }
100  else if ($idSupplierOrigin)
101  {
102  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idSupplierOrigin.'&type='.$type);
103  exit;
104  }
105  else if ($idMemberOrigin)
106  {
107  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$type);
108  exit;
109  }
110  else if ($idContactOrigin)
111  {
112  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&type='.$type);
113  exit;
114  }
115  else if ($idProjectOrigin)
116  {
117  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProjectOrigin.'&type='.$type);
118  exit;
119  }
120  else
121  {
122  header("Location: ".DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type);
123  exit;
124  }
125  }
126 
127 
128 
129  $object->label = $label;
130  $object->color = $color;
131  $object->description = dol_htmlcleanlastbr($description);
132  $object->socid = ($socid ? $socid : 'null');
133  $object->visible = $visible;
134  $object->type = $type;
135 
136  if ($parent != "-1") $object->fk_parent = $parent;
137 
138  $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
139  if ($ret < 0) $error++;
140 
141  if (! $object->label)
142  {
143  $error++;
144  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
145  $action = 'create';
146  }
147 
148  // Create category in database
149  if (! $error)
150  {
151  $result = $object->create($user);
152  if ($result > 0)
153  {
154  $action = 'confirmed';
155  $_POST["addcat"] = '';
156  }
157  else
158  {
159  setEventMessages($object->error, $object->errors, 'errors');
160  }
161  }
162 }
163 
164 // Confirm action
165 if (($action == 'add' || $action == 'confirmed') && $user->rights->categorie->creer)
166 {
167  // Action confirmation de creation categorie
168  if ($action == 'confirmed')
169  {
170  if ($urlfrom)
171  {
172  header("Location: ".$urlfrom);
173  exit;
174  }
175  else if ($idProdOrigin)
176  {
177  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProdOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
178  exit;
179  }
180  else if ($idCompanyOrigin)
181  {
182  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCompanyOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
183  exit;
184  }
185  else if ($idSupplierOrigin)
186  {
187  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idSupplierOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
188  exit;
189  }
190  else if ($idMemberOrigin)
191  {
192  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
193  exit;
194  }
195  else if ($idContactOrigin)
196  {
197  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
198  exit;
199  }
200  else if ($idProjectOrigin)
201  {
202  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProjectOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
203  exit;
204  }
205 
206  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$result.'&type='.$type);
207  exit;
208  }
209 }
210 
211 
212 /*
213  * View
214  */
215 
216 $form = new Form($db);
217 $formother = new FormOther($db);
218 
219 $helpurl='';
220 llxHeader("",$langs->trans("Categories"),$helpurl);
221 
222 if ($user->rights->categorie->creer)
223 {
224  // Create or add
225  if ($action == 'create' || $_POST["addcat"] == 'addcat')
226  {
227  dol_set_focus('#label');
228 
229  print '<form action="'.$_SERVER['PHP_SELF'].'?type='.$type.'" method="POST">';
230  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
231  print '<input type="hidden" name="urlfrom" value="'.$urlfrom.'">';
232  print '<input type="hidden" name="action" value="add">';
233  print '<input type="hidden" name="addcat" value="addcat">';
234  print '<input type="hidden" name="id" value="'.GETPOST('origin').'">';
235  print '<input type="hidden" name="type" value="'.$type.'">';
236  if ($origin) print '<input type="hidden" name="origin" value="'.$origin.'">';
237  if ($catorigin) print '<input type="hidden" name="catorigin" value="'.$catorigin.'">';
238 
239  print load_fiche_titre($langs->trans("CreateCat"));
240 
241  dol_fiche_head('');
242 
243  print '<table width="100%" class="border">';
244 
245  // Ref
246  print '<tr>';
247  print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td><input id="label" class="minwidth100" name="label" value="'.$label.'">';
248  print'</td></tr>';
249 
250  // Description
251  print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
252  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
253  $doleditor=new DolEditor('description',$description,'',200,'dolibarr_notes','',false,true,$conf->global->FCKEDITOR_ENABLE_PRODUCTDESC,ROWS_6,'90%');
254  $doleditor->Create();
255  print '</td></tr>';
256 
257  // Color
258  print '<tr><td>'.$langs->trans("Color").'</td><td>';
259  print $formother->selectColor($color,'color');
260  print '</td></tr>';
261 
262  // Parent category
263  print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
264  print $form->select_all_categories($type, $catorigin, 'parent');
265  print ajax_combobox('parent');
266  print '</td></tr>';
267 
268  $parameters=array();
269  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
270  print $hookmanager->resPrint;
271  if (empty($reshook) && ! empty($extrafields->attribute_label))
272  {
273  print $object->showOptionals($extrafields,'edit');
274  }
275 
276  print '</table>';
277 
278  dol_fiche_end('');
279 
280  print '<div class="center">';
281  print '<input type="submit" class="button" value="'.$langs->trans("CreateThisCat").'" name="creation" />';
282  print '&nbsp; &nbsp; &nbsp;';
283  print '<input type="submit" class="button" value="'.$langs->trans("Cancel").'" name="cancel" />';
284  print '</div>';
285 
286  print '</form>';
287  }
288 }
289 
290 
291 llxFooter();
292 
293 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:392
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.
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.
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...
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.
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
$parameters
Actions.
Definition: card.php:112