* @copyright 2005 by gERD Schaufelberger * @package wombat * @subpackage admin */ /** * admin interface * * @abstract * @version 1.0.1 * @package wombat * @subpackage Admin */ class wbAdminApp { /** * whether this is a custom application * @var bool */ var $_appCustom = false; /** * 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(); /** * locale configuratoin * @access protected * @var array $_lang */ var $_lang = array(); /** * visit id - session id for each visit * * Used by logging mechanism to track useers even if their session-id has changed (e.g. during log in) * * @var string $_visitId */ var $_visitId = ''; /** * messages * @access private * @var array $_msg */ var $_msg = array(); /** * constructor * * @access public */ function __construct() { if( !$this->_appCustom ) { $this->_tmpl =& wbFactory::singleton( 'patTemplate' ); return; } $params = array( 'tmplDir' => wbFactory::getParam( 'baseDir' ) . '/templates/admin' ); $this->_tmpl =& wbFactory::create( 'patTemplate', $params ); } /** * 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 languration values * * @access public * @return boolean true on success */ function setLang( &$lang ) { $this->_lang =& $lang; return true; } /** * set visit session id * * @access public * @return boolean true on success */ function setVisitId( $id ) { $this->_visitId = $id; 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, $app = true ) { $switchRoot = false; if( $app ) { $name = $this->_appName . '/' . $name; } else if( $this->_appCustom ) { $switchRoot = true; $root = wbFactory::getParam( 'systemDir' ) . '/'. wbFactory::getParam( 'adminDir' ) . '/templates'; $this->_tmpl->setRoot( $root ); } $this->_tmpl->readTemplatesFromInput( $name . '.tmpl' ); if( $switchRoot ) { $root = wbFactory::getParam( 'baseDir' ) . '/templates/admin'; $this->_tmpl->setRoot( $root ); } 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; } /** * get form errors from form and translate them to template * * @access private * @param object $form patForm object * @return boolean true */ function _displayFormErrors( &$form ) { $errors = $form->getValidationErrors(); if( empty( $errors ) ) { return true; } $errorRows = array(); foreach( $errors as $elName => $elErrors ) { $row = array(); $el =& $form->getElement( $elName ); $atts = $el->getAttributes(); foreach( $atts as $key => $att ) { if( is_array( $att ) ) { continue; } $row['field_'.$key] = $att; } foreach( $elErrors as $err ) { foreach( $err as $key => $value ) { $row['error_' . $key] = $value; } } array_push( $errorRows, $row ); } $this->_tmpl->addRows( 'formErrors_entry', $errorRows ); $this->_tmpl->setAttribute( 'formErrors' , 'visibility', 'visible' ); return true; } function addGlobalTemplateVars( $globals, $prefix = null ) { if( $this->_appCustom ) { $this->_tmpl->addGlobalVars( $globals, $prefix ); } return true; } } ?>