Work on extrafields : position management & new type : select list
This commit is contained in:
parent
14f21bc9f1
commit
3d8197ce4b
@ -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"]);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -55,7 +55,8 @@
|
||||
<input type="hidden" name="action" value="add">
|
||||
|
||||
<table summary="listofattributes" class="border centpercent">
|
||||
|
||||
<!-- Position -->
|
||||
<tr><td class="fieldrequired"><?php echo $langs->trans("Position"); ?></td><td class="valeur"><input type="text" name="pos" size="5" value="<?php echo GETPOST('pos'); ?>"></td></tr>
|
||||
<!-- Label -->
|
||||
<tr><td class="fieldrequired"><?php echo $langs->trans("Label"); ?></td><td class="valeur"><input type="text" name="label" size="40" value="<?php echo GETPOST('label'); ?>"></td></tr>
|
||||
<!-- Code -->
|
||||
@ -70,7 +71,7 @@
|
||||
<?php echo $langs->trans("Value"); ?>
|
||||
</td>
|
||||
<td>
|
||||
<textarea name="extra_value" id="extra_value"><?php echo GETPOST('extra_value'); ?></textarea>
|
||||
<textarea name="param" id="param"><?php echo GETPOST('param'); ?></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- Default Value -->
|
||||
|
||||
@ -47,21 +47,53 @@
|
||||
|
||||
<table summary="listofattributes" class="border centpercent">
|
||||
|
||||
<!-- Label -->
|
||||
<tr><td class="fieldrequired"><?php echo $langs->trans("Label"); ?></td><td class="valeur"><input type="text" name="label" size="40" value="<?php echo $extrafields->attribute_label[$attrname]; ?>"></td></tr>
|
||||
<!-- Code -->
|
||||
<tr><td class="fieldrequired"><?php echo $langs->trans("AttributeCode"); ?></td><td class="valeur"><?php echo $attrname; ?></td></tr>
|
||||
<!-- Type -->
|
||||
<?php
|
||||
$type=$extrafields->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";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!-- Position -->
|
||||
<tr><td class="fieldrequired"><?php echo $langs->trans("Position"); ?></td><td class="valeur"><input type="text" name="pos" size="5" value="<?php echo $extrafields->attribute_pos[$attrname]; ?>"></td></tr>
|
||||
<!-- Label -->
|
||||
<tr><td class="fieldrequired"><?php echo $langs->trans("Label"); ?></td><td class="valeur"><input type="text" name="label" size="40" value="<?php echo $extrafields->attribute_label[$attrname]; ?>"></td></tr>
|
||||
<!-- Code -->
|
||||
<tr><td class="fieldrequired"><?php echo $langs->trans("AttributeCode"); ?></td><td class="valeur"><?php echo $attrname; ?></td></tr>
|
||||
<!-- Type -->
|
||||
<tr><td class="fieldrequired"><?php echo $langs->trans("Type"); ?></td><td class="valeur">
|
||||
<?php print $type2label[$type]; ?>
|
||||
<input type="hidden" name="type" id="type" value="<?php print $type; ?>">
|
||||
</td></tr>
|
||||
<!-- Value (for select list / radio) -->
|
||||
<?php
|
||||
if($type == 'select')
|
||||
{
|
||||
?>
|
||||
<tr id="value_choice">
|
||||
<td>
|
||||
<?php echo $langs->trans("Value"); ?>
|
||||
</td>
|
||||
<td>
|
||||
<textarea name="param" id="param"><?php echo $param_chain; ?></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<!-- Size -->
|
||||
<tr><td class="fieldrequired"><?php echo $langs->trans("Size"); ?></td><td><input id="size" type="text" name="size" size="5" value="<?php echo $size; ?>"></td></tr>
|
||||
<!-- Unique -->
|
||||
|
||||
@ -84,6 +84,7 @@ $extrafields->fetch_name_optionals_label($elementtype);
|
||||
print "<table summary=\"listofattributes\" class=\"noborder\" width=\"100%\">";
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td align="center">'.$langs->trans("Position").'</td>';
|
||||
print '<td>'.$langs->trans("Label").'</td>';
|
||||
print '<td>'.$langs->trans("AttributeCode").'</td>';
|
||||
print '<td>'.$langs->trans("Type").'</td>';
|
||||
@ -98,6 +99,7 @@ foreach($extrafields->attribute_type as $key => $value)
|
||||
{
|
||||
$var=!$var;
|
||||
print "<tr ".$bc[$var].">";
|
||||
print "<td>".$extrafields->attribute_pos[$key]."</td>\n";
|
||||
print "<td>".$extrafields->attribute_label[$key]."</td>\n";
|
||||
print "<td>".$key."</td>\n";
|
||||
print "<td>".$type2label[$extrafields->attribute_type[$key]]."</td>\n";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user