<Wolf>
<Table name="cart">
<!--the cookie for this cart-->
- <Column name="cartid" type="string:32" primarykey="yes"/>
+ <Column name="cartid" type="string:32" primarykey="yes">
+ <Call lang="php" method="WebCart::getNewCartId()"/>
+ </Column>
<!--when the cart expires-->
<Column name="timeout" type="int64" notnull="yes"/>
<!--shipping address during order process-->
/**return a new Code-39 capable ID; length is the amount of characters*/
function getCode39ID($length,$range=RND_ANYRANGE)
{
- $c39="23456789ABCDEFGHJKLMNPRSTUVWXYZ+";
+ $c39="123456789ABCDEFGHJKLMNPQRSTUVWXYZ";
$rnd=getRandom($length*8);
$ret="";
for($i=0;$i<$length;$i++){
//
$d=dirname(__FILE__);
wob_autoclass("EventRender",$d.'/event_listing.php');
+wob_autoclass("WebCart",$d.'/cart_listing.php');
?>
// +----------------------------------------------------------------------
//
+/** helper class wrapping Web Cart handling */
+class WebCart{
+static private $cartid=false;
+
+/**contains the name of the cookie and the HTTP parameter for the cart ID*/
+const cartIdName = "smoke_cartid";
+
+/**called from index.php - add tickets to cart*/
+static function addTickets(){
+ global $HTTPARGS;
+ $cart=self::getOrCreateCart();
+ echo $cart;
+}
+
+/**returns the current cart ID, or an empty string if there is no cart*/
+static function getCart(){
+ global $HTTPARGS,$_COOKIE;
+ if(self::$cartid!==false)return self::$cartid;
+ //search GET/POST parms
+ if(isset($HTTPARGS[self::cartIdName])){
+ //found it, test it!
+ $ci=trim($HTTPARGS[self::cartIdName]);
+ if($ci!=""){
+ $res=WTcart::getFromDB($ci);
+ if(is_a($res,"WTcart")){
+ self::$cartid=$ci;
+ return $ci;
+ }
+ }
+ }
+ //search cookies
+ if(isset($_COOKIE[self::cartIdName])){
+ //found it, test it!
+ $ci=trim($_COOKIE[self::cartIdName]);
+ if($ci!=""){
+ $res=WTcart::getFromDB($ci);
+ if(is_a($res,"WTcart")){
+ self::$cartid=$ci;
+ return $ci;
+ }
+ }
+ }
+ //none found
+ self::$cartid="";
+ return "";
+}
+
+/**return existing cart or create a new one*/
+static public function getOrCreateCart(){
+ global $CartTimeout;
+ //try to find it
+ self::getCart();
+ if(self::$cartid==""){
+ //none there, create it
+ $c=WTcart::newRow();
+ $exp=time()+$CartTimeout;
+ $c->timeout=$exp;
+ $c->insert();
+ //set cookies
+ setCookie(self::cartIdName,$c->cartid,0);
+ //remember
+ self::$cartid=$c->cartid;
+ }
+ //return
+ return self::$cartid;
+}
+
+/** \internal called to generate a new cart*/
+static public function getNewCartId(){
+ do{
+ //generate ID
+ $ci=getCode39ID(32);
+ //look for duplicate
+ $res=WTcart::getFromDB($ci);
+ if(is_a($res,"WTcart"))continue;
+ //return ID
+ return $ci;
+ }while(true);
+}
+
+//end of WebCart
+};
+
+
/** creates the cart overview */
function createCartOverview()
{
//include process script (TODO: rework to be autoloaded)
include('inc/rendering/submit.php');
+//unify arguments
+$HTTPARGS=$_GET;
+foreach($_POST as $a=>$p)$HTTPARGS[$a]=$p;
+
//set common basics
$mode="index";
if(isset($_GET["mode"])){
$twig = new Twig_Environment($loader, $twigoptions );
foreach($twigextensions as $te)$twig->addExtension($te);
+$cartid=WebCart::getCart();
+// if($cartid!="")$carturl="cartid=$cartid&";else $carturl="";
+
//basic variables shared by all templates
// script URLs
$basevars['script']['root']=$_SERVER['SCRIPT_NAME'];
$basevars['script']['this']=$_SERVER['REQUEST_URI'];
+$basevars['script']['index']=$_SERVER['SCRIPT_NAME']."?mode=index";
$basevars['script']['eventDetails']=$_SERVER['SCRIPT_NAME']."?mode=eventDetails&event=";
$basevars['script']['eventOrder']=$_SERVER['SCRIPT_NAME']."?mode=eventOrder&event=";
//$basevars['script']['cart']=$_SERVER['SCRIPT_NAME']."?mode=cart";
$basevars['inputnames']['amountTickets']="amountTickets";
$basevars['inputnames']['event']="event";
$basevars['inputnames']['mode']="mode";
+$basevars['inputnames']['cartid']=WebCart::cartIdName;
+$basevars['cartcookie']=WebCart::cartIdName;
//strings that are used to compose the overall layout
-$page="(internal error: no page text yet)";
+$page="(internal error: no page text yet, probably no template defined)";
try{
//get page template and process it
$page=EventRender::createEventDetails();
break;
case "eventOrder":
- $page=
+ WebCart::addTickets();
+ break;
/* case "cart":
deleteEventFromCart();
changeTicketAmountInCart();
{{event.date}} {{event.time}}, {{event.place}}<br/>
Artist: {{event.artist}}<br/>
{{event.description}}<br/>
- <form action="{{script.eventOrder}}{{event.ID}}" method="GET">
+ <form action="{{script.eventOrder}}{{event.ID}}" method="POST">
<table>
<tr><td>Price:</td><td>Amount:</td></tr>
{% for price in event.prices %}
{% for price in event.prices %}
{{price.price}} ({{price.categoryname}})
{% endfor %}<br/>
- <a href="{{script.eventDetails}}{{event.ID}}">order tickets</a>
+ <a href="{{script.eventDetails}}{{event.ID}}">details/order tickets</a>
{% endfor %}
{% endblock %}