/src/2.071.0/core/profil_collab/annuaire_recherche_result.php

https://github.com/yvesb/soothERP · PHP · 216 lines · 161 code · 27 blank · 28 comment · 67 complexity · a74224cf63235d86a83583f7f6ad2cca MD5 · raw file

  1. <?php
  2. // ******************************************************
  3. // [ADMINISTRATEUR] RECHERCHE D'UNE FICHE DE CONTACT
  4. // ******************************************************
  5. require ("_dir.inc.php");
  6. require ("_profil.inc.php");
  7. require ($DIR."_session.inc.php");
  8. // ******************************************************
  9. // TRAITEMENTS
  10. // ******************************************************
  11. // *************************************************
  12. // Profils à afficher
  13. $profils = array();
  14. foreach ($_SESSION['profils'] as $profil) {
  15. if ($profil->getActif() != 1) { continue; }
  16. $profils[] = $profil;
  17. }
  18. unset ($profil);
  19. // *************************************************
  20. // Données pour le formulaire && la requete
  21. $form['page_to_show'] = $search['page_to_show'] = 1;
  22. if (isset($_REQUEST['page_to_show'])) {
  23. $form['page_to_show'] = $_REQUEST['page_to_show'];
  24. $search['page_to_show'] = $_REQUEST['page_to_show'];
  25. }
  26. $form['fiches_par_page'] = $search['fiches_par_page'] = $ANNUAIRE_RECHERCHE_SHOWED_FICHES;
  27. if (isset($_REQUEST['fiches_par_page'])) {
  28. $form['fiches_par_page'] = $_REQUEST['fiches_par_page'];
  29. $search['fiches_par_page'] = $_REQUEST['fiches_par_page'];
  30. }
  31. $form['orderby'] = $search['orderby'] = "nom";
  32. if (isset($_REQUEST['orderby'])) {
  33. $form['orderby'] = $_REQUEST['orderby'];
  34. $search['orderby'] = $_REQUEST['orderby'];
  35. }
  36. $form['orderorder'] = $search['orderorder'] = "ASC";
  37. if (isset($_REQUEST['orderorder'])) {
  38. $form['orderorder'] = $_REQUEST['orderorder'];
  39. $search['orderorder'] = $_REQUEST['orderorder'];
  40. }
  41. $nb_fiches = 0;
  42. $form['nom'] = "";
  43. if (isset($_REQUEST['nom'])) {
  44. $form['nom'] = trim(urldecode($_REQUEST['nom']));
  45. $search['nom'] = trim(urldecode($_REQUEST['nom']));
  46. }
  47. $form['id_profil'] = 0;
  48. if (isset($_REQUEST['id_profil'])) {
  49. $form['id_profil'] = $_REQUEST['id_profil'];
  50. $search['id_profil'] = $_REQUEST['id_profil'];
  51. }
  52. // *************************************************
  53. // Résultat de la recherche
  54. $fiches = array();
  55. if (isset($_REQUEST['recherche'])) {
  56. // Préparation de la requete
  57. $query_join = "";
  58. $query_where = "date_archivage IS NULL";
  59. $query_limit = (($search['page_to_show']-1)*$search['fiches_par_page']).", ".$search['fiches_par_page'];
  60. // Nom
  61. if ($search['nom']) {
  62. $libs = explode (" ", $search['nom']);
  63. if ($query_where) { $query_where .= " && "; }
  64. $query_where .= " ( ";
  65. for ($i=0; $i<count($libs); $i++) {
  66. $lib = trim($libs[$i]);
  67. $query_where .= " nom LIKE '%".addslashes($lib)."%' ";
  68. if ( isset($libs[$i+1]) ) { $query_where .= " && "; }
  69. }
  70. $query_where .= " ) ";
  71. }
  72. // Profils
  73. if ($search['id_profil'] != "ALL") {
  74. $query_join .= " LEFT JOIN annuaire_profils ap ON a.ref_contact = ap.ref_contact ";
  75. if($search['id_profil']){
  76. if ($query_where) { $query_where .= " && "; }
  77. $query_where .= "ap.id_profil = '".$search['id_profil']."'";
  78. }else{
  79. if ($query_where) { $query_where .= " && "; }
  80. $query_where .= "ap.id_profil is null";
  81. }
  82. }
  83. $query = "SELECT a.ref_contact, nom, lib_civ_court, ad.id_type_adresse,
  84. text_adresse, ad.code_postal, ad.ville, ad.ordre,
  85. tel1, tel2, fax, email, co.ordre, co.id_type_coordonnee, si.id_type_site_web,
  86. url, si.ordre
  87. FROM annuaire a
  88. LEFT JOIN civilites c ON a.id_civilite = c.id_civilite
  89. LEFT JOIN adresses ad ON a.ref_contact = ad.ref_contact
  90. LEFT JOIN coordonnees co ON a.ref_contact = co.ref_contact && co.ordre = 1
  91. LEFT JOIN sites_web si ON a.ref_contact = si.ref_contact && si.ordre = 1
  92. ".$query_join."
  93. WHERE ".$query_where."
  94. GROUP BY a.ref_contact
  95. ORDER BY ".$search['orderby']." ".$search['orderorder'].", ad.ordre ASC, co.ordre ASC, si.ordre ASC
  96. LIMIT ".$query_limit;
  97. $resultat = $bdd->query($query);
  98. while ($fiche = $resultat->fetchObject()) { $fiches[] = $fiche; }
  99. //echo nl2br ($query);
  100. unset ($fiche, $resultat, $query);
  101. $ref_user = $_SESSION['user']->getRef_user();
  102. $droitsVoirAdresses = getDroitVoirAdresse($ref_user);
  103. $droitsVoirCoord = getDroitVoirCoordonnees($ref_user);
  104. $droitsVoirSite = getDroitVoirSiteWeb($ref_user);
  105. //_vardump($fiches);
  106. //Gestion des droits affichage addresse------------------------------
  107. if(count($droitsVoirAdresses)>0){
  108. if($droitsVoirAdresses[0] != "ALL"){
  109. for($i=0;$i<count($fiches);$i++){
  110. if($fiches[$i]->id_type_adresse != "" && $fiches[$i]->id_type_adresse != 0){
  111. if (!in_array($fiches[$i]->id_type_adresse,$droitsVoirAdresses)){
  112. $fiches[$i]->text_adresse = "";
  113. $fiches[$i]->code_postal = "";
  114. $fiches[$i]->ville = "";
  115. }
  116. }
  117. }
  118. }
  119. }else{
  120. for($i=0;$i<count($fiches);$i++){
  121. if($fiches[$i]->id_type_adresse != "" && $fiches[$i]->id_type_adresse != 0){
  122. $fiches[$i]->text_adresse = "";
  123. $fiches[$i]->code_postal = "";
  124. $fiches[$i]->ville = "";
  125. }
  126. }
  127. }
  128. //FIN Gestion des droits affichage addresse---------------------------
  129. //Gestion des droits affichage coordonnees----------------------------
  130. if(count($droitsVoirCoord)>0){
  131. if($droitsVoirCoord[0] != "ALL"){
  132. for($i=0;$i<count($fiches);$i++){
  133. if($fiches[$i]->id_type_coordonnee != "" && $fiches[$i]->id_type_coordonnee != 0){
  134. if (!in_array($fiches[$i]->id_type_coordonnee,$droitsVoirCoord)){
  135. $fiches[$i]->tel1 = "";
  136. $fiches[$i]->tel2 = "";
  137. $fiches[$i]->fax = "";
  138. $fiches[$i]->email = "";
  139. }
  140. }
  141. }
  142. }
  143. }else{
  144. for($i=0;$i<count($fiches);$i++){
  145. if($fiches[$i]->id_type_coordonnee != "" && $fiches[$i]->id_type_coordonnee != 0){
  146. $fiches[$i]->tel1 = "";
  147. $fiches[$i]->tel2 = "";
  148. $fiches[$i]->fax = "";
  149. $fiches[$i]->email = "";
  150. }
  151. }
  152. }
  153. //FIN Gestion des droits affichage coordonnees-----------------------
  154. //Gestion des droits affichage site web------------------------------
  155. if(count($droitsVoirSite)>0){
  156. if($droitsVoirSite[0] != "ALL"){
  157. for($i=0;$i<count($fiches);$i++){
  158. if($fiches[$i]->id_type_site_web != "" && $fiches[$i]->id_type_site_web != 0){
  159. if (!in_array($fiches[$i]->id_type_site_web,$droitsVoirSite)){
  160. $fiches[$i]->url = "";
  161. }
  162. }
  163. }
  164. }
  165. }else{
  166. for($i=0;$i<count($fiches);$i++){
  167. if($fiches[$i]->id_type_site_web != "" && $fiches[$i]->id_type_site_web != 0){
  168. $fiches[$i]->url = "";
  169. }
  170. }
  171. }
  172. //FIN Gestion des droits affichage site web---------------------------
  173. // Comptage des résultats
  174. $query = "SELECT COUNT(a.ref_contact) nb_fiches
  175. FROM annuaire a
  176. ".$query_join."
  177. WHERE ".$query_where."
  178. GROUP BY a.ref_contact";
  179. $resultat = $bdd->query($query);
  180. $result = $resultat->fetchAll();
  181. $nb_fiches = count($result);
  182. //echo "<br><hr>".nl2br ($query);
  183. unset ($result, $resultat, $query);
  184. }
  185. // ******************************************************
  186. // AFFICHAGE
  187. // ******************************************************
  188. include ($DIR.$_SESSION['theme']->getDir_theme()."page_annuaire_recherche_result.inc.php");
  189. ?>