2018-02-17 17:18:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace router\controller;
|
|
|
|
|
|
|
|
|
|
|
|
class page{
|
|
|
|
|
|
|
|
|
|
|
|
private $pagename;
|
2018-02-27 13:48:07 +00:00
|
|
|
private $uri;
|
2018-02-17 17:18:58 +00:00
|
|
|
|
|
|
|
/* PRE-CALL
|
|
|
|
*
|
|
|
|
* @url<String> Calling URI
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function __construct($url){
|
|
|
|
$this->pagename = $url['page'];
|
2018-02-20 16:17:53 +00:00
|
|
|
$this->uri = $url['uri'];
|
2018-02-17 17:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* CALL
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function load(){
|
2018-02-20 16:17:53 +00:00
|
|
|
|
2018-03-03 14:55:10 +00:00
|
|
|
/* (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();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-05-17 13:16:30 +00:00
|
|
|
/* (2) Only teacher */
|
|
|
|
if( !in_array('cas_admin', $_SESSION['AUTH']) ){
|
2018-03-03 14:55:10 +00:00
|
|
|
|
2018-05-17 13:16:30 +00:00
|
|
|
// redirection
|
|
|
|
if( $this->pagename != "fiche" ){
|
|
|
|
header('Location: /fiche/');
|
|
|
|
die();
|
|
|
|
}
|
2018-03-03 14:55:10 +00:00
|
|
|
|
2018-05-17 13:16:30 +00:00
|
|
|
// 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 */
|
2018-02-20 16:17:53 +00:00
|
|
|
$page_fname = __PUBLIC__."/page/".$this->pagename.".php";
|
|
|
|
|
2018-05-17 13:16:30 +00:00
|
|
|
/* (4) If page does not exist -> 404 */
|
2018-02-20 16:45:02 +00:00
|
|
|
if( !file_exists($page_fname) )
|
|
|
|
include __PUBLIC__.'/page/404.php';
|
2018-02-20 16:17:53 +00:00
|
|
|
|
2018-05-17 13:16:30 +00:00
|
|
|
/* (5) Set URI arguments */
|
2018-02-20 16:17:53 +00:00
|
|
|
$_GET['uri'] = explode('/', $this->uri);
|
|
|
|
|
2018-05-17 13:16:30 +00:00
|
|
|
/* (6) Load page */
|
2018-02-20 16:17:53 +00:00
|
|
|
include __PUBLIC__."/page/".$this->pagename.".php";
|
|
|
|
|
2018-02-17 17:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* POST-CALL
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function __destruct(){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|