155 lines
5.3 KiB
PHP
155 lines
5.3 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());
|
|
|
|
private static $onLoadEvents = 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="'.self::getStylesheetsUrl().$file.'"';
|
|
}
|
|
|
|
$othStyle = $admin?self::STYLESHEET_ADMIN:self::STYLESHEET_USER;
|
|
foreach (self::$STYLESHEETS[$othStyle] as $file){
|
|
echo '<link type="text/css" rel="stylesheet" href="'.self::getStylesheetsUrl().$file.'">'."\n";
|
|
}
|
|
|
|
foreach (self::$JAVASCRIPTS[self::JAVASCRIPT_GENERAL] as $file){
|
|
echo '<script type="text/javascript" src="'.self::getJavascriptsUrl().$file.'"></script>'."\n";
|
|
}
|
|
|
|
$othJs = $admin?self::JAVASCRIPT_ADMIN:self::JAVASCRIPT_USER;
|
|
foreach (self::$JAVASCRIPTS[$othJs] as $file){
|
|
echo '<script type="text/javascript" src="'.self::getJavascriptsUrl().$file.'"></script>'."\n";
|
|
}
|
|
|
|
if (sizeof(self::$onLoadEvents)>0){
|
|
echo '<script type="text/javascript">'."\n";
|
|
echo '$(document).ready(function(){'."\n";
|
|
foreach (self::$onLoadEvents as $evt){
|
|
echo $evt;
|
|
}
|
|
echo '});'."\n";
|
|
echo '</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 redirectPost($url,array $vals = array()){
|
|
// $tmp = new JavaScriptElement("var index = window.location.href.indexOf('#');window.location.href='".$url."'+(index == -1 ? '' : window.location.href.substr(index));");
|
|
// $tmp->render();
|
|
$valArr = array();
|
|
|
|
if (sizeof($vals)>0){
|
|
foreach ($vals as $key=>$val){
|
|
$valArr[] = '{"name":"'.$key.'","value":"'.$val.'"}';
|
|
}
|
|
}
|
|
$valString = '['.implode(",", $valArr).']';
|
|
echo '<script type="text/javascript">$(document).ready(function(){openPagePost("'.self::getBaseUrl().$url.'",'.$valString.');});</script>';
|
|
die();
|
|
}
|
|
|
|
public static function addStylesheet($group, $file){
|
|
if (array_key_exists($group, self::$STYLESHEETS)){
|
|
self::$STYLESHEETS[$group][] = $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][] = $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/";
|
|
}
|
|
|
|
public static function addOnLoadJsEvent($script){
|
|
self::$onLoadEvents[] = $script;
|
|
}
|
|
|
|
public static function generateHeadPublic(){
|
|
$mesi = array(1=>'Gennaio', 'Febbraio', 'Marzo', 'Aprile',
|
|
'Maggio', 'Giugno', 'Luglio', 'Agosto',
|
|
'Settembre', 'Ottobre', 'Novembre','Dicembre');
|
|
$day = date("d");
|
|
|
|
$head = '<div class="headContainer"><div style=""></div></div>';
|
|
}
|
|
}
|
|
|
|
?>
|