- added language manager
authorpeter <peter@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 21 Oct 2007 17:30:48 +0000 (17:30 +0000)
committerpeter <peter@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 21 Oct 2007 17:30:48 +0000 (17:30 +0000)
- 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
www/config.php.template
www/inc/error.php [new file with mode: 0644]
www/inc/event_listing.php
www/inc/language_manager.php [new file with mode: 0644]
www/inc/parser.php
www/inc/submit.php [new file with mode: 0644]
www/index.php
www/template/de/definition.html [new file with mode: 0644]
www/template/de/eventdetails.html
www/template/de/index.html

index cd49519..1a8924c 100644 (file)
@@ -44,4 +44,6 @@ p                     {line-height:130%; margin-left:30px; margin-right:30px; margin-top:15px; mar
 .ms_AlignRight         {text-align: right;}\r
 .ms_Bold               {font-weight: bold;}\r
 \r
-.ms_ButtonArea         {margin-top: 10px}
\ No newline at end of file
+.ms_ButtonArea         {margin-top: 10px}\r
+\r
+.ms_Error              {color: red; margin-top: 20px;}
\ No newline at end of file
index ac5e0e3..d0b7a9e 100644 (file)
@@ -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 (file)
index 0000000..914f0b2
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+// +----------------------------------------------------------------------
+// | PHP Source                                                           
+// +----------------------------------------------------------------------
+// | Copyright (C) 2007 by Peter keller <peter@silmor.de>
+// +----------------------------------------------------------------------
+// |
+// | 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
index 22b306c..ccb6f89 100644 (file)
@@ -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", "<input type='text' id='ms_textfield_amount' name='ms_amount' size='2' maxlength='2'/>");
+       $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 (file)
index 0000000..5956e03
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+// +----------------------------------------------------------------------
+// | PHP Source                                                           
+// +----------------------------------------------------------------------
+// | Copyright (C) 2007 by Peter keller <peter@silmor.de>
+// +----------------------------------------------------------------------
+// |
+// | 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)
+       {
+       
+       }
+}
+
+?>
index 4b92512..6f38701 100644 (file)
@@ -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 (file)
index 0000000..272a2ab
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+// +----------------------------------------------------------------------
+// | PHP Source                                                           
+// +----------------------------------------------------------------------
+// | Copyright (C) 2007 by Peter keller <peter@silmor.de>
+// +----------------------------------------------------------------------
+// |
+// | 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");
+               }
+       }
+}
+?>
index fd3ac43..eb72b5f 100644 (file)
@@ -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 (file)
index 0000000..0b80387
--- /dev/null
@@ -0,0 +1,5 @@
+#set:ERROR:
+<div>
+@MESSAGE@
+</div>
+#endset
\ No newline at end of file
index f81d391..b462bf3 100644 (file)
@@ -1,6 +1,6 @@
 <h1>Veranstaltungsdetails</h1>
 <div id="ms_form">
-<form action="." method="POST">
+<form action="@FULLURL@" method="POST">
 
 @EVENTDETAILS@
 
 </div>
 <div class="ms_FormRow">
 <label for="ms_textfield_amount">Kartenanzahl:</label>
-@fieldAMOUNT@
+<input type="text" id="ms_textfield_amount" name="@fieldAMOUNT@" size="2" maxlength="2"/>
 </div>
 </fieldset>
 #endset
 
 <div class="ms_ButtonArea">
-<input type="button" id="ms_button_save" name="@buttonSAVE@" value="In den Warenkorb" />
+<input type="submit" id="ms_button_save" name="@buttonSAVE@" value="In den Warenkorb" />
 </div>
 </form>
+
+#if:ERROR==true
+<div class="ms_ErrorArea">
+@ERRORMESSAGE@
+</div>
+#endif
+
 </div>
\ No newline at end of file
index c13bef8..6d331e6 100644 (file)
@@ -19,4 +19,4 @@ Kartenpreis: @PRICE@ EUR<br/>
 <a href="@SCRIPT@?mode=info&event=@ID@">Info</a>
 <a href="@SCRIPT@?mode=eventDetails&event=@ID@">Bestellen</a>
 </p>
-#endset
\ No newline at end of file
+#endset