[castleparadox] / trunk / manager / layoutManager.php Repository:
ViewVC logotype

View of /trunk/manager/layoutManager.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 73 - (download) (annotate)
Fri Dec 4 09:17:24 2009 UTC (9 years ago) by inferiorminion
File size: 4541 byte(s)
Bug #30: Implement Project Soft Delete 
https://bugs.castleparadox.com/show_bug.cgi?id=30

<?php
/**
 * @package castleparadox
 * @subpackage manager
 * @version layoutManager.php, Apr 21, 2008 10:00:54 PM 
 * @author inferiorminion
 * @copyright Copyright &copy; 2008, Castle Paradox
 */
set_include_pathget_include_path() . PATH_SEPARATOR $_SERVER['DOCUMENT_ROOT'] );

include_once 
'./constants.php';
include_once 
'./model/messageContext.php';

/**
 * LayoutManager class
 * @package castleparadox
 * @subpackage manager
 */
class LayoutManager {
    protected static
        
$template,
        
$user,
        
$pageTitle,
        
$redirect,
        
$messageContext,
        
$genericsSet false,
        
$headersSent false;
        
    public static function 
setTemplate($template) {
        
LayoutManager::$template $template;
    }
    
    public static function 
getTemplate() {
        return 
LayoutManager::$template;
    }
    
    public static function 
setUser($user) {
        
LayoutManager::$user $user;
    }
    
    public static function 
getUser() {
        return 
LayoutManager::$user;
    }
    
    public static function 
setCustomTemplate($template$name) {
        
LayoutManager::$template->set_custom_template($template$name);
    }
    
    public static function 
setPageTitle($pageTitle) {
        
LayoutManager::$pageTitle $pageTitle;
    }
    
    public static function 
setRedirect($url$params false$is_amp true$session_id false) {
        
LayoutManager::$redirect append_sid($url$params$is_amp$session_id);
    }
    
    public static function 
performRedirect() {
        
Header 'Status: 302' );
        
Header 'Location: ' htmlspecialchars_decode(LayoutManager::$redirect) );
        exit;
    }
    
    public static function 
setHeader($datatype$size$filename) {
        
$bad_chars = array(":""*""?""\\""/""\"",);
        
        
// Send down the header to the client
        
Header 'Content-Type: ' $datatype );
        
Header 'Content-Length: ' $size );
        
Header 'Content-Disposition: inline; filename="' str_replace($bad_chars"-"$filename) . '"' );
        
LayoutManager::$headersSent true;
    }
    
    public static function 
display($tagName) {
        if( !
LayoutManager::$headersSent ) {
            if( !
LayoutManager::$genericsSet ) {
                if( isset(
LayoutManager::$messageContext) ) {
                    
LayoutManager::$messageContext->display(LayoutManager::$template);
                }
                
LayoutManager::setGenerics();
                
page_header(LayoutManager::$pageTitlefalse);
                
LayoutManager::$genericsSet true;
            }
            
LayoutManager::$template->display($tagName);
        }
    }
    
    public static function 
requireLogin() {
        if (
LayoutManager::$user->data['user_id'] == 1) {
            
LayoutManager::$pageTitle 'Login Required';
            
LayoutManager::$template->set_filenames(array(
                
'body' => 'loginRequired.html')
            );
            return 
false;
        }
        return 
true;
    }
    
    public static function 
missingResource() {
        
LayoutManager::$pageTitle 'Resource Does Not Exist';
        
LayoutManager::$template->set_filenames(array(
            
'body' => 'missingResource.html')
        );
    }
    
    public static function 
addMessage($message) {
        if( !isset(
LayoutManager::$messageContext) ) {
            
LayoutManager::$messageContext = new MessageContext();
        }
        
LayoutManager::$messageContext->addMessage($message);
    }
    
    public static function 
addError($field$message) {
        if( !isset(
LayoutManager::$messageContext) ) {
            
LayoutManager::$messageContext = new MessageContext();
        }
        
LayoutManager::$messageContext->addError($field$message);
    }
    
    public static function 
hasErrors() {
        if( !isset(
LayoutManager::$messageContext) ) {
            return 
false;
        }
        return 
LayoutManager::$messageContext->hasErrors();
    }
    
    public static function 
fatalMessage($title$message$line$file$context) {
        
LayoutManager::$template->set_filenames(array(
            
'error' => 'fatalMessage.html')
        );
        
LayoutManager::$template->assign_block_vars('fatal', array(
            
'TITLE' => $title,
            
'MESSAGE' => $message,
            
'FILE' => $file,
            
'LINE' => $line,
            
'CONTEXT' => $context
            
)
        );
        
error_log('FATAL ERROR: ' $title ' - ' $message ' in ' $file ' at line ' $line ' - ' $context);
        
LayoutManager::display('error');
        exit();
    }
    
    private static function 
setGenerics() {
        
LayoutManager::$template->assign_vars(array(
            
'U_LOGIN_REDIRECT'    =>    BASE_PATH_FROM_PHPBB LayoutManager::$redirect,
            
'U_ADD_PROJECT' => append_sid('./project.php''mode=add'),
            
'U_MANAGE_PROJECTS' => append_sid('./project.php''mode=manage'),
            
'U_SEARCH_PROJECTS' => append_sid('./project.php''mode=search'),
            
'U_IRC' => append_sid('./irc.php'),
            
'U_MAIN_PAGE' => append_sid('./'),
            
'S_USER_ID'    => LayoutManager::$user->data['user_id'],
            
'S_SESSION_ID' => LayoutManager::$user->session_id,
            
'S_YEAR' => date('Y')
            )
        );
    }
    
}
?>

Inferior Minion
ViewVC Help
Powered by ViewVC 1.0.4