* @copyright 2005 by gERD Schaufelberger * @package wombat * @subpackage admin */ /** * admin interface * * @abstract * @version 0.1.0 * @package wombat * @subpackage Admin */ class wbAdminApp { /** * name of this application * @var string $appName */ var $_appName; /** * fullscreen? * @var boolean $_fullScreen */ var $_fullScreen = false; /** * patTemplate object * @var object $_tmpl */ var $_tmpl = null; /** * request variables * @access protected * @var array $_request */ var $_request = array(); /** * default values for request variables * @access protected * @var array $_requestDefaults * @see $_request */ var $_requestDefaults = array(); /** * config * @access protected * @var array $_config */ var $_config = array(); /** * messages * @access private * @var array $_msg */ var $_msg = array(); /** * constructor * * @access public */ function __construct() { $this->_tmpl =& wbFactory::singleton( 'patTemplate' ); } /** * constructor wrapper for PHP4 * * @access public * @see __construct() */ function wbAdminApp() { $this->__construct(); } /** * set configuration values * * @access public * @return boolean true on success */ function setConfig( &$config ) { $this->_config =& $config; return true; } /** * set request variables * * @access public * @param array $request * @return boolean $result true on success */ function setRequest( &$request ) { $this->_request =& $request; foreach( $this->_requestDefaults as $key => $value ) { if( !isset( $this->_request[$key] ) ) { $this->_request[$key] = $value; } } return true; } /** * run application * * default behaviour: display template. If path is empty 'index.tmpl' will be used * * @access public * @param array $path * @return boolean true on success */ function process( $path ) { if( empty( $path ) ) { $tmpl = 'index'; } else { $tmpl = strtolower( $path[0] ); } $this->_loadTemplates( $tmpl ); return true; } /** * recieve html * * Select templata for fullscreen and normal mode. * * @access public * @return sting $html parsed templates */ function getHtml() { if( $this->_fullScreen ) { return $this->_tmpl->getParsedTemplate( 'page' ); } return $this->_tmpl->getParsedTemplate( 'wbAdminApp_' . $this->_appName ); } /** * recieve submenu items * * most applications will return "null". Then there is no submenu * Also this function will only be called, if there is no submenu definition * in app/MyApplication.xml * * @access public * @return mixed $submenu */ function getMenu() { return null; } /** * ask whether application runs in fullscreen mode * * @final * @access public * @return boolean true if fullscreen mode is set */ function isFullscreen() { return $this->_fullScreen; } /** * recieve collected messages * * @final * @access public * @return array $msg */ function getMsg() { return $this->_msg; } /** * add user message * * @final * @access protected * @param string $msg message template with optional placeholders * @return boolean $result true on success */ function _addMsg( $msg, $data = array()) { foreach( $data as $key => $value ) { $msg = str_replace( '[' . strtoupper( $key ) . ']', $value, $msg ); } array_push( $this->_msg, $msg ); return true; } /** * load templates * - wrapper for patTemplate-readTemplateFromInput() * * @final * @access protected * @param string $name name of template file, without trailing '.tmpl' * @return boolean $result true on success */ function _loadTemplates( $name ) { $this->_tmpl->readTemplatesFromInput( $this->_appName . '/' . $name . '.tmpl' ); return true; } /** * checkReload * * @access protected * @return boolean $result true on reload */ function _checkReload() { $sess =& wbFactory::singleton( 'patSession' ); // create checksum from request vars $req = $this->_request; ksort( $req ); $req = serialize( $req ); $newChecksum = md5( $req ); // get saved checksum $checksum = $sess->get( 'wbAdminApp_reload' ); if( $newChecksum == $checksum ) { return true; } $sess->set( 'wbAdminApp_reload', $newChecksum ); return false; } } ?>