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='