ajaxsearch.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. session_start();
  3. //Encodage des caractères
  4. header('Content-Type: text/html; charset=$ENCODAGE');
  5. const AUCUN_RESULTAT = "<div style='text-align:center; font-size:11pt; margin:5px; '><span style='color:white;'>Aucun r&eacute;sultat</span>\n</div>\n";
  6. //Librairie de fonctions
  7. require("lib/libencode.inc.php");
  8. require("lib/libmysql.inc.php");
  9. setConnectionSql();
  10. function enleveAccent($chaine) {
  11. $accent = "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿ";
  12. $noaccent = "AAAAAAACEEEEIIIIDNOOOOOOUUUUYBSaaaaaaaceeeeiiiidnoooooouuuyyby";
  13. return strtr(trim($chaine), $accent, $noaccent);
  14. }
  15. if (filter_input(INPUT_POST,'zonerecherche',FILTER_SANITIZE_ADD_SLASHES)!=="") {
  16. $zonerecherche = antiInjection(filter_input(INPUT_POST,'zonerecherche',FILTER_SANITIZE_ADD_SLASHES));
  17. $zonerecherche2 = trim($zonerecherche);
  18. $id = sprintf("%d", filter_input(INPUT_POST,'id',FILTER_SANITIZE_ADD_SLASHES));
  19. if (($zonerecherche2 != null && !empty($zonerecherche2)) && ($id != null && !empty($id))) {
  20. unset($sqlparam);
  21. $sqlparam["table"][] = "employes";
  22. $sqlparam["champs"][] = "nomfamille";
  23. $sqlparam["champs"][] = "prenom";
  24. $sqlparam["champs"][] = "numemploye";
  25. $sqlparam["champs"][] = "adresse1";
  26. $sqlparam["champs"][] = "adresse2";
  27. $sqlparam["champs"][] = "ville";
  28. $sqlparam["champs"][] = "codepostal";
  29. $sqlparam["champs"][] = "numtel";
  30. $sqlparam["champs"][] = "membreca";
  31. $sqlparam["champs"][] = "refemploye";
  32. $sqlparam["champs"][] = "presentation";
  33. $sqlparam["champs"][] = "email";
  34. $sqlparam["champs"][] = "numemploye";
  35. $sqlparam["order"][] = "nomfamille";
  36. $sqlparam["order"][] = "prenom";
  37. $sqlparam["where"][] = "TRIM(CONCAT_WS(' ',nomfamille,prenom)) LIKE '%" . trim($zonerecherche2) . "%'";
  38. if ($_SESSION['gestion_site'] == 'Non') {
  39. $sqlparam["where"][] = sprintf("employes.refemployeur=%d", $_SESSION['employeur']);
  40. }
  41. // Ne pas prendre les employés qui ont été archivés
  42. $sqlparam["where"][] = "archive=0";
  43. $sqlparam["limite"] = 7;
  44. $result = executerRequeteSql($sqlparam);
  45. if ($result) {
  46. foreach ($result as $clef => $champs) {
  47. $valeur0 = $champs["nomfamille"];
  48. $valeur1 = $champs["prenom"];
  49. $valeur2 = $champs["refemploye"];
  50. $valeur3 = $champs["numemploye"];
  51. $valeur4 = $champs["ville"];
  52. $ligne = enleveAccent(htmlentities($valeur0 . ", " . $valeur1 . " (" . $valeur3 . "), " . $valeur4, ENT_SUBSTITUTE, "UTF-8"));
  53. $zonerecheche = strtolower(enleveAccent($zonerecherche2));
  54. $ligne2 = ucwords($ligne);
  55. $ligne3 = str_ireplace(strtoupper($zonerecherche2), '<span class="highlight">' . strtoupper($zonerecherche2) . '</span>', $ligne2);
  56. $nomTemp = str_replace("'", "&apos;", htmlentities($valeur0 . ", " . $valeur1, ENT_SUBSTITUTE, "UTF-8"));
  57. print sprintf("<a style='cursor:pointer;' onclick='selectedC(%d,\"%s\",%d);'> %s</a>", $id, $nomTemp, $valeur2, $ligne3);
  58. }
  59. } else {
  60. print AUCUN_RESULTAT;
  61. }
  62. } else {
  63. print AUCUN_RESULTAT;
  64. }
  65. }