diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index ae4ada04f3b..49a8ab4df8f 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -5767,7 +5767,7 @@ function dol_concatdesc($text1,$text2,$forxml=false, $invert=false)
$text1 = $text2;
$text2 = $tmp;
}
-
+
$ret='';
$ret.= (! dol_textishtml($text1) && dol_textishtml($text2))?dol_nl2br($text1, 0, $forxml):$text1;
$ret.= (! empty($text1) && ! empty($text2)) ? ((dol_textishtml($text1) || dol_textishtml($text2))?($forxml?"
\n":"
\n") : "\n") : "";
@@ -7163,7 +7163,7 @@ function printCommonFooter($zone='private')
if ($zone == 'private' && empty($conf->dol_use_jmobile))
{
print "\n";
- print '/* JS CODE TO ENABLE to enable handler to switch left menu page (menuhider) */'."\n";
+ print '/* JS CODE TO ENABLE to manage handler to switch left menu page (menuhider) */'."\n";
print 'jQuery(".menuhider").click(function() {';
print ' console.log("We click on .menuhider");'."\n";
//print " $('.side-nav').animate({width:'toggle'},200);\n"; // OK with eldy theme but not with md
@@ -7173,9 +7173,9 @@ function printCommonFooter($zone='private')
}
// Management of focus and mandatory for fields
- if ($action == 'create' || $action == 'edit')
+ if ($action == 'create' || $action == 'edit' || (empty($action) && (preg_match('/new\.php/', $_SERVER["PHP_SELF"]))))
{
- print '/* Code js to manage focus and mandatory form fields */'."\n";
+ print '/* JS CODE TO ENABLE to manage focus and mandatory form fields */'."\n";
$relativepathstring = $_SERVER["PHP_SELF"];
// Clean $relativepathstring
if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'),'/').'/', '', $relativepathstring);
@@ -7204,8 +7204,10 @@ function printCommonFooter($zone='private')
{
foreach($defval as $paramkey => $paramval)
{
- // Add property 'required' on input
+ // Set focus on field
print 'jQuery("input[name=\''.$paramkey.'\']").focus();'."\n";
+ print 'jQuery("textarea[name=\''.$paramkey.'\']").focus();'."\n";
+ print 'jQuery("select[name=\''.$paramkey.'\']").focus();'."\n"; // Not really usefull, but we keep it in case of.
}
}
}
@@ -7234,6 +7236,7 @@ function printCommonFooter($zone='private')
{
// Add property 'required' on input
print 'jQuery("input[name=\''.$paramkey.'\']").prop(\'required\',true);'."\n";
+ print 'jQuery("textarea[name=\''.$paramkey.'\']").prop(\'required\',true);'."\n";
print 'jQuery("select[name=\''.$paramkey.'\']").prop(\'required\',true);'."\n"; // required on a select works only if key is "", this does not happen in Dolibarr
}
}
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index 3e430c9a4a5..c8f9eea87d9 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -1821,7 +1821,7 @@ SocialNetworkSetup=Setup of module Social Networks
EnableFeatureFor=Enable features for %s
VATIsUsedIsOff=Note: The option to use Sales Tax or VAT has been set to Off in the menu %s - %s, so Sales tax or Vat used will always be 0 for sales.
SwapSenderAndRecipientOnPDF=Swap sender and recipient address on PDF
-FeatureSupportedOnTextFieldsOnly=Warning, feature supported on text fields only
+FeatureSupportedOnTextFieldsOnly=Warning, feature supported on text fields only. Also an URL parameter action=create or action=edit' must be set OR page name must end with 'new.php' to trigger this feature.
EmailCollector=Email collector
EmailCollectorDescription=Add a scheduled job and a setup page to scan regularly email boxes (using IMAP protocol) and record emails received into your application, at the right place and/or create some records automatically (like leads).
NewEmailCollector=New Email Collector
diff --git a/htdocs/public/members/new.php b/htdocs/public/members/new.php
index b78534bf4b0..79485ee9820 100644
--- a/htdocs/public/members/new.php
+++ b/htdocs/public/members/new.php
@@ -77,6 +77,8 @@ $extrafields = new ExtraFields($db);
$object = new Adherent($db);
+$user->loadDefaultValues();
+
/**
* Show header for new member
diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php
index 6c0ff6e4915..4aaaff7ed21 100644
--- a/htdocs/user/class/user.class.php
+++ b/htdocs/user/class/user.class.php
@@ -422,45 +422,9 @@ class User extends CommonObject
return -2;
}
- // Load user->default_values for user. TODO Save this in memcached ?
- $sql = "SELECT rowid, entity, type, page, param, value";
- $sql.= " FROM ".MAIN_DB_PREFIX."default_values";
- $sql.= " WHERE entity IN (".$this->entity.",".$conf->entity.")";
- $sql.= " AND user_id IN (0, ".$this->id.")";
- $resql = $this->db->query($sql);
- if ($resql)
- {
- while ($obj = $this->db->fetch_object($resql))
- {
- if (! empty($obj->page) && ! empty($obj->type) && ! empty($obj->param))
- {
- // $obj->page is relative URL with or without params
- // $obj->type can be 'filters', 'sortorder', 'createform', ...
- // $obj->param is key or param
- $pagewithoutquerystring=$obj->page;
- $pagequeries='';
- if (preg_match('/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) // There is query param
- {
- $pagewithoutquerystring=$reg[1];
- $pagequeries=$reg[2];
- }
- $this->default_values[$pagewithoutquerystring][$obj->type][$pagequeries?$pagequeries:'_noquery_'][$obj->param]=$obj->value;
- //if ($pagequeries) $this->default_values[$pagewithoutquerystring][$obj->type.'_queries']=$pagequeries;
- }
- }
- // Sort by key, so _noquery_ is last
- if(!empty($this->default_values)) {
- foreach($this->default_values as $a => $b)
- {
- foreach($b as $c => $d)
- {
- krsort($this->default_values[$a][$c]);
- }
- }
- }
- $this->db->free($resql);
- }
- else
+ $result = $this->loadDefaultValues();
+
+ if ($result < 0)
{
$this->error=$this->db->lasterror();
return -3;
@@ -470,6 +434,62 @@ class User extends CommonObject
return 1;
}
+ /**
+ * Load default value in property ->default_values
+ *
+ * @return int > 0 if OK, < 0 if KO
+ */
+ function loadDefaultValues()
+ {
+ global $conf;
+
+ // Load user->default_values for user. TODO Save this in memcached ?
+ $sql = "SELECT rowid, entity, type, page, param, value";
+ $sql.= " FROM ".MAIN_DB_PREFIX."default_values";
+ $sql.= " WHERE entity IN (".($this->entity > 0 ? $this->entity.", " : "").$conf->entity.")"; // Entity of user (if defined) + current entity
+ $sql.= " AND user_id IN (0".($this->id > 0 ? ", ".$this->id : "").")"; // User 0 (all) + me (if defined)
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ while ($obj = $this->db->fetch_object($resql))
+ {
+ if (! empty($obj->page) && ! empty($obj->type) && ! empty($obj->param))
+ {
+ // $obj->page is relative URL with or without params
+ // $obj->type can be 'filters', 'sortorder', 'createform', ...
+ // $obj->param is key or param
+ $pagewithoutquerystring=$obj->page;
+ $pagequeries='';
+ if (preg_match('/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) // There is query param
+ {
+ $pagewithoutquerystring=$reg[1];
+ $pagequeries=$reg[2];
+ }
+ $this->default_values[$pagewithoutquerystring][$obj->type][$pagequeries?$pagequeries:'_noquery_'][$obj->param]=$obj->value;
+ //if ($pagequeries) $this->default_values[$pagewithoutquerystring][$obj->type.'_queries']=$pagequeries;
+ }
+ }
+ // Sort by key, so _noquery_ is last
+ if(!empty($this->default_values)) {
+ foreach($this->default_values as $a => $b)
+ {
+ foreach($b as $c => $d)
+ {
+ krsort($this->default_values[$a][$c]);
+ }
+ }
+ }
+ $this->db->free($resql);
+
+ return 1;
+ }
+ else
+ {
+ dol_print_error($this->db);
+ return -1;
+ }
+ }
+
/**
* Add a right to the user
*