New: Member module use generic extrafields feature.
This commit is contained in:
parent
52a6b11297
commit
cb263d64f2
@ -422,11 +422,11 @@ class Adherent extends CommonObject
|
||||
|
||||
if (sizeof($this->array_options) > 0)
|
||||
{
|
||||
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options WHERE fk_member = ".$this->id;
|
||||
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."adherent_extrafields WHERE fk_member = ".$this->id;
|
||||
dol_syslog("Adherent::update sql=".$sql_del);
|
||||
$this->db->query($sql_del);
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options (fk_member";
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_extrafields (fk_member";
|
||||
foreach($this->array_options as $key => $value)
|
||||
{
|
||||
// Add field of attribut
|
||||
@ -642,7 +642,7 @@ class Adherent extends CommonObject
|
||||
$this->db->begin();
|
||||
|
||||
// Suppression options
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options WHERE fk_member = ".$rowid;
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_extrafields WHERE fk_member = ".$rowid;
|
||||
|
||||
dol_syslog("Adherent::delete sql=".$sql);
|
||||
$resql=$this->db->query($sql);
|
||||
@ -1109,7 +1109,7 @@ class Adherent extends CommonObject
|
||||
$sql.= ", ".$name;
|
||||
}
|
||||
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."adherent_options";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."adherent_extrafields";
|
||||
$sql.= " WHERE fk_member=".$rowid;
|
||||
|
||||
dol_syslog("Adherent::fetch_optionals sql=".$sql, LOG_DEBUG);
|
||||
|
||||
@ -75,7 +75,7 @@ class AdherentOptions
|
||||
if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname))
|
||||
{
|
||||
$field_desc = array('type'=>$type, 'value'=>$length);
|
||||
$result=$this->db->DDLAddField(MAIN_DB_PREFIX.'adherent_options', $attrname, $field_desc);
|
||||
$result=$this->db->DDLAddField(MAIN_DB_PREFIX.'adherent_extrafields', $attrname, $field_desc);
|
||||
if ($result > 0)
|
||||
{
|
||||
return 1;
|
||||
@ -99,9 +99,10 @@ class AdherentOptions
|
||||
* @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', ...)
|
||||
* @return int <=0 if KO, >0 if OK
|
||||
*/
|
||||
function create_label($attrname,$label='',$type='',$pos=0,$size=0)
|
||||
function create_label($attrname,$label='',$type='',$pos=0,$size=0, $elementtype='member')
|
||||
{
|
||||
global $conf;
|
||||
|
||||
@ -111,13 +112,14 @@ class AdherentOptions
|
||||
|
||||
if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname))
|
||||
{
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options_label(name, label, type, pos, size, entity)";
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields(name, label, type, pos, size, entity, elementtype)";
|
||||
$sql.= " VALUES('".$attrname."',";
|
||||
$sql.= " '".$this->db->escape($label)."',";
|
||||
$sql.= " '".$type."',";
|
||||
$sql.= " '".$pos."',";
|
||||
$sql.= " '".$size."',";
|
||||
$sql.= " ".$conf->entity;
|
||||
$sql.= ", '".$elementtype."'";
|
||||
$sql.=')';
|
||||
|
||||
dol_syslog("AdherentOptions::create_label sql=".$sql);
|
||||
@ -142,7 +144,7 @@ class AdherentOptions
|
||||
{
|
||||
if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname))
|
||||
{
|
||||
$result=$this->db->DDLDropField(MAIN_DB_PREFIX."adherent_options",$attrname);
|
||||
$result=$this->db->DDLDropField(MAIN_DB_PREFIX."adherent_extrafields",$attrname);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
@ -170,7 +172,7 @@ class AdherentOptions
|
||||
|
||||
if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname))
|
||||
{
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options_label";
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."extrafields";
|
||||
$sql.= " WHERE name = '$attrname'";
|
||||
$sql.= " AND entity = ".$conf->entity;
|
||||
|
||||
@ -205,7 +207,7 @@ class AdherentOptions
|
||||
if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname))
|
||||
{
|
||||
$field_desc = array('type'=>$type, 'value'=>$length);
|
||||
$result=$this->db->DDLUpdateField(MAIN_DB_PREFIX.'adherent_options', $attrname, $field_desc);
|
||||
$result=$this->db->DDLUpdateField(MAIN_DB_PREFIX.'extrafields', $attrname, $field_desc);
|
||||
if ($result > 0)
|
||||
{
|
||||
return 1;
|
||||
@ -229,8 +231,9 @@ class AdherentOptions
|
||||
* @param label nom du label
|
||||
* @param type type
|
||||
* @param size size
|
||||
* @param elementtype Element type ('member', 'product', ...)
|
||||
*/
|
||||
function update_label($attrname,$label,$type,$size)
|
||||
function update_label($attrname,$label,$type,$size,$elementtype='member')
|
||||
{
|
||||
global $conf;
|
||||
dol_syslog("AdherentOptions::update_label $attrname,$label,$type,$size");
|
||||
@ -239,13 +242,14 @@ class AdherentOptions
|
||||
{
|
||||
$this->db->begin();
|
||||
|
||||
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options_label";
|
||||
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields";
|
||||
$sql_del.= " WHERE name = '".$attrname."'";
|
||||
$sql_del.= " AND entity = ".$conf->entity;
|
||||
$sql_del.= " AND elementtype = '".$elementtype."'";
|
||||
dol_syslog("AdherentOptions::update_label sql=".$sql_del);
|
||||
$resql1=$this->db->query($sql_del);
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options_label(";
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields(";
|
||||
$sql.= " name,"; // This is code
|
||||
$sql.= " entity,";
|
||||
$sql.= " label,";
|
||||
@ -256,9 +260,9 @@ class AdherentOptions
|
||||
$sql.= " ".$conf->entity.",";
|
||||
$sql.= " '".$this->db->escape($label)."',";
|
||||
$sql.= " '".$type."',";
|
||||
$sql.= " '".$size."'";
|
||||
$sql.= " '".$size."',";
|
||||
$sql.= " '".$elementtype."'";
|
||||
$sql.= ")";
|
||||
//$sql = "REPLACE INTO ".MAIN_DB_PREFIX."adherent_options_label SET name='$attrname',label='$escaped_label'";
|
||||
dol_syslog("AdherentOptions::update_label sql=".$sql);
|
||||
$resql2=$this->db->query($sql);
|
||||
|
||||
@ -294,15 +298,16 @@ class AdherentOptions
|
||||
/**
|
||||
* \brief Load array this->attribute_label
|
||||
*/
|
||||
function fetch_name_optionals_label()
|
||||
function fetch_name_optionals_label($elementtype='member')
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$array_name_label=array();
|
||||
|
||||
$sql = "SELECT name,label,type,size";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."adherent_options_label";
|
||||
$sql = "SELECT rowid,name,label,type,size,elementtype";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."extrafields";
|
||||
$sql.= " WHERE entity = ".$conf->entity;
|
||||
if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'";
|
||||
$sql.= " ORDER BY pos";
|
||||
|
||||
dol_syslog("Adherent_options::fetch_name_optionals_label sql=".$sql);
|
||||
@ -318,6 +323,7 @@ class AdherentOptions
|
||||
$this->attribute_type[$tab->name]=$tab->type;
|
||||
$this->attribute_label[$tab->name]=$tab->label;
|
||||
$this->attribute_size[$tab->name]=$tab->size;
|
||||
$this->attribute_elementtype[$tab->name]=$tab->elementtype;
|
||||
}
|
||||
}
|
||||
return $array_name_label;
|
||||
|
||||
@ -251,13 +251,12 @@ if ($_REQUEST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->adhe
|
||||
$adh->statut = $_POST["statut"];
|
||||
$adh->public = $_POST["public"];
|
||||
|
||||
// Get extra fields
|
||||
foreach($_POST as $key => $value)
|
||||
{
|
||||
if (preg_match("/^options_/",$key))
|
||||
{
|
||||
//escape values from POST, at least with $db->escape, to avoid obvious SQL injections
|
||||
//(array_options is directly input in the DB in adherent.class.php::update())
|
||||
$adh->array_options[$key]=$db->escape($_POST[$key]);
|
||||
$adh->array_options[$key]=$_POST[$key];
|
||||
}
|
||||
}
|
||||
|
||||
@ -392,6 +391,17 @@ if ($_POST["action"] == 'add' && $user->rights->adherent->creer)
|
||||
$adh->fk_soc = $socid;
|
||||
$adh->public = $public;
|
||||
|
||||
// Get extra fields
|
||||
foreach($_POST as $key => $value)
|
||||
{
|
||||
if (preg_match("/^options_/",$key))
|
||||
{
|
||||
//escape values from POST, at least with $db->escape, to avoid obvious SQL injections
|
||||
//(array_options is directly input in the DB in adherent.class.php::update())
|
||||
$adh->array_options[$key]=$_POST[$key];
|
||||
}
|
||||
}
|
||||
|
||||
// Check parameters
|
||||
if (empty($morphy) || $morphy == "-1") {
|
||||
$error++;
|
||||
|
||||
@ -189,8 +189,8 @@ class modAdherent extends DolibarrModules
|
||||
$this->export_permission[$r]=array(array("adherent","export"));
|
||||
$this->export_fields_array[$r]=array('a.rowid'=>'Id','a.civilite'=>"UserTitle",'a.nom'=>"Lastname",'a.prenom'=>"Firstname",'a.login'=>"Login",'a.morphy'=>'MorPhy','a.societe'=>'Company','a.adresse'=>"Address",'a.cp'=>"Zip",'a.ville'=>"Town",'a.pays'=>"Country",'a.phone'=>"PhonePro",'a.phone_perso'=>"PhonePerso",'a.phone_mobile'=>"PhoneMobile",'a.email'=>"Email",'a.naiss'=>"Birthday",'a.statut'=>"Status",'a.photo'=>"Photo",'a.note'=>"Note",'a.datec'=>'DateCreation','a.datevalid'=>'DateValidation','a.tms'=>'DateLastModification','a.datefin'=>'DateEndSubscription','ta.rowid'=>'MemberTypeId','ta.libelle'=>'MemberTypeLabel','c.rowid'=>'SubscriptionId','c.dateadh'=>'DateSubscription','c.cotisation'=>'Amount');
|
||||
$this->export_entities_array[$r]=array('a.rowid'=>'member','a.civilite'=>"member",'a.nom'=>"member",'a.prenom'=>"member",'a.login'=>"member",'a.morphy'=>'member','a.societe'=>'member','a.adresse'=>"member",'a.cp'=>"member",'a.ville'=>"member",'a.pays'=>"member",'a.phone'=>"member",'a.phone_perso'=>"member",'a.phone_mobile'=>"member",'a.email'=>"member",'a.naiss'=>"member",'a.statut'=>"member",'a.photo'=>"member",'a.note'=>"member",'a.datec'=>'member','a.datevalid'=>'member','a.tms'=>'member','a.datefin'=>'member','ta.rowid'=>'member_type','ta.libelle'=>'member_type','c.rowid'=>'subscription','c.dateadh'=>'subscription','c.cotisation'=>'subscription');
|
||||
// On complete avec champs options
|
||||
$sql='SELECT name, label FROM '.MAIN_DB_PREFIX.'adherent_options_label';
|
||||
// TODO Use generic method
|
||||
$sql="SELECT name, label FROM ".MAIN_DB_PREFIX."extrafields AND elementtype = 'member'";
|
||||
$resql=$this->db->query($sql);
|
||||
while ($obj=$this->db->fetch_object($resql))
|
||||
{
|
||||
@ -202,7 +202,7 @@ class modAdherent extends DolibarrModules
|
||||
// Fin complement
|
||||
$this->export_sql_start[$r]='SELECT DISTINCT ';
|
||||
$this->export_sql_end[$r] =' FROM ('.MAIN_DB_PREFIX.'adherent_type as ta, '.MAIN_DB_PREFIX.'adherent as a)';
|
||||
$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'adherent_options as ao ON a.rowid = ao.fk_member';
|
||||
$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'adherent_extrafields as ao ON a.rowid = ao.fk_member';
|
||||
$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'cotisation as c ON c.fk_adherent = a.rowid';
|
||||
$this->export_sql_end[$r] .=' WHERE a.fk_adherent_type = ta.rowid';
|
||||
|
||||
|
||||
@ -392,3 +392,13 @@ create table llx_product_extrafields
|
||||
) ENGINE=innodb;
|
||||
|
||||
|
||||
alter table llx_adherent_options_label drop index uk_adherent_options_label_name;
|
||||
alter table llx_adherent_options_label rename to llx_extrafields;
|
||||
ALTER TABLE llx_extrafields ADD COLUMN elementtype varchar(64) NOT NULL DEFAULT 'member' AFTER entity;
|
||||
ALTER TABLE llx_extrafields ADD UNIQUE INDEX uk_extrafields_name (name, entity, elementtype);
|
||||
ALTER TABLE llx_adherent_options rename to llx_adherent_extrafields;
|
||||
|
||||
-- drop tables renamed into llx_advanced_extra_xxx
|
||||
drop table llx_extra_fields_options;
|
||||
drop table llx_extra_fields_values;
|
||||
drop table llx_extra_fields;
|
||||
|
||||
2
htdocs/install/mysql/tables/llx_adherent_options.key.sql → htdocs/install/mysql/tables/llx_adherent_extrafields.key.sql
Normal file → Executable file
2
htdocs/install/mysql/tables/llx_adherent_options.key.sql → htdocs/install/mysql/tables/llx_adherent_extrafields.key.sql
Normal file → Executable file
@ -21,4 +21,4 @@
|
||||
-- ===================================================================
|
||||
|
||||
|
||||
ALTER TABLE llx_adherent_options ADD INDEX idx_adherent_options (fk_member);
|
||||
ALTER TABLE llx_adherent_extrafields ADD INDEX idx_adherent_extrafields (fk_member);
|
||||
2
htdocs/install/mysql/tables/llx_adherent_options.sql → htdocs/install/mysql/tables/llx_adherent_extrafields.sql
Normal file → Executable file
2
htdocs/install/mysql/tables/llx_adherent_options.sql → htdocs/install/mysql/tables/llx_adherent_extrafields.sql
Normal file → Executable file
@ -20,7 +20,7 @@
|
||||
-- $Id$
|
||||
-- ===================================================================
|
||||
|
||||
create table llx_adherent_options
|
||||
create table llx_adherent_extrafields
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
tms timestamp,
|
||||
0
htdocs/install/mysql/tables/llx_extra_fields.key.sql → htdocs/install/mysql/tables/llx_advanced_extra_fields.key.sql
Normal file → Executable file
0
htdocs/install/mysql/tables/llx_extra_fields.key.sql → htdocs/install/mysql/tables/llx_advanced_extra_fields.key.sql
Normal file → Executable file
0
htdocs/install/mysql/tables/llx_extra_fields.sql → htdocs/install/mysql/tables/llx_advanced_extra_fields.sql
Normal file → Executable file
0
htdocs/install/mysql/tables/llx_extra_fields.sql → htdocs/install/mysql/tables/llx_advanced_extra_fields.sql
Normal file → Executable file
0
htdocs/install/mysql/tables/llx_extra_fields_options.sql → htdocs/install/mysql/tables/llx_advanced_extra_fields_options.sql
Normal file → Executable file
0
htdocs/install/mysql/tables/llx_extra_fields_options.sql → htdocs/install/mysql/tables/llx_advanced_extra_fields_options.sql
Normal file → Executable file
0
htdocs/install/mysql/tables/llx_extra_fields_values.sql → htdocs/install/mysql/tables/llx_advanced_extra_fields_values.sql
Normal file → Executable file
0
htdocs/install/mysql/tables/llx_extra_fields_values.sql → htdocs/install/mysql/tables/llx_advanced_extra_fields_values.sql
Normal file → Executable file
2
htdocs/install/mysql/tables/llx_adherent_options_label.key.sql → htdocs/install/mysql/tables/llx_extrafields.key.sql
Normal file → Executable file
2
htdocs/install/mysql/tables/llx_adherent_options_label.key.sql → htdocs/install/mysql/tables/llx_extrafields.key.sql
Normal file → Executable file
@ -19,4 +19,4 @@
|
||||
-- ===================================================================
|
||||
|
||||
|
||||
ALTER TABLE llx_adherent_options_label ADD UNIQUE INDEX uk_adherent_options_label_name (name, entity);
|
||||
ALTER TABLE llx_extrafields ADD UNIQUE INDEX uk_extrafields_name (name, entity, elementtype);
|
||||
3
htdocs/install/mysql/tables/llx_adherent_options_label.sql → htdocs/install/mysql/tables/llx_extrafields.sql
Normal file → Executable file
3
htdocs/install/mysql/tables/llx_adherent_options_label.sql → htdocs/install/mysql/tables/llx_extrafields.sql
Normal file → Executable file
@ -20,11 +20,12 @@
|
||||
-- $Id$
|
||||
-- ===================================================================
|
||||
|
||||
create table llx_adherent_options_label
|
||||
create table llx_extrafields
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
name varchar(64) NOT NULL, -- nom de l'attribut
|
||||
entity integer DEFAULT 1 NOT NULL, -- multi company id
|
||||
elementtype varchar(64) NOT NULL DEFAULT 'member',
|
||||
tms timestamp,
|
||||
label varchar(255) NOT NULL, -- label correspondant a l'attribut
|
||||
type varchar(8),
|
||||
Loading…
Reference in New Issue
Block a user