From 78fcbe9633806eee6d0705a9f655cecae0a79b39 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 13 Apr 2018 10:48:29 +0200 Subject: [PATCH 01/15] FIX the extrafields separator was not translated --- htdocs/core/class/commonobject.class.php | 2 +- htdocs/core/class/extrafields.class.php | 11 ++++++++--- htdocs/core/tpl/extrafields_view.tpl.php | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 8e92715cf76..c2f4dbef1d9 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -5996,7 +5996,7 @@ abstract class CommonObject if ($extrafields->attributes[$this->table_element]['type'][$key] == 'separate') { - $out .= $extrafields->showSeparator($key); + $out .= $extrafields->showSeparator($key, $this); } else { diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 09b73ab03c3..89c867a3adc 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -1743,11 +1743,16 @@ class ExtraFields * Return HTML string to print separator extrafield * * @param string $key Key of attribute - * @return string + * @param string $object Object + * @return string HTML code with line for separator */ - function showSeparator($key) + function showSeparator($key, $object) { - $out = ''.$this->attribute_label[$key].''; + global $langs; + + $out = ''; + $out.= $langs->trans($this->attributes[$object->table_element]['label'][$key]); + $out.= ''; return $out; } diff --git a/htdocs/core/tpl/extrafields_view.tpl.php b/htdocs/core/tpl/extrafields_view.tpl.php index 25e0183fef9..3b75905370f 100644 --- a/htdocs/core/tpl/extrafields_view.tpl.php +++ b/htdocs/core/tpl/extrafields_view.tpl.php @@ -80,7 +80,7 @@ if (empty($reshook) && ! empty($extrafields->attributes[$object->table_element][ } if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') { - print $extrafields->showSeparator($key); + print $extrafields->showSeparator($key, $object); } else { From 1521b0595b4c97275bbda7d5ea555f8df27f1c4e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 13 Apr 2018 11:03:03 +0200 Subject: [PATCH 02/15] Clean code --- htdocs/adherents/cartes/carte.php | 11 ++++++----- htdocs/adherents/type.php | 6 +++--- htdocs/assets/type.php | 6 +++--- htdocs/categories/card.php | 2 +- htdocs/categories/edit.php | 2 +- htdocs/comm/action/card.php | 4 ++-- htdocs/comm/mailing/card.php | 4 ++-- htdocs/commande/card.php | 2 +- htdocs/commande/orderstoinvoice.php | 2 +- htdocs/compta/bank/card.php | 4 ++-- htdocs/compta/facture/card.php | 2 +- htdocs/contact/card.php | 4 ++-- htdocs/contrat/card.php | 2 +- htdocs/don/card.php | 4 ++-- htdocs/expedition/card.php | 2 +- htdocs/expensereport/card.php | 2 +- htdocs/fichinter/card.php | 2 +- htdocs/fourn/commande/card.php | 2 +- htdocs/fourn/commande/orderstoinvoice.php | 2 +- htdocs/fourn/facture/card.php | 2 +- htdocs/product/card.php | 4 ++-- htdocs/projet/card.php | 4 ++-- htdocs/projet/tasks/task.php | 2 +- htdocs/resource/card.php | 2 +- htdocs/societe/card.php | 4 ++-- htdocs/supplier_proposal/card.php | 2 +- htdocs/user/card.php | 4 ++-- htdocs/user/group/card.php | 4 ++-- 28 files changed, 47 insertions(+), 46 deletions(-) diff --git a/htdocs/adherents/cartes/carte.php b/htdocs/adherents/cartes/carte.php index 59713e20573..2c1db41ed00 100644 --- a/htdocs/adherents/cartes/carte.php +++ b/htdocs/adherents/cartes/carte.php @@ -45,6 +45,7 @@ $modellabel=GETPOST("modellabel"); // Doc template to use for address sheet $mesg=''; $adherentstatic=new Adherent($db); +$object=new Adherent($db); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels @@ -70,11 +71,11 @@ if ((! empty($foruserid) || ! empty($foruserlogin) || ! empty($mode)) && ! $mesg $sql.= " t.libelle as type,"; $sql.= " c.code as country_code, c.label as country"; // Add fields from extrafields - foreach ($extrafields->attribute_label as $key => $val) - $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : ''); + if (! empty($extrafields->attributes[$object->table_element]['label'])) + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.country = c.rowid"; - if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."adherent_extrafields as ef on (d.rowid = ef.fk_object)"; + if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."adherent_extrafields as ef on (d.rowid = ef.fk_object)"; $sql.= " WHERE d.fk_adherent_type = t.rowid AND d.statut = 1"; $sql.= " AND d.entity IN (".getEntity('adherent').")"; if (is_numeric($foruserid)) $sql.=" AND d.rowid=".$foruserid; @@ -98,10 +99,10 @@ if ((! empty($foruserid) || ! empty($foruserlogin) || ! empty($mode)) && ! $mesg $adherentstatic->firstname=$objp->firstname; // format extrafiled so they can be parsed in function complete_substitutions_array - if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) + if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { $adherentstatic->array_options = array(); - foreach($extrafields->attribute_label as $key => $val) + foreach($extrafields->attributes[$object->table_element]['label'] as $key => $val) { $tmpkey='options_'.$key; if (!empty($objp->$tmpkey)) diff --git a/htdocs/adherents/type.php b/htdocs/adherents/type.php index 929dc706042..c695d0cc699 100644 --- a/htdocs/adherents/type.php +++ b/htdocs/adherents/type.php @@ -338,7 +338,7 @@ if ($action == 'create') $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } @@ -736,7 +736,7 @@ if ($rowid > 0) $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } @@ -744,7 +744,7 @@ if ($rowid > 0) print ''; // Extra field - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print '

'; foreach($extrafields->attribute_label as $key=>$label) diff --git a/htdocs/assets/type.php b/htdocs/assets/type.php index 51445f86254..15d93f598f8 100644 --- a/htdocs/assets/type.php +++ b/htdocs/assets/type.php @@ -317,7 +317,7 @@ if ($action == 'create') $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } @@ -715,7 +715,7 @@ if ($rowid > 0) $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } @@ -723,7 +723,7 @@ if ($rowid > 0) print '
'; // Extra field - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print '

'; foreach($extrafields->attribute_label as $key=>$label) diff --git a/htdocs/categories/card.php b/htdocs/categories/card.php index 9f49e42f060..9911ad01b0b 100644 --- a/htdocs/categories/card.php +++ b/htdocs/categories/card.php @@ -268,7 +268,7 @@ if ($user->rights->categorie->creer) $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php index 4ccd9116d74..ed6783ea59e 100644 --- a/htdocs/categories/edit.php +++ b/htdocs/categories/edit.php @@ -176,7 +176,7 @@ print ''; $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; -if (empty($reshook) && ! empty($extrafields->attribute_label)) +if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index d0d97f83435..c42bf4b8c70 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -908,7 +908,7 @@ if ($action == 'create') $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } @@ -1260,7 +1260,7 @@ if ($id > 0) $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index a8bbb05fb84..ddce7036c58 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -754,7 +754,7 @@ if ($action == 'create') $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } @@ -1235,7 +1235,7 @@ else $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index b3757021ee8..e0f29d5f7ee 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -1646,7 +1646,7 @@ if ($action == 'create' && $user->rights->commande->creer) $parameters = array('objectsrc' => $objectsrc, 'socid'=>$socid); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) { + if (empty($reshook) { print $object->showOptionals($extrafields, 'edit'); } diff --git a/htdocs/commande/orderstoinvoice.php b/htdocs/commande/orderstoinvoice.php index bebcaa93097..63c590af3be 100644 --- a/htdocs/commande/orderstoinvoice.php +++ b/htdocs/commande/orderstoinvoice.php @@ -472,7 +472,7 @@ if ($action == 'create' && !$error) $parameters=array('objectsrc' => $objectsrc, 'idsrc' => $listoforders); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { $object=new Facture($db); print $object->showOptionals($extrafields,'edit'); diff --git a/htdocs/compta/bank/card.php b/htdocs/compta/bank/card.php index 78c5defed30..ee7adeb57d7 100644 --- a/htdocs/compta/bank/card.php +++ b/htdocs/compta/bank/card.php @@ -413,7 +413,7 @@ if ($action == 'create') $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit',$parameters); } @@ -914,7 +914,7 @@ else $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 044ca7da392..d21d6a637ad 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -2857,7 +2857,7 @@ if ($action == 'create') $parameters = array('objectsrc' => $objectsrc,'colspan' => ' colspan="2"', 'cols'=>2); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) { + if (empty($reshook) { print $object->showOptionals($extrafields, 'edit'); } diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index 560acabaee9..bf05d802438 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -686,7 +686,7 @@ else $parameters=array('socid' => $socid, 'objsoc' => $objsoc, 'colspan' => ' colspan="3"', 'cols' => 3); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } @@ -963,7 +963,7 @@ else $parameters=array('colspan' => ' colspan="3"', 'cols'=>3); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 41cf0c12f3e..3ea527c80b9 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -1287,7 +1287,7 @@ if ($action == 'create') print $hookmanager->resPrint; // Other attributes - if (empty($reshook) && ! empty($extrafields->attribute_label)) { + if (empty($reshook) { print $object->showOptionals($extrafields, 'edit'); } diff --git a/htdocs/don/card.php b/htdocs/don/card.php index 78b8d01e51d..d15fe10ec0b 100644 --- a/htdocs/don/card.php +++ b/htdocs/don/card.php @@ -387,7 +387,7 @@ if ($action == 'create') $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit',$parameters); } @@ -513,7 +513,7 @@ if (! empty($id) && $action == 'edit') $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 89f1aee7b4b..338b07edca4 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -1059,7 +1059,7 @@ if ($action == 'create') $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$expe,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) { + if (empty($reshook) { // copy from order $orderExtrafields = new Extrafields($db); $orderExtrafieldLabels = $orderExtrafields->fetch_name_optionals_label($object->table_element); diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 33bf5245e62..0474cde1128 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -1412,7 +1412,7 @@ if ($action == 'create') $parameters = array('colspan' => ' colspan="3"'); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) { + if (empty($reshook) { print $object->showOptionals($extrafields, 'edit'); } diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index 01e7e1d7160..67d6a55c8bc 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -1002,7 +1002,7 @@ if ($action == 'create') $parameters=array('colspan' => ' colspan="2"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 226ae56125a..ef13353ed64 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -1609,7 +1609,7 @@ if ($action=='create') $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/fourn/commande/orderstoinvoice.php b/htdocs/fourn/commande/orderstoinvoice.php index dbed55a75f5..330a404790c 100644 --- a/htdocs/fourn/commande/orderstoinvoice.php +++ b/htdocs/fourn/commande/orderstoinvoice.php @@ -371,7 +371,7 @@ if ($action == 'create' && !$error) { $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { $object=new FactureFournisseur($db); print $object->showOptionals($extrafields,'edit'); diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 1029cad1b03..d79005ea9a2 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -1998,7 +1998,7 @@ if ($action == 'create') // print ''; print ''; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields, 'edit'); } diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 1b68baf253a..99cf8654006 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1097,7 +1097,7 @@ else $parameters=array('cols' => 3); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit',$parameters); } @@ -1470,7 +1470,7 @@ else $parameters=array('colspan' => ' colspan="3"', 'cols'=>3); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php index 00266b74e9c..96bb5b99795 100644 --- a/htdocs/projet/card.php +++ b/htdocs/projet/card.php @@ -629,7 +629,7 @@ if ($action == 'create' && $user->rights->projet->creer) $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } @@ -869,7 +869,7 @@ elseif ($object->id > 0) $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php index ac711015765..fa837607f41 100644 --- a/htdocs/projet/tasks/task.php +++ b/htdocs/projet/tasks/task.php @@ -416,7 +416,7 @@ if ($id > 0 || ! empty($ref)) $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index 6e3d1896a71..f8ff77c035e 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -285,7 +285,7 @@ if ($action == 'create' || $object->fetch($id) > 0) $parameters=array('objectsrc' => $objectsrc); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index bc16a30d7da..66795cfd8e7 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -1431,7 +1431,7 @@ else $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } @@ -2018,7 +2018,7 @@ else $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php index ade114f11b3..fd74932d57e 100644 --- a/htdocs/supplier_proposal/card.php +++ b/htdocs/supplier_proposal/card.php @@ -1151,7 +1151,7 @@ if ($action == 'create') $parameters = array('colspan' => ' colspan="3"'); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) { + if (empty($reshook) { print $object->showOptionals($extrafields, 'edit'); } diff --git a/htdocs/user/card.php b/htdocs/user/card.php index f9a69d37baa..4fd1c105055 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -1070,7 +1070,7 @@ if ($action == 'create' || $action == 'adduserldap') $parameters=array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } @@ -2322,7 +2322,7 @@ else $parameters=array('colspan' => ' colspan="2"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/user/group/card.php b/htdocs/user/group/card.php index 3f350b7773e..c3adb2f2f20 100644 --- a/htdocs/user/group/card.php +++ b/htdocs/user/group/card.php @@ -304,7 +304,7 @@ if ($action == 'create') $parameters=array('object' => $object, 'colspan' => ' colspan="2"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } @@ -570,7 +570,7 @@ else $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) + if (empty($reshook) { print $object->showOptionals($extrafields,'edit'); } From fbae4429b7f4478b45e701b4ef123351994ed9b9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 13 Apr 2018 12:52:23 +0200 Subject: [PATCH 03/15] Clean code for better extrafields management --- htdocs/core/actions_addupdatedelete.inc.php | 2 +- htdocs/core/class/commonobject.class.php | 4 +- htdocs/core/class/extrafields.class.php | 2 - htdocs/core/class/html.formmail.class.php | 4 +- htdocs/core/lib/functions.lib.php | 2 +- .../core/tpl/admin_extrafields_edit.tpl.php | 3 +- .../tpl/extrafields_list_print_fields.tpl.php | 37 +- .../tpl/extrafields_list_search_input.tpl.php | 10 +- .../tpl/extrafields_list_search_sql.tpl.php | 26 +- htdocs/install/repair.php | 2 +- .../modulebuilder/template/myobject_list.php | 9 +- .../class/price_parser.class.php | 2 +- htdocs/public/members/public_card.php | 2 +- htdocs/ticketsup/card.php | 24 +- htdocs/ticketsup/class/ticketsup.class.php | 10 +- htdocs/ticketsup/list.php | 394 +++++++++--------- 16 files changed, 259 insertions(+), 274 deletions(-) diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index 3e045140cb5..ff723866b74 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -153,7 +153,7 @@ if ($action == "update_extras" && ! empty($permissiontoadd)) $attributekeylong = 'options_'.$attributekey; $object->array_options['options_'.$attributekey] = GETPOST($attributekeylong,' alpha'); - $result = $object->updateExtraField($attributekey, empty($triggermodname)?'':$triggermodname, $user); + $result = $object->insertExtraFields(empty($triggermodname)?'':$triggermodname, $user); if ($result > 0) { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index c2f4dbef1d9..e5f4fe140b5 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4903,7 +4903,7 @@ abstract class CommonObject } /** - * Update an exta field value for the current object. + * Update an extra field value for the current object. * Data to describe values to update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...) * * @param string $key Key of the extrafield (without starting 'options_') @@ -5054,7 +5054,6 @@ abstract class CommonObject if (is_array($val['arrayofkeyval'])) $type='select'; if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link'; - //$elementtype=$this->attribute_elementtype[$key]; // seems to not be used $default=$val['default']; $computed=$val['computed']; $unique=$val['unique']; @@ -5597,7 +5596,6 @@ abstract class CommonObject if (is_array($val['arrayofkeyval'])) $type='select'; if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link'; - //$elementtype=$this->attribute_elementtype[$key]; // seems to not be used $default=$val['default']; $computed=$val['computed']; $unique=$val['unique']; diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 89c867a3adc..c6dab1241f8 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -1384,7 +1384,6 @@ class ExtraFields if (! empty($extrafieldsobjectkey)) { - $elementtype=$this->attributes[$extrafieldsobjectkey]['elementtype'][$key]; // seems not used $label=$this->attributes[$extrafieldsobjectkey]['label'][$key]; $type=$this->attributes[$extrafieldsobjectkey]['type'][$key]; $size=$this->attributes[$extrafieldsobjectkey]['size'][$key]; @@ -1400,7 +1399,6 @@ class ExtraFields } else // Old usage { - $elementtype=$this->attribute_elementtype[$key]; // seems not used $label=$this->attribute_label[$key]; $type=$this->attribute_type[$key]; $size=$this->attribute_size[$key]; diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index c5d66bc6791..0dd843813e8 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -1261,12 +1261,12 @@ class FormMail extends Form // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__ if (!empty($line->fk_product)) { - $extrafields = new ExtraFields($this->db); + if (! is_object($extrafields)) $extrafields = new ExtraFields($this->db); $extralabels = $extrafields->fetch_name_optionals_label('product', true); $product = new Product($this->db); $product->fetch($line->fk_product, '', '', 1); $product->fetch_optionals(); - foreach ($extrafields->attribute_label as $key => $label) { + foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) { $substit_line['__PRODUCT_EXTRAFIELD_' . strtoupper($key) . '__'] = $product->array_options['options_' . $key]; } } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 1037422957e..af8ae019a9c 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5967,7 +5967,7 @@ function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $ob $extrafieldstmp = new ExtraFields($db); $extralabels = $extrafieldstmp->fetch_name_optionals_label($object->table_element, true); $object->fetch_optionals(); - foreach ($extrafieldstmp->attribute_label as $key => $label) { + foreach ($extrafieldstmp->attributes[$object->table_element]['label'] as $key => $label) { $substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '__'] = $object->array_options['options_' . $key]; } } diff --git a/htdocs/core/tpl/admin_extrafields_edit.tpl.php b/htdocs/core/tpl/admin_extrafields_edit.tpl.php index 5ecf859f603..3c3cc1858c5 100644 --- a/htdocs/core/tpl/admin_extrafields_edit.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_edit.tpl.php @@ -143,6 +143,7 @@ $langs->load("modulebuilder");
attributes[$elementtype]['label'][$attrname]; $type=$extrafields->attributes[$elementtype]['type'][$attrname]; $size=$extrafields->attributes[$elementtype]['size'][$attrname]; $computed=$extrafields->attributes[$elementtype]['computed'][$attrname]; @@ -175,7 +176,7 @@ elseif (($type== 'sellist') || ($type == 'chkbxlst') || ($type == 'link') || ($t } ?> - + diff --git a/htdocs/core/tpl/extrafields_list_print_fields.tpl.php b/htdocs/core/tpl/extrafields_list_print_fields.tpl.php index 58915b7a786..2576873a2c5 100644 --- a/htdocs/core/tpl/extrafields_list_print_fields.tpl.php +++ b/htdocs/core/tpl/extrafields_list_print_fields.tpl.php @@ -7,8 +7,10 @@ if (empty($conf) || ! is_object($conf)) exit; } +if (empty($extrafieldsobjectkey) && is_object($object)) $extrafieldsobjectkey=$object->table_element; + // Loop to show all columns of extrafields from $obj, $extrafields and $db -if (! empty($extrafieldsobjectkey)) // New method: $extrafieldsobject can be 'societe', 'socpeople', ... +if (! empty($extrafieldsobjectkey)) // $extrafieldsobject is the $object->table_element like 'societe', 'socpeople', ... { if (is_array($extrafields->attributes[$extrafieldsobjectkey]['label']) && count($extrafields->attributes[$extrafieldsobjectkey]['label'])) { @@ -42,36 +44,3 @@ if (! empty($extrafieldsobjectkey)) // New method: $extrafieldsobject can be 'so } } } -else // Old method -{ - if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) - { - foreach($extrafields->attribute_label as $key => $val) - { - if (! empty($arrayfields["ef.".$key]['checked'])) - { - $align=$extrafields->getAlignFlag($key); - print ''; - $tmpkey='options_'.$key; - if (in_array($extrafields->attribute_type[$key], array('date', 'datetime', 'timestamp'))) - { - $value = $db->jdate($obj->$tmpkey); - } - else - { - $value = $obj->$tmpkey; - } - print $extrafields->showOutputField($key, $value, ''); - print ''; - if (! $i) $totalarray['nbfield']++; - if (! empty($val['isameasure'])) - { - if (! $i) $totalarray['pos'][$totalarray['nbfield']]='ef.'.$tmpkey; - $totalarray['val']['ef.'.$tmpkey] += $obj->$tmpkey; - } - } - } - } -} \ No newline at end of file diff --git a/htdocs/core/tpl/extrafields_list_search_input.tpl.php b/htdocs/core/tpl/extrafields_list_search_input.tpl.php index 42770fc91f5..2bef2ea42ab 100644 --- a/htdocs/core/tpl/extrafields_list_search_input.tpl.php +++ b/htdocs/core/tpl/extrafields_list_search_input.tpl.php @@ -7,16 +7,18 @@ if (empty($conf) || ! is_object($conf)) exit; } +if (empty($extrafieldsobjectkey) && is_object($object)) $extrafieldsobjectkey=$object->table_element; + // Loop to show all columns of extrafields for the search title line -if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) +if (is_array($extrafields->attributes[$extrafieldsobjectkey]['label']) && count($extrafields->attributes[$extrafieldsobjectkey]['label'])) { - foreach($extrafields->attribute_label as $key => $val) + foreach($extrafields->attributes[$extrafieldsobjectkey]['label'] as $key => $val) { if (! empty($arrayfields["ef.".$key]['checked'])) { $align=$extrafields->getAlignFlag($key); - $typeofextrafield=$extrafields->attribute_type[$key]; + $typeofextrafield=$extrafields->attributes[$extrafieldsobjectkey]['type'][$key]; print ''."\n"; } - // foreach($objecto->attribute_label as $key=>$value){ + // foreach($extrafields->attributes[$object->table_element]['label'] as $key=>$value){ // print "\n"; // } diff --git a/htdocs/ticketsup/card.php b/htdocs/ticketsup/card.php index ddfa6d183c6..6d33a5cd9be 100644 --- a/htdocs/ticketsup/card.php +++ b/htdocs/ticketsup/card.php @@ -1,6 +1,7 @@ * Copyright (C) 2016 Christophe Battarel + * Copyright (C) 2018 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -76,25 +77,38 @@ if ($id || $track_id || $ref) { // Security check $result = restrictedArea($user, 'ticketsup', $object->id); +$triggermodname = 'TICKETSUP_MODIFY'; +$permissiontoadd = $user->rights->ticketsup->write; + /* * Actions */ +if ($cancel) +{ + if (! empty($backtopage)) + { + header("Location: ".$backtopage); + exit; + } + $action=''; +} + + $actionobject = new ActionsTicketsup($db); $actionobject->doActions($action, $object); -if ($action == "update_extras" && $user->rights->ticketsup->write && !GETPOST('cancel','alpha')) +// Action to update one extrafield +if ($action == "update_extras" && ! empty($permissiontoadd)) { - $triggermodname = 'TICKETSUP_MODIFY'; - - $res = $object->fetch(GETPOST('id','int'), '', GETPOST('track_id','alpha')); + $object->fetch(GETPOST('id','int'), '', GETPOST('track_id','alpha')); $attributekey = GETPOST('attribute','alpha'); $attributekeylong = 'options_'.$attributekey; $object->array_options['options_'.$attributekey] = GETPOST($attributekeylong,' alpha'); - $result = $object->updateExtraField($attributekey, $triggermodname, $user); + $result = $object->insertExtraFields(empty($triggermodname)?'':$triggermodname, $user); if ($result > 0) { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); diff --git a/htdocs/ticketsup/class/ticketsup.class.php b/htdocs/ticketsup/class/ticketsup.class.php index fc0dc679344..5a4f71e81e3 100644 --- a/htdocs/ticketsup/class/ticketsup.class.php +++ b/htdocs/ticketsup/class/ticketsup.class.php @@ -586,8 +586,8 @@ class Ticketsup extends CommonObject $sql .= " t.tms"; $sql .= ", type.label as type_label, category.label as category_label, severity.label as severity_label"; // Add fields for extrafields - foreach ($extrafields->attribute_list as $key => $val) { - $sql .= ($extrafields->attribute_type[$key] != 'separate' ? ",ef." . $key . ' as options_' . $key : ''); + foreach ($extrafields->attributes[$this->table_element]['label'] as $key => $val) { + $sql .= ($extrafields->attributes[$this->table_element]['type'][$key] != 'separate' ? ",ef." . $key . ' as options_' . $key : ''); } $sql .= " FROM " . MAIN_DB_PREFIX . "ticketsup as t"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_ticketsup_type as type ON type.code=t.type_code"; @@ -596,7 +596,7 @@ class Ticketsup extends CommonObject $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid=t.fk_soc"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user as uc ON uc.rowid=t.fk_user_create"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user as ua ON ua.rowid=t.fk_user_assign"; - if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { + if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label'])) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "ticketsup_extrafields as ef on (t.rowid = ef.fk_object)"; } if (!$user->rights->societe->client->voir && !$user->socid) { @@ -690,8 +690,8 @@ class Ticketsup extends CommonObject $line->date_close = $this->db->jdate($obj->date_close); // Extra fields - if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { - foreach ($extrafields->attribute_label as $key => $val) { + if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label'])) { + foreach ($extrafields->attributes[$this->table_element]['label'] as $key => $val) { $tmpkey = 'options_' . $key; $line->{$tmpkey} = $obj->$tmpkey; } diff --git a/htdocs/ticketsup/list.php b/htdocs/ticketsup/list.php index 9a2ef7c31e1..4f7cd955852 100644 --- a/htdocs/ticketsup/list.php +++ b/htdocs/ticketsup/list.php @@ -86,7 +86,7 @@ $search_all=trim(GETPOST("search_all",'alpha')); $search=array(); foreach($object->fields as $key => $val) { - if (GETPOST('search_'.$key,'alpha')) $search[$key]=GETPOST('search_'.$key,'alpha'); + if (GETPOST('search_'.$key,'alpha')) $search[$key]=GETPOST('search_'.$key,'alpha'); } @@ -94,23 +94,24 @@ foreach($object->fields as $key => $val) $fieldstosearchall = array(); foreach($object->fields as $key => $val) { - if ($val['searchall']) $fieldstosearchall['t.'.$key]=$val['label']; + if ($val['searchall']) $fieldstosearchall['t.'.$key]=$val['label']; } // Definition of fields for list $arrayfields=array(); foreach($object->fields as $key => $val) { - // If $val['visible']==0, then we never show the field - if (! empty($val['visible'])) $arrayfields['t.'.$key]=array('label'=>$val['label'], 'checked'=>(($val['visible']<0)?0:1), 'enabled'=>$val['enabled'], 'position'=>$val['position']); + // If $val['visible']==0, then we never show the field + if (! empty($val['visible'])) $arrayfields['t.'.$key]=array('label'=>$val['label'], 'checked'=>(($val['visible']<0)?0:1), 'enabled'=>$val['enabled'], 'position'=>$val['position']); } // Extra fields -if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { - foreach($extrafields->attribute_label as $key => $val) - { - if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key])); - } + foreach($extrafields->attributes[$object->table_element]['label'] as $key => $val) + { + if (! empty($extrafields->attributes[$object->table_element]['list'][$key])) + $arrayfields["ef.".$key]=array('label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key]<0)?0:1), 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key])!=3 && $extrafields->attributes[$object->table_element]['perms'][$key])); + } } $object->fields = dol_sort_array($object->fields, 'position'); $arrayfields = dol_sort_array($arrayfields, 'position'); @@ -141,32 +142,32 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e if (empty($reshook)) { - // Selection of new fields - include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; + // Selection of new fields + include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; - // Purge search criteria - if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers - { - foreach($object->fields as $key => $val) - { - $search[$key]=''; - } - $toselect=''; - $search_array_options=array(); - } - if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha') - || GETPOST('button_search_x','alpha') || GETPOST('button_search.x','alpha') || GETPOST('button_search','alpha')) - { - $massaction=''; // Protection to avoid mass action if we force a new search during a mass action confirmation - } - - // Mass actions - $objectclass='Ticketsup'; - $objectlabel='Ticketsup'; - $permtoread = $user->rights->ticketsup->read; - $permtodelete = $user->rights->ticketsup->delete; - $uploaddir = $conf->ticketsup->dir_output; - include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; + // Purge search criteria + if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers + { + foreach($object->fields as $key => $val) + { + $search[$key]=''; + } + $toselect=''; + $search_array_options=array(); + } + if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha') + || GETPOST('button_search_x','alpha') || GETPOST('button_search.x','alpha') || GETPOST('button_search','alpha')) + { + $massaction=''; // Protection to avoid mass action if we force a new search during a mass action confirmation + } + + // Mass actions + $objectclass='Ticketsup'; + $objectlabel='Ticketsup'; + $permtoread = $user->rights->ticketsup->read; + $permtodelete = $user->rights->ticketsup->delete; + $uploaddir = $conf->ticketsup->dir_output; + include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } @@ -191,7 +192,7 @@ $socstatic = new Societe($db); $sql = 'SELECT '; foreach($object->fields as $key => $val) { - $sql.='t.'.$key.', '; + $sql.='t.'.$key.', '; } // Add fields from extrafields if (! empty($extrafields->attributes[$object->table_element]['label'])) @@ -202,7 +203,7 @@ $reshook=$hookmanager->executeHooks('printFieldListSelect', $parameters, $object $sql.=$hookmanager->resPrint; $sql=preg_replace('/, $/','', $sql); $sql.= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t"; -if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."ticketsup_extrafields as ef on (t.rowid = ef.fk_object)"; +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."ticketsup_extrafields as ef on (t.rowid = ef.fk_object)"; if ($object->ismultientitymanaged == 1) $sql.= " WHERE t.entity IN (".getEntity('ticketsup').")"; else $sql.=" WHERE 1 = 1"; foreach($search as $key => $val) @@ -231,18 +232,19 @@ $reshook=$hookmanager->executeHooks('printFieldListWhere', $parameters, $object) $sql.=$hookmanager->resPrint; /* If a group by is required - $sql.= " GROUP BY " - foreach($object->fields as $key => $val) - { - $sql.='t.'.$key.', '; - } - // Add fields from extrafields - foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key : ''); - // Add where from hooks - $parameters=array(); - $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook - $sql.=$hookmanager->resPrint; - */ +$sql.= " GROUP BY " +foreach($object->fields as $key => $val) +{ + $sql.='t.'.$key.', '; +} +// Add fields from extrafields +if (! empty($extrafields->attributes[$object->table_element]['label'])) { + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : ''); +// Add where from hooks +$parameters=array(); +$reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook +$sql.=$hookmanager->resPrint; +*/ $sql.=$db->order($sortfield,$sortorder); @@ -250,42 +252,42 @@ $sql.=$db->order($sortfield,$sortorder); $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { - $result = $db->query($sql); - $nbtotalofrecords = $db->num_rows($result); + $result = $db->query($sql); + $nbtotalofrecords = $db->num_rows($result); } // if total resultset is smaller then paging size (filtering), goto and load page 0 if (($page * $limit) > $nbtotalofrecords) { - $page = 0; - $offset = 0; + $page = 0; + $offset = 0; } // if total resultset is smaller the limit, no need to do paging. if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) { - $resql = $result; - $num = $nbtotalofrecords; + $resql = $result; + $num = $nbtotalofrecords; } else { - $sql.= $db->plimit($limit+1, $offset); + $sql.= $db->plimit($limit+1, $offset); - $resql=$db->query($sql); - if (! $resql) - { - dol_print_error($db); - exit; - } + $resql=$db->query($sql); + if (! $resql) + { + dol_print_error($db); + exit; + } - $num = $db->num_rows($resql); + $num = $db->num_rows($resql); } // Direct jump if only one record found if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all) { - $obj = $db->fetch_object($resql); - $id = $obj->rowid; - header("Location: ".DOL_URL_ROOT.'/ticketsup/card.php?id='.$id); - exit; + $obj = $db->fetch_object($resql); + $id = $obj->rowid; + header("Location: ".DOL_URL_ROOT.'/ticketsup/card.php?id='.$id); + exit; } @@ -404,7 +406,7 @@ if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&con if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit); foreach($search as $key => $val) { - $param.= '&search_'.$key.'='.urlencode($search[$key]); + $param.= '&search_'.$key.'='.urlencode($search[$key]); } if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss); // Add $param from extra fields @@ -414,8 +416,8 @@ if ($projectid) $param.='&projectid='.urlencode($projectid); // List of mass actions available $arrayofmassactions = array( - //'presend'=>$langs->trans("SendByMail"), - //'builddoc'=>$langs->trans("PDFMerge"), + //'presend'=>$langs->trans("SendByMail"), + //'builddoc'=>$langs->trans("PDFMerge"), ); if ($user->rights->ticketsup->delete) $arrayofmassactions['predelete']=$langs->trans("Delete"); if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array(); @@ -451,8 +453,8 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; if ($sall) { - foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); - print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall); + foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); + print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall); } if ($search_fk_status == 'non_closed') { @@ -467,8 +469,8 @@ if ($search_fk_status == 'non_closed') { $moreforfilter = ''; /*$moreforfilter.='
'; - $moreforfilter.= $langs->trans('MyFilter') . ': '; - $moreforfilter.= '
';*/ +$moreforfilter.= $langs->trans('MyFilter') . ': '; +$moreforfilter.= '';*/ $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook @@ -477,9 +479,9 @@ else $moreforfilter = $hookmanager->resPrint; if (! empty($moreforfilter)) { - print '
'; - print $moreforfilter; - print '
'; + print '
'; + print $moreforfilter; + print '
'; } $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; @@ -496,32 +498,32 @@ print '
'; foreach($object->fields as $key => $val) { - $align=''; - if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center'; - if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap'; - if ($key == 'status') $align.=($align?' ':'').'center'; - if (! empty($arrayfields['t.'.$key]['checked'])) { - if ($key == 'type_code') { - print ''; - } elseif ($key == 'category_code') { - print ''; - } elseif ($key == 'severity_code') { - print ''; - } elseif ($key == 'fk_statut') { - print ''; - } - else { - print ''; - } - } + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center'; + if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap'; + if ($key == 'status') $align.=($align?' ':'').'center'; + if (! empty($arrayfields['t.'.$key]['checked'])) { + if ($key == 'type_code') { + print ''; + } elseif ($key == 'category_code') { + print ''; + } elseif ($key == 'severity_code') { + print ''; + } elseif ($key == 'fk_statut') { + print ''; + } + else { + print ''; + } + } } // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; @@ -535,7 +537,6 @@ print ''; - print ''."\n"; @@ -544,11 +545,11 @@ print ''."\n"; print ''; foreach($object->fields as $key => $val) { - $align=''; - if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center'; - if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap'; - if ($key == 'status') $align.=($align?' ':'').'center'; - if (! empty($arrayfields['t.'.$key]['checked'])) print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n"; + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center'; + if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap'; + if ($key == 'status') $align.=($align?' ':'').'center'; + if (! empty($arrayfields['t.'.$key]['checked'])) print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n"; } // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; @@ -562,102 +563,101 @@ print ''."\n"; // Detect if we need a fetch on each output line $needToFetchEachLine=0; -foreach ($extrafields->attribute_computed as $key => $val) +foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) { - if (preg_match('/\$object/',$val)) $needToFetchEachLine++; // There is at least one compute field that use $object + if (preg_match('/\$object/',$val)) $needToFetchEachLine++; // There is at least one compute field that use $object } - // Loop on record // -------------------------------------------------------------------- $i=0; $totalarray=array(); while ($i < min($num, $limit)) { - $obj = $db->fetch_object($resql); - if (empty($obj)) break; // Should not happen + $obj = $db->fetch_object($resql); + if (empty($obj)) break; // Should not happen - // Store properties in $object - $object->id = $obj->rowid; - foreach($object->fields as $key => $val) - { - if (isset($obj->$key)) $object->$key = $obj->$key; - } + // Store properties in $object + $object->id = $obj->rowid; + foreach($object->fields as $key => $val) + { + if (isset($obj->$key)) $object->$key = $obj->$key; + } - // Show here line of result - print ''; - foreach($object->fields as $key => $val) - { - $align=''; - if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center'; - if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap'; - if ($key == 'status') $align.=($align?' ':'').'center'; - if (! empty($arrayfields['t.'.$key]['checked'])) - { - print ''; - print $object->showOutputField($val, $key, $obj->$key, ''); - print ''; - if (! $i) $totalarray['nbfield']++; - if (! empty($val['isameasure'])) - { - if (! $i) $totalarray['pos'][$totalarray['nbfield']]='t.'.$key; - $totalarray['val']['t.'.$key] += $obj->$key; - } - } - } - // Extra fields - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; - // Fields from hook - $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj); - $reshook=$hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - // Action column - print ''; - if (! $i) $totalarray['nbfield']++; + // Show here line of result + print ''; + foreach($object->fields as $key => $val) + { + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center'; + if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap'; + if ($key == 'status') $align.=($align?' ':'').'center'; + if (! empty($arrayfields['t.'.$key]['checked'])) + { + print ''; + print $object->showOutputField($val, $key, $obj->$key, ''); + print ''; + if (! $i) $totalarray['nbfield']++; + if (! empty($val['isameasure'])) + { + if (! $i) $totalarray['pos'][$totalarray['nbfield']]='t.'.$key; + $totalarray['val']['t.'.$key] += $obj->$key; + } + } + } + // Extra fields + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; + // Fields from hook + $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj); + $reshook=$hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + // Action column + print ''; + if (! $i) $totalarray['nbfield']++; - print ''; + print ''; - $i++; + $i++; } // Show total line if (isset($totalarray['pos'])) { - print ''; - $i=0; - while ($i < $totalarray['nbfield']) - { - $i++; - if (! empty($totalarray['pos'][$i])) print ''; - else - { - if ($i == 1) - { - if ($num < $limit) print ''; - else print ''; - } - else print ''; - } - } - print ''; + print ''; + $i=0; + while ($i < $totalarray['nbfield']) + { + $i++; + if (! empty($totalarray['pos'][$i])) print ''; + else + { + if ($i == 1) + { + if ($num < $limit) print ''; + else print ''; + } + else print ''; + } + } + print ''; } // If no record found if ($num == 0) { - $colspan=1; - foreach($arrayfields as $key => $val) { if (! empty($val['checked'])) $colspan++; } - print ''; + $colspan=1; + foreach($arrayfields as $key => $val) { if (! empty($val['checked'])) $colspan++; } + print ''; } @@ -672,27 +672,25 @@ print ''."\n"; print ''."\n"; - - if (in_array('builddoc',$arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) { - $hidegeneratedfilelistifempty=1; - if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty=0; - - require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'); - $formfile = new FormFile($db); - - // Show list of available documents - $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; - $urlsource.=str_replace('&','&',$param); - - $filedir=$diroutputmassaction; - $genallowed=$user->rights->ticketsup->read; - $delallowed=$user->rights->ticketsup->write; - - print $formfile->showdocuments('massfilesarea_ticketsup','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'','','',null,$hidegeneratedfilelistifempty); + $hidegeneratedfilelistifempty=1; + if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty=0; + + require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'); + $formfile = new FormFile($db); + + // Show list of available documents + $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; + $urlsource.=str_replace('&','&',$param); + + $filedir=$diroutputmassaction; + $genallowed=$user->rights->ticketsup->read; + $delallowed=$user->rights->ticketsup->write; + + print $formfile->showdocuments('massfilesarea_ticketsup','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'','','',null,$hidegeneratedfilelistifempty); } // End of page -llxFooter(''); +llxFooter(); $db->close(); From b68cded9c497d6146b072185b1840aa9a3c90b9d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 13 Apr 2018 13:11:07 +0200 Subject: [PATCH 04/15] Clean code --- .../core/class/html.formticketsup.class.php | 2 +- htdocs/public/ticketsup/list.php | 31 +++++++++---------- htdocs/theme/eldy/style.css.php | 3 -- htdocs/theme/md/style.css.php | 3 -- htdocs/ticketsup/css/styles.css.php | 14 +++++++++ 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/htdocs/core/class/html.formticketsup.class.php b/htdocs/core/class/html.formticketsup.class.php index 545a6e210b4..1a8897c0a7d 100644 --- a/htdocs/core/class/html.formticketsup.class.php +++ b/htdocs/core/class/html.formticketsup.class.php @@ -140,7 +140,7 @@ class FormTicketsup print "\n\n"; - print '
'; + print ''; print ''; print ''; foreach ($this->param as $key => $value) { diff --git a/htdocs/public/ticketsup/list.php b/htdocs/public/ticketsup/list.php index 4d98b69a669..d4d8b16a743 100644 --- a/htdocs/public/ticketsup/list.php +++ b/htdocs/public/ticketsup/list.php @@ -40,9 +40,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticketsup.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/ticketsup.lib.php'; // Load traductions files requiredby by page -$langs->load("companies"); -$langs->load("other"); -$langs->load("ticketsup"); +$langs->loadLangs(array("companies","other","ticketsup")); // Get parameters $track_id = GETPOST('track_id', 'alpha'); @@ -201,10 +199,10 @@ if ($action == "view_ticketlist") { ); // Extra fields - if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { - foreach ($extrafields->attribute_label as $key => $val) { - if ($extrafields->attribute_type[$key] != 'separate') { - $arrayfields["ef." . $key] = array('label' => $extrafields->attribute_label[$key], 'checked' => $extrafields->attribute_list[$key], 'position' => $extrafields->attribute_pos[$key], 'enabled' => $extrafields->attribute_perms[$key]); + if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { + if ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate') { + $arrayfields["ef." . $key] = array('label' => $extrafields->attributes[$object->table_element]['label'][$key], 'checked' => $extrafields->attributes[$object->table_element]['list'][$key], 'position' => $extrafields->attributes[$object->table_element]['pos'][$key], 'enabled' => $extrafields->attributes[$object->table_element]['perms'][$key]); } } } @@ -297,8 +295,9 @@ if ($action == "view_ticketlist") { $sql .= " t.tms,"; $sql .= " type.label as type_label, category.label as category_label, severity.label as severity_label"; // Add fields for extrafields - foreach ($extrafields->attribute_list as $key => $val) { - $sql .= ($extrafields->attribute_type[$key] != 'separate' ? ",ef." . $key . ' as options_' . $key : ''); + if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) + $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef." . $key . ' as options_' . $key : ''); } $sql .= " FROM " . MAIN_DB_PREFIX . "ticketsup as t"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_ticketsup_type as type ON type.code=t.type_code"; @@ -310,7 +309,7 @@ if ($action == "view_ticketlist") { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "element_contact as ec ON ec.element_id=t.rowid"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_type_contact as tc ON ec.fk_c_type_contact=tc.rowid"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "socpeople sp ON ec.fk_socpeople=sp.rowid"; - if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { + if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "ticketsup_extrafields as ef on (t.rowid = ef.fk_object)"; } $sql .= " WHERE t.entity IN (" . getEntity('ticketsup') . ")"; @@ -408,8 +407,8 @@ if ($action == "view_ticketlist") { print_liste_field_titre($arrayfields['t.tms']['label'], $url_page_current, 't.tms', '', $param, '', $sortfield, $sortorder); } // Extra fields - if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { - foreach ($extrafields->attribute_label as $key => $val) { + if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { if (!empty($arrayfields["ef." . $key]['checked'])) { $align = $extrafields->getAlignFlag($key); print_liste_field_titre($extralabels[$key], $url_page_current, "ef." . $key, "", $param, ($align ? 'align="' . $align . '"' : ''), $sortfield, $sortorder); @@ -490,8 +489,8 @@ if ($action == "view_ticketlist") { } // Extra fields - if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { - foreach ($extrafields->attribute_label as $key => $val) { + if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { if (!empty($arrayfields["ef." . $key]['checked'])) { print '
'; } @@ -613,8 +612,8 @@ if ($action == "view_ticketlist") { } // Extra fields - if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { - foreach ($extrafields->attribute_label as $key => $val) { + if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { if (!empty($arrayfields["ef." . $key]['checked'])) { print 'getAlignFlag($key); diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index 8973d421f7f..b69d9b88048 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -73,9 +73,6 @@ top_httphead('text/css'); if (empty($dolibarr_nocache)) header('Cache-Control: max-age=3600, public, must-revalidate'); else header('Cache-Control: no-cache'); -// On the fly GZIP compression for all pages (if browser support it). Must set the bit 3 of constant to 1. -if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x04)) { ob_start("ob_gzhandler"); } - if (GETPOST('theme','alpha')) $conf->theme=GETPOST('theme','alpha'); // If theme was forced on URL if (GETPOST('lang','aZ09')) $langs->setDefaultLang(GETPOST('lang', 'aZ09')); // If language was forced on URL diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index f5c2032e308..929f95c1d0f 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -74,9 +74,6 @@ top_httphead('text/css'); if (empty($dolibarr_nocache)) header('Cache-Control: max-age=3600, public, must-revalidate'); else header('Cache-Control: no-cache'); -// On the fly GZIP compression for all pages (if browser support it). Must set the bit 3 of constant to 1. -if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x04)) { ob_start("ob_gzhandler"); } - if (GETPOST('theme','alpha')) $conf->theme=GETPOST('theme','alpha'); // If theme was forced on URL if (GETPOST('lang', 'aZ09')) $langs->setDefaultLang(GETPOST('lang', 'aZ09')); // If language was forced on URL diff --git a/htdocs/ticketsup/css/styles.css.php b/htdocs/ticketsup/css/styles.css.php index 955e6a1979d..aed9b79cbc9 100644 --- a/htdocs/ticketsup/css/styles.css.php +++ b/htdocs/ticketsup/css/styles.css.php @@ -36,12 +36,26 @@ session_cache_limiter(FALSE); require_once '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; +// Define css type +top_httphead('text/css'); +// Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access. +if (empty($dolibarr_nocache)) header('Cache-Control: max-age=3600, public, must-revalidate'); +else header('Cache-Control: no-cache'); + ?> html { min-height: 100%; height: 100%; } +html { +global->TICKETS_SHOW_MODULE_LOGO)) { + print 'background: url("../public/img/bg_ticket.png") no-repeat 95% 90%;'; +} +?> +} + body { font-size: 0.88em; background: none; From be965bdbabe26231d14f837a1cf240cd5691f7d8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 13 Apr 2018 13:28:48 +0200 Subject: [PATCH 05/15] Clean code --- htdocs/adherents/type.php | 6 +++--- htdocs/assets/type.php | 6 +++--- htdocs/categories/card.php | 2 +- htdocs/categories/edit.php | 2 +- htdocs/comm/action/card.php | 4 ++-- htdocs/commande/card.php | 2 +- htdocs/commande/orderstoinvoice.php | 2 +- htdocs/compta/bank/card.php | 4 ++-- htdocs/compta/facture/card.php | 2 +- htdocs/contact/card.php | 4 ++-- htdocs/contrat/card.php | 2 +- htdocs/core/class/html.formticketsup.class.php | 2 +- htdocs/core/tpl/extrafields_add.tpl.php | 2 +- htdocs/core/tpl/extrafields_edit.tpl.php | 2 +- htdocs/core/tpl/extrafields_view.tpl.php | 2 +- htdocs/don/card.php | 4 ++-- htdocs/expedition/card.php | 2 +- htdocs/expensereport/card.php | 2 +- htdocs/fourn/commande/card.php | 2 +- htdocs/fourn/commande/orderstoinvoice.php | 2 +- htdocs/fourn/facture/card.php | 2 +- htdocs/product/card.php | 4 ++-- htdocs/projet/card.php | 4 ++-- htdocs/projet/tasks.php | 2 +- htdocs/projet/tasks/task.php | 2 +- htdocs/resource/card.php | 2 +- htdocs/societe/card.php | 4 ++-- htdocs/supplier_proposal/card.php | 2 +- htdocs/user/card.php | 4 ++-- htdocs/user/group/card.php | 4 ++-- 30 files changed, 43 insertions(+), 43 deletions(-) diff --git a/htdocs/adherents/type.php b/htdocs/adherents/type.php index c695d0cc699..d942038b0bc 100644 --- a/htdocs/adherents/type.php +++ b/htdocs/adherents/type.php @@ -338,7 +338,7 @@ if ($action == 'create') $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } @@ -736,7 +736,7 @@ if ($rowid > 0) $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } @@ -744,7 +744,7 @@ if ($rowid > 0) print '
trans("Label"); ?>
trans("Label"); ?>
trans("AttributeCode"); ?>
'; - if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')) && empty($extrafields->attribute_computed[$key])) + if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')) && empty($extrafields->attributes[$extrafieldsobjectkey]['computed'][$key])) { $crit=$val; $tmpkey=preg_replace('/search_options_/','',$key); diff --git a/htdocs/core/tpl/extrafields_list_search_sql.tpl.php b/htdocs/core/tpl/extrafields_list_search_sql.tpl.php index e40ac5f2a07..a8e43d6429f 100644 --- a/htdocs/core/tpl/extrafields_list_search_sql.tpl.php +++ b/htdocs/core/tpl/extrafields_list_search_sql.tpl.php @@ -7,18 +7,24 @@ if (empty($conf) || ! is_object($conf)) exit; } +if (empty($extrafieldsobjectkey) && is_object($object)) $extrafieldsobjectkey=$object->table_element; + // Loop to complete the sql search criterias from extrafields -foreach ($search_array_options as $key => $val) +if (! empty($extrafieldsobjectkey)) // $extrafieldsobject is the $object->table_element like 'societe', 'socpeople', ... { - $crit=$val; - $tmpkey=preg_replace('/search_options_/','',$key); - $typ=$extrafields->attribute_type[$tmpkey]; - $mode_search=0; - if (in_array($typ, array('int','double','real'))) $mode_search=1; // Search on a numeric - if (in_array($typ, array('sellist','link')) && $crit != '0' && $crit != '-1') $mode_search=2; // Search on a foreign key int - if (in_array($typ, array('chkbxlst','checkbox'))) $mode_search=4; // Search on a multiselect field with sql type = text - if ($crit != '' && (! in_array($typ, array('select','sellist')) || $crit != '0') && (! in_array($typ, array('link')) || $crit != '-1')) + foreach ($search_array_options as $key => $val) { - $sql .= natural_search('ef.'.$tmpkey, $crit, $mode_search); + $crit=$val; + $tmpkey=preg_replace('/search_options_/','',$key); + $typ=$extrafields->attributes[$extrafieldsobjectkey]['type'][$tmpkey]; + + $mode_search=0; + if (in_array($typ, array('int','double','real'))) $mode_search=1; // Search on a numeric + if (in_array($typ, array('sellist','link')) && $crit != '0' && $crit != '-1') $mode_search=2; // Search on a foreign key int + if (in_array($typ, array('chkbxlst','checkbox'))) $mode_search=4; // Search on a multiselect field with sql type = text + if ($crit != '' && (! in_array($typ, array('select','sellist')) || $crit != '0') && (! in_array($typ, array('link')) || $crit != '-1')) + { + $sql .= natural_search('ef.'.$tmpkey, $crit, $mode_search); + } } } \ No newline at end of file diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php index 229ae0a3c3e..896d6964bdd 100644 --- a/htdocs/install/repair.php +++ b/htdocs/install/repair.php @@ -267,7 +267,7 @@ if ($ok && GETPOST('standard', 'alpha')) if (! in_array($code,array_keys($arrayoffieldsfound))) { print 'Found field '.$code.' declared into '.MAIN_DB_PREFIX.'extrafields table but not found into desc of table '.$tableextra." -> "; - $type=$extrafields->attribute_type[$code]; $length=$extrafields->attribute_size[$code]; $attribute=''; $default=''; $extra=''; $null='null'; + $type=$extrafields->attributes[$elementtype]['type'][$code]; $length=$extrafields->attributes[$elementtype]['size'][$code]; $attribute=''; $default=''; $extra=''; $null='null'; if ($type=='boolean') { $typedb='int'; diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 9083eb311b1..1ed34d5681c 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -205,7 +205,6 @@ $help_url=''; $title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("MyObjects")); -// TODO : move this SQL request into fetchAll class method // Build and execute select // -------------------------------------------------------------------- $sql = 'SELECT '; @@ -222,8 +221,8 @@ $reshook=$hookmanager->executeHooks('printFieldListSelect', $parameters, $object $sql.=$hookmanager->resPrint; $sql=preg_replace('/, $/','', $sql); $sql.= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t"; -if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."myobject_extrafields as ef on (t.rowid = ef.fk_object)"; -if ($object->ismultientitymanaged == 1) $sql.= " WHERE t.entity IN (".getEntity('myobject').")"; +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)"; +if ($object->ismultientitymanaged == 1) $sql.= " WHERE t.entity IN (".getEntity($object->element).")"; else $sql.=" WHERE 1 = 1"; foreach($search as $key => $val) { @@ -243,7 +242,7 @@ $sql.=$hookmanager->resPrint; $sql.= " GROUP BY " foreach($object->fields as $key => $val) { - $sql.='t.'.$key.', '; + $sql.='t.'.$key.', '; } // Add fields from extrafields if (! empty($extrafields->attributes[$object->table_element]['label'])) { @@ -252,6 +251,7 @@ if (! empty($extrafields->attributes[$object->table_element]['label'])) { $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook $sql.=$hookmanager->resPrint; +$sql=preg_replace('/, $/','', $sql); */ $sql.=$db->order($sortfield,$sortorder); @@ -272,7 +272,6 @@ if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller the limit, no need to do paging. if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) { - $resql = $result; $num = $nbtotalofrecords; } else diff --git a/htdocs/product/dynamic_price/class/price_parser.class.php b/htdocs/product/dynamic_price/class/price_parser.class.php index fc986a9e051..867a30faaeb 100644 --- a/htdocs/product/dynamic_price/class/price_parser.class.php +++ b/htdocs/product/dynamic_price/class/price_parser.class.php @@ -157,7 +157,7 @@ class PriceParser $extrafields = new ExtraFields($this->db); $extralabels = $extrafields->fetch_name_optionals_label('product', true); $product->fetch_optionals(); - foreach ($extrafields->attribute_label as $key=>$label) + foreach ($extrafields->attributes[$product->table_element]['label'] as $key=>$label) { $values["extrafield_".$key] = $product->array_options['options_'.$key]; } diff --git a/htdocs/public/members/public_card.php b/htdocs/public/members/public_card.php index f21a4d1a338..f3027eb0149 100644 --- a/htdocs/public/members/public_card.php +++ b/htdocs/public/members/public_card.php @@ -107,7 +107,7 @@ if ($id > 0) print $form->showphoto('memberphoto', $object, 64); print '
$value".$object->array_options["options_$key"]." 
'; - $formTicket->selectTypesTickets(dol_escape_htmltag($search[$key]), 'search_'.$key.'', '', 0, 1, 1, 0, ($val['css']?$val['css']:'maxwidth200')); - print ''; - $formTicket->selectCategoriesTickets(dol_escape_htmltag($search[$key]), 'search_'.$key.'', '', 0, 1, 1, 0, ($val['css']?$val['css']:'maxwidth200')); - print ''; - $formTicket->selectSeveritiesTickets(dol_escape_htmltag($search[$key]), 'search_'.$key.'', '', 0, 1, 1, 0, ($val['css']?$val['css']:'maxwidth200')); - print ''; - $object->printSelectStatus(dol_escape_htmltag($search[$key])); - print ''; + $formTicket->selectTypesTickets(dol_escape_htmltag($search[$key]), 'search_'.$key.'', '', 0, 1, 1, 0, ($val['css']?$val['css']:'maxwidth200')); + print ''; + $formTicket->selectCategoriesTickets(dol_escape_htmltag($search[$key]), 'search_'.$key.'', '', 0, 1, 1, 0, ($val['css']?$val['css']:'maxwidth200')); + print ''; + $formTicket->selectSeveritiesTickets(dol_escape_htmltag($search[$key]), 'search_'.$key.'', '', 0, 1, 1, 0, ($val['css']?$val['css']:'maxwidth200')); + print ''; + $object->printSelectStatus(dol_escape_htmltag($search[$key])); + print ''; $searchpicto=$form->showFilterButtons(); print $searchpicto; print '
'; - if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - { - $selected=0; - if (in_array($obj->rowid, $arrayofselected)) $selected=1; - print ''; - } - print '
'; + if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined + { + $selected=0; + if (in_array($obj->rowid, $arrayofselected)) $selected=1; + print ''; + } + print '
'.price($totalarray['val'][$totalarray['pos'][$i]]).''.$langs->trans("Total").''.$langs->trans("Totalforthispage").'
'.price($totalarray['val'][$totalarray['pos'][$i]]).''.$langs->trans("Total").''.$langs->trans("Totalforthispage").'
'.$langs->trans("NoRecordFound").'
'.$langs->trans("NoRecordFound").'
'; // Extra field - if (empty($reshook) + if (empty($reshook)) { print '

'; foreach($extrafields->attribute_label as $key=>$label) diff --git a/htdocs/assets/type.php b/htdocs/assets/type.php index 15d93f598f8..f9e725acafa 100644 --- a/htdocs/assets/type.php +++ b/htdocs/assets/type.php @@ -317,7 +317,7 @@ if ($action == 'create') $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } @@ -715,7 +715,7 @@ if ($rowid > 0) $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } @@ -723,7 +723,7 @@ if ($rowid > 0) print '
'; // Extra field - if (empty($reshook) + if (empty($reshook)) { print '

'; foreach($extrafields->attribute_label as $key=>$label) diff --git a/htdocs/categories/card.php b/htdocs/categories/card.php index 9911ad01b0b..60689dd37aa 100644 --- a/htdocs/categories/card.php +++ b/htdocs/categories/card.php @@ -268,7 +268,7 @@ if ($user->rights->categorie->creer) $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php index ed6783ea59e..67190aee2e2 100644 --- a/htdocs/categories/edit.php +++ b/htdocs/categories/edit.php @@ -176,7 +176,7 @@ print ''; $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; -if (empty($reshook) +if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index c42bf4b8c70..fb9c5944baf 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -908,7 +908,7 @@ if ($action == 'create') $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } @@ -1260,7 +1260,7 @@ if ($id > 0) $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index e0f29d5f7ee..76a290a79cd 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -1646,7 +1646,7 @@ if ($action == 'create' && $user->rights->commande->creer) $parameters = array('objectsrc' => $objectsrc, 'socid'=>$socid); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by print $hookmanager->resPrint; - if (empty($reshook) { + if (empty($reshook)) { print $object->showOptionals($extrafields, 'edit'); } diff --git a/htdocs/commande/orderstoinvoice.php b/htdocs/commande/orderstoinvoice.php index 63c590af3be..c9acc111dc4 100644 --- a/htdocs/commande/orderstoinvoice.php +++ b/htdocs/commande/orderstoinvoice.php @@ -472,7 +472,7 @@ if ($action == 'create' && !$error) $parameters=array('objectsrc' => $objectsrc, 'idsrc' => $listoforders); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { $object=new Facture($db); print $object->showOptionals($extrafields,'edit'); diff --git a/htdocs/compta/bank/card.php b/htdocs/compta/bank/card.php index ee7adeb57d7..6a9ce1d2ba1 100644 --- a/htdocs/compta/bank/card.php +++ b/htdocs/compta/bank/card.php @@ -413,7 +413,7 @@ if ($action == 'create') $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit',$parameters); } @@ -914,7 +914,7 @@ else $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index d21d6a637ad..ec14ec3da14 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -2857,7 +2857,7 @@ if ($action == 'create') $parameters = array('objectsrc' => $objectsrc,'colspan' => ' colspan="2"', 'cols'=>2); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) { + if (empty($reshook)) { print $object->showOptionals($extrafields, 'edit'); } diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index bf05d802438..bb67f0f183d 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -686,7 +686,7 @@ else $parameters=array('socid' => $socid, 'objsoc' => $objsoc, 'colspan' => ' colspan="3"', 'cols' => 3); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } @@ -963,7 +963,7 @@ else $parameters=array('colspan' => ' colspan="3"', 'cols'=>3); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 3ea527c80b9..17beae4be46 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -1287,7 +1287,7 @@ if ($action == 'create') print $hookmanager->resPrint; // Other attributes - if (empty($reshook) { + if (empty($reshook)) { print $object->showOptionals($extrafields, 'edit'); } diff --git a/htdocs/core/class/html.formticketsup.class.php b/htdocs/core/class/html.formticketsup.class.php index 1a8897c0a7d..7248e2b9a8e 100644 --- a/htdocs/core/class/html.formticketsup.class.php +++ b/htdocs/core/class/html.formticketsup.class.php @@ -386,7 +386,7 @@ class FormTicketsup // Other attributes $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $ticketstat, $action); // Note that $action and $object may have been modified by hook - if (empty($reshook) && is_array($extrafields->attributes[$ticketstat->table_element]['label'])) + if (empty($reshook)) { print $ticketstat->showOptionals($extrafields, 'edit'); } diff --git a/htdocs/core/tpl/extrafields_add.tpl.php b/htdocs/core/tpl/extrafields_add.tpl.php index 0dc6e81321f..f4f74d35428 100644 --- a/htdocs/core/tpl/extrafields_add.tpl.php +++ b/htdocs/core/tpl/extrafields_add.tpl.php @@ -40,7 +40,7 @@ if (empty($conf) || ! is_object($conf)) $parameters = array(); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; -if (empty($reshook) && ! empty($extrafields->attributes[$object->table_element]['label'])) { +if (empty($reshook)) { print $object->showOptionals($extrafields, 'edit'); } diff --git a/htdocs/core/tpl/extrafields_edit.tpl.php b/htdocs/core/tpl/extrafields_edit.tpl.php index 5c63233d373..c6d0cf61043 100644 --- a/htdocs/core/tpl/extrafields_edit.tpl.php +++ b/htdocs/core/tpl/extrafields_edit.tpl.php @@ -40,7 +40,7 @@ if (empty($conf) || ! is_object($conf)) $parameters = array(); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; -if (empty($reshook) && ! empty($extrafields->attributes[$object->table_element]['label'])) { +if (empty($reshook)) { print $object->showOptionals($extrafields, 'edit'); } diff --git a/htdocs/core/tpl/extrafields_view.tpl.php b/htdocs/core/tpl/extrafields_view.tpl.php index 3b75905370f..05d4eeab36e 100644 --- a/htdocs/core/tpl/extrafields_view.tpl.php +++ b/htdocs/core/tpl/extrafields_view.tpl.php @@ -46,7 +46,7 @@ print $hookmanager->resPrint; if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); //var_dump($extrafields->attributes); -if (empty($reshook) && ! empty($extrafields->attributes[$object->table_element]['label'])) +if (empty($reshook) && is_array($extrafields->attributes[$object->table_element]['label'])) { foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) { diff --git a/htdocs/don/card.php b/htdocs/don/card.php index d15fe10ec0b..375b49bd4d1 100644 --- a/htdocs/don/card.php +++ b/htdocs/don/card.php @@ -387,7 +387,7 @@ if ($action == 'create') $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit',$parameters); } @@ -513,7 +513,7 @@ if (! empty($id) && $action == 'edit') $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 338b07edca4..078d77c47c9 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -1059,7 +1059,7 @@ if ($action == 'create') $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$expe,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) { + if (empty($reshook)) { // copy from order $orderExtrafields = new Extrafields($db); $orderExtrafieldLabels = $orderExtrafields->fetch_name_optionals_label($object->table_element); diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 0474cde1128..1faa521d8b7 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -1412,7 +1412,7 @@ if ($action == 'create') $parameters = array('colspan' => ' colspan="3"'); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by print $hookmanager->resPrint; - if (empty($reshook) { + if (empty($reshook)) { print $object->showOptionals($extrafields, 'edit'); } diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index ef13353ed64..c0842bc253a 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -1609,7 +1609,7 @@ if ($action=='create') $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/fourn/commande/orderstoinvoice.php b/htdocs/fourn/commande/orderstoinvoice.php index 330a404790c..13a40d9fe64 100644 --- a/htdocs/fourn/commande/orderstoinvoice.php +++ b/htdocs/fourn/commande/orderstoinvoice.php @@ -371,7 +371,7 @@ if ($action == 'create' && !$error) { $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { $object=new FactureFournisseur($db); print $object->showOptionals($extrafields,'edit'); diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index d79005ea9a2..0725043f680 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -1998,7 +1998,7 @@ if ($action == 'create') // print ''; print ''; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields, 'edit'); } diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 99cf8654006..549eca022b0 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1097,7 +1097,7 @@ else $parameters=array('cols' => 3); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit',$parameters); } @@ -1470,7 +1470,7 @@ else $parameters=array('colspan' => ' colspan="3"', 'cols'=>3); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php index 96bb5b99795..89144482c25 100644 --- a/htdocs/projet/card.php +++ b/htdocs/projet/card.php @@ -869,7 +869,7 @@ elseif ($object->id > 0) $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } @@ -1055,7 +1055,7 @@ elseif ($object->id > 0) if (parseFloat(oldpercent) != 100) { jQuery("#opp_percent").val(oldpercent); } else { jQuery("#opp_percent").val(defaultpercent); } } - else + else { if ((parseFloat(jQuery("#opp_percent").val()) < parseFloat(defaultpercent))); { diff --git a/htdocs/projet/tasks.php b/htdocs/projet/tasks.php index d8b4e3ef72c..e29a1d6826e 100644 --- a/htdocs/projet/tasks.php +++ b/htdocs/projet/tasks.php @@ -418,7 +418,7 @@ if ($action == 'create' && $user->rights->projet->creer && (empty($object->third $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields_task->attribute_label)) + if (empty($reshook)) { print $object->showOptionals($extrafields_task,'edit'); } diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php index fa837607f41..735b5a81195 100644 --- a/htdocs/projet/tasks/task.php +++ b/htdocs/projet/tasks/task.php @@ -416,7 +416,7 @@ if ($id > 0 || ! empty($ref)) $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index f8ff77c035e..afdc26db622 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -285,7 +285,7 @@ if ($action == 'create' || $object->fetch($id) > 0) $parameters=array('objectsrc' => $objectsrc); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 66795cfd8e7..f318d49f98d 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -1431,7 +1431,7 @@ else $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } @@ -2018,7 +2018,7 @@ else $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php index fd74932d57e..8e391b0f1dd 100644 --- a/htdocs/supplier_proposal/card.php +++ b/htdocs/supplier_proposal/card.php @@ -1151,7 +1151,7 @@ if ($action == 'create') $parameters = array('colspan' => ' colspan="3"'); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) { + if (empty($reshook)) { print $object->showOptionals($extrafields, 'edit'); } diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 4fd1c105055..192ff3b1191 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -1070,7 +1070,7 @@ if ($action == 'create' || $action == 'adduserldap') $parameters=array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } @@ -2322,7 +2322,7 @@ else $parameters=array('colspan' => ' colspan="2"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/user/group/card.php b/htdocs/user/group/card.php index c3adb2f2f20..11850940f85 100644 --- a/htdocs/user/group/card.php +++ b/htdocs/user/group/card.php @@ -304,7 +304,7 @@ if ($action == 'create') $parameters=array('object' => $object, 'colspan' => ' colspan="2"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } @@ -570,7 +570,7 @@ else $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } From d4cd5a0d957bb76d18f4ec1f10895f07437f741c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 13 Apr 2018 13:37:43 +0200 Subject: [PATCH 06/15] Fix syntax error --- htdocs/comm/mailing/card.php | 2 +- htdocs/fichinter/card.php | 2 +- htdocs/projet/card.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index ddce7036c58..b77b5c6a549 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -754,7 +754,7 @@ if ($action == 'create') $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index 67d6a55c8bc..540f897ffe5 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -1002,7 +1002,7 @@ if ($action == 'create') $parameters=array('colspan' => ' colspan="2"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php index 89144482c25..e73db5a9155 100644 --- a/htdocs/projet/card.php +++ b/htdocs/projet/card.php @@ -629,7 +629,7 @@ if ($action == 'create' && $user->rights->projet->creer) $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } From 9f5eed0c9aca08486734c62126221bdb35232861 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 13 Apr 2018 14:12:31 +0200 Subject: [PATCH 07/15] Code comment --- htdocs/core/class/commonobject.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index e5f4fe140b5..d662fa98820 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4910,7 +4910,7 @@ abstract class CommonObject * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) * @param User $userused Object user * @return int -1=error, O=did nothing, 1=OK - * @see setValueFrom + * @see setValueFrom, insertExtraFields */ function updateExtraField($key, $trigger, $userused) { From 86112f009609ce55aa09d053657ce0c7c7faef51 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 13 Apr 2018 14:15:33 +0200 Subject: [PATCH 08/15] Syntax error --- htdocs/comm/mailing/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index b77b5c6a549..5ded0c16b5e 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -1235,7 +1235,7 @@ else $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook) + if (empty($reshook)) { print $object->showOptionals($extrafields,'edit'); } From 77a853e49d347bb36508de91ea7cc82f8993923f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 13 Apr 2018 14:53:40 +0200 Subject: [PATCH 09/15] Fix remove warning --- htdocs/core/class/conf.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 0ea6af8d5de..103b52f48f1 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -113,6 +113,7 @@ class Conf $this->notification = new stdClass(); $this->mailing = new stdClass(); $this->expensereport = new stdClass(); + $this->productbatch = new stdClass(); } @@ -509,7 +510,7 @@ class Conf // Define list of limited modules (value must be key found for "name" property of module, so for example 'supplierproposal' for Module "Supplier Proposal" if (! isset($this->global->MAIN_MODULES_FOR_EXTERNAL)) $this->global->MAIN_MODULES_FOR_EXTERNAL='user,societe,propal,commande,facture,categorie,supplierproposal,fournisseur,contact,projet,contrat,ficheinter,expedition,agenda,resource,adherent,blockedlog'; // '' means 'all'. Note that contact is added here as it should be a module later. - // Module part to include an external module into the MAIN_MODULES_FOR_EXTERNAL list + // Module part to include an external module into the MAIN_MODULES_FOR_EXTERNAL list if (! empty($this->modules_parts['moduleforexternal'])) foreach($this->modules_parts['moduleforexternal'] as $key=>$value) $this->global->MAIN_MODULES_FOR_EXTERNAL.=",$key"; From 7811796491e43aae16fc1a60356f61ffd5d9fe9a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 13 Apr 2018 15:43:26 +0200 Subject: [PATCH 10/15] Fix test --- test/phpunit/FactureTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/phpunit/FactureTest.php b/test/phpunit/FactureTest.php index d3e202f33c2..2fe0b751e1f 100644 --- a/test/phpunit/FactureTest.php +++ b/test/phpunit/FactureTest.php @@ -216,7 +216,13 @@ class FactureTest extends PHPUnit_Framework_TestCase $newlocalobject=new Facture($this->savdb); $newlocalobject->initAsSpecimen(); $this->changeProperties($newlocalobject); - $this->assertEquals($this->objCompare($localobject,$newlocalobject,true,array('newref','oldref','id','lines','client','thirdparty','brouillon','user_author','date_creation','date_validation','datem','ref','statut','paye','specimen','facnumber','actiontypecode','actionmsg2','actionmsg','mode_reglement','cond_reglement','cond_reglement_doc','situation_cycle_ref','situation_counter','situation_final','multicurrency_total_ht','multicurrency_total_tva','multicurrency_total_ttc','fk_multicurrency','multicurrency_code','multicurrency_tx')), array()); // Actual, Expected + + // Hack to avoid test to be wrong when module sellyoursaas is on + unset($localobject->array_options['options_commission']); + unset($localobject->array_options['options_reseller']); + + $arraywithdiff = $this->objCompare($localobject,$newlocalobject,true,array('newref','oldref','id','lines','client','thirdparty','brouillon','user_author','date_creation','date_validation','datem','ref','statut','paye','specimen','facnumber','actiontypecode','actionmsg2','actionmsg','mode_reglement','cond_reglement','cond_reglement_doc','situation_cycle_ref','situation_counter','situation_final','multicurrency_total_ht','multicurrency_total_tva','multicurrency_total_ttc','fk_multicurrency','multicurrency_code','multicurrency_tx')); + $this->assertEquals($arraywithdiff, array()); // Actual, Expected return $localobject; } From 4251748aca9500b585b68d82465c0c8c86e58b92 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 13 Apr 2018 16:18:33 +0200 Subject: [PATCH 11/15] Clean code --- htdocs/core/class/html.formmail.class.php | 7 +++++-- htdocs/core/lib/functions.lib.php | 9 ++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 0dd843813e8..a73422a8499 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -1266,8 +1266,11 @@ class FormMail extends Form $product = new Product($this->db); $product->fetch($line->fk_product, '', '', 1); $product->fetch_optionals(); - foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) { - $substit_line['__PRODUCT_EXTRAFIELD_' . strtoupper($key) . '__'] = $product->array_options['options_' . $key]; + if (is_array($extrafieldstmp->attributes[$object->table_element]['label']) && count($extrafieldstmp->attributes[$object->table_element]['label']) > 0) + { + foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) { + $substit_line['__PRODUCT_EXTRAFIELD_' . strtoupper($key) . '__'] = $product->array_options['options_' . $key]; + } } } $this->substit_lines[] = $substit_line; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index af8ae019a9c..c01aafdce1f 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5964,11 +5964,14 @@ function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $ob // Create dynamic tags for __EXTRAFIELD_FIELD__ if ($object->table_element && $object->id > 0) { - $extrafieldstmp = new ExtraFields($db); + if (! is_object($extrafields)) $extrafieldstmp = new ExtraFields($db); $extralabels = $extrafieldstmp->fetch_name_optionals_label($object->table_element, true); $object->fetch_optionals(); - foreach ($extrafieldstmp->attributes[$object->table_element]['label'] as $key => $label) { - $substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '__'] = $object->array_options['options_' . $key]; + if (is_array($extrafieldstmp->attributes[$object->table_element]['label']) && count($extrafieldstmp->attributes[$object->table_element]['label']) > 0) + { + foreach ($extrafieldstmp->attributes[$object->table_element]['label'] as $key => $label) { + $substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '__'] = $object->array_options['options_' . $key]; + } } } From 300d6962d932f0f5f8a28d57d65492b5e16bb1a6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 13 Apr 2018 17:05:35 +0200 Subject: [PATCH 12/15] Fix step5 upgrade process --- htdocs/install/step5.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/install/step5.php b/htdocs/install/step5.php index 9c2d8408a7d..79fead3c51d 100644 --- a/htdocs/install/step5.php +++ b/htdocs/install/step5.php @@ -37,7 +37,7 @@ $versionfrom=GETPOST("versionfrom",'alpha',3)?GETPOST("versionfrom",'alpha',3):( $versionto=GETPOST("versionto",'alpha',3)?GETPOST("versionto",'alpha',3):(empty($argv[2])?'':$argv[2]); $setuplang=GETPOST('selectlang','aZ09',3)?GETPOST('selectlang','aZ09',3):(empty($argv[3])?'auto':$argv[3]); $langs->setDefaultLang($setuplang); -$action=GETPOST('action','alpha')?GETPOST('action','alpha'):(empty($argv[4])?'auto':$argv[4]); +$action=GETPOST('action','alpha')?GETPOST('action','alpha'):(empty($argv[4])?'':$argv[4]); // Define targetversion used to update MAIN_VERSION_LAST_INSTALL for first install // or MAIN_VERSION_LAST_UPGRADE for upgrade. From 6f91b8019f53333450f7050506cc39c7b8210990 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 13 Apr 2018 17:54:27 +0200 Subject: [PATCH 13/15] Remove warnings --- htdocs/compta/facture/class/facture.class.php | 13 +++++++------ htdocs/core/class/html.formfile.class.php | 2 +- htdocs/modulebuilder/template/myobject_list.php | 9 ++++++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 343bbbe6414..a06c1ccfa20 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2730,14 +2730,15 @@ class Facture extends CommonInvoice // Mise a jour informations denormalisees au niveau de la facture meme $result=$this->update_price(1,'auto',0,$mysoc); // The addline method is designed to add line from user input so total calculation with update_price must be done using 'auto' mode. + if ($result > 0) { $this->db->commit(); - return $this->line->rowid; + return $this->line->id; } else { - $this->error=$this->db->error(); + $this->error=$this->db->lasterror(); $this->db->rollback(); return -1; } @@ -4482,11 +4483,11 @@ class FactureLigne extends CommonInvoiceLine $resql=$this->db->query($sql); if ($resql) { - $this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'facturedet'); + $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX.'facturedet'); + $this->rowid=$this->id; // For backward compatibility if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used { - $this->id=$this->rowid; $result=$this->insertExtraFields(); if ($result < 0) { @@ -4558,12 +4559,12 @@ class FactureLigne extends CommonInvoiceLine } $this->db->commit(); - return $this->rowid; + return $this->id; } else { - $this->error=$this->db->error(); + $this->error=$this->db->lasterror(); $this->db->rollback(); return -2; } diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 50386e277a1..e64271b7c0e 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -867,7 +867,7 @@ class FormFile } else { - preg_match('/\/([0-9]+)\/[^\/]+\/'.preg_quote($modulesubdir).'$/', $filedir, $regs); + preg_match('/\/([0-9]+)\/[^\/]+\/'.preg_quote($modulesubdir,'/').'$/', $filedir, $regs); $entity = ((! empty($regs[1]) && $regs[1] > 1) ? $regs[1] : $conf->entity); } diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 1ed34d5681c..5c3e5f2ae96 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -132,7 +132,7 @@ foreach($object->fields as $key => $val) if (! empty($val['visible'])) $arrayfields['t.'.$key]=array('label'=>$val['label'], 'checked'=>(($val['visible']<0)?0:1), 'enabled'=>$val['enabled'], 'position'=>$val['position']); } // Extra fields -if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) { foreach($extrafields->attributes[$object->table_element]['label'] as $key => $val) { @@ -439,9 +439,12 @@ print ''."\n"; // Detect if we need a fetch on each output line $needToFetchEachLine=0; -foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) +if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) { - if (preg_match('/\$object/',$val)) $needToFetchEachLine++; // There is at least one compute field that use $object + foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) + { + if (preg_match('/\$object/',$val)) $needToFetchEachLine++; // There is at least one compute field that use $object + } } From 32ff8ae132fa942b54ea484bf83954e7b61bf844 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 13 Apr 2018 18:02:25 +0200 Subject: [PATCH 14/15] Fix link --- htdocs/admin/system/perf.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/admin/system/perf.php b/htdocs/admin/system/perf.php index 55584df6445..1e757b72f63 100644 --- a/htdocs/admin/system/perf.php +++ b/htdocs/admin/system/perf.php @@ -50,7 +50,7 @@ llxHeader(); print load_fiche_titre($langs->trans("PerfDolibarr"),'','title_setup'); -print $langs->trans("YouMayFindPerfAdviceHere",'http://wiki.dolibarr.org/index.php/FAQ_Increase_Performance').' ('.$langs->trans("Reload").')
'; +print $langs->trans("YouMayFindPerfAdviceHere",'https://wiki.dolibarr.org/index.php/FAQ_Increase_Performance').' ('.$langs->trans("Reload").')
'; // Recupere la version de PHP $phpversion=version_php(); From 374a0723bf708bc5a2881f9e7eab1281c4e97d38 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 13 Apr 2018 22:20:14 +0200 Subject: [PATCH 15/15] Fix VAT report by rate --- htdocs/compta/tva/quadri_detail.php | 27 +++++++++++++++++++-------- htdocs/core/lib/tax.lib.php | 1 - 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php index 713cab1dc13..e04f4d83ee8 100644 --- a/htdocs/compta/tva/quadri_detail.php +++ b/htdocs/compta/tva/quadri_detail.php @@ -369,7 +369,8 @@ if (! is_array($x_coll) || ! is_array($x_paye)) foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) { // Define type - $type=($fields['dtype']?$fields['dtype']:$fields['ptype']); + // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. + $type=(isset($fields['dtype'])?$fields['dtype']:$fields['ptype']); // Try to enhance type detection using date_start and date_end for free lines where type // was not saved. if (!empty($fields['ddate_start'])) { @@ -401,10 +402,10 @@ if (! is_array($x_coll) || ! is_array($x_paye)) { $product_static->id=$fields['pid']; $product_static->ref=$fields['pref']; - $product_static->type=$fields['ptype']; + $product_static->type=$fields['dtype']; // We force with the type of line to have type how line is registered print $product_static->getNomUrl(1); if (dol_string_nohtmltag($fields['descr'])) { - print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); + print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),24); } } else @@ -423,7 +424,7 @@ if (! is_array($x_coll) || ! is_array($x_paye)) $fields['descr']=$langs->transnoentitiesnoconv($reg[1]); } } - print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); + print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),24); // Show range print_date_range($fields['ddate_start'],$fields['ddate_end']); @@ -550,7 +551,8 @@ if (! is_array($x_coll) || ! is_array($x_paye)) foreach ($x_both[$rate]['paye']['detail'] as $index=>$fields) { // Define type - $type=($fields['dtype']?$fields['dtype']:$fields['ptype']); + // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. + $type=(isset($fields['dtype'])?$fields['dtype']:$fields['ptype']); // Try to enhance type detection using date_start and date_end for free lines where type // was not saved. if (!empty($fields['ddate_start'])) { @@ -582,10 +584,10 @@ if (! is_array($x_coll) || ! is_array($x_paye)) { $product_static->id=$fields['pid']; $product_static->ref=$fields['pref']; - $product_static->type=$fields['ptype']; + $product_static->type=$fields['dtype']; // We force with the type of line to have type how line is registered print $product_static->getNomUrl(1); if (dol_string_nohtmltag($fields['descr'])) { - print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); + print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),24); } } else @@ -595,7 +597,16 @@ if (! is_array($x_coll) || ! is_array($x_paye)) } else { $text = img_object($langs->trans('Product'),'product'); } - print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); + if (preg_match('/^\((.*)\)$/',$fields['descr'],$reg)) { + if ($reg[1]=='DEPOSIT') { + $fields['descr']=$langs->transnoentitiesnoconv('Deposit'); + } elseif ($reg[1]=='CREDIT_NOTE') { + $fields['descr']=$langs->transnoentitiesnoconv('CreditNote'); + } else { + $fields['descr']=$langs->transnoentitiesnoconv($reg[1]); + } + } + print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),24); // Show range print_date_range($fields['ddate_start'],$fields['ddate_end']); diff --git a/htdocs/core/lib/tax.lib.php b/htdocs/core/lib/tax.lib.php index 26c31a4eee0..99737322267 100644 --- a/htdocs/core/lib/tax.lib.php +++ b/htdocs/core/lib/tax.lib.php @@ -323,7 +323,6 @@ function tax_by_date($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid"; } - //print $sql.'
'; if (! $sql) return -1; if ($sql == 'TODO') return -2; if ($sql != 'TODO')