31require
'../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
37$langs->load(
"categories");
40$socid = (int)
GETPOST(
'socid',
'int');
41if (!$user->hasRight(
'categorie',
'lire')) {
45$action =
GETPOST(
'action',
'alpha');
46$cancel =
GETPOST(
'cancel',
'alpha');
47$origin =
GETPOST(
'origin',
'alpha');
48$catorigin = (int)
GETPOST(
'catorigin',
'int');
50$urlfrom =
GETPOST(
'urlfrom',
'alpha');
51$backtopage =
GETPOST(
'backtopage',
'alpha');
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');
60 if ($type == Categorie::TYPE_PRODUCT) {
61 $idProdOrigin = $origin;
63 if ($type == Categorie::TYPE_SUPPLIER) {
64 $idSupplierOrigin = $origin;
66 if ($type == Categorie::TYPE_CUSTOMER) {
67 $idCompanyOrigin = $origin;
69 if ($type == Categorie::TYPE_MEMBER) {
70 $idMemberOrigin = $origin;
72 if ($type == Categorie::TYPE_CONTACT) {
73 $idContactOrigin = $origin;
75 if ($type == Categorie::TYPE_PROJECT) {
76 $idProjectOrigin = $origin;
80if ($catorigin && $type == Categorie::TYPE_PRODUCT) {
81 $idCatOrigin = $catorigin;
87$extrafields->fetch_name_optionals_label($object->table_element);
90$hookmanager->initHooks(array(
'categorycard'));
98$parameters = array(
'socid' => $socid,
'origin' => $origin,
'catorigin' => $catorigin,
'type' => $type,
'urlfrom' => $urlfrom,
'backtopage' => $backtopage,
'label' => $label,
'description' => $description,
'color' => $color,
'visible' => $visible,
'parent' => $parent);
100$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
105if (empty($reshook)) {
107 if ($action ==
'add' && $user->hasRight(
'categorie',
'creer')) {
111 header(
"Location: ".$urlfrom);
113 } elseif ($backtopage) {
114 header(
"Location: ".$backtopage);
116 } elseif ($idProdOrigin) {
117 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idProdOrigin.
'&type='.$type);
119 } elseif ($idCompanyOrigin) {
120 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idCompanyOrigin.
'&type='.$type);
122 } elseif ($idSupplierOrigin) {
123 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idSupplierOrigin.
'&type='.$type);
125 } elseif ($idMemberOrigin) {
126 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idMemberOrigin.
'&type='.$type);
128 } elseif ($idContactOrigin) {
129 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idContactOrigin.
'&type='.$type);
131 } elseif ($idProjectOrigin) {
132 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idProjectOrigin.
'&type='.$type);
135 header(
"Location: ".DOL_URL_ROOT.
'/categories/index.php?leftmenu=cat&type='.$type);
139 $object->label = $label;
140 $object->color = $color;
142 $object->socid = ($socid > 0 ? $socid : 0);
143 $object->visible = $visible;
144 $object->type = $type;
146 if ($parent !=
"-1") {
147 $object->fk_parent = $parent;
150 $ret = $extrafields->setOptionalsFromPost(
null, $object);
155 if (!$object->label) {
157 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Ref")),
null,
'errors');
163 $result = $object->create($user);
165 $action =
'confirmed';
166 $_POST[
"addcat"] =
'';
173 if (($action ==
'add' || $action ==
'confirmed') && $user->hasRight(
'categorie',
'creer')) {
175 if ($action ==
'confirmed') {
177 header(
"Location: ".$urlfrom);
179 } elseif ($backtopage) {
180 header(
"Location: ".$backtopage);
182 } elseif ($idProdOrigin) {
183 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idProdOrigin.
'&type='.$type.
'&mesg='.urlencode($langs->trans(
"CatCreated")));
185 } elseif ($idCompanyOrigin) {
186 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idCompanyOrigin.
'&type='.$type.
'&mesg='.urlencode($langs->trans(
"CatCreated")));
188 } elseif ($idSupplierOrigin) {
189 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idSupplierOrigin.
'&type='.$type.
'&mesg='.urlencode($langs->trans(
"CatCreated")));
191 } elseif ($idMemberOrigin) {
192 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idMemberOrigin.
'&type='.$type.
'&mesg='.urlencode($langs->trans(
"CatCreated")));
194 } elseif ($idContactOrigin) {
195 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idContactOrigin.
'&type='.$type.
'&mesg='.urlencode($langs->trans(
"CatCreated")));
197 } elseif ($idProjectOrigin) {
198 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$idProjectOrigin.
'&type='.$type.
'&mesg='.urlencode($langs->trans(
"CatCreated")));
202 header(
"Location: ".DOL_URL_ROOT.
'/categories/viewcat.php?id='.$result.
'&type='.$type);
212$form =
new Form($db);
215$help_url =
'EN:Module_Categories|FR:Module_Catégories|DE:Modul_Kategorien';
217llxHeader(
"", $langs->trans(
"Categories"), $help_url);
219if ($user->hasRight(
'categorie',
'creer')) {
221 if ($action ==
'create' ||
GETPOST(
"addcat") ==
'addcat') {
224 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?type='.$type.
'" method="POST">';
225 print
'<input type="hidden" name="token" value="'.newToken().
'">';
226 print
'<input type="hidden" name="urlfrom" value="'.$urlfrom.
'">';
227 print
'<input type="hidden" name="action" value="add">';
228 print
'<input type="hidden" name="addcat" value="addcat">';
229 print
'<input type="hidden" name="id" value="'.GETPOST(
'origin',
'alpha').
'">';
230 print
'<input type="hidden" name="type" value="'.$type.
'">';
231 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
233 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
236 print
'<input type="hidden" name="catorigin" value="'.$catorigin.
'">';
243 print
'<table width="100%" class="border">';
247 print
'<td class="titlefieldcreate fieldrequired">'.$langs->trans(
"Ref").
'</td><td><input id="label" class="minwidth100" name="label" value="'.
dol_escape_htmltag($label).
'">';
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,
'', 160,
'dolibarr_notes',
'',
false,
true,
getDolGlobalInt(
'FCKEDITOR_ENABLE_SOCIETE'), ROWS_5,
'90%');
254 $doleditor->Create();
258 print
'<tr><td>'.$langs->trans(
"Color").
'</td><td>';
259 print $formother->selectColor($color,
'color');
263 print
'<tr><td>'.$langs->trans(
"AddIn").
'</td><td>';
264 print
img_picto($langs->trans(
"ParentCategory"),
'category',
'class="pictofixedwidth"');
265 print $form->select_all_categories($type, $catorigin,
'parent');
269 $parameters = array();
270 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
271 print $hookmanager->resPrint;
272 if (empty($reshook)) {
273 print $object->showOptionals($extrafields,
'create', $parameters);
280 print
'<div class="center">';
281 print
'<input type="submit" class="button b" value="'.$langs->trans(
"CreateThisCat").
'" name="creation" />';
282 print
' ';
283 print
'<input type="submit" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'" name="cancel" />';
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage categories.
Class to manage a WYSIWYG editor.
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 a 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.