--- /dev/null
+<?php
+
+class Page_Add extends Page {
+
+ public function logic($template){
+
+ $system = Ticketing::Get();
+
+ try {
+ $arg = $system->arg(1);
+ if(!isset($arg) || $arg == ''){
+ header('Location: ' . $system->url('index'));
+ }
+
+ $system->database()->begin();
+
+ // Do we have any tickets left?
+
+ $type = Type::Get($arg);
+
+ if(!isset($type)){
+ header('Location: ' . $system->url('index'));
+ }
+
+ if(!$type->left()){
+ header('Location: ' . $system->url('index'));
+ }
+
+ $this->error = false;
+
+ if(isset($_POST['submit'])){
+ if(isset($_POST['name']) && $_POST['name'] != ''){
+ $this->name = $template->name = $_POST['name'];
+ } else {
+ $this->error = true;
+ $template->error = 'Please fill in the form below.';
+ }
+
+ if(!$this->error && (!isset($_POST['age']) || $_POST['age'] == '')){
+ $template->error = 'Guests for Homerton May Ball 2011 must be over 18.';
+ $this->error = true;
+ }
+
+ if(!$this->error){
+ $current = Order::Get_Unconfirmed_By_User($system->user());
+ var_dump($this);
+ exit;
+ }
+ }
+
+ $template->type = $type->name();
+ $template->price = $type->price();
+ $template->url = $system->url('add', $type->id());
+
+ $system->database()->commit();
+ } catch (Exception $e){
+ $system->database()->rollback();
+ throw $e;
+ }
+
+ }
+
+
+}
--- /dev/null
+<?php
+
+class Template_Add extends Template {
+
+ public function display(){
+?>
+<div id="add">
+<?php if(isset($this->error)){ ?>
+ <?php echo $this->error; ?>
+<?php } ?>
+<form action="<?php echo $this->url; ?>" method="post">
+ <dl>
+ <dt>Name:</dt>
+ <dd><input type="text" value="<?php echo $this->name; ?>" name="name"></dd>
+ </dl>
+ <dl>
+ <dt>Over 18?</dt>
+ <dd><input type="checkbox" name="age"></dd>
+ </dl>
+ <input type="submit" value="Order <?php echo $this->type; ?> Ticket" name="submit">
+</form>
+</div>
+<?php
+ }
+
+}