From 6ceea92eea36570bc9b284019b4311313c5e3e79 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@users.sourceforge.net> Date: Sun, 19 Jun 2011 14:27:06 +0000 Subject: [PATCH] New: Member module use generic extrafields feature. --- htdocs/adherents/card_subscriptions.php | 4 +- htdocs/adherents/class/adherent.class.php | 91 ++++++------ htdocs/adherents/fiche.php | 6 +- htdocs/adherents/options.php | 4 +- .../class/extrafields.class.php} | 135 +++++++++++------- htdocs/main.inc.php | 2 +- htdocs/public/members/new.php | 5 +- htdocs/public/members/public_card.php | 14 +- 8 files changed, 151 insertions(+), 110 deletions(-) rename htdocs/{adherents/class/adherent_options.class.php => core/class/extrafields.class.php} (62%) mode change 100644 => 100755 diff --git a/htdocs/adherents/card_subscriptions.php b/htdocs/adherents/card_subscriptions.php index 03f571e1c46..befd5ade5d5 100644 --- a/htdocs/adherents/card_subscriptions.php +++ b/htdocs/adherents/card_subscriptions.php @@ -30,9 +30,9 @@ require_once(DOL_DOCUMENT_ROOT."/lib/member.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/date.lib.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php"); -require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent_options.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/class/cotisation.class.php"); require_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php"); +require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php"); $langs->load("companies"); $langs->load("bills"); @@ -45,7 +45,7 @@ $langs->load("mails"); if (! $user->rights->adherent->cotisation->lire) accessforbidden(); $adh = new Adherent($db); -$adho = new AdherentOptions($db); +$adho = new ExtraFields($db); $adht = new AdherentType($db); $errmsg=''; diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 12780503e35..33b75246afd 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -279,7 +279,7 @@ class Adherent extends CommonObject $sql.= ", ".$conf->entity; $sql.= ")"; - dol_syslog("Adherent::create sql=".$sql); + dol_syslog(get_class($this)."::create sql=".$sql); $result = $this->db->query($sql); if ($result) { @@ -303,7 +303,7 @@ class Adherent extends CommonObject $sql = "UPDATE ".MAIN_DB_PREFIX."user SET"; $sql.= " fk_member = '".$this->id."'"; $sql.= " WHERE rowid = ".$this->user_id; - dol_syslog("Adherent::create sql=".$sql); + dol_syslog(get_class($this)."::create sql=".$sql); $resql = $this->db->query($sql); if (! $resql) { @@ -327,7 +327,7 @@ class Adherent extends CommonObject if (sizeof($this->errors)) { - dol_syslog("Adherent::create ".join(',',$this->errors), LOG_ERR); + dol_syslog(get_class($this)."::create ".join(',',$this->errors), LOG_ERR); $this->db->rollback(); return -3; } @@ -340,7 +340,7 @@ class Adherent extends CommonObject else { $this->error='Failed to get last insert id'; - dol_syslog("Adherent::create ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); $this->db->rollback(); return -2; } @@ -348,7 +348,7 @@ class Adherent extends CommonObject else { $this->error=$this->db->error(); - dol_syslog("Adherent::create ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); $this->db->rollback(); return -1; } @@ -370,7 +370,7 @@ class Adherent extends CommonObject $nbrowsaffected=0; $error=0; - dol_syslog("Adherent::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser.", nosyncuserpass=".$nosyncuserpass.", email=".$this->email); + dol_syslog(get_class($this)."::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser.", nosyncuserpass=".$nosyncuserpass.", email=".$this->email); // Clean parameters if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->nom=ucwords(trim($this->nom)); @@ -414,7 +414,7 @@ class Adherent extends CommonObject $sql.= ", fk_user_mod=".($user->id>0?$user->id:'null'); // Can be null because member can be create by a guest $sql.= " WHERE rowid = ".$this->id; - dol_syslog("Adherent::update update member sql=".$sql); + dol_syslog(get_class($this)."::update update member sql=".$sql); $resql = $this->db->query($sql); if ($resql) { @@ -423,7 +423,7 @@ class Adherent extends CommonObject if (sizeof($this->array_options) > 0) { $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."adherent_extrafields WHERE fk_member = ".$this->id; - dol_syslog("Adherent::update sql=".$sql_del); + dol_syslog(get_class($this)."::update sql=".$sql_del); $this->db->query($sql_del); $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_extrafields (fk_member"; @@ -447,7 +447,7 @@ class Adherent extends CommonObject } $sql.=")"; - dol_syslog("Adherent::update update option sql=".$sql); + dol_syslog(get_class($this)."::update update option sql=".$sql); $resql = $this->db->query($sql); if ($resql) { @@ -456,7 +456,7 @@ class Adherent extends CommonObject else { $this->error=$this->db->error(); - dol_syslog("Adherent::update ".$this->error,LOG_ERR); + dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR); $this->db->rollback(); return -2; } @@ -465,7 +465,7 @@ class Adherent extends CommonObject // Update password if ($this->pass) { - dol_syslog("Adherent::update update password"); + dol_syslog(get_class($this)."::update update password"); if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted) { // Si mot de passe saisi et different de celui en base @@ -475,16 +475,16 @@ class Adherent extends CommonObject } // Remove link to user - dol_syslog("Adherent::update update link to user"); + dol_syslog(get_class($this)."::update update link to user"); $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".$this->id; - dol_syslog("Adherent::update sql=".$sql, LOG_DEBUG); + dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -5; } // If there is a user linked to this member if ($this->user_id > 0) { $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".$this->id." WHERE rowid = ".$this->user_id; - dol_syslog("Adherent::update sql=".$sql, LOG_DEBUG); + dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -5; } } @@ -495,7 +495,7 @@ class Adherent extends CommonObject { require_once(DOL_DOCUMENT_ROOT."/user/class/user.class.php"); - dol_syslog("Adherent::update update linked user"); + dol_syslog(get_class($this)."::update update linked user"); // This member is linked with a user, so we also update users informations // if this is an update. @@ -523,7 +523,7 @@ class Adherent extends CommonObject if ($result < 0) { $this->error=$luser->error; - dol_syslog("Adherent::update ".$this->error,LOG_ERR); + dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR); $error++; } } @@ -563,7 +563,7 @@ class Adherent extends CommonObject $this->db->rollback(); $this->error=$this->db->lasterror(); - dol_syslog("Adherent::update ".$this->error,LOG_ERR); + dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR); return -1; } } @@ -589,7 +589,7 @@ class Adherent extends CommonObject $sql.= " WHERE fk_adherent='".$this->id."'"; $sql.= " ORDER by dateadh DESC"; // Sort by start subscription date - dol_syslog("Adherent::update_end_date sql=".$sql); + dol_syslog(get_class($this)."::update_end_date sql=".$sql); $resql=$this->db->query($sql); if ($resql) { @@ -602,7 +602,7 @@ class Adherent extends CommonObject $sql.= " datefin=".($datefin != '' ? "'".$this->db->idate($datefin)."'" : "null"); $sql.= " WHERE rowid = ".$this->id; - dol_syslog("Adherent::update_end_date sql=".$sql); + dol_syslog(get_class($this)."::update_end_date sql=".$sql); $resql=$this->db->query($sql); if ($resql) { @@ -622,7 +622,7 @@ class Adherent extends CommonObject else { $this->error=$this->db->lasterror(); - dol_syslog("Adherent::update_end_date ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::update_end_date ".$this->error, LOG_ERR); $this->db->rollback(); return -1; } @@ -644,17 +644,17 @@ class Adherent extends CommonObject // Suppression options $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_extrafields WHERE fk_member = ".$rowid; - dol_syslog("Adherent::delete sql=".$sql); + dol_syslog(get_class($this)."::delete sql=".$sql); $resql=$this->db->query($sql); if ($resql) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."cotisation WHERE fk_adherent = ".$rowid; - dol_syslog("Adherent::delete sql=".$sql); + dol_syslog(get_class($this)."::delete sql=".$sql); $resql=$this->db->query( $sql); if ($resql) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent WHERE rowid = ".$rowid; - dol_syslog("Adherent::delete sql=".$sql); + dol_syslog(get_class($this)."::delete sql=".$sql); $resql=$this->db->query($sql); if ($resql) { @@ -720,7 +720,7 @@ class Adherent extends CommonObject $error=0; - dol_syslog("Adherent::Password user=".$user->id." password=".preg_replace('/./i','*',$password)." isencrypted=".$isencrypted); + dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i','*',$password)." isencrypted=".$isencrypted); // If new password not provided, we generate one if (! $password) @@ -746,7 +746,7 @@ class Adherent extends CommonObject $sql.= " WHERE rowid = ".$this->id; //dol_syslog("Adherent::Password sql=hidden"); - dol_syslog("Adherent::Password sql=".$sql); + dol_syslog(get_class($this)."::setPassword sql=".$sql); $result = $this->db->query($sql); if ($result) { @@ -772,7 +772,7 @@ class Adherent extends CommonObject if ($result < 0) { $this->error=$luser->error; - dol_syslog("Adherent::password ".$this->error,LOG_ERR); + dol_syslog(get_class($this)."::setPassword ".$this->error,LOG_ERR); $error++; } } @@ -821,7 +821,7 @@ class Adherent extends CommonObject // If user is linked to this member, remove old link to this member $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".$this->id; - dol_syslog("Adherent::setUserId sql=".$sql, LOG_DEBUG); + dol_syslog(get_class($this)."::setUserId sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -1; } @@ -830,7 +830,7 @@ class Adherent extends CommonObject { $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".$this->id; $sql.= " WHERE rowid = ".$userid; - dol_syslog("Adherent::setUserId sql=".$sql, LOG_DEBUG); + dol_syslog(get_class($this)."::setUserId sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -2; } } @@ -858,7 +858,7 @@ class Adherent extends CommonObject $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = null"; $sql.= " WHERE fk_soc = '".$thirdpartyid."'"; $sql.= " AND entity = ".$conf->entity; - dol_syslog("Adherent::setThirdPartyId sql=".$sql); + dol_syslog(get_class($this)."::setThirdPartyId sql=".$sql); $resql = $this->db->query($sql); } @@ -866,7 +866,7 @@ class Adherent extends CommonObject $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = ".($thirdpartyid>0 ? $thirdpartyid : 'null'); $sql.= " WHERE rowid = ".$this->id; - dol_syslog("Adherent::setThirdPartyId sql=".$sql); + dol_syslog(get_class($this)."::setThirdPartyId sql=".$sql); $resql = $this->db->query($sql); if ($resql) { @@ -876,7 +876,7 @@ class Adherent extends CommonObject else { $this->error=$this->db->error(); - dol_syslog("Adherent::setThirdPartyId ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::setThirdPartyId ".$this->error, LOG_ERR); $this->db->rollback(); return -1; } @@ -947,7 +947,7 @@ class Adherent extends CommonObject elseif ($fk_soc) $sql.= " AND d.fk_soc='".$fk_soc."'"; else $sql.= " AND d.rowid=".$rowid; - dol_syslog("Adherent::fetch sql=".$sql); + dol_syslog(get_class($this)."::fetch sql=".$sql); $resql=$this->db->query($sql); if ($resql) { @@ -1022,7 +1022,7 @@ class Adherent extends CommonObject else { $this->error=$this->db->lasterror(); - dol_syslog("Adherent::fetch ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR); return -1; } } @@ -1048,7 +1048,7 @@ class Adherent extends CommonObject $sql.= " FROM ".MAIN_DB_PREFIX."cotisation as c"; $sql.= " WHERE c.fk_adherent = ".$this->id; $sql.= " ORDER BY c.dateadh"; - dol_syslog("Adherent::fetch_subscriptions sql=".$sql); + dol_syslog(get_class($this)."::fetch_subscriptions sql=".$sql); $resql=$this->db->query($sql); if ($resql) @@ -1092,27 +1092,28 @@ class Adherent extends CommonObject /** - * Fonction qui recupere les donnees optionelles de l'adherent + * 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) { - $options = new AdherentOptions($this->db); + 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("Adherent::fetch_optionals sql=".$sql, LOG_DEBUG); + dol_syslog(get_class($this)."::fetch_optionals sql=".$sql, LOG_DEBUG); $result=$this->db->query( $sql); if ($result) { @@ -1236,7 +1237,7 @@ class Adherent extends CommonObject if ($this->statut == 1) { - dol_syslog("Adherent::validate statut of member does not allow this", LOG_WARNING); + dol_syslog(get_class($this)."::validate statut of member does not allow this", LOG_WARNING); return 0; } @@ -1248,7 +1249,7 @@ class Adherent extends CommonObject $sql.= ", fk_user_valid=".$user->id; $sql.= " WHERE rowid = ".$this->id; - dol_syslog("Adherent::validate sql=".$sql); + dol_syslog(get_class($this)."::validate sql=".$sql); $result = $this->db->query($sql); if ($result) { @@ -1286,7 +1287,7 @@ class Adherent extends CommonObject if ($this->statut == 0) { - dol_syslog("Adherent::resiliate statut of member does not allow this", LOG_WARNING); + dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING); return 0; } @@ -1405,7 +1406,7 @@ class Adherent extends CommonObject { require_once(DOL_DOCUMENT_ROOT.'/lib/security.lib.php'); - dol_syslog("Adherent::add_to_spip"); + dol_syslog(get_class($this)."::add_to_spip"); if (defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 && defined('ADHERENT_SPIP_SERVEUR') && ADHERENT_SPIP_SERVEUR != '' && @@ -1517,7 +1518,7 @@ class Adherent extends CommonObject { global $conf,$langs; - dol_syslog("Adherent::add_to_mailman"); + dol_syslog(get_class($this)."::add_to_mailman"); if (! function_exists("curl_init")) { @@ -2059,7 +2060,7 @@ class Adherent extends CommonObject $sql.= ' FROM '.MAIN_DB_PREFIX.'adherent as a'; $sql.= ' WHERE a.rowid = '.$id; - dol_syslog("Adherent::info sql=".$sql, LOG_DEBUG); + dol_syslog(get_class($this)."::info sql=".$sql, LOG_DEBUG); $result=$this->db->query($sql); if ($result) { diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index 446359bdbbe..eba85c54453 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -33,7 +33,7 @@ require_once(DOL_DOCUMENT_ROOT."/lib/images.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php"); -require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent_options.class.php"); +require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/class/cotisation.class.php"); require_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formcompany.class.php"); @@ -47,7 +47,7 @@ $langs->load("users"); if (! $user->rights->adherent->lire) accessforbidden(); $adh = new Adherent($db); -$adho = new AdherentOptions($db); +$adho = new ExtraFields($db); $errmsg=''; $action=GETPOST("action"); @@ -796,7 +796,7 @@ if ($action == 'edit') * ********************************************/ - $adho = new AdherentOptions($db); + $adho = new ExtraFields($db); $adh = new Adherent($db); $adh->id = $rowid; $adh->fetch($rowid); diff --git a/htdocs/adherents/options.php b/htdocs/adherents/options.php index fa79db38358..84928f01517 100644 --- a/htdocs/adherents/options.php +++ b/htdocs/adherents/options.php @@ -26,11 +26,11 @@ */ require("../main.inc.php"); -require(DOL_DOCUMENT_ROOT."/adherents/class/adherent_options.class.php"); +require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php"); $langs->load("members"); -$adho = new AdherentOptions($db); +$adho = new ExtraFields($db); $form = new Form($db); /* diff --git a/htdocs/adherents/class/adherent_options.class.php b/htdocs/core/class/extrafields.class.php old mode 100644 new mode 100755 similarity index 62% rename from htdocs/adherents/class/adherent_options.class.php rename to htdocs/core/class/extrafields.class.php index 03d70a2a01c..5ac0be91a50 --- a/htdocs/adherents/class/adherent_options.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -3,7 +3,7 @@ * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org> * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org> * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> - * Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net> + * Copyright (C) 2009-2011 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr> * * This program is free software; you can redistribute it and/or modify @@ -22,19 +22,18 @@ */ /** - * \file htdocs/adherents/class/adherent_options.class.php - * \ingroup member - * \brief File of class to manage optionnal fields + * \file htdocs/core/class/extrafields.class.php + * \ingroup core + * \brief File of class to manage extra fields * \version $Id$ */ /** - * \class AdherentOptions - * \brief Class to manage table of optionnal fields + * \class ExtraFields + * \brief Class to manage standard extra fields */ -class AdherentOptions +class ExtraFields { - var $id; var $db; // Tableau contenant le nom des champs en clef et la definition de ces champs var $attribute_type; @@ -44,24 +43,20 @@ class AdherentOptions var $attribute_size; var $error; - /* - * Constructor - * - */ + /** - * \brief AdherentOptions - * \param DB base de donnees - * \param id id de l'adherent + * Constructor + * @param DB base de donnees */ - function AdherentOptions($DB, $id='') + function ExtraFields($DB) { $this->db = $DB ; - $this->id = $id; $this->error = array(); $this->attribute_type = array(); $this->attribute_label = array(); $this->attribute_size = array(); + $this->attribute_elementtype = array(); } /** @@ -69,13 +64,26 @@ class AdherentOptions * @param attrname code of attribute * @param type Type of attribute ('int', 'text', 'varchar', 'date', 'datehour') * @param length Size/length of attribute + * @param elementtype Element type ('member', 'product', 'company', ...) + * @return int <=0 if KO, >0 if OK */ - function create($attrname,$type='varchar',$length=255) { + function create($attrname,$type='varchar',$length=255,$elementtype='member') + { + $table=''; + if ($elementtype == 'member') $table='adherent_extrafields'; + if ($elementtype == 'company') $table='societe_extrafields'; + if ($elementtype == 'contact') $table='socpeople_extrafields'; + if ($elementtype == 'product') $table='product_extrafields'; + if (empty($table)) + { + print 'ErrorBarValueForParameters'; + return -1; + } 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_extrafields', $attrname, $field_desc); + $result=$this->db->DDLAddField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); if ($result > 0) { return 1; @@ -99,7 +107,7 @@ 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', ...) + * @param elementtype Element type ('member', 'product', 'company', ...) * @return int <=0 if KO, >0 if OK */ function create_label($attrname,$label='',$type='',$pos=0,$size=0, $elementtype='member') @@ -118,11 +126,11 @@ class AdherentOptions $sql.= " '".$type."',"; $sql.= " '".$pos."',"; $sql.= " '".$size."',"; - $sql.= " ".$conf->entity; - $sql.= ", '".$elementtype."'"; + $sql.= " ".$conf->entity.","; + $sql.= " '".$elementtype."'"; $sql.=')'; - dol_syslog("AdherentOptions::create_label sql=".$sql); + dol_syslog(get_class($this)."::create_label sql=".$sql); if ($this->db->query($sql)) { return 1; @@ -137,18 +145,30 @@ class AdherentOptions /** * Delete an optionnal attribute - * @param attrname Code of attribute to delete - * TODO This does not work with multicompany module + * @param attrname Code of attribute to delete + * @param elementtype Element type ('member', 'product', 'company', ...) + * @return int < 0 if KO, 0 if nothing is done, 1 if OK */ - function delete($attrname) + function delete($attrname,$elementtype='member') { + $table=''; + if ($elementtype == 'member') $table='adherent_extrafields'; + if ($elementtype == 'company') $table='societe_extrafields'; + if ($elementtype == 'contact') $table='socpeople_extrafields'; + if ($elementtype == 'product') $table='product_extrafields'; + if (empty($table)) + { + print 'ErrorBarValueForParameters'; + return -1; + } + if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) { - $result=$this->db->DDLDropField(MAIN_DB_PREFIX."adherent_extrafields",$attrname); + $result=$this->db->DDLDropField(MAIN_DB_PREFIX.$table,$attrname); if ($result < 0) { $this->error=$this->db->lasterror(); - dol_syslog("AdherentOption::delete ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR); } $result=$this->delete_label($attrname); @@ -165,18 +185,21 @@ class AdherentOptions /** * Delete description of an optionnal attribute * @param attrname Code of attribute to delete + * @param elementtype Element type ('member', 'product', 'company', ...) + * @return int < 0 if KO, 0 if nothing is done, 1 if OK */ - function delete_label($attrname) + function delete_label($attrname,$elementtype='member') { global $conf; if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."extrafields"; - $sql.= " WHERE name = '$attrname'"; + $sql.= " WHERE name = '".$attrname."'"; $sql.= " AND entity = ".$conf->entity; + $sql.= " AND elementtype = '".$elementtype."'"; - dol_syslog("AdherentOptions::delete_label sql=".$sql); + dol_syslog(get_class($this)."::delete_label sql=".$sql); if ( $this->db->query( $sql) ) { return 1; @@ -184,7 +207,7 @@ class AdherentOptions else { print dol_print_error($this->db); - return 0; + return -1; } } else @@ -199,15 +222,26 @@ class AdherentOptions * @param attrname name of attribute * @param type type of attribute * @param length length of attribute + * @param elementtype Element type ('member', 'product', 'company', ...) * @return int >0 if OK, <=0 if KO - * TODO This does not works with mutlicompany module */ - function update($attrname,$type='varchar',$length=255) + function update($attrname,$type='varchar',$length=255,$elementtype='member') { - if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) + $table=''; + if ($elementtype == 'member') $table='adherent_extrafields'; + if ($elementtype == 'company') $table='societe_extrafields'; + if ($elementtype == 'contact') $table='socpeople_extrafields'; + if ($elementtype == 'product') $table='product_extrafields'; + if (empty($table)) + { + print 'ErrorBarValueForParameters'; + return -1; + } + + 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.'extrafields', $attrname, $field_desc); + $result=$this->db->DDLUpdateField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); if ($result > 0) { return 1; @@ -226,17 +260,17 @@ class AdherentOptions } /** - * Modify description of an optionnal attribute - * @param attrname nom de l'atribut - * @param label nom du label - * @param type type - * @param size size - * @param elementtype Element type ('member', 'product', ...) - */ + * Modify description of personalized attribute + * @param attrname name of attribute + * @param label label of attribute + * @param type type of attribute + * @param length length of attribute + * @param elementtype Element type ('member', 'product', 'company', ...) + */ function update_label($attrname,$label,$type,$size,$elementtype='member') { global $conf; - dol_syslog("AdherentOptions::update_label $attrname,$label,$type,$size"); + dol_syslog(get_class($this)."::update_label $attrname,$label,$type,$size"); if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) { @@ -246,7 +280,7 @@ class AdherentOptions $sql_del.= " WHERE name = '".$attrname."'"; $sql_del.= " AND entity = ".$conf->entity; $sql_del.= " AND elementtype = '".$elementtype."'"; - dol_syslog("AdherentOptions::update_label sql=".$sql_del); + dol_syslog(get_class($this)."::update_label sql=".$sql_del); $resql1=$this->db->query($sql_del); $sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields("; @@ -254,7 +288,8 @@ class AdherentOptions $sql.= " entity,"; $sql.= " label,"; $sql.= " type,"; - $sql.= " size"; + $sql.= " size,"; + $sql.= " elementtype"; $sql.= ") VALUES ("; $sql.= "'".$attrname."',"; $sql.= " ".$conf->entity.","; @@ -263,7 +298,7 @@ class AdherentOptions $sql.= " '".$size."',"; $sql.= " '".$elementtype."'"; $sql.= ")"; - dol_syslog("AdherentOptions::update_label sql=".$sql); + dol_syslog(get_class($this)."::update_label sql=".$sql); $resql2=$this->db->query($sql); if ($resql1 && $resql2) @@ -287,7 +322,7 @@ class AdherentOptions /** - * \brief fonction qui modifie un label + * Load array of labels */ function fetch_optionals() { @@ -296,7 +331,7 @@ class AdherentOptions /** - * \brief Load array this->attribute_label + * Load array this->attribute_label */ function fetch_name_optionals_label($elementtype='member') { @@ -310,7 +345,7 @@ class AdherentOptions if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'"; $sql.= " ORDER BY pos"; - dol_syslog("Adherent_options::fetch_name_optionals_label sql=".$sql); + dol_syslog(get_class($this)."::fetch_name_optionals_label sql=".$sql); $resql=$this->db->query($sql); if ($resql) { diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 25c40e82623..3d97c4dc1f8 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -239,7 +239,7 @@ if (! empty($conf->file->main_force_https)) // Chargement des includes complementaires de presentation if (! defined('NOREQUIREMENU')) require_once(DOL_DOCUMENT_ROOT ."/core/class/menu.class.php"); // Need 10ko memory (11ko in 2.2) -if (! defined('NOREQUIREHTML')) require_once(DOL_DOCUMENT_ROOT ."/core/class/html.form.class.php"); // Need 660ko memory (800ko in 2.2) +if (! defined('NOREQUIREHTML')) require_once(DOL_DOCUMENT_ROOT ."/core/class/html.form.class.php"); // Need 660ko memory (800ko in 2.2) if (! defined('NOREQUIREAJAX') && $conf->use_javascript_ajax) require_once(DOL_DOCUMENT_ROOT.'/lib/ajax.lib.php'); // Need 22ko memory //dol_stopwithmem(); diff --git a/htdocs/public/members/new.php b/htdocs/public/members/new.php index 192af5d1c3e..64c9a99f49b 100644 --- a/htdocs/public/members/new.php +++ b/htdocs/public/members/new.php @@ -31,8 +31,7 @@ define("NOCSRFCHECK",1); // We accept to go on this page from external web site. require("../../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php"); -require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent_options.class.php"); -require_once(DOL_DOCUMENT_ROOT."/core/class/html.form.class.php"); +require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php"); // Security check if (empty($conf->adherent->enabled)) accessforbidden('',1,1,1); @@ -217,7 +216,7 @@ if (isset($_GET["action"]) && $_GET["action"] == 'added') $html = new Form($db); $adht = new AdherentType($db); -$adho = new AdherentOptions($db); +$adho = new ExtraFields($db); llxHeaderVierge($langs->trans("NewSubscription")); diff --git a/htdocs/public/members/public_card.php b/htdocs/public/members/public_card.php index 4b3489c7a16..72db8f68fb1 100644 --- a/htdocs/public/members/public_card.php +++ b/htdocs/public/members/public_card.php @@ -1,7 +1,7 @@ <?php /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org> - * Copyright (C) 2007-2009 Laurent Destailleur <eldy@users.sourceforge.net> + * Copyright (C) 2007-2011 Laurent Destailleur <eldy@users.sourceforge.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,7 +31,7 @@ define("NOCSRFCHECK",1); // We accept to go on this page from external web site. require("../../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php"); -require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent_options.class.php"); +require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php"); // Security check if (empty($conf->adherent->enabled)) accessforbidden('',1,1,1); @@ -42,9 +42,15 @@ $langs->load("members"); $langs->load("companies"); $langs->load("other"); - $rowid=$_GET["id"]; -$adho = new AdherentOptions($db); +$adho = new ExtraFields($db); + + +/* + * Actions + */ + +// None /* -- GitLab