forked from Wavyzz/dolibarr
Merge pull request #13388 from OPEN-DSI/new-type-category-from-hook
NEW add category type from hook
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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 = '<a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("BackToList").'</a>';
|
||||
|
||||
$object->next_prev_filter = ' type = ' . $object->type;
|
||||
$object->ref = $object->label;
|
||||
$morehtmlref='<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
|
||||
$ways = $object->print_all_ways(" >> ", '', 1);
|
||||
@@ -136,7 +138,7 @@ if ($object->id)
|
||||
}
|
||||
$morehtmlref.='</div>';
|
||||
|
||||
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
|
||||
|
||||
@@ -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 = '<a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("BackToList").'</a>';
|
||||
|
||||
$object->next_prev_filter = ' type = ' . $object->type;
|
||||
$object->ref = $object->label;
|
||||
$morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
|
||||
$ways = $object->print_all_ways(" >> ", '', 1);
|
||||
@@ -207,7 +208,7 @@ foreach ($ways as $way)
|
||||
}
|
||||
$morehtmlref .= '</div>';
|
||||
|
||||
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 '<br>';
|
||||
|
||||
|
||||
@@ -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 = '<a href="'.$backtolist.'\">'.$langs->trans("BackToList").'</a>';
|
||||
$object->next_prev_filter=" type = ".$object->type;
|
||||
$linkback = '<a href="'.$backtolist.'">'.$langs->trans("BackToList").'</a>';
|
||||
$object->next_prev_filter = ' type = ' . $object->type;
|
||||
$object->ref = $object->label;
|
||||
$morehtmlref='<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
|
||||
$ways = $object->print_all_ways(" >> ", '', 1);
|
||||
@@ -233,7 +232,7 @@ foreach ($ways as $way)
|
||||
}
|
||||
$morehtmlref.='</div>';
|
||||
|
||||
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);
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -198,3 +198,4 @@ ALTER TABLE llx_entrepot ADD COLUMN phone varchar(20) DEFAULT NULL;
|
||||
|
||||
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';
|
||||
|
||||
Reference in New Issue
Block a user