2018-02-19 23:52:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace router\controller;
|
|
|
|
|
|
|
|
|
|
|
|
class js{
|
|
|
|
|
|
|
|
|
|
|
|
private $page;
|
|
|
|
|
|
|
|
/* PRE-CALL
|
|
|
|
*
|
|
|
|
* @url<String> Calling URI
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function __construct($url){
|
|
|
|
$this->page = isset($url['page']) ? $url['page'] : '';
|
|
|
|
$this->page = preg_match('/^@[a-z]+$/', $this->page) ? substr($this->page, 1) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Generate _SERVER.js
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function server(){
|
|
|
|
header('Content-Type: text/javascript; charset=utf-8');
|
|
|
|
|
|
|
|
echo "window._SERVER = ".json_encode([
|
|
|
|
|
|
|
|
'session' => [
|
2018-03-15 12:13:35 +00:00
|
|
|
'name' => $_SESSION['CAS']['login'],
|
|
|
|
'connected' => isset($_SESSION['AUTH']) ? count($_SESSION['AUTH']) > 0 : false,
|
|
|
|
'departments' => array_map(function($d){ return [ 'id' => $d['idDep'], 'label' => $d['labelDep']]; }, $_SESSION['AvailableDepartment']),
|
2018-03-17 18:07:44 +00:00
|
|
|
'department_id' => $_SESSION['CurrentDepartementId'],
|
|
|
|
'version' => $_SESSION['VERSION']
|
2018-02-19 23:52:07 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
])."\n";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Manage bundle hash
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function bundle(){
|
2018-02-20 16:45:02 +00:00
|
|
|
if( is_null($this->page) )
|
|
|
|
include __PUBLIC__.'/page/404.php';
|
2018-02-19 23:52:07 +00:00
|
|
|
|
|
|
|
/* (1) Extract /public_html/js/ all .js files */
|
|
|
|
$js_scripts = glob(__PUBLIC__.'/js/bundle/'.$this->page.'@*.js');
|
|
|
|
|
|
|
|
/* (2) If match pattern 'bundle@home@*.js' */
|
|
|
|
foreach($js_scripts as $fname){
|
|
|
|
|
|
|
|
$bname = basename($fname);
|
|
|
|
|
|
|
|
// if match -> load it and exit
|
|
|
|
header("Location: /js/bundle/$bname");
|
|
|
|
die();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (3) If nothing found */
|
2018-02-20 16:45:02 +00:00
|
|
|
include __PUBLIC__.'/page/404.php';
|
2018-02-19 23:52:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* POST-CALL
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function __destruct(){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|