diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 5ed546716da..bb9d6b65cef 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -9173,7 +9173,7 @@ abstract class CommonObject } else { return true; } - } elseif ($type == 'mail') { + } elseif ($type == 'mail' || $type == 'email') { if (!$validate->isEmail($fieldValue)) { $this->setFieldError($fieldKey, $validate->error); return false; diff --git a/htdocs/core/class/defaultvalues.class.php b/htdocs/core/class/defaultvalues.class.php index c92697a4a9f..98f42c6ba8e 100644 --- a/htdocs/core/class/defaultvalues.class.php +++ b/htdocs/core/class/defaultvalues.class.php @@ -49,7 +49,7 @@ class DefaultValues extends CommonObject public $picto = ''; /** - * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password') + * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'email', 'phone', 'url', 'password') * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)" * 'label' the translation key. * 'picto' is code of a picto to show before value in forms diff --git a/htdocs/core/class/emailsenderprofile.class.php b/htdocs/core/class/emailsenderprofile.class.php index bd1034abe3d..dae553788ff 100644 --- a/htdocs/core/class/emailsenderprofile.class.php +++ b/htdocs/core/class/emailsenderprofile.class.php @@ -62,7 +62,7 @@ class EmailSenderProfile extends CommonObject /** - * 'type' if the field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password') + * 'type' if the field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'html', 'date', 'datetime', 'timestamp', 'duration', 'email', 'phone', 'url', 'password') * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)" * 'label' the translation key. * 'enabled' is a condition when the field must be managed. diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 2b818e09c38..bf58a8ccfc0 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -88,7 +88,7 @@ class ExtraFields 'price' => 'ExtrafieldPrice', 'pricecy' => 'ExtrafieldPriceWithCurrency', 'phone' => 'ExtrafieldPhone', - 'mail' => 'ExtrafieldMail', + 'email' => 'ExtrafieldMail', 'url' => 'ExtrafieldUrl', 'ip' => 'ExtrafieldIP', 'icon' => 'Icon', @@ -142,7 +142,7 @@ class ExtraFields * * @param string $attrname Code of attribute * @param string $label label of attribute - * @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'duration', 'price', 'pricecy', 'phone', 'mail', 'password', 'url', 'select', 'checkbox', 'separate',...) + * @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'duration', 'price', 'pricecy', 'phone', 'email', 'password', 'url', 'select', 'checkbox', 'separate',...) * @param int $pos Position of attribute * @param string $size Size/length definition of attribute ('5', '24,8', ...). For float, it contains 2 numeric separated with a comma. * @param string $elementtype Element type. Same value than object->table_element (Example 'member', 'product', 'thirdparty', ...) @@ -221,7 +221,7 @@ class ExtraFields * * @param string $attrname Code of attribute * @param string $label label of attribute - * @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'duration', 'price', 'pricecy', 'phone', 'mail', 'password', 'url', 'select', 'checkbox', 'separate',...) + * @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'duration', 'price', 'pricecy', 'phone', 'email', 'password', 'url', 'select', 'checkbox', 'separate',...) * @param int $pos Position of attribute * @param string $size Size/length definition of attribute ('5', '24,8', ...). For float, it contains 2 numeric separated with a comma. * @param string $elementtype Element type. Same value than object->table_element (Example 'member', 'product', 'thirdparty', ...) @@ -293,7 +293,7 @@ class ExtraFields * This is a private method. For public method, use addExtraField. * * @param string $attrname code of attribute - * @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'duration', 'price', 'pricecy', 'phone', 'mail', 'password', 'url', 'select', 'checkbox', ...) + * @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'duration', 'price', 'pricecy', 'phone', 'email', 'password', 'url', 'select', 'checkbox', ...) * @param string $length Size/length of attribute ('5', '24,8', ...) * @param string $elementtype Element type ('member', 'product', 'thirdparty', 'contact', ...) * @param int<0,1> $unique Is field unique or not @@ -668,7 +668,7 @@ class ExtraFields * * @param string $attrname Name of attribute * @param string $label Label of attribute - * @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'duration', 'price', 'phone', 'mail', 'password', 'url', 'select', 'checkbox', ...) + * @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'duration', 'price', 'phone', 'email', 'password', 'url', 'select', 'checkbox', ...) * @param string $length Size/length of attribute ('5', '24,8', ...) * @param string $elementtype Element type ('member', 'product', 'thirdparty', 'contact', ...) * @param int<0,1> $unique Is field unique or not @@ -723,7 +723,7 @@ class ExtraFields } elseif ($type == 'phone') { $typedb = 'varchar'; $lengthdb = '20'; - } elseif ($type == 'mail' || $type == 'ip' || $type == 'icon') { + } elseif ($type == 'mail' || $type == 'email' || $type == 'ip' || $type == 'icon') { $typedb = 'varchar'; $lengthdb = '128'; } elseif ($type == 'url') { @@ -1259,7 +1259,7 @@ class ExtraFields $out = ''; } elseif (preg_match('/varchar/', $type)) { $out = ''; - } elseif (in_array($type, array('mail', 'ip', 'phone', 'url'))) { + } elseif (in_array($type, array('email', 'mail', 'ip', 'phone', 'url'))) { $out = ''; } elseif ($type == 'icon') { /* External lib inclusion are not allowed in backoffice. Also lib is included several time if there is several icon file. @@ -2117,7 +2117,7 @@ class ExtraFields } else { $value = yn($value ? 1 : 0); } - } elseif ($type == 'mail') { + } elseif ($type == 'mail' || $type == 'email') { $value = dol_print_email($value, 0, 0, 0, 64, 1, 1); } elseif ($type == 'ip') { $value = dol_print_ip($value, 0); diff --git a/htdocs/core/class/timespent.class.php b/htdocs/core/class/timespent.class.php index f7844ac896d..e7655fe4582 100644 --- a/htdocs/core/class/timespent.class.php +++ b/htdocs/core/class/timespent.class.php @@ -71,7 +71,7 @@ class TimeSpent extends CommonObject * 'double(24,8)', 'real', 'price', * 'date', 'datetime', 'timestamp', 'duration', * 'boolean', 'checkbox', 'radio', 'array', - * 'mail', 'phone', 'url', 'password', 'ip' + * 'email', 'phone', 'url', 'password', 'ip' * Note: Filter must be a Dolibarr filter syntax string. Example: "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.status:!=:0) or (t.nature:is:NULL)" * 'label' the translation key. * 'picto' is code of a picto to show before value in forms diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index eb7cfa1ad56..930e3cf9f35 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -55,7 +55,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = $error = 0; - // Check parameters + // Check parameters into $addfieldentry (this provided array is filled by modulebuilder/index.php) if (is_array($addfieldentry) && count($addfieldentry) > 0) { if (empty($addfieldentry['name'])) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Name")), null, 'errors'); @@ -66,11 +66,12 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = return -2; } if (!preg_match('/^(integer|price|sellist|varchar|double|text|html|duration|stars)/', $addfieldentry['type']) - && !preg_match('/^(boolean|smallint|real|date|datetime|timestamp|phone|mail|url|ip|password)$/', $addfieldentry['type'])) { + && !preg_match('/^(boolean|smallint|real|date|datetime|timestamp|phone|email|url|ip|password)$/', $addfieldentry['type'])) { // Use email for email, mail is kept for compatibility setEventMessages($langs->trans('BadValueForType', $addfieldentry['type']), null, 'errors'); return -2; } // Check for type stars(NumberOfStars), NumberOfStars must be an integer between 1 and 10 + $matches = array(); if (preg_match('/^stars\((.+)\)$/', $addfieldentry['type'], $matches)) { if (!ctype_digit($matches[1]) || $matches[1] < 1 || $matches[1] > 10) { setEventMessages($langs->trans('BadValueForType', $addfieldentry['type']), null, 'errors'); @@ -350,7 +351,7 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = ' $type = 'integer'; } elseif ($type == 'chkbxlst') { $type = 'varchar(128)'; - } elseif ($type == 'mail') { + } elseif ($type == 'mail' || $type == 'email') { // Prefer to use 'email' $type = 'varchar(128)'; } elseif (strpos($type, 'stars(') === 0) { $type = 'integer'; @@ -358,6 +359,8 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = ' $type = 'varchar(20)'; } elseif ($type == 'ip') { $type = 'varchar(32)'; + } elseif ($type == 'url') { + $type = 'varchar(255)'; } $texttoinsert .= "\t".$key." ".$type; diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 2f4b510ada2..76418dce2df 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -1130,7 +1130,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname && $user->hasRi setEventMessages($langs->trans("ErrorTableNotFound", $tablename), null, 'errors'); } else { /** - * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter[:Sortfield]]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'ip', 'url', 'password') + * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter[:Sortfield]]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'email', 'phone', 'ip', 'url', 'password') * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)" * 'label' the translation key. * 'picto' is code of a picto to show before value in forms @@ -4636,7 +4636,34 @@ if ($module == 'initmodule') { print ''; print ''; print '