Fixed logout/login bug
Fixed logout/login bug

<?php <?php
/** Entry Point for Crypto key - Utilises browser caching so only have to send to the client once per key session /** Entry Point for Crypto key - Utilises browser caching so only have to send to the client once per key session
* *
* Originally had to send twice because expiry was tied to the user's CredLocker session, * Originally had to send twice because expiry was tied to the user's CredLocker session,
* meaning Chrome requested twice (expiry of 0 epoch was sent by the login form). Firefox exhibited an odd behaviour and * meaning Chrome requested twice (expiry of 0 epoch was sent by the login form). Firefox exhibited an odd behaviour and
* ignored the expiry date, so only requested once. * ignored the expiry date, so only requested once.
* *
* *
* Although not currently implemented, this file will eventually define the following * Although not currently implemented, this file will eventually define the following
* *
* - Encryption key for received data * - Encryption key for received data
* - Encryption key for sent data * - Encryption key for sent data
* - Delimiter to use for API requests * - Delimiter to use for API requests
* - API terminology to use (allowing us to replace known calls such as retCred with a random string) * - API terminology to use (allowing us to replace known calls such as retCred with a random string)
* *
* *
* *
* Copyright (C) 2012 B Tasker * Copyright (C) 2012 B Tasker
* Released under GNU GPL V2 * Released under GNU GPL V2
* See LICENSE * See LICENSE
* *
*/ */
   
   
// Using gzhandler broke on a few systems. A lot seem to automatically gzip where possible though, so removed gzhandler call // Using gzhandler broke on a few systems. A lot seem to automatically gzip where possible though, so removed gzhandler call
ob_start(); ob_start();
error_reporting(0); error_reporting(0);
   
session_start(); session_start();
define('_CREDLOCK',1); define('_CREDLOCK',1);
   
// Change the current working dir // Change the current working dir
chdir(dirname(__FILE__)."/../"); chdir(dirname(__FILE__)."/../");
   
// Load the framework // Load the framework
require_once 'lib/Framework/main.php'; require_once 'lib/Framework/main.php';
   
   
  if (isset($_COOKIE['PHPCredLockerKeySet']) && BTMain::getVar('destSession') == 'Y'){
   
  $expires = strtotime("-2 days");
  setcookie("PHPCredLockerKeySet", 1, $expires, dirname($_SERVER["REQUEST_URI"]), $_SERVER['HTTP_HOST'], BTMain::getConf()->forceSSL);
  BTMain::unsetSessVar('tls');
  BTMain::unsetSessVar('KeyExpiry');
  BTMain::unsetSessVar('apiterms');
   
  $_COOKIE['PHPCredLockerKeySet'] = 0;
   
  }
   
   
   
   
$tls = BTMain::getSessVar('tls'); $tls = BTMain::getSessVar('tls');
$expiry = BTMain::getSessVar('KeyExpiry'); $expiry = BTMain::getSessVar('KeyExpiry');
   
   
   
$apiterms = array( $apiterms = array(
"retCred", "retCred",
"checkSess", "checkSess",
"delCred", "delCred",
"delUser", "delUser",
"delCredType", "delCredType",
"delCust", "delCust",
"delGroup" "delGroup"
); );
   
   
   
   
// We only to do key generation if we're not on a SSL connection or if the system is configured to force use // We only to do key generation if we're not on a SSL connection or if the system is configured to force use
if (!BTMain::getConnTypeSSL() || BTMain::getConf()->forceTLS){ if (!BTMain::getConnTypeSSL() || BTMain::getConf()->forceTLS){
   
   
// If the key is still valid and we know the browser has already retrieved it, just tell the browser to use the cache // If the key is still valid and we know the browser has already retrieved it, just tell the browser to use the cache
if ((BTMain::getVar('forceload') != 'y') && (time() < $expiry) && ($_COOKIE['PHPCredLockerKeySet'] == 1) && ($expiry) && (!empty($tls))){ if ((BTMain::getVar('forceload') != 'y') && (time() < $expiry) && ($_COOKIE['PHPCredLockerKeySet'] == 1) && ($expiry) && (!empty($tls))){
header("HTTP/1.1 304 Not Modified"); header("HTTP/1.1 304 Not Modified");
die; die;
} }
   
// Would actually prefer not to include this in an unauthenticated session, but want to put key generation in the most logical place. // Would actually prefer not to include this in an unauthenticated session, but want to put key generation in the most logical place.
require_once 'lib/crypto.php'; require_once 'lib/crypto.php';
   
   
   
// Set MIME-Header // Set MIME-Header
header("Content-Type: text/javascript"); header("Content-Type: text/javascript");
   
   
   
   
   
if (isset($_COOKIE['PHPCredLocker'])): if (isset($_COOKIE['PHPCredLocker'])):
   
foreach ($apiterms as $term){ foreach ($apiterms as $term){
   
$x = 0; $x = 0;
$new = ''; $new = '';
$termlength = mt_rand(4,15); $termlength = mt_rand(4,15);
   
   
while ($x <= $termlength){ while ($x <= $termlength){
$new .= chr(mt_rand(97,122)); $new .= chr(mt_rand(97,122));
if (($x == $termlength) && in_array($new,$usedterms)){ if (($x == $termlength) && in_array($new,$usedterms)){
// Make sure the termcode isn't already in used, if so, start again // Make sure the termcode isn't already in used, if so, start again
$x = 0; $x = 0;
$new = ''; $new = '';
} }
$x++; $x++;
} }
   
$usedterms[] = $new; $usedterms[] = $new;
$terms[$new] = $term; $terms[$new] = $term;
} }
   
   
$expiry = strtotime('+10 minutes'); $expiry = strtotime('+10 minutes');
$seconds_to_cache = $expiry - time(); $seconds_to_cache = $expiry - time();
$gmt = gmdate("D, d M Y H:i:s", $expiry) . " GMT"; $gmt = gmdate("D, d M Y H:i:s", $expiry) . " GMT";
   
// Set caching headers // Set caching headers
header("Expires: $gmt"); header("Expires: $gmt");
header("Pragma: cache"); header("Pragma: cache");
header("Cache-Control: Private, max-age=$seconds_to_cache"); header("Cache-Control: Private, max-age=$seconds_to_cache");
   
// Add the key and it's expiry to the session // Add the key and it's expiry to the session
BTMain::setSessVar('KeyExpiry',$expiry); BTMain::setSessVar('KeyExpiry',$expiry);
BTMain::setSessVar('tls',Crypto::genxorekey()); BTMain::setSessVar('tls',Crypto::genxorekey());
BTMain::setSessVar('apiterms',$terms); BTMain::setSessVar('apiterms',$terms);
   
// By setting a cookie, we provide an easy mechanism for allowing the API to force a key refresh // By setting a cookie, we provide an easy mechanism for allowing the API to force a key refresh
setcookie("PHPCredLockerKeySet", 1, $expiry, dirname($_SERVER["REQUEST_URI"]), $_SERVER['HTTP_HOST'], BTMain::getConf()->forceSSL); setcookie("PHPCredLockerKeySet", 1, $expiry, dirname($_SERVER["REQUEST_URI"]), $_SERVER['HTTP_HOST'], BTMain::getConf()->forceSSL);
   
endif; endif;
   
// We use a different method to generate Auth keys - in case a pattern does somehow appear in the TLS generation stuff we don't want anyone to be // We use a different method to generate Auth keys - in case a pattern does somehow appear in the TLS generation stuff we don't want anyone to be
// able to view those keys without a valid login (at which point they won't really need to do key analysis!) // able to view those keys without a valid login (at which point they won't really need to do key analysis!)
   
$x = 0; $x = 0;
$str = ''; $str = '';
$str2 = ''; $str2 = '';
   
while ($x < 40){ while ($x < 40){
   
$str .= chr(rand(33,126)) .mt_rand(16,45); $str .= chr(rand(33,126)) .mt_rand(16,45);
$str2 .= chr(rand(33,126)) .mt_rand(16,45); $str2 .= chr(rand(33,126)) .mt_rand(16,45);
$x++; $x++;
   
} }
   
   
BTMain::setSessVar('AuthKey',rtrim(base64_encode($str),"=") . ":" . rtrim(base64_encode($str2),"=")); BTMain::setSessVar('AuthKey',rtrim(base64_encode($str),"=") . ":" . rtrim(base64_encode($str2),"="));
$enabled = 'true'; $enabled = 'true';
   
   
   
}else{ }else{
// We don't need to generate keys as we're on a SSL connection // We don't need to generate keys as we're on a SSL connection
   
foreach ($apiterms as $value){ foreach ($apiterms as $value){
$terms[$value] = $value; $terms[$value] = $value;
} }
   
BTMain::setSessVar('apiterms',$terms); BTMain::setSessVar('apiterms',$terms);
BTMain::setSessVar('tls',' '); BTMain::setSessVar('tls',' ');
BTMain::setSessVar('AuthKey',' '); BTMain::setSessVar('AuthKey',' ');
$enabled = 'false'; $enabled = 'false';
   
   
   
$expiry = strtotime('+1 day'); $expiry = strtotime('+1 day');
$seconds_to_cache = $expiry - time(); $seconds_to_cache = $expiry - time();
$gmt = gmdate("D, d M Y H:i:s", $expiry) . " GMT"; $gmt = gmdate("D, d M Y H:i:s", $expiry) . " GMT";
   
// Set caching headers // Set caching headers
header("Expires: $gmt"); header("Expires: $gmt");
header("Pragma: cache"); header("Pragma: cache");
header("Cache-Control: Private, max-age=$seconds_to_cache"); header("Cache-Control: Private, max-age=$seconds_to_cache");
   
} }
   
   
   
ob_start(); ob_start();
?> ?>
function getKey(){ return '<?php echo base64_encode(BTMain::getSessVar('tls'));?>'; } function getKey(){ return '<?php echo base64_encode(BTMain::getSessVar('tls'));?>'; }
   
   
function getDelimiter(){ return "|..|";} function getDelimiter(){ return "|..|";}
   
   
function getTerminology(a){ function getTerminology(a){
   
if (a == 'undefined' || a == 'null' || a == ''){ if (a == 'undefined' || a == 'null' || a == ''){
return;} return;}
   
<?php foreach ($terms as $key=>$value){ echo "this.$value='".base64_encode($key) ."';"; }?> <?php foreach ($terms as $key=>$value){ echo "this.$value='".base64_encode($key) ."';"; }?>
   
return this[a]; return this[a];
} }
   
   
   
function getAuthKey(){ function getAuthKey(){
return '<?php echo base64_encode(BTMain::getSessVar('AuthKey')); ?>'; return '<?php echo base64_encode(BTMain::getSessVar('AuthKey')); ?>';
} }
   
   
function destroyKeys(){ function destroyKeys(){
window.getKey = ''; window.getKey = '';
window.getDelimiter = ''; window.getDelimiter = '';
window.getTerminology = ''; window.getTerminology = '';
window.getAuthKey = ''; window.getAuthKey = '';
return window.destroyKeys = ''; return window.destroyKeys = '';
} }
   
function enabledEncryption(){ function enabledEncryption(){
return <?php echo $enabled;?>; return <?php echo $enabled;?>;
} }
   
   
   
   
   
   
   
new getTerminology(); new getTerminology();
<?php <?php
   
   
   
echo str_replace("\n","",ob_get_clean()); echo str_replace("\n","",ob_get_clean());
   
ob_end_flush(); ob_end_flush();
<?php <?php
/** Main HTML Output generation /** Main HTML Output generation
* *
* Copyright (C) 2012 B Tasker * Copyright (C) 2012 B Tasker
* Released under GNU GPL V2 * Released under GNU GPL V2
* See LICENSE * See LICENSE
* *
*/ */
   
defined('_CREDLOCK') or die; defined('_CREDLOCK') or die;
   
   
   
class genOutput{ class genOutput{
   
/** Ouputs the default content for the homepage. Content can be controlled in the notifications config file /** Ouputs the default content for the homepage. Content can be controlled in the notifications config file
* *
*/ */
function genDefaultPage(){ function genDefaultPage(){
global $notifications; global $notifications;
$notifications->setPageTitle("Home"); $notifications->setPageTitle("Home");
   
if (BTMain::getUser()->name){ if (BTMain::getUser()->name){
$notname= 'HomePageTextLoggedIn'; $notname= 'HomePageTextLoggedIn';
}else{ }else{
$notname= 'HomePageTextNotLoggedIn'; $notname= 'HomePageTextNotLoggedIn';
} }
   
   
$notif = $notifications->getNotification($notname); $notif = $notifications->getNotification($notname);
$str = "<div class='{$notif->className}'"; $str = "<div class='{$notif->className}'";
   
   
if (isset($notif->id)){ if (isset($notif->id)){
$str .= " id='{$notif->id}'"; $str .= " id='{$notif->id}'";
} }
   
   
   
return $str . ">" . $notif->text . "</div>\n"; return $str . ">" . $notif->text . "</div>\n";
   
} }
   
   
   
   
   
/** Call the relevant template /** Call the relevant template
* *
*/ */
function callTemplate(){ function callTemplate(){
// Load the config so we know which template to call // Load the config so we know which template to call
   
$template = BTMain::getConf()->template; $template = BTMain::getConf()->template;
require "templates/$template/index.php"; require "templates/$template/index.php";
   
} }
   
   
/** Load a view and return the output /** Load a view and return the output
* *
* @arg view string * @arg view string
*/ */
function loadView($view){ function loadView($view){
   
ob_start; ob_start;
$template = BTMain::getConf()->template; $template = BTMain::getConf()->template;
$view = str_replace(".","/",$view); $view = str_replace(".","/",$view);
// Check for template level override // Check for template level override
if (file_exists("templates/". $template . "html/views/" . $view . ".php")){ if (file_exists("templates/". $template . "html/views/" . $view . ".php")){
require "templates/". $template . "html/views/" . $view . ".php"; require "templates/". $template . "html/views/" . $view . ".php";
}else{ }else{
require "views/" . $view . ".php"; require "views/" . $view . ".php";
   
} }
return ob_get_clean(); return ob_get_clean();
} }
   
   
/** Output the Breadcrumbs /** Output the Breadcrumbs
* *
*/ */
function BreadCrumbs(){ function BreadCrumbs(){
?> ?>
<ul class="breadcrumb"> <ul class="breadcrumb">
<li> <li>
<a href="index.php">Home</a> <a href="index.php">Home</a>
</li> </li>
<?php foreach ($GLOBALS['BREADCRUMB'] as $crumb){?> <?php foreach ($GLOBALS['BREADCRUMB'] as $crumb){?>
<li> <li>
<span class="divider">/</span> <span class="divider">/</span>
<a href="<?php echo $crumb['url']; ?>"><?php echo $crumb['name']; ?></a> <a href="<?php echo $crumb['url']; ?>"><?php echo $crumb['name']; ?></a>
</li> </li>
   
<?php }?> <?php }?>
</ul> </ul>
<?php <?php
   
} }
   
   
   
/** Generate the HTML for any relevant Notifications /** Generate the HTML for any relevant Notifications
* *
*/ */
function Notifications(){ function Notifications(){
   
global $notifications; global $notifications;
$nots = $notifications->getNotifications(); $nots = $notifications->getNotifications();
$str = array(); $str = array();
   
if ($nots){ if ($nots){
foreach ($nots as $not){ foreach ($nots as $not){
$id=''; $id='';
   
if (!empty($not->id)){ if (!empty($not->id)){
$id = " id='{$not->id}'"; $id = " id='{$not->id}'";
} }
   
$str[] = "<div class='{$not->className}'$id>{$not->text}</div>"; $str[] = "<div class='{$not->className}'$id>{$not->text}</div>";
   
} }
   
   
} }
   
return implode("\n",$str); return implode("\n",$str);
   
} }
   
   
/** Defines (almost) every static resource to be included in the document head /** Defines (almost) every static resource to be included in the document head
* *
* @return object * @return object
* *
*/ */
function includedresources(){ function includedresources(){
$coreres->css->bootstrap->fname = 'bootstrap'; $coreres->css->bootstrap->fname = 'bootstrap';
$coreres->css->bootstrap->path = 'bootstrap/css/'; $coreres->css->bootstrap->path = 'bootstrap/css/';
$coreres->css->bootstrapresponsive->fname = 'bootstrap-responsive'; $coreres->css->bootstrapresponsive->fname = 'bootstrap-responsive';
$coreres->css->bootstrapresponsive->path = 'bootstrap/css/'; $coreres->css->bootstrapresponsive->path = 'bootstrap/css/';
$coreres->css->jquerytooltip->fname = 'jquery.tooltip'; $coreres->css->jquerytooltip->fname = 'jquery.tooltip';
   
   
$coreres->js->jquery->fname = 'jquery'; $coreres->js->jquery->fname = 'jquery';
$coreres->js->jquery->forcemin = '.min'; $coreres->js->jquery->forcemin = '.min';
$coreres->js->bootstrap->fname = 'bootstrap'; $coreres->js->bootstrap->fname = 'bootstrap';
$coreres->js->bootstrap->path = 'bootstrap/js/'; $coreres->js->bootstrap->path = 'bootstrap/js/';
$coreres->js->jquerytooltip->fname = 'jquery.tooltip'; $coreres->js->jquerytooltip->fname = 'jquery.tooltip';
$coreres->js->jquerytooltip->forcemin = '.min'; $coreres->js->jquerytooltip->forcemin = '.min';
$coreres->js->main->fname = 'main'; $coreres->js->main->fname = 'main';
$coreres->js->base64->fname = 'base64'; $coreres->js->base64->fname = 'base64';
   
$coreres->resourcespath = "Resources"; $coreres->resourcespath = "Resources";
   
return $coreres; return $coreres;
} }
   
   
   
/** Push the required headers /** Push the required headers
* *
*/ */
function headContents(){ function headContents(){
   
global $notifications; global $notifications;
$page = $notifications->getPageInfo(); $page = $notifications->getPageInfo();
$conf = BTMain::getConf(); $conf = BTMain::getConf();
$plg = new Plugins; $plg = new Plugins;
   
$coreres = $this->includedresources(); $coreres = $this->includedresources();
   
// Call any configured plugins // Call any configured plugins
$data->resources = $coreres; $data->resources = $coreres;
$data->action = 'loadresource'; $data->action = 'loadresource';
   
$coreres = $plg->loadPlugins("Resources",$data); $coreres = $plg->loadPlugins("Resources",$data);
   
   
   
// I'm knackered, quitting while I'm ahead. Will improve/finish later // I'm knackered, quitting while I'm ahead. Will improve/finish later
$resourcespath = $coreres->resourcespath; $resourcespath = $coreres->resourcespath;
   
   
?> ?>
<title><?php echo $conf->ProgName;?> - <?php echo htmlentities($page->title);?></title> <title><?php echo $conf->ProgName;?> - <?php echo htmlentities($page->title);?></title>
   
   
<?php <?php
foreach($coreres->resources->css as $css){ foreach($coreres->resources->css as $css){
   
if ($css->disable){ continue; } if ($css->disable){ continue; }
   
if (!empty($css->url)){ if (!empty($css->url)){
$path = $css->url; $path = $css->url;
}else{ }else{
$path = $coreres->resources->resourcespath . "/"; $path = $coreres->resources->resourcespath . "/";
if (!empty($css->path)){ if (!empty($css->path)){
$path .= $css->path; $path .= $css->path;
} }
$path .= $css->fname; $path .= $css->fname;
   
if ($css->forcemin){ if ($css->forcemin){
$path .= $css->forcemin; $path .= $css->forcemin;
}else{ }else{
$path .= $conf->JSMinName; $path .= $conf->JSMinName;
} }
$path .= '.css'; $path .= '.css';
} }
   
?> ?>
<link rel="stylesheet" type="text/css" href="<?php echo $path; ?>" /> <link rel="stylesheet" type="text/css" href="<?php echo $path; ?>" />
<?php <?php
} }
?> ?>
   
<?php foreach ($page->css as $css):?> <?php foreach ($page->css as $css):?>
<link rel="stylesheet" type="text/css" href='<?php echo $coreres->resources->resourcespath; ?>/<?php echo $css;?>.css'/> <link rel="stylesheet" type="text/css" href='<?php echo $coreres->resources->resourcespath; ?>/<?php echo $css;?>.css'/>
<?php endforeach;?> <?php endforeach;?>
   
   
<script id='kFile' src="Resources/info.php?<?php echo md5(session_id().$_SERVER['REMOTE_ADDR']); ?>" type="text/javascript"></script> <script id='kFile' src="Resources/info.php?<?php $frs = BTMain::getSessVar('cacheFrustrate'); echo md5(session_id().$_SERVER['REMOTE_ADDR']).$frs; ?><?php $notif=BTMain::getVar('notif'); if (!empty($notif) && ($notif == 'LoginFailed' || $notif == 'LoggedOut' || $notif == 'InvalidSession')){ echo "&destSession=Y"; BTMain::setSessVar('cacheFrustrate',mt_rand());}?>" type="text/javascript"></script>
   
   
<?php <?php
foreach($coreres->resources->js as $js){ foreach($coreres->resources->js as $js){
if ($js->disable){ continue; } if ($js->disable){ continue; }
if (!empty($js->url)){ if (!empty($js->url)){
$path = $js->url; $path = $js->url;
}else{ }else{
$path = $coreres->resources->resourcespath . "/"; $path = $coreres->resources->resourcespath . "/";
if (!empty($js->path)){ if (!empty($js->path)){
$path .= $js->path; $path .= $js->path;
} }
$path .= $js->fname; $path .= $js->fname;
   
if ($js->forcemin){ if ($js->forcemin){
$path .= $js->forcemin; $path .= $js->forcemin;
}else{ }else{
$path .= $conf->JSMinName; $path .= $conf->JSMinName;
} }
$path .= '.js'; $path .= '.js';
} }
   
?> ?>
<script type="text/javascript" src="<?php echo $path; ?>" /></script> <script type="text/javascript" src="<?php echo $path; ?>" /></script>
<?php <?php
} }
?> ?>
   
   
<?php foreach ($page->reqscripts as $script):?> <?php foreach ($page->reqscripts as $script):?>
<script src="<?php echo $coreres->resources->resourcespath; ?>/<?php echo $script;?><?php echo $conf->JSMinName;?>.js" type="text/javascript"></script> <script src="<?php echo $coreres->resources->resourcespath; ?>/<?php echo $script;?><?php echo $conf->JSMinName;?>.js" type="text/javascript"></script>
<?php endforeach; if (!empty($page->custJS[0])):?> <?php endforeach; if (!empty($page->custJS[0])):?>
   
<script type="text/javascript"> <script type="text/javascript">
<?php echo implode("\n",$page->custJS);?> <?php echo implode("\n",$page->custJS);?>
</script> </script>
   
<?php endif; ?> <?php endif; ?>
   
<!-- Fire the default scripts when the browser reports document ready --> <!-- Fire the default scripts when the browser reports document ready -->
<script type="text/javascript"> <script type="text/javascript">
var sesscheck; jQuery(document).ready(function() { checkKeyAvailable(); <?php if (BTMain::getUser()->name):?>sesscheck = setInterval("checkSession()",120000);<?php endif;?>}); var sesscheck; jQuery(document).ready(function() { checkKeyAvailable(); <?php if (BTMain::getUser()->name):?>sesscheck = setInterval("checkSession()",120000);<?php endif;?>});
</script> </script>
   
<?php <?php
} }
   
   
   
   
/** Load a module by name /** Load a module by name
* *
* @arg module - string * @arg module - string
* *
*/ */
function loadModule($module){ function loadModule($module){
   
$template = BTMain::getConf()->template; $template = BTMain::getConf()->template;
   
   
// Check for template override // Check for template override
if (file_exists("templates/$template/html/modules/$module/$module.php")){ if (file_exists("templates/$template/html/modules/$module/$module.php")){
require "templates/$template/html/modules/$module/$module.php"; require "templates/$template/html/modules/$module/$module.php";
}else{ }else{
require "modules/$module/$module.php"; require "modules/$module/$module.php";
} }
   
   
   
} }
   
   
   
   
}/** Gen Output Class Ends **/ }/** Gen Output Class Ends **/
   
   
   
   
   
   
   
   
/** Notifications class **/ /** Notifications class **/
class notifications{ class notifications{
   
   
   
   
/** Return an object containing any notification items that have been set (or at least those suited for embedding in the head) /** Return an object containing any notification items that have been set (or at least those suited for embedding in the head)
* *
* @return object * @return object
* *
*/ */
function getPageInfo(){ function getPageInfo(){
   
$page->title = ''; $page->title = '';
$page->css = array(); $page->css = array();
$page->reqscripts = array(); $page->reqscripts = array();
$page->custJS = array(); $page->custJS = array();
   
if (isset($this->pagetitle)){ if (isset($this->pagetitle)){
$page->title = $this->pagetitle; $page->title = $this->pagetitle;
} }
   
if (is_array($this->css)){ if (is_array($this->css)){
$page->css = $this->css; $page->css = $this->css;
} }
   
if (is_array($this->requiredscripts)){ if (is_array($this->requiredscripts)){
$page->reqscripts = $this->requiredscripts; $page->reqscripts = $this->requiredscripts;
} }
   
if (is_array($this->customJS)){ if (is_array($this->customJS)){
$page->custJS = $this->customJS; $page->custJS = $this->customJS;
} }
   
return $page; return $page;
} }
   
   
/** Set the page title /** Set the page title
* *
* @arg title * @arg title
* *
*/ */
function setPageTitle($title){ function setPageTitle($title){
$this->pagetitle = $title; $this->pagetitle = $title;
} }
   
   
   
   
/** Return the content of a single named notification /** Return the content of a single named notification
* *
* @arg notname - string - notification name * @arg notname - string - notification name
* *
* @return object * @return object
* *
*/ */
function getNotification($notname){ function getNotification($notname){
   
if (empty($notname)){ return false; } if (empty($notname)){ return false; }
   
include 'conf/notifications.php'; include 'conf/notifications.php';
   
return $notifs->$notname; return $notifs->$notname;
   
   
} }
   
   
   
   
   
/** Get any notifications that have been triggered /** Get any notifications that have been triggered
* *
* @return object (or false if no notifications) * @return object (or false if no notifications)
* *
*/ */
function getNotifications(){ function getNotifications(){
   
$notif = BTMain::getVar('notif'); $notif = BTMain::getVar('notif');
$triggernotifs = is_array($this->notifications); $triggernotifs = is_array($this->notifications);
   
   
// Check whether there are any notifications to push // Check whether there are any notifications to push
if (!$notif && !$triggernotifs){ if (!$notif && !$triggernotifs){
return false; return false;
} }
   
   
$nots = new stdClass(); $nots = new stdClass();
include 'conf/notifications.php'; include 'conf/notifications.php';
   
// Check for notifications triggered by views // Check for notifications triggered by views
if ($triggernotifs){ if ($triggernotifs){
   
foreach ($this->notifications as $msg){ foreach ($this->notifications as $msg){
$nots->$msg = $notifs->$msg; $nots->$msg = $notifs->$msg;
} }
   
} }
   
   
// Check for notifications triggered by the request // Check for notifications triggered by the request
if ($notif){ if ($notif){
$nots->$notif = $notifs->$notif; $nots->$notif = $notifs->$notif;
} }
   
   
return $nots; return $nots;
} }
   
   
/** Set a notification to display when getNotifications is called /** Set a notification to display when getNotifications is called
* *
* @arg notification - string containing notification name * @arg notification - string containing notification name
* *
*/ */
function setNotification($notification){ function setNotification($notification){
$this->notifications[] = $notification; $this->notifications[] = $notification;
} }
   
   
/** Trigger the inclusion of a CSS file in the document head /** Trigger the inclusion of a CSS file in the document head
* *
* @arg file - filename (Will be automatically prefixed with Resources/ and appended with .css) * @arg file - filename (Will be automatically prefixed with Resources/ and appended with .css)
* *
*/ */
function RequireCSS($file){ function RequireCSS($file){
$this->css[] = $file; $this->css[] = $file;
} }
   
   
/** Trigger the inclusion of a JS file in the document head /** Trigger the inclusion of a JS file in the document head
* *
* @arg file - filename (Will be automatically prefixed with Resources/ and appended with .js) * @arg file - filename (Will be automatically prefixed with Resources/ and appended with .js)
* *
*/ */
function RequireScript($script){ function RequireScript($script){
$this->requiredscripts[] = $script; $this->requiredscripts[] = $script;
} }
   
   
/** Set the breadcrumb path /** Set the breadcrumb path
* *
* @arg path - array * @arg path - array
* *
* Exact schema of the array is dictated by class genOutput but at time of writing, * Exact schema of the array is dictated by class genOutput but at time of writing,
* each breadcrumb item should be an array containing elements name and url * each breadcrumb item should be an array containing elements name and url
* *
*/ */
function setBreadcrumb($path){ function setBreadcrumb($path){
   
$GLOBALS['BREADCRUMB'] = $path; $GLOBALS['BREADCRUMB'] = $path;
   
} }
   
   
/** Embed a JS string into the document head, will automatically be placed between script tags /** Embed a JS string into the document head, will automatically be placed between script tags
* *
* @arg js - string * @arg js - string
* *
*/ */
function setCustomJS($js){ function setCustomJS($js){
$this->customJS[] = "$js"; $this->customJS[] = "$js";
} }
   
/** TODO add support for custom notifications passed as an argument **/ /** TODO add support for custom notifications passed as an argument **/
} }
   
   
   
   
   
?> ?>