Qual: Uniformisation du code. La propriété pour remonter une erreur est $error dans toutes les classes

This commit is contained in:
Laurent Destailleur 2006-11-19 17:16:39 +00:00
parent 8f6129a9cc
commit 64e610f3f6
5 changed files with 285 additions and 265 deletions

View File

@ -36,7 +36,7 @@
*/ */
/** /**
\class Adherent \class Adherent
\brief Classe permettant la gestion d'un adhérent \brief Classe permettant la gestion d'un adhérent
*/ */
@ -47,6 +47,7 @@ class Adherent
var $db; var $db;
var $prenom; var $prenom;
var $nom; var $nom;
var $fullname;
var $societe; var $societe;
var $adresse; var $adresse;
var $cp; var $cp;
@ -63,15 +64,15 @@ class Adherent
var $pass; var $pass;
var $naiss; var $naiss;
var $photo; var $photo;
var $typeid; // Id type adherent var $typeid; // Id type adherent
var $type; // Libellé type adherent var $type; // Libellé type adherent
var $need_subscription; var $need_subscription;
// var $public; // var $public;
var $array_options; var $array_options;
var $errorstr; var $error;
/** /**
\brief Adherent \brief Adherent
@ -108,7 +109,7 @@ class Adherent
function send_an_email($recipients,$text,$subject="Vos coordonnees sur %SERVEUR%") function send_an_email($recipients,$text,$subject="Vos coordonnees sur %SERVEUR%")
{ {
global $conf,$langs; global $conf,$langs;
$patterns = array ( $patterns = array (
'/%PRENOM%/', '/%PRENOM%/',
'/%NOM%/', '/%NOM%/',
@ -160,13 +161,13 @@ class Adherent
$texttosend = preg_replace ($patterns, $replace, $text); $texttosend = preg_replace ($patterns, $replace, $text);
$subjectosend = preg_replace ($patterns, $replace, $subject); $subjectosend = preg_replace ($patterns, $replace, $subject);
$msgishtml=0; $msgishtml=0;
// Envoi mail confirmation // Envoi mail confirmation
include_once(DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php"); include_once(DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
$from=$conf->email_from; $from=$conf->email_from;
if ($conf->global->ADHERENT_MAIL_FROM) $from=$conf->global->ADHERENT_MAIL_FROM; if ($conf->global->ADHERENT_MAIL_FROM) $from=$conf->global->ADHERENT_MAIL_FROM;
$mailfile = new CMailFile($subjectosend,$this->email,$from,$texttosend, $mailfile = new CMailFile($subjectosend,$this->email,$from,$texttosend,
array(),array(),array(), array(),array(),array(),
'', '', 0, $msgishtml); '', '', 0, $msgishtml);
@ -189,10 +190,10 @@ class Adherent
function print_error_list() function print_error_list()
{ {
$num = sizeof($this->errorstr); $num = sizeof($this->error);
for ($i = 0 ; $i < $num ; $i++) for ($i = 0 ; $i < $num ; $i++)
{ {
print "<li>" . $this->errorstr[$i]; print "<li>" . $this->error[$i];
} }
} }
@ -275,7 +276,7 @@ class Adherent
$err++; $err++;
$amount_invalid = 1; $amount_invalid = 1;
break; break;
} }
} }
if (! $amount_invalid) if (! $amount_invalid)
@ -294,14 +295,14 @@ class Adherent
} }
} }
} }
/* /*
* Return errors * Return errors
*/ */
if ($err) if ($err)
{ {
$this->errorstr = $error_string; $this->error = $error_string;
return 0; return 0;
} }
else else
@ -318,25 +319,25 @@ class Adherent
function create() function create()
{ {
global $conf,$langs,$user; global $conf,$langs,$user;
// Verification parametres // Verification parametres
if ($conf->global->ADHERENT_MAIL_REQUIRED && ! ValidEMail($this->email)) { if ($conf->global->ADHERENT_MAIL_REQUIRED && ! ValidEMail($this->email)) {
$this->error = $langs->trans("ErrorBadEMail",$this->email); $this->error = $langs->trans("ErrorBadEMail",$this->email);
return -1; return -1;
} }
$this->date = $this->db->idate($this->date); $this->date = $this->db->idate($this->date);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent (datec)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent (datec)";
$sql .= " VALUES (now())"; $sql .= " VALUES (now())";
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent"); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent");
$result=$this->update(1); $result=$this->update(1);
// Appel des triggers // Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db); $interface=new Interfaces($this->db);
@ -351,7 +352,7 @@ class Adherent
return -1; return -1;
} }
} }
/** /**
\brief fonction qui met à jour l'adhérent \brief fonction qui met à jour l'adhérent
@ -361,18 +362,18 @@ class Adherent
function update($disable_trigger=0) function update($disable_trigger=0)
{ {
global $conf,$langs,$user; global $conf,$langs,$user;
dolibarr_syslog("Adherent.class.php::update $disable_trigger"); dolibarr_syslog("Adherent.class.php::update $disable_trigger");
// Verification parametres // Verification parametres
if ($conf->global->ADHERENT_MAIL_REQUIRED && ! ValidEMail($this->email)) if ($conf->global->ADHERENT_MAIL_REQUIRED && ! ValidEMail($this->email))
{ {
$this->error = $langs->trans("ErrorBadEMail",$this->email); $this->error = $langs->trans("ErrorBadEMail",$this->email);
return -1; return -1;
} }
$this->db->begin(); $this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
$sql .= " prenom = '".$this->prenom ."'"; $sql .= " prenom = '".$this->prenom ."'";
$sql .= ",nom='" .$this->nom."'"; $sql .= ",nom='" .$this->nom."'";
@ -392,7 +393,7 @@ class Adherent
$sql .= ",fk_adherent_type=".$this->typeid; $sql .= ",fk_adherent_type=".$this->typeid;
$sql .= ",morphy='".$this->morphy."'"; $sql .= ",morphy='".$this->morphy."'";
$sql .= " WHERE rowid = ".$this->id; $sql .= " WHERE rowid = ".$this->id;
$result = $this->db->query($sql); $result = $this->db->query($sql);
if (! $result) if (! $result)
{ {
@ -400,12 +401,12 @@ class Adherent
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
if (sizeof($this->array_options) > 0) if (sizeof($this->array_options) > 0)
{ {
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options WHERE adhid = ".$this->id; $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options WHERE adhid = ".$this->id;
$this->db->query($sql_del); $this->db->query($sql_del);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options (adhid"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options (adhid";
foreach($this->array_options as $key => $value) foreach($this->array_options as $key => $value)
{ {
@ -419,7 +420,7 @@ class Adherent
$sql.=",'".$this->array_options[$key]."'"; $sql.=",'".$this->array_options[$key]."'";
} }
$sql.=");"; $sql.=");";
$result = $this->db->query($sql); $result = $this->db->query($sql);
if (! $result) if (! $result)
{ {
@ -439,7 +440,7 @@ class Adherent
} }
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
@ -520,7 +521,7 @@ class Adherent
function fetch($rowid) function fetch($rowid)
{ {
global $langs; global $langs;
$sql = "SELECT d.rowid, d.prenom, d.nom, d.societe, d.statut, d.public, d.adresse, d.cp, d.ville, d.note, d.email, d.login, d.pass, d.naiss, d.photo, d.fk_adherent_type, d.morphy,"; $sql = "SELECT d.rowid, d.prenom, d.nom, d.societe, d.statut, d.public, d.adresse, d.cp, d.ville, d.note, d.email, d.login, d.pass, d.naiss, d.photo, d.fk_adherent_type, d.morphy,";
$sql.= " ".$this->db->pdate("d.datefin")." as datefin,"; $sql.= " ".$this->db->pdate("d.datefin")." as datefin,";
$sql.= " d.pays, p.rowid as pays_id, p.code as pays_code, p.libelle as pays_lib,"; $sql.= " d.pays, p.rowid as pays_id, p.code as pays_code, p.libelle as pays_lib,";
@ -528,37 +529,37 @@ class Adherent
$sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d"; $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
$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.= " WHERE d.rowid = ".$rowid." AND d.fk_adherent_type = t.rowid"; $sql.= " WHERE d.rowid = ".$rowid." AND d.fk_adherent_type = t.rowid";
$result=$this->db->query( $sql); $result=$this->db->query( $sql);
if ($result) if ($result)
{ {
if ($this->db->num_rows($result)) if ($this->db->num_rows($result))
{ {
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->statut = $obj->statut; $this->statut = $obj->statut;
$this->public = $obj->public; $this->public = $obj->public;
$this->date = $obj->datedon; $this->date = $obj->datedon;
$this->prenom = stripslashes($obj->prenom); $this->prenom = $obj->prenom;
$this->nom = stripslashes($obj->nom); $this->nom = $obj->nom;
$this->fullname = $obj->nom.($obj->nom&&$obj->prenom?' ':'').$obj->prenom; $this->fullname = trim($obj->nom.' '.$obj->prenom);
$this->societe = stripslashes($obj->societe); $this->societe = $obj->societe;
$this->adresse = stripslashes($obj->adresse); $this->adresse = $obj->adresse;
$this->cp = stripslashes($obj->cp); $this->cp = $obj->cp;
$this->ville = stripslashes($obj->ville); $this->ville = $obj->ville;
$this->pays_id = $obj->pays_id; $this->pays_id = $obj->pays_id;
$this->pays_code = $obj->pays_code; $this->pays_code = $obj->pays_code;
if ($langs->trans("Country".$obj->pays_code) != "Country".$obj->pays_code) $this->pays = $langs->trans("Country".$obj->pays_code); if ($langs->trans("Country".$obj->pays_code) != "Country".$obj->pays_code) $this->pays = $langs->trans("Country".$obj->pays_code);
elseif ($obj->pays_lib) $this->pays=$obj->pays_lib; elseif ($obj->pays_lib) $this->pays=$obj->pays_lib;
else $this->pays=$obj->pays; else $this->pays=$obj->pays;
$this->email = stripslashes($obj->email); $this->email = $obj->email;
$this->login = stripslashes($obj->login); $this->login = $obj->login;
$this->pass = stripslashes($obj->pass); $this->pass = $obj->pass;
$this->naiss = stripslashes($obj->naiss); $this->naiss = $obj->naiss;
$this->photo = stripslashes($obj->photo); $this->photo = $obj->photo;
$this->datefin = $obj->datefin; $this->datefin = $obj->datefin;
$this->commentaire = stripslashes($obj->note); $this->commentaire = $obj->note;
$this->morphy = $obj->morphy; $this->morphy = $obj->morphy;
$this->typeid = $obj->fk_adherent_type; $this->typeid = $obj->fk_adherent_type;
@ -570,10 +571,10 @@ class Adherent
{ {
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
} }
} }
/** /**
\brief Fonction qui récupére les données optionelles de l'adhérent \brief Fonction qui récupére les données optionelles de l'adhérent
\param rowid \param rowid
@ -585,7 +586,7 @@ class Adherent
$sql = "SELECT *"; $sql = "SELECT *";
$sql .= " FROM ".MAIN_DB_PREFIX."adherent_options"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent_options";
$sql .= " WHERE adhid=$rowid"; $sql .= " WHERE adhid=$rowid";
$result=$this->db->query( $sql); $result=$this->db->query( $sql);
if ($result) if ($result)
@ -593,7 +594,7 @@ class Adherent
if ($this->db->num_rows()) if ($this->db->num_rows())
{ {
$tab = $this->db->fetch_array($result); $tab = $this->db->fetch_array($result);
foreach ($tab as $key => $value) foreach ($tab as $key => $value)
{ {
if ($key != 'optid' && $key != 'tms' && $key != 'adhid') if ($key != 'optid' && $key != 'tms' && $key != 'adhid')
@ -608,7 +609,7 @@ class Adherent
{ {
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
} }
} }
/* /*
@ -618,7 +619,7 @@ class Adherent
{ {
$array_name_options=array(); $array_name_options=array();
$sql = "SHOW COLUMNS FROM ".MAIN_DB_PREFIX."adherent_options"; $sql = "SHOW COLUMNS FROM ".MAIN_DB_PREFIX."adherent_options";
$result=$this->db->query( $sql); $result=$this->db->query( $sql);
if ($result) if ($result)
@ -646,9 +647,9 @@ class Adherent
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
return array() ; return array() ;
} }
} }
/** /**
\brief Fonction qui insère la cotisation dans la base de données \brief Fonction qui insère la cotisation dans la base de données
et eventuellement liens dans banques, mailman, etc... et eventuellement liens dans banques, mailman, etc...
@ -659,13 +660,13 @@ class Adherent
function cotisation($date, $montant, $accountid, $operation, $label, $num_chq) function cotisation($date, $montant, $accountid, $operation, $label, $num_chq)
{ {
global $conf,$langs,$user; global $conf,$langs,$user;
dolibarr_syslog("Adherent.class.php::cotisation $date, $montant, $accountid, $operation, $label, $num_chq"); dolibarr_syslog("Adherent.class.php::cotisation $date, $montant, $accountid, $operation, $label, $num_chq");
$this->db->begin(); $this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."cotisation (fk_adherent, datec, dateadh, cotisation)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."cotisation (fk_adherent, datec, dateadh, cotisation)";
$sql .= " VALUES ($this->id, now(), ".$this->db->idate($date).", $montant)"; $sql .= " VALUES ($this->id, now(), ".$this->db->idate($date).", $montant)";
$result=$this->db->query($sql); $result=$this->db->query($sql);
if ($result) if ($result)
{ {
@ -683,17 +684,17 @@ class Adherent
// Rajout du nouveau cotisant dans les listes qui vont bien // Rajout du nouveau cotisant dans les listes qui vont bien
if ($conf->global->ADHERENT_MAILMAN_LISTS_COTISANT && ! $adh->datefin) if ($conf->global->ADHERENT_MAILMAN_LISTS_COTISANT && ! $adh->datefin)
{ {
$adh->add_to_mailman($conf->global->ADHERENT_MAILMAN_LISTS_COTISANT); $result=$adh->add_to_mailman($conf->global->ADHERENT_MAILMAN_LISTS_COTISANT);
} }
// Insertion dans la gestion bancaire si configuré pour // Insertion dans la gestion bancaire si configuré pour
if ($conf->global->ADHERENT_BANK_USE && $accountid) if ($conf->global->ADHERENT_BANK_USE && $accountid)
{ {
$acct=new Account($this->db,$accountid); $acct=new Account($this->db,$accountid);
$dateop=strftime("%Y%m%d",time()); $dateop=strftime("%Y%m%d",time());
$amount=$cotisation; $amount=$cotisation;
$insertid=$acct->addline($dateop, $operation, $label, $amount, $num_chq, '', $user); $insertid=$acct->addline($dateop, $operation, $label, $amount, $num_chq, '', $user);
if ($insertid > 0) if ($insertid > 0)
{ {
@ -734,12 +735,12 @@ class Adherent
$this->db->commit(); $this->db->commit();
return $rowid; return $rowid;
} }
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
$this->db->rollback(); $this->db->rollback();
return -2; return -2;
} }
} }
else else
{ {
@ -757,12 +758,12 @@ class Adherent
function validate($userid) function validate($userid)
{ {
global $user,$langs,$conf; global $user,$langs,$conf;
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
$sql.= " statut=1, datevalid = now(),"; $sql.= " statut=1, datevalid = now(),";
$sql.= " fk_user_valid=".$userid; $sql.= " fk_user_valid=".$userid;
$sql.= " WHERE rowid = $this->id"; $sql.= " WHERE rowid = $this->id";
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
@ -771,7 +772,7 @@ class Adherent
$interface=new Interfaces($this->db); $interface=new Interfaces($this->db);
$result=$interface->run_triggers('MEMBER_VALIDATE',$this,$user,$langs,$conf); $result=$interface->run_triggers('MEMBER_VALIDATE',$this,$user,$langs,$conf);
// Fin appel triggers // Fin appel triggers
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
@ -792,14 +793,14 @@ class Adherent
function resiliate($userid) function resiliate($userid)
{ {
global $user,$langs,$conf; global $user,$langs,$conf;
$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=".$userid; $sql .= ",fk_user_valid=".$userid;
$sql .= " WHERE rowid = ".$this->id; $sql .= " WHERE rowid = ".$this->id;
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
@ -821,97 +822,101 @@ class Adherent
} }
/** /**
\brief fonction qui ajoute l'adhérent au abonnements automatiques \brief fonction qui ajoute l'adhérent au abonnements automatiques
\param adht \param adht
\remarks mailing-list, spip, glasnost, etc... \remarks mailing-list, spip, glasnost, etc...
*/ */
function add_to_abo($adht) function add_to_abo($adht)
{
$err=0;
// mailman
if (defined("ADHERENT_USE_MAILMAN") && ADHERENT_USE_MAILMAN == 1)
{ {
if(!$this->add_to_mailman()) $err=0;
{ // mailman
$err+=1; if (defined("ADHERENT_USE_MAILMAN") && ADHERENT_USE_MAILMAN == 1)
} {
$result=$this->add_to_mailman();
if ($result < 0)
{
$err+=1;
}
}
if ($adht->vote == 'yes' &&
defined("ADHERENT_USE_GLASNOST") && ADHERENT_USE_GLASNOST ==1 &&
defined("ADHERENT_USE_GLASNOST_AUTO") && ADHERENT_USE_GLASNOST_AUTO ==1
)
{
if(!$this->add_to_glasnost())
{
$err+=1;
}
}
if (
defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 &&
defined("ADHERENT_USE_SPIP_AUTO") && ADHERENT_USE_SPIP_AUTO ==1
)
{
if(!$this->add_to_spip())
{
$err+=1;
}
}
if ($err>0)
{
// error
return 0;
}
else
{
return 1;
}
} }
if ($adht->vote == 'yes' &&
defined("ADHERENT_USE_GLASNOST") && ADHERENT_USE_GLASNOST ==1 && /**
defined("ADHERENT_USE_GLASNOST_AUTO") && ADHERENT_USE_GLASNOST_AUTO ==1 \brief fonction qui supprime l'adhérent des abonnements automatiques
) \param adht
\remarks mailing-list, spip, glasnost, etc...
*/
function del_to_abo($adht)
{ {
if(!$this->add_to_glasnost()){ $err=0;
$err+=1; // mailman
} if (defined("ADHERENT_USE_MAILMAN") && ADHERENT_USE_MAILMAN == 1)
} {
if ( if(!$this->del_to_mailman()){
defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 && $err+=1;
defined("ADHERENT_USE_SPIP_AUTO") && ADHERENT_USE_SPIP_AUTO ==1 }
) }
{ if ($adht->vote == 'yes' &&
if(!$this->add_to_spip()){ defined("ADHERENT_USE_GLASNOST") && ADHERENT_USE_GLASNOST ==1 &&
$err+=1; defined("ADHERENT_USE_GLASNOST_AUTO") && ADHERENT_USE_GLASNOST_AUTO ==1
} )
} {
if ($err>0){ if(!$this->del_to_glasnost()){
// error $err+=1;
return 0; }
}else{ }
return 1; if (
} defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 &&
} defined("ADHERENT_USE_SPIP_AUTO") && ADHERENT_USE_SPIP_AUTO ==1
)
{
if(!$this->del_to_spip()){
$err+=1;
}
}
if ($err>0){
// error
return 0;
}else{
return 1;
}
}
/** /**
\brief fonction qui supprime l'adhérent des abonnements automatiques \brief fonction qui donne les droits rédacteurs dans spip
\param adht */
\remarks mailing-list, spip, glasnost, etc...
*/
function del_to_abo($adht)
{
$err=0;
// mailman
if (defined("ADHERENT_USE_MAILMAN") && ADHERENT_USE_MAILMAN == 1)
{
if(!$this->del_to_mailman()){
$err+=1;
}
}
if ($adht->vote == 'yes' &&
defined("ADHERENT_USE_GLASNOST") && ADHERENT_USE_GLASNOST ==1 &&
defined("ADHERENT_USE_GLASNOST_AUTO") && ADHERENT_USE_GLASNOST_AUTO ==1
)
{
if(!$this->del_to_glasnost()){
$err+=1;
}
}
if (
defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 &&
defined("ADHERENT_USE_SPIP_AUTO") && ADHERENT_USE_SPIP_AUTO ==1
)
{
if(!$this->del_to_spip()){
$err+=1;
}
}
if ($err>0){
// error
return 0;
}else{
return 1;
}
}
/**
\brief fonction qui donne les droits rédacteurs dans spip
*/
function add_to_spip() function add_to_spip()
{ {
if (defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 && if (defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 &&
@ -934,7 +939,7 @@ class Adherent
} }
else else
{ {
$this->errorstr=$mydb->error(); $this->error=$mydb->error();
return 0; return 0;
} }
} }
@ -963,7 +968,7 @@ class Adherent
} }
else else
{ {
$this->errorstr=$mydb->error(); $this->error=$mydb->error();
return 0; return 0;
} }
} }
@ -982,14 +987,14 @@ class Adherent
defined('ADHERENT_SPIP_PASS') && ADHERENT_SPIP_PASS != '' && defined('ADHERENT_SPIP_PASS') && ADHERENT_SPIP_PASS != '' &&
defined('ADHERENT_SPIP_DB') && ADHERENT_SPIP_DB != '') defined('ADHERENT_SPIP_DB') && ADHERENT_SPIP_DB != '')
{ {
$query = "SELECT login FROM spip_auteurs WHERE login='".$this->login."'"; $query = "SELECT login FROM spip_auteurs WHERE login='".$this->login."'";
$mydb=new DoliDb('mysql',ADHERENT_SPIP_SERVEUR,ADHERENT_SPIP_USER,ADHERENT_SPIP_PASS,ADHERENT_SPIP_DB); $mydb=new DoliDb('mysql',ADHERENT_SPIP_SERVEUR,ADHERENT_SPIP_USER,ADHERENT_SPIP_PASS,ADHERENT_SPIP_DB);
if ($mydb->ok) { if ($mydb->ok) {
$result = $mydb->query($query); $result = $mydb->query($query);
if ($result) if ($result)
{ {
if ($mydb->num_rows()) if ($mydb->num_rows())
@ -1008,11 +1013,11 @@ class Adherent
else else
{ {
# error # error
$this->errorstr=$mydb->error(); $this->error=$mydb->error();
return -1; return -1;
} }
} else { } else {
$this->errorstr="Echec de connexion avec les identifiants ".ADHERENT_SPIP_SERVEUR." ".ADHERENT_SPIP_USER." ".ADHERENT_SPIP_PASS." ".ADHERENT_SPIP_DB; $this->error="Echec de connexion avec les identifiants ".ADHERENT_SPIP_SERVEUR." ".ADHERENT_SPIP_USER." ".ADHERENT_SPIP_PASS." ".ADHERENT_SPIP_DB;
return -1; return -1;
} }
} }
@ -1045,7 +1050,7 @@ class Adherent
$userid=$response[0]; $userid=$response[0];
$usertoken=$response[1]; $usertoken=$response[1];
}else{ }else{
$this->errorstr=$response['faultString']; $this->error=$response['faultString'];
return 0; return 0;
} }
@ -1074,12 +1079,12 @@ class Adherent
if ($success){ if ($success){
$personid=$response[0]; $personid=$response[0];
}else{ }else{
$this->errorstr=$response['faultString']; $this->error=$response['faultString'];
return 0; return 0;
} }
return 1; return 1;
}else{ }else{
$this->errorstr="Constantes de connection non definies"; $this->error="Constantes de connection non definies";
return 0; return 0;
} }
} }
@ -1131,7 +1136,7 @@ class Adherent
if ($success){ if ($success){
$personid=$response['id']; $personid=$response['id'];
}else{ }else{
$this->errorstr=$response['faultString']; $this->error=$response['faultString'];
return 0; return 0;
} }
if (defined('ADHERENT_GLASNOST_DEFAULT_GROUPID') && ADHERENT_GLASNOST_DEFAULT_GROUPID != ''){ if (defined('ADHERENT_GLASNOST_DEFAULT_GROUPID') && ADHERENT_GLASNOST_DEFAULT_GROUPID != ''){
@ -1154,7 +1159,7 @@ class Adherent
if ($success){ if ($success){
$groupids=$response['membersSet']; $groupids=$response['membersSet'];
}else{ }else{
$this->errorstr=$response['faultString']; $this->error=$response['faultString'];
return 0; return 0;
} }
// TODO faire la verification que le user n'est pas dans ce // TODO faire la verification que le user n'est pas dans ce
@ -1180,11 +1185,11 @@ class Adherent
if ($success){ if ($success){
return 1; return 1;
}else{ }else{
$this->errorstr=$response['faultString']; $this->error=$response['faultString'];
return 0; return 0;
} }
}else{ }else{
$this->errorstr="Constantes de connection non definies"; $this->error="Constantes de connection non definies";
return 0; return 0;
} }
} }
@ -1237,87 +1242,98 @@ class Adherent
$personid=$response['id']; $personid=$response['id'];
return 1; return 1;
}else{ }else{
$this->errorstr=$response['faultString']; $this->error=$response['faultString'];
return 0; return 0;
} }
}else{ }else{
$this->errorstr="Constantes de connection non definies"; $this->error="Constantes de connection non definies";
return 0; return 0;
} }
} }
/**
\brief fonction qui rajoute l'utilisateur dans mailman
*/
/**
\brief Fonction qui rajoute l'utilisateur dans mailman
\return int <0 si KO, >0 si OK
*/
function add_to_mailman($listes='') function add_to_mailman($listes='')
{ {
if (defined("ADHERENT_MAILMAN_URL") && ADHERENT_MAILMAN_URL != '' && defined("ADHERENT_MAILMAN_LISTS") && ADHERENT_MAILMAN_LISTS != '') global $conf,$langs;
{
if ($listes ==''){ if (! function_exists("curl_init"))
$lists=explode(',',ADHERENT_MAILMAN_LISTS); {
}else{ $this->error=$langs->trans("ErrorFunctionNotAvailableInPHP","curl_init");
$lists=explode(',',$listes); return -1;
}
if (defined("ADHERENT_MAILMAN_URL") && ADHERENT_MAILMAN_URL != '' && defined("ADHERENT_MAILMAN_LISTS") && ADHERENT_MAILMAN_LISTS != '')
{
if ($listes =='')
{
$lists=explode(',',ADHERENT_MAILMAN_LISTS);
}
else
{
$lists=explode(',',$listes);
}
foreach ($lists as $list)
{
// on remplace dans l'url le nom de la liste ainsi
// que l'email et le mot de passe
$patterns = array (
'/%LISTE%/',
'/%EMAIL%/',
'/%PASS%/',
'/%ADMINPW%/',
'/%SERVER%/'
);
$replace = array (
$list,
$this->email,
$this->pass,
ADHERENT_MAILMAN_ADMINPW,
ADHERENT_MAILMAN_SERVER
);
$curl_url = preg_replace ($patterns, $replace, ADHERENT_MAILMAN_URL);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"$curl_url");
//curl_setopt($ch, CURLOPT_URL,"http://www.j1b.org/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
//curl_setopt($ch, CURLOPT_POST, 0);
//curl_setopt($ch, CURLOPT_POSTFIELDS, "a=3&b=5");
//--- Start buffering
//ob_start();
$result=curl_exec ($ch);
dolibarr_syslog($result);
//--- End buffering and clean output
//ob_end_clean();
if (curl_error($ch) > 0)
{
// error
return 0;
}
curl_close ($ch);
}
return 1;
}
else
{
$this->error="Constantes de connection non definies";
return -1;
}
} }
foreach ($lists as $list)
{
// on remplace dans l'url le nom de la liste ainsi
// que l'email et le mot de passe
$patterns = array (
'/%LISTE%/',
'/%EMAIL%/',
'/%PASS%/',
'/%ADMINPW%/',
'/%SERVER%/'
);
$replace = array (
$list,
$this->email,
$this->pass,
ADHERENT_MAILMAN_ADMINPW,
ADHERENT_MAILMAN_SERVER
);
$curl_url = preg_replace ($patterns, $replace, ADHERENT_MAILMAN_URL);
$ch = curl_init(); /**
curl_setopt($ch, CURLOPT_URL,"$curl_url");
//curl_setopt($ch, CURLOPT_URL,"http://www.j1b.org/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
//curl_setopt($ch, CURLOPT_POST, 0);
//curl_setopt($ch, CURLOPT_POSTFIELDS, "a=3&b=5");
//--- Start buffering
//ob_start();
$result=curl_exec ($ch);
dolibarr_syslog($result);
//--- End buffering and clean output
//ob_end_clean();
if (curl_error($ch) > 0)
{
// error
return 0;
}
curl_close ($ch);
}
return 1;
}
else
{
$this->errorstr="Constantes de connection non definies";
return 0;
}
}
/**
\brief fonction qui désinscrit l'utilisateur de toutes les mailing list mailman \brief fonction qui désinscrit l'utilisateur de toutes les mailing list mailman
\ remarks utilie lors de la résiliation d'adhésion \ remarks utilie lors de la résiliation d'adhésion
*/ */
function del_to_mailman($listes='')
function del_to_mailman($listes='') {
{
if (defined("ADHERENT_MAILMAN_UNSUB_URL") && ADHERENT_MAILMAN_UNSUB_URL != '' && defined("ADHERENT_MAILMAN_LISTS") && ADHERENT_MAILMAN_LISTS != '') if (defined("ADHERENT_MAILMAN_UNSUB_URL") && ADHERENT_MAILMAN_UNSUB_URL != '' && defined("ADHERENT_MAILMAN_LISTS") && ADHERENT_MAILMAN_LISTS != '')
{ {
if ($listes==''){ if ($listes==''){
@ -1375,7 +1391,7 @@ class Adherent
} }
else else
{ {
$this->errorstr="Constantes de connection non definies"; $this->error="Constantes de connection non definies";
return 0; return 0;
} }
} }
@ -1477,7 +1493,7 @@ class Adherent
else return $langs->trans("MemberStatusPayed").' '.img_picto($langs->trans('MemberStatusPayed'),'statut4'); else return $langs->trans("MemberStatusPayed").' '.img_picto($langs->trans('MemberStatusPayed'),'statut4');
} }
if ($statut == 0) return $langs->trans("MemberStatusResiliated").' '.img_picto($langs->trans('MemberStatusResiliated'),'statut5'); if ($statut == 0) return $langs->trans("MemberStatusResiliated").' '.img_picto($langs->trans('MemberStatusResiliated'),'statut5');
} }
} }
@ -1488,7 +1504,7 @@ class Adherent
function load_state_board() function load_state_board()
{ {
global $conf; global $conf;
$this->nb=array(); $this->nb=array();
$sql = "SELECT count(a.rowid) as nb"; $sql = "SELECT count(a.rowid) as nb";
@ -1503,7 +1519,7 @@ class Adherent
} }
return 1; return 1;
} }
else else
{ {
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
$this->error=$this->db->error(); $this->error=$this->db->error();
@ -1511,7 +1527,7 @@ class Adherent
} }
} }
/** /**
* \brief Charge indicateurs this->nbtodo et this->nbtodolate de tableau de bord * \brief Charge indicateurs this->nbtodo et this->nbtodolate de tableau de bord
* \param user Objet user * \param user Objet user
@ -1520,7 +1536,7 @@ class Adherent
function load_board($user) function load_board($user)
{ {
global $conf; global $conf;
if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe
$this->nbtodo=$this->nbtodolate=0; $this->nbtodo=$this->nbtodolate=0;
@ -1537,7 +1553,7 @@ class Adherent
} }
return 1; return 1;
} }
else else
{ {
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
$this->error=$this->db->error(); $this->error=$this->db->error();
@ -1558,6 +1574,7 @@ class Adherent
$this->fullname = 'DOLIBARR SPECIMEN'; $this->fullname = 'DOLIBARR SPECIMEN';
$this->nom = 'DOLIBARR'; $this->nom = 'DOLIBARR';
$this->prenom = 'SPECIMEN'; $this->prenom = 'SPECIMEN';
$this->fullname=trim($this->nom.' '.$this->prenom);
$this->societe = 'Societe ABC'; $this->societe = 'Societe ABC';
$this->adresse = '61 jump street'; $this->adresse = '61 jump street';
$this->cp = '75000'; $this->cp = '75000';
@ -1574,7 +1591,7 @@ class Adherent
$this->pass='dolibspec'; $this->pass='dolibspec';
$this->naiss=time(); $this->naiss=time();
$this->photo=''; $this->photo='';
$this->typeid=1; // Id type adherent $this->typeid=1; // Id type adherent
$this->type='Type adherent'; // Libellé type adherent $this->type='Type adherent'; // Libellé type adherent
$this->need_subscription=0; $this->need_subscription=0;

View File

@ -52,7 +52,7 @@ class AdherentOptions
*/ */
var $attribute_label; var $attribute_label;
var $errorstr; var $error;
/* /*
* Constructor * Constructor
* *
@ -68,7 +68,7 @@ class AdherentOptions
{ {
$this->db = $DB ; $this->db = $DB ;
$this->id = $id; $this->id = $id;
$this->errorstr = array(); $this->error = array();
$this->attribute_name = array(); $this->attribute_name = array();
$this->attribute_label = array(); $this->attribute_label = array();
} }
@ -78,10 +78,10 @@ class AdherentOptions
*/ */
function print_error_list() function print_error_list()
{ {
$num = sizeof($this->errorstr); $num = sizeof($this->error);
for ($i = 0 ; $i < $num ; $i++) for ($i = 0 ; $i < $num ; $i++)
{ {
print "<li>" . $this->errorstr[$i]; print "<li>" . $this->error[$i];
} }
} }
@ -115,7 +115,7 @@ class AdherentOptions
if ($err) if ($err)
{ {
$this->errorstr = $error_string; $this->error = $error_string;
return 0; return 0;
} }
else else

View File

@ -41,7 +41,7 @@ class AdherentType
var $libelle; var $libelle;
var $statut; var $statut;
var $cotisation; /**< Soumis à la cotisation */ var $cotisation; /**< Soumis à la cotisation */
var $errorstr; var $error;
var $mail_valid; /**< mail envoye lors de la validation */ var $mail_valid; /**< mail envoye lors de la validation */
var $commentaire; /**< commentaire */ var $commentaire; /**< commentaire */
var $vote; /** droit de vote ? */ var $vote; /** droit de vote ? */
@ -65,10 +65,10 @@ class AdherentType
function print_error_list() function print_error_list()
{ {
$num = sizeof($this->errorstr); $num = sizeof($this->error);
for ($i = 0 ; $i < $num ; $i++) for ($i = 0 ; $i < $num ; $i++)
{ {
print "<li>" . $this->errorstr[$i]; print "<li>" . $this->error[$i];
} }
} }

View File

@ -53,7 +53,7 @@ class Cotisation
var $statut; var $statut;
var $projet; var $projet;
var $errorstr; var $error;
/** /**
\brief Cotisation \brief Cotisation
@ -73,10 +73,10 @@ class Cotisation
*/ */
function print_error_list() function print_error_list()
{ {
$num = sizeof($this->errorstr); $num = sizeof($this->error);
for ($i = 0 ; $i < $num ; $i++) for ($i = 0 ; $i < $num ; $i++)
{ {
print "<li>" . $this->errorstr[$i]; print "<li>" . $this->error[$i];
} }
} }
@ -159,7 +159,7 @@ class Cotisation
if ($err) if ($err)
{ {
$this->errorstr = $error_string; $this->error = $error_string;
return 0; return 0;
} }
else else

View File

@ -346,7 +346,7 @@ if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes')
if (!$adh->add_to_abo($adht)) if (!$adh->add_to_abo($adht))
{ {
// error // error
$errmsg.="echec du rajout de l'utilisateur aux abonnements: ".$adh->errostr."<BR>\n"; $errmsg.="Echec du rajout de l'utilisateur aux abonnements: ".$adh->error."<BR>\n";
} }
} }
@ -363,10 +363,10 @@ if ($_POST["action"] == 'confirm_resign' && $_POST["confirm"] == 'yes')
$adh->send_an_email($adh->email,$conf->adherent->email_resil,$conf->adherent->email_resil_subject); $adh->send_an_email($adh->email,$conf->adherent->email_resil,$conf->adherent->email_resil_subject);
// supprime l'utilisateur des divers abonnements .. // supprime l'utilisateur des divers abonnements ..
if (!$adh->del_to_abo($adht)) if (! $adh->del_to_abo($adht))
{ {
// error // error
$errmsg.="echec de la suppression de l'utilisateur aux abonnements: ".$adh->errostr."<BR>\n"; $errmsg.="echec de la suppression de l'utilisateur aux abonnements: ".$adh->error."<BR>\n";
} }
} }
@ -379,7 +379,7 @@ if ($_POST["action"] == 'confirm_add_glasnost' && $_POST["confirm"] == 'yes')
if ($adht->vote == 'yes'){ if ($adht->vote == 'yes'){
define("XMLRPC_DEBUG", 1); define("XMLRPC_DEBUG", 1);
if (!$adh->add_to_glasnost()){ if (!$adh->add_to_glasnost()){
$errmsg.="Echec du rajout de l'utilisateur dans glasnost: ".$adh->errostr."<BR>\n"; $errmsg.="Echec du rajout de l'utilisateur dans glasnost: ".$adh->error."<BR>\n";
} }
XMLRPC_debug_print(); XMLRPC_debug_print();
} }
@ -394,7 +394,7 @@ if ($_POST["action"] == 'confirm_del_glasnost' && $_POST["confirm"] == 'yes')
if ($adht->vote == 'yes'){ if ($adht->vote == 'yes'){
define("XMLRPC_DEBUG", 1); define("XMLRPC_DEBUG", 1);
if(!$adh->del_to_glasnost()){ if(!$adh->del_to_glasnost()){
$errmsg.="Echec de la suppression de l'utilisateur dans glasnost: ".$adh->errostr."<BR>\n"; $errmsg.="Echec de la suppression de l'utilisateur dans glasnost: ".$adh->error."<BR>\n";
} }
XMLRPC_debug_print(); XMLRPC_debug_print();
} }
@ -405,7 +405,7 @@ if ($_POST["action"] == 'confirm_del_spip' && $_POST["confirm"] == 'yes')
$adh = new Adherent($db, $rowid); $adh = new Adherent($db, $rowid);
$adh->fetch($rowid); $adh->fetch($rowid);
if(!$adh->del_to_spip()){ if(!$adh->del_to_spip()){
$errmsg.="Echec de la suppression de l'utilisateur dans spip: ".$adh->errostr."<BR>\n"; $errmsg.="Echec de la suppression de l'utilisateur dans spip: ".$adh->error."<BR>\n";
} }
} }
@ -414,7 +414,7 @@ if ($_POST["action"] == 'confirm_add_spip' && $_POST["confirm"] == 'yes')
$adh = new Adherent($db, $rowid); $adh = new Adherent($db, $rowid);
$adh->fetch($rowid); $adh->fetch($rowid);
if (!$adh->add_to_spip()){ if (!$adh->add_to_spip()){
$errmsg.="Echec du rajout de l'utilisateur dans spip: ".$adh->errostr."<BR>\n"; $errmsg.="Echec du rajout de l'utilisateur dans spip: ".$adh->error."<BR>\n";
} }
} }
@ -784,7 +784,10 @@ if ($rowid && $action != 'edit')
} }
// Envoi fiche par mail // Envoi fiche par mail
print "<a class=\"butAction\" href=\"fiche.php?rowid=$adh->id&action=sendinfo\">".$langs->trans("SendCardByMail")."</a>\n"; if ($adh->statut >= 1)
{
print "<a class=\"butAction\" href=\"fiche.php?rowid=$adh->id&action=sendinfo\">".$langs->trans("SendCardByMail")."</a>\n";
}
// Résilier // Résilier
if ($adh->statut == 1) if ($adh->statut == 1)
@ -810,7 +813,7 @@ if ($rowid && $action != 'edit')
print "<a class=\"tabAction\" href=\"fiche.php?rowid=$adh->id&action=add_glasnost\">Ajout dans Glasnost</a>\n"; print "<a class=\"tabAction\" href=\"fiche.php?rowid=$adh->id&action=add_glasnost\">Ajout dans Glasnost</a>\n";
} }
if ($isinglasnost == -1) { if ($isinglasnost == -1) {
print '<br><font class="error">Failed to connect to SPIP: '.$adh->errorstr.'</font>'; print '<br><font class="error">Failed to connect to SPIP: '.$adh->error.'</font>';
} }
} }
@ -827,7 +830,7 @@ if ($rowid && $action != 'edit')
print "<a class=\"tabAction\" href=\"fiche.php?rowid=$adh->id&action=add_spip\">Ajout dans Spip</a>\n"; print "<a class=\"tabAction\" href=\"fiche.php?rowid=$adh->id&action=add_spip\">Ajout dans Spip</a>\n";
} }
if ($isinspip == -1) { if ($isinspip == -1) {
print '<br><font class="error">Failed to connect to SPIP: '.$adh->errorstr.'</font>'; print '<br><font class="error">Failed to connect to SPIP: '.$adh->error.'</font>';
} }
} }