PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/classes/controleurs/GestionAdherents/AjoutAdherentControleur.php

http://zeybux.googlecode.com/
PHP | 173 lines | 114 code | 22 blank | 37 comment | 16 complexity | 6d61e9fef5bb9dab3285dc9203274984 MD5 | raw file
  1. <?php
  2. //****************************************************************
  3. //
  4. // Createur : Julien PIERRE
  5. // Date de creation : 01/02/2010
  6. // Fichier : AjoutAdherentControleur.php
  7. //
  8. // Description : Classe AjoutAdherentControleur
  9. //
  10. //****************************************************************
  11. // Inclusion des classes
  12. include_once(CHEMIN_CLASSES_UTILS . "StringUtils.php" );
  13. include_once(CHEMIN_CLASSES_VO . "AutorisationVO.php");
  14. include_once(CHEMIN_CLASSES_MANAGERS . "ModuleManager.php");
  15. include_once(CHEMIN_CLASSES_MANAGERS . "AutorisationManager.php");
  16. include_once(CHEMIN_CLASSES_MANAGERS . "AdherentManager.php");
  17. include_once(CHEMIN_CLASSES_RESPONSE . MOD_GESTION_ADHERENTS . "/AfficheAjoutAdherentResponse.php" );
  18. include_once(CHEMIN_CLASSES_MANAGERS . "CompteManager.php");
  19. include_once(CHEMIN_CLASSES_MANAGERS . "OperationManager.php");
  20. include_once(CHEMIN_CLASSES_VALIDATEUR . MOD_GESTION_ADHERENTS . "/AdherentValid.php" );
  21. include_once(CHEMIN_CLASSES_RESPONSE . MOD_GESTION_ADHERENTS . "/AjoutAdherentResponse.php" );
  22. include_once(CHEMIN_CLASSES_TOVO . "AdherentToVO.php" );
  23. include_once(CHEMIN_CLASSES_MANAGERS . "IdentificationManager.php");
  24. include_once(CHEMIN_CLASSES_UTILS . "MotDePasseUtils.php" );
  25. include_once(CHEMIN_CLASSES_SERVICE . "MailingListeService.php");
  26. /**
  27. * @name AjoutAdherentControleur
  28. * @author Julien PIERRE
  29. * @since 01/02/2010
  30. * @desc Classe controleur d'un Ajout d'adherent
  31. */
  32. class AjoutAdherentControleur
  33. {
  34. /**
  35. * @name getListeModule()
  36. * @desc Retourne l'ensemble des modules
  37. */
  38. public function getListeModule() {
  39. $lResponse = new AfficheAjoutAdherentResponse();
  40. $lResponse->setModules(ModuleManager::selectAllVisible());
  41. return $lResponse;
  42. }
  43. /**
  44. * @name ajoutAdherent($pParam)
  45. * @return string
  46. * @desc Controle et formatte les données avant de les insérer dans la BDD. Retourne l'Id en cas de succés ou une erreur.
  47. */
  48. public function ajoutAdherent($pParam) {
  49. // Initialisation du Logger
  50. $lLogger = &Log::singleton('file', CHEMIN_FICHIER_LOGS);
  51. $lLogger->setMask(Log::MAX(LOG_LEVEL));
  52. $lVr = AdherentValid::validAjout($pParam);
  53. if($lVr->getValid()) {
  54. include_once(CHEMIN_CONFIGURATION . "Mail.php"); // Les Constantes de mail
  55. $lAdherent = AdherentToVO::convertFromArray($pParam);
  56. $lAdherentCompte = $pParam['compte'];
  57. $lCompte = CompteManager::selectByLabel($lAdherentCompte);
  58. if(empty($lAdherentCompte) || is_null($lCompte[0]->getId())) {
  59. // Création d'un nouveau compte
  60. $lCompte = new CompteVO();
  61. $lIdCompte = CompteManager::insert($lCompte);
  62. // Le label est l'id du compte par défaut
  63. $lCompte->setId($lIdCompte);
  64. $lCompte->setLabel('C' . $lIdCompte);
  65. CompteManager::update($lCompte);
  66. // Initialisation du compte
  67. $lOperation = new OperationVO();
  68. $lOperation->setIdCompte($lIdCompte);
  69. $lOperation->setMontant(0);
  70. $lOperation->setLibelle("Création du compte");
  71. $lOperation->setDate(StringUtils::dateAujourdhuiDb());
  72. //$lOperation->setType(1);
  73. $lOperation->setIdCommande(0);
  74. $lOperation->setTypePaiement(-1);
  75. OperationManager::insert($lOperation);
  76. $lAdherent->setIdCompte($lIdCompte);
  77. } else {
  78. $lAdherent->setIdCompte($lCompte[0]->getId());
  79. }
  80. // Insertion de la premičre mise ŕ jour
  81. $lAdherent->setDateMaj( StringUtils::dateTimeAujourdhuiDb() );
  82. // L'adherent n'est pas supprimé
  83. $lAdherent->setEtat(1);
  84. // Enregistre l'adherent dans la BDD
  85. $lId = AdherentManager::insert( $lAdherent );
  86. // Ajout des autorisations du compte
  87. foreach( $lAdherent->getListeModule() as $lIdModule) {
  88. $lAutorisation = new AutorisationVO();
  89. $lAutorisation->setIdAdherent($lId);
  90. $lAutorisation->setIdModule($lIdModule);
  91. AutorisationManager::insert($lAutorisation);
  92. }
  93. $lAdherent = AdherentManager::select($lId);
  94. // Insertion des informations de connexion
  95. $lMdp = MotDePasseUtils::generer();
  96. $lIdentification = new IdentificationVO();
  97. $lIdentification->setIdLogin($lId);
  98. $lIdentification->setLogin($lAdherent->getNumero());
  99. $lIdentification->setPass( md5( $lMdp ) );
  100. $lIdentification->setType(1);
  101. $lIdentification->setAutorise(1);
  102. IdentificationManager::insert( $lIdentification );
  103. // Ajout ŕ la mailing liste
  104. $lMailingListeService = new MailingListeService();
  105. if($lAdherent->getCourrielPrincipal() != "") {
  106. $lMailingListeService->insert($lAdherent->getCourrielPrincipal());
  107. }
  108. if($lAdherent->getCourrielSecondaire() != "") {
  109. $lMailingListeService->insert($lAdherent->getCourrielSecondaire());
  110. }
  111. // Envoi du mail de confirmation
  112. if($lAdherent->getCourrielPrincipal() != "") {
  113. $lTo = $lAdherent->getCourrielPrincipal();
  114. } else if($lAdherent->getCourrielSecondaire() != "") {
  115. $lTo = $lAdherent->getCourrielSecondaire();
  116. } else { // Pas de mail sur le compte : Envoi au gestionnaire
  117. $lTo = MAIL_SUPPORT;
  118. }
  119. $lFrom = MAIL_SUPPORT;
  120. $jour = date("d-m-Y");
  121. $heure = date("H:i");
  122. $lSujet = "Votre Compte zeybux";
  123. $lContenu = file_get_contents(CHEMIN_TEMPLATE . MOD_GESTION_ADHERENTS . "/" . "MailAjoutAdherent.html");
  124. $lContenu = str_replace(array("{LOGIN}", "{MOT_PASSE}"), array($lAdherent->getNumero(), $lMdp), $lContenu);
  125. $lHeaders = file_get_contents(CHEMIN_TEMPLATE . COMMUN_TEMPLATE . "/" . "EnteteMail.html");
  126. $lHeaders = str_replace("{FROM}", $lFrom, $lHeaders);
  127. $VerifEnvoiMail = TRUE;
  128. $VerifEnvoiMail = @mail ($lTo, $lSujet, $lContenu, $lHeaders);
  129. if ($VerifEnvoiMail === FALSE) {
  130. $lVr->setValid(false);
  131. $lVr->getLog()->setValid(false);
  132. $lErreur = new VRerreur();
  133. $lErreur->setCode(MessagesErreurs::ERR_118_CODE);
  134. $lErreur->setMessage(MessagesErreurs::ERR_118_MSG);
  135. $lVr->getLog()->addErreur($lErreur);
  136. $lLogger->log("Erreur d'envoi du mail de création de l'adhérent " . $pParam['numero'] . "par : " . $_SESSION[ID_CONNEXION] . ".",PEAR_LOG_INFO); // Maj des logs
  137. return $lVr;
  138. } else {
  139. $lLogger->log("Envoi du mail de création de l'adhérent " . $pParam['numero'] . "par : " . $_SESSION[ID_CONNEXION] . ".",PEAR_LOG_INFO); // Maj des logs
  140. }
  141. $lResponse = new AjoutAdherentResponse();
  142. $lResponse->setId($lId);
  143. $lResponse->setNumero($lAdherent->getNumero());
  144. return $lResponse;
  145. }
  146. return $lVr;
  147. }
  148. }
  149. ?>