<?php
$tabNotions = array();
$notions_select = "SELECT * FROM ".$prefix."_savnotions ORDER BY 
	replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
	replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
	replace(notion_nom,'À','A'),'Á','A'),'Â','A'),'Ã','A'),'Ä','A'),'Å','A'),'Ç','C'),'È','E'),'É','E')
	,'Ê','E'),'Ë','E'),'Ì','I'),'Í','I'),'Î','I'),'Ï','I'),'Ò','O'),'Ó','O'),'Ô','O'),'Õ','O')
	,'Ö','O'),'Ù','U'),'Ú','U'),'Û','U'),'Ü','U'),'Ý','Y')";
// requete sql à personnaliser pour correspondre à votre base de données
$result = mysqli_query($bdd,$notions_select);
if($result) {
	// on parcourt les resultats
	while ($ligne = mysqli_fetch_assoc($result)) {
		// on affiche les resultats dans un element de liste en ajoutant 
		// la fonction fill sur l'evenenement onClick
		$nom = stripslashes(mysqli_real_escape_string($bdd,$ligne['notion_nom']));
		$notion = isset($translations[$nom]) ? $translations[$nom] : $nom;
    array_push($tabNotions, $notion);
	}			
} else {
	echo SQLPB;
}
?>
<script>
$( function() {
    var accentMap = {
      'é':'e','è':'e','ê':'e','ë':'e','à':'a','â':'a',
      'î':'i','ï':'i','ô':'o','ö':'o','ù':'u','û':'u',
	  'É':'e','È':'e','Ê':'e','Ë':'e','À':'a','Â':'a',
	  'Î':'i','Ï':'i','Ô':'o','Ö':'o','Ù':'u','Û':'u'
    };
    var normalize = function( term ) {
      var ret = "";
      for ( var i = 0; i < term.length; i++ ) {
        ret += accentMap[ term.charAt(i) ] || term.charAt(i);
      }
      return ret;
    };
    
	$("#notions").autocomplete({
        source: function(request, response) {
            var matcher = new RegExp("^" + $.ui.autocomplete.escapeRegex(request.term), "i");
            response($.grep(<?php echo json_encode($tabNotions); ?>, function(value) {
                return matcher.test(value) || matcher.test(normalize(value));
            }));
        }
    });
  } );
</script>