From c966cdbd476cfc4ed29a158d52431a1180d5e5cc Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio Date: Wed, 11 Apr 2018 11:43:51 +0200 Subject: [PATCH 1/5] FIX: selectForFormsList: entity checked even is object not multi-entity managed --- htdocs/core/class/html.form.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 4daf78ad52e..bd5a32dc9a4 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5293,7 +5293,8 @@ class Form $sql = "SELECT t.rowid, ".$fieldstoshow." FROM ".MAIN_DB_PREFIX .$objecttmp->table_element." as t"; if ($objecttmp->ismultientitymanaged == 2) if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE t.entity IN (".getEntity($objecttmp->table_element).")"; + $sql.= " WHERE 1"; + if(! empty($objecttmp->ismultientitymanaged)) $sql.= " AND t.entity IN (".getEntity($objecttmp->table_element).")"; if ($objecttmp->ismultientitymanaged == 1 && ! empty($user->societe_id)) { if ($objecttmp->element == 'societe') $sql.= " AND t.rowid = ".$user->societe_id; From 2f75bfcd83c4f93480f0611142b8b8c16de2c34a Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio Date: Wed, 11 Apr 2018 11:46:47 +0200 Subject: [PATCH 2/5] FIX: modulebuilder: could not create html fields --- htdocs/core/lib/modulebuilder.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index 8e2cba43097..496a3dbbf54 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -63,7 +63,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir=' setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Label")), null, 'errors'); return -2; } - if (! preg_match('/^(integer|date|timestamp|varchar|double)/', $addfieldentry['type'])) + if (! preg_match('/^(integer|date|timestamp|varchar|double|html)/', $addfieldentry['type'])) { setEventMessages($langs->trans('BadFormatForType', $objectname), null, 'errors'); return -2; From bbc12cf06b8f2cfc58b89462b69c6686a434b0d9 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio Date: Wed, 11 Apr 2018 11:49:29 +0200 Subject: [PATCH 3/5] FIX: default addupdatedelete actions: uniformize add/update value checks --- htdocs/core/actions_addupdatedelete.inc.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index b8ede4d7d14..f24e0264bd4 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -47,8 +47,15 @@ if ($action == 'add' && ! empty($permissiontoadd)) if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; // Ignore special fields // Set value to insert - if (in_array($object->fields[$key]['type'], array('text', 'html'))) $value = GETPOST($key,'none'); - else $value = GETPOST($key,'alpha'); + if (in_array($object->fields[$key]['type'], array('text', 'html'))) { + $value = GETPOST($key,'none'); + } elseif ($object->fields[$key]['type']=='date') { + $value = dol_mktime(12, 0, 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year')); + } elseif ($object->fields[$key]['type']=='datetime') { + $value = dol_mktime(GETPOST($key.'hour'), GETPOST($key.'min'), 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year')); + } else { + $value = GETPOST($key,'alpha'); + } if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') $value=''; // This is an implicit foreign key field if (! empty($object->fields[$key]['foreignkey']) && $value == '-1') $value=''; // This is an explicit foreign key field @@ -95,8 +102,7 @@ if ($action == 'update' && ! empty($permissiontoadd)) // Set value to update if (in_array($object->fields[$key]['type'], array('text', 'html'))) { $value = GETPOST($key,'none'); - } - elseif ($object->fields[$key]['type']=='date') { + } elseif ($object->fields[$key]['type']=='date') { $value = dol_mktime(12, 0, 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year')); } elseif ($object->fields[$key]['type']=='datetime') { $value = dol_mktime(GETPOST($key.'hour'), GETPOST($key.'min'), 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year')); From fa8cf982492f6096c853b620d65a11b854c5b0f6 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio Date: Wed, 11 Apr 2018 12:18:54 +0200 Subject: [PATCH 4/5] FIX: modulebuilder: handle 'price' fieldtype --- htdocs/core/actions_addupdatedelete.inc.php | 4 ++++ htdocs/core/lib/modulebuilder.lib.php | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index f24e0264bd4..6e1ddf8a796 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -53,6 +53,8 @@ if ($action == 'add' && ! empty($permissiontoadd)) $value = dol_mktime(12, 0, 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year')); } elseif ($object->fields[$key]['type']=='datetime') { $value = dol_mktime(GETPOST($key.'hour'), GETPOST($key.'min'), 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year')); + } elseif ($object->fields[$key]['type']=='price') { + $value = price2num(GETPOST($key)); } else { $value = GETPOST($key,'alpha'); } @@ -106,6 +108,8 @@ if ($action == 'update' && ! empty($permissiontoadd)) $value = dol_mktime(12, 0, 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year')); } elseif ($object->fields[$key]['type']=='datetime') { $value = dol_mktime(GETPOST($key.'hour'), GETPOST($key.'min'), 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year')); + } elseif ($object->fields[$key]['type']=='price') { + $value = price2num(GETPOST($key)); } else { $value = GETPOST($key,'alpha'); } diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index 496a3dbbf54..185e3a3b4a1 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -63,7 +63,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir=' setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Label")), null, 'errors'); return -2; } - if (! preg_match('/^(integer|date|timestamp|varchar|double|html)/', $addfieldentry['type'])) + if (! preg_match('/^(integer|date|timestamp|varchar|double|html|price)/', $addfieldentry['type'])) { setEventMessages($langs->trans('BadFormatForType', $objectname), null, 'errors'); return -2; @@ -257,6 +257,7 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir='', $type = $val['type']; $type = preg_replace('/:.*$/', '', $type); // For case type = 'integer:Societe:societe/class/societe.class.php' if ($type == 'html') $type = 'text'; // html modulebuilder type is a text type in database + if ($type == 'price') $type = 'double'; // html modulebuilder type is a text type in database $texttoinsert.= "\t".$key." ".$type; if ($key == 'rowid') $texttoinsert.= ' AUTO_INCREMENT PRIMARY KEY'; if ($key == 'entity') $texttoinsert.= ' DEFAULT 1'; From 9ccba03a1720565d80d52b25a4624859dcb7a854 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 11 Apr 2018 18:00:34 +0200 Subject: [PATCH 5/5] Update html.form.class.php --- htdocs/core/class/html.form.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index bd5a32dc9a4..c1602066ee6 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5293,7 +5293,7 @@ class Form $sql = "SELECT t.rowid, ".$fieldstoshow." FROM ".MAIN_DB_PREFIX .$objecttmp->table_element." as t"; if ($objecttmp->ismultientitymanaged == 2) if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE 1"; + $sql.= " WHERE 1=1"; if(! empty($objecttmp->ismultientitymanaged)) $sql.= " AND t.entity IN (".getEntity($objecttmp->table_element).")"; if ($objecttmp->ismultientitymanaged == 1 && ! empty($user->societe_id)) {