Code

9eeda233ac613ce7f8582dc6533b4e90e067585d
[gosa.git] / include / class_ViewportController.inc
1 <?php
3 /* Provide Smarty capabilities */
4 require("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= 'default';
31   private $smarty;
32   private $language= '';
33   private $timezone;
35   /*! \brief ViewportController constructor
37     The ViewportController loads the 'display' config option from the
38     ConfigRegistry and acts depending on these settings.
39    */
40         public function __construct(){
42     /* Do language setup during initialization, so we can really be sure
43        that most stuff gets translated in the beginning. */
44     $this->languageSetup();
46     /* Get configuration instance */
47     $config= Registry::getInstance("ConfigManager");
48     $config->setSection('display');
50     /* Set timezone */
51     $this->timezone= $config->getValue('timezone', 'GMT');
52     if (!date_default_timezone_set($this->timezone)){
53       throw new ViewportControllerException(_("Timezone '%s' is not valid!"), $this->timezone);
54     }
56     /* Do Smarty setup */
57     $this->Smarty= new Smarty;
58     $this->Smarty->template_dir= BASE_DIR.'/templates/';
59     $this->Smarty->caching= $config->getValue('cache-templates', FALSE);
60     $this->Smarty->php_handling= SMARTY_PHP_REMOVE;
62     /* Set template compile directory */
63     $this->Smarty->compile_dir= $config->getValue('compile-directory', '/var/spool/gosa');
65     /* Check if our template directory is accessible */
66     if (!(is_dir($this->Smarty->compile_dir) && is_writable($this->Smarty->compile_dir))){
67       throw new ViewportControllerException(sprintf(_("Directory '%s' specified as compile-directory is not accessible!"), $this->Smarty->compile_dir));
68     }
70     /* Check for old files in compile directory */
71     $this->cleanSmartyCompileDir();
72   }
75   private function cleanSmartyCompileDir() {
76     #TODO: Clean compile dir
77   }
80   private function languageSetup() {
82     /* Get the browser language if */
83     $lang= Utils::getBrowserLanguage();
84     if ($this->language != $lang){
85       #TODO: Emit EventObject for changed language
86       $this->language= $lang;
87     }
89     /* Get the browser language */
90     putenv("LANGUAGE=");
91     putenv("LANG=$this->language");
92     setlocale(LC_ALL, $this->language);
94     /* Set the text domain as 'messages' */
95     $domain= 'messages';
96     bindtextdomain($domain, BASE_DIR.'/locale');
97     textdomain($domain);
99     /* Set global Smarty variable to language and */
100     $GLOBALS['t_language']= $this->language;
101     $GLOBALS['t_gettext_message_dir']= BASE_DIR.'/locale/';
102   }
105   public function getSmartyInstance() {
106     return $this->Smarty;
107   }
110   public function render() {
111     echo "Render called\n";
112   }
116 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
117 ?>