dolibarr  19.0.0-dev
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
3  * Copyright (C) 2006-2021 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  * Copyright (C) 2020 Frédéric France <frederic.france@netlogic.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
30 // Load Dolibarr environment
31 require '../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
35 
36 // Load translation files required by the page
37 $langs->load("categories");
38 
39 // Security check
40 $socid = (int) GETPOST('socid', 'int');
41 if (!$user->hasRight('categorie', 'lire')) {
43 }
44 
45 $action = GETPOST('action', 'alpha');
46 $cancel = GETPOST('cancel', 'alpha');
47 $origin = GETPOST('origin', 'alpha');
48 $catorigin = (int) GETPOST('catorigin', 'int');
49 $type = GETPOST('type', 'aZ09');
50 $urlfrom = GETPOST('urlfrom', 'alpha');
51 $backtopage = GETPOST('backtopage', 'alpha');
52 
53 $label = (string) GETPOST('label', 'alphanohtml');
54 $description = (string) GETPOST('description', 'restricthtml');
55 $color = preg_replace('/[^0-9a-f#]/i', '', (string) GETPOST('color', 'alphanohtml'));
56 $visible = (int) GETPOST('visible', 'int');
57 $parent = (int) GETPOST('parent', 'int');
58 
59 if ($origin) {
60  if ($type == Categorie::TYPE_PRODUCT) {
61  $idProdOrigin = $origin;
62  }
63  if ($type == Categorie::TYPE_SUPPLIER) {
64  $idSupplierOrigin = $origin;
65  }
66  if ($type == Categorie::TYPE_CUSTOMER) {
67  $idCompanyOrigin = $origin;
68  }
69  if ($type == Categorie::TYPE_MEMBER) {
70  $idMemberOrigin = $origin;
71  }
72  if ($type == Categorie::TYPE_CONTACT) {
73  $idContactOrigin = $origin;
74  }
75  if ($type == Categorie::TYPE_PROJECT) {
76  $idProjectOrigin = $origin;
77  }
78 }
79 
80 if ($catorigin && $type == Categorie::TYPE_PRODUCT) {
81  $idCatOrigin = $catorigin;
82 }
83 
84 $object = new Categorie($db);
85 
86 $extrafields = new ExtraFields($db);
87 $extrafields->fetch_name_optionals_label($object->table_element);
88 
89 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array
90 $hookmanager->initHooks(array('categorycard'));
91 
92 $error = 0;
93 
94 
95 /*
96  * Actions
97  */
98 
99 // Add action
100 if ($action == 'add' && $user->rights->categorie->creer) {
101  // Action add a category
102  if ($cancel) {
103  if ($urlfrom) {
104  header("Location: ".$urlfrom);
105  exit;
106  } elseif ($backtopage) {
107  header("Location: ".$backtopage);
108  exit;
109  } elseif ($idProdOrigin) {
110  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProdOrigin.'&type='.$type);
111  exit;
112  } elseif ($idCompanyOrigin) {
113  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCompanyOrigin.'&type='.$type);
114  exit;
115  } elseif ($idSupplierOrigin) {
116  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idSupplierOrigin.'&type='.$type);
117  exit;
118  } elseif ($idMemberOrigin) {
119  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$type);
120  exit;
121  } elseif ($idContactOrigin) {
122  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&type='.$type);
123  exit;
124  } elseif ($idProjectOrigin) {
125  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProjectOrigin.'&type='.$type);
126  exit;
127  } else {
128  header("Location: ".DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type);
129  exit;
130  }
131  }
132 
133 
134 
135  $object->label = $label;
136  $object->color = $color;
137  $object->description = dol_htmlcleanlastbr($description);
138  $object->socid = ($socid > 0 ? $socid : 0);
139  $object->visible = $visible;
140  $object->type = $type;
141 
142  if ($parent != "-1") {
143  $object->fk_parent = $parent;
144  }
145 
146  $ret = $extrafields->setOptionalsFromPost(null, $object);
147  if ($ret < 0) {
148  $error++;
149  }
150 
151  if (!$object->label) {
152  $error++;
153  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
154  $action = 'create';
155  }
156 
157  // Create category in database
158  if (!$error) {
159  $result = $object->create($user);
160  if ($result > 0) {
161  $action = 'confirmed';
162  $_POST["addcat"] = '';
163  } else {
164  setEventMessages($object->error, $object->errors, 'errors');
165  }
166  }
167 }
168 
169 // Confirm action
170 if (($action == 'add' || $action == 'confirmed') && $user->rights->categorie->creer) {
171  // Action confirmation of creation category
172  if ($action == 'confirmed') {
173  if ($urlfrom) {
174  header("Location: ".$urlfrom);
175  exit;
176  } elseif ($backtopage) {
177  header("Location: ".$backtopage);
178  exit;
179  } elseif ($idProdOrigin) {
180  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProdOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
181  exit;
182  } elseif ($idCompanyOrigin) {
183  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCompanyOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
184  exit;
185  } elseif ($idSupplierOrigin) {
186  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idSupplierOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
187  exit;
188  } elseif ($idMemberOrigin) {
189  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
190  exit;
191  } elseif ($idContactOrigin) {
192  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
193  exit;
194  } elseif ($idProjectOrigin) {
195  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProjectOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
196  exit;
197  }
198 
199  header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$result.'&type='.$type);
200  exit;
201  }
202 }
203 
204 
205 /*
206  * View
207  */
208 
209 $form = new Form($db);
210 $formother = new FormOther($db);
211 
212 $help_url = 'EN:Module_Categories|FR:Module_Catégories|DE:Modul_Kategorien';
213 
214 llxHeader("", $langs->trans("Categories"), $help_url);
215 
216 if ($user->rights->categorie->creer) {
217  // Create or add
218  if ($action == 'create' || GETPOST("addcat") == 'addcat') {
219  dol_set_focus('#label');
220 
221  print '<form action="'.$_SERVER['PHP_SELF'].'?type='.$type.'" method="POST">';
222  print '<input type="hidden" name="token" value="'.newToken().'">';
223  print '<input type="hidden" name="urlfrom" value="'.$urlfrom.'">';
224  print '<input type="hidden" name="action" value="add">';
225  print '<input type="hidden" name="addcat" value="addcat">';
226  print '<input type="hidden" name="id" value="'.GETPOST('origin', 'alpha').'">';
227  print '<input type="hidden" name="type" value="'.$type.'">';
228  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
229  if ($origin) {
230  print '<input type="hidden" name="origin" value="'.$origin.'">';
231  }
232  if ($catorigin) {
233  print '<input type="hidden" name="catorigin" value="'.$catorigin.'">';
234  }
235 
236  print load_fiche_titre($langs->trans("CreateCat"));
237 
238  print dol_get_fiche_head('');
239 
240  print '<table width="100%" class="border">';
241 
242  // Ref
243  print '<tr>';
244  print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td><input id="label" class="minwidth100" name="label" value="'.dol_escape_htmltag($label).'">';
245  print'</td></tr>';
246 
247  // Description
248  print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
249  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
250  $doleditor = new DolEditor('description', $description, '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_5, '90%');
251  $doleditor->Create();
252  print '</td></tr>';
253 
254  // Color
255  print '<tr><td>'.$langs->trans("Color").'</td><td>';
256  print $formother->selectColor($color, 'color');
257  print '</td></tr>';
258 
259  // Parent category
260  print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
261  print img_picto($langs->trans("ParentCategory"), 'category', 'class="pictofixedwidth"');
262  print $form->select_all_categories($type, $catorigin, 'parent');
263  print ajax_combobox('parent');
264  print '</td></tr>';
265 
266  $parameters = array();
267  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
268  print $hookmanager->resPrint;
269  if (empty($reshook)) {
270  print $object->showOptionals($extrafields, 'create', $parameters);
271  }
272 
273  print '</table>';
274 
275  print dol_get_fiche_end('');
276 
277  print '<div class="center">';
278  print '<input type="submit" class="button b" value="'.$langs->trans("CreateThisCat").'" name="creation" />';
279  print '&nbsp; &nbsp; &nbsp;';
280  print '<input type="submit" class="button button-cancel" value="'.$langs->trans("Cancel").'" name="cancel" />';
281  print '</div>';
282 
283  print '</form>';
284  }
285 }
286 
287 // End of page
288 llxFooter();
289 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:449
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage categories.
Class to manage a WYSIWYG editor.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
Classe permettant la generation de composants html autre Only common components are here.
$parameters
Actions.
Definition: card.php:83
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.