Inclusi js essenziali BugFix LoginManager Creata classe MenuGenerator per ottenere le voci menu in base ai ruoli Incluso sistema di inclusione header in GUIHandler
116 lines
4.0 KiB
PHP
116 lines
4.0 KiB
PHP
<?php
|
|
/*
|
|
Author: Riccardo Di Dato
|
|
Creation Date: 13/gen/2016
|
|
*/
|
|
|
|
class GUIHandler {
|
|
const STYLESHEET_GENERAL = 0;
|
|
const STYLESHEET_USER = 1;
|
|
const STYLESHEET_ADMIN = 2;
|
|
|
|
const JAVASCRIPT_GENERAL = 0;
|
|
const JAVASCRIPT_USER = 1;
|
|
const JAVASCRIPT_ADMIN = 2;
|
|
|
|
private static $STYLESHEETS = array(self::STYLESHEET_GENERAL=>array(),self::STYLESHEET_USER=>array(),self::STYLESHEET_ADMIN=>array());
|
|
private static $JAVASCRIPTS = array(self::JAVASCRIPT_GENERAL=>array(),self::JAVASCRIPT_USER=>array(),self::JAVASCRIPT_ADMIN=>array());
|
|
|
|
public static function generateHtmlHeaders(array $data = array(), $admin = false){
|
|
$conf = GlobalVariables::get("config");
|
|
|
|
$title = $conf->info->projectName;
|
|
if (array_key_exists("title", $data)){
|
|
$title = $data["title"];
|
|
}
|
|
|
|
$description = $conf->info->projectDescription;
|
|
if (array_key_exists("description", $data)){
|
|
$description = $data["description"];
|
|
}
|
|
|
|
$author = $conf->info->author;
|
|
if (array_key_exists("author", $data)){
|
|
$author = $data["author"];
|
|
}
|
|
|
|
header("Content-type: text/html; charset=utf-8");
|
|
|
|
echo "<!DOCTYPE html>\n";
|
|
echo "<html class=\"sidebar_default no-js\" lang=\"en\">\n<head>\n";
|
|
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
|
|
echo "<title>$title</title>\n";
|
|
echo "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
|
|
echo "<meta name=\"description\" content=\"$description\">\n";
|
|
echo "<meta name=\"author\" content=\"$author\">\n";
|
|
echo "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=Edge,chrome=1\">";
|
|
echo '<link rel="shortcut icon" href="'.self::getImagesUrl().'/favicon.png">'."\n";
|
|
|
|
foreach (self::$STYLESHEETS[self::STYLESHEET_GENERAL] as $file){
|
|
echo '<link type="text/css" rel="stylesheet" href="'.$file.'"';
|
|
}
|
|
|
|
$othStyle = $admin?self::STYLESHEET_ADMIN:self::STYLESHEET_USER;
|
|
foreach (self::$STYLESHEETS[$othStyle] as $file){
|
|
echo '<link type="text/css" rel="stylesheet" href="'.$file.'">'."\n";
|
|
}
|
|
|
|
foreach (self::$JAVASCRIPTS[self::JAVASCRIPT_GENERAL] as $file){
|
|
echo '<script type="text/javascript" src="'.$file.'"></script>'."\n";
|
|
}
|
|
|
|
$othJs = $admin?self::JAVASCRIPT_ADMIN:self::JAVASCRIPT_USER;
|
|
foreach (self::$JAVASCRIPTS[$othJs] as $file){
|
|
echo '<script type="text/javascript" src="'.$file.'"></script>'."\n";
|
|
}
|
|
|
|
echo '</head>';
|
|
}
|
|
|
|
public static function redirect($url){
|
|
// $tmp = new JavaScriptElement("var index = window.location.href.indexOf('#');window.location.href='".$url."'+(index == -1 ? '' : window.location.href.substr(index));");
|
|
// $tmp->render();
|
|
echo '<script type="text/javascript">window.location.href="'.self::getBaseUrl().$url.'";</script>';
|
|
die();
|
|
}
|
|
|
|
public static function addStylesheet($group, $file){
|
|
if (array_key_exists($group, self::$STYLESHEETS)){
|
|
self::$STYLESHEETS[$group][] = self::getStylesheetsUrl().$file;
|
|
}
|
|
else {
|
|
throw new CoreException("Invalid stylesheet group ($group) passed to GUIHandler::addStylesheet() for file '$file'");
|
|
}
|
|
}
|
|
|
|
public static function addJavascriptLib($group, $file){
|
|
if (array_key_exists($group, self::$JAVASCRIPTS)){
|
|
self::$JAVASCRIPTS[$group][] = self::getJavascriptsUrl().$file;
|
|
}
|
|
else {
|
|
throw new CoreException("Invalid stylesheet group ($group) passed to GUIHandler::addJavascriptLib() for file '$file'");
|
|
}
|
|
}
|
|
// public static function generateLoadingOverlay(){
|
|
// echo '<div id="loading" class="no-print"><div>Caricamento....<br/>Attendere prego<br/><br/><img src="'.self::getImagesUrl().'/ajax-loader.gif"></div></div>';
|
|
// }
|
|
|
|
public static function getBaseUrl(){
|
|
$conf = GlobalVariables::get("config");
|
|
return "http://$_SERVER[HTTP_HOST]".$conf->pages->remoteLocationPath;
|
|
}
|
|
|
|
public static function getImagesUrl(){
|
|
return self::getBaseUrl()."images/";
|
|
}
|
|
|
|
public static function getStylesheetsUrl(){
|
|
return self::getBaseUrl()."style/";
|
|
}
|
|
|
|
public static function getJavascriptsUrl(){
|
|
return self::getBaseUrl()."js/";
|
|
}
|
|
}
|
|
|
|
?>
|