diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index e8296b96beb..2e8afdb0089 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -243,7 +243,49 @@ class Categorie extends CommonObject */ public function __construct($db) { + global $hookmanager; + $this->db = $db; + + if (is_object($hookmanager)) { + $hookmanager->initHooks(array('category')); + $parameters = array(); + $reshook = $hookmanager->executeHooks('constructCategory', $parameters, $this); // Note that $action and $object may have been modified by some hooks + if ($reshook >= 0 && !empty($hookmanager->resArray)) { + $mapList = $hookmanager->resArray; + $mapId = $mapList['id']; + $mapCode = $mapList['code']; + self::$MAP_ID_TO_CODE[$mapId] = $mapCode; + $this->MAP_ID[$mapCode] = $mapId; + $this->MAP_CAT_FK[$mapCode] = $mapList['cat_fk']; + $this->MAP_CAT_TABLE[$mapCode] = $mapList['cat_table']; + $this->MAP_OBJ_CLASS[$mapCode] = $mapList['obj_class']; + $this->MAP_OBJ_TABLE[$mapCode] = $mapList['obj_table']; + } + } + } + + /** + * Get map list + * + * @return array + */ + public function getMapList() + { + $mapList = array(); + + foreach ($this->MAP_ID as $mapCode => $mapId) { + $mapList[] = array( + 'id' => $mapId, + 'code' => $mapCode, + 'cat_fk' => $this->MAP_CAT_FK[$mapCode], + 'cat_table' => $this->MAP_CAT_TABLE[$mapCode], + 'obj_class' => $this->MAP_OBJ_CLASS[$mapCode], + 'obj_table' => $this->MAP_OBJ_TABLE[$mapCode] + ); + } + + return $mapList; } /** diff --git a/htdocs/categories/index.php b/htdocs/categories/index.php index d96fddca150..54a4ff9f1d2 100644 --- a/htdocs/categories/index.php +++ b/htdocs/categories/index.php @@ -40,6 +40,7 @@ $id = GETPOST('id', 'int'); $type = (GETPOST('type', 'aZ09') ? GETPOST('type', 'aZ09') : Categorie::TYPE_PRODUCT); $catname = GETPOST('catname', 'alpha'); +$categstatic = new Categorie($db); if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility @@ -47,25 +48,13 @@ if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backwar * View */ -$categstatic = new Categorie($db); $form = new Form($db); -if ($type == Categorie::TYPE_PRODUCT) { $title=$langs->trans("ProductsCategoriesArea"); $typetext='product'; } -elseif ($type == Categorie::TYPE_SUPPLIER) { $title=$langs->trans("SuppliersCategoriesArea"); $typetext='supplier'; } -elseif ($type == Categorie::TYPE_CUSTOMER) { $title=$langs->trans("CustomersCategoriesArea"); $typetext='customer'; } -elseif ($type == Categorie::TYPE_MEMBER) { $title=$langs->trans("MembersCategoriesArea"); $typetext='member'; } -elseif ($type == Categorie::TYPE_CONTACT) { $title=$langs->trans("ContactsCategoriesArea"); $typetext='contact'; } -elseif ($type == Categorie::TYPE_ACCOUNT) { $title=$langs->trans("AccountsCategoriesArea"); $typetext='bank_account'; } -elseif ($type == Categorie::TYPE_PROJECT) { $title=$langs->trans("ProjectsCategoriesArea"); $typetext='project'; } -elseif ($type == Categorie::TYPE_USER) { $title=$langs->trans("UsersCategoriesArea"); $typetext='user'; } -elseif ($type == Categorie::TYPE_WAREHOUSE) { $title=$langs->trans("StocksCategoriesArea"); $typetext='warehouse'; } -elseif ($type == Categorie::TYPE_ACTIONCOMM) { - $title = $langs->trans("ActionCommCategoriesArea"); - $typetext = 'actioncomm'; -} else { - $title = $langs->trans("CategoriesArea"); - $typetext = 'unknown'; -} +$typetext = $type; +if ($type == Categorie::TYPE_ACCOUNT) $title = $langs->trans('AccountsCategoriesArea'); +elseif ($type == Categorie::TYPE_WAREHOUSE) $title = $langs->trans('StocksCategoriesArea'); +elseif ($type == Categorie::TYPE_ACTIONCOMM) $title = $langs->trans('ActionCommCategoriesArea'); +else $title = $langs->trans(ucfirst($type). 'sCategoriesArea'); $arrayofjs=array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js'); $arrayofcss=array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css'); diff --git a/htdocs/categories/photos.php b/htdocs/categories/photos.php index ed6091e3568..b9fd23c1a3d 100644 --- a/htdocs/categories/photos.php +++ b/htdocs/categories/photos.php @@ -36,15 +36,13 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php'; $langs->loadlangs(array('categories', 'bills')); -$id = GETPOST('id', 'int'); -$ref = GETPOST('ref'); -$type = GETPOST('type'); -$action = GETPOST('action', 'aZ09'); +$id = GETPOST('id', 'int'); +$label = GETPOST('label', 'alpha'); +$type = GETPOST('type'); +$action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm'); -if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility - -if ($id == "") +if ($id == '' && $label == '') { dol_print_error('', 'Missing parameter id'); exit(); @@ -54,13 +52,17 @@ if ($id == "") $result = restrictedArea($user, 'categorie', $id, '&category'); $object = new Categorie($db); -if ($id > 0) -{ - $result = $object->fetch($id); - - $upload_dir = $conf->categorie->multidir_output[$object->entity]; +$result = $object->fetch($id, $label, $type); +if ($result <= 0) { + dol_print_error($db, $object->error); exit; } +$object->fetch_optionals(); +if ($result <= 0) { + dol_print_error($db, $object->error); exit; +} +$upload_dir = $conf->categorie->multidir_output[$object->entity]; +if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility /* * Actions @@ -126,7 +128,7 @@ if ($object->id) dol_fiche_head($head, 'photos', $title, -1, 'category'); $linkback = ''.$langs->trans("BackToList").''; - + $object->next_prev_filter = ' type = ' . $object->type; $object->ref = $object->label; $morehtmlref='
'.$langs->trans("Root").' >> '; $ways = $object->print_all_ways(" >> ", '', 1); @@ -136,7 +138,7 @@ if ($object->id) } $morehtmlref.='
'; - dol_banner_tab($object, 'ref', $linkback, ($user->socid?0:1), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1); + dol_banner_tab($object, 'label', $linkback, ($user->socid?0:1), 'label', 'label', $morehtmlref, '&type=' . $type, 0, '', '', 1); /* * Confirmation de la suppression de photo diff --git a/htdocs/categories/traduction.php b/htdocs/categories/traduction.php index 03ca6e977bd..697db116881 100644 --- a/htdocs/categories/traduction.php +++ b/htdocs/categories/traduction.php @@ -36,18 +36,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; $langs->loadLangs(array('categories', 'languages')); $id = GETPOST('id', 'int'); -$ref = GETPOST('ref', 'alpha'); +$label = GETPOST('label', 'alpha'); $action = GETPOST('action', 'alpha'); $cancel = GETPOST('cancel', 'alpha'); $type = GETPOST('type', 'aZ09'); -if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility - -// Security check -$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : '')); -$fieldtype = (!empty($ref) ? 'ref' : 'rowid'); - -if ($id == "") +if ($id == '' && $label == '') { dol_print_error('', 'Missing parameter id'); exit(); @@ -57,7 +51,16 @@ if ($id == "") $result = restrictedArea($user, 'categorie', $id, '&category'); $object = new Categorie($db); +$result = $object->fetch($id, $label, $type); +if ($result <= 0) { + dol_print_error($db, $object->error); exit; +} +$object->fetch_optionals(); +if ($result <= 0) { + dol_print_error($db, $object->error); exit; +} +if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility /* * Actions @@ -159,8 +162,6 @@ $cancel != $langs->trans("Cancel") && } } -$result = $object->fetch($id, $ref); - /* * View @@ -197,7 +198,7 @@ if (!empty($object->multilangs)) dol_fiche_head($head, 'translation', $title, -1, 'category'); $linkback = ''.$langs->trans("BackToList").''; - +$object->next_prev_filter = ' type = ' . $object->type; $object->ref = $object->label; $morehtmlref = '
'.$langs->trans("Root").' >> '; $ways = $object->print_all_ways(" >> ", '', 1); @@ -207,7 +208,7 @@ foreach ($ways as $way) } $morehtmlref .= '
'; -dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1); +dol_banner_tab($object, 'label', $linkback, ($user->socid ? 0 : 1), 'label', 'label', $morehtmlref, '&type=' . $type, 0, '', '', 1); print '
'; diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index 62538da0273..727ef8b0610 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -71,7 +71,7 @@ if ($id == "" && $label == "") $result = restrictedArea($user, 'categorie', $id, '&category'); $object = new Categorie($db); -$result = $object->fetch($id, $label); +$result = $object->fetch($id, $label, $type); if ($result <= 0) { dol_print_error($db, $object->error); exit; } @@ -80,7 +80,6 @@ if ($result <= 0) { dol_print_error($db, $object->error); exit; } -$type = $object->type; if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility $extrafields = new ExtraFields($db); @@ -222,8 +221,8 @@ $head = categories_prepare_head($object, $type); dol_fiche_head($head, 'card', $title, -1, 'category'); $backtolist = (GETPOST('backtolist') ? GETPOST('backtolist') : DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type); -$linkback = ''.$langs->trans("BackToList").''; -$object->next_prev_filter=" type = ".$object->type; +$linkback = ''.$langs->trans("BackToList").''; +$object->next_prev_filter = ' type = ' . $object->type; $object->ref = $object->label; $morehtmlref='
'.$langs->trans("Root").' >> '; $ways = $object->print_all_ways(" >> ", '', 1); @@ -233,7 +232,7 @@ foreach ($ways as $way) } $morehtmlref.='
'; -dol_banner_tab($object, 'label', $linkback, ($user->socid?0:1), 'label', 'label', $morehtmlref, '', 0, '', '', 1); +dol_banner_tab($object, 'label', $linkback, ($user->socid?0:1), 'label', 'label', $morehtmlref, '&type=' . $type, 0, '', '', 1); /* diff --git a/htdocs/install/mysql/migration/11.0.0-12.0.0.sql b/htdocs/install/mysql/migration/11.0.0-12.0.0.sql index b2d0b9b0bd1..aef9692bf75 100644 --- a/htdocs/install/mysql/migration/11.0.0-12.0.0.sql +++ b/htdocs/install/mysql/migration/11.0.0-12.0.0.sql @@ -198,3 +198,4 @@ ALTER TABLE llx_entrepot ADD COLUMN phone varchar(20) DEFAULT NULL AFTER fk_pays ALTER TABLE llx_accounting_account ADD COLUMN reconcilable tinyint DEFAULT 0 NOT NULL after active; +ALTER TABLE llx_categorie CHANGE type type integer NOT NULL DEFAULT '1';