diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php
index 0040f1e3184..e25809559d2 100644
--- a/htdocs/core/class/extrafields.class.php
+++ b/htdocs/core/class/extrafields.class.php
@@ -528,7 +528,7 @@ class ExtraFields
$typedb=$type;
$lengthdb=$length;
}
- $field_desc = array('type'=>$typedb, 'value'=>$lengthdb, 'null'=>($required?'NOT NULL':'NULL'));
+ $field_desc = array('type'=>$typedb, 'value'=>$lengthdb, 'null'=>($required?'NOT NULL':'NULL'), 'default'=>$default);
if ($type != 'separate') // No table update when separate type
{
diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php
index 4358e8695fe..14256b37d29 100644
--- a/htdocs/core/db/mysqli.class.php
+++ b/htdocs/core/db/mysqli.class.php
@@ -779,7 +779,28 @@ class DoliDBMysqli extends DoliDB
if ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') {
$sql.="(".$field_desc['value'].")";
}
- if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL') $sql.=" NOT NULL";
+ if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL')
+ {
+ // We will try to change format of column to NOT NULL. To be sure the ALTER works, we try to update fields that are NULL
+ if ($field_desc['type'] == 'varchar' || $field_desc['type'] == 'text')
+ {
+ $sqlbis="UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL";
+ $this->query($sqlbis);
+ }
+ elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int')
+ {
+ $sqlbis="UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL";
+ $this->query($sqlbis);
+ }
+
+ $sql.=" NOT NULL";
+ }
+
+ if ($field_desc['default'])
+ {
+ if ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']);
+ elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields
+ }
dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG);
if (! $this->query($sql))
diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php
index d02ff4a1341..0448789fc50 100644
--- a/htdocs/core/db/pgsql.class.php
+++ b/htdocs/core/db/pgsql.class.php
@@ -1088,8 +1088,26 @@ class DoliDBPgsql extends DoliDB
$sql.="(".$field_desc['value'].")";
}
- // TODO May not work with pgsql. May need to run a second request. If it works, just remove the comment
- if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL') $sql.=" NOT NULL";
+ if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL')
+ {
+ // We will try to change format of column to NOT NULL. To be sure the ALTER works, we try to update fields that are NULL
+ if ($field_desc['type'] == 'varchar' || $field_desc['type'] == 'text')
+ {
+ $sqlbis="UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL";
+ $this->query($sqlbis);
+ }
+ elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int')
+ {
+ $sqlbis="UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL";
+ $this->query($sqlbis);
+ }
+ }
+
+ if ($field_desc['default'])
+ {
+ if ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']);
+ elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields
+ }
dol_syslog($sql,LOG_DEBUG);
if (! $this->query($sql))
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index da6cbc6c15c..9b643efa086 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -345,8 +345,20 @@ function GETPOST($paramname, $check='', $method=0, $filter=NULL, $options=NULL)
}
elseif (isset($user->default_values[$relativepathstring]['filters'][$paramname]))
{
- $forbidden_chars_to_replace=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",";","="); // we accept _, -, . and ,
- $out = dol_string_nospecial($user->default_values[$relativepathstring]['filters'][$paramname], '', $forbidden_chars_to_replace);
+ if (isset($_POST['sall']) || isset($_POST['search_all']) || isset($_GET['sall']) || isset($_GET['search_all']))
+ {
+ // We made a search from quick search menu, do we still use default filter ?
+ if (empty($conf->global->MAIN_DISABLE_DEFAULT_FILTER_FOR_QUICK_SEARCH))
+ {
+ $forbidden_chars_to_replace=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",";","="); // we accept _, -, . and ,
+ $out = dol_string_nospecial($user->default_values[$relativepathstring]['filters'][$paramname], '', $forbidden_chars_to_replace);
+ }
+ }
+ else
+ {
+ $forbidden_chars_to_replace=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",";","="); // we accept _, -, . and ,
+ $out = dol_string_nospecial($user->default_values[$relativepathstring]['filters'][$paramname], '', $forbidden_chars_to_replace);
+ }
}
}
}
diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php
index a7f98bdba72..6c5f563e106 100644
--- a/htdocs/core/tpl/admin_extrafields_add.tpl.php
+++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php
@@ -42,12 +42,12 @@
var alwayseditable = jQuery("#alwayseditable");
var list = jQuery("#list");
');
+ init_typeoffields('');
jQuery("#type").change(function() {
init_typeoffields($(this).val());
});
@@ -130,15 +130,15 @@
-| trans("Label"); ?> | |
+| trans("Label"); ?> | |
-| trans("AttributeCode"); ?> | (trans("AlphaNumOnlyLowerCharsAndNoSpace"); ?>) |
+| trans("AttributeCode"); ?> | (trans("AlphaNumOnlyLowerCharsAndNoSpace"); ?>) |
| trans("Type"); ?> |
-selectarray('type',$type2label,GETPOST('type')); ?>
+selectarray('type',$type2label,GETPOST('type','alpha')); ?>
|
-
+
|
@@ -147,7 +147,7 @@
|
diff --git a/htdocs/core/tpl/admin_extrafields_edit.tpl.php b/htdocs/core/tpl/admin_extrafields_edit.tpl.php
index beb1e34055e..85cfe510df8 100644
--- a/htdocs/core/tpl/admin_extrafields_edit.tpl.php
+++ b/htdocs/core/tpl/admin_extrafields_edit.tpl.php
@@ -41,12 +41,12 @@
var alwayseditable = jQuery("#alwayseditable");
var list = jQuery("#list");
$val)
{
$selected='';
- if ($key == (GETPOST('type')?GETPOST('type'):$type)) $selected=' selected="selected"';
+ if ($key == (GETPOST('type','alpha')?GETPOST('type','alpha'):$type)) $selected=' selected="selected"';
if (in_array($key, $typewecanchangeinto[$type])) print '';
else print '';
}
@@ -222,8 +222,8 @@ else
|
| trans("LanguageFile"); ?> | |
-
-
+
+
diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php
index 00b463f647a..bc62e71dd04 100644
--- a/htdocs/societe/card.php
+++ b/htdocs/societe/card.php
@@ -701,6 +701,10 @@ if (empty($reshook))
}
}
}
+ else
+ {
+ $action='create';
+ }
}
// Delete third party