PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/src/2.071.0/_inscription.class.php

https://github.com/crepeausucre/soothERP
PHP | 276 lines | 130 code | 44 blank | 102 comment | 23 complexity | e15f29245fa4e662689f2ae03744969e MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0
  1. <?php
  2. // *************************************************************************************************************
  3. // CLASSE COMMUNE AU INSCRIPTION ET AU MODIFICATION
  4. // *************************************************************************************************************
  5. abstract class InscriptionModification{
  6. private $id_profil;
  7. private $id_interface;
  8. private $id_theme;
  9. private $dossier;
  10. private $lib_interface;
  11. private $url;
  12. private $nom_entreprise;
  13. function __construct($id_interface) {
  14. global $bdd;
  15. global $DIR;
  16. if (is_null($id_interface) || !is_numeric($id_interface))
  17. { return false;}
  18. $query = "SELECT id_profil, id_interface, lib_interface, dossier, url, defaut_id_theme as id_theme
  19. FROM interfaces
  20. WHERE id_interface = '".$id_interface."' ";
  21. $resultat = $bdd->query ($query);
  22. if (!$interfaces = $resultat->fetchObject())
  23. { return false;}
  24. $this->id_profil = $interfaces->id_profil;
  25. $this->id_interface = $interfaces->id_interface;
  26. $this->lib_interface = $interfaces->lib_interface;
  27. $this->dossier = $interfaces->dossier;
  28. $this->url = $interfaces->url;
  29. $this->id_theme = $interfaces->id_theme;
  30. global $REF_CONTACT_ENTREPRISE;
  31. $contact_entreprise = new contact($REF_CONTACT_ENTREPRISE);
  32. $this->nom_entreprise = str_replace(CHR(13), " " ,str_replace (CHR(10), " " , $contact_entreprise->getNom()));
  33. }
  34. // *************************************************************************************************************
  35. // *************************************************************************************************************
  36. // INSCRIPTION D'UN CONTACT
  37. // *************************************************************************************************************
  38. // *************************************************************************************************************
  39. // Utilisation de la table Table: annuaire_tmp
  40. //
  41. // id_contact_tmp smallint(5) UNSIGNED NOTNULL auto_increment :
  42. // id_interface smallint(5) UNSIGNED NOTNULL :
  43. // infos mediumtext NOTNULL : liste de couple clé/valeur séparé par un ;
  44. // date_demande datetime NOTNULL :
  45. // code_validation varchar(64) NOTNULL : code pour que l'utilisateur confirme son inscription
  46. // validation_email tinyint(2) NOTNULL : 1 => validation par un collab : ce contact n'a pas de besoin la confirmation par mail :
  47. // - soit c'est une inscription sans confirmation
  48. // - soit c'est une inscription avec confirmation, mais l'utilisateur a déjŕ confirmé son inscription
  49. // 2 => validation par un collab : cet utilisateur doit confirmer son inscription pour pouvoir passer
  50. // ŕ l'étape suivante : validation_email <- 1
  51. // 3 => validation automatique : cet utilisateur doit confirmer son inscription pour pouvoir passer
  52. // ŕ l'étape suivante (création du contact et supression de la ligne)
  53. // mode enum('inscription', 'modification') NOTNULL :
  54. //
  55. //
  56. // listes des clé contenu dans le champ infos :
  57. // id_categorie
  58. // civilite
  59. // nom
  60. // siret
  61. // tva_intra
  62. // admin_pseudo
  63. // admin_emaila
  64. // admin_passworda
  65. // livraison_adresse
  66. // livraison_code
  67. // livraison_ville
  68. // id_pays_livraison
  69. // adresse_adresse
  70. // adresse_code
  71. // adresse_ville
  72. // id_pays_contact
  73. // coordonnee_tel1
  74. // coordonnee_tel2
  75. // coordonnee_fax
  76. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  77. //vérifie qu'il y a les données minimum dans le tableau
  78. //@param $infos_contact array : tableau associatif contenant les informations du contact
  79. //@return boolean : vrai si les données nécessaire ŕ l'inscription sont présente, faux sinon.
  80. protected static function verifie_infos_contact_pour_inscription_ou_modification_contact($infos_contact){
  81. if(is_null($infos_contact) || !is_array($infos_contact))
  82. { return false;}
  83. return isset($infos_contact["nom"])
  84. && isset($infos_contact["admin_pseudo"])
  85. && isset($infos_contact["admin_emaila"])
  86. && isset($infos_contact["admin_passworda"])
  87. && isset($infos_contact["adresse_adresse"])
  88. && isset($infos_contact["adresse_code"])
  89. && isset($infos_contact["adresse_ville"])
  90. && isset($infos_contact["id_pays_contact"]);
  91. }
  92. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  93. //retourne l'eamil du collaborateur ŕ qui les demandes de validation doivent ętre envoyé
  94. //@return mixed : l'email sous forme de string s'il a été trouvé, faux sinon.
  95. protected function getEmail_du_collaborateur(){
  96. global $REF_CONTACT_ENTREPRISE;
  97. $contact_entreprise = new contact($REF_CONTACT_ENTREPRISE);
  98. $coordonnees_entreprise = $contact_entreprise->getCoordonnees();
  99. for($i = 0; $i < count($coordonnees_entreprise); $i++){
  100. if($coordonnees_entreprise[$i]->getEmail())
  101. { return $coordonnees_entreprise[$i]->getEmail();}
  102. }
  103. return false;
  104. }
  105. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  106. //supprimer l'inscription
  107. //@param int $id_contact_tmp : Id du contact temporaire ŕ effacer dans la liste des contact en attente de validation
  108. //(pour une inscription ou une modification
  109. //@return bool : retourne vrai si le contact temporaire ŕ été effécé, faux sinon
  110. protected function supprimer_inscription($id_contact_tmp) {
  111. global $bdd;
  112. $query = "DELETE FROM annuaire_tmp
  113. WHERE id_contact_tmp = '".$id_contact_tmp."' ";
  114. return $bdd->exec($query) > 0;
  115. }
  116. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  117. //fonction d'envoi des mail avec template
  118. protected function envoi_email_templated($to, $sujet, $message) {
  119. //simulation denvois de mail
  120. /*
  121. $separateur_long = "<br /><br />--------------------------------------------------------------------------------<br /><br />";
  122. $separateur_court = "<br />-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
  123. "&nbsp;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
  124. "&nbsp;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
  125. "&nbsp;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-<br />";
  126. $fichier = fopen ("simulation_email.html", "a");
  127. fputs($fichier, $separateur_long.$to.$separateur_court.$sujet.$separateur_court.$message);
  128. fclose($fichier);
  129. return true;
  130. */
  131. //NORMAL
  132. // Envoi de l'email
  133. $mail = new email();
  134. $mail->prepare_envoi(0, 1);
  135. return $mail->envoi_email_templated ($to, $sujet, $message);
  136. }
  137. // *************************************************************************************************************
  138. // Fonctions d'accčs aux données
  139. // *************************************************************************************************************
  140. // Retourne l'identifiant du profil
  141. public function getId_profil() {
  142. return $this->id_profil;
  143. }
  144. // Retourne l'identifiant du id_interface
  145. public function getId_interface() {
  146. return $this->id_interface;
  147. }
  148. // Retourne defaut_id_theme
  149. public function getId_theme() {
  150. return $this->id_theme;
  151. }
  152. // Retourne le dossier
  153. public function getDossier() {
  154. return $this->dossier;
  155. }
  156. // Retourne lib_interface
  157. public function getLib_interface() {
  158. return $this->lib_interface;
  159. }
  160. // Retourne l'url
  161. public function getUrl() {
  162. return $this->url;
  163. }
  164. // Retourne le nom de l'entreprise
  165. public function getNom_entreprise(){
  166. return $this->nom_entreprise;
  167. }
  168. // *************************************************************************************************************
  169. public static function extractEmail($infos){
  170. //expression réguličre qui extrait l'email de la forme "toto@toto.com" du champ info
  171. $pattern = '.*admin_emaila=(([a-zA-Z0-9]+(([\.\-\_]?[a-zA-Z0-9]+)+)?)\@(([a-zA-Z0-9]+[\.\-\_])+[a-zA-Z]{2,4}));.*';
  172. $email_contact = preg_replace('/'.$pattern.'/', '$1', $infos);
  173. if($email_contact == $infos)
  174. { return false;} // l'email n'a pas été trouvé
  175. else{ return $email_contact;}
  176. }
  177. public static function extractNom($infos){
  178. //expression réguličre qui extrait le du champ info
  179. //le champ nom
  180. $pattern = '(.*;nom|$nom)=([^=;]*)(^|;[a-zA-Z_]+=.*)';
  181. $email_contact = preg_replace('/'.$pattern.'/', '$2', $infos);
  182. if($email_contact == $infos)
  183. { return false;} // l'email n'a pas été trouvé
  184. else{ return $email_contact;}
  185. }
  186. public static function extractCivilite($infos){
  187. //expression réguličre qui extrait le du champ info
  188. //le champ nom
  189. $pattern = '(.*;civilite|$civilite)=([^=;]*)(^|;[a-zA-Z_]+=.*)';
  190. $email_contact = preg_replace('/'.$pattern.'/', '$2', $infos);
  191. if($email_contact == $infos)
  192. { return false;} // l'email n'a pas été trouvé
  193. else{ return $email_contact;}
  194. }
  195. public static function extractRef_contact($infos){
  196. //expression réguličre qui extrait le du champ info
  197. //le champ nom
  198. $pattern = '(.*;)?ref_contact=([^=;]*);?.*';
  199. $email_contact = preg_replace('/'.$pattern.'/', '$2', $infos);
  200. if($email_contact == $infos)
  201. { return false;} // l'email n'a pas été trouvé
  202. else{ return $email_contact;}
  203. }
  204. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  205. //retourne l'eamil du collaborateur ŕ qui les demandes de validation doivent ętre envoyé
  206. //@param $id_contact_tmp int : indentifiant du contact temporaire
  207. //@return mixed : l'email sous forme de string s'il a été trouvé, faux sinon.
  208. protected function modification_contact_email_du_contact($id_contact_tmp){
  209. global $bdd;
  210. $query = "SELECT infos
  211. FROM annuaire_tmp
  212. WHERE id_contact_tmp = ".$id_contact_tmp."";
  213. $resultat = $bdd->query ($query);
  214. if (!$res = $resultat->fetchObject())
  215. { return false;}
  216. return $this->extractEmail($res->infos);
  217. }
  218. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  219. //supprimer l'modification
  220. //@param int $id_contact_tmp : Id du contact temporaire ŕ effacer dans la liste des contact en attente de validation
  221. //(pour une modification ou une modification
  222. //@return bool : retourne vrai si le contact temporaire ŕ été effécé, faux sinon
  223. protected function supprimer_modification($id_contact_tmp) {
  224. global $bdd;
  225. $query = "DELETE FROM annuaire_tmp
  226. WHERE id_contact_tmp = '".$id_contact_tmp."' ";
  227. return $bdd->exec($query) > 0;
  228. }
  229. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  230. }
  231. ?>