From 3d8197ce4be0d36ee7de7a5dc11fe9c7ac0db1cf Mon Sep 17 00:00:00 2001 From: jfefe Date: Fri, 15 Feb 2013 11:19:49 +0100 Subject: [PATCH] Work on extrafields : position management & new type : select list --- htdocs/core/admin_extrafields.inc.php | 15 +++++-- htdocs/core/class/extrafields.class.php | 33 +++++++++++---- htdocs/core/tpl/admin_extrafields_add.tpl.php | 5 ++- .../core/tpl/admin_extrafields_edit.tpl.php | 42 ++++++++++++++++--- htdocs/societe/admin/societe_extrafields.php | 2 + 5 files changed, 79 insertions(+), 18 deletions(-) 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 @@ - + + @@ -70,7 +71,7 @@ trans("Value"); ?> diff --git a/htdocs/core/tpl/admin_extrafields_edit.tpl.php b/htdocs/core/tpl/admin_extrafields_edit.tpl.php index 8eed3b96c37..c2112b636f2 100644 --- a/htdocs/core/tpl/admin_extrafields_edit.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_edit.tpl.php @@ -47,21 +47,53 @@
trans("Position"); ?>
trans("Label"); ?>
- +
- - - - -attribute_type[$attrname]; $size=$extrafields->attribute_size[$attrname]; $unique=$extrafields->attribute_unique[$attrname]; $required=$extrafields->attribute_required[$attrname]; +$pos=$extrafields->attribute_pos[$attrname]; +$param=$extrafields->attribute_param[$attrname]; + +if($type == 'select' && is_array($param)) +{ + $param_chain = ''; + foreach ($param['options'] as $key => $value) + { + if(strlen($key)) + { + $param_chain .= $key.', '.$value."\n"; + } + } +} ?> + + + + + + + + + + + + + + diff --git a/htdocs/societe/admin/societe_extrafields.php b/htdocs/societe/admin/societe_extrafields.php index cbac832ee3b..66957c0314a 100755 --- a/htdocs/societe/admin/societe_extrafields.php +++ b/htdocs/societe/admin/societe_extrafields.php @@ -84,6 +84,7 @@ $extrafields->fetch_name_optionals_label($elementtype); print "
trans("Label"); ?>
trans("AttributeCode"); ?>
trans("Position"); ?>
trans("Label"); ?>
trans("AttributeCode"); ?>
trans("Type"); ?>
+ trans("Value"); ?> + + +
trans("Size"); ?>
"; print ''; +print ''; print ''; print ''; print ''; @@ -98,6 +99,7 @@ foreach($extrafields->attribute_type as $key => $value) { $var=!$var; print ""; + print "\n"; print "\n"; print "\n"; print "\n";
'.$langs->trans("Position").''.$langs->trans("Label").''.$langs->trans("AttributeCode").''.$langs->trans("Type").'
".$extrafields->attribute_pos[$key]."".$extrafields->attribute_label[$key]."".$key."".$type2label[$extrafields->attribute_type[$key]]."