diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 103cea62daf516d2ab818715793c7a20a46221e9..12780503e357b66dde60de9e3bee3804cf34b12b 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -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); diff --git a/htdocs/adherents/class/adherent_options.class.php b/htdocs/adherents/class/adherent_options.class.php index 5da0ec4968349f47f1e8e382d234afad2e22fa01..03d70a2a01ca36960b72e1b724e25f589d7c35df 100644 --- a/htdocs/adherents/class/adherent_options.class.php +++ b/htdocs/adherents/class/adherent_options.class.php @@ -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; diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index 2ce29a0bdefd4fde3d78a5f8f8288ea7fd6b02f5..446359bdbbec3b52746b96f0994f9053abfbd019 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -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++; diff --git a/htdocs/includes/modules/modAdherent.class.php b/htdocs/includes/modules/modAdherent.class.php index 3f9c95c7c61ed9a5ec7aa683538fdf1d40d051db..be81c4f25ee888ad85a3e2c845fd9c2a7a89c820 100644 --- a/htdocs/includes/modules/modAdherent.class.php +++ b/htdocs/includes/modules/modAdherent.class.php @@ -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'; diff --git a/htdocs/install/mysql/migration/3.0.0-3.1.0.sql b/htdocs/install/mysql/migration/3.0.0-3.1.0.sql index 385f7d0b046128c5f61d2007f2feae3782f86a39..ffd39f8d299b97ecde73aabf90ec539d4cfce16a 100755 --- a/htdocs/install/mysql/migration/3.0.0-3.1.0.sql +++ b/htdocs/install/mysql/migration/3.0.0-3.1.0.sql @@ -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; diff --git a/htdocs/install/mysql/tables/llx_adherent_options.key.sql b/htdocs/install/mysql/tables/llx_adherent_extrafields.key.sql old mode 100644 new mode 100755 similarity index 92% rename from htdocs/install/mysql/tables/llx_adherent_options.key.sql rename to htdocs/install/mysql/tables/llx_adherent_extrafields.key.sql index cc726558339d42c0ad158a2790e2de5f908890a7..ab416392c0f9e31a1743c011bcf8d86a07e852a2 --- a/htdocs/install/mysql/tables/llx_adherent_options.key.sql +++ b/htdocs/install/mysql/tables/llx_adherent_extrafields.key.sql @@ -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); diff --git a/htdocs/install/mysql/tables/llx_adherent_options.sql b/htdocs/install/mysql/tables/llx_adherent_extrafields.sql old mode 100644 new mode 100755 similarity index 97% rename from htdocs/install/mysql/tables/llx_adherent_options.sql rename to htdocs/install/mysql/tables/llx_adherent_extrafields.sql index 491d5690802cfcdd8623f04175d1f33b36b56205..aff99786751019e1795060f7ea48430596cfd4c1 --- a/htdocs/install/mysql/tables/llx_adherent_options.sql +++ b/htdocs/install/mysql/tables/llx_adherent_extrafields.sql @@ -20,7 +20,7 @@ -- $Id$ -- =================================================================== -create table llx_adherent_options +create table llx_adherent_extrafields ( rowid integer AUTO_INCREMENT PRIMARY KEY, tms timestamp, diff --git a/htdocs/install/mysql/tables/llx_extra_fields.key.sql b/htdocs/install/mysql/tables/llx_advanced_extra_fields.key.sql old mode 100644 new mode 100755 similarity index 100% rename from htdocs/install/mysql/tables/llx_extra_fields.key.sql rename to htdocs/install/mysql/tables/llx_advanced_extra_fields.key.sql diff --git a/htdocs/install/mysql/tables/llx_extra_fields.sql b/htdocs/install/mysql/tables/llx_advanced_extra_fields.sql old mode 100644 new mode 100755 similarity index 100% rename from htdocs/install/mysql/tables/llx_extra_fields.sql rename to htdocs/install/mysql/tables/llx_advanced_extra_fields.sql diff --git a/htdocs/install/mysql/tables/llx_extra_fields_options.key.sql b/htdocs/install/mysql/tables/llx_advanced_extra_fields_options.key.sql old mode 100644 new mode 100755 similarity index 100% rename from htdocs/install/mysql/tables/llx_extra_fields_options.key.sql rename to htdocs/install/mysql/tables/llx_advanced_extra_fields_options.key.sql diff --git a/htdocs/install/mysql/tables/llx_extra_fields_options.sql b/htdocs/install/mysql/tables/llx_advanced_extra_fields_options.sql old mode 100644 new mode 100755 similarity index 100% rename from htdocs/install/mysql/tables/llx_extra_fields_options.sql rename to htdocs/install/mysql/tables/llx_advanced_extra_fields_options.sql diff --git a/htdocs/install/mysql/tables/llx_extra_fields_values.key.sql b/htdocs/install/mysql/tables/llx_advanced_extra_fields_values.key.sql old mode 100644 new mode 100755 similarity index 100% rename from htdocs/install/mysql/tables/llx_extra_fields_values.key.sql rename to htdocs/install/mysql/tables/llx_advanced_extra_fields_values.key.sql diff --git a/htdocs/install/mysql/tables/llx_extra_fields_values.sql b/htdocs/install/mysql/tables/llx_advanced_extra_fields_values.sql old mode 100644 new mode 100755 similarity index 100% rename from htdocs/install/mysql/tables/llx_extra_fields_values.sql rename to htdocs/install/mysql/tables/llx_advanced_extra_fields_values.sql diff --git a/htdocs/install/mysql/tables/llx_adherent_options_label.key.sql b/htdocs/install/mysql/tables/llx_extrafields.key.sql old mode 100644 new mode 100755 similarity index 90% rename from htdocs/install/mysql/tables/llx_adherent_options_label.key.sql rename to htdocs/install/mysql/tables/llx_extrafields.key.sql index 299d512a9f0c7bee165bd1c577b2b767f7eb2dcd..99cf1edd744e51eb635f0e597b5f79d0396bf0d9 --- a/htdocs/install/mysql/tables/llx_adherent_options_label.key.sql +++ b/htdocs/install/mysql/tables/llx_extrafields.key.sql @@ -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); diff --git a/htdocs/install/mysql/tables/llx_adherent_options_label.sql b/htdocs/install/mysql/tables/llx_extrafields.sql old mode 100644 new mode 100755 similarity index 94% rename from htdocs/install/mysql/tables/llx_adherent_options_label.sql rename to htdocs/install/mysql/tables/llx_extrafields.sql index e514c2cb67b5638f4207032d5603f9b2ea7547e0..415b44c6a35c5fa066b1dc5049edee87acca1a0e --- a/htdocs/install/mysql/tables/llx_adherent_options_label.sql +++ b/htdocs/install/mysql/tables/llx_extrafields.sql @@ -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),