/**use this to get tickets by eventid; returns false if it does not exist*/
public function getTicketsByEvent($eventid)
{
+ global $db;
$where="cartid=".$db->escapeString($this->cartid)." AND eventid=".$db->escapeInt($eventid);
$res=$db->select("cart_ticket","*",$where);
- if(count($res>0))
- return new CartTicket($res[0]["cartid"],$res[0]["eventid"],$res[0]["amount"]);
+ if(count($res) > 0)
+ return new CartTicket($res[0]["cartid"],$res[0]["eventid"],$res[0]["amount"]);
+ else
+ return false;
}
/**use this to add tickets, returns new CartTicket object or false if the event does not exist or is cancelled*/
// +----------------------------------------------------------------------
//
+/** creates the cart overview */
function createCartOverview()
{
global $parser;
$error = ErrorManager::singleton();
$lang = LanguageManager::singleton();
- $COOKIE_NAME = "ms_cartid";
- $cart = new Cart($_COOKIE[$COOKIE_NAME]);
+ $cart = new Cart($_COOKIE[COOKIE_NAME]);
$p = new Parser("cart.html");
- $details = "";
+ $tablerows = "";
$totalsum = 0;
+ $hiddenfields = "";
// get tickets from cart
foreach ($cart->getTickets() as $ticket)
// set event details
$p->setVars($event->getParserData());
- $p->setVar("AMOUNT", $ticket->getAmount());
+
+ // if no error exists set values of database, else values of submit
+ if (!$error->exists()) {
+ $p->setVar("AMOUNT", $ticket->getAmount());
+ } else {
+ $ticketAmounts = $_POST["ms_amount"];
+ $eventIDs = $_POST["ms_event"];
+ $amountValue = $ticketAmounts[array_search($event->getEventId(),$eventIDs)];
+ $p->setVar("AMOUNT", $amountValue);
+ }
+
+ $p->setVar("linkDELETEROW", "index.php?mode=cart&action=deleteEvent&event=".$event->getEventId());
+ $p->setVar("fieldAMOUNT", "ms_amount[]");
+
+ // fill hidden fields
+ $hiddenfields .= "<input type=\"hidden\" name=\"ms_event[]\" value=\"".$event->getEventId()."\" />\n";
$rowsum = $ticket->getAmount()*$event->getDefaultPrice();
$p->setVar("ROWSUM", $lang->getPrice($rowsum));
$totalsum += $rowsum;
- $details .= $p->parse($cartRowTmpl);
+ $tablerows .= $p->parse($cartRowTmpl);
}
- $p->setVar("TABLEROWS", $details);
+ // if no tickets in cart set EMPTYROWS
+ if (count($cart->getTickets()) == 0) {
+ $tablerows = $p->getVar("EMPTYROWS");
+ }
+
+ $p->setVar("TABLEROWS", $tablerows);
$p->setVar("TOTALSUM", $lang->getPrice($totalsum));
- $p->setVar("fieldAMOUNT", "ms_amount[]");
+ // set buttons
$p->setVar("buttonSAVE", "ms_save");
- $p->setVar("buttonORDER", "ms_order");
+ $p->setVar("buttonORDER", "ms_goToOrder");
+ // set hidden fields
+ $p->setVar("IS_HIDDEN", "true");
+ $p->setVar("HIDDENAREA", $hiddenfields);
// set error message
if ($error->exists()) {
- $p->setVar("ERROR", "true");
+ $p->setVar("IS_ERROR", "true");
$p->setVar("ERRORAREA", $error->getAllFormatted());
}
$parser->setVAR("PAGE", $p->parseFile("cart.html"));
}
-
-?>
+?>
\ No newline at end of file
{
$lang = LanguageManager::singleton();
- return array("DATE"=>$lang->getDate($this->getStartTime()), "TIME"=>$lang->getTime($this->getStartTime()), "PLACE"=>$this->getRoomId(), "EVENTNAME"=>$this->getTitle(), "ARTIST"=>$this->getArtist(),"PRICE"=>$lang->getPrice($this->getDefaultPrice()), "ID"=>$this->getEventId(), "DESCRIPTION"=>$this->getDescription());
+ return array("DATE"=>$lang->getDate($this->getStartTime()), "TIME"=>$lang->getTime($this->getStartTime()), "PLACE"=>$this->getRoomId(), "EVENTNAME"=>$this->getTitle(), "ARTIST"=>$this->getArtist(),"PRICE"=>$lang->getPrice($this->getDefaultPrice()), "ID"=>$this->getEventId(), "DESCRIPTION"=>$this->getDescription(), "LINK"=>"");
}
/**returns how many tickets can still be sold*/
if (!$event->exists())
{
header("Location:index.php");
+ return;
}
// set event details
--- /dev/null
+<?php
+// +----------------------------------------------------------------------
+// | PHP Source
+// +----------------------------------------------------------------------
+// | Copyright (C) 2007 by Peter Keller <peter@silmor.de>
+// +----------------------------------------------------------------------
+// |
+// | Copyright: See COPYING file that comes with this distribution
+// +----------------------------------------------------------------------
+//
+
+define("COOKIE_NAME", "ms_cartid");
+
+$lang = LanguageManager::singleton();
+$error = ErrorManager::singleton();
+$parser = new Parser();
+
+?>
// +----------------------------------------------------------------------
//
+/** function to replace gettext */
function i18n($key)
{
$lang = LanguageManager::singleton();
}
}
+/** replaces each {number} in a string with its equivalent in the array
+{1} => array[0] */
+function string_format($string, $array)
+{
+ $num = count($array);
+
+ for ($i=0; $i < $num; $i++) {
+ $string = str_replace("{".($i+1)."}", $array[$i], $string);
+ }
+
+ return $string;
+}
+
class LanguageManager
{
private static $COOKIE_NAME = "ms_lang";
$this->templateFolder = $template;
//default fallback for empty setting
- if($this->templateFolder=="")$this->templateFolder="./template/";
+ if($this->templateFolder == "")
+ $this->templateFolder = "./template/";
//make sure it ends with /
- if(substr($this->templateFolder,-1,1)!="/")$this->templateFolder.="/";
+ if(substr($this->templateFolder,-1,1) != "/")
+ $this->templateFolder .= "/";
// check if cookie is set
if (isset($_COOKIE[self::$COOKIE_NAME])) {
--- /dev/null
+<?php
+// +----------------------------------------------------------------------
+// | PHP Source
+// +----------------------------------------------------------------------
+// | Copyright (C) 2007 by Peter Keller <peter@silmor.de>
+// +----------------------------------------------------------------------
+// |
+// | Copyright: See COPYING file that comes with this distribution
+// +----------------------------------------------------------------------
+//
+
+/** creates the login to an order */
+function createOrderLogin()
+{
+ global $parser;
+
+ $error = ErrorManager::singleton();
+
+ $localParser = new Parser("orderlogin.html");
+
+ $localParser->setVar("fieldEMAIL", "ms_email");
+ $localParser->setVar("radioIS_CUSTOMER", "ms_isCustomer");
+ $localParser->setVar("fieldPASSWORD", "ms_password");
+ $localParser->setVar("buttonCONTINUE", "ms_loginContinue");
+
+ if (!empty($_POST["ms_email"])) {
+ $localParser->setVar("valueEMAIL", $_POST["ms_email"]);
+ } else {
+ $localParser->setVar("valueEMAIL", "");
+ }
+
+ // set error message
+ if ($error->exists()) {
+ $localParser->setVar("IS_ERROR", "true");
+ $localParser->setVar("ERRORAREA", $error->getAllFormatted());
+ }
+
+ // create page
+ $parser->setVAR("PAGE", $localParser->parseFile("orderlogin.html"));
+}
+
+?>
\ No newline at end of file
// +----------------------------------------------------------------------
//
+// forward to order login when order button in cart is pressed
+if (isset($_POST["ms_goToOrder"])) {
+ Header("Location: index.php?mode=orderLogin");
+ exit();
+}
+
/** adds an event to the cart */
function addEventToCart()
{
$error = ErrorManager::singleton();
- $lang = LanguageManager::singleton();
- $COOKIE_NAME = "ms_cartid";
if (isset($_POST["ms_save"])) {
- $event = new Event($_GET["event"]);
+ $event = new Event(($_GET["event"]+0));
+ $availableTickets = $event->availableTicketAmount();
if (empty($_POST["ms_amount"])) {
$error->add(i18n("Please insert the number of tickets!"));
return;
} elseif (!$event->exists()) {
$error->add(i18n("The event does not exist!"));
return;
+ } else if ($availableTickets == 0) {
+ $error->add(i18n("No more tickets for this event available!"));
+ return;
} else {
- $cart = new Cart($_COOKIE[$COOKIE_NAME]);
+ $cart = new Cart(addslashes($_COOKIE[COOKIE_NAME]));
if (!$cart->isValid()) {
$cart = new Cart();
- setcookie($COOKIE_NAME, $cart->getCartId(), 0);
+ setcookie(COOKIE_NAME, $cart->getCartId(), 0);
}
- $cart->addTickets($event->getEventId(), $_POST["ms_amount"]);
+ // check if event is already booked
+ $cartTicket = $cart->getTicketsByEvent($event->getEventId());
+ // if event is not booked
+ if ($cartTicket == false) {
+ // check if enough tickets available
+ if ($availableTickets < ($_POST["ms_amount"]+0)) {
+ $error->add(string_format(i18n("Only {1} tickets left!"), array("$availableTickets")));
+ return;
+ }
+
+ // add tickets to cart
+ $cart->addTickets(($event->getEventId()+0), ($_POST["ms_amount"]+0));
+ } else {
+ // check if enough tickets available
+ if ($availableTickets < ($_POST["ms_amount"] + $cartTicket->getAmount())) {
+ $ticketsLeft = $availableTickets - $cartTicket->getAmount();
+ if ($ticketsLeft > 0)
+ $error->add(string_format(i18n("Only {1} more tickets left!"),array("$ticketsLeft")));
+ else
+ $error->add(i18n("No more tickets for this event available!"));
+ return;
+ }
+
+ // set tickets to cartTicket
+ $cartTicket->changeAmount($cartTicket->getAmount() + $_POST["ms_amount"]);
+ }
+
Header("Location: index.php?mode=cart");
+ exit();
}
}
}
-?>
+
+/** deletes an event from the cart */
+function deleteEventFromCart()
+{
+ if ($_GET["action"]=="deleteEvent") {
+ $cart = new Cart(addslashes($_COOKIE[COOKIE_NAME]));
+ // check if cart valid
+ if ($cart->isValid()) {
+ // get cart ticket
+ $cartTicket = $cart->getTicketsByEvent($_GET["event"]+0);
+ if ($cartTicket != false) {
+ $cartTicket->changeAmount(0);
+ }
+ }
+ }
+}
+
+/** modifies the amount of tickets in the cart */
+function changeTicketAmountInCart()
+{
+ $error = ErrorManager::singleton();
+
+ if (isset($_POST["ms_save"])) {
+
+ $cart = new Cart(addslashes($_COOKIE[COOKIE_NAME]));
+ // check if cart valid
+ if ($cart->isValid()) {
+
+ // get event IDs and amounts
+ $eventIDs = $_POST["ms_event"];
+ $ticketAmounts = $_POST["ms_amount"];
+
+ $num = count($eventIDs);
+
+ // check for errors in input
+ for ($i=0; $i < $num; $i++) {
+ $line = $i + 1;
+ if (empty($ticketAmounts[$i]) || !is_numeric($ticketAmounts[$i])) {
+ $error->add(string_format(i18n("Please enter an amount in line {1}!"), array("$line")));
+ }
+ }
+
+ if ($error->exists())
+ return;
+
+ // iterate over events
+ for ($i=0; $i < $num; $i++) {
+ // get eventID and belonging amount
+ $eventID = $eventIDs[$i]+0;
+ $amount = $ticketAmounts[$i]+0;
+
+ $cartTicket = $cart->getTicketsByEvent($eventID);
+
+ // check if amount changed
+ if ($cartTicket->getAmount() != $amount) {
+ // check if enough tickets available
+ $event = $cartTicket->eventObject();
+ if ($event->availableTicketAmount() >= $amount) {
+ $cartTicket->changeAmount($amount);
+ } else {
+ $title = $event->getTitle();
+ $availableTickets = $event->availableTicketAmount();
+ $error->add(string_format(i18n("Event {1} has only {2} tickets left."), array("\"$title\"", "$availableTickets")));
+ }
+ }
+ }
+ }
+ }
+}
+
+/** checks order login for valid values */
+function checkOrderLogin()
+{
+ $error = ErrorManager::singleton();
+
+ if (isset($_POST["ms_loginContinue"])) {
+ // if user isn't registered
+ if ($_POST["ms_isCustomer"] == "false") {
+ if (!isEmail($_POST["ms_email"])) {
+ $error->add(i18n("Please enter a correct email address!"));
+ return;
+ }
+
+ // if user is registered
+ } elseif ($_POST["ms_isCustomer"] == "true") {
+ if (!isEmail($_POST["ms_email"])) {
+ $error->add(i18n("Please enter a correct email address!"));
+ }
+ if (empty($_POST["ms_password"])) {
+ $error->add(i18n("Please enter a password!"));
+ }
+ if ($error->exists())
+ return;
+ // TODO: check if login valid
+
+ // if radio button is not checked
+ } else {
+ $error->add(i18n("Please specify if you're a registered user!"));
+ return;
+ }
+
+ Header("Location: index.php?mode=userdata");
+ exit();
+ }
+}
+
+/** checks if given value is a valid email address */
+function isEmail($value) {
+ return ereg("^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+$", $value);
+}
+
+?>
\ No newline at end of file
//basics
include('inc/loader.php');
include('inc/loader_nonadmin.php');
+include('inc/global_variables.php');
//include process script
include('inc/submit.php');
//include display scripts
include('inc/event_listing.php');
include('inc/cart_listing.php');
+include('inc/order_listing.php');
//set common basics
$mode="index";
$mode=$_GET["mode"];
}
-$lang = LanguageManager::singleton();
-$error = ErrorManager::singleton();
-$parser = new Parser();
+$lang->setLanguage("de");
//get page template and process it
switch($mode){
createEventDetails();
break;
case "cart":
+ deleteEventFromCart();
+ changeTicketAmountInCart();
createCartOverview();
break;
+ case "orderLogin":
+ checkOrderLogin();
+ createOrderLogin();
+ break;
default:
createEventList();
break;
<h1>Warenkorb</h1>
<div id="ms_form">
-<form action="." method="POST">
+<form action="@FULLURL@" method="POST">
<table class="ms_Table">
<tr>
<th> </th>
<th>Anzahl</th>
<th>Summe</th>
</tr>
+
@TABLEROWS@
-<tr>
-<td colspan="6" class="ms_AlignRight"><b>Summe:</b></td>
-<td class="ms_AlignRight">@TOTALSUM@ €</td>
-</tr>
-</table>
#set:ROW:
<tr>
-<td><a href=".">Löschen</a></td>
-<td><a href=".">@EVENTNAME@</a></td>
+<td><a href="@linkDELETEROW@">Löschen</a></td>
+<td><a href="@LINK@">@EVENTNAME@</a></td>
<td>@DATE@</td>
<td class="ms_AlignRight">@TIME@</td>
<td class="ms_AlignRight">@PRICE@ €</td>
</tr>
#endset
+#set:EMPTYROWS:
+<tr><td colspan="7">Sie haben keine Veranstaltungen im Warenkorb.</td></tr>
+#endset
+
+<tr>
+<td colspan="6" class="ms_AlignRight"><b>Summe:</b></td>
+<td class="ms_AlignRight">@TOTALSUM@ €</td>
+</tr>
+</table>
+
<div class="ms_ButtonArea">
<input type="submit" id="ms_button_save" name="@buttonSAVE@" value="Aktualisieren" />
<input type="submit" id="ms_button_order" name="@buttonORDER@" value="Zur Bestellung" />
</div>
+#if:IS_HIDDEN==true
+@HIDDENAREA@
+#endif
</form>
-#if:ERROR==true
+#if:IS_ERROR==true
@ERRORAREA@
#endif
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2007-11-04 17:12+0100\n"
+"POT-Creation-Date: 2007-11-17 23:42+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
-#: ../../inc/submit.php:22
+#: ../../inc/submit.php:26
msgid "Please insert the number of tickets!"
msgstr "Bitte angeben wieviele Tickets gewünscht werden!"
-#: ../../inc/submit.php:25
+#: ../../inc/submit.php:29
msgid "Please insert a number!"
msgstr "Bitte Zahlen verwenden!"
-#: ../../inc/submit.php:28
+#: ../../inc/submit.php:32
msgid "The event does not exist!"
msgstr "Diese Veranstaltung existiert nicht."
-#: inc/language_manager.php:60
+#: ../../inc/submit.php:35 ../../inc/submit.php:64
+msgid "No more tickets for this event available!"
+msgstr "Für diese Veranstaltung gibt es keine Tickets mehr!"
+
+#: ../../inc/submit.php:51
+msgid "Only {1} tickets left!"
+msgstr "Nur noch {1} Tickets übrig!"
+
+#: ../../inc/submit.php:62
+msgid "Only {1} more tickets left!"
+msgstr "Nur noch {1} Tickets übrig!"
+
+#: ../../inc/submit.php:115
+msgid "Please enter an amount in line {1}!"
+msgstr "Bitte geben Sie eine Menge in Zeile {1} ein."
+
+#: ../../inc/submit.php:139
+msgid "Event {1} has only {2} tickets left."
+msgstr "Für die Veranstaltung {1} sind nur noch {2} Tickets übrig."
+
+#: ../../inc/submit.php:156 ../../inc/submit.php:163
+msgid "Please enter a correct email address!"
+msgstr "Bitte geben Sie eine korrekte E-Mail-Adresse ein!"
+
+#: ../../inc/submit.php:166
+msgid "Please enter a password!"
+msgstr "Bitte geben Sie ein Passwort ein!"
+
+#: ../../inc/submit.php:174
+msgid "Please specify if you're a registered user!"
+msgstr "Bitte geben Sie an, ob Sie ein registrierter Nutzer sind!"
+
+#: ../../inc/language_manager.php:108
msgid "Y-m-d"
msgstr "d.m.Y"
-#: inc/language_manager.php:66
+#: ../../inc/language_manager.php:114
msgid "h:i a"
msgstr "H:i"
-#: inc/language_manager.php:72
+#: ../../inc/language_manager.php:120
msgid "."
msgstr ","
-#: inc/language_manager.php:72
+#: ../../inc/language_manager.php:120
msgid ","
msgstr "."
--- /dev/null
+<h1>Bestellung - Anmeldung</h1>
+<div id="ms_form">
+<form action="@FULLURL@" method="post">
+<p>Bitte geben Sie Ihre E-Mail-Adresse ein: <input type="text" id="ms_inputfield_email" name="@fieldEMAIL@" value="@valueEMAIL@" /></p>
+<p>
+<input type="radio" name="@radioIS_CUSTOMER@" value="false">Ich bin ein neuer Kunde.</input>
+</p>
+<p>
+<input type="radio" name="@radioIS_CUSTOMER@" value="true" checked="checked">Ich bin bereits Kunde. Mein Passwort: <input type="password" id="ms_inputfield_password" name="@fieldPASSWORD@" value="" /></input>
+</p>
+<div class="ms_ButtonArea">
+<input type="submit" id="ms_button_continue" name="@buttonCONTINUE@" value="Weiter" />
+</div>
+</form>
+
+#if:IS_ERROR==true
+@ERRORAREA@
+#endif
+
+</div>
\ No newline at end of file
--- /dev/null
+<h1>Login</h1>
+<div id="ms_form">
+<form action="." method="POST">
+<fieldset class="ms_Form">
+<div class="ms_FormRow">
+<label for="ms_textfield_email">E-Mail-Adresse:</label>
+<input type="text" id="ms_textfield_email" name="ms_email" />
+</div>
+<div class="ms_FormRow">
+<label for="ms_textfield_password">Passwort:</label>
+<input type="text" id="ms_textfield_password" name="ms_password" />
+</div>
+</fieldset>
+<div class="ms_ButtonArea">
+<input type="submit" id="ms_button_login" name="ms_login" value="Login" />
+</div>
+</form>
+</div>
\ No newline at end of file