Advertisement
Guest User

Untitled

a guest
Jan 9th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.79 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: lasezn
  5. * Date: 04/12/2015
  6. * Time: 16:24
  7. */
  8.  
  9. namespace AppBundle\Even;
  10.  
  11.  
  12.  
  13. use AppBundle\Exception\EvenException;
  14.  
  15. class EvenManager
  16. {
  17. private
  18. $ldap_service,
  19. $ldap_dn,
  20. $ldap_password,
  21. $ldap_basedn_emp,
  22. $ldap_basedn_ext,
  23. $ldap_basedn_comp,
  24. $ldap_basedn_loca,
  25. $ldap_filtre_user,
  26. $ldap_filtre_comp,
  27. $ldap_filtre_loca;
  28.  
  29. public function __construct($ldap_service, $ldap_dn, $ldap_password, $ldap_basedn_emp, $ldap_basedn_ext, $ldap_basedn_comp, $ldap_basedn_loca, $ldap_filtre_user, $ldap_filtre_comp, $ldap_filtre_loca){
  30. $this->ldap_service = $ldap_service;
  31. $this->ldap_dn = $ldap_dn;
  32. $this->ldap_password = $ldap_password;
  33. $this->ldap_basedn_emp = $ldap_basedn_emp;
  34. $this->ldap_basedn_ext = $ldap_basedn_ext;
  35. $this->ldap_basedn_comp = $ldap_basedn_comp;
  36. $this->ldap_basedn_loca = $ldap_basedn_loca;
  37. $this->ldap_filtre_user = $ldap_filtre_user;
  38. $this->ldap_filtre_comp = $ldap_filtre_comp;
  39. $this->ldap_filtre_loca = $ldap_filtre_loca;
  40. }
  41.  
  42. private function authentification(){
  43. $this->ldap_service->bind($this->ldap_dn, $this->ldap_password);
  44. return $this;
  45. }
  46. public function cleanData($datas){
  47. $dataclean = [];
  48. for( $i=0; $i < $datas['count']; $i++)
  49. {
  50. if(is_array($datas[$i]))
  51. {
  52. $subdatas = $datas[$i];
  53. if( !empty($subdatas['dn']) and ! isset($dataclean[$subdatas['dn']]))
  54. {
  55.  
  56. if ((preg_match('#employees#i',$subdatas['dn'])) || (preg_match('#externals#i',$subdatas['dn'])))
  57. {
  58. $subdatas['dn'] = preg_replace('#cn=([a-z]*) ([a-z0-9 \'-]*),ou=([a-z]+),ou=([a-z]+),dc=([a-z]+),dc=eu#i', '$2 $1,$3', $subdatas['dn']);
  59. } else
  60. $subdatas['dn'] = preg_replace('#cn=([a-z0-9 \'-]*),ou=([a-z]+),ou=([a-z]+),dc=([a-z]+),dc=eu#i', '$1,$2', $subdatas['dn']);
  61. $dataclean[$subdatas['dn']] = $this->cleanData($subdatas);
  62. }
  63. else {
  64. $dataclean[] = $this->cleanData($subdatas);
  65. }
  66. }
  67. else {
  68. $attribut = $datas[$i];
  69. if( $datas[$attribut]['count'] == 1){
  70. $dataclean[$attribut] = $datas[$attribut][0];
  71. } else {
  72. for( $j = 0; $j < $datas[$attribut]; $j++){
  73. $dataclean[$attribut][] = $datas[$attribut][$j];
  74. }
  75. }
  76. }
  77. }
  78. return $dataclean;
  79.  
  80. }
  81.  
  82.  
  83. public function eventestRecherche($params){
  84. $this->authentification();
  85. $resultat= [];
  86.  
  87. // $this->ldap_service->find( $cible, $saisie, $filter )
  88. if (is_array($params)){ //ici c ests pour page liistage repertoire
  89.  
  90. if (isset($params['cible']))
  91. {
  92. $cible = $params['cible'];
  93. //dump($cible);
  94. $filter = $this->getFiltre($cible);
  95. //dump($filter);
  96. if (isset($params['saisie']))
  97. {
  98. $saisie = "cn={$params['saisie']}";
  99. //dump($saisie);
  100. } else
  101. $saisie = "cn=*";
  102. }
  103. $reponse = $this->ldap_service->find($cible, $saisie, $filter);
  104. if(empty($reponse)){
  105. throw new EvenException("Aucun résultat avec vos criteres de recherche");
  106. } else
  107. //dump($reponse);
  108. foreach($reponse as $test)
  109. {
  110. if (is_array($test))
  111. {
  112.  
  113. $test = $this->cleanData($test);
  114. array_push($resultat,$test);
  115. //dump($test);
  116. }
  117. }
  118.  
  119. //dump($resultat);
  120.  
  121.  
  122. } else {
  123. $basedn = array($this->ldap_basedn_emp,$this->ldap_basedn_ext,$this->ldap_basedn_loca,$this->ldap_basedn_comp);
  124.  
  125. foreach($basedn as $key => $base){
  126. if ($key < 2) $filter = $this->ldap_filtre_user;
  127. else if ($key == 2)
  128. $filter = $this->ldap_filtre_loca;
  129. else
  130. $filter = $this->ldap_filtre_comp;
  131.  
  132. $reponse = $this->ldap_service->find($base, "cn=*{$params}*",$filter);
  133. //dump($reponse);
  134. if ($reponse != null){
  135. $cible = preg_replace('#ou=([a-z]+),ou=([a-z]+),dc=evengroup,dc=eu#i', '$1', $base);
  136.  
  137. foreach($reponse as $repertoire){
  138. if (is_array($repertoire))// on supprime la ligne count et sa valeur
  139. {
  140. $repertoire=$this->cleanData($repertoire);
  141. $repertoire["repertoire"]= $cible;
  142. array_push($resultat,$repertoire);
  143. }
  144. }
  145. }
  146.  
  147. }
  148. // ici c est qu'onn utilise le formulaire
  149. //dump($resultat);
  150. if ($resultat == null){
  151. throw new EvenException("Aucun résultat avec vos criteres de recherche");
  152. }
  153. }
  154.  
  155. return $resultat;
  156. }
  157.  
  158. private function getFiltre($cible){
  159. if ($cible == $this->ldap_basedn_ext)
  160. {
  161. $filter = $this->ldap_filtre_user;
  162. }
  163. if ($cible == $this->ldap_basedn_emp)
  164. {
  165. $filter = $this->ldap_filtre_user;
  166. }
  167. if ($cible == $this->ldap_basedn_loca)
  168. {
  169. $filter = $this->ldap_filtre_loca;
  170. }
  171. if ($cible == $this->ldap_basedn_comp)
  172. {
  173. $filter = $this->ldap_filtre_comp;
  174. }
  175.  
  176.  
  177. return $filter;
  178. }
  179.  
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement