Begun work on adding a ticket to a order.
authorRichard Whitehouse <github@richardwhiuk.com>
Fri, 4 Feb 2011 16:46:25 +0000 (16:46 +0000)
committerRichard Whitehouse <github@richardwhiuk.com>
Fri, 4 Feb 2011 16:46:25 +0000 (16:46 +0000)
pages/add.php [new file with mode: 0644]
templates/add.php [new file with mode: 0644]

diff --git a/pages/add.php b/pages/add.php
new file mode 100644 (file)
index 0000000..de7937e
--- /dev/null
@@ -0,0 +1,64 @@
+<?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;
+               }
+
+       }
+
+
+}
diff --git a/templates/add.php b/templates/add.php
new file mode 100644 (file)
index 0000000..70ee1db
--- /dev/null
@@ -0,0 +1,26 @@
+<?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
+       }
+
+}