<?php

session_start();
include 'modeles/Mconnect.php';
include_once 'modeles/Mfilms.php';
include_once 'modeles/Mutilitaire.php';
//je récupère la recherche
$recherche = $_POST['recherche'];
$recherche = utf8_decode($recherche);
//je remplace les caractères spéciaux pour améliorer la recherche dans la BDD
$recherche = str_replace("àáâãäåòóôõöøèéêëçìíîïùúûüÿñ", "aaaaaaooooooeeeeciiiiuuuuyn", $recherche);
$bd = new Mconnect();
$tab = Mfilms::parNom($recherche);
$bd->close();
$nb_element_par_page = Mutilitaire::configuration("nb_pagination");
$nb_pages = ceil(count($tab) / $nb_element_par_page);
$_SESSION['tab'] = $tab;
$_SESSION['nbpages'] = $nb_pages;
$_SESSION['elemparpage'] = $nb_element_par_page;
if ($tab == NULL) {
    echo "<center><div id='avertissement'>";
    echo "<img src='vues/img/attention.gif'/>";
    echo utf8_encode("<span style='color:red;'><strong>&nbsp;&nbsp;&nbsp;&nbsp;Aucun résultat n'à été trouvé&nbsp;&nbsp;&nbsp;&nbsp;</strong></span>");
    echo "<img src='vues/img/attention.gif'/>";
    echo "</div></center>";
} else {
    include 'vues/Vfilm.php';
}
 public function parNom($rech, $nom)
 {
     switch ($rech) {
         case "genre":
             $tab = Mfilms::parGenres($nom);
             $nb_element_par_page = Mutilitaire::configuration("nb_pagination");
             $nb_pages = ceil(count($tab) / $nb_element_par_page);
             $_SESSION['tab'] = $tab;
             $_SESSION['nbpages'] = $nb_pages;
             $_SESSION['elemparpage'] = $nb_element_par_page;
             if ($tab == NULL) {
                 include 'vues/Vfilm_absent.php';
             } else {
                 include 'vues/Vfilm.php';
             }
             break;
         case "alphabet":
             $tab = Mfilms::parAlphabet($nom);
             $nb_element_par_page = Mutilitaire::configuration("nb_pagination");
             $nb_pages = ceil(count($tab) / $nb_element_par_page);
             $_SESSION['tab'] = $tab;
             $_SESSION['nbpages'] = $nb_pages;
             $_SESSION['elemparpage'] = $nb_element_par_page;
             if ($tab == NULL) {
                 include 'vues/Vfilm_absent.php';
             } else {
                 include 'vues/Vfilm.php';
             }
             break;
         case "date":
             echo "date";
             $tab = Mfilms::parDate($nom);
             $nb_element_par_page = Mutilitaire::configuration("nb_pagination");
             $nb_pages = ceil(count($tab) / $nb_element_par_page);
             $_SESSION['tab'] = $tab;
             $_SESSION['nbpages'] = $nb_pages;
             $_SESSION['elemparpage'] = $nb_element_par_page;
             if ($tab == NULL) {
                 include 'vues/Vfilm_absent.php';
             } else {
                 include 'vues/Vfilm.php';
             }
             break;
         case "nom":
             echo "nom";
             $tab = Mfilms::parNom($nom);
             $nb_element_par_page = Mutilitaire::configuration("nb_pagination");
             $nb_pages = ceil(count($tab) / $nb_element_par_page);
             $_SESSION['tab'] = $tab;
             $_SESSION['nbpages'] = $nb_pages;
             $_SESSION['elemparpage'] = $nb_element_par_page;
             if ($tab == NULL) {
                 include 'vues/Vfilm_absent.php';
             } else {
                 include 'vues/Vfilm.php';
             }
             break;
         case "acteur":
             $tab = Mfilms::parActeur($nom);
             $nb_element_par_page = Mutilitaire::configuration("nb_pagination");
             $nb_pages = ceil(count($tab) / $nb_element_par_page);
             $_SESSION['tab'] = $tab;
             $_SESSION['nbpages'] = $nb_pages;
             $_SESSION['elemparpage'] = $nb_element_par_page;
             if ($tab == NULL) {
                 include 'vues/Vfilm_absent.php';
             } else {
                 include 'vues/Vfilm.php';
             }
             break;
         case "realisateur":
             $tab = Mfilms::parRealisateur($nom);
             $nb_element_par_page = Mutilitaire::configuration("nb_pagination");
             $nb_pages = ceil(count($tab) / $nb_element_par_page);
             $_SESSION['tab'] = $tab;
             $_SESSION['nbpages'] = $nb_pages;
             $_SESSION['elemparpage'] = $nb_element_par_page;
             if ($tab == NULL) {
                 include 'vues/Vfilm_absent.php';
             } else {
                 include 'vues/Vfilm.php';
             }
             break;
         case "everything":
             $tab = Mfilms::everything();
             $nb_element_par_page = Mutilitaire::configuration("nb_pagination");
             $nb_pages = ceil(count($tab) / $nb_element_par_page);
             $_SESSION['tab'] = $tab;
             $_SESSION['nbpages'] = $nb_pages;
             $_SESSION['elemparpage'] = $nb_element_par_page;
             if ($tab == NULL) {
                 include 'vues/Vfilm_absent.php';
             } else {
                 include 'vues/Vfilm.php';
             }
             break;
         case "id":
             $tab = Mfilms::parId($nom);
             $acteurs = Mpersonne::acteurParId($nom);
             $realisateurs = Mpersonne::realisateurParId($nom);
             include 'vues/Vafficher_film.php';
             break;
     }
 }