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

@ -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;
@ -71,7 +72,7 @@ class Adherent
// var $public; // var $public;
var $array_options; var $array_options;
var $errorstr; var $error;
/** /**
\brief Adherent \brief Adherent
@ -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];
} }
} }
@ -301,7 +302,7 @@ class Adherent
if ($err) if ($err)
{ {
$this->errorstr = $error_string; $this->error = $error_string;
return 0; return 0;
} }
else else
@ -540,25 +541,25 @@ class Adherent
$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;
@ -683,7 +684,7 @@ 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
@ -821,19 +822,19 @@ 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; $err=0;
// mailman // mailman
if (defined("ADHERENT_USE_MAILMAN") && ADHERENT_USE_MAILMAN == 1) if (defined("ADHERENT_USE_MAILMAN") && ADHERENT_USE_MAILMAN == 1)
{ {
if(!$this->add_to_mailman()) $result=$this->add_to_mailman();
if ($result < 0)
{ {
$err+=1; $err+=1;
} }
@ -844,7 +845,8 @@ class Adherent
defined("ADHERENT_USE_GLASNOST_AUTO") && ADHERENT_USE_GLASNOST_AUTO ==1 defined("ADHERENT_USE_GLASNOST_AUTO") && ADHERENT_USE_GLASNOST_AUTO ==1
) )
{ {
if(!$this->add_to_glasnost()){ if(!$this->add_to_glasnost())
{
$err+=1; $err+=1;
} }
} }
@ -853,25 +855,28 @@ class Adherent
defined("ADHERENT_USE_SPIP_AUTO") && ADHERENT_USE_SPIP_AUTO ==1 defined("ADHERENT_USE_SPIP_AUTO") && ADHERENT_USE_SPIP_AUTO ==1
) )
{ {
if(!$this->add_to_spip()){ if(!$this->add_to_spip())
{
$err+=1; $err+=1;
} }
} }
if ($err>0){ if ($err>0)
{
// error // error
return 0; return 0;
}else{ }
else
{
return 1; return 1;
} }
} }
/** /**
\brief fonction qui supprime l'adhérent des abonnements automatiques \brief fonction qui supprime l'adhérent des abonnements automatiques
\param adht \param adht
\remarks mailing-list, spip, glasnost, etc... \remarks mailing-list, spip, glasnost, etc...
*/ */
function del_to_abo($adht) function del_to_abo($adht)
{ {
$err=0; $err=0;
@ -908,10 +913,10 @@ class Adherent
} }
} }
/**
\brief fonction qui donne les droits rédacteurs dans spip
*/
/**
\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;
} }
} }
@ -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,26 +1242,38 @@ 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='')
{ {
global $conf,$langs;
if (! function_exists("curl_init"))
{
$this->error=$langs->trans("ErrorFunctionNotAvailableInPHP","curl_init");
return -1;
}
if (defined("ADHERENT_MAILMAN_URL") && ADHERENT_MAILMAN_URL != '' && defined("ADHERENT_MAILMAN_LISTS") && ADHERENT_MAILMAN_LISTS != '') if (defined("ADHERENT_MAILMAN_URL") && ADHERENT_MAILMAN_URL != '' && defined("ADHERENT_MAILMAN_LISTS") && ADHERENT_MAILMAN_LISTS != '')
{ {
if ($listes ==''){ if ($listes =='')
{
$lists=explode(',',ADHERENT_MAILMAN_LISTS); $lists=explode(',',ADHERENT_MAILMAN_LISTS);
}else{ }
else
{
$lists=explode(',',$listes); $lists=explode(',',$listes);
} }
foreach ($lists as $list) foreach ($lists as $list)
@ -1306,16 +1323,15 @@ class Adherent
} }
else else
{ {
$this->errorstr="Constantes de connection non definies"; $this->error="Constantes de connection non definies";
return 0; return -1;
} }
} }
/** /**
\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 != '')
@ -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;
} }
} }
@ -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';

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
if ($adh->statut >= 1)
{
print "<a class=\"butAction\" href=\"fiche.php?rowid=$adh->id&action=sendinfo\">".$langs->trans("SendCardByMail")."</a>\n"; 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>';
} }
} }