Works on multicompany module

Fix: uniformize code
This commit is contained in:
Regis Houssin 2009-11-07 10:34:25 +00:00
parent 0ef7f36b19
commit 3428bba405
4 changed files with 201 additions and 143 deletions

View File

@ -4,6 +4,7 @@
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org> * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -273,13 +274,14 @@ class Adherent extends CommonObject
// Insert member // Insert member
$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent"; $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.= " VALUES (";
$sql.= " '".$this->db->idate($this->datec)."',"; $sql.= " '".$this->db->idate($this->datec)."'";
$sql.= " '".$this->login."',"; $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.= ", ".($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.= ", null, null, '".$this->morphy."'";
$sql.= " '".$this->typeid."'"; $sql.= ", '".$this->typeid."'";
$sql.= ", ".$conf->entity;
$sql.= ")"; $sql.= ")";
dol_syslog("Adherent::create sql=".$sql); dol_syslog("Adherent::create sql=".$sql);
@ -474,14 +476,14 @@ class Adherent extends CommonObject
// Remove link to user // Remove link to user
dol_syslog("Adherent::update UPDATE 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); dol_syslog("Adherent::update sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -5; } if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -5; }
// If there is a user linked to this member // If there is a user linked to this member
if ($this->user_id > 0) 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); dol_syslog("Adherent::update sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -5; } 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<EFBFBD>sion \brief Fonction qui met a jour le chp denormalise date fin adhesion
\param user Utilisateur qui realise la mise a jour \param user Utilisateur qui realise la mise a jour
\return int <0 si KO, >0 si OK \return int <0 si KO, >0 si OK
*/ */
@ -815,7 +817,7 @@ class Adherent extends CommonObject
$this->db->begin(); $this->db->begin();
// If user is linked to this member, remove old link to this member // 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); dol_syslog("Adherent::setUserId sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -1; } 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 // Update link to third party
if ($thirdpartyid > 0) 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); dol_syslog("Adherent::setThirdPartyId sql=".$sql);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
} }
@ -882,7 +886,11 @@ class Adherent extends CommonObject
*/ */
function fetch_login($login) 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); $resql=$this->db->query( $sql);
@ -910,7 +918,7 @@ class Adherent extends CommonObject
*/ */
function fetch($rowid,$ref='',$fk_soc='') 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 = "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,"; $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."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.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON d.rowid = u.fk_member";
$sql.= " WHERE d.fk_adherent_type = t.rowid"; $sql.= " WHERE d.fk_adherent_type = t.rowid";
$sql.= " AND d.entity = ".$conf->entity;
if ($ref) $sql.= " AND d.rowid='".$ref."'"; if ($ref) $sql.= " AND d.rowid='".$ref."'";
elseif ($fk_soc) $sql.= " AND d.fk_soc='".$fk_soc."'"; elseif ($fk_soc) $sql.= " AND d.fk_soc='".$fk_soc."'";
else $sql.= " AND d.rowid=".$rowid; else $sql.= " AND d.rowid=".$rowid;
@ -1061,7 +1070,7 @@ class Adherent extends CommonObject
return -1; return -1;
} }
} }
/** /**
* \brief Fonction qui recupere les donnees optionelles de l'adherent * \brief Fonction qui recupere les donnees optionelles de l'adherent
@ -1069,8 +1078,18 @@ class Adherent extends CommonObject
*/ */
function fetch_optionals($rowid) function fetch_optionals($rowid)
{ {
$options = new AdherentOptions($this->db);
$optionsArray = $options->fetch_name_optionals_label();
$tab=array(); $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.= " FROM ".MAIN_DB_PREFIX."adherent_options";
$sql.= " WHERE adhid=".$rowid; $sql.= " WHERE adhid=".$rowid;
@ -1246,8 +1265,9 @@ class Adherent extends CommonObject
$this->db->begin(); $this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
$sql.= " statut=1, datevalid = ".$this->db->idate(mktime()).","; $sql.= " statut = 1";
$sql.= " fk_user_valid=".$user->id; $sql.= ", datevalid = ".$this->db->idate(mktime());
$sql.= ", fk_user_valid=".$user->id;
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;
dol_syslog("Adherent::validate sql=".$sql); dol_syslog("Adherent::validate sql=".$sql);
@ -1295,8 +1315,8 @@ class Adherent extends CommonObject
$this->db->begin(); $this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
$sql.= " statut=0,"; $sql.= " statut = 0";
$sql.= " fk_user_valid=".$user->id; $sql.= ", fk_user_valid=".$user->id;
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;
$result = $this->db->query($sql); $result = $this->db->query($sql);
@ -1811,6 +1831,8 @@ class Adherent extends CommonObject
$sql = "SELECT count(a.rowid) as nb"; $sql = "SELECT count(a.rowid) as nb";
$sql.= " FROM ".MAIN_DB_PREFIX."adherent as a"; $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a";
$sql.= " WHERE a.statut > 0"; $sql.= " WHERE a.statut > 0";
$sql.= " AND a.entity = ".$conf->entity;
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -1846,7 +1868,8 @@ class Adherent extends CommonObject
$sql = "SELECT a.rowid, a.datefin"; $sql = "SELECT a.rowid, a.datefin";
$sql.= " FROM ".MAIN_DB_PREFIX."adherent as a"; $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); $resql=$this->db->query($sql);
if ($resql) if ($resql)

View File

@ -3,6 +3,7 @@
* Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org> * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org> * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -34,15 +35,9 @@ class AdherentOptions
{ {
var $id; var $id;
var $db; 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; 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 $attribute_label;
var $error; var $error;
@ -51,12 +46,11 @@ class AdherentOptions
* *
*/ */
/*! /**
\brief AdherentOptions * \brief AdherentOptions
\param DB base de donn<EFBFBD>es * \param DB base de donnees
\param id id de l'adh<EFBFBD>rent * \param id id de l'adherent
*/ */
function AdherentOptions($DB, $id='') function AdherentOptions($DB, $id='')
{ {
$this->db = $DB ; $this->db = $DB ;
@ -66,9 +60,9 @@ class AdherentOptions
$this->attribute_label = array(); $this->attribute_label = array();
} }
/*! /**
\brief fonction qui imprime un liste d'erreurs * \brief fonction qui imprime un liste d'erreurs
*/ */
function print_error_list() function print_error_list()
{ {
$num = sizeof($this->error); $num = sizeof($this->error);
@ -78,54 +72,49 @@ class AdherentOptions
} }
} }
/*! /**
\brief fonction qui v<EFBFBD>rifie les donn<EFBFBD>es entr<EFBFBD>es * \brief fonction qui verifie les donnees entrees
\param minimum * \param minimum
*/ */
function check($minimum=0) function check($minimum=0)
{ {
$err = 0; $err = 0;
if (strlen(trim($this->societe)) == 0) if (strlen(trim($this->societe)) == 0)
{ {
if ((strlen(trim($this->nom)) + strlen(trim($this->prenom))) == 0) if ((strlen(trim($this->nom)) + strlen(trim($this->prenom))) == 0)
{ {
$error_string[$err] = "Vous devez saisir vos nom et pr<EFBFBD>nom ou le nom de votre soci<63>t<EFBFBD>."; $error_string[$err] = "Vous devez saisir vos nom et prenom ou le nom de votre societe.";
$err++; $err++;
} }
} }
if (strlen(trim($this->adresse)) == 0) if (strlen(trim($this->adresse)) == 0)
{ {
$error_string[$err] = "L'adresse saisie est invalide"; $error_string[$err] = "L'adresse saisie est invalide";
$err++; $err++;
} }
/* // Return errors
* Return errors
*
*/
if ($err) if ($err)
{ {
$this->error = $error_string; $this->error = $error_string;
return 0; return 0;
} }
else else
{ {
return 1; return 1;
} }
} }
/** /**
\brief fonction qui cr<EFBFBD>e un attribut optionnel * \brief fonction qui cree un attribut optionnel
\param attrname nom de l'atribut * \param attrname nom de l'atribut
\param type type de l'attribut * \param type type de l'attribut
\param length longuer 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
\remarks Ceci correspond a une modification de la table et pas a un rajout d'enregistrement */
*/
function create($attrname,$type='varchar',$length=255) { function create($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))
@ -168,6 +157,8 @@ class AdherentOptions
*/ */
function create_label($attrname,$label='',$type='',$pos=0,$size=0) function create_label($attrname,$label='',$type='',$pos=0,$size=0)
{ {
global $conf;
// Clean parameters // Clean parameters
if (empty($pos)) $pos=0; if (empty($pos)) $pos=0;
@ -175,8 +166,12 @@ class AdherentOptions
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 = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options_label SET "; $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options_label SET ";
$sql .= " name='$attrname', label='".addslashes($label)."',"; $sql.= " name = '".$attrname."'";
$sql .= " type='".$type."', pos='".$pos."', size='".$size."'"; $sql.= ", label = '".addslashes($label)."'";
$sql.= ", type = '".$type."'";
$sql.= ", pos = '".$pos."'";
$sql.= ", size = '".$size."'";
$sql.= ", entity = ".$conf->entity;
dol_syslog("AdherentOptions::create_label sql=".$sql); dol_syslog("AdherentOptions::create_label sql=".$sql);
if ($this->db->query($sql)) if ($this->db->query($sql))
@ -194,6 +189,7 @@ class AdherentOptions
/** /**
* \brief Fonction qui supprime un attribut * \brief Fonction qui supprime un attribut
* \param attrname nom de l'atribut * \param attrname nom de l'atribut
* \TODO pouvoir gerer les entités
*/ */
function delete($attrname) function delete($attrname)
{ {
@ -223,8 +219,13 @@ class AdherentOptions
*/ */
function delete_label($attrname) function delete_label($attrname)
{ {
if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)){ global $conf;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options_label WHERE name='$attrname'";
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) ) if ( $this->db->query( $sql) )
{ {
@ -235,21 +236,25 @@ class AdherentOptions
print dol_print_error($this->db); print dol_print_error($this->db);
return 0; return 0;
} }
}else{ }
else
{
return 0; return 0;
} }
} }
/** /**
\brief fonction qui modifie un attribut optionnel * \brief fonction qui modifie un attribut optionnel
\param attrname nom de l'atribut * \param attrname nom de l'atribut
\param type type de l'attribut * \param type type de l'attribut
\param length longuer de l'attribut * \param length longuer de l'attribut
*/ * \TODO pouvoir gerer les entités
*/
function update($attrname,$type='varchar',$length=255) 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 "; $sql = "ALTER TABLE ".MAIN_DB_PREFIX."adherent_options ";
switch ($type){ switch ($type){
case 'varchar' : case 'varchar' :
@ -276,26 +281,39 @@ class AdherentOptions
print dol_print_error($this->db); print dol_print_error($this->db);
return 0; return 0;
} }
}else{ }else
{
return 0; return 0;
} }
} }
/*! /**
\brief fonction qui modifie un label * \brief fonction qui modifie un label
\param attrname nom de l'atribut * \param attrname nom de l'atribut
\param label nom du label * \param label nom du label
*/ */
function update_label($attrname,$label='') function update_label($attrname,$label='')
{ {
if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)){ global $conf;
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options_label WHERE name =
'$attrname';"; 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); $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'"; //$sql = "REPLACE INTO ".MAIN_DB_PREFIX."adherent_options_label SET name='$attrname',label='$escaped_label'";
if ( $this->db->query( $sql) ) if ( $this->db->query( $sql) )
@ -307,16 +325,18 @@ class AdherentOptions
print dol_print_error($this->db); print dol_print_error($this->db);
return 0; return 0;
} }
}else{ }
else
{
return 0; return 0;
} }
} }
/*! /**
\brief fonction qui modifie un label * \brief fonction qui modifie un label
*/ */
function fetch_optionals() function fetch_optionals()
{ {
$this->fetch_name_optionals_label(); $this->fetch_name_optionals_label();
@ -328,8 +348,13 @@ class AdherentOptions
*/ */
function fetch_name_optionals_label() function fetch_name_optionals_label()
{ {
global $conf;
$array_name_label=array(); $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"; $sql.= " ORDER BY pos";
dol_syslog("Adherent_options::fetch_name_optionals_label"); dol_syslog("Adherent_options::fetch_name_optionals_label");
@ -345,15 +370,14 @@ class AdherentOptions
$this->attribute_name[$tab->name]=$tab->type; $this->attribute_name[$tab->name]=$tab->type;
$this->attribute_label[$tab->name]=$tab->label; $this->attribute_label[$tab->name]=$tab->label;
} }
return $array_name_label;
}else{
return array();
} }
}else{ return $array_name_label;
print dol_print_error($this->db); }
return array() ; else
{
print dol_print_error($this->db);
} }
} }
} }
?> ?>

View File

@ -1,6 +1,7 @@
<?php <?php
/* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2008 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 * 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 * it under the terms of the GNU General Public License as published by
@ -42,16 +43,16 @@ class AdherentType extends CommonObject
var $id; var $id;
var $libelle; var $libelle;
var $statut; var $statut;
var $cotisation; /**< Soumis <20> la cotisation */ var $cotisation; // Soumis a la cotisation
var $vote; /**< droit de vote ? */ var $vote; // droit de vote
var $note; /**< commentaire */ var $note; // commentaire
var $mail_valid; /**< mail envoye lors de la validation */ var $mail_valid; //mail envoye lors de la validation
/** /**
\brief AdherentType * \brief AdherentType
\param DB handler acc<EFBFBD>s base de donn<EFBFBD>es * \param DB handler acces base de donnees
*/ */
function AdherentType($DB) function AdherentType($DB)
{ {
@ -61,9 +62,8 @@ class AdherentType extends CommonObject
/** /**
\brief print_error_list * \brief print_error_list
*/ */
function print_error_list() function print_error_list()
{ {
$num = sizeof($this->error); $num = sizeof($this->error);
@ -75,16 +75,23 @@ class AdherentType extends CommonObject
/** /**
\brief Fonction qui permet de cr<EFBFBD>er le status de l'adh<EFBFBD>rent * \brief Fonction qui permet de creer le status de l'adherent
\param userid userid de l'adh<EFBFBD>rent * \param userid userid de l'adherent
\return > 0 si ok, < 0 si ko * \return > 0 si ok, < 0 si ko
*/ */
function create($userid) function create($userid)
{ {
global $conf;
$this->statut=trim($this->statut); $this->statut=trim($this->statut);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type (libelle)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type (";
$sql.= " VALUES ('".addslashes($this->libelle)."')"; $sql.= "libelle";
$sql.= ", entity";
$sql.= ") VALUES (";
$sql.= "'".addslashes($this->libelle)."'";
$sql.= ", ".$conf->entity;
$sql.= ")";
dol_syslog("Adherent_type::create sql=".$sql); dol_syslog("Adherent_type::create sql=".$sql);
$result = $this->db->query($sql); $result = $this->db->query($sql);
@ -102,21 +109,21 @@ class AdherentType extends CommonObject
/** /**
\brief Met a jour en base donn<EFBFBD>es du type * \brief Met a jour en base donnees du type
\return > 0 si ok, < 0 si ko * \return > 0 si ok, < 0 si ko
*/ */
function update() function update()
{ {
$this->libelle=trim($this->libelle); $this->libelle=trim($this->libelle);
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent_type "; $sql = "UPDATE ".MAIN_DB_PREFIX."adherent_type ";
$sql.= "SET "; $sql.= "SET ";
$sql.= "statut=".$this->statut.","; $sql.= "statut = ".$this->statut.",";
$sql.= "libelle = '".addslashes($this->libelle) ."',"; $sql.= "libelle = '".addslashes($this->libelle) ."',";
$sql.= "cotisation='".$this->cotisation."',"; $sql.= "cotisation = '".$this->cotisation."',";
$sql.= "note='".addslashes($this->note)."',"; $sql.= "note = '".addslashes($this->note)."',";
$sql.= "vote='".$this->vote."',"; $sql.= "vote = '".$this->vote."',";
$sql.= "mail_valid='".addslashes($this->mail_valid)."'"; $sql.= "mail_valid = '".addslashes($this->mail_valid)."'";
$sql .= " WHERE rowid = $this->id"; $sql .= " WHERE rowid = $this->id";
@ -124,17 +131,17 @@ class AdherentType extends CommonObject
if ($result) if ($result)
{ {
return 1; return 1;
} }
else else
{ {
$this->error=$this->db->error().' sql='.$sql; $this->error=$this->db->error().' sql='.$sql;
return -1; return -1;
} }
} }
/** /**
* \brief Fonction qui permet de supprimer le status de l'adh<EFBFBD>rent * \brief Fonction qui permet de supprimer le status de l'adherent
* \param rowid * \param rowid
*/ */
function delete($rowid) function delete($rowid)
@ -145,13 +152,13 @@ class AdherentType extends CommonObject
if ( $this->db->query( $sql) ) if ( $this->db->query( $sql) )
{ {
if ( $this->db->affected_rows() ) if ( $this->db->affected_rows() )
{ {
return 1; return 1;
} }
else else
{ {
return 0; return 0;
} }
} }
else else
{ {
@ -161,15 +168,16 @@ class AdherentType extends CommonObject
} }
/** /**
\brief Fonction qui permet de r<EFBFBD>cup<EFBFBD>rer le status de l'adh<EFBFBD>rent * \brief Fonction qui permet de recuperer le status de l'adherent
\param rowid * \param rowid
\return int <0 si KO, >0 si OK * \return int <0 si KO, >0 si OK
*/ */
function fetch($rowid) function fetch($rowid)
{ {
$sql = "SELECT d.rowid, d.libelle, d.statut, d.cotisation, d.mail_valid, d.note, d.vote"; $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 .= " FROM ".MAIN_DB_PREFIX."adherent_type as d";
$sql .= " WHERE d.rowid = ".$rowid; $sql .= " WHERE d.rowid = ".$rowid;
dol_syslog("Adherent_type::fetch sql=".$sql); dol_syslog("Adherent_type::fetch sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
@ -198,15 +206,18 @@ class AdherentType extends CommonObject
} }
/** /**
* Return list of members' type * \brief Return list of members' type
* * \return array List of types
* @return array List of types
*/ */
function liste_array() function liste_array()
{ {
global $conf;
$projets = array(); $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); $resql=$this->db->query($sql);
if ($resql) if ($resql)

View File

@ -94,10 +94,10 @@ class Cotisation extends CommonObject
/** /**
\brief Fonction qui permet de r<EFBFBD>cup<EFBFBD>rer une cotisation * \brief Fonction qui permet de recuperer une cotisation
\param rowid Id cotisation * \param rowid Id cotisation
\return int <0 si KO, =0 si OK mais non trouve, >0 si OK * \return int <0 si KO, =0 si OK mais non trouve, >0 si OK
*/ */
function fetch($rowid) function fetch($rowid)
{ {
$sql ="SELECT rowid, fk_adherent, ".$this->db->pdate("datec")." as datec,"; $sql ="SELECT rowid, fk_adherent, ".$this->db->pdate("datec")." as datec,";