<?php
    header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 
    header("Cache-Control: post-check=0, pre-check=0", false); 
    header("Cache-Control: private");
    header("Pragma: no-cache");
    header('Content-Type:text/html; Charset=UTF-8');
	
	ob_start();

	session_start();

	define("BASEURL", "/admin/");
	require_once("fonctions.php");  
	require("db.php");

	$_SESSION["famille"] = 5;
	
	include 'models/classes.php';
	$query = array();
	$parts = parse_url($_SERVER["REQUEST_URI"]);
	if(isset($parts['query'])){
		parse_str($parts['query'], $query);
		if(isset($query) && count($query)>0){
			foreach ($query as $key => $value) {
				$_REQUEST[$key] = $value;
			}
		}
	}
	//$_SESSION['annee']="1";
	$defautColor = "#61b47c";
	$ctrl = "home"; // Page de connexion par défaut

	// Par défaut on affiche le TABLEAU DE BORD
	if(isset($_REQUEST['page'])){
		$ctrl = $_REQUEST['page'];
	}

	if (isset($_SESSION["iduser"])) {
		switch($ctrl){
			case 'home':{ 
				$page_title = "Dashboard";
				header('Location: categorie');
				break;
			}
			case 'utilisateur':{ 
				include("controller/UtilisateurController.php");
				break;
			}
			case 'service':{ 
				include("controller/ServiceController.php");
			 	break;
			}
			case 'produit':{ 
				include("controller/ProduitController.php");
			 	break;
			}
			case 'apropos':{ 
				include("controller/AproposController.php");
			 	break;
			}
			case 'actualite':{ 
				include("controller/ActualiteController.php");
			 	break;
			}
			case 'temoignage':{ 
				include("controller/TemoignageController.php");
			 	break;
			}
			case 'foire':{ 
				include("controller/FoireController.php");
			 	break;
			}
			case 'client':{ 
				include("controller/ClientController.php");
			 	break;
			}
			case 'logout':{ 
				Utilisateur::logout();
				break;
			}
			default:{
				header("Location: actualite");
			}
		}
	}  else {
		switch($ctrl){
			case 'login':{ 
				$page_title = "Connexion";
				include("views/login.php");
				break;
			}
			case 'utilisateur':{ 
				include("controller/UtilisateurController.php");
				break;
			}
			// case 'famille':{ 
			// 	include("controller/FamilleController.php");
			// 	break;
			// }
			default:{
				header("Location:login");
			}
		}
	}
	
	
ob_end_flush();
?>