New: Member module use generic extrafields feature.
This commit is contained in:
parent
7a6c24399b
commit
412a01e146
@ -44,13 +44,9 @@ if ($_POST["action"] == 'add' && $user->rights->adherent->configurer)
|
|||||||
// Type et taille non encore pris en compte => varchar(255)
|
// Type et taille non encore pris en compte => varchar(255)
|
||||||
if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname']))
|
if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname']))
|
||||||
{
|
{
|
||||||
$result=$adho->create($_POST['attrname'],$_POST['type'],$_POST['size']);
|
$result=$adho->addExtraField($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['pos'],$_POST['size'],'member');
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
if (isset($_POST['label']))
|
|
||||||
{
|
|
||||||
$adho->create_label($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['pos'],$_POST['size']);
|
|
||||||
}
|
|
||||||
Header("Location: ".$_SERVER["PHP_SELF"]);
|
Header("Location: ".$_SERVER["PHP_SELF"]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,6 +59,34 @@ class ExtraFields
|
|||||||
$this->attribute_elementtype = array();
|
$this->attribute_elementtype = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new extra field parameter
|
||||||
|
* @param attrname code of attribute
|
||||||
|
* @param label label of attribute
|
||||||
|
* @param type Type of attribute ('int', 'text', 'varchar', 'date', 'datehour')
|
||||||
|
* @param pos Position of attribute
|
||||||
|
* @param size Size/length of attribute
|
||||||
|
* @param elementtype Element type ('member', 'product', 'company', ...)
|
||||||
|
* @return int <=0 if KO, >0 if OK
|
||||||
|
*/
|
||||||
|
function addExtraField($attrname,$label,$type='',$pos=0,$size=0, $elementtype='member')
|
||||||
|
{
|
||||||
|
if (empty($attrname)) return -1;
|
||||||
|
if (empty($label)) return -1;
|
||||||
|
|
||||||
|
$result=$this->create($attrname,$type,$size);
|
||||||
|
if ($result > 0)
|
||||||
|
{
|
||||||
|
$result2=$this->create_label($attrname,$label,$type,$pos,$size,$elementtype);
|
||||||
|
if ($result2 > 0) return 1;
|
||||||
|
else return -2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new optionnal attribute
|
* Add a new optionnal attribute
|
||||||
* @param attrname code of attribute
|
* @param attrname code of attribute
|
||||||
|
|||||||
@ -916,55 +916,64 @@ class DoliDb
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief decrit une table dans une database.
|
* Return a pointer on fields describing table
|
||||||
* \param table Nom de la table
|
* @param table Nom de la table
|
||||||
* \param field Optionnel : Nom du champ si l'on veut la desc d'un champ
|
* @param field Optionnel : Nom du champ si l'on veut la desc d'un champ
|
||||||
* \return resource
|
* @return resource
|
||||||
*/
|
*/
|
||||||
function DDLDescTable($table,$field="")
|
function DDLDescTable($table,$field="")
|
||||||
{
|
{
|
||||||
$sql="DESC ".$table." ".$field;
|
$sql="DESC ".$table." ".$field;
|
||||||
|
|
||||||
dol_syslog($sql,LOG_DEBUG);
|
dol_syslog(get_class($this)."::DDLDescTable ".$sql,LOG_DEBUG);
|
||||||
$this->results = $this->query($sql);
|
$this->results = $this->query($sql);
|
||||||
return $this->results;
|
return $this->results;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Insert a new field in table
|
* Insert a new field in table
|
||||||
* \param table Nom de la table
|
* @param table Table name
|
||||||
* \param field_name Nom du champ a inserer
|
* @param field_name Name of field
|
||||||
* \param field_desc Tableau associatif de description du champ a inserer[nom du parametre][valeur du parametre]
|
* @param field_desc Array with properties describing new field
|
||||||
* \param field_position Optionnel ex.: "after champtruc"
|
* @param field_position Optionnal ie.: "after fielddummy"
|
||||||
* \return int <0 si KO, >0 si OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function DDLAddField($table,$field_name,$field_desc,$field_position="")
|
function DDLAddField($table,$field_name,$field_desc,$field_position="")
|
||||||
{
|
{
|
||||||
// cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra
|
// cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra
|
||||||
// ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment');
|
// ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment');
|
||||||
$sql= "ALTER TABLE ".$table." ADD ".$field_name." ";
|
$sql= "ALTER TABLE ".$table." ADD ".$field_name." ";
|
||||||
$sql .= $field_desc['type'];
|
$sql.= $field_desc['type'];
|
||||||
if( preg_match("/^[^\s]/i",$field_desc['value']))
|
if(preg_match("/^[^\s]/i",$field_desc['value']))
|
||||||
$sql .= "(".$field_desc['value'].")";
|
if (! in_array($field_desc['type'],array('date','datetime')))
|
||||||
if( preg_match("/^[^\s]/i",$field_desc['attribute']))
|
{
|
||||||
$sql .= " ".$field_desc['attribute'];
|
$sql.= "(".$field_desc['value'].")";
|
||||||
if( preg_match("/^[^\s]/i",$field_desc['null']))
|
}
|
||||||
$sql .= " ".$field_desc['null'];
|
if(preg_match("/^[^\s]/i",$field_desc['attribute']))
|
||||||
if( preg_match("/^[^\s]/i",$field_desc['default']))
|
$sql.= " ".$field_desc['attribute'];
|
||||||
if(preg_match("/null/i",$field_desc['default']))
|
if(preg_match("/^[^\s]/i",$field_desc['null']))
|
||||||
$sql .= " default ".$field_desc['default'];
|
$sql.= " ".$field_desc['null'];
|
||||||
else
|
if(preg_match("/^[^\s]/i",$field_desc['default']))
|
||||||
$sql .= " default '".$field_desc['default']."'";
|
{
|
||||||
if( preg_match("/^[^\s]/i",$field_desc['extra']))
|
if(preg_match("/null/i",$field_desc['default']))
|
||||||
$sql .= " ".$field_desc['extra'];
|
$sql.= " default ".$field_desc['default'];
|
||||||
$sql .= " ".$field_position;
|
else
|
||||||
|
$sql.= " default '".$field_desc['default']."'";
|
||||||
|
}
|
||||||
|
if(preg_match("/^[^\s]/i",$field_desc['extra']))
|
||||||
|
$sql.= " ".$field_desc['extra'];
|
||||||
|
$sql.= " ".$field_position;
|
||||||
|
|
||||||
dol_syslog($sql,LOG_DEBUG);
|
dol_syslog(get_class($this)."::DDLAddField ".$sql,LOG_DEBUG);
|
||||||
if(! $this -> query($sql))
|
if(! $this->query($sql))
|
||||||
return -1;
|
{
|
||||||
else
|
return -1;
|
||||||
return 1;
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update format of a field into a table
|
* Update format of a field into a table
|
||||||
@ -979,7 +988,7 @@ class DoliDb
|
|||||||
$sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type'];
|
$sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type'];
|
||||||
if ($field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') $sql.="(".$field_desc['value'].")";
|
if ($field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') $sql.="(".$field_desc['value'].")";
|
||||||
|
|
||||||
dol_syslog($sql,LOG_DEBUG);
|
dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG);
|
||||||
if (! $this->query($sql))
|
if (! $this->query($sql))
|
||||||
return -1;
|
return -1;
|
||||||
else
|
else
|
||||||
@ -987,15 +996,15 @@ class DoliDb
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Drop a field in table
|
* Drop a field in table
|
||||||
* \param table Nom de la table
|
* @param table Nom de la table
|
||||||
* \param field_name Nom du champ a inserer
|
* @param field_name Nom du champ a inserer
|
||||||
* \return int <0 si KO, >0 si OK
|
* @return int <0 si KO, >0 si OK
|
||||||
*/
|
*/
|
||||||
function DDLDropField($table,$field_name)
|
function DDLDropField($table,$field_name)
|
||||||
{
|
{
|
||||||
$sql= "ALTER TABLE ".$table." DROP COLUMN `".$field_name."`";
|
$sql= "ALTER TABLE ".$table." DROP COLUMN `".$field_name."`";
|
||||||
dol_syslog($sql,LOG_DEBUG);
|
dol_syslog(get_class($this)."::DDLDropField ".$sql,LOG_DEBUG);
|
||||||
if (! $this->query($sql))
|
if (! $this->query($sql))
|
||||||
{
|
{
|
||||||
$this->error=$this->lasterror();
|
$this->error=$this->lasterror();
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user