From e2b47b99191b13de4540917ccaeeb9a4484324e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Ferry?= Date: Sun, 16 Mar 2014 16:04:18 +0100 Subject: [PATCH] Category extrafields on categories: edit and view --- htdocs/categories/class/categorie.class.php | 44 ++++++++++++++++++++- htdocs/categories/edit.php | 13 +++++- htdocs/categories/viewcat.php | 11 ++++++ 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index de82480bf4f..f645739d25e 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -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); diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php index 388cf47436a..de85a6ca6e2 100644 --- a/htdocs/categories/edit.php +++ b/htdocs/categories/edit.php @@ -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 ''.$langs->trans("In").''; print $form->select_all_categories($type,$object->fk_parent,'parent',64,$object->id); print ''; +$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 ''; print '
'; diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index 53bd6179000..bec834e1ff9 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -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").''; print nl2br($object->description); print ''; +$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 ''; print '';