- added new methods for time, date, price to language manager
authorpeter <peter@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Tue, 23 Oct 2007 09:59:59 +0000 (09:59 +0000)
committerpeter <peter@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Tue, 23 Oct 2007 09:59:59 +0000 (09:59 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@64 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

www/inc/config_manager.php [new file with mode: 0644]
www/inc/event.php
www/inc/language_manager.php
www/inc/loader_nonadmin.php
www/template/de/lang.conf [new file with mode: 0644]

diff --git a/www/inc/config_manager.php b/www/inc/config_manager.php
new file mode 100644 (file)
index 0000000..0e21f38
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+// +----------------------------------------------------------------------
+// | PHP Source                                                           
+// +----------------------------------------------------------------------
+// | Copyright (C) 2007 by Peter keller <peter@silmor.de>
+// +----------------------------------------------------------------------
+// |
+// | Copyright: See COPYING file that comes with this distribution
+// +----------------------------------------------------------------------
+//
+
+class ConfigManager
+{
+       private $configFile;
+       private $config;
+       
+       public function __construct($file = "lang.conf")
+       {
+               global $template;
+               
+               $this->configFile = $template.$file;
+               $this->readConfig();
+       }
+       
+       /** reads the configuration values from the file */
+       private function readConfig()
+       {
+               // check if file really exists
+               if (file_exists($this->configFile)) {
+                       $lines = file($this->configFile);
+                       $this->config = array();
+       
+                       foreach ($lines as $line_num => $line) {
+                               # Comment?
+                               if ( !preg_match("/^#.*/", $line) ) {
+                                       # Contains non-whitespace?
+                                       if ( preg_match("/\S/", $line) ) {
+                                               list( $key, $value ) = explode( "=", trim( $line ), 2);
+                                               $this->config[trim($key)] = trim($value);
+                                       }
+                               }
+                       }
+               }
+       }
+       
+       /** returns the value of the given configuration item */
+       public function get($key)
+       {
+               return $this->config[$key];
+       }
+       
+       /** can be used to set an alternate path to a config file */
+       public function setConfigFile($file)
+       {
+               $this->configFile = $file;
+               $this->readConfig();
+       }
+}
+
+?>
index 660ae61..14f9f2e 100644 (file)
@@ -116,25 +116,12 @@ class Event
        public function getDescription(){return $this->description;}
        /**returns the reason why the event is cancelled if isCancelled() returns true*/
        public function getCancelReason(){return $this->cancelreason;}
-       /**returns the date of the event*/
-       public function getStDate()
-       {
-               return date("d.m.Y", $this->getStartTime());
-       }
-       /**returns the time of the event*/
-       public function getStTime()
-       {
-               return date("H:i", $this->getStartTime());
-       }
-       /**returns the price in euro*/
-       public function getPriceInEuro()
-       {
-               return number_format($this->getDefaultPrice()/100, 2, ",", ".");
-       }
        /**returns the data in an array*/
        public function getParserData()
        {
-               return array("DATE"=>$this->getStDate(), "TIME"=>$this->getStTime(), "PLACE"=>$this->getRoomId(), "EVENTNAME"=>$this->getTitle(), "ARTIST"=>$this->getArtist(),"PRICE"=>$this->getPriceInEuro(), "ID"=>$this->getEventId(), "DESCRIPTION"=>$this->getDescription());
+               global $lang;
+       
+               return array("DATE"=>$lang->getDate($this->getStartTime()), "TIME"=>$lang->getTime($this->getStartTime()), "PLACE"=>$this->getRoomId(), "EVENTNAME"=>$this->getTitle(), "ARTIST"=>$this->getArtist(),"PRICE"=>$lang->getPrice($this->getDefaultPrice()), "ID"=>$this->getEventId(), "DESCRIPTION"=>$this->getDescription());
        }
 };
 
index 5956e03..6db60e8 100644 (file)
@@ -13,6 +13,7 @@ class LanguageManager
 {
        private $COOKIE_NAME = "ms_lang"; 
        private $lang;
+       private $config;
        
        /** constructor */
        public function __construct()
@@ -35,6 +36,8 @@ class LanguageManager
                        // set default value
                        $template .= "de/";
                }
+               
+               $this->config = new ConfigManager("lang.conf");
        }
        
        /** set language */
@@ -44,22 +47,28 @@ class LanguageManager
                setcookie($this->COOKIE_NAME, $language, 0);
        }
        
-       /** get date in current language */
+       /** returns date in current language */
        public function getDate($date)
        {
-               
+               return date($this->config->get("DateFormat"), $date);
        }
        
-       /** get time in current language */
+       /** returns time in current language */
        public function getTime($time)
        {
-       
+               return date($this->config->get("TimeFormat"), $time);
        }
        
-       /** get price in current language */
+       /** returns price in current language */
        public function getPrice($price)
        {
+               return number_format($price/100, 2, $this->config->get("DecimalPoint"), $this->config->get("ThousandSeparator"));
+       }
        
+       /** returns error message for specified number in current language */
+       public function getErrMsg($num)
+       {
+               return $this->config->get("ERR".$num);
        }
 }
 
index 7ae349c..13e48b1 100644 (file)
@@ -8,8 +8,9 @@ include('./inc/room.php');
 include("./inc/random.php");
 include("./inc/order.php");
 include("./inc/cart.php");
-include('inc/error.php');
-include('inc/language_manager.php');
-include('inc/parser.php');
+include('./inc/error.php');
+include('./inc/language_manager.php');
+include('./inc/parser.php');
+include('./inc/config_manager.php')
 
 ?>
\ No newline at end of file
diff --git a/www/template/de/lang.conf b/www/template/de/lang.conf
new file mode 100644 (file)
index 0000000..f3b6c9a
--- /dev/null
@@ -0,0 +1,10 @@
+# Time
+TimeFormat = H:i 
+DateFormat = d/m/Y
+
+# Currency
+DecimalPoint = .
+ThousandSeparator = ,
+
+# Error messages
+ERR001 = Test
\ No newline at end of file