From 3428bba405986ca5120e9a3937bfa95358e3ef82 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 7 Nov 2009 10:34:25 +0000 Subject: [PATCH] Works on multicompany module Fix: uniformize code --- htdocs/adherents/adherent.class.php | 63 ++++--- htdocs/adherents/adherent_options.class.php | 182 +++++++++++--------- htdocs/adherents/adherent_type.class.php | 91 +++++----- htdocs/adherents/cotisation.class.php | 8 +- 4 files changed, 201 insertions(+), 143 deletions(-) diff --git a/htdocs/adherents/adherent.class.php b/htdocs/adherents/adherent.class.php index 368d8d4ead2..ff831ea17e8 100644 --- a/htdocs/adherents/adherent.class.php +++ b/htdocs/adherents/adherent.class.php @@ -4,6 +4,7 @@ * Copyright (C) 2004-2009 Laurent Destailleur * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2009 Regis Houssin * * 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 @@ -273,13 +274,14 @@ class Adherent extends CommonObject // Insert member $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent"; - $sql.= " (datec,login,fk_user_author,fk_user_mod,fk_user_valid,morphy,fk_adherent_type)"; + $sql.= " (datec,login,fk_user_author,fk_user_mod,fk_user_valid,morphy,fk_adherent_type,entity)"; $sql.= " VALUES ("; - $sql.= " '".$this->db->idate($this->datec)."',"; - $sql.= " '".$this->login."',"; - $sql.= " ".($user->id>0?$user->id:"null").","; // Can be null because member can be create by a guest or a script - $sql.= " null,null,'".$this->morphy."',"; - $sql.= " '".$this->typeid."'"; + $sql.= " '".$this->db->idate($this->datec)."'"; + $sql.= ", '".$this->login."'"; + $sql.= ", ".($user->id>0?$user->id:"null"); // Can be null because member can be create by a guest or a script + $sql.= ", null, null, '".$this->morphy."'"; + $sql.= ", '".$this->typeid."'"; + $sql.= ", ".$conf->entity; $sql.= ")"; dol_syslog("Adherent::create sql=".$sql); @@ -474,14 +476,14 @@ class Adherent extends CommonObject // Remove link to user dol_syslog("Adherent::update UPDATE LINK TO USER"); - $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL where fk_member = ".$this->id; + $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".$this->id; dol_syslog("Adherent::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; + $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".$this->id." WHERE rowid = ".$this->user_id; dol_syslog("Adherent::update sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -5; } @@ -570,7 +572,7 @@ class Adherent extends CommonObject /** - \brief Fonction qui met a jour le chp denormalise date fin adh�sion + \brief Fonction qui met a jour le chp denormalise date fin adhesion \param user Utilisateur qui realise la mise a jour \return int <0 si KO, >0 si OK */ @@ -815,7 +817,7 @@ class Adherent extends CommonObject $this->db->begin(); // 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; + $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".$this->id; dol_syslog("Adherent::setUserId sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -1; } @@ -850,7 +852,9 @@ class Adherent extends CommonObject // Update link to third party if ($thirdpartyid > 0) { - $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = null where fk_soc = '".$thirdpartyid."'"; + $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); $resql = $this->db->query($sql); } @@ -882,7 +886,11 @@ class Adherent extends CommonObject */ function fetch_login($login) { - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent WHERE login='$login'"; + global $conf; + + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent"; + $sql.= " WHERE login='".$login."'"; + $sql.= " AND entity = ".$conf->entity; $resql=$this->db->query( $sql); @@ -910,7 +918,7 @@ class Adherent extends CommonObject */ function fetch($rowid,$ref='',$fk_soc='') { - global $langs; + global $conf, $langs; $sql = "SELECT d.rowid, d.prenom, d.nom, d.societe, d.fk_soc, d.statut, d.public, d.adresse, d.cp, d.ville, d.note,"; $sql.= " d.email, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass,"; @@ -928,6 +936,7 @@ class Adherent extends CommonObject $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_pays as p ON d.pays = p.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON d.rowid = u.fk_member"; $sql.= " WHERE d.fk_adherent_type = t.rowid"; + $sql.= " AND d.entity = ".$conf->entity; if ($ref) $sql.= " AND d.rowid='".$ref."'"; elseif ($fk_soc) $sql.= " AND d.fk_soc='".$fk_soc."'"; else $sql.= " AND d.rowid=".$rowid; @@ -1061,7 +1070,7 @@ class Adherent extends CommonObject return -1; } } - + /** * \brief Fonction qui recupere les donnees optionelles de l'adherent @@ -1069,8 +1078,18 @@ class Adherent extends CommonObject */ function fetch_optionals($rowid) { + $options = new AdherentOptions($this->db); + $optionsArray = $options->fetch_name_optionals_label(); + $tab=array(); - $sql = "SELECT *"; // \TODO Should not use this syntax + + $sql = "SELECT optid"; + + foreach ($optionsArray as $name => $label) + { + $sql.= ", ".$name; + } + $sql.= " FROM ".MAIN_DB_PREFIX."adherent_options"; $sql.= " WHERE adhid=".$rowid; @@ -1246,8 +1265,9 @@ class Adherent extends CommonObject $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET"; - $sql.= " statut=1, datevalid = ".$this->db->idate(mktime()).","; - $sql.= " fk_user_valid=".$user->id; + $sql.= " statut = 1"; + $sql.= ", datevalid = ".$this->db->idate(mktime()); + $sql.= ", fk_user_valid=".$user->id; $sql.= " WHERE rowid = ".$this->id; dol_syslog("Adherent::validate sql=".$sql); @@ -1295,8 +1315,8 @@ class Adherent extends CommonObject $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET"; - $sql.= " statut=0,"; - $sql.= " fk_user_valid=".$user->id; + $sql.= " statut = 0"; + $sql.= ", fk_user_valid=".$user->id; $sql.= " WHERE rowid = ".$this->id; $result = $this->db->query($sql); @@ -1811,6 +1831,8 @@ class Adherent extends CommonObject $sql = "SELECT count(a.rowid) as nb"; $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a"; $sql.= " WHERE a.statut > 0"; + $sql.= " AND a.entity = ".$conf->entity; + $resql=$this->db->query($sql); if ($resql) { @@ -1846,7 +1868,8 @@ class Adherent extends CommonObject $sql = "SELECT a.rowid, a.datefin"; $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a"; - $sql.= " WHERE a.statut=1"; + $sql.= " WHERE a.statut = 1"; + $sql.= " AND a.entity = ".$conf->entity; $resql=$this->db->query($sql); if ($resql) diff --git a/htdocs/adherents/adherent_options.class.php b/htdocs/adherents/adherent_options.class.php index 152548dbfc3..9c96d1f8639 100644 --- a/htdocs/adherents/adherent_options.class.php +++ b/htdocs/adherents/adherent_options.class.php @@ -3,6 +3,7 @@ * Copyright (C) 2002-2003 Jean-Louis Bergamo * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2009 Regis Houssin * * 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 @@ -34,15 +35,9 @@ class AdherentOptions { var $id; var $db; - /* - * Tableau contenant le nom des champs en clef et la definition de - * ces champs - */ + // Tableau contenant le nom des champs en clef et la definition de ces champs var $attribute_name; - /* - * Tableau contenant le nom des champs en clef et le label de ces - * champs en value - */ + // Tableau contenant le nom des champs en clef et le label de ces champs en value var $attribute_label; var $error; @@ -51,12 +46,11 @@ class AdherentOptions * */ - /*! - \brief AdherentOptions - \param DB base de donn�es - \param id id de l'adh�rent - */ - + /** + * \brief AdherentOptions + * \param DB base de donnees + * \param id id de l'adherent + */ function AdherentOptions($DB, $id='') { $this->db = $DB ; @@ -66,9 +60,9 @@ class AdherentOptions $this->attribute_label = array(); } - /*! - \brief fonction qui imprime un liste d'erreurs - */ + /** + * \brief fonction qui imprime un liste d'erreurs + */ function print_error_list() { $num = sizeof($this->error); @@ -78,54 +72,49 @@ class AdherentOptions } } - /*! - \brief fonction qui v�rifie les donn�es entr�es - \param minimum - */ + /** + * \brief fonction qui verifie les donnees entrees + * \param minimum + */ function check($minimum=0) { $err = 0; if (strlen(trim($this->societe)) == 0) { - if ((strlen(trim($this->nom)) + strlen(trim($this->prenom))) == 0) - { - $error_string[$err] = "Vous devez saisir vos nom et pr�nom ou le nom de votre soci�t�."; - $err++; - } + if ((strlen(trim($this->nom)) + strlen(trim($this->prenom))) == 0) + { + $error_string[$err] = "Vous devez saisir vos nom et prenom ou le nom de votre societe."; + $err++; + } } if (strlen(trim($this->adresse)) == 0) { - $error_string[$err] = "L'adresse saisie est invalide"; - $err++; + $error_string[$err] = "L'adresse saisie est invalide"; + $err++; } - - /* - * Return errors - * - */ - + + // Return errors if ($err) { - $this->error = $error_string; - return 0; + $this->error = $error_string; + return 0; } else { - return 1; + return 1; } } /** - \brief fonction qui cr�e un attribut optionnel - \param attrname nom de l'atribut - \param type type de l'attribut - \param length longuer de l'attribut - - \remarks Ceci correspond a une modification de la table et pas a un rajout d'enregistrement - */ + * \brief fonction qui cree un attribut optionnel + * \param attrname nom de l'atribut + * \param type type de l'attribut + * \param length longuer de l'attribut + * \remarks Ceci correspond a une modification de la table et pas a un rajout d'enregistrement + */ function create($attrname,$type='varchar',$length=255) { if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) @@ -168,6 +157,8 @@ class AdherentOptions */ function create_label($attrname,$label='',$type='',$pos=0,$size=0) { + global $conf; + // Clean parameters if (empty($pos)) $pos=0; @@ -175,8 +166,12 @@ class AdherentOptions if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) { $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options_label SET "; - $sql .= " name='$attrname', label='".addslashes($label)."',"; - $sql .= " type='".$type."', pos='".$pos."', size='".$size."'"; + $sql.= " name = '".$attrname."'"; + $sql.= ", label = '".addslashes($label)."'"; + $sql.= ", type = '".$type."'"; + $sql.= ", pos = '".$pos."'"; + $sql.= ", size = '".$size."'"; + $sql.= ", entity = ".$conf->entity; dol_syslog("AdherentOptions::create_label sql=".$sql); if ($this->db->query($sql)) @@ -194,6 +189,7 @@ class AdherentOptions /** * \brief Fonction qui supprime un attribut * \param attrname nom de l'atribut + * \TODO pouvoir gerer les entités */ function delete($attrname) { @@ -223,8 +219,13 @@ class AdherentOptions */ function delete_label($attrname) { - if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)){ - $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options_label WHERE name='$attrname'"; + global $conf; + + if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options_label"; + $sql.= " WHERE name = '$attrname'"; + $sql.= " AND entity = ".$conf->entity; if ( $this->db->query( $sql) ) { @@ -235,21 +236,25 @@ class AdherentOptions print dol_print_error($this->db); return 0; } - }else{ + } + else + { return 0; } } /** - \brief fonction qui modifie un attribut optionnel - \param attrname nom de l'atribut - \param type type de l'attribut - \param length longuer de l'attribut - */ + * \brief fonction qui modifie un attribut optionnel + * \param attrname nom de l'atribut + * \param type type de l'attribut + * \param length longuer de l'attribut + * \TODO pouvoir gerer les entités + */ function update($attrname,$type='varchar',$length=255) { - if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)){ + if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) + { $sql = "ALTER TABLE ".MAIN_DB_PREFIX."adherent_options "; switch ($type){ case 'varchar' : @@ -276,26 +281,39 @@ class AdherentOptions print dol_print_error($this->db); return 0; } - }else{ + }else + { return 0; } } - /*! - \brief fonction qui modifie un label - \param attrname nom de l'atribut - \param label nom du label - */ - + /** + * \brief fonction qui modifie un label + * \param attrname nom de l'atribut + * \param label nom du label + */ function update_label($attrname,$label='') { - if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)){ - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options_label WHERE name = - '$attrname';"; + global $conf; + + if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) + { + $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options_label"; + $sql_del.= " WHERE name = '".$attrname."'"; + $sql_del.= " AND entity = ".$conf->entity; + $this->db->query($sql_del); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options_label (name,label) - VALUES ('$attrname','".addslashes($escaped_label)."')"; + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options_label ("; + $sql.= "name"; + $sql.= ", label"; + $sql.= ", entity"; + $sql.= ") VALUES ("; + $sql.= "'".$attrname."'"; + $sql.= ", '".addslashes($escaped_label)."'"; + $sql.= ", ".$conf->entity; + $sql.= ")"; //$sql = "REPLACE INTO ".MAIN_DB_PREFIX."adherent_options_label SET name='$attrname',label='$escaped_label'"; if ( $this->db->query( $sql) ) @@ -307,16 +325,18 @@ class AdherentOptions print dol_print_error($this->db); return 0; } - }else{ + } + else + { return 0; } } - /*! - \brief fonction qui modifie un label - */ + /** + * \brief fonction qui modifie un label + */ function fetch_optionals() { $this->fetch_name_optionals_label(); @@ -328,8 +348,13 @@ class AdherentOptions */ function fetch_name_optionals_label() { + global $conf; + $array_name_label=array(); - $sql = "SELECT name,label,type FROM ".MAIN_DB_PREFIX."adherent_options_label"; + + $sql = "SELECT name,label,type"; + $sql.= " FROM ".MAIN_DB_PREFIX."adherent_options_label"; + $sql.= " WHERE entity = ".$conf->entity; $sql.= " ORDER BY pos"; dol_syslog("Adherent_options::fetch_name_optionals_label"); @@ -345,15 +370,14 @@ class AdherentOptions $this->attribute_name[$tab->name]=$tab->type; $this->attribute_label[$tab->name]=$tab->label; } - return $array_name_label; - }else{ - return array(); } - }else{ - print dol_print_error($this->db); - return array() ; + return $array_name_label; + } + else + { + print dol_print_error($this->db); } - } + } ?> diff --git a/htdocs/adherents/adherent_type.class.php b/htdocs/adherents/adherent_type.class.php index 6fcadb9c0a8..4548c5a542f 100644 --- a/htdocs/adherents/adherent_type.class.php +++ b/htdocs/adherents/adherent_type.class.php @@ -1,6 +1,7 @@ * Copyright (C) 2004-2008 Laurent Destailleur + * Copyright (C) 2009 Regis Houssin * * 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 @@ -42,16 +43,16 @@ class AdherentType extends CommonObject var $id; var $libelle; var $statut; - var $cotisation; /**< Soumis � la cotisation */ - var $vote; /**< droit de vote ? */ - var $note; /**< commentaire */ - var $mail_valid; /**< mail envoye lors de la validation */ + var $cotisation; // Soumis a la cotisation + var $vote; // droit de vote + var $note; // commentaire + var $mail_valid; //mail envoye lors de la validation /** - \brief AdherentType - \param DB handler acc�s base de donn�es + * \brief AdherentType + * \param DB handler acces base de donnees */ function AdherentType($DB) { @@ -61,9 +62,8 @@ class AdherentType extends CommonObject /** - \brief print_error_list - */ - + * \brief print_error_list + */ function print_error_list() { $num = sizeof($this->error); @@ -75,16 +75,23 @@ class AdherentType extends CommonObject /** - \brief Fonction qui permet de cr�er le status de l'adh�rent - \param userid userid de l'adh�rent - \return > 0 si ok, < 0 si ko + * \brief Fonction qui permet de creer le status de l'adherent + * \param userid userid de l'adherent + * \return > 0 si ok, < 0 si ko */ function create($userid) { + global $conf; + $this->statut=trim($this->statut); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type (libelle)"; - $sql.= " VALUES ('".addslashes($this->libelle)."')"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type ("; + $sql.= "libelle"; + $sql.= ", entity"; + $sql.= ") VALUES ("; + $sql.= "'".addslashes($this->libelle)."'"; + $sql.= ", ".$conf->entity; + $sql.= ")"; dol_syslog("Adherent_type::create sql=".$sql); $result = $this->db->query($sql); @@ -102,21 +109,21 @@ class AdherentType extends CommonObject /** - \brief Met a jour en base donn�es du type - \return > 0 si ok, < 0 si ko - */ + * \brief Met a jour en base donnees du type + * \return > 0 si ok, < 0 si ko + */ function update() { $this->libelle=trim($this->libelle); $sql = "UPDATE ".MAIN_DB_PREFIX."adherent_type "; $sql.= "SET "; - $sql.= "statut=".$this->statut.","; + $sql.= "statut = ".$this->statut.","; $sql.= "libelle = '".addslashes($this->libelle) ."',"; - $sql.= "cotisation='".$this->cotisation."',"; - $sql.= "note='".addslashes($this->note)."',"; - $sql.= "vote='".$this->vote."',"; - $sql.= "mail_valid='".addslashes($this->mail_valid)."'"; + $sql.= "cotisation = '".$this->cotisation."',"; + $sql.= "note = '".addslashes($this->note)."',"; + $sql.= "vote = '".$this->vote."',"; + $sql.= "mail_valid = '".addslashes($this->mail_valid)."'"; $sql .= " WHERE rowid = $this->id"; @@ -124,17 +131,17 @@ class AdherentType extends CommonObject if ($result) { - return 1; + return 1; } else { $this->error=$this->db->error().' sql='.$sql; - return -1; + return -1; } } /** - * \brief Fonction qui permet de supprimer le status de l'adh�rent + * \brief Fonction qui permet de supprimer le status de l'adherent * \param rowid */ function delete($rowid) @@ -145,13 +152,13 @@ class AdherentType extends CommonObject if ( $this->db->query( $sql) ) { if ( $this->db->affected_rows() ) - { - return 1; - } - else - { - return 0; - } + { + return 1; + } + else + { + return 0; + } } else { @@ -161,15 +168,16 @@ class AdherentType extends CommonObject } /** - \brief Fonction qui permet de r�cup�rer le status de l'adh�rent - \param rowid - \return int <0 si KO, >0 si OK - */ + * \brief Fonction qui permet de recuperer le status de l'adherent + * \param rowid + * \return int <0 si KO, >0 si OK + */ function fetch($rowid) { $sql = "SELECT d.rowid, d.libelle, d.statut, d.cotisation, d.mail_valid, d.note, d.vote"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d"; $sql .= " WHERE d.rowid = ".$rowid; + dol_syslog("Adherent_type::fetch sql=".$sql); $resql=$this->db->query($sql); @@ -198,15 +206,18 @@ class AdherentType extends CommonObject } /** - * Return list of members' type - * - * @return array List of types + * \brief Return list of members' type + * \return array List of types */ function liste_array() { + global $conf; + $projets = array(); - $sql = "SELECT rowid, libelle FROM ".MAIN_DB_PREFIX."adherent_type"; + $sql = "SELECT rowid, libelle"; + $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type"; + $sql.= "WHERE entity = ".$conf->entity; $resql=$this->db->query($sql); if ($resql) diff --git a/htdocs/adherents/cotisation.class.php b/htdocs/adherents/cotisation.class.php index 7c523bd057a..5f1678ebf00 100644 --- a/htdocs/adherents/cotisation.class.php +++ b/htdocs/adherents/cotisation.class.php @@ -94,10 +94,10 @@ class Cotisation extends CommonObject /** - \brief Fonction qui permet de r�cup�rer une cotisation - \param rowid Id cotisation - \return int <0 si KO, =0 si OK mais non trouve, >0 si OK - */ + * \brief Fonction qui permet de recuperer une cotisation + * \param rowid Id cotisation + * \return int <0 si KO, =0 si OK mais non trouve, >0 si OK + */ function fetch($rowid) { $sql ="SELECT rowid, fk_adherent, ".$this->db->pdate("datec")." as datec,";