diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 3c8da38dd5b..cb075d5d639 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -423,11 +423,11 @@ class Adherent extends CommonObject if (sizeof($this->array_options) > 0) { - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."adherent_extrafields WHERE fk_member = ".$this->id; + $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."adherent_extrafields WHERE fk_object = ".$this->id; dol_syslog(get_class($this)."::update sql=".$sql_del); $this->db->query($sql_del); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_extrafields (fk_member"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_extrafields (fk_object"; foreach($this->array_options as $key => $value) { // Add field of attribut @@ -643,7 +643,7 @@ class Adherent extends CommonObject $this->db->begin(); // Suppression options - $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_extrafields WHERE fk_member = ".$rowid; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_extrafields WHERE fk_object = ".$rowid; dol_syslog(get_class($this)."::delete sql=".$sql); $resql=$this->db->query($sql); @@ -1092,54 +1092,6 @@ class Adherent extends CommonObject } - /** - * Function to get extra fields of a member into $this->array_options - * @param rowid - * TODO Move this function into ExtraField class - * TODO rename field fk_member into fk_element - */ - function fetch_optionals($rowid) - { - require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php"); - $options = new ExtraFields($this->db); - $optionsArray = $options->fetch_name_optionals_label(); - - $tab=array(); - - $sql = "SELECT rowid"; - foreach ($optionsArray as $name => $label) - { - $sql.= ", ".$name; - } - $sql.= " FROM ".MAIN_DB_PREFIX."adherent_extrafields"; - $sql.= " WHERE fk_member=".$rowid; - - dol_syslog(get_class($this)."::fetch_optionals sql=".$sql, LOG_DEBUG); - $result=$this->db->query( $sql); - if ($result) - { - if ($this->db->num_rows($result)) - { - $tab = $this->db->fetch_array($result); - - foreach ($tab as $key => $value) - { - if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member') - { - // we can add this attribute to adherent object - $this->array_options["options_$key"]=$value; - } - } - } - } - else - { - dol_print_error($this->db); - } - - } - - /** * Fonction qui insere la cotisation dans la base de donnees * et eventuellement liens dans banques, mailman, etc... diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index e703f6b97dd..49c6b2453e2 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -47,8 +47,9 @@ $langs->load("users"); if (! $user->rights->adherent->lire) accessforbidden(); $adh = new Adherent($db); -$adho = new ExtraFields($db); -$errmsg=''; +$extrafields = new ExtraFields($db); + +$errmsg=''; $errmsgs=array(); $action=GETPOST("action"); $rowid=GETPOST("rowid"); @@ -595,14 +596,15 @@ if ($user->rights->adherent->creer && $_POST["action"] == 'confirm_add_spip' && * View */ -llxHeader('',$langs->trans("Member"),'EN:Module_Foundations|FR:Module_Adhérents|ES:Módulo_Miembros'); +// fetch optionals attributes and labels +$extralabels=$extrafields->fetch_name_optionals_label('member'); + +$help_url='EN:Module_Foundations|FR:Module_Adhérents|ES:Módulo_Miembros'; +llxHeader('',$langs->trans("Member"),$help_url); $html = new Form($db); $htmlcompany = new FormCompany($db); -// fetch optionals attributes and labels -$adho->fetch_name_optionals_label(); - $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')'; if ($action == 'create') @@ -692,11 +694,11 @@ if ($action == 'create') print $htmlcompany->select_civilite(isset($_POST["civilite_id"])?$_POST["civilite_id"]:$adh->civilite_id,'civilite_id').''; print ''; - // Nom + // Lastname print ''.$langs->trans("Lastname").'nom).'" size="40">'; print ''; - // Prenom + // Firstname print ''.$langs->trans("Firstname").'prenom).'">'; print ''; @@ -756,7 +758,7 @@ if ($action == 'create') // EMail print ''.($conf->global->ADHERENT_MAIL_REQUIRED?'':'').$langs->trans("EMail").($conf->global->ADHERENT_MAIL_REQUIRED?'':'').'email).'">'; - // Date naissance + // Birthday print "".$langs->trans("Birthday")."\n"; $html->select_date(($adh->naiss ? $adh->naiss : -1),'naiss','','',1,'formsoc'); print "\n"; @@ -767,7 +769,7 @@ if ($action == 'create') print "\n"; // Attribut optionnels - foreach($adho->attribute_label as $key=>$value) + foreach($extrafields->attribute_label as $key=>$value) { print "".$value.''."\n"; } @@ -803,14 +805,11 @@ if ($action == 'edit') * ********************************************/ - $adho = new ExtraFields($db); $adh = new Adherent($db); - $adh->id = $rowid; - $adh->fetch($rowid); - // fetch optionals value - $adh->fetch_optionals($rowid); - // fetch optionals attributes and labels - $adho->fetch_name_optionals_label(); + $res=$adh->fetch($rowid); + if ($res < 0) { dol_print_error($db,$adh->error); exit; } + $res=$adh->fetch_optionals($rowid,$extralabels); + if ($res < 0) { dol_print_error($db); exit; } $adht = new AdherentType($db); $adht->fetch($adh->typeid); @@ -855,7 +854,7 @@ if ($action == 'edit') $rowspan=17; if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) $rowspan+=1; - $rowspan+=sizeof($adho->attribute_label); + $rowspan+=sizeof($extrafields->attribute_label); if ($conf->societe->enabled) $rowspan++; print '
'; @@ -980,10 +979,10 @@ if ($action == 'edit') print $html->selectyesno("public",(isset($_POST["public"])?$_POST["public"]:$adh->public),1); print "\n"; - // Attributs supplementaires - foreach($adho->attribute_label as $key=>$value) + // Other attributes + foreach($extrafields->attribute_label as $key=>$value) { - print "$valuearray_options["options_$key"]."\">\n"; + print "".$value."array_options["options_$key"]."\">\n"; } // Third party Dolibarr @@ -1035,13 +1034,13 @@ if ($rowid && $action != 'edit') $adh = new Adherent($db); $res=$adh->fetch($rowid); - if ($res < 0) dol_print_error($db); - $res=$adh->fetch_optionals($rowid); - if ($res < 0) dol_print_error($db); + if ($res < 0) { dol_print_error($db,$adh->error); exit; } + $res=$adh->fetch_optionals($rowid,$extralabels); + if ($res < 0) { dol_print_error($db); exit; } $adht = new AdherentType($db); $res=$adht->fetch($adh->typeid); - if ($res < 0) dol_print_error($db); + if ($res < 0) { dol_print_error($db); exit; } /* @@ -1194,7 +1193,7 @@ if ($rowid && $action != 'edit') if ($ret == 'html') print '
'; } - $rowspan=19+sizeof($adho->attribute_label); + $rowspan=19+sizeof($extrafields->attribute_label); if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) $rowspan+=1; if ($conf->societe->enabled) $rowspan++; @@ -1285,10 +1284,10 @@ if ($rowid && $action != 'edit') // Status print ''.$langs->trans("Status").''.$adh->getLibStatut(4).''; - // Other attributs - foreach($adho->attribute_label as $key=>$value) + // Other attributes + foreach($extrafields->attribute_label as $key=>$value) { - print "$value".$adh->array_options["options_$key"]." \n"; + print "".$value."".$adh->array_options["options_$key"]." \n"; } // Third party Dolibarr diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 05afb692ed8..c552d4557b8 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -21,14 +21,14 @@ /** * \file htdocs/core/class/commonobject.class.php * \ingroup core - * \brief Fichier de la classe mere des classes metiers (facture, contrat, propal, commande, etc...) + * \brief File of parent class of all other business classes (invoices, contracts, proposals, orders, ...) * \version $Id$ */ /** * \class CommonObject - * \brief Classe mere pour heritage des classes metiers + * \brief Class of all other business classes (invoices, contracts, proposals, orders, ...) */ class CommonObject @@ -1489,9 +1489,64 @@ class CommonObject } + /** + * Function to get extra fields of a member into $this->array_options + * @param rowid + * @param optionsArray Array resulting of call of extrafields->fetch_name_optionals_label() + */ + function fetch_optionals($rowid,$optionsArray='') + { + if (! is_array($optionsArray)) + { + // optionsArray not already loaded, so we load it + require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php"); + $extrafields = new ExtraFields($this->db); + $optionsArray = $extrafields->fetch_name_optionals_label(); + } + + // Request to get complementary values + if (sizeof($optionsArray) > 0) + { + $sql = "SELECT rowid"; + foreach ($optionsArray as $name => $label) + { + $sql.= ", ".$name; + } + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields"; + $sql.= " WHERE fk_object = ".$rowid; + + dol_syslog(get_class($this)."::fetch_optionals sql=".$sql, LOG_DEBUG); + $resql=$this->db->query( $sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $tab = $this->db->fetch_array($resql); + + foreach ($tab as $key => $value) + { + if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member') + { + // we can add this attribute to adherent object + $this->array_options["options_$key"]=$value; + } + } + } + $this->db->free($resql); + } + else + { + dol_print_error($this->db); + } + } + } + + // -------------------- // TODO: All functions here must be redesigned and moved as they are not business functions but output functions + // -------------------- + /** * @@ -1547,7 +1602,7 @@ class CommonObject /** * Show linked object block * TODO Move this into html.class.php - * But for the moment we don't know if it'st possible as we keep a method available on overloaded objects. + * But for the moment we don't know if it's possible as we keep a method available on overloaded objects. */ function showLinkedObjectBlock() { diff --git a/htdocs/includes/modules/modAdherent.class.php b/htdocs/includes/modules/modAdherent.class.php index 5cee76706be..4650e493f15 100644 --- a/htdocs/includes/modules/modAdherent.class.php +++ b/htdocs/includes/modules/modAdherent.class.php @@ -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_extrafields 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_object'; $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 0025df5d219..a7aee5d7deb 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 @@ -383,12 +383,16 @@ alter table llx_propal add column tms timestamp after fk_projet; create table llx_societe_extrafields ( - rowid integer PRIMARY KEY + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + fk_object integer NOT NULL ) ENGINE=innodb; create table llx_product_extrafields ( - rowid integer PRIMARY KEY + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + fk_object integer NOT NULL ) ENGINE=innodb; @@ -397,6 +401,7 @@ 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; +ALTER TABLE llx_adherent_extrafields CHANGE COLUMN fk_member fk_object integer NOT NULL; -- drop tables renamed into llx_advanced_extra_xxx drop table llx_extra_fields_options; diff --git a/htdocs/install/mysql/tables/llx_adherent_extrafields.sql b/htdocs/install/mysql/tables/llx_adherent_extrafields.sql index aff99786751..db64e0cbf9c 100755 --- a/htdocs/install/mysql/tables/llx_adherent_extrafields.sql +++ b/htdocs/install/mysql/tables/llx_adherent_extrafields.sql @@ -24,5 +24,5 @@ create table llx_adherent_extrafields ( rowid integer AUTO_INCREMENT PRIMARY KEY, tms timestamp, - fk_member integer NOT NULL -- member id + fk_object integer NOT NULL -- member id )ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_product_extrafields.sql b/htdocs/install/mysql/tables/llx_product_extrafields.sql index 1073abfed03..45845593162 100755 --- a/htdocs/install/mysql/tables/llx_product_extrafields.sql +++ b/htdocs/install/mysql/tables/llx_product_extrafields.sql @@ -20,5 +20,7 @@ create table llx_product_extrafields ( - rowid integer PRIMARY KEY + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + fk_object integer NOT NULL ) ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_societe_extrafields.sql b/htdocs/install/mysql/tables/llx_societe_extrafields.sql index 55c25077c6f..7db41de673c 100755 --- a/htdocs/install/mysql/tables/llx_societe_extrafields.sql +++ b/htdocs/install/mysql/tables/llx_societe_extrafields.sql @@ -20,6 +20,8 @@ create table llx_societe_extrafields ( - rowid integer PRIMARY KEY + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + fk_object integer NOT NULL ) ENGINE=innodb; diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 7595b403e92..4ad50377b07 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -36,6 +36,7 @@ require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formadmin.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formcompany.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php"); +require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php"); require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php"); if ($conf->adherent->enabled) require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php"); @@ -74,6 +75,8 @@ else $error=0; $errors=array(); +$extrafields = new ExtraFields($db); + /* * Actions @@ -461,6 +464,9 @@ else * View */ +// fetch optionals attributes and labels +$extralabels=$extrafields->fetch_name_optionals_label('company'); + $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; llxHeader('',$langs->trans("ThirdParty"),$help_url); @@ -817,14 +823,8 @@ else if (empty($conf->global->SOCIETE_DISABLE_STATE)) { print ''.$langs->trans('State').''; - if ($soc->pays_id) - { - $formcompany->select_departement($soc->departement_id,$soc->pays_code); - } - else - { - print $countrynotdefined; - } + if ($soc->pays_id) $formcompany->select_departement($soc->departement_id,$soc->pays_code); + else print $countrynotdefined; print ''; } @@ -982,6 +982,12 @@ else print ''; } + // Attribut optionnels + foreach($extrafields->attribute_label as $key=>$value) + { + print "".$value.''."\n"; + } + // Ajout du logo print ''; print ''.$langs->trans("Logo").''; @@ -1006,6 +1012,12 @@ else if ($socid) { + $soc = new Societe($db); + $res=$soc->fetch($socid); + if ($res < 0) { dol_print_error($db,$soc->error); exit; } + $res=$soc->fetch_optionals($socid,$extralabels); + if ($res < 0) { dol_print_error($db); exit; } + // Load object modCodeTiers $module=$conf->global->SOCIETE_CODECLIENT_ADDON; if (! $module) dolibarr_error('',$langs->trans("ErrorModuleThirdPartyCodeInCompanyModuleNotDefined")); @@ -1034,14 +1046,14 @@ else $prefixSupplierIsUsed = $modCodeFournisseur->verif_prefixIsUsed(); } - if (! $_POST["nom"]) - { - $soc = new Societe($db); - $soc->fetch($socid); - } - else - { - $soc->id=$_POST["socid"]; +// if (! $_POST["nom"]) +// { +// $soc->fetch($socid); +// $soc->fetch_optionals($socid,$extralabels); +// } +// else +// { +// $soc->id=$_POST["socid"]; $soc->nom=$_POST["nom"]; $soc->prefix_comm=$_POST["prefix_comm"]; $soc->client=$_POST["client"]; @@ -1093,7 +1105,7 @@ else $soc->pays_code=$obj->code; $soc->pays=$langs->trans("Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->libelle; } - } +// } dol_htmloutput_errors($error,$errors); @@ -1394,9 +1406,15 @@ else print ''; } + // Other attributes + foreach($extrafields->attribute_label as $key=>$value) + { + print "".$value."array_options["options_$key"]."\">\n"; + } + // Logo print ''; - print ''.$langs->trans("Logo").''; + print ''.$langs->trans("Logo").''; print ''; if ($soc->logo) print $form->showphoto('societe',$soc,50); $caneditfield=1; @@ -1430,12 +1448,11 @@ else * View */ $soc = new Societe($db); - $result=$soc->fetch($socid); - if ($result < 0) - { - dol_print_error($db,$soc->error); - exit; - } + $res=$soc->fetch($socid); + if ($res < 0) { dol_print_error($db,$soc->error); exit; } + $res=$soc->fetch_optionals($socid,$extralabels); + if ($res < 0) { dol_print_error($db); exit; } + $head = societe_prepare_head($soc); @@ -1722,6 +1739,12 @@ else print ''; } + // Other attributes + foreach($extrafields->attribute_label as $key=>$value) + { + print "".$value."".$soc->array_options["options_$key"]." \n"; + } + // Ban if (empty($conf->global->SOCIETE_DISABLE_BANKACCOUNT)) {