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');
42 $action =
GETPOST(
'action',
'alpha');
43 $cancel =
GETPOST(
'cancel',
'alpha');
44 $origin =
GETPOST(
'origin',
'alpha');
45 $catorigin = (int)
GETPOST(
'catorigin',
'int');
46 $type =
GETPOST(
'type',
'aZ09');
47 $urlfrom =
GETPOST(
'urlfrom',
'alpha');
48 $backtopage =
GETPOST(
'backtopage',
'alpha');
50 $label = (string)
GETPOST(
'label',
'alphanohtml');
51 $description = (string)
GETPOST(
'description',
'restricthtml');
52 $color = preg_replace(
'/[^0-9a-f#]/i',
'', (
string)
GETPOST(
'color',
'alphanohtml'));
53 $visible = (int)
GETPOST(
'visible',
'int');
54 $parent = (int)
GETPOST(
'parent',
'int');
57 if ($type == Categorie::TYPE_PRODUCT) $idProdOrigin = $origin;
58 if ($type == Categorie::TYPE_SUPPLIER) $idSupplierOrigin = $origin;
59 if ($type == Categorie::TYPE_CUSTOMER) $idCompanyOrigin = $origin;
60 if ($type == Categorie::TYPE_MEMBER) $idMemberOrigin = $origin;
61 if ($type == Categorie::TYPE_CONTACT) $idContactOrigin = $origin;
62 if ($type == Categorie::TYPE_PROJECT) $idProjectOrigin = $origin;
65 if ($catorigin && $type == Categorie::TYPE_PRODUCT) $idCatOrigin = $catorigin;
70 $extrafields->fetch_name_optionals_label($object->table_element);
73 $hookmanager->initHooks(array(
'categorycard'));
83 if ($action ==
'add' && $user->rights->categorie->creer)
90 header(
"Location: ".$urlfrom);
92 } elseif ($backtopage) {
93 header(
"Location: ".$backtopage);
95 } elseif ($idProdOrigin) {
96 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idProdOrigin.
'&type='.$type);
98 } elseif ($idCompanyOrigin) {
99 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idCompanyOrigin.
'&type='.$type);
101 } elseif ($idSupplierOrigin) {
102 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idSupplierOrigin.
'&type='.$type);
104 } elseif ($idMemberOrigin) {
105 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idMemberOrigin.
'&type='.$type);
107 } elseif ($idContactOrigin) {
108 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idContactOrigin.
'&type='.$type);
110 } elseif ($idProjectOrigin) {
111 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idProjectOrigin.
'&type='.$type);
114 header(
"Location: ".DOL_URL_ROOT.
'/categories/index.php?leftmenu=cat&type='.$type);
121 $object->label = $label;
122 $object->color = $color;
124 $object->socid = ($socid > 0 ? $socid : 0);
125 $object->visible = $visible;
126 $object->type = $type;
128 if ($parent !=
"-1") $object->fk_parent = $parent;
130 $ret = $extrafields->setOptionalsFromPost(null, $object);
131 if ($ret < 0) $error++;
136 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Ref")), null,
'errors');
143 $result = $object->create($user);
146 $action =
'confirmed';
147 $_POST[
"addcat"] =
'';
155 if (($action ==
'add' || $action ==
'confirmed') && $user->rights->categorie->creer)
158 if ($action ==
'confirmed')
162 header(
"Location: ".$urlfrom);
164 } elseif ($backtopage)
166 header(
"Location: ".$backtopage);
168 } elseif ($idProdOrigin)
170 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idProdOrigin.
'&type='.$type.
'&mesg='.urlencode($langs->trans(
"CatCreated")));
172 } elseif ($idCompanyOrigin)
174 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idCompanyOrigin.
'&type='.$type.
'&mesg='.urlencode($langs->trans(
"CatCreated")));
176 } elseif ($idSupplierOrigin)
178 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idSupplierOrigin.
'&type='.$type.
'&mesg='.urlencode($langs->trans(
"CatCreated")));
180 } elseif ($idMemberOrigin)
182 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idMemberOrigin.
'&type='.$type.
'&mesg='.urlencode($langs->trans(
"CatCreated")));
184 } elseif ($idContactOrigin)
186 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idContactOrigin.
'&type='.$type.
'&mesg='.urlencode($langs->trans(
"CatCreated")));
188 } elseif ($idProjectOrigin)
190 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idProjectOrigin.
'&type='.$type.
'&mesg='.urlencode($langs->trans(
"CatCreated")));
194 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$result.
'&type='.$type);
204 $form =
new Form($db);
208 llxHeader(
"", $langs->trans(
"Categories"), $helpurl);
210 if ($user->rights->categorie->creer)
213 if ($action ==
'create' ||
GETPOST(
"addcat") ==
'addcat')
217 print '<form action="'.$_SERVER[
'PHP_SELF'].
'?type='.$type.
'" method="POST">';
218 print '<input type="hidden" name="token" value="'.newToken().
'">';
219 print '<input type="hidden" name="urlfrom" value="'.$urlfrom.
'">';
220 print '<input type="hidden" name="action" value="add">';
221 print '<input type="hidden" name="addcat" value="addcat">';
222 print '<input type="hidden" name="id" value="'.GETPOST(
'origin',
'alpha').
'">';
223 print '<input type="hidden" name="type" value="'.$type.
'">';
224 print '<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
225 if ($origin)
print '<input type="hidden" name="origin" value="'.$origin.
'">';
226 if ($catorigin)
print '<input type="hidden" name="catorigin" value="'.$catorigin.
'">';
232 print '<table width="100%" class="border">';
236 print '<td class="titlefieldcreate fieldrequired">'.$langs->trans(
"Ref").
'</td><td><input id="label" class="minwidth100" name="label" value="'.
dol_escape_htmltag($label).
'">';
240 print '<tr><td class="tdtop">'.$langs->trans(
"Description").
'</td><td>';
241 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
242 $doleditor =
new DolEditor(
'description', $description,
'', 160,
'dolibarr_notes',
'',
false,
true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_5,
'90%');
243 $doleditor->Create();
247 print '<tr><td>'.$langs->trans(
"Color").
'</td><td>';
248 print $formother->selectColor($color,
'color');
252 print '<tr><td>'.$langs->trans(
"AddIn").
'</td><td>';
253 print $form->select_all_categories($type, $catorigin,
'parent');
257 $parameters = array();
258 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
259 print $hookmanager->resPrint;
262 print $object->showOptionals($extrafields,
'edit', $parameters);
269 print '<div class="center">';
270 print '<input type="submit" class="button" value="'.$langs->trans(
"CreateThisCat").
'" name="creation" />';
271 print ' ';
272 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.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete= 'resolve')
Convert a html select field into an ajax combobox.
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.
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 ...
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
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)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...