page = $_SERVER['PHP_SELF']; //Page that instantiates the template.
        $this->prefix = '../';              //Default prefix.
        $this->set_page_prefix();           //Assigns the name and prefix of the page.
        $this->session = 'Iniciar Sesión';  //Default, the session has not started.
        $this->session_route = 'login/';    //Default, the session has not started.
        $this->panel = '';                  //Default, the session has not started.
        $this->user_route = 'panel_user/';  //Default, the type of client is user.
        $this->sessionButtonClass = '';     //Default, normal button.
    }
    //Methods:
    //Assigns the name and prefix of the page:
    private function set_page_prefix() {
        switch(true){
            case strpos($this->page, 'panel_user'): $this->page = 'Panel de Usuario'; break;
            case strpos($this->page, 'panel_manager'): $this->page = 'Panel de Gerente'; break;
            case strpos($this->page, 'panel_admin'): $this->page = 'Panel de Administrador'; break;
            case strpos($this->page, 'login'): $this->page = 'Acceso'; break;
            case strpos($this->page, 'logout'): $this->page = 'Cerrar Sesión'; break;
            case strpos($this->page, 'register'): $this->page = 'Registro de Usuario'; break;
            case strpos($this->page, 'showtimes'): $this->page = 'Cartelera'; break;
            case strpos($this->page, 'purchase'): $this->page = 'Comprar Entrada'; break;
            case strpos($this->page, 'promotions'): $this->page = 'Promociones'; break;
            case strpos($this->page, 'cinemas'): $this->page = 'Nuestros Cines'; break;
            case strpos($this->page, 'about_us'): $this->page = 'Sobre FDI-Cines'; $this->prefix = '../../'; break;
            case strpos($this->page, 'terms'): $this->page = 'Términos y Condiciones'; $this->prefix = '../../'; break;
            case strpos($this->page, 'detalles'): $this->page = 'Detalles'; $this->prefix = '../../'; break;
            case strpos($this->page, 'bocetos'): $this->page = 'Bocetos'; $this->prefix = '../../'; break;
            case strpos($this->page, 'miembros'): $this->page = 'Miembros'; $this->prefix = '../../'; break;
            case strpos($this->page, 'planificacion'): $this->page = 'Planificación'; $this->prefix = '../../'; break;
            case strpos($this->page, 'contacto'): $this->page = 'Contacto'; break;
            case strpos($this->page, 'assets'): $this->prefix = '../../../'; break;
            default: $this->page = 'FDI-Cines'; $this->prefix = './'; break;
        }
    }
    //Returns page name:
    function get_page(){
        return $this->page;
    }
    //Returns page prefix:
    function get_prefix(){
        return $this->prefix;
    }
    //Print generic Head:
    function print_head(){
        $page = $this->page;
        $prefix = $this->prefix;
        if(!isset($_SESSION["css"])) $_SESSION["css"] = "main.css";
        $extraCSS = "";
        if($page === "Comprar Entrada") $extraCSS = "\n";
        echo"
        CompluCine | {$page}
        
        {$extraCSS}
        
        
        
    \n";
    }
    //Print generic Header:
    function print_header(){
        $page = $this->page;
        $prefix = $this->prefix;
        $session = $this->session;
        $sessionButtonClass = $this->sessionButtonClass;
        $session_route = $this->session_route;
        $user_route = $this->user_route;
        $panel =$this->panel;
        if(isset($_SESSION["rol"])){
            if($_SESSION["rol"] === "admin") $user_route = 'panel_admin/';
            else if($_SESSION["rol"] === "manager") $user_route = 'panel_manager/';
            $panel = "Mi Panel";
            $session = 'Cerrar Sesión';
            $sessionButtonClass = 'danger';
            $session_route = 'logout/';
        }
        if(isset($_SESSION["lastRol"]) && ($_SESSION["lastRol"] === "admin" || $_SESSION["lastRol"] === "manager" )){
            $changeRol = "Volver a {$_SESSION["lastRol"]}";
        } else {
            $changeRol = null;
        }
        
        echo"\n";
    }
    //Print generic subHeader:
    function print_subheader(){
        //$page = $this->page;
        $prefix = $this->prefix;
        echo"\n";
    }
    //Print generic Main:
    function print_main($content = ""){
        $page = $this->page;
        $prefix = $this->prefix;
        /* SubHeader on Main */
        $sub_header = '';
        if(strpos($_SERVER['PHP_SELF'], 'fdicines')){
            $sub_header = "
                \n"; 
        }
        /* MAIN */
        if($prefix === "./"){ 
            if(isset($_SESSION["nombre"])){
                $tittle = "Bienvenido {$_SESSION["nombre"]}
\n";
            } else {
                $tittle = "Bienvenido a CompluCine
\n";
            }
        } else {
            $tittle = "{$page}
\n";
        }
        echo"
            
            {$sub_header}
            {$tittle}{$content}
            
        \n";
    }
    //Print panel menu:
    function print_panelMenu($panel){
        if($_SESSION["login"]){
            $prefix = $this->prefix;
            $menus = array("Panel Principal");
            switch($panel){
                case "admin": array_push($menus, "Ver como...
                                                        
                                                    ");
                                array_push($menus, "Modificar
                                                        
                                                    ");
                                break;
                case "manager": array_push($menus, "Ver como...
                                                        
                                                    ");
                                array_push($menus, "Modificar
                                                        
                                                    ");
                                break;
                case "user": array_push($menus, "Historial Compras");
                                //array_push($menus, "Datos Pago");
                                    array_push($menus, "Eliminar Usuario");
                                        break;
                default: $menus = array(); break;
            }
            if($_SESSION["rol"] === $panel){
                echo"
        ";
            }
        }
    }
    //Print specific page content:
    function print_section($section){
        /* Panel menu */
        $sub_header = '';
        if(strpos($_SERVER['PHP_SELF'], 'panel')){
            echo "
            ";
            $this->print_panelMenu($_SESSION["rol"]);
            $this->print_msg();
        }
        echo $section;
    }
    //Print Films Cards:
    function print_fimls(){
        $reply = "";
        //List of the movies:
        require_once(__DIR__.'/includes/film_dao.php');
        $prefix= $this->get_prefix();
        $films = new Film_DAO("complucine");
        $films_array = $films->allFilmData();
        $ids = array();
        $tittles = array();
        $descriptions = array();
        $times = array();
        $languages = array();
        $images = array();
        if(is_array($films_array)){
            foreach($films_array as $key => $value){
                $ids[$key] = $value->getId();
                $tittles[$key] = $value->getTittle();
                $descriptions[$key] = $value->getDescription();
                $times[$key] = $value->getDuration();
                $languages[$key] = $value->getLanguage();
                $images[$key] = $value->getImg();
            }
        }
        switch($this->page){
            case "Cartelera": 
                if(is_array($films_array)){
                for($i = 0; $i < count($films_array); $i++){
                    $tittle = str_replace('_', ' ', $tittles[$i]);
                    if($i%2 === 0){
                        if($i != 0) $reply .= "
                    ";
                        $reply .= "
                        ";
                    }
                    else{
                        if($i != 0) $reply .= "
                    ";
                    $reply .= "
                        ";
                    }
                    $reply .= "
                    ";
                }
                }
                $reply .= "
 \n";
                break;
            case "Panel de Administrador":
                $reply .= "";
                if(is_array($films_array)){
                for($i = 0; $i < count($films_array); $i++){
                    $tittle = str_replace('_', ' ', $tittles[$i]);
                    if($i%2 === 0){
                        if($i != 0) $reply .= "
                    ";
                        $reply .= "
                        ";
                    }
                    else{
                        if($i != 0) $reply .= "
                    ";
                        $reply .= "
                        ";
                    }
                    $reply .= "
                    ";
                }
                }
                $reply .= "
 \n";                
                break;
				
			case "Panel de Gerente":
                $reply .= "";
                if(is_array($films_array)){
                for($i = 0; $i < count($films_array); $i++){
                    $tittle = str_replace('_', ' ', $tittles[$i]);
                    if($i%2 === 0){
                        if($i != 0) $reply .= "
                    ";
                        $reply .= "
                        ";
                    }
                    else{
                        if($i != 0) $reply .= "
                    ";
                        $reply .= "
                        ";
                    }
                    $reply .= "
                            
                                
                                    
                                    ".$tittle."
                                    
                                    Duración: ".$times[$i]." minutos
                                    Lenguaje: ".$languages[$i]."
                                
								
								 
                             
                        
                    ";
                }
                }
                $reply .= "
 \n"; 
                break;
				
            default: 
                if(is_array($films_array)){
                    $reply .='
                         
                            
Últimos Estrenos
';
                    $count = 0;
                    for($i = count($tittles)-4; $i < count($tittles); $i++){
                        if($count%2===0){
                            if($count != 0) $reply .= "
                            ";
                        $reply .= "
                            
";
                        }
                        $reply .= "
                                
";
                        $count++;
                    }
                    $reply .= "
                            
 
                         
                    
                    
                        ";
                    $count = rand(0, count($tittles)-1);
                    $title = str_replace('_', ' ', $tittles[$count]); 
                    $reply .= "
                            
{$title}
                            
                         
                     \n";
                }
                    break;
        }
        return $reply;
    }
    //Print Cinemas info:
    function print_cinemas(){
        $reply = "";
        //List of the cinemas:
        require_once(__DIR__.'/includes/cinema_dao.php');
        $prefix= $this->get_prefix();
        $cine = new Cinema_DAO("complucine");
        $cinemas = $cine->allCinemaData();
        $ids = array();
        $names = array();
        $directions = array();
        $phones = array();
        if(!is_array($cinemas)){
            $reply = "No hay cines actualmente
";
        }
        else{
            foreach($cinemas as $key => $value){
                $ids[$key] = $value->getId();
                $names[$key] = $value->getName();
                $directions[$key] = $value->getDirection();
                $phones[$key] = $value->getPhone();
            }
        
        switch($this->page){
            case "Nuestros Cines":
                for($i = 0; $i < count($cinemas); $i++){
                    if($i%2 === 0){
                        if($i != 0) $reply .= "
                    ";
                        $reply .= "
                        ";
                    }
                    else{
                        if($i != 0) $reply .= "
                    ";
                    $reply .= "
                        ";
                    }
                    $reply .= "
                    ";
                }
                $reply .= "
 \n";
                break;
            case "Panel de Administrador":
                    $reply .= "
                             
                                - Id
 
                                - Nombre
 
                                - Dirección
 
                                - Teléfono
 
                                - Editar
 
                                - Eliminar
 
                            ";
                        $parity = "odd";
                        for($i = 0; $i < count($cinemas); $i++){
                            $reply .= '
                                    
                                '; 
                                $parity = ($parity == "odd") ? "even" : "odd";
                        } 
                    $reply .=' 
 ';
                break;
            
            default:
                break;
         }
        }
        return $reply;
    }
    function print_promotions(){
        $reply = "";
        //List of the cinemas:
        require_once(__DIR__.'/includes/promotion_dao.php');
        $prefix= $this->get_prefix();
        $promotion = new Promotion_DAO("complucine");
        $promotions = $promotion->allPromotionData();
        $ids = array();
        $tittles = array();
        $descriptions = array();
        $codes = array();
        $isActive = array();
        if(is_array($promotions)){
            foreach($promotions as $key => $value){
                $ids[$key] = $value->getId();
                $tittles[$key] = $value->getTittle();
                $descriptions[$key] = $value->getDescription();
                $codes[$key] = $value->getCode();
                if($value->getActive()){
                    $isActives[$key] = "ACTIVA";
                } else {
                    $isActives[$key] = "CADUCADA";
                }
            }
        }
        switch($this->page){
            case "Promociones":
                for($i = 0; $i < count($promotions); $i++){
                    if($i%2 === 0){
                        if($i != 0) $reply .= "
                    ";
                        $reply .= "
                        ";
                    }
                    else{
                        if($i != 0) $reply .= "
                    ";
                    $reply .= "
                        ";
                    }
                    $reply .= "
                    ";
                }
                $reply .= "
 \n";
                break;
            default:
                break;
        }
        return $reply;
    }
    //Print session MSG:
    function print_msg() {
        if(isset($_SESSION['message'])){
            echo "".$_SESSION['message']."
";
            unset($_SESSION['message']);
        }
    }
    //Print generic Footer:
    function print_footer(){
        $prefix = $this->prefix;
        $page = $this->page;
        
        if(!isset($_SESSION["css"]) || $_SESSION["css"] === "main.css"){
            $css = "{$prefix}assets/css/highContrast.css";
            $nameCSS = "Alto Contraste";
        } else {
            $css = "{$prefix}assets/css/main.css";
            $nameCSS = "Contraste Normal";
        }
        
        echo"\n";
    }
    //Print JS scripts:
    function print_scripts(){
        $prefix = $this->prefix;
        $page = $this->page;
        echo"
        
        
        
        ";
        if($page === "FDI-Cines") echo"\n";
        if($page === "Panel de Usuario") echo"\n";
        if($page === "Comprar Entrada") echo"
        
        \n";
    }
    }
?>