Code

Updated paths
[gosa.git] / include / core / class_ViewportController.inc
1 <?php
3 /* Provide Smarty capabilities */
4 require(BASE_DIR."/include/smarty/Smarty.class.php");
6 /*! \brief   Exception implementation for ViewPortController
7     \author  Cajus Pollmeier <pollmeier@gonicus.de>
8     \version 1.00
9     \date    2007/11/02
11     This class handles the exceptions occuring in ObjectList.
12  */
13 class ViewportControllerException extends Exception {
14         public function __construct($message, $code = 0) {
15                 parent::__construct($message, $code);
16         }
17 }
18  
20 /*! \brief   Implementation for rendering the main view
21     \author  Cajus Pollmeier <pollmeier@gonicus.de>
22     \version 1.00
23     \date    2007/11/02
25     The class ViewportController handles the rendering of the main view port,
26     manages the location for images and templates based on themes.
27  */
28 class ViewportController {
30   private $theme;
31   private $smarty;
32   private $language= '';
33   private $timezone;
34   private $mainTemplate= 'main';
36   /*! \brief ViewportController constructor
38     The ViewportController loads the 'display' config option from the
39     ConfigRegistry and acts depending on these settings.
40    */
41         public function __construct(){
43     /* Do language setup during initialization, so we can really be sure
44        that most stuff gets translated in the beginning. */
45     $this->languageSetup();
47     /* Get configuration instance */
48     $config= Registry::getInstance("ConfigManager");
49     $config->setSection('display');
51     /* Set timezone */
52     $this->timezone= $config->getValue('timezone', 'GMT');
53     if (!date_default_timezone_set($this->timezone)){
54       throw new ViewportControllerException(_("Timezone '%s' is not valid!"), $this->timezone);
55     }
57     /* Do Smarty setup */
58     $this->Smarty= new Smarty;
59     $this->Smarty->template_dir= BASE_DIR.'/templates/';
60     $this->Smarty->caching= $config->getValue('cache-templates', FALSE);
61     $this->Smarty->php_handling= SMARTY_PHP_REMOVE;
63     /* Set template compile directory */
64     $this->Smarty->compile_dir= $config->getValue('compile-directory', '/var/spool/gosa');
66     /* Check if our template directory is accessible */
67     if (!(is_dir($this->Smarty->compile_dir) && is_writable($this->Smarty->compile_dir))){
68       throw new ViewportControllerException(sprintf(_("Directory '%s' specified as compile-directory is not accessible!"), $this->Smarty->compile_dir));
69     }
71     /* Get more display settings */
72     $this->theme= $config->getValue('theme', 'default');
73     
74     /* Check for old files in compile directory */
75     $this->cleanSmartyCompileDir();
76   }
79   private function cleanSmartyCompileDir() {
80     #TODO: Clean compile dir
81   }
84   private function languageSetup() {
86     /* Get the browser language if */
87     $lang= Utils::getBrowserLanguage();
88     if ($this->language != $lang){
89       #TODO: Emit EventObject for changed language
90       $this->language= $lang;
91     }
93     /* Get the browser language */
94     putenv("LANGUAGE=");
95     putenv("LANG=$this->language");
96     setlocale(LC_ALL, $this->language);
98     /* Set the text domain as 'messages' */
99     $domain= 'messages';
100     bindtextdomain($domain, BASE_DIR.'/locale');
101     textdomain($domain);
103     /* Set global Smarty variable to language and */
104     $GLOBALS['t_language']= $this->language;
105     $GLOBALS['t_gettext_message_dir']= BASE_DIR.'/locale/';
106   }
109   public function getSmartyInstance() {
110     return $this->Smarty;
111   }
114   public function getTemplatePath($name) {
115         return "horst";
116   }
117   
118   
119   public function render() {
120     #Header generator from template
121     echo $this->getTemplatePath('main');
122   }
126 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
127 ?>