[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org> 4 * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net> 5 * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org> 6 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 * 22 * $Id: adherent.class.php,v 1.27 2005/10/02 19:43:11 eldy Exp $ 23 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/adherents/adherent.class.php,v $ 24 */ 25 26 /** 27 \file htdocs/adherents/adherent.class.php 28 \ingroup adherent 29 \brief Fichier de la classe permettant la gestion d'un adhérent 30 \author Rodolphe Qiedeville 31 \author Jean-Louis Bergamo 32 \author Laurent Destailleur 33 \author Sebastien Di Cintio 34 \author Benoit Mortier 35 \version $Revision: 1.27 $ 36 */ 37 38 39 /** 40 \class Adherent 41 \brief Classe permettant la gestion d'un adhérent 42 */ 43 44 class Adherent 45 { 46 var $id; 47 var $db; 48 var $prenom; 49 var $nom; 50 var $societe; 51 var $adresse; 52 var $cp; 53 var $ville; 54 var $pays_id; 55 var $pays_code; 56 var $pays; 57 var $typeid; 58 var $morphy; 59 var $email; 60 var $public; 61 var $commentaire; 62 var $statut; 63 var $login; 64 var $pass; 65 var $naiss; 66 var $photo; 67 // var $public; 68 var $array_options; 69 70 var $errorstr; 71 72 /** 73 \brief Adherent 74 \param DB base de données 75 \param id id de l'adhérent 76 */ 77 78 function Adherent($DB, $id='') 79 { 80 $this->db = $DB ; 81 $this->id = $id; 82 $this->statut = -1; 83 // l'adherent n'est pas public par defaut 84 $this->public = 0; 85 // les champs optionnels sont vides 86 $this->array_options=array(); 87 } 88 89 90 /** 91 \brief function envoyant un email au destinataire (recipient) avec le text fourni en parametre. 92 \param recipients destinataires 93 \param text contenu du message 94 \param subject sujet du message 95 \remarks La particularite de cette fonction est de remplacer certains champs 96 \remarks par leur valeur pour l'adherent en l'occurrence : 97 \remarks %PRENOM% : est remplace par le prenom 98 \remarks %NOM% : est remplace par nom 99 \remarks %INFOS% : l'ensemble des attributs de cet adherent 100 \remarks %SERVEUR% : URL du serveur web 101 \remarks etc.. 102 \todo Utiliser classe CMailFile 103 */ 104 105 function send_an_email($recipients,$text,$subject="Vos coordonnees sur %SERVEUR%") 106 { 107 $patterns = array ( 108 '/%PRENOM%/', 109 '/%NOM%/', 110 '/%INFOS%/', 111 '/%INFO%/', 112 '/%SERVEUR%/', 113 '/%SOCIETE%/', 114 '/%ADRESSE%/', 115 '/%CP%/', 116 '/%VILLE%/', 117 '/%PAYS%/', 118 '/%EMAIL%/', 119 '/%NAISS%/', 120 '/%PHOTO%/', 121 '/%LOGIN%/', 122 '/%PASS%/' 123 ); 124 $infos = "Prenom : $this->prenom\nNom : $this->nom\nSociete : $this->societe\nAdresse : $this->adresse\nCP : $this->cp\nVille : $this->ville\nPays : $this->pays\nEmail : $this->email\nLogin : $this->login\nPassword : $this->pass\nDate de naissance : $this->naiss\nPhoto : $this->photo\n"; 125 if ($this->public == 1) 126 { 127 $infos.="Fiche Publique : Oui\n"; 128 } 129 else 130 { 131 $infos.="Fiche Publique : Non\n"; 132 } 133 $replace = array ( 134 $this->prenom, 135 $this->nom, 136 $infos, 137 $infos, 138 "http://".$_SERVER["SERVER_NAME"]."/", 139 $this->societe, 140 $this->adresse, 141 $this->cp, 142 $this->ville, 143 $this->pays, 144 $this->email, 145 $this->naiss, 146 $this->photo, 147 $this->login, 148 $this->pass 149 ); 150 $texttosend = preg_replace ($patterns, $replace, $text); 151 $subjectosend = preg_replace ($patterns, $replace, $subject); 152 if (defined('ADHERENT_MAIL_FROM') && ADHERENT_MAIL_FROM != ''){ 153 return mail($recipients,$subjectosend,$texttosend,"From: ".ADHERENT_MAIL_FROM."\nReply-To: ".ADHERENT_MAIL_FROM."\nX-Mailer: php/" . phpversion()); 154 }else{ 155 return mail($recipients,$subjectosend,$texttosend); 156 } 157 } 158 159 /** 160 \brief imprime une liste d'erreur. 161 */ 162 163 function print_error_list() 164 { 165 $num = sizeof($this->errorstr); 166 for ($i = 0 ; $i < $num ; $i++) 167 { 168 print "<li>" . $this->errorstr[$i]; 169 } 170 } 171 172 173 /** 174 \brief Renvoie le libelle traduit de la nature d'un adherent (physique ou morale) 175 \param morphy Nature physique ou morale de l'adhérent 176 */ 177 178 function getmorphylib($morphy='') 179 { 180 global $langs; 181 if (! $morphy) { $morphy=$this->morphy; } 182 if ($morphy == 'phy') { return $langs->trans("Physical"); } 183 if ($morphy == 'mor') { return $langs->trans("Moral"); } 184 return $morphy; 185 } 186 187 /** 188 \brief Vérifie les données entrées 189 \param minimum 190 */ 191 192 function check($minimum=0) 193 { 194 $err = 0; 195 196 if (strlen(trim($this->societe)) == 0) 197 { 198 if ((strlen(trim($this->nom)) + strlen(trim($this->prenom))) == 0) 199 { 200 $error_string[$err] = "Vous devez saisir vos nom et prénom ou le nom de votre société."; 201 $err++; 202 } 203 } 204 205 if (strlen(trim($this->adresse)) == 0) 206 { 207 $error_string[$err] = "L'adresse saisie est invalide"; 208 $err++; 209 } 210 211 if (strlen(trim($this->cp)) == 0) 212 { 213 $error_string[$err] = "Le code postal saisi est invalide"; 214 $err++; 215 } 216 217 if (strlen(trim($this->ville)) == 0) 218 { 219 $error_string[$err] = "La ville saisie est invalide"; 220 $err++; 221 } 222 223 if (strlen(trim($this->email)) == 0) 224 { 225 $error_string[$err] = "L'email saisi est invalide"; 226 $err++; 227 } 228 229 if (strlen(trim($this->login)) == 0) 230 { 231 $error_string[$err] = "Le login saisi est invalide"; 232 $err++; 233 } 234 235 if (strlen(trim($this->pass)) == 0) 236 { 237 $error_string[$err] = "Le pass saisi est invalide"; 238 $err++; 239 } 240 $this->amount = trim($this->amount); 241 242 $map = range(0,9); 243 for ($i = 0; $i < strlen($this->amount) ; $i++) 244 { 245 if (!isset($map[substr($this->amount, $i, 1)] )) 246 { 247 $error_string[$err] = "Le montant du don contient un/des caractère(s) invalide(s)"; 248 $err++; 249 $amount_invalid = 1; 250 break; 251 } 252 } 253 254 if (! $amount_invalid) 255 { 256 if ($this->amount == 0) 257 { 258 $error_string[$err] = "Le montant du don est null"; 259 $err++; 260 } 261 else 262 { 263 if ($this->amount < $minimum && $minimum > 0) 264 { 265 $error_string[$err] = "Le montant minimum du don est de $minimum"; 266 $err++; 267 } 268 } 269 } 270 271 /* 272 * Return errors 273 */ 274 275 if ($err) 276 { 277 $this->errorstr = $error_string; 278 return 0; 279 } 280 else 281 { 282 return 1; 283 } 284 285 } 286 287 /** 288 \brief fonction qui crée l'adhérent 289 \param userid userid de l'adhérent 290 */ 291 292 function create($userid) 293 { 294 /* 295 * Insertion dans la base 296 */ 297 298 $this->date = $this->db->idate($this->date); 299 300 $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent (datec)"; 301 $sql .= " VALUES (now())"; 302 303 $result = $this->db->query($sql); 304 305 if ($result) 306 { 307 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent"); 308 return $this->update(); 309 } 310 else 311 { 312 dolibarr_print_error($this->db); 313 return 0; 314 } 315 } 316 317 318 /** 319 \brief fonction qui met à jour l'adhérent 320 */ 321 function update() 322 { 323 324 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET"; 325 $sql .= " prenom = '".$this->prenom ."'"; 326 $sql .= ",nom='" .$this->nom."'"; 327 $sql .= ",societe='".$this->societe."'"; 328 $sql .= ",adresse='".$this->adresse."'"; 329 $sql .= ",cp='" .$this->cp."'"; 330 $sql .= ",ville='" .$this->ville."'"; 331 $sql .= ",pays='" .$this->pays."'"; 332 $sql .= ",note='" .$this->commentaire."'"; 333 $sql .= ",email='" .$this->email."'"; 334 $sql .= ",login='" .$this->login."'"; 335 $sql .= ",pass='" .$this->pass."'"; 336 if ($this->naiss) $sql .= ",naiss='" .$this->naiss."'"; 337 else $sql .= ",naiss=null"; 338 $sql .= ",photo='" .$this->photo."'"; 339 $sql .= ",public='" .$this->public."'"; 340 $sql .= ",statut=" .$this->statut; 341 $sql .= ",fk_adherent_type=".$this->typeid; 342 $sql .= ",morphy='".$this->morphy."'"; 343 344 $sql .= " WHERE rowid = $this->id"; 345 346 $result = $this->db->query($sql); 347 348 if (!$result) 349 { 350 dolibarr_print_error($this->db); 351 return 0; 352 } 353 354 if (sizeof($this->array_options) > 0 ) 355 { 356 $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options WHERE adhid = $this->id;"; 357 $this->db->query($sql_del); 358 359 $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options (adhid"; 360 foreach($this->array_options as $key => $value) 361 { 362 // recupere le nom de l'attribut 363 $attr=substr($key,8); 364 $sql.=",$attr"; 365 } 366 $sql .= ") VALUES ($this->id"; 367 foreach($this->array_options as $key => $value) 368 { 369 370 $sql.=",'".$this->array_options[$key]."'"; 371 } 372 $sql.=");"; 373 374 $result = $this->db->query($sql); 375 376 if ($result) 377 { 378 return 1; 379 } 380 else 381 { 382 dolibarr_print_error($this->db); 383 return 0; 384 } 385 386 } 387 388 return 1; 389 } 390 391 392 /** 393 \brief fonction qui supprime l'adhérent et les données associées 394 \param rowid 395 */ 396 397 function delete($rowid) 398 399 { 400 $result = 0; 401 $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent WHERE rowid = $rowid"; 402 403 if ( $this->db->query( $sql) ) 404 { 405 if ( $this->db->affected_rows() ) 406 { 407 408 $sql = "DELETE FROM ".MAIN_DB_PREFIX."cotisation WHERE fk_adherent = $rowid"; 409 if ( $this->db->query( $sql) ) 410 { 411 if ( $this->db->affected_rows() ) 412 { 413 $result = 1; 414 } 415 } 416 $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options WHERE adhid = $rowid"; 417 if ( $this->db->query( $sql) ) 418 { 419 if ( $this->db->affected_rows() ) 420 { 421 $result = 1; 422 } 423 } 424 } 425 } 426 else 427 { 428 dolibarr_print_error($this->db); 429 } 430 431 return $result; 432 433 } 434 435 /** 436 \brief Fonction qui récupére l'adhérent en donnant son login 437 \param login login de l'adhérent 438 */ 439 440 function fetch_login($login) 441 { 442 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent WHERE login='$login' LIMIT 1"; 443 444 $result=$this->db->query( $sql); 445 446 if ($result) 447 { 448 if ($this->db->num_rows()) 449 { 450 $obj = $this->db->fetch_object($result); 451 $this->fetch($obj->rowid); 452 } 453 } 454 else 455 { 456 dolibarr_print_error($this->db); 457 } 458 } 459 460 461 /** 462 \brief fonction qui récupére l'adhérent en donnant son rowid 463 \param rowid 464 */ 465 function fetch($rowid) 466 { 467 global $langs; 468 469 $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, t.libelle as type"; 470 $sql .= ",".$this->db->pdate("d.datefin")." as datefin"; 471 $sql .= ", d.pays, p.rowid as pays_id, p.code as pays_code, p.libelle as pays_lib"; 472 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."adherent_type as t"; 473 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_pays as p ON d.pays = p.rowid"; 474 $sql .= " WHERE d.rowid = $rowid AND d.fk_adherent_type = t.rowid"; 475 476 $result=$this->db->query( $sql); 477 if ($result) 478 { 479 if ($this->db->num_rows($result)) 480 { 481 $obj = $this->db->fetch_object($result); 482 483 $this->id = $obj->rowid; 484 $this->typeid = $obj->fk_adherent_type; 485 $this->type = $obj->type; 486 $this->statut = $obj->statut; 487 $this->public = $obj->public; 488 $this->date = $obj->datedon; 489 $this->prenom = stripslashes($obj->prenom); 490 $this->nom = stripslashes($obj->nom); 491 $this->fullname = $obj->nom.($obj->nom&&$obj->prenom?' ':'').$obj->prenom; 492 $this->societe = stripslashes($obj->societe); 493 $this->adresse = stripslashes($obj->adresse); 494 $this->cp = stripslashes($obj->cp); 495 $this->ville = stripslashes($obj->ville); 496 $this->pays_id = $obj->pays_id; 497 $this->pays_code = $obj->pays_code; 498 if ($langs->trans("Country".$obj->pays_code) != "Country".$obj->pays_code) $this->pays = $langs->trans("Country".$obj->pays_code); 499 elseif ($obj->pays_lib) $this->pays=$obj->pays_lib; 500 else $this->pays=$obj->pays; 501 $this->email = stripslashes($obj->email); 502 $this->login = stripslashes($obj->login); 503 $this->pass = stripslashes($obj->pass); 504 $this->naiss = stripslashes($obj->naiss); 505 $this->photo = stripslashes($obj->photo); 506 $this->datefin = $obj->datefin; 507 $this->commentaire = stripslashes($obj->note); 508 $this->morphy = $obj->morphy; 509 } 510 } 511 else 512 { 513 dolibarr_print_error($this->db); 514 } 515 516 } 517 518 519 /** 520 \brief Fonction qui récupére les données optionelles de l'adhérent 521 \param rowid 522 */ 523 524 function fetch_optionals($rowid) 525 { 526 $tab=array(); 527 $sql = "SELECT *"; 528 $sql .= " FROM ".MAIN_DB_PREFIX."adherent_options"; 529 $sql .= " WHERE adhid=$rowid"; 530 531 $result=$this->db->query( $sql); 532 533 if ($result) 534 { 535 if ($this->db->num_rows()) 536 { 537 $tab = $this->db->fetch_array($result); 538 539 foreach ($tab as $key => $value) 540 { 541 if ($key != 'optid' && $key != 'tms' && $key != 'adhid') 542 { 543 // we can add this attribute to adherent object 544 $this->array_options["options_$key"]=$value; 545 } 546 } 547 } 548 } 549 else 550 { 551 dolibarr_print_error($this->db); 552 } 553 554 } 555 556 /* 557 * fetch optional attribute name 558 */ 559 function fetch_name_optionals() 560 { 561 $array_name_options=array(); 562 $sql = "SHOW COLUMNS FROM ".MAIN_DB_PREFIX."adherent_options"; 563 564 $result=$this->db->query( $sql); 565 566 if ($result) 567 { 568 if ($this->db->num_rows()) 569 { 570 //$array_name_options[]=$tab->Field; 571 while ($tab = $this->db->fetch_object($result)) 572 { 573 if ($tab->Field != 'optid' && $tab->Field != 'tms' && $tab->Field != 'adhid') 574 { 575 // we can add this attribute to adherent object 576 $array_name_options[]=$tab->Field; 577 } 578 } 579 return $array_name_options; 580 } 581 else 582 { 583 return array(); 584 } 585 } 586 else 587 { 588 dolibarr_print_error($this->db); 589 return array() ; 590 } 591 592 } 593 594 /** 595 \brief Fonction qui insère la cotisation dans la base de données 596 \param date Date cotisation 597 \param montant Montant cotisation 598 \return int rowid de l'entrée ajoutée, <0 si erreur 599 */ 600 function cotisation($date, $montant) 601 { 602 $this->db->begin(); 603 604 $sql = "INSERT INTO ".MAIN_DB_PREFIX."cotisation (fk_adherent, datec, dateadh, cotisation)"; 605 $sql .= " VALUES ($this->id, now(), ".$this->db->idate($date).", $montant)"; 606 607 $result=$this->db->query($sql); 608 if ($result) 609 { 610 if ( $this->db->affected_rows($result) ) 611 { 612 $rowid=$this->db->last_insert_id(MAIN_DB_PREFIX."cotisation"); 613 $datefin = mktime(12, 0 , 0, 614 strftime("%m",$date), 615 strftime("%d",$date), 616 strftime("%Y",$date)+1) - (24 * 3600); 617 618 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET datefin = ".$this->db->idate($datefin)." WHERE rowid =". $this->id; 619 if ( $this->db->query( $sql) ) 620 { 621 $this->db->commit(); 622 return $rowid; 623 } 624 else 625 { 626 $this->error=$this->db->error(); 627 $this->db->rollback(); 628 return -3; 629 } 630 } 631 else 632 { 633 $this->error=$this->db->error(); 634 $this->db->rollback(); 635 return -2; 636 } 637 } 638 else 639 { 640 $this->error=$this->db->error(); 641 $this->db->rollback(); 642 return -1; 643 } 644 } 645 646 /** 647 \brief fonction qui vérifie que l'utilisateur est valide 648 \param userid userid de l'adhérent 649 */ 650 651 function validate($userid) 652 { 653 654 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET "; 655 $sql .= "statut=1"; 656 $sql .= ",fk_user_valid=".$userid; 657 658 $sql .= " WHERE rowid = $this->id"; 659 660 $result = $this->db->query($sql); 661 662 if ($result) 663 { 664 return 1; 665 } 666 else 667 { 668 dolibarr_print_error($this->db); 669 return 0; 670 } 671 } 672 673 /** 674 \brief fonction qui résilie un adhérent 675 \param userid userid de de l'adhérent 676 */ 677 678 function resiliate($userid) 679 { 680 681 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET "; 682 $sql .= "statut=0"; 683 $sql .= ",fk_user_valid=".$userid; 684 685 $sql .= " WHERE rowid = $this->id"; 686 687 $result = $this->db->query($sql); 688 689 if ($result) 690 { 691 return 1; 692 } 693 else 694 { 695 dolibarr_print_error($this->db); 696 return 0; 697 } 698 } 699 700 701 /** 702 \brief fonction qui ajoute l'adhérent au abonnements automatiques 703 \param adht 704 \remarks mailing-list, spip, glasnost, etc... 705 */ 706 707 function add_to_abo($adht) 708 { 709 $err=0; 710 // mailman 711 if (defined("ADHERENT_USE_MAILMAN") && ADHERENT_USE_MAILMAN == 1) 712 { 713 if(!$this->add_to_mailman()) 714 { 715 $err+=1; 716 } 717 } 718 719 if ($adht->vote == 'yes' && 720 defined("ADHERENT_USE_GLASNOST") && ADHERENT_USE_GLASNOST ==1 && 721 defined("ADHERENT_USE_GLASNOST_AUTO") && ADHERENT_USE_GLASNOST_AUTO ==1 722 ) 723 { 724 if(!$this->add_to_glasnost()){ 725 $err+=1; 726 } 727 } 728 if ( 729 defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 && 730 defined("ADHERENT_USE_SPIP_AUTO") && ADHERENT_USE_SPIP_AUTO ==1 731 ) 732 { 733 if(!$this->add_to_spip()){ 734 $err+=1; 735 } 736 } 737 if ($err>0){ 738 // error 739 return 0; 740 }else{ 741 return 1; 742 } 743 } 744 745 746 /** 747 \brief fonction qui supprime l'adhérent des abonnements automatiques 748 \param adht 749 \remarks mailing-list, spip, glasnost, etc... 750 */ 751 752 function del_to_abo($adht) 753 { 754 $err=0; 755 // mailman 756 if (defined("ADHERENT_USE_MAILMAN") && ADHERENT_USE_MAILMAN == 1) 757 { 758 if(!$this->del_to_mailman()){ 759 $err+=1; 760 } 761 } 762 if ($adht->vote == 'yes' && 763 defined("ADHERENT_USE_GLASNOST") && ADHERENT_USE_GLASNOST ==1 && 764 defined("ADHERENT_USE_GLASNOST_AUTO") && ADHERENT_USE_GLASNOST_AUTO ==1 765 ) 766 { 767 if(!$this->del_to_glasnost()){ 768 $err+=1; 769 } 770 } 771 if ( 772 defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 && 773 defined("ADHERENT_USE_SPIP_AUTO") && ADHERENT_USE_SPIP_AUTO ==1 774 ) 775 { 776 if(!$this->del_to_spip()){ 777 $err+=1; 778 } 779 } 780 if ($err>0){ 781 // error 782 return 0; 783 }else{ 784 return 1; 785 } 786 } 787 788 /** 789 \brief fonction qui donne les droits rédacteurs dans spip 790 */ 791 792 function add_to_spip() 793 { 794 if (defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 && 795 defined('ADHERENT_SPIP_SERVEUR') && ADHERENT_SPIP_SERVEUR != '' && 796 defined('ADHERENT_SPIP_USER') && ADHERENT_SPIP_USER != '' && 797 defined('ADHERENT_SPIP_PASS') && ADHERENT_SPIP_PASS != '' && 798 defined('ADHERENT_SPIP_DB') && ADHERENT_SPIP_DB != '' 799 ){ 800 $mdpass=md5($this->pass); 801 $htpass=crypt($this->pass,initialiser_sel()); 802 $query = "INSERT INTO spip_auteurs (nom, email, login, pass, htpass, alea_futur, statut) VALUES(\"".$this->prenom." ".$this->nom."\",\"".$this->email."\",\"".$this->login."\",\"$mdpass\",\"$htpass\",FLOOR(32000*RAND()),\"1comite\")"; 803 // $mydb=new Db('mysql',ADHERENT_SPIP_SERVEUR,ADHERENT_SPIP_USER,ADHERENT_SPIP_PASS,ADHERENT_SPIP_DB); 804 $mydb=new DoliDb('mysql',ADHERENT_SPIP_SERVEUR,ADHERENT_SPIP_USER,ADHERENT_SPIP_PASS,ADHERENT_SPIP_DB); 805 $result = $mydb->query($query); 806 807 if ($result) 808 { 809 $mydb->close(); 810 return 1; 811 } 812 else 813 { 814 $this->errorstr=$mydb->error(); 815 return 0; 816 } 817 } 818 } 819 820 /** 821 \brief fonction qui enlève les droits rédacteurs dans spip 822 */ 823 824 function del_to_spip() 825 { 826 if (defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 && 827 defined('ADHERENT_SPIP_SERVEUR') && ADHERENT_SPIP_SERVEUR != '' && 828 defined('ADHERENT_SPIP_USER') && ADHERENT_SPIP_USER != '' && 829 defined('ADHERENT_SPIP_PASS') && ADHERENT_SPIP_PASS != '' && 830 defined('ADHERENT_SPIP_DB') && ADHERENT_SPIP_DB != '' 831 ){ 832 $query = "DELETE FROM spip_auteurs WHERE login='".$this->login."'"; 833 $mydb=new DoliDb('mysql',ADHERENT_SPIP_SERVEUR,ADHERENT_SPIP_USER,ADHERENT_SPIP_PASS,ADHERENT_SPIP_DB); 834 $result = $mydb->query($query); 835 836 if ($result) 837 { 838 $mydb->close(); 839 return 1; 840 } 841 else 842 { 843 $this->errorstr=$mydb->error(); 844 return 0; 845 } 846 } 847 } 848 849 /** 850 \brief Fonction qui dit si cet utilisateur est un rédacteur existant dans spip 851 \return int 1=existe, 0=n'existe pas, -1=erreur 852 */ 853 854 function is_in_spip() 855 { 856 if (defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 && 857 defined('ADHERENT_SPIP_SERVEUR') && ADHERENT_SPIP_SERVEUR != '' && 858 defined('ADHERENT_SPIP_USER') && ADHERENT_SPIP_USER != '' && 859 defined('ADHERENT_SPIP_PASS') && ADHERENT_SPIP_PASS != '' && 860 defined('ADHERENT_SPIP_DB') && ADHERENT_SPIP_DB != '') 861 { 862 863 $query = "SELECT login FROM spip_auteurs WHERE login='".$this->login."'"; 864 $mydb=new DoliDb('mysql',ADHERENT_SPIP_SERVEUR,ADHERENT_SPIP_USER,ADHERENT_SPIP_PASS,ADHERENT_SPIP_DB); 865 866 if ($mydb->ok) { 867 868 $result = $mydb->query($query); 869 870 if ($result) 871 { 872 if ($mydb->num_rows()) 873 { 874 # nous avons au moins une reponse 875 $mydb->close(); 876 return 1; 877 } 878 else 879 { 880 # nous n'avons pas de reponse => n'existe pas 881 $mydb->close(); 882 return 0; 883 } 884 } 885 else 886 { 887 # error 888 $this->errorstr=$mydb->error(); 889 return -1; 890 } 891 } else { 892 $this->errorstr="Echec de connexion avec les identifiants ".ADHERENT_SPIP_SERVEUR." ".ADHERENT_SPIP_USER." ".ADHERENT_SPIP_PASS." ".ADHERENT_SPIP_DB; 893 return -1; 894 } 895 } 896 } 897 898 899 /** 900 \brief Fonction qui ajoute l'utilisateur dans glasnost 901 */ 902 903 function add_to_glasnost() 904 { 905 if (defined("ADHERENT_USE_GLASNOST") && ADHERENT_USE_GLASNOST ==1 && 906 defined('ADHERENT_GLASNOST_SERVEUR') && ADHERENT_GLASNOST_SERVEUR != '' && 907 defined('ADHERENT_GLASNOST_USER') && ADHERENT_GLASNOST_USER != '' && 908 defined('ADHERENT_GLASNOST_PASS') && ADHERENT_GLASNOST_PASS != '' 909 ){ 910 // application token is not useful here 911 $applicationtoken=''; 912 list($success, $response) = 913 XMLRPC_request(ADHERENT_GLASNOST_SERVEUR.':8001', 914 '/RPC2', 915 'callGateway', 916 array(XMLRPC_prepare("glasnost://".ADHERENT_GLASNOST_SERVEUR."/authentication"), 917 XMLRPC_prepare('getUserIdAndToken'), 918 XMLRPC_prepare(array("glasnost://".ADHERENT_GLASNOST_SERVEUR."/authentication","$applicationtoken",ADHERENT_GLASNOST_USER,ADHERENT_GLASNOST_PASS)) 919 ) 920 ); 921 if ($success){ 922 $userid=$response[0]; 923 $usertoken=$response[1]; 924 }else{ 925 $this->errorstr=$response['faultString']; 926 return 0; 927 } 928 929 list($success,$response)= 930 XMLRPC_request(ADHERENT_GLASNOST_SERVEUR.':8001', 931 '/RPC2', 932 'callGateway', 933 array(XMLRPC_prepare("glasnost://".ADHERENT_GLASNOST_SERVEUR."/people"), 934 XMLRPC_prepare('addObject'), 935 XMLRPC_prepare(array( 936 "glasnost://".ADHERENT_GLASNOST_SERVEUR."/people", 937 "$applicationtoken", 938 $usertoken, 939 array( 940 '__thingCategory__'=>'object', 941 '__thingName__'=> 'Person', 942 'firstName'=>$this->prenom, 943 'lastName'=>$this->nom, 944 'login'=>$this->login, 945 'email'=>$this->email 946 ) 947 ) 948 ) 949 ) 950 ); 951 if ($success){ 952 $personid=$response[0]; 953 }else{ 954 $this->errorstr=$response['faultString']; 955 return 0; 956 } 957 return 1; 958 }else{ 959 $this->errorstr="Constantes de connection non definies"; 960 return 0; 961 } 962 } 963 964 /** 965 \brief fonction qui enlève l'utilisateur de glasnost 966 */ 967 968 function del_to_glasnost() 969 { 970 if (defined("ADHERENT_USE_GLASNOST") && ADHERENT_USE_GLASNOST ==1 && 971 defined('ADHERENT_GLASNOST_SERVEUR') && ADHERENT_GLASNOST_SERVEUR != '' && 972 defined('ADHERENT_GLASNOST_USER') && ADHERENT_GLASNOST_USER != '' && 973 defined('ADHERENT_GLASNOST_PASS') && ADHERENT_GLASNOST_PASS != '' 974 ){ 975 // application token is not useful here 976 $applicationtoken=''; 977 list($success, $response) = 978 XMLRPC_request(ADHERENT_GLASNOST_SERVEUR.':8001', 979 '/RPC2', 980 'callGateway', 981 array(XMLRPC_prepare("glasnost://".ADHERENT_GLASNOST_SERVEUR."/authentication"), 982 XMLRPC_prepare('getUserIdAndToken'), 983 XMLRPC_prepare(array("glasnost://".ADHERENT_GLASNOST_SERVEUR."/authentication","$applicationtoken",ADHERENT_GLASNOST_USER,ADHERENT_GLASNOST_PASS)) 984 ) 985 ); 986 if ($success){ 987 $userid=$response[0]; 988 $usertoken=$response[1]; 989 }else{ 990 return 0; 991 } 992 // recuperation du personID 993 list($success,$response)= 994 XMLRPC_request(ADHERENT_GLASNOST_SERVEUR.':8001', 995 '/RPC2', 996 'callGateway', 997 array(XMLRPC_prepare("glasnost://".ADHERENT_GLASNOST_SERVEUR."/people"), 998 XMLRPC_prepare('getObjectByLogin'), 999 XMLRPC_prepare(array( 1000 "glasnost://".ADHERENT_GLASNOST_SERVEUR."/people", 1001 "$applicationtoken", 1002 $usertoken, 1003 $this->login 1004 ) 1005 ) 1006 ) 1007 ); 1008 if ($success){ 1009 $personid=$response['id']; 1010 }else{ 1011 $this->errorstr=$response['faultString']; 1012 return 0; 1013 } 1014 if (defined('ADHERENT_GLASNOST_DEFAULT_GROUPID') && ADHERENT_GLASNOST_DEFAULT_GROUPID != ''){ 1015 // recuperation des personne de ce groupe 1016 list($success,$response)= 1017 XMLRPC_request(ADHERENT_GLASNOST_SERVEUR.':8001', 1018 '/RPC2', 1019 'callGateway', 1020 array(XMLRPC_prepare("glasnost://".ADHERENT_GLASNOST_SERVEUR."/groups"), 1021 XMLRPC_prepare('getObject'), 1022 XMLRPC_prepare(array( 1023 "glasnost://".ADHERENT_GLASNOST_SERVEUR."/groups", 1024 "$applicationtoken", 1025 $usertoken, 1026 ADHERENT_GLASNOST_DEFAULT_GROUPID 1027 ) 1028 ) 1029 ) 1030 ); 1031 if ($success){ 1032 $groupids=$response['membersSet']; 1033 }else{ 1034 $this->errorstr=$response['faultString']; 1035 return 0; 1036 } 1037 // TODO faire la verification que le user n'est pas dans ce 1038 // groupe par defaut. si il y ai il faut l'effacer et 1039 // modifier le groupe 1040 } 1041 // suppression du personID 1042 list($success,$response)= 1043 XMLRPC_request(ADHERENT_GLASNOST_SERVEUR.':8001', 1044 '/RPC2', 1045 'callGateway', 1046 array(XMLRPC_prepare("glasnost://".ADHERENT_GLASNOST_SERVEUR."/people"), 1047 XMLRPC_prepare('deleteObject'), 1048 XMLRPC_prepare(array( 1049 "glasnost://".ADHERENT_GLASNOST_SERVEUR."/people", 1050 "$applicationtoken", 1051 $usertoken, 1052 $personid 1053 ) 1054 ) 1055 ) 1056 ); 1057 if ($success){ 1058 return 1; 1059 }else{ 1060 $this->errorstr=$response['faultString']; 1061 return 0; 1062 } 1063 }else{ 1064 $this->errorstr="Constantes de connection non definies"; 1065 return 0; 1066 } 1067 } 1068 1069 /** 1070 \brief fonction qui vérifie si l'utilisateur est dans glasnost 1071 */ 1072 1073 function is_in_glasnost() 1074 { 1075 if (defined("ADHERENT_USE_GLASNOST") && ADHERENT_USE_GLASNOST ==1 && 1076 defined('ADHERENT_GLASNOST_SERVEUR') && ADHERENT_GLASNOST_SERVEUR != '' && 1077 defined('ADHERENT_GLASNOST_USER') && ADHERENT_GLASNOST_USER != '' && 1078 defined('ADHERENT_GLASNOST_PASS') && ADHERENT_GLASNOST_PASS != '' 1079 ){ 1080 // application token is not useful here 1081 $applicationtoken=''; 1082 list($success, $response) = 1083 XMLRPC_request(ADHERENT_GLASNOST_SERVEUR.':8001', 1084 '/RPC2', 1085 'callGateway', 1086 array(XMLRPC_prepare("glasnost://".ADHERENT_GLASNOST_SERVEUR."/authentication"), 1087 XMLRPC_prepare('getUserIdAndToken'), 1088 XMLRPC_prepare(array("glasnost://".ADHERENT_GLASNOST_SERVEUR."/authentication","$applicationtoken",ADHERENT_GLASNOST_USER,ADHERENT_GLASNOST_PASS)) 1089 ) 1090 ); 1091 if ($success){ 1092 $userid=$response[0]; 1093 $usertoken=$response[1]; 1094 }else{ 1095 return 0; 1096 } 1097 // recuperation du personID 1098 list($success,$response)= 1099 XMLRPC_request(ADHERENT_GLASNOST_SERVEUR.':8001', 1100 '/RPC2', 1101 'callGateway', 1102 array(XMLRPC_prepare("glasnost://".ADHERENT_GLASNOST_SERVEUR."/people"), 1103 XMLRPC_prepare('getObjectByLogin'), 1104 XMLRPC_prepare(array( 1105 "glasnost://".ADHERENT_GLASNOST_SERVEUR."/people", 1106 "$applicationtoken", 1107 $usertoken, 1108 $this->login 1109 ) 1110 ) 1111 ) 1112 ); 1113 if ($success){ 1114 $personid=$response['id']; 1115 return 1; 1116 }else{ 1117 $this->errorstr=$response['faultString']; 1118 return 0; 1119 } 1120 }else{ 1121 $this->errorstr="Constantes de connection non definies"; 1122 return 0; 1123 } 1124 } 1125 1126 /** 1127 \brief fonction qui rajoute l'utilisateur dans mailman 1128 */ 1129 1130 function add_to_mailman($listes='') 1131 { 1132 if (defined("ADHERENT_MAILMAN_URL") && ADHERENT_MAILMAN_URL != '' && defined("ADHERENT_MAILMAN_LISTS") && ADHERENT_MAILMAN_LISTS != '') 1133 { 1134 if ($listes ==''){ 1135 $lists=explode(',',ADHERENT_MAILMAN_LISTS); 1136 }else{ 1137 $lists=explode(',',$listes); 1138 } 1139 foreach ($lists as $list) 1140 { 1141 // on remplace dans l'url le nom de la liste ainsi 1142 // que l'email et le mot de passe 1143 $patterns = array ( 1144 '/%LISTE%/', 1145 '/%EMAIL%/', 1146 '/%PASS%/', 1147 '/%ADMINPW%/', 1148 '/%SERVER%/' 1149 ); 1150 $replace = array ( 1151 $list, 1152 $this->email, 1153 $this->pass, 1154 ADHERENT_MAILMAN_ADMINPW, 1155 ADHERENT_MAILMAN_SERVER 1156 ); 1157 $curl_url = preg_replace ($patterns, $replace, ADHERENT_MAILMAN_URL); 1158 1159 $ch = curl_init(); 1160 curl_setopt($ch, CURLOPT_URL,"$curl_url"); 1161 //curl_setopt($ch, CURLOPT_URL,"http://www.j1b.org/"); 1162 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 1163 curl_setopt($ch, CURLOPT_FAILONERROR, 1); 1164 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 1165 curl_setopt($ch, CURLOPT_TIMEOUT, 5); 1166 //curl_setopt($ch, CURLOPT_POST, 0); 1167 //curl_setopt($ch, CURLOPT_POSTFIELDS, "a=3&b=5"); 1168 //--- Start buffering 1169 //ob_start(); 1170 $result=curl_exec ($ch); 1171 dolibarr_syslog($result); 1172 //--- End buffering and clean output 1173 //ob_end_clean(); 1174 if (curl_error($ch) > 0) 1175 { 1176 // error 1177 return 0; 1178 } 1179 curl_close ($ch); 1180 1181 } 1182 return 1; 1183 } 1184 else 1185 { 1186 $this->errorstr="Constantes de connection non definies"; 1187 return 0; 1188 } 1189 } 1190 1191 /** 1192 \brief fonction qui désinscrit l'utilisateur de toutes les mailing list mailman 1193 \ remarks utilie lors de la résiliation d'adhésion 1194 */ 1195 1196 function del_to_mailman($listes='') 1197 { 1198 if (defined("ADHERENT_MAILMAN_UNSUB_URL") && ADHERENT_MAILMAN_UNSUB_URL != '' && defined("ADHERENT_MAILMAN_LISTS") && ADHERENT_MAILMAN_LISTS != '') 1199 { 1200 if ($listes==''){ 1201 $lists=explode(',',ADHERENT_MAILMAN_LISTS); 1202 if (defined("ADHERENT_MAILMAN_LISTS_COTISANT") && ADHERENT_MAILMAN_LISTS_COTISANT !=''){ 1203 $lists=array_merge ($lists,explode(',',ADHERENT_MAILMAN_LISTS_COTISANT)); 1204 } 1205 }else{ 1206 $lists=explode(',',$listes); 1207 } 1208 foreach ($lists as $list) 1209 { 1210 // on remplace dans l'url le nom de la liste ainsi 1211 // que l'email et le mot de passe 1212 $patterns = array ( 1213 '/%LISTE%/', 1214 '/%EMAIL%/', 1215 '/%PASS%/', 1216 '/%ADMINPW%/', 1217 '/%SERVER%/' 1218 ); 1219 $replace = array ( 1220 $list, 1221 $this->email, 1222 $this->pass, 1223 ADHERENT_MAILMAN_ADMINPW, 1224 ADHERENT_MAILMAN_SERVER 1225 ); 1226 $curl_url = preg_replace ($patterns, $replace, ADHERENT_MAILMAN_UNSUB_URL); 1227 1228 $ch = curl_init(); 1229 curl_setopt($ch, CURLOPT_URL,"$curl_url"); 1230 //curl_setopt($ch, CURLOPT_URL,"http://www.j1b.org/"); 1231 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 1232 curl_setopt($ch, CURLOPT_FAILONERROR, 1); 1233 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 1234 curl_setopt($ch, CURLOPT_TIMEOUT, 5); 1235 //curl_setopt($ch, CURLOPT_POST, 0); 1236 //curl_setopt($ch, CURLOPT_POSTFIELDS, "a=3&b=5"); 1237 //--- Start buffering 1238 //ob_start(); 1239 $result=curl_exec ($ch); 1240 dolibarr_syslog($result); 1241 //--- End buffering and clean output 1242 //ob_end_clean(); 1243 if (curl_error($ch) > 0) 1244 { 1245 // error 1246 return 0; 1247 } 1248 curl_close ($ch); 1249 1250 } 1251 return 1; 1252 } 1253 else 1254 { 1255 $this->errorstr="Constantes de connection non definies"; 1256 return 0; 1257 } 1258 } 1259 1260 /** 1261 * \brief Retourne le nom complet de l'adhérent 1262 * \return string Nom complet 1263 */ 1264 function getFullname() 1265 { 1266 if ($this->nom && $this->prenom) return $this->nom.' '.$this->prenom; 1267 if ($this->nom) return $this->nom; 1268 if ($this->prenom) return $this->prenom; 1269 return ''; 1270 } 1271 1272 /** 1273 * \brief Retourne le libellé du statut d'un adhérent (brouillon, validé, résilié) 1274 * \return string Libellé 1275 */ 1276 function getLibStatut() 1277 { 1278 return $this->LibStatut($this->statut); 1279 } 1280 1281 /** 1282 * \brief Renvoi le libellé d'un statut donné 1283 * \param statut id statut 1284 * \return string Libellé 1285 */ 1286 function LibStatut($statut) 1287 { 1288 global $langs; 1289 $langs->load("members"); 1290 if ($statut == -1) return $langs->trans("MemberStatusDraft"); 1291 if ($statut == 1) return $langs->trans("MemberStatusActive"); 1292 if ($statut == 0) return $langs->trans("MemberStatusResiliated"); 1293 } 1294 1295 1296 /** 1297 * \brief Charge indicateurs this->nb de tableau de bord 1298 * \return int <0 si ko, >0 si ok 1299 */ 1300 function load_state_board() 1301 { 1302 global $conf; 1303 1304 $this->nb=array(); 1305 1306 $sql = "SELECT count(a.rowid) as nb"; 1307 $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a"; 1308 $sql.= " WHERE a.statut > 0"; 1309 $resql=$this->db->query($sql); 1310 if ($resql) 1311 { 1312 while ($obj=$this->db->fetch_object($resql)) 1313 { 1314 $this->nb["members"]=$obj->nb; 1315 } 1316 return 1; 1317 } 1318 else 1319 { 1320 dolibarr_print_error($this->db); 1321 $this->error=$this->db->error(); 1322 return -1; 1323 } 1324 1325 } 1326 1327 /** 1328 * \brief Charge indicateurs this->nbtodo et this->nbtodolate de tableau de bord 1329 * \param user Objet user 1330 * \return int <0 si ko, >0 si ok 1331 */ 1332 function load_board($user) 1333 { 1334 global $conf; 1335 1336 if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe 1337 1338 $this->nbtodo=$this->nbtodolate=0; 1339 $sql = "SELECT a.rowid,".$this->db->pdate("a.datefin")." as datefin"; 1340 $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a"; 1341 $sql.= " WHERE a.statut=1"; 1342 $resql=$this->db->query($sql); 1343 if ($resql) 1344 { 1345 while ($obj=$this->db->fetch_object($resql)) 1346 { 1347 $this->nbtodo++; 1348 if ($obj->datefin < (time() - $conf->adherent->cotisation->warning_delay)) $this->nbtodolate++; 1349 } 1350 return 1; 1351 } 1352 else 1353 { 1354 dolibarr_print_error($this->db); 1355 $this->error=$this->db->error(); 1356 return -1; 1357 } 1358 } 1359 1360 } 1361 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |