From d77eca294fafd079b71c74a304eae8ea86572124 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 26 Sep 2024 13:26:54 +0200 Subject: [PATCH] FIX Protection to avoid an extrafield to be mandatory if computed --- htdocs/core/class/extrafields.class.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 63d0f4aeb9d..6727755443a 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -148,6 +148,7 @@ class ExtraFields $result = 0; + // Clean properties if ($type == 'separate') { $unique = 0; $required = 0; @@ -158,6 +159,10 @@ class ExtraFields if ($elementtype == 'contact') { $elementtype = 'socpeople'; } + // If property has a computed formula, it must not be a required field + if (!empty($computed)) { + $required = 0; + } // Create field into database except for separator type which is not stored in database if ($type != 'separate') { @@ -568,6 +573,7 @@ class ExtraFields } if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname)) { + // Clean parameters if ($type == 'boolean') { $typedb = 'int'; $lengthdb = '1'; @@ -604,6 +610,11 @@ class ExtraFields } $field_desc = array('type'=>$typedb, 'value'=>$lengthdb, 'null'=>($required ? 'NOT NULL' : 'NULL'), 'default'=>$default); + // If property has a computed formula, it must not be a required field + if (!empty($computed)) { + $required = 0; + } + if (is_object($hookmanager)) { $hookmanager->initHooks(array('extrafieldsdao')); $parameters = array('field_desc'=>&$field_desc, 'table'=>$table, 'attr_name'=>$attrname, 'label'=>$label, 'type'=>$type, 'length'=>$length, 'unique'=>$unique, 'required'=>$required, 'pos'=>$pos, 'param'=>$param, 'alwayseditable'=>$alwayseditable, 'perms'=>$perms, 'list'=>$list, 'help'=>$help, 'default'=>$default, 'computed'=>$computed, 'entity'=>$entity, 'langfile'=>$langfile, 'enabled'=>$enabled, 'totalizable'=>$totalizable, 'printable'=>$printable);