30 require
'../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
36 $langs->load(
"categories");
39 $socid = (int)
GETPOST(
'socid',
'int');
40 if (!$user->rights->categorie->lire) {
44 $action =
GETPOST(
'action',
'alpha');
45 $cancel =
GETPOST(
'cancel',
'alpha');
46 $origin =
GETPOST(
'origin',
'alpha');
47 $catorigin = (int)
GETPOST(
'catorigin',
'int');
48 $type =
GETPOST(
'type',
'aZ09');
49 $urlfrom =
GETPOST(
'urlfrom',
'alpha');
50 $backtopage =
GETPOST(
'backtopage',
'alpha');
52 $label = (string)
GETPOST(
'label',
'alphanohtml');
53 $description = (string)
GETPOST(
'description',
'restricthtml');
54 $color = preg_replace(
'/[^0-9a-f#]/i',
'', (
string)
GETPOST(
'color',
'alphanohtml'));
55 $visible = (int)
GETPOST(
'visible',
'int');
56 $parent = (int)
GETPOST(
'parent',
'int');
59 if ($type == Categorie::TYPE_PRODUCT) {
60 $idProdOrigin = $origin;
62 if ($type == Categorie::TYPE_SUPPLIER) {
63 $idSupplierOrigin = $origin;
65 if ($type == Categorie::TYPE_CUSTOMER) {
66 $idCompanyOrigin = $origin;
68 if ($type == Categorie::TYPE_MEMBER) {
69 $idMemberOrigin = $origin;
71 if ($type == Categorie::TYPE_CONTACT) {
72 $idContactOrigin = $origin;
74 if ($type == Categorie::TYPE_PROJECT) {
75 $idProjectOrigin = $origin;
79 if ($catorigin && $type == Categorie::TYPE_PRODUCT) {
80 $idCatOrigin = $catorigin;
86 $extrafields->fetch_name_optionals_label($object->table_element);
89 $hookmanager->initHooks(array(
'categorycard'));
99 if ($action ==
'add' && $user->rights->categorie->creer) {
103 header(
"Location: ".$urlfrom);
105 } elseif ($backtopage) {
106 header(
"Location: ".$backtopage);
108 } elseif ($idProdOrigin) {
109 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idProdOrigin.
'&type='.$type);
111 } elseif ($idCompanyOrigin) {
112 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idCompanyOrigin.
'&type='.$type);
114 } elseif ($idSupplierOrigin) {
115 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idSupplierOrigin.
'&type='.$type);
117 } elseif ($idMemberOrigin) {
118 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idMemberOrigin.
'&type='.$type);
120 } elseif ($idContactOrigin) {
121 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idContactOrigin.
'&type='.$type);
123 } elseif ($idProjectOrigin) {
124 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idProjectOrigin.
'&type='.$type);
127 header(
"Location: ".DOL_URL_ROOT.
'/categories/index.php?leftmenu=cat&type='.$type);
134 $object->label = $label;
135 $object->color = $color;
137 $object->socid = ($socid > 0 ? $socid : 0);
138 $object->visible = $visible;
139 $object->type = $type;
141 if ($parent !=
"-1") {
142 $object->fk_parent = $parent;
145 $ret = $extrafields->setOptionalsFromPost(null, $object);
150 if (!$object->label) {
152 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Ref")), null,
'errors');
158 $result = $object->create($user);
160 $action =
'confirmed';
161 $_POST[
"addcat"] =
'';
169 if (($action ==
'add' || $action ==
'confirmed') && $user->rights->categorie->creer) {
171 if ($action ==
'confirmed') {
173 header(
"Location: ".$urlfrom);
175 } elseif ($backtopage) {
176 header(
"Location: ".$backtopage);
178 } elseif ($idProdOrigin) {
179 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idProdOrigin.
'&type='.$type.
'&mesg='.urlencode($langs->trans(
"CatCreated")));
181 } elseif ($idCompanyOrigin) {
182 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idCompanyOrigin.
'&type='.$type.
'&mesg='.urlencode($langs->trans(
"CatCreated")));
184 } elseif ($idSupplierOrigin) {
185 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idSupplierOrigin.
'&type='.$type.
'&mesg='.urlencode($langs->trans(
"CatCreated")));
187 } elseif ($idMemberOrigin) {
188 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idMemberOrigin.
'&type='.$type.
'&mesg='.urlencode($langs->trans(
"CatCreated")));
190 } elseif ($idContactOrigin) {
191 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idContactOrigin.
'&type='.$type.
'&mesg='.urlencode($langs->trans(
"CatCreated")));
193 } elseif ($idProjectOrigin) {
194 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idProjectOrigin.
'&type='.$type.
'&mesg='.urlencode($langs->trans(
"CatCreated")));
198 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$result.
'&type='.$type);
211 $help_url =
'EN:Module_Categories|FR:Module_Catégories|DE:Modul_Kategorien';
215 if ($user->rights->categorie->creer) {
217 if ($action ==
'create' ||
GETPOST(
"addcat") ==
'addcat') {
220 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?type='.$type.
'" method="POST">';
221 print
'<input type="hidden" name="token" value="'.newToken().
'">';
222 print
'<input type="hidden" name="urlfrom" value="'.$urlfrom.
'">';
223 print
'<input type="hidden" name="action" value="add">';
224 print
'<input type="hidden" name="addcat" value="addcat">';
225 print
'<input type="hidden" name="id" value="'.GETPOST(
'origin',
'alpha').
'">';
226 print
'<input type="hidden" name="type" value="'.$type.
'">';
227 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
229 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
232 print
'<input type="hidden" name="catorigin" value="'.$catorigin.
'">';
239 print
'<table width="100%" class="border">';
243 print
'<td class="titlefieldcreate fieldrequired">'.$langs->trans(
"Ref").
'</td><td><input id="label" class="minwidth100" name="label" value="'.
dol_escape_htmltag($label).
'">';
247 print
'<tr><td class="tdtop">'.$langs->trans(
"Description").
'</td><td>';
248 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
249 $doleditor =
new DolEditor(
'description', $description,
'', 160,
'dolibarr_notes',
'',
false,
true,
getDolGlobalInt(
'FCKEDITOR_ENABLE_PRODUCTDESC'), ROWS_5,
'90%');
250 $doleditor->Create();
254 print
'<tr><td>'.$langs->trans(
"Color").
'</td><td>';
255 print $formother->selectColor($color,
'color');
259 print
'<tr><td>'.$langs->trans(
"AddIn").
'</td><td>';
260 print
img_picto($langs->trans(
"ParentCategory"),
'category',
'class="pictofixedwidth"');
261 print
$form->select_all_categories($type, $catorigin,
'parent');
265 $parameters = array();
266 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
267 print $hookmanager->resPrint;
268 if (empty($reshook)) {
269 print $object->showOptionals($extrafields,
'create', $parameters);
276 print
'<div class="center">';
277 print
'<input type="submit" class="button b" value="'.$langs->trans(
"CreateThisCat").
'" name="creation" />';
278 print
' ';
279 print
'<input type="submit" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'" name="cancel" />';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
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.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage categories.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete= 'resolve', $idforemptyvalue= '-1')
Convert a html select field into an ajax combobox.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage a WYSIWYG editor.
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)