From a94b0f5f61f8fb86ae29fd5935f25bbcebc0cdaa Mon Sep 17 00:00:00 2001 From: peter Date: Sun, 21 Oct 2007 17:30:48 +0000 Subject: [PATCH] - added language manager - added error manager - added some functionality to event details git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@61 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- draft/www/style.css | 4 ++- www/config.php.template | 2 +- www/inc/error.php | 59 +++++++++++++++++++++++++++++++++ www/inc/event_listing.php | 12 +++++-- www/inc/language_manager.php | 66 +++++++++++++++++++++++++++++++++++++ www/inc/parser.php | 1 + www/inc/submit.php | 27 +++++++++++++++ www/index.php | 17 +++++++--- www/template/de/definition.html | 5 +++ www/template/de/eventdetails.html | 13 +++++-- www/template/de/index.html | 2 +- 11 files changed, 194 insertions(+), 14 deletions(-) create mode 100644 www/inc/error.php create mode 100644 www/inc/language_manager.php create mode 100644 www/inc/submit.php create mode 100644 www/template/de/definition.html diff --git a/draft/www/style.css b/draft/www/style.css index cd49519..1a8924c 100644 --- a/draft/www/style.css +++ b/draft/www/style.css @@ -44,4 +44,6 @@ p {line-height:130%; margin-left:30px; margin-right:30px; margin-top:15px; mar .ms_AlignRight {text-align: right;} .ms_Bold {font-weight: bold;} -.ms_ButtonArea {margin-top: 10px} \ No newline at end of file +.ms_ButtonArea {margin-top: 10px} + +.ms_Error {color: red; margin-top: 20px;} \ No newline at end of file diff --git a/www/config.php.template b/www/config.php.template index ac5e0e3..d0b7a9e 100644 --- a/www/config.php.template +++ b/www/config.php.template @@ -5,7 +5,7 @@ // see the documentation on how to make settings //Template directory -$template="./template/de/"; +$template="./template/"; /////////// diff --git a/www/inc/error.php b/www/inc/error.php new file mode 100644 index 0000000..914f0b2 --- /dev/null +++ b/www/inc/error.php @@ -0,0 +1,59 @@ + +// +---------------------------------------------------------------------- +// | +// | Copyright: See COPYING file that comes with this distribution +// +---------------------------------------------------------------------- +// + +class ErrorManager +{ + private $errorMessages; + + public function __construct() + { + $this->errorMessages = array(); + } + + /** add new error message */ + public function add($message) + { + $this->errorMessages[] = $message; + } + + /** get all error messages in an array */ + public function getAll() + { + return $this->errorMessages; + } + + /** get all error messages formatted */ + public function getAllFormatted() + { + $p = new Parser("definition.html"); + $messages = ""; + + foreach ($this->errorMessages as $message) + { + $errorTmpl = $p->getVar("ERROR"); + $p->setVar("MESSAGE", $message); + $messages .= $p->parse($errorTmpl); + } + return $messages; + } + + /** returns true if errors exist */ + public function exists() + { + if (count($this->errorMessages) > 0) { + return true; + } + else { + return false; + } + } +} +?> \ No newline at end of file diff --git a/www/inc/event_listing.php b/www/inc/event_listing.php index 22b306c..ccb6f89 100644 --- a/www/inc/event_listing.php +++ b/www/inc/event_listing.php @@ -33,8 +33,8 @@ function createEventList() function createEventDetails() { global $parser; - global $_GET; - + global $error; + if (isset($_GET["event"])) { $eventID = $_GET["event"]; } @@ -53,8 +53,14 @@ function createEventDetails() $p->setVars($event->getParserData()); $details = $p->parse($eventTmpl); $p->setVar("EVENTDETAILS",$details); - $p->setVar("fieldAMOUNT", ""); + $p->setVar("fieldAMOUNT", "ms_amount"); $p->setVar("buttonSAVE", "ms_save"); + + // set error message + if ($error->exists()) { + $p->setVar("ERROR", "true"); + $p->setVar("ERRORMESSAGE", $error->getAllFormatted()); + } // create page $parser->setVAR("PAGE", $p->parseFile("eventdetails.html")); diff --git a/www/inc/language_manager.php b/www/inc/language_manager.php new file mode 100644 index 0000000..5956e03 --- /dev/null +++ b/www/inc/language_manager.php @@ -0,0 +1,66 @@ + +// +---------------------------------------------------------------------- +// | +// | Copyright: See COPYING file that comes with this distribution +// +---------------------------------------------------------------------- +// + +class LanguageManager +{ + private $COOKIE_NAME = "ms_lang"; + private $lang; + + /** constructor */ + public function __construct() + { + global $template; + + // check if cookie is set + if (isset($_COOKIE[$this->COOKIE_NAME])) { + $this->lang = $_COOKIE[$this->COOKIE_NAME]; + } else { + $this->lang = substr($_SERVER[HTTP_ACCEPT_LANGUAGE],0,2); + } + + $dir = $template.$this->lang."/"; + + if (is_dir($dir)) { + // if language folder exists + $template = $dir; + } else { + // set default value + $template .= "de/"; + } + } + + /** set language */ + public function setLanguage($language) + { + $this->lang = $language; + setcookie($this->COOKIE_NAME, $language, 0); + } + + /** get date in current language */ + public function getDate($date) + { + + } + + /** get time in current language */ + public function getTime($time) + { + + } + + /** get price in current language */ + public function getPrice($price) + { + + } +} + +?> diff --git a/www/inc/parser.php b/www/inc/parser.php index 4b92512..6f38701 100644 --- a/www/inc/parser.php +++ b/www/inc/parser.php @@ -28,6 +28,7 @@ class Parser { global $_SERVER; $this->vars["SCRIPT"]=$_SERVER[SCRIPT_NAME]; + $this->vars["FULLURL"]=$_SERVER[REQUEST_URI]; if($fname!="") $this->parseFile($fname); } diff --git a/www/inc/submit.php b/www/inc/submit.php new file mode 100644 index 0000000..272a2ab --- /dev/null +++ b/www/inc/submit.php @@ -0,0 +1,27 @@ + +// +---------------------------------------------------------------------- +// | +// | Copyright: See COPYING file that comes with this distribution +// +---------------------------------------------------------------------- +// + +/** adds an event to the cart */ +function addEventToCart() +{ + global $error; + + if (isset($_POST["ms_save"])) { + if (empty($_POST["ms_amount"])) { + $error->add("Bitte geben Sie eine Kartenmenge an!"); + return; + } else { + // TODO: add to cart + Header("Location: index.php"); + } + } +} +?> diff --git a/www/index.php b/www/index.php index fd3ac43..eb72b5f 100644 --- a/www/index.php +++ b/www/index.php @@ -2,23 +2,30 @@ //basics include('inc/loader.php'); include('inc/loader_nonadmin.php'); +include('inc/parser.php'); +include('inc/error.php'); +include('inc/language_manager.php'); + +//include +include('inc/submit.php'); + //include display scripts include('inc/event_listing.php'); -include('inc/parser.php'); //set common basics $mode="index"; if(isset($_GET["mode"])){ $mode=$_GET["mode"]; } -$parser=new Parser(); + +$parser = new Parser(); +$error = new ErrorManager(); +$lang = new LanguageManager(); //get page template and process it switch($mode){ - case "reserve": - createreservation(); - break; case "eventDetails": + addEventToCart(); createEventDetails(); break; default: diff --git a/www/template/de/definition.html b/www/template/de/definition.html new file mode 100644 index 0000000..0b80387 --- /dev/null +++ b/www/template/de/definition.html @@ -0,0 +1,5 @@ +#set:ERROR: +
+@MESSAGE@ +
+#endset \ No newline at end of file diff --git a/www/template/de/eventdetails.html b/www/template/de/eventdetails.html index f81d391..b462bf3 100644 --- a/www/template/de/eventdetails.html +++ b/www/template/de/eventdetails.html @@ -1,6 +1,6 @@

Veranstaltungsdetails

-
+ @EVENTDETAILS@ @@ -36,13 +36,20 @@
-@fieldAMOUNT@ +
#endset
- +
+ +#if:ERROR==true +
+@ERRORMESSAGE@ +
+#endif + \ No newline at end of file diff --git a/www/template/de/index.html b/www/template/de/index.html index c13bef8..6d331e6 100644 --- a/www/template/de/index.html +++ b/www/template/de/index.html @@ -19,4 +19,4 @@ Kartenpreis: @PRICE@ EUR
Info Bestellen

-#endset \ No newline at end of file +#endset -- 1.7.2.5