/**returns a nice printable string*/
public function toString()
{
- $ret="Error: ";
+ $ret=i18n("Error: ");
switch($this->etype){
- case CE_NOITEMS:$ret.="No items in cart.";break;
- case CE_EVENTCANCELLED:$ret.="Event has been cancelled.";break;
- case CE_EVENTNOTICKETS:$ret.="No more tickets available.";break;
- case CE_EVENTUNKNOWN:$ret.="Unknown Event.";break;
- case CE_EVENTOVER:$ret.="Cannot order tickets from past.";break;
- case CE_INVALIDVOUCHER:$ret="Voucher is invalid.";break;
+ case CE_NOITEMS:$ret.=i18n("No items in cart.");break;
+ case CE_EVENTCANCELLED:$ret.=i18n("Event has been cancelled.");break;
+ case CE_EVENTNOTICKETS:$ret.=i18n("No more tickets available.");break;
+ case CE_EVENTUNKNOWN:$ret.=i18n("Unknown Event.");break;
+ case CE_EVENTOVER:$ret.=i18n("Cannot order tickets from past.");break;
+ case CE_INVALIDVOUCHER:$ret=i18n("Voucher is invalid.");break;
}
return $ret;
}
}
}
+ /**deletes a cart and all its tickets */
+ public function destroyCart()
+ {
+ global $db;
+ if ($this->isValid()) {
+ $db->deleteRows("cart_ticket", "cartid=".$db->escapeInt($this->cartid));
+ $db->deleteRows("cart", "cartid=".$db->escapeInt($this->cartid));
+ }
+ }
+
/**adds the shipping address to the cart*/
public function addShippingAddress($address)
{
}
}
+/** orders the tickets */
function orderTickets()
{
if (isset($_POST["ms_orderTickets"])) {
+ $error = ErrorManager::singleton();
+
// check if loggedin
$session = new WebSession();
if (!$session->isAuthorized()) {
if ($cart->isValid()) {
$check=$cart->orderCheck();
if(count($check)>0){
- //TODO: do something useful with that...
- print("cart failed order check");
foreach($check as $err)
- print($err->toString());
+ $error->add($err->toString());
return;
}
$order=new Order;
$order->emptyCart($cart);
$ret=$order->placeOrder();
if($ret===false){
- //TODO: panic properly!
- print("unable to order!");
+ $error->add(i18n("Can't order!"));
return;
}
- //TODO: destroy cart
+ $cart->destroyCart();
+ setcookie(COOKIE_CART, "", 1);
+ } else {
+ $error->add(i18n("Cart is not valid!"));
}
}
}