From 826bde06566b00d68dcba36f1cb46059daeea4a4 Mon Sep 17 00:00:00 2001 From: Quentin VIAL-GOUTEYRON Date: Mon, 6 Dec 2021 11:19:12 +0100 Subject: [PATCH 1/4] FIX set optional from post --- htdocs/adherents/card.php | 2 +- htdocs/adherents/type.php | 2 +- htdocs/asset/type.php | 2 +- htdocs/categories/edit.php | 2 +- htdocs/comm/action/card.php | 2 +- htdocs/compta/bank/card.php | 2 +- htdocs/contact/card.php | 2 +- htdocs/core/class/extrafields.class.php | 3 ++- htdocs/don/card.php | 2 +- htdocs/product/stock/card.php | 2 +- htdocs/projet/card.php | 2 +- htdocs/projet/tasks/task.php | 2 +- htdocs/resource/card.php | 2 +- htdocs/user/card.php | 2 +- htdocs/user/group/card.php | 2 +- 15 files changed, 16 insertions(+), 15 deletions(-) diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index 93c548cef62..0987b3efcf4 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -326,7 +326,7 @@ if (empty($reshook)) $object->public = GETPOST("public", 'alpha'); // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost(null, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET'); if ($ret < 0) $error++; // Check if we need to also synchronize user information diff --git a/htdocs/adherents/type.php b/htdocs/adherents/type.php index d8890836bb7..d404080b2c0 100644 --- a/htdocs/adherents/type.php +++ b/htdocs/adherents/type.php @@ -175,7 +175,7 @@ if ($action == 'update' && $user->rights->adherent->configurer) $object->vote = (boolean) trim($vote); // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost(null, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET'); if ($ret < 0) $error++; $ret = $object->update($user); diff --git a/htdocs/asset/type.php b/htdocs/asset/type.php index 8df5ffe8c40..b58bb74853c 100644 --- a/htdocs/asset/type.php +++ b/htdocs/asset/type.php @@ -154,7 +154,7 @@ if ($action == 'update' && $user->rights->asset->write) $object->note = trim($comment); // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost(null, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET'); if ($ret < 0) $error++; $ret = $object->update($user); diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php index cd8a718279e..10af9ff2b25 100644 --- a/htdocs/categories/edit.php +++ b/htdocs/categories/edit.php @@ -102,7 +102,7 @@ if ($action == 'update' && $user->rights->categorie->creer) } if (!$error && empty($object->error)) { - $ret = $extrafields->setOptionalsFromPost(null, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET'); if ($ret < 0) $error++; if (!$error && $object->update($user) > 0) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index fcb33bd544a..b1314a8e702 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -529,7 +529,7 @@ if (empty($reshook) && $action == 'update') } // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost(null, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET'); if ($ret < 0) $error++; if (!$error) { diff --git a/htdocs/compta/bank/card.php b/htdocs/compta/bank/card.php index 1403ecc66b8..ebc8a479213 100644 --- a/htdocs/compta/bank/card.php +++ b/htdocs/compta/bank/card.php @@ -246,7 +246,7 @@ if ($action == 'update') if (!$error) { // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost(null, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET'); } if (!$error) diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index 3e3e1894a75..0ca5b184f88 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -421,7 +421,7 @@ if (empty($reshook)) $object->roles = GETPOST("roles", 'array'); // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost(null, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET'); if ($ret < 0) $error++; if (!$error) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index f37d2e1932c..4d20499b5ba 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -2055,7 +2055,8 @@ class ExtraFields foreach ($extralabels as $key => $value) { if (!empty($onlykey) && $onlykey != '@GETPOSTISSET' && $key != $onlykey) continue; - if (!empty($onlykey) && $onlykey == '@GETPOSTISSET' && ! GETPOSTISSET('options_'.$key)) continue; + //when unticking boolean field, it's not set in POST + if (!empty($onlykey) && $onlykey == '@GETPOSTISSET' && ! GETPOSTISSET('options_'.$key) && $this->attributes[$object->table_element]['type'][$key] != 'boolean') continue; $key_type = $this->attributes[$object->table_element]['type'][$key]; if ($key_type == 'separate') continue; diff --git a/htdocs/don/card.php b/htdocs/don/card.php index 3d2e873b5b3..9c7c0a0bcc5 100644 --- a/htdocs/don/card.php +++ b/htdocs/don/card.php @@ -118,7 +118,7 @@ if ($action == 'update') $object->modepaymentid = GETPOST('modepayment', 'int'); // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost(null, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET'); if ($ret < 0) $error++; if ($object->update($user) > 0) diff --git a/htdocs/product/stock/card.php b/htdocs/product/stock/card.php index 1f53d3491fa..1fa34d2f03f 100644 --- a/htdocs/product/stock/card.php +++ b/htdocs/product/stock/card.php @@ -182,7 +182,7 @@ if (empty($reshook)) $object->fax = GETPOST("fax"); // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost(null, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET'); if ($ret < 0) $error++; if (!$error) { diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php index ab350dc0919..3ec0141bedb 100644 --- a/htdocs/projet/card.php +++ b/htdocs/projet/card.php @@ -276,7 +276,7 @@ if (empty($reshook)) $object->usage_organize_event = (GETPOST('usage_organize_event', 'alpha') == 'on' ? 1 : 0); // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost(null, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET'); if ($ret < 0) $error++; } diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php index d912286b3c8..228c17328f2 100644 --- a/htdocs/projet/tasks/task.php +++ b/htdocs/projet/tasks/task.php @@ -102,7 +102,7 @@ if ($action == 'update' && !$_POST["cancel"] && $user->rights->projet->creer) $object->progress = $_POST['progress']; // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost(null, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET'); if ($ret < 0) $error++; if (!$error) diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index b403c0516f9..2204d9c05bf 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -155,7 +155,7 @@ if (empty($reshook)) $object->country_id = $country_id; // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost(null, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET'); if ($ret < 0) { $error++; } diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 9b747d9c713..6cce8180502 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -440,7 +440,7 @@ if (empty($reshook)) { } // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost(null, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET'); if ($ret < 0) { $error++; } diff --git a/htdocs/user/group/card.php b/htdocs/user/group/card.php index d70827d357f..8db1e90c72d 100644 --- a/htdocs/user/group/card.php +++ b/htdocs/user/group/card.php @@ -219,7 +219,7 @@ if (empty($reshook)) { $object->note = dol_htmlcleanlastbr(trim(GETPOST("note", 'none'))); // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost(null, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET'); if ($ret < 0) $error++; if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) $object->entity = 0; From 386771cffc96106afb570f96867db49a60ab660b Mon Sep 17 00:00:00 2001 From: atm-gregr Date: Wed, 8 Dec 2021 14:21:42 +0100 Subject: [PATCH 2/4] fix display contat line on list --- htdocs/contact/list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index 7397cf8b61f..113fc5e74f7 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -418,7 +418,7 @@ if (count($search_roles) > 0) { $sql .= " AND p.rowid IN (SELECT sc.fk_socpeople FROM ".MAIN_DB_PREFIX."societe_contacts as sc WHERE sc.fk_c_type_contact IN (".implode(',', $search_roles)."))"; } if ($search_no_email != -1 && $search_no_email > 0) $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = p.email) > 0"; -if ($search_no_email != -1 && $search_no_email == 0) $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = p.email) = 0 AND p.email IS NOT NULL AND p.email <> ''"; +if ($search_no_email != -1 && $search_no_email == 0) $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = p.email) = 0"; if ($search_status != '' && $search_status >= 0) $sql .= " AND p.statut = ".$db->escape($search_status); if ($search_import_key) $sql .= natural_search("p.import_key", $search_import_key); if ($type == "o") // filtre sur type From 01893caa610240b48076a315697319a2fd5778aa Mon Sep 17 00:00:00 2001 From: atm-gregr Date: Wed, 8 Dec 2021 14:40:46 +0100 Subject: [PATCH 3/4] bad default value --- htdocs/contact/list.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index 113fc5e74f7..1672bdd3f7f 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -96,6 +96,7 @@ $search_level = GETPOST("search_level", "array"); $search_stcomm = GETPOST('search_stcomm', 'int'); if ($search_status == '') $search_status = 1; // always display active customer first +if ($search_no_email == '') $search_no_email = -1; $optioncss = GETPOST('optioncss', 'alpha'); @@ -418,7 +419,7 @@ if (count($search_roles) > 0) { $sql .= " AND p.rowid IN (SELECT sc.fk_socpeople FROM ".MAIN_DB_PREFIX."societe_contacts as sc WHERE sc.fk_c_type_contact IN (".implode(',', $search_roles)."))"; } if ($search_no_email != -1 && $search_no_email > 0) $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = p.email) > 0"; -if ($search_no_email != -1 && $search_no_email == 0) $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = p.email) = 0"; +if ($search_no_email != -1 && $search_no_email == 0) $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = p.email) = 0 AND p.email IS NOT NULL AND p.email <> ''"; if ($search_status != '' && $search_status >= 0) $sql .= " AND p.statut = ".$db->escape($search_status); if ($search_import_key) $sql .= natural_search("p.import_key", $search_import_key); if ($type == "o") // filtre sur type From 9b65bb2085b8ef70f89d42bc600e298b428615a8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 8 Dec 2021 15:29:16 +0100 Subject: [PATCH 4/4] Update list.php --- htdocs/contact/list.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index 1672bdd3f7f..45454485b70 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -95,8 +95,8 @@ $search_roles = GETPOST("search_roles", 'array'); $search_level = GETPOST("search_level", "array"); $search_stcomm = GETPOST('search_stcomm', 'int'); -if ($search_status == '') $search_status = 1; // always display active customer first -if ($search_no_email == '') $search_no_email = -1; +if ($search_status === '') $search_status = 1; // always display active customer first +if ($search_no_email === '') $search_no_email = -1; $optioncss = GETPOST('optioncss', 'alpha');