diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 24d8c40f5b3..7bebeb0b660 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -596,7 +596,7 @@ class ExtraFields $this->attribute_pos[$tab->name]=$tab->pos; $this->attribute_alwayseditable[$tab->name]=$tab->alwayseditable; $this->attribute_perms[$tab->name]=$tab->perms; - $this->attribute_perms[$tab->name]=$tab->list; + $this->attribute_list[$tab->name]=$tab->list; } } } diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 3ad0ec897f9..5cb0ca81faf 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -128,10 +128,8 @@ class HookManager $parameters['context']=join(':',$this->contextarray); dol_syslog(get_class($this).'::executeHooks method='.$method." action=".$action." context=".$parameters['context']); - // Define type of hook ('output', 'returnvalue' or 'addreplace'). 'addreplace' should be type for all hooks. 'output' and 'returnvalue' are deprecated. + // Define type of hook ('output' or 'addreplace'. 'returnvalue' is deprecated). $hooktype='output'; - if (preg_match('/^pdf_/',$method)) $hooktype='returnvalue'; // pdf_xxx except pdf_writelinedesc are returnvalue hooks. When there is 2 hooks of this type, only last one win. - if ($method =='insertExtraFields') $hooktype='returnvalue'; if (in_array( $method, array( @@ -149,6 +147,13 @@ class HookManager 'formatEvent' ) )) $hooktype='addreplace'; + // Deprecated hook types + if (preg_match('/^pdf_/',$method) && $method != 'pdf_writelinedesc') $hooktype='returnvalue'; // pdf_xxx except pdf_writelinedesc are 'returnvalue' hooks. When there is 2 hooks of this type, only last one win. TODO Move them into 'output' or 'addreplace' hooks. + if ($method == 'insertExtraFields') + { + $hooktype='returnvalue'; // deprecated. TODO Remove all code with "executeHooks('insertExtraFields'" as soon as there is a trigger available. + dol_syslog("Warning: The hook 'insertExtraFields' is deprecated and must not be used. Use instead trigger on CRUD event (ask it to dev team if not implemented)", LOG_WARNING); + } // Loop on each hook to qualify modules that have declared context $modulealreadyexecuted=array(); @@ -201,8 +206,6 @@ class HookManager if (! empty($actionclassinstance->results) && is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results); if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints; - // TODO dead code to remove (do not enable this, but fix hook instead) - //if (is_array($result)) $this->resArray = array_merge($this->resArray, $result); // TODO dead code to remove (do not enable this, but fix hook instead): result must not be a string. we must use $actionclassinstance->resprints to return a string if (! is_array($result) && ! is_numeric($result)) { @@ -221,8 +224,8 @@ class HookManager } // TODO remove this. When there is something to print for an output hook, ->resPrint is filled. - if ($hooktype == 'output') return $this->resPrint; - if ($hooktype == 'returnvalue') return $result; + //if ($hooktype == 'output') return $this->resPrint; + //if ($hooktype == 'returnvalue') return $result; return ($error?-1:$resaction); } diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php index f94664531dd..1d4c144a098 100644 --- a/htdocs/fourn/card.php +++ b/htdocs/fourn/card.php @@ -31,6 +31,7 @@ require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; $langs->load('suppliers'); @@ -49,6 +50,7 @@ if ($user->societe_id) $id=$user->societe_id; $result = restrictedArea($user, 'societe&fournisseur', $id, '&societe'); $object = new Fournisseur($db); +$extrafields = new ExtraFields($db); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('suppliercard','globalcard')); diff --git a/htdocs/fourn/list.php b/htdocs/fourn/list.php index b0d7caf8695..4c16f3a1d61 100644 --- a/htdocs/fourn/list.php +++ b/htdocs/fourn/list.php @@ -27,6 +27,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $langs->load("suppliers"); $langs->load("orders"); @@ -59,6 +60,7 @@ if (! $sortfield) $sortfield="nom"; // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('supplierlist')); +$extrafields = new ExtraFields($db); if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers { @@ -73,6 +75,9 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both $catid=""; } +$extrafields->fetch_name_optionals_label('thirdparty'); + + /* * Actions */ @@ -95,7 +100,14 @@ llxHeader('',$langs->trans("ThirdParty"),$help_url); $sql = "SELECT s.rowid as socid, s.nom as name, s.zip, s.town, s.datec, st.libelle as stcomm, s.prefix_comm, s.status as status, "; $sql.= "code_fournisseur, code_compta_fournisseur"; if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user "; +// Add fields for extrafields +foreach ($extrafields->attribute_list as $key => $val) $sql.=",ef.".$key; +// Add fields from hooks +$parameters=array(); +$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook +$sql.=$hookmanager->resPrint; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; +$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_extrafields as ef ON ef.fk_object = s.rowid"; if (! empty($search_categ) || ! empty($catid)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_fournisseur as cf ON s.rowid = cf.fk_societe"; // We need this table joined to the select in order to filter by categ $sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st"; if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; @@ -122,6 +134,9 @@ if ($catid > 0) $sql.= " AND cf.fk_categorie = ".$catid; if ($catid == -2) $sql.= " AND cf.fk_categorie IS NULL"; if ($search_categ > 0) $sql.= " AND cf.fk_categorie = ".$search_categ; if ($search_categ == -2) $sql.= " AND cf.fk_categorie IS NULL"; +// Add where from hooks +$parameters=array(); +$sql.=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook // Count total nb of records $nbtotalofrecords = 0; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) @@ -131,6 +146,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) } $sql.= $db->order($sortfield,$sortorder); $sql.= $db->plimit($conf->liste_limit+1, $offset); +//print $sql; dol_syslog('fourn/list.php:', LOG_DEBUG); $resql = $db->query($sql); @@ -200,7 +216,7 @@ if ($resql) print ''; print ''; print "\n"; - + $parameters=array(); $formconfirm=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook diff --git a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql index 65273632998..73ace187708 100755 --- a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql +++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql @@ -366,3 +366,7 @@ INSERT INTO llx_c_incoterms (code, libelle, active) VALUES ('CIP', 'Carriage and INSERT INTO llx_c_incoterms (code, libelle, active) VALUES ('DAT', 'Delivered At Terminal, marchandises (déchargées) livrées sur quai, dans un terminal maritime, fluvial, aérien, routier ou ferroviaire désigné (dédouanement import, et post-acheminement payés par l''acheteur)', 1); INSERT INTO llx_c_incoterms (code, libelle, active) VALUES ('DAP', 'Delivered At Place, marchandises (non déchargées) mises à disposition de l''acheteur dans le pays d''importation au lieu précisé dans le contrat (déchargement, dédouanement import payé par l''acheteur)', 1); INSERT INTO llx_c_incoterms (code, libelle, active) VALUES ('DDP', 'Delivered Duty Paid, marchandises (non déchargées) livrées à destination finale, dédouanement import et taxes à la charge du vendeur ; l''acheteur prend en charge uniquement le déchargement (si exclusion des taxes type TVA, le préciser clairement)', 1); + +-- Extrafields fk_object must be unique (1-1 relation) +ALTER TABLE llx_societe_extrafields DROP INDEX idx_societe_extrafields +ALTER TABLE llx_societe_extrafields ADD UNIQUE INDEX uk_societe_extrafields (fk_object); diff --git a/htdocs/install/mysql/tables/llx_societe_extrafields.key.sql b/htdocs/install/mysql/tables/llx_societe_extrafields.key.sql index 44ce4dda753..9d89beebd37 100644 --- a/htdocs/install/mysql/tables/llx_societe_extrafields.key.sql +++ b/htdocs/install/mysql/tables/llx_societe_extrafields.key.sql @@ -17,4 +17,4 @@ -- =================================================================== -ALTER TABLE llx_societe_extrafields ADD INDEX idx_societe_extrafields (fk_object); +ALTER TABLE llx_societe_extrafields ADD UNIQUE INDEX uk_societe_extrafields (fk_object);