From 1dc917bb05b79dd2676ecbdf6188119d6b448d63 Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 30 Sep 2007 09:18:28 +0000 Subject: [PATCH] *added tables for shopping cart *added getallevents transaction git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@40 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- www/config.php.template | 7 +++++++ www/inc/db_mysql.php | 4 +++- www/inc/db_scheme.php | 27 ++++++++++++++++++++++++++- www/inc/event.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ www/loader_nonadmin.php | 2 ++ www/machine.php | 6 ++++++ 6 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 www/inc/event.php diff --git a/www/config.php.template b/www/config.php.template index c1727bb..ac5e0e3 100644 --- a/www/config.php.template +++ b/www/config.php.template @@ -48,4 +48,11 @@ $ClientAuthTimeout=300; //Authenticated session timeout - how long an authenticated session lasts // this should usually be a few hours (3600s per hour) $ClientSessionTimeout=2*3600; + + +/////////// +//Web-Client Configuration + +//how long the stuff in a shopping cart is stored +$CartTimeout=3600; ?> \ No newline at end of file diff --git a/www/inc/db_mysql.php b/www/inc/db_mysql.php index b07619d..56e3141 100644 --- a/www/inc/db_mysql.php +++ b/www/inc/db_mysql.php @@ -71,7 +71,9 @@ class MysqlEngine extends DbEngine public function select($table,$cols,$where) { - $res=mysql_query("SELECT $cols FROM ".$this->tableName($table)." WHERE ".$where); + $query="SELECT $cols FROM ".$this->tableName($table); + if($where!="")$query.=" WHERE ".$where; + $res=mysql_query($query); if($res===false)return false; $nr=mysql_num_rows($res); $ret=array(); diff --git a/www/inc/db_scheme.php b/www/inc/db_scheme.php index ea5b3fa..3b4e3f4 100644 --- a/www/inc/db_scheme.php +++ b/www/inc/db_scheme.php @@ -95,7 +95,10 @@ class DbScheme { "ordertime" => array("int32","notnull"), "senttime" => array("int32"), //comments made on web form (eg. "urgently needed for dads birthday") - "comments" => array("text") + "comments" => array("text"), + //how much has been paid already (including used vouchers) + //this is for comparison with the price fields in ticket and voucher tables + "amountpaid" => array("int32") ); //tickets $this->scheme["ticket"]=array( @@ -123,6 +126,28 @@ class DbScheme { //remaining value in cents "value" => array("int32","notnull") ); + + //shopping cart + $this->scheme["cart"]=array( + //the cookie for this cart + "cartid" => array("string:32","primarykey"), + //when the cart expires + "timeout" => array("int32","notnull") + ); + //buying tickets + $this->scheme["cart_ticket"]=array( + "ctid" => array("int64","primarykey"), + //tickets in the cart + "eventid" => array("int32","foreignkey:event:eventid"), + "amount" => array("int32","notnull"), + ); + //buying vouchers + $this->scheme["cart_voucher"]=array( + "cvid" => array("int64","primarykey"), + //voucher value + "value" => array("int32","notnull") + ); + } /**return the tables to be created in order*/ diff --git a/www/inc/event.php b/www/inc/event.php new file mode 100644 index 0000000..3348f02 --- /dev/null +++ b/www/inc/event.php @@ -0,0 +1,46 @@ +, (C) 2007 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + + +/**Get an overview of all events: +returns an array of array("eventid"=>int, "title"=>string,"starttime"=>int)*/ +function getAllEvents() +{ + global $db; + return $db->select("event","eventid,title,starttime",""); +} + +/**Machine-wrapper for getAllEvents() */ +function getAllEventsXml() +{ + $all=getAllEvents(); + if($all===false){ + header("X-MagicSmoke-Status: Error"); + echo "Database Error."; + return; + } + header("X-MagicSmoke-Status: Ok"); + $xml=new DOMDocument; + $root=$xml->createElement("EventList"); + if(count($all)>0) + foreach($all as $k => $ev){ + $nod=$xml->createElement("Event",$ev["title"]); + $nod->setAttribute("id",$ev["eventid"]); + $nod->setAttribute("start",$ev["starttime"]); + $root->appendChild($nod); + } + $xml->appendChild($root); + echo $xml->saveXml(); +} + +?> \ No newline at end of file diff --git a/www/loader_nonadmin.php b/www/loader_nonadmin.php index a22f454..2b2af5f 100644 --- a/www/loader_nonadmin.php +++ b/www/loader_nonadmin.php @@ -2,4 +2,6 @@ //check database if(!$db->canUseDb()) die("Database is not correctly configured. Giving up."); +//load class-files +include('inc/event.php'); ?> \ No newline at end of file diff --git a/www/machine.php b/www/machine.php index 433a03c..0934ce6 100644 --- a/www/machine.php +++ b/www/machine.php @@ -100,6 +100,12 @@ if(!$session->canExecute($SMOKEREQUEST)){ die("You do not have the right to execute this transaction."); } +//get a list of events +if($SMOKEREQUEST=="geteventlist"){ + getAllEventsXml(); + exit(); +} + //EOF header("X-MagicSmoke-Status: Error"); die("Internal Error: unknown command, hiccup in code structure."); -- 1.7.2.5