function createCartOverview()
{
global $parser;
- global $error;
- global $lang;
+ $error = ErrorManager::singleton();
+ $lang = LanguageManager::singleton();
$COOKIE_NAME = "ms_cartid";
$cart = new Cart($_COOKIE[$COOKIE_NAME]);
{
private $configFile;
private $config;
+ private static $instance;
- public function __construct($file)
+ private function __construct($file)
{
global $template;
$this->readConfig();
}
+ /** returns the instance of the Config Manager */
+ public static function singleton($file)
+ {
+ if(!self::$instance) {
+ self::$instance = new ConfigManager($file);
+ }
+
+ return self::$instance;
+ }
+
/** reads the configuration values from the file */
private function readConfig()
{
if (file_exists($this->configFile)) {
$lines = file($this->configFile);
$this->config = array();
-
+ $key = "";
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);
- }
+ if ( ereg("^msgid.*\"(.*)\"", $line, $reg) ) {
+ $key = $reg[1];
+ }
+ if ( ereg("^msgstr.*\"(.*)\"", $line, $reg) ) {
+ $value = $reg[1];
+ $this->config[$key] = $value;
}
}
}
/** returns the value of the given configuration item */
public function get($key)
{
- return $this->config[$key];
+ if ($this->hasKey($key)) {
+ return $this->config[$key];
+ } else {
+ return "";
+ }
+ }
+
+ /** checks if key exists */
+ public function hasKey($key)
+ {
+ return array_key_exists($key, $this->config);
}
/** can be used to set an alternate path to a config file */
class ErrorManager
{
private $errorMessages;
+ private static $instance;
- public function __construct()
+ private function __construct()
{
$this->errorMessages = array();
}
+ /** returns the instance of the Error Manager */
+ public static function singleton()
+ {
+ if(!self::$instance) {
+ self::$instance = new ErrorManager();
+ }
+
+ return self::$instance;
+ }
+
/** add new error message */
public function add($message)
{
/** get all error messages in an array */
public function getAll()
{
- return $this->errorMessages;
+ return $this->$errorMessages;
}
/** get all error messages formatted */
/**returns the data in an array*/
public function getParserData()
{
- global $lang;
+ $lang = LanguageManager::singleton();
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());
}
function createEventList()
{
global $parser;
+
//pass 1: get layout of single event
$p=new Parser("index.html");
$list="";
function createEventDetails()
{
global $parser;
- global $error;
+
+ $error = ErrorManager::singleton();
if (isset($_GET["event"])) {
$eventID = $_GET["event"];
// +----------------------------------------------------------------------
//
+function i18n($key)
+{
+ $lang = LanguageManager::singleton();
+
+ $translation = $lang->getValue($key);
+
+ if ($translation != "") {
+ return $translation;
+ } else {
+ return $key;
+ }
+}
+
class LanguageManager
{
- private $COOKIE_NAME = "ms_lang";
+ private static $COOKIE_NAME = "ms_lang";
+ private static $instance;
private $lang;
private $config;
+ private $templateFolder;
- /** constructor */
- public function __construct()
- {
+ /** private constructor */
+ private function __construct()
+ {
global $template;
+ $this->templateFolder = $template;
+
// check if cookie is set
- if (isset($_COOKIE[$this->COOKIE_NAME])) {
- $this->lang = $_COOKIE[$this->COOKIE_NAME];
+ if (isset($_COOKIE[self::$COOKIE_NAME])) {
+ $this->lang = $_COOKIE[self::$COOKIE_NAME];
} else {
$this->lang = substr($_SERVER[HTTP_ACCEPT_LANGUAGE],0,2);
}
- $dir = $template.$this->lang."/";
+ $this->setLanguageConfig();
+ }
+
+ /** returns the instance of the Language Manager */
+ public static function singleton()
+ {
+ if(!self::$instance) {
+ self::$instance = new LanguageManager();
+ }
+
+ return self::$instance;
+ }
+
+ /** set language */
+ public function setLanguage($language)
+ {
+ $this->lang = $language;
+ setcookie(self::$COOKIE_NAME, $language, 0);
+
+ $this->setLanguageConfig();
+ }
+
+ private function setLanguageConfig() {
+ global $template;
+
+ $dir = $this->templateFolder.$this->lang."/";
if (is_dir($dir)) {
// if language folder exists
$template = $dir;
} else {
// set default value
- $template .= "de/";
+ $template = $this->templageFolder."de/";
}
-
- $this->config = new ConfigManager("lang.conf");
- }
-
- /** set language */
- public function setLanguage($language)
- {
- $this->lang = $language;
- setcookie($this->COOKIE_NAME, $language, 0);
+ $this->config = ConfigManager::singleton("lang.po");
}
/** returns date in current language */
public function getDate($date)
{
- return date($this->config->get("DateFormat"), $date);
+ return date(i18n("d/m/Y"), $date);
}
/** returns time in current language */
public function getTime($time)
{
- return date($this->config->get("TimeFormat"), $time);
+ return date(i18n("h:i a"), $time);
}
/** returns price in current language */
public function getPrice($price)
{
- return number_format($price/100, 2, $this->config->get("DecimalPoint"), $this->config->get("ThousandSeparator"));
+ return number_format($price/100, 2, i18n("."), i18n(","));
}
- /** returns error message for specified number in current language */
- public function getErrMsg($num)
+ /** returns value for specified key in current language */
+ public function getValue($key)
{
- return $this->config->get("ERR".$num);
+ return $this->config->get($key);
}
}
/** adds an event to the cart */
function addEventToCart()
{
- global $error;
- global $lang;
+ $error = ErrorManager::singleton();
+ $lang = LanguageManager::singleton();
$COOKIE_NAME = "ms_cartid";
if (isset($_POST["ms_save"])) {
$event = new Event($_GET["event"]);
if (empty($_POST["ms_amount"])) {
- $error->add($lang->getErrMsg("100"));
+ $error->add(i18n("Please insert the number of tickets!"));
return;
} elseif (!is_numeric($_POST["ms_amount"])) {
- $error->add($lang->getErrMsg("000"));
+ $error->add(i18n("Please insert a number!"));
return;
} elseif (!$event->exists()) {
- $error->add($lang->getErrMsg("200"));
+ $error->add(i18n("The event does not exist!"));
return;
} else {
$cart = new Cart($_COOKIE[$COOKIE_NAME]);
$mode=$_GET["mode"];
}
+$lang = LanguageManager::singleton();
+$error = ErrorManager::singleton();
$parser = new Parser();
-$error = new ErrorManager();
-$lang = new LanguageManager();
//get page template and process it
switch($mode){
+++ /dev/null
-# Time
-TimeFormat = H:i
-DateFormat = d/m/Y
-
-# Currency
-DecimalPoint = .
-ThousandSeparator = ,
-
-# Error messages
-ERR000 = Bitte geben Sie eine Zahl ein!
-
-ERR100 = Bitte geben Sie eine Kartenmenge an!
-
-ERR200 = Veranstaltung nicht vorhanden!
\ No newline at end of file
--- /dev/null
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2007-11-04 17:12+0100\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: ../../inc/submit.php:22
+msgid "Please insert the number of tickets!"
+msgstr "Please insert the number of tickets!"
+
+#: ../../inc/submit.php:25
+msgid "Please insert a number!"
+msgstr "Please insert a number!"
+
+#: ../../inc/submit.php:28
+msgid "The event does not exist!"
+msgstr "The event does not exist!"
+
+#: inc/language_manager.php:60
+msgid "d/m/Y"
+msgstr "d.m.Y"
+
+#: inc/language_manager.php:66
+msgid "h:i a"
+msgstr "H:i"
+
+#: inc/language_manager.php:72
+msgid "."
+msgstr ","
+
+#: inc/language_manager.php:72
+msgid ","
+msgstr "."