diff --git a/htdocs/core/class/html.formadmin.class.php b/htdocs/core/class/html.formadmin.class.php index 0c8773efd74..15a0d4b6d42 100644 --- a/htdocs/core/class/html.formadmin.class.php +++ b/htdocs/core/class/html.formadmin.class.php @@ -363,8 +363,6 @@ class FormAdmin public function select_timezone($selected, $htmlname) { // phpcs:enable - global $langs, $conf; - print ''; + foreach ($type2label as $key => $val) { + $selected = ''; + if ($key == $type) { + $selected = ' selected="selected"'; + } + + // Set $valhtml with the picto for the type + $valhtml = ($key ? getPictoForType($key) : '').$val; + + if (empty($typewecanchangeinto) || in_array($key, $typewecanchangeinto[$type])) { + $out .= ''; + } else { + $out .= ''; + } + } + $out .= ''; + $out .= ajax_combobox('type'); + + return $out; + } } diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index 3950427a9df..62cd566cddd 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -337,7 +337,14 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = ' $type = 'double'; // html modulebuilder type is a text type in database } elseif (in_array($type, array('link', 'sellist', 'duration'))) { $type = 'integer'; + } elseif ($type == 'mail') { + $type = 'varchar(128)'; + } elseif ($type == 'phone') { + $type = 'varchar(20)'; + } elseif ($type == 'ip') { + $type = 'varchar(32)'; } + $texttoinsert .= "\t".$key." ".$type; if ($key == 'rowid') { $texttoinsert .= ' AUTO_INCREMENT PRIMARY KEY'; diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index f95c9ccf34c..2b8e6bc5793 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -974,7 +974,7 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it $sql = "SELECT tms FROM ".MAIN_DB_PREFIX."const"; $sql .= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'"; - $sql .= " AND entity IN (0, ".$conf->entity.")"; + $sql .= " AND entity IN (0, ".((int) $conf->entity).")"; dol_syslog(get_class($this)."::getLastActiveDate", LOG_DEBUG); $resql = $this->db->query($sql); diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php index 7930551e376..4fb742d07fd 100644 --- a/htdocs/core/tpl/admin_extrafields_add.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php @@ -158,20 +158,12 @@ $listofexamplesforlink = 'Societe:societe/class/societe.class.php
Contact:con trans("Type"); ?> '; -foreach ($type2label as $key => $val) { - $selected = ''; - if ($key == GETPOST('type', 'alpha')) { - $selected = ' selected="selected"'; - } - - // Set $valhtml with the picto for the type - $valhtml = ($key ? getPictoForType($key) : '').$val; - - print ''; +// Combo with list of fields +if (empty($formadmin)) { + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; + $formadmin = new FormAdmin($db); } -print ''; -print ajax_combobox('type'); +print $formadmin->selectTypeOfFields('type', GETPOST('type', 'alpha')); ?> diff --git a/htdocs/core/tpl/admin_extrafields_edit.tpl.php b/htdocs/core/tpl/admin_extrafields_edit.tpl.php index d94d58a1659..bf9fa2a840c 100644 --- a/htdocs/core/tpl/admin_extrafields_edit.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_edit.tpl.php @@ -216,24 +216,12 @@ if ($size <= 255 && in_array($type, array('text', 'html'))) { }*/ if (in_array($type, array_keys($typewecanchangeinto))) { - print ''; - print ajax_combobox('type'); + print $formadmin->selectTypeOfFields('type', GETPOST('type', 'alpha') ? GETPOST('type', 'alpha') : $type, $typewecanchangeinto); } else { print getPictoForType($type).$type2label[$type]; print ''; diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index 710eb671af5..bed3def3c38 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -149,7 +149,7 @@ CSSListClass=CSS for list NotEditable=Not editable ForeignKey=Foreign key ForeignKeyDesc=If the value of this field must be guaranted to exists into another table. Enter here a value matching syntax: tablename.parentfieldtocheck -TypeOfFieldsHelp=Example:
varchar(99), double(24,8), real, text, html, datetime, timestamp, integer, integer:ClassName:relativepath/to/classfile.class.php[:1[:filter]]

'1' means we add a + button after the combo to create the record
'filter' is an Universal Filter syntax condition, example: '((status:=:1) AND (fk_user:=:__USER_ID__) AND (entity:IN:(__SHARED_ENTITIES__))' +TypeOfFieldsHelp=Example:
varchar(99)
email
phone
ip
url
password
double(24,8)
real
text
html
date
datetime
timestamp
integer
integer:ClassName:relativepath/to/classfile.class.php[:1[:filter]]

'1' means we add a + button after the combo to create the record
'filter' is an Universal Filter syntax condition, example: '((status:=:1) AND (fk_user:=:__USER_ID__) AND (entity:IN:(__SHARED_ENTITIES__))' TypeOfFieldsHelpIntro=This is the type of the field/attribute. AsciiToHtmlConverter=Ascii to HTML converter AsciiToPdfConverter=Ascii to PDF converter diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 9ee777a0191..564654b1c42 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -350,21 +350,9 @@ if ($dirins && $action == 'initmodule' && $modulename) { '500000'=>$idmodule ); - if (!empty($conf->global->MODULEBUILDER_SPECIFIC_EDITOR_NAME)) { - $arrayreplacement['Editor name'] = $conf->global->MODULEBUILDER_SPECIFIC_EDITOR_NAME; - } - if (!empty($conf->global->MODULEBUILDER_SPECIFIC_EDITOR_URL)) { - $arrayreplacement['https://www.example.com'] = $conf->global->MODULEBUILDER_SPECIFIC_EDITOR_URL; - } if (!empty($conf->global->MODULEBUILDER_SPECIFIC_AUTHOR)) { $arrayreplacement['---Put here your own copyright and developer email---'] = dol_print_date($now, '%Y').' '.$conf->global->MODULEBUILDER_SPECIFIC_AUTHOR; } - if (!empty($conf->global->MODULEBUILDER_SPECIFIC_VERSION)) { - $arrayreplacement['1.0'] = $conf->global->MODULEBUILDER_SPECIFIC_VERSION; - } - if (!empty($conf->global->MODULEBUILDER_SPECIFIC_FAMILY)) { - $arrayreplacement['modulefamily'] = $conf->global->MODULEBUILDER_SPECIFIC_FAMILY; - } $result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement); //var_dump($result); @@ -1031,7 +1019,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname) { 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', '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', 'mail', '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 @@ -1521,21 +1509,9 @@ if ($dirins && $action == 'initobject' && $module && $objectname) { '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '') ); - if (!empty($conf->global->MODULEBUILDER_SPECIFIC_EDITOR_NAME)) { - $arrayreplacement['Editor name'] = $conf->global->MODULEBUILDER_SPECIFIC_EDITOR_NAME; - } - if (!empty($conf->global->MODULEBUILDER_SPECIFIC_EDITOR_URL)) { - $arrayreplacement['https://www.example.com'] = $conf->global->MODULEBUILDER_SPECIFIC_EDITOR_URL; - } if (!empty($conf->global->MODULEBUILDER_SPECIFIC_AUTHOR)) { $arrayreplacement['---Put here your own copyright and developer email---'] = dol_print_date($now, '%Y').' '.$conf->global->MODULEBUILDER_SPECIFIC_AUTHOR; } - if (!empty($conf->global->MODULEBUILDER_SPECIFIC_VERSION)) { - $arrayreplacement['1.0'] = $conf->global->MODULEBUILDER_SPECIFIC_VERSION; - } - if (!empty($conf->global->MODULEBUILDER_SPECIFIC_FAMILY)) { - $arrayreplacement['other'] = $conf->global->MODULEBUILDER_SPECIFIC_FAMILY; - } $result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement); //var_dump($result); @@ -3884,7 +3860,34 @@ if ($module == 'initmodule') { if ($key == 'propname' || $key == 'proplabel') { print ''.$attribute.''; } elseif ($key == 'proptype') { - print ''.$attribute.'
'; + print ''.$attribute.''; + print ''; + //print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + // Combo with list of fields + /* + if (empty($formadmin)) { + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; + $formadmin = new FormAdmin($db); + } + print $formadmin->selectTypeOfFields($key, GETPOST($key, 'alpha')); + */ + print ''; + print ''; //} elseif ($key == 'propvalidate') { // print ''.$attribute.''; } elseif ($key == 'propvisible') { @@ -3923,70 +3926,12 @@ if ($module == 'initmodule') { window.location.href = url; } $(document).ready(function() { - // Tableau de suggestions statiques - var suggestions = ["VARCHAR", "DOUBLE", "REAL", "TEXT", "HTML", "DATETIME", "TIMESTAMP", "INTEGER", "INTEGER:CLASSNAME:RELATIVEPATH/TO/CLASSFILE.CLASS.PHP[:1[:FILTER]]"]; - - function showSuggestions() { - var inputText = $("#proptype").val().toLowerCase(); - var suggestionsDiv = $("#suggestions"); - - var filteredSuggestions = suggestions.filter(function(suggestion) { - return suggestion.toLowerCase().indexOf(inputText) !== -1; - }); - - //get suggestion on div - suggestionsDiv.empty(); - for (var i = 0; i < filteredSuggestions.length; i++) { - var suggestion = filteredSuggestions[i]; - var suggestionItem = $("
").text(suggestion).css({ cursor: "pointer", padding: "5px" }); - suggestionsDiv.append(suggestionItem); - } - - - if (inputText === "" || filteredSuggestions.length === 0) { - suggestionsDiv.hide(); - } else { - suggestionsDiv.show(); - } - } - - $("#proptype").on("input", showSuggestions); - - $("#suggestions").on("click", "div", function() { - var selectedValue = $(this).text(); - $("#proptype").val(selectedValue); - $("#suggestions").hide(); - }); - // when we click outside the input - $(document).on("click", function(event) { - if (!$(event.target).closest("#proptype, #suggestions").length) { - $("#suggestions").hide(); - } - }); - // when we delete the content input - $("#proptype").on("keyup", function() { - if ($(this).val() === "") { - $("#suggestions").hide(); - } - }); - $("#proplabel").on("keyup", function() { console.log("key up on label"); s = cleanString($("#proplabel").val()); $("#propname").val(s); }); - // when hover in suggestion - $("#suggestions").on("mouseenter", "div", function() { - console.log("enter suggestion"); - $(this).css("background-color", "#e0e0e0"); - }); - - $("#suggestions").on("mouseleave", "div", function() { - console.log("leave suggestion"); - $(this).css("background-color", "#fff"); - }); - function cleanString( stringtoclean ) { // allow "a-z", "A-Z", "0-9" and "_" @@ -4001,7 +3946,7 @@ if ($module == 'initmodule') { if (stringtoclean.length > 28) { stringtoclean = stringtoclean.substring(0, 27); } - return stringtoclean + return stringtoclean; } });';