From 43324b4510cf7e596c0a54652f2c63aa22945f40 Mon Sep 17 00:00:00 2001 From: konrad Date: Mon, 24 May 2010 19:07:00 +0000 Subject: [PATCH] started to port web-browser interface to new transaction format git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@474 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- Makefile.unix | 4 +- wob/event.wolf | 4 ++ www/config.php.template | 5 ++ www/inc/classes/parser.php | 4 +- www/inc/global_functions.php | 16 +++++++ www/inc/rendering/autoload.php | 14 ++++++ www/inc/rendering/event_listing.php | 15 ++++-- www/inc/rendering/order_listing.php | 8 ++-- www/inc/rendering/submit.php | 26 +++++----- www/inc/wext/event.php | 18 +++++++ www/index.php | 84 ++++++++++++++++++++-------------- www/template/de/error.html | 6 +++ 12 files changed, 144 insertions(+), 60 deletions(-) create mode 100644 www/inc/rendering/autoload.php create mode 100644 www/template/de/error.html diff --git a/Makefile.unix b/Makefile.unix index 7a77aeb..cb7157e 100644 --- a/Makefile.unix +++ b/Makefile.unix @@ -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 diff --git a/wob/event.wolf b/wob/event.wolf index af83cff..557e80d 100644 --- a/wob/event.wolf +++ b/wob/event.wolf @@ -225,6 +225,7 @@ + @@ -260,6 +261,9 @@ + + + diff --git a/www/config.php.template b/www/config.php.template index 36dc7cd..74e6798 100644 --- a/www/config.php.template +++ b/www/config.php.template @@ -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; + ?> diff --git a/www/inc/classes/parser.php b/www/inc/classes/parser.php index 6f38701..beda639 100644 --- a/www/inc/classes/parser.php +++ b/www/inc/classes/parser.php @@ -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); } diff --git a/www/inc/global_functions.php b/www/inc/global_functions.php index 3e05163..9b00bf1 100644 --- a/www/inc/global_functions.php +++ b/www/inc/global_functions.php @@ -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 index 0000000..71172b2 --- /dev/null +++ b/www/inc/rendering/autoload.php @@ -0,0 +1,14 @@ + +// +---------------------------------------------------------------------- +// | +// | Copyright: See COPYING file that comes with this distribution +// +---------------------------------------------------------------------- +// +$d=dirname(__FILE__); +$AUTOCLASS["EventRender"]=$d.'/event_listing.php'; + +?> diff --git a/www/inc/rendering/event_listing.php b/www/inc/rendering/event_listing.php index bb1e98d..1de0682 100644 --- a/www/inc/rendering/event_listing.php +++ b/www/inc/rendering/event_listing.php @@ -3,14 +3,18 @@ // | PHP Source // +---------------------------------------------------------------------- // | Copyright (C) 2007 by Peter Keller +// | (c) 2010 by Konrad Rosenbaum // +---------------------------------------------------------------------- // | // | 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 +}; ?> diff --git a/www/inc/rendering/order_listing.php b/www/inc/rendering/order_listing.php index bca8285..67f6963 100644 --- a/www/inc/rendering/order_listing.php +++ b/www/inc/rendering/order_listing.php @@ -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(); } diff --git a/www/inc/rendering/submit.php b/www/inc/rendering/submit.php index b9b29d8..a80fe41 100644 --- a/www/inc/rendering/submit.php +++ b/www/inc/rendering/submit.php @@ -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(); } diff --git a/www/inc/wext/event.php b/www/inc/wext/event.php index 9595974..9575af2 100644 --- a/www/inc/wext/event.php +++ b/www/inc/wext/event.php @@ -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 diff --git a/www/index.php b/www/index.php index 3dfaff2..1d80a91 100644 --- a/www/index.php +++ b/www/index.php @@ -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 index 0000000..1e7fdbe --- /dev/null +++ b/www/template/de/error.html @@ -0,0 +1,6 @@ +

Error

+ +@ErrorText@ + +
+Back to Index -- 1.7.2.5