diff --git a/htdocs/core/admin_extrafields.inc.php b/htdocs/core/admin_extrafields.inc.php
index 29c71f9ba45..975fa94d308 100644
--- a/htdocs/core/admin_extrafields.inc.php
+++ b/htdocs/core/admin_extrafields.inc.php
@@ -59,7 +59,7 @@ if ($action == 'add')
$mesg=$langs->trans("ErrorSizeTooLongForIntType",$maxsizeint);
$action = 'create';
}
- if (GETPOST('type')=='select' && !GETPOST('extra_value'))
+ if (GETPOST('type')=='select' && !GETPOST('param'))
{
$error++;
$langs->load("errors");
@@ -73,7 +73,7 @@ if ($action == 'add')
if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname']))
{
// Construct array for parameter (value of select list)
- $parameters = GETPOST('extra_value');
+ $parameters = GETPOST('param');
$parameters_array = explode("\r\n",$parameters);
foreach($parameters_array as $param_ligne)
{
@@ -136,7 +136,16 @@ if ($action == 'update')
{
if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname']))
{
- $result=$extrafields->update($_POST['attrname'],$_POST['label'],$_POST['type'],$extrasize,$elementtype,(GETPOST('unique')?1:0),(GETPOST('required')?1:0));
+ $pos = GETPOST('pos','int');
+ // Construct array for parameter (value of select list)
+ $parameters = GETPOST('param');
+ $parameters_array = explode("\r\n",$parameters);
+ foreach($parameters_array as $param_ligne)
+ {
+ list($key,$value) = explode(',',$param_ligne);
+ $params['options'][$key] = $value;
+ }
+ $result=$extrafields->update($_POST['attrname'],$_POST['label'],$_POST['type'],$extrasize,$elementtype,(GETPOST('unique')?1:0),(GETPOST('required')?1:0),$pos,$params);
if ($result > 0)
{
header("Location: ".$_SERVER["PHP_SELF"]);
diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php
index 0fd57fed96d..4f583a667f9 100755
--- a/htdocs/core/class/extrafields.class.php
+++ b/htdocs/core/class/extrafields.class.php
@@ -207,7 +207,7 @@ class ExtraFields
* @param string $elementtype Element type ('member', 'product', 'company', ...)
* @param int $unique Is field unique or not
* @param int $required Is field required or not
- * @param array $param Params for field (ex for select list : array('value'=>'label of option') )
+ * @param array $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) )
* @return int <=0 if KO, >0 if OK
*/
private function create_label($attrname, $label='', $type='', $pos=0, $size=0, $elementtype='member', $unique=0, $required=0,$param)
@@ -343,9 +343,11 @@ class ExtraFields
* @param string $elementtype Element type ('member', 'product', 'company', 'contact', ...)
* @param int $unique Is field unique or not
* @param int $required Is field required or not
+ * @param int $pos Position of attribute
+ * @param array $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) )
* @return int >0 if OK, <=0 if KO
*/
- function update($attrname,$label,$type,$length,$elementtype,$unique=0,$required=0)
+ function update($attrname,$label,$type,$length,$elementtype,$unique=0,$required=0,$pos,$param='')
{
$table=$elementtype.'_extrafields';
@@ -368,6 +370,9 @@ class ExtraFields
}elseif($type=='mail') {
$typedb='varchar';
$lengthdb='128';
+ } elseif ($type=='select') {
+ $typedb='text';
+ $lengthdb='';
} else {
$typedb=$type;
$lengthdb=$length;
@@ -378,7 +383,7 @@ class ExtraFields
{
if ($label)
{
- $result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required);
+ $result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param);
}
if ($result > 0)
{
@@ -424,9 +429,11 @@ class ExtraFields
* @param string $elementtype Element type ('member', 'product', 'company', ...)
* @param int $unique Is field unique or not
* @param int $required Is field required or not
+ * @param int $pos Position of attribute
+ * @param array $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) )
* @return int <=0 if KO, >0 if OK
*/
- private function update_label($attrname,$label,$type,$size,$elementtype,$unique=0,$required=0)
+ private function update_label($attrname,$label,$type,$size,$elementtype,$unique=0,$required=0,$pos=0,$param='')
{
global $conf;
dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required);
@@ -434,7 +441,12 @@ class ExtraFields
if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname))
{
$this->db->begin();
-
+
+ if(is_array($param) && count($param) > 0)
+ {
+ $param = serialize($param);
+ }
+
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields";
$sql_del.= " WHERE name = '".$attrname."'";
$sql_del.= " AND entity = ".$conf->entity;
@@ -450,7 +462,9 @@ class ExtraFields
$sql.= " size,";
$sql.= " elementtype,";
$sql.= " fieldunique,";
- $sql.= " fieldrequired";
+ $sql.= " fieldrequired,";
+ $sql.= " pos,";
+ $sql.= " param";
$sql.= ") VALUES (";
$sql.= "'".$attrname."',";
$sql.= " ".$conf->entity.",";
@@ -459,7 +473,9 @@ class ExtraFields
$sql.= " '".$size."',";
$sql.= " '".$elementtype."',";
$sql.= " '".$unique."',";
- $sql.= " '".$required."'";
+ $sql.= " '".$required."',";
+ $sql.= " '".$pos."',";
+ $sql.= " '".$param."'";
$sql.= ")";
dol_syslog(get_class($this)."::update_label sql=".$sql);
$resql2=$this->db->query($sql);
@@ -512,7 +528,7 @@ class ExtraFields
if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))
return $array_name_label;
- $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param";
+ $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos";
$sql.= " FROM ".MAIN_DB_PREFIX."extrafields";
$sql.= " WHERE entity = ".$conf->entity;
if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'";
@@ -535,6 +551,7 @@ class ExtraFields
$this->attribute_unique[$tab->name]=$tab->fieldunique;
$this->attribute_required[$tab->name]=$tab->fieldrequired;
$this->attribute_param[$tab->name]=unserialize($tab->param);
+ $this->attribute_pos[$tab->name]=$tab->pos;
}
}
return $array_name_label;
diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php
index 0af2b782912..d4f5cf9ae40 100644
--- a/htdocs/core/tpl/admin_extrafields_add.tpl.php
+++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php
@@ -55,7 +55,8 @@