started to port web-browser interface to new transaction format
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 24 May 2010 19:07:00 +0000 (19:07 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 24 May 2010 19:07:00 +0000 (19:07 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@474 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

12 files changed:
Makefile.unix
wob/event.wolf
www/config.php.template
www/inc/classes/parser.php
www/inc/global_functions.php
www/inc/rendering/autoload.php [new file with mode: 0644]
www/inc/rendering/event_listing.php
www/inc/rendering/order_listing.php
www/inc/rendering/submit.php
www/inc/wext/event.php
www/index.php
www/template/de/error.html [new file with mode: 0644]

index 7a77aeb..cb7157e 100644 (file)
@@ -55,5 +55,7 @@ clean:
        rm -rf pack/qtbase/.ctmp pack/qtbase/libqwbase* pack/qtbase/Makefile*
        rm -rf doc/source-php doc/source-cpp
 
+distclean: clean
+
 #tell Make that the rules above are symbolic:
-.PHONY: woc wob server client sdoc zip wbase
+.PHONY: woc wob server client sdoc zip wbase clean distclean
index af83cff..557e80d 100644 (file)
                <Property name="cancelreason" type="string"/>
                <Property name="amountSold" type="int"/>
                <Property name="amountReserved" type="int"/>
+               <Property name="amountFree" type="int"/>
                <Property name="description" type="string"/>
                <Property name="comment" type="string"/>
                <Property name="tax" type="int"/>
                        <Map property="amountReserved">
                                <Call lang="php" method="$data->getAmountReservedFromDB()"/>
                        </Map>
+                       <Map property="amountFree">
+                               <Call lang="php" method="$data->getcapacity()-$data->getamountSold()-$data->getamountReserved()"/>
+                       </Map>
                        <Map property="canuse">
                                <Call lang="php" method="$GLOBALS['session']->checkFlags($data->getflags())"/>
                        </Map>
index 36dc7cd..74e6798 100644 (file)
@@ -56,7 +56,12 @@ $ClientSessionTimeout=2*3600;
 
 //how long the stuff in a shopping cart is stored
 $CartTimeout=3600;
+
 //Authenticated web session timeout - how long an authenticated web session lasts
 // this should usually be a few hours (3600s per hour)
 $WebSessionTimeout=1800;
+
+//whether to show errors in the web client - usually turned off in production mode
+$WebShowErrors=false;
+
 ?>
index 6f38701..beda639 100644 (file)
@@ -27,8 +27,8 @@ class Parser
        public function __construct($fname="")
        {
                global $_SERVER;
-               $this->vars["SCRIPT"]=$_SERVER[SCRIPT_NAME];
-               $this->vars["FULLURL"]=$_SERVER[REQUEST_URI];
+               $this->vars["SCRIPT"]=$_SERVER['SCRIPT_NAME'];
+               $this->vars["FULLURL"]=$_SERVER['REQUEST_URI'];
                if($fname!="")
                        $this->parseFile($fname);
        }
index 3e05163..9b00bf1 100644 (file)
@@ -21,5 +21,21 @@ function isEmail($value)
        return ereg("^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+$", $value);
 }
 
+/**redirects the browser to index.php*/
+function redirectHome(array $query=array())
+{
+       global $_SERVER;
+       $url=$_SERVER["SCRIPT_NAME"];
+       $i=0;
+       foreach($query as $k => $v){
+               //character signalling next parameter
+               if($i)$url.="&";
+               else $url.="?";//first one...
+               $i++;
+               //append
+               $url.=urlencode($k)."=".urlencode($v);
+       }
+       Header("Location: ".$url);
+}
 
 ?>
diff --git a/www/inc/rendering/autoload.php b/www/inc/rendering/autoload.php
new file mode 100644 (file)
index 0000000..71172b2
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+// +----------------------------------------------------------------------
+// | PHP Source                                                           
+// +----------------------------------------------------------------------
+// | Copyright (C) 2010 by Konrad Rosenbaum <konrad@silmor.de>
+// +----------------------------------------------------------------------
+// |
+// | Copyright: See COPYING file that comes with this distribution
+// +----------------------------------------------------------------------
+//
+$d=dirname(__FILE__);
+$AUTOCLASS["EventRender"]=$d.'/event_listing.php';
+
+?>
index bb1e98d..1de0682 100644 (file)
@@ -3,14 +3,18 @@
 // | PHP Source                                                           
 // +----------------------------------------------------------------------
 // | Copyright (C) 2007 by Peter Keller <peter@silmor.de>
+// |           (c) 2010 by Konrad Rosenbaum <konrad@silmor.de>
 // +----------------------------------------------------------------------
 // |
 // | Copyright: See COPYING file that comes with this distribution
 // +----------------------------------------------------------------------
 //
 
+
+class EventRender {
+
 /** creates an list of events */
-function createEventList()
+public static function createEventList()
 {
        global $parser;
        
@@ -18,11 +22,10 @@ function createEventList()
        $p=new Parser("index.html");
        $list="";
        $eventTmpl=$p->getVar("EVENT");
-       $events = getAllEventsForListing();
+       $trn=WTrGetAllEvents::execute();
+       $events = $trn->resultevents();
        foreach ($events as $event) 
        {
-               $eventID = $event["eventid"];
-               $event = new Event($eventID);
                $p->setVars($event->getParserData());
                $list .= $p->parse($eventTmpl);
        }
@@ -33,7 +36,7 @@ function createEventList()
 }
 
 /** creates the details of an event */
-function createEventDetails()
+public static function createEventDetails()
 {
        global $parser;
        
@@ -71,5 +74,7 @@ function createEventDetails()
        $parser->setVAR("PAGE", $p->parseFile("eventdetails.html"));
 }
 
+//end of class
+};
 
 ?>
index bca8285..67f6963 100644 (file)
@@ -66,7 +66,7 @@ function createCustomerRegistration()
        
        // if email not available and no error, then it must be an intrusion
        if (empty($email) && !$error->exists()) {
-               header("Location:index.php");
+               redirectHome();
                exit();
        }
        
@@ -115,7 +115,7 @@ function createOrderOverview()
        // check if loggedin
        $session = new WebSession();
        if (!$session->isAuthorized()) {
-               Header("Location: index.php");
+               redirectHome();
                exit();
        }
        
@@ -202,7 +202,7 @@ function editShippingAddress()
        // check if loggedin
        $session = new WebSession();
        if (!$session->isAuthorized()) {
-               Header("Location: index.php");
+               redirectHome();
                exit();
        }
        
@@ -233,7 +233,7 @@ function editOrderComments()
        // check if loggedin
        $session = new WebSession();
        if (!$session->isAuthorized()) {
-               Header("Location: index.php");
+               redirectHome();
                exit();
        }
        
index b9b29d8..a80fe41 100644 (file)
@@ -12,9 +12,9 @@
 // forward to order login when order button in cart is pressed
 if (isset($_POST["ms_goToOrder"])) {
        if ($_POST["ms_isOrder"] == "true")
-               Header("Location: index.php?mode=orderOverview");
+               redirectHome(array("mode"=>"orderOverview"));
        else
-               Header("Location: index.php?mode=orderLogin");
+               redirectHome(array("mode"=>"orderLogin"));
        exit();
 }
 
@@ -73,7 +73,7 @@ function addEventToCart()
                                $cartTicket->changeAmount($cartTicket->getAmount() + $_POST["ms_amount"]);
                        }
                         
-                       Header("Location: index.php?mode=cart");
+                       redirectHome(array("mode"=>"cart"));
                        exit();
                }
        }
@@ -169,7 +169,7 @@ function checkOrderLogin()
                        }
                        
                        // go to user registration
-                       Header("Location: index.php?mode=customerRegistration&email=".$_POST["ms_email"]);
+                       redirectHome(array("mode"=>"customerRegistration","email"=>$_POST["ms_email"]));
                        exit();
                        
                // if user is registered
@@ -192,7 +192,7 @@ function checkOrderLogin()
                                $session->createSession($customer->getID());
                                
                                // go to order overview
-                               Header("Location: index.php?mode=orderOverview");
+                               redirectHome(array("mode"=>"orderOverview"));
                                exit();
                        } else {
                                $error->add(i18n("eMail or Password wrong"));
@@ -266,7 +266,7 @@ function registerUser()
                $session->createSession($customer->getID());
                
                // redirect to overview page
-               Header("Location: index.php?mode=orderOverview");
+               redirectHome(array("mode"=>"orderOverview"));
                exit();
        }
 }
@@ -279,7 +279,7 @@ function saveShippingAddress()
                // check if loggedin
                $session = new WebSession();
                if (!$session->isAuthorized()) {
-                       Header("Location: index.php");
+                       redirectHome();
                        exit();
                }
                
@@ -288,9 +288,9 @@ function saveShippingAddress()
                        $cart->addShippingAddress($_POST["ms_shippingAddress"]);
                }
                
-               Header("Location: index.php?mode=orderOverview");
+               redirectHome(array("mode"=>"orderOverview"));
        } else if (isset($_POST["ms_cancelShippingAddress"])) {
-               Header("Location: index.php?mode=orderOverview");
+               redirectHome(array("mode"=>"orderOverview"));
                exit();
        }
 }
@@ -303,7 +303,7 @@ function saveOrderComments()
                // check if loggedin
                $session = new WebSession();
                if (!$session->isAuthorized()) {
-                       Header("Location: index.php");
+                       redirectHome();
                        exit();
                }
                
@@ -312,9 +312,9 @@ function saveOrderComments()
                        $cart->addOrderComments($_POST["ms_comments"]);
                }
                
-               Header("Location: index.php?mode=orderOverview");
+               redirectHome(array("mode"=>"orderOverview"));
        } else if (isset($_POST["ms_cancelComments"])) {
-               Header("Location: index.php?mode=orderOverview");
+               redirectHome(array("mode"=>"orderOverview"));
                exit();
        }
 }
@@ -329,7 +329,7 @@ function orderTickets()
                // check if loggedin
                $session = new WebSession();
                if (!$session->isAuthorized()) {
-                       Header("Location: index.php");
+                       redirectHome();
                        exit();
                }
                
index 9595974..9575af2 100644 (file)
@@ -227,6 +227,24 @@ class WOEvent extends WOEventAbstract
                global $db;
                $trans->setevents(WOEvent::fromTableArrayevent(WTevent::selectFromDB("starttime<=".$db->escapeInt($start)." AND endtime>=".$db->escapeInt($end))));
        }
+       
+       /**returns the data in an array suitable for the web-page-renderer*/
+       public function getParserData()
+       {
+               $lang = LanguageManager::singleton();
+               return array(
+                       "DATE"=>$lang->getDate($this->getstart()),
+                       "TIME"=>$lang->getTime($this->getstart()),
+                       "PLACE"=>$this->getroom(),
+                       "EVENTNAME"=>$this->gettitle(),
+                       "ARTIST"=>$this->getartist()->getname(),
+                       //TODO: do something about prices
+//                     "PRICE"=>$lang->getPrice($this->getDefaultPrice()),
+                       "ID"=>$this->getid(),
+                       "DESCRIPTION"=>$this->getdescription(),
+                       "AVAILABLETICKETS"=>$this->getamountFree()
+               );;
+       }
 };
 
 ?>
\ No newline at end of file
index 3dfaff2..1d80a91 100644 (file)
@@ -4,12 +4,13 @@ include('inc/loader.php');
 include('inc/loader_nonadmin.php');
 include('inc/global_variables.php');
 include('inc/global_functions.php');
+include("inc/rendering/autoload.php");
 
 //include process script
 include('inc/rendering/submit.php');
 
 //include display scripts
-include('inc/rendering/event_listing.php');
+// include('inc/rendering/event_listing.php');
 include('inc/rendering/cart_listing.php');
 include('inc/rendering/order_listing.php');
 
@@ -19,47 +20,60 @@ if(isset($_GET["mode"])){
        $mode=$_GET["mode"];
 }
 
+//TODO: set this to something more sensible
 $lang->setLanguage("de");
 
+//set internal session to virtual "_web" user for use by transactions
 Session::setWebSession();
 
-//get page template and process it
-switch($mode){
-       case "eventDetails":
-               addEventToCart();
-               createEventDetails();
-               break;
-       case "cart":
-               deleteEventFromCart();
-               changeTicketAmountInCart();
-               createCartOverview();
-               break;
-       case "orderLogin":
-               checkOrderLogin();
-               createOrderLogin();
-               break;
-       case "customerRegistration":
-               registerUser();
-               createCustomerRegistration();
-               break;
-       case "orderOverview":
-               orderTickets();
-               createOrderOverview();
-               break;
-       case "editShippingAddress":
-               saveShippingAddress();
-               editShippingAddress();
-               break;
-       case "editOrderComments":
-               saveOrderComments();
-               editOrderComments();
-               break;
-       default:
-               createEventList();
-               break;
+try{
+       //get page template and process it
+       switch($mode){
+               case "eventDetails":
+                       addEventToCart();
+                       EventRender::createEventDetails();
+                       break;
+               case "cart":
+                       deleteEventFromCart();
+                       changeTicketAmountInCart();
+                       createCartOverview();
+                       break;
+               case "orderLogin":
+                       checkOrderLogin();
+                       createOrderLogin();
+                       break;
+               case "customerRegistration":
+                       registerUser();
+                       createCustomerRegistration();
+                       break;
+               case "orderOverview":
+                       orderTickets();
+                       createOrderOverview();
+                       break;
+               case "editShippingAddress":
+                       saveShippingAddress();
+                       editShippingAddress();
+                       break;
+               case "editOrderComments":
+                       saveOrderComments();
+                       editOrderComments();
+                       break;
+               default:
+                       EventRender::createEventList();
+                       break;
+       }
+}catch(Exception $ex){
+       error_log($ex->getMessage());
+       $p=new Parser("error.html");
+       if($WebShowErrors)
+               $p->setVar("ErrorText",$ex->getMessage());
+       else
+               $p->setVar("ErrorText","An error occured, contact the server admin for details.");
+       $parser->setVar("PAGE",$p->parseFile("error.html"));
 }
 //spit out completed page
 header("Content-Type: text/html; charset=utf-8");
 print($parser->parseFile("layout.html"));
 
+
 ?>
\ No newline at end of file
diff --git a/www/template/de/error.html b/www/template/de/error.html
new file mode 100644 (file)
index 0000000..1e7fdbe
--- /dev/null
@@ -0,0 +1,6 @@
+<h1>Error</h1>
+
+@ErrorText@
+
+<hr/>
+<a href="@SCRIPT@">Back to Index</a>