ptut-vhost/build/router/controller/page.php

87 lines
1.3 KiB
PHP

<?php
namespace router\controller;
class page{
private $pagename;
private $uri;
/* PRE-CALL
*
* @url<String> Calling URI
*
*/
public function __construct($url){
$this->pagename = $url['page'];
$this->uri = $url['uri'];
}
/* CALL
*
*/
public function load(){
/* (1) If not logged in -> login page*/
if( !isset($_SESSION['AUTH']) || !is_array($_SESSION['AUTH']) || count($_SESSION['AUTH']) < 1 ){
include __PUBLIC__."/page/login.php";
die();
}
/* (2) Only teacher */
if( !in_array('cas_admin', $_SESSION['AUTH']) ){
// redirection
if( $this->pagename != "fiche" ){
header('Location: /fiche/');
die();
}
// deconnection
if( $this->uri == 'logout' || $this->uri == 'logout/' ){
\session_destroy();
header('Location: /');
die();
}
// load page
include __PUBLIC__."/page/fiche.php";
die();
}
/* (3) Build page file name */
$page_fname = __PUBLIC__."/page/".$this->pagename.".php";
/* (4) If page does not exist -> 404 */
if( !file_exists($page_fname) )
include __PUBLIC__.'/page/404.php';
/* (5) Set URI arguments */
$_GET['uri'] = explode('/', $this->uri);
/* (6) Load page */
include __PUBLIC__."/page/".$this->pagename.".php";
}
/* POST-CALL
*
*/
public function __destruct(){
}
}