From 3e91fdda77a6763a347c2f419aec4e945f3d4053 Mon Sep 17 00:00:00 2001 From: fbosman Date: Mon, 1 Jul 2019 12:34:27 +0200 Subject: [PATCH 01/12] Update commonobject.class.php --- htdocs/core/class/commonobject.class.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 5016d10780d..b065bb27470 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -5008,6 +5008,8 @@ abstract class CommonObject $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$attributeKey]; $attributeParam = $extrafields->attributes[$this->table_element]['param'][$attributeKey]; $attributeRequired = $extrafields->attributes[$this->table_element]['required'][$attributeKey]; + $attrfieldcomputed = $extrafields->attributes[$this->table_element]['computed'][$attributeKey]; + if ($attributeRequired) { @@ -5024,6 +5026,12 @@ abstract class CommonObject //dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG); //dol_syslog("attributeType=".$attributeType, LOG_DEBUG); + if (!empty($attrfieldcomputed)) + { + $value = dol_eval($attrfieldcomputed, 1, 0); + $new_array_options[$key] = $value; + } + switch ($attributeType) { From 221c202add5821ed95c81d855446fbdac86df68e Mon Sep 17 00:00:00 2001 From: Frans Bosman Date: Wed, 3 Jul 2019 06:59:52 +0200 Subject: [PATCH 02/12] Update commonobject.class.php --- 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 b065bb27470..8949dbc5f97 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -5026,7 +5026,7 @@ abstract class CommonObject //dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG); //dol_syslog("attributeType=".$attributeType, LOG_DEBUG); - if (!empty($attrfieldcomputed)) + if ((!empty($attrfieldcomputed) && (! empty($conf->global->MAIN_STORE_COMPUTED_EXTRAFIELDS))) { $value = dol_eval($attrfieldcomputed, 1, 0); $new_array_options[$key] = $value; From 9064737930307a62f75c0f406794925ddf7056df Mon Sep 17 00:00:00 2001 From: Frans Bosman Date: Wed, 3 Jul 2019 07:08:53 +0200 Subject: [PATCH 03/12] Update commonobject.class.php --- 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 8949dbc5f97..d164761366d 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -5026,7 +5026,7 @@ abstract class CommonObject //dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG); //dol_syslog("attributeType=".$attributeType, LOG_DEBUG); - if ((!empty($attrfieldcomputed) && (! empty($conf->global->MAIN_STORE_COMPUTED_EXTRAFIELDS))) + if ((!empty($attrfieldcomputed)) && (!empty($conf->global->MAIN_STORE_COMPUTED_EXTRAFIELDS))) { $value = dol_eval($attrfieldcomputed, 1, 0); $new_array_options[$key] = $value; From 116c6d7a6a9b03eb61ba8564646b4a22fe1a7cc1 Mon Sep 17 00:00:00 2001 From: Frans Bosman Date: Wed, 3 Jul 2019 11:09:24 +0200 Subject: [PATCH 04/12] Update commonobject.class.php --- htdocs/core/class/commonobject.class.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index d164761366d..67d75a62169 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -5026,10 +5026,19 @@ abstract class CommonObject //dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG); //dol_syslog("attributeType=".$attributeType, LOG_DEBUG); - if ((!empty($attrfieldcomputed)) && (!empty($conf->global->MAIN_STORE_COMPUTED_EXTRAFIELDS))) + + if (!empty($attrfieldcomputed)) { + if (!empty($conf->global->MAIN_STORE_COMPUTED_EXTRAFIELDS)) + { $value = dol_eval($attrfieldcomputed, 1, 0); + dol_syslog($langs->trans("Extrafieldcomputed")." sur ".$attributeLabel."(".$value.")", LOG_DEBUG); $new_array_options[$key] = $value; + } + else + { + $new_array_options[$key] = null; + } } From 135e47892bcd7f62b27c801feec835b02be84692 Mon Sep 17 00:00:00 2001 From: Frans Bosman Date: Wed, 3 Jul 2019 16:15:20 +0200 Subject: [PATCH 05/12] Update admin_extrafields_add.tpl.php --- htdocs/core/tpl/admin_extrafields_add.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php index 04720004492..a7ae00b9ac9 100644 --- a/htdocs/core/tpl/admin_extrafields_add.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php @@ -179,7 +179,7 @@ $langs->load("modulebuilder"); trans("LanguageFile"); ?> -textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc"), 1, 'help', '', 0, 2, 'tooltipcompute'); ?> +textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc")).$form->textwithpicto($langs->trans("Computedpersistent"), $langs->trans("ComputedpersistentDesc"), 1, 'warning', '', 0, 2, 'tooltipcompute'); ?> trans("DefaultValue").' ('.$langs->trans("Database").')'; ?> From 123cf7ce502d494915c25ba03b1bd71f2faa8169 Mon Sep 17 00:00:00 2001 From: Frans Bosman Date: Wed, 3 Jul 2019 16:16:45 +0200 Subject: [PATCH 06/12] Update admin_extrafields_add.tpl.php --- htdocs/core/tpl/admin_extrafields_add.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php index a7ae00b9ac9..5bd161c9893 100644 --- a/htdocs/core/tpl/admin_extrafields_add.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php @@ -179,7 +179,7 @@ $langs->load("modulebuilder"); trans("LanguageFile"); ?> -textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc")).$form->textwithpicto($langs->trans("Computedpersistent"), $langs->trans("ComputedpersistentDesc"), 1, 'warning', '', 0, 2, 'tooltipcompute'); ?> +textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc")).$form->textwithpicto($langs->trans("Computedpersistent"), $langs->trans("ComputedpersistentDesc"), 1, 'warning'); ?> trans("DefaultValue").' ('.$langs->trans("Database").')'; ?> From 9962243df3b772c64018c782bc15195856a8906f Mon Sep 17 00:00:00 2001 From: Frans Bosman Date: Wed, 3 Jul 2019 16:19:51 +0200 Subject: [PATCH 07/12] Update admin_extrafields_edit.tpl.php --- htdocs/core/tpl/admin_extrafields_edit.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/tpl/admin_extrafields_edit.tpl.php b/htdocs/core/tpl/admin_extrafields_edit.tpl.php index 7ed41af9281..2acdf7e864f 100644 --- a/htdocs/core/tpl/admin_extrafields_edit.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_edit.tpl.php @@ -243,7 +243,7 @@ else trans("LanguageFile"); ?> -textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc"), 1, 'help', '', 0, 2, 'tooltipcompute'); ?> +textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc")).$form->textwithpicto($langs->trans("Computedpersistent"), $langs->trans("ComputedpersistentDesc"), 1, 'warning'); ?> trans("DefaultValue").' ('.$langs->trans("Database").')'; ?> From f8a5ae90e3cf8ac89feae9f4eb8d8e616528931e Mon Sep 17 00:00:00 2001 From: Frans Bosman Date: Wed, 3 Jul 2019 16:43:47 +0200 Subject: [PATCH 08/12] Update admin.lang --- htdocs/langs/en_US/admin.lang | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 7480550195a..73d825d8320 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -422,6 +422,8 @@ ExtrafieldCheckBoxFromList=Checkboxes from table ExtrafieldLink=Link to an object ComputedFormula=Computed field ComputedFormulaDesc=You can enter here a formula using other properties of object or any PHP coding to get a dynamic computed value. You can use any PHP compatible formulas including the "?" condition operator, and following global object: $db, $conf, $langs, $mysoc, $user, $object.
WARNING: Only some properties of $object may be available. If you need a properties not loaded, just fetch yourself the object into your formula like in the second example.
Using a computed field means you can't enter yourself any value from interface. Also, if there is a syntax error, the formula may return nothing.

Example of formula:
$object->id < 10 ? round($object->id / 2, 2): ($object->id + 2 * $user->id) * (int) substr($mysoc->zip, 1, 2)

Example to reload object
(($reloadedobj = new Societe($db)) && ($reloadedobj->fetch($obj->id ? $obj->id: ($obj->rowid ? $obj->rowid: $object->id)) > 0)) ? $reloadedobj->array_options['options_extrafieldkey'] * $reloadedobj->capital / 5: '-1'

Other example of formula to force load of object and its parent object:
(($reloadedobj = new Task($db)) && ($reloadedobj->fetch($object->id) > 0) && ($secondloadedobj = new Project($db)) && ($secondloadedobj->fetch($reloadedobj->fk_project) > 0)) ? $secondloadedobj->ref: 'Parent project not found' +Computedpersistent=Store computed field +ComputedpersistentDesc=Computed extra fields will be stored in the database, however, the value will only be recalculated when the object of this field is changed. If the computed field depends on other objects or global data this value might be wrong!! ExtrafieldParamHelpPassword=Leaving this field blank means this value will be stored without encryption (field must be only hidden with star on screen).
Set 'auto' to use the default encryption rule to save password into database (then value read will be the hash only, no way to retrieve original value) ExtrafieldParamHelpselect=List of values must be lines with format key,value (where key can't be '0')

for example:
1,value1
2,value2
code3,value3
...

In order to have the list depending on another complementary attribute list:
1,value1|options_parent_list_code:parent_key
2,value2|options_parent_list_code:parent_key

In order to have the list depending on another list:
1,value1|parent_list_code:parent_key
2,value2|parent_list_code:parent_key ExtrafieldParamHelpcheckbox=List of values must be lines with format key,value (where key can't be '0')

for example:
1,value1
2,value2
3,value3
... @@ -1924,4 +1926,4 @@ UrlForIFTTT=URL endpoint for IFTTT YouWillFindItOnYourIFTTTAccount=You will find it on your IFTTT account EndPointFor=End point for %s : %s DeleteEmailCollector=Delete email collector -ConfirmDeleteEmailCollector=Are you sure you want to delete this email collector? \ No newline at end of file +ConfirmDeleteEmailCollector=Are you sure you want to delete this email collector? From cd7d4de6ecae99d7723ed55d7e9e1141242c6bbc Mon Sep 17 00:00:00 2001 From: Frans Bosman Date: Wed, 3 Jul 2019 16:53:26 +0200 Subject: [PATCH 09/12] Update commonobject.class.php --- 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 67d75a62169..0a300476fb5 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -5029,7 +5029,7 @@ abstract class CommonObject if (!empty($attrfieldcomputed)) { - if (!empty($conf->global->MAIN_STORE_COMPUTED_EXTRAFIELDS)) + if (!empty($conf->global->MAIN_STORE_COMPUTED_EXTRAFIELDS)) { $value = dol_eval($attrfieldcomputed, 1, 0); dol_syslog($langs->trans("Extrafieldcomputed")." sur ".$attributeLabel."(".$value.")", LOG_DEBUG); From b691396fceedcda48a57550efd694c3e9724bf44 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 4 Jul 2019 16:19:24 +0200 Subject: [PATCH 10/12] Update admin_extrafields_add.tpl.php --- htdocs/core/tpl/admin_extrafields_add.tpl.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php index 5bd161c9893..0db5d6afb68 100644 --- a/htdocs/core/tpl/admin_extrafields_add.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php @@ -179,7 +179,11 @@ $langs->load("modulebuilder"); trans("LanguageFile"); ?> -textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc")).$form->textwithpicto($langs->trans("Computedpersistent"), $langs->trans("ComputedpersistentDesc"), 1, 'warning'); ?> +global->STORE_COMPUTED_EXTRAFIELDS)) { > + textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc"), 1, 'help', '', 0, 2, 'tooltipcompute'); ?> + + textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc")).$form->textwithpicto($langs->trans("Computedpersistent"), $langs->trans("ComputedpersistentDesc"), 1, 'warning'); ?> + trans("DefaultValue").' ('.$langs->trans("Database").')'; ?> From f14b0b4fcc79fa01ff5b1fb514ce6bb9c78550f0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 4 Jul 2019 16:20:01 +0200 Subject: [PATCH 11/12] Update admin_extrafields_add.tpl.php --- htdocs/core/tpl/admin_extrafields_add.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php index 0db5d6afb68..834462aab5f 100644 --- a/htdocs/core/tpl/admin_extrafields_add.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php @@ -179,7 +179,7 @@ $langs->load("modulebuilder"); trans("LanguageFile"); ?> -global->STORE_COMPUTED_EXTRAFIELDS)) { > +global->MAIN_STORE_COMPUTED_EXTRAFIELDS)) { > textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc"), 1, 'help', '', 0, 2, 'tooltipcompute'); ?> textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc")).$form->textwithpicto($langs->trans("Computedpersistent"), $langs->trans("ComputedpersistentDesc"), 1, 'warning'); ?> From 0d738a04f9d617b4efe0a6b1d2d24e48feaeab0c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 4 Jul 2019 16:22:10 +0200 Subject: [PATCH 12/12] Update admin_extrafields_edit.tpl.php --- htdocs/core/tpl/admin_extrafields_edit.tpl.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/core/tpl/admin_extrafields_edit.tpl.php b/htdocs/core/tpl/admin_extrafields_edit.tpl.php index 2acdf7e864f..17399b0a824 100644 --- a/htdocs/core/tpl/admin_extrafields_edit.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_edit.tpl.php @@ -243,7 +243,11 @@ else trans("LanguageFile"); ?> -textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc")).$form->textwithpicto($langs->trans("Computedpersistent"), $langs->trans("ComputedpersistentDesc"), 1, 'warning'); ?> +global->MAIN_STORE_COMPUTED_EXTRAFIELDS)) { ?> + textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc"), 1, 'help', '', 0, 2, 'tooltipcompute'); ?> + + textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc")).$form->textwithpicto($langs->trans("Computedpersistent"), $langs->trans("ComputedpersistentDesc"), 1, 'warning'); ?> + trans("DefaultValue").' ('.$langs->trans("Database").')'; ?>