Category extrafields on categories: edit and view
This commit is contained in:
parent
d9baae3456
commit
e2b47b9919
@ -103,6 +103,8 @@ class Categorie extends CommonObject
|
||||
$this->visible = $res['visible'];
|
||||
$this->type = $res['type'];
|
||||
$this->entity = $res['entity'];
|
||||
|
||||
$this->fetch_optionals($this->id,$extralabels);
|
||||
|
||||
$this->db->free($resql);
|
||||
|
||||
@ -131,7 +133,7 @@ class Categorie extends CommonObject
|
||||
*/
|
||||
function create($user='')
|
||||
{
|
||||
global $conf,$langs;
|
||||
global $conf,$langs,$hookmanager;
|
||||
$langs->load('categories');
|
||||
|
||||
$error=0;
|
||||
@ -189,6 +191,24 @@ class Categorie extends CommonObject
|
||||
if ($id > 0)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
// Actions on extra fields (by external module or standard code)
|
||||
// FIXME le hook fait double emploi avec le trigger !!
|
||||
$hookmanager->initHooks(array('HookModuleNamedao'));
|
||||
$parameters=array('socid'=>$this->id);
|
||||
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
||||
if (empty($reshook))
|
||||
{
|
||||
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
|
||||
{
|
||||
$result=$this->insertExtraFields();
|
||||
if ($result < 0)
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($reshook < 0) $error++;
|
||||
|
||||
// Appel des triggers
|
||||
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
||||
@ -225,7 +245,7 @@ class Categorie extends CommonObject
|
||||
*/
|
||||
function update($user='')
|
||||
{
|
||||
global $conf, $langs;
|
||||
global $conf, $langs,$hookmanager;
|
||||
|
||||
$error=0;
|
||||
|
||||
@ -258,8 +278,28 @@ class Categorie extends CommonObject
|
||||
dol_syslog(get_class($this)."::update sql=".$sql);
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
|
||||
// Actions on extra fields (by external module or standard code)
|
||||
// FIXME le hook fait double emploi avec le trigger !!
|
||||
$hookmanager->initHooks(array('HookCategorydao'));
|
||||
$parameters=array();
|
||||
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
||||
if (empty($reshook))
|
||||
{
|
||||
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
|
||||
{
|
||||
$result=$this->insertExtraFields();
|
||||
if ($result < 0)
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($reshook < 0) $error++;
|
||||
|
||||
$this->db->commit();
|
||||
|
||||
|
||||
// Appel des triggers
|
||||
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
||||
$interface=new Interfaces($this->db);
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
|
||||
require '../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
|
||||
|
||||
$langs->load("categories");
|
||||
|
||||
@ -50,7 +51,10 @@ if ($id == "")
|
||||
// Security check
|
||||
$result = restrictedArea($user, 'categorie', $id, '&category');
|
||||
|
||||
$object = new Categorie($db);
|
||||
|
||||
$extrafields = new ExtraFields($db);
|
||||
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
|
||||
|
||||
/*
|
||||
* Actions
|
||||
@ -85,6 +89,8 @@ if ($action == 'update' && $user->rights->categorie->creer)
|
||||
}
|
||||
if (empty($categorie->error))
|
||||
{
|
||||
$ret = $extrafields->setOptionalsFromPost($extralabels,$categorie);
|
||||
|
||||
if ($categorie->update($user) > 0)
|
||||
{
|
||||
header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$categorie->id.'&type='.$type);
|
||||
@ -115,7 +121,6 @@ print_fiche_titre($langs->trans("ModifCat"));
|
||||
dol_htmloutput_errors($mesg);
|
||||
|
||||
|
||||
$object = new Categorie($db);
|
||||
$object->fetch($id);
|
||||
|
||||
$form = new Form($db);
|
||||
@ -153,6 +158,12 @@ print '<tr><td>'.$langs->trans("In").'</td><td>';
|
||||
print $form->select_all_categories($type,$object->fk_parent,'parent',64,$object->id);
|
||||
print '</td></tr>';
|
||||
|
||||
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
|
||||
if (empty($reshook) && ! empty($extrafields->attribute_label))
|
||||
{
|
||||
print $object->showOptionals($extrafields,'edit');
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
print '<br>';
|
||||
|
||||
|
||||
@ -27,6 +27,8 @@
|
||||
require '../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
|
||||
|
||||
|
||||
$langs->load("categories");
|
||||
|
||||
@ -49,6 +51,7 @@ $result = restrictedArea($user, 'categorie', $id, '&category');
|
||||
|
||||
$object = new Categorie($db);
|
||||
$result=$object->fetch($id);
|
||||
$object->fetch_optionals($id,$extralabels);
|
||||
if ($result <= 0)
|
||||
{
|
||||
dol_print_error($db,$object->error);
|
||||
@ -57,6 +60,8 @@ if ($result <= 0)
|
||||
|
||||
$type=$object->type;
|
||||
|
||||
$extrafields = new ExtraFields($db);
|
||||
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
|
||||
|
||||
/*
|
||||
* Actions
|
||||
@ -166,6 +171,12 @@ print $langs->trans("Description").'</td><td>';
|
||||
print nl2br($object->description);
|
||||
print '</td></tr>';
|
||||
|
||||
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
|
||||
if (empty($reshook) && ! empty($extrafields->attribute_label))
|
||||
{
|
||||
print $object->showOptionals($extrafields);
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
|
||||
print '</div>';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user