- added pages to edit order comments and the shipping address
authorpeter <peter@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 9 Mar 2008 16:05:52 +0000 (16:05 +0000)
committerpeter <peter@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 9 Mar 2008 16:05:52 +0000 (16:05 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@108 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

www/inc/classes/cart.php
www/inc/classes/customer.php
www/inc/db/db_scheme.php
www/inc/global_functions.php [new file with mode: 0644]
www/inc/rendering/order_listing.php
www/inc/rendering/submit.php
www/index.php
www/template/de/editordercomments.html [new file with mode: 0644]
www/template/de/editshippingaddress.html [new file with mode: 0644]
www/template/de/orderoverview.html

index 10ca092..cec8e8d 100644 (file)
@@ -132,7 +132,7 @@ class Cart
                        
                        $timeout = time()+$CartTimeout ;
 //                     print $timeout;
-                       $db->insert("cart",array("cartid"=>$id,"timeout"=>$timeout,"shippingaddress"=>"test"));
+                       $db->insert("cart",array("cartid"=>$id,"timeout"=>$timeout));
                        $db->commitTransaction();
                }else{
                        //check that cart exists
@@ -249,7 +249,16 @@ class Cart
        {
                global $db;
                if ($this->isValid()) {
-                       $db->update("cart", array("shippingaddress"=>$db->escapeString($address)), "cartid=".$db->escapeString($this->cartid)); 
+                       $db->update("cart", array("shippingaddress"=>$address), "cartid=".$db->escapeString($this->cartid));    
+               }
+       }
+       
+       /**adds the customer comments to the cart*/
+       public function addOrderComments($comment)
+       {
+               global $db;
+               if ($this->isValid()) {
+                       $db->update("cart", array("ordercomments"=>$comment), "cartid=".$db->escapeString($this->cartid));      
                }
        }
        
@@ -265,6 +274,19 @@ class Cart
                                return false;
                }
        }
+               
+       /**returns the customer comments for the cart*/
+       public function getOrderComments()
+       {
+               global $db;
+               if ($this->isValid()) {
+                       $res = $db->select("cart", "ordercomments", "cartid=".$db->escapeString($this->cartid));
+                       if (count($res) > 0)
+                               return $res[0]["ordercomments"];
+                       else
+                               return false;
+               }
+       }
 };
 
 ?>
\ No newline at end of file
index 8c630fa..8a92e26 100644 (file)
@@ -17,15 +17,7 @@ class Customer
                
                $this->id=false;
                if($id!==false){
-                       if ($this->getByID($id)) {
-                               $res=$db->select("customer", "*", "customerid=".$db->escapeInt($id));
-                               if (count($res) == 1) {
-                                       $this->email = $res[0]["email"];
-                                       $this->name = $res[0]["name"];
-                                       $this->address = $res[0]["address"];
-                                       $this->contact = $res[0]["contact"];
-                               }
-                       }
+                       $this->getByID($id);
                }
        }
        
@@ -65,37 +57,64 @@ class Customer
        /** returns the name of the customer */
        public function getName()
        {
+               global $db;
                if($this->id===false)
                        return "";
-               else 
-                       return $this->name;
+               else {
+                       $res = $db->select("customer", "name", "customerid=".$db->escapeInt($this->id));
+                       if (count($res) > 0)
+                               return $res[0]["name"];
+                       else
+                               return "";
+               }
        }
        
        /** returns the email address of the customer */
        public function getEmail()
        {
+               global $db;
                if($this->id===false)
                        return "";
-               else 
-                       return $this->email;
+               else {
+                       $res = $db->select("webuser", "email", "customerid=".$db->escapeInt($this->id));
+                       if (count($res) > 0)
+                               return $res[0]["email"];
+                       else
+                               return "";
+               }
+
        }
        
        /** returns the address of the customer */
        public function getAddress()
        {
+               global $db;
                if($this->id===false)
                        return "";
-               else 
-                       return $this->address;
+               else {
+                       $res = $db->select("customer", "address", "customerid=".$db->escapeInt($this->id));
+                       if (count($res) > 0)
+                               return $res[0]["address"];
+                       else
+                               return "";
+               }
+
        }
        
        /** returns the contact data of the customer */
        public function getContact()
        {
+               global $db;
                if($this->id===false)
                        return "";
-               else 
-                       return $this->contact;
+               else {
+                       $res = $db->select("customer", "contact", "customerid=".$db->escapeInt($this->id));
+                       if (count($res) > 0)
+                               return $res[0]["contact"];
+                       else
+                               return "";
+               }
+
        }
        
        /**returns the data in an array suitable for the web-page-renderer*/
index 6092457..77d5bbd 100644 (file)
@@ -155,7 +155,9 @@ class DbScheme {
                        //when the cart expires
                        "timeout" => array("int32","notnull"),
                        //shipping address during order process
-                       "shippingaddress" => array("text")
+                       "shippingaddress" => array("text"),
+                       //customer comments during order process
+                       "ordercomments" => array("text")
                );
                //buying tickets
                $this->scheme["cart_ticket"]=array(
diff --git a/www/inc/global_functions.php b/www/inc/global_functions.php
new file mode 100644 (file)
index 0000000..3e05163
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+// +----------------------------------------------------------------------
+// | PHP Source                                                           
+// +----------------------------------------------------------------------
+// | Copyright (C) 2008 by Peter Keller <peter@silmor.de>
+// +----------------------------------------------------------------------
+// |
+// | Copyright: See COPYING file that comes with this distribution
+// +----------------------------------------------------------------------
+//
+
+/** checks if a variable is empty, needs to be used to check class methods */
+function isEmpty($var)
+{
+       return empty($var);
+}
+
+/** checks if given value is a valid email address */
+function isEmail($value)
+{
+       return ereg("^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+$", $value);
+}
+
+
+?>
index 0ec3661..d49f83e 100644 (file)
@@ -102,6 +102,7 @@ function createCustomerRegistration()
        $parser->setVAR("PAGE", $localParser->parseFile("customerregistration.html"));
 }
 
+/**creates the overview of an order */
 function createOrderOverview()
 {      
        global $parser;
@@ -124,6 +125,26 @@ function createOrderOverview()
        
        // set cart overview
        $cart = new Cart($_COOKIE[COOKIE_CART]);
+       if ($cart->isValid()) {
+               // renew cart
+               $cart->renewCart();
+               
+               $shippingAddress = "";
+               $comments = "";
+               
+               if (!isEmpty($shippingAddress = $cart->getShippingAddress()))
+                       $shippingAddress .= " (<a href=index.php?mode=editShippingAddress>".i18n("Change")."</a>)";
+               else
+                       $shippingAddress = "(<a href=index.php?mode=editShippingAddress>".i18n("Add")."</a>)";
+               
+               if (!isEmpty($comments = $cart->getOrderComments()))
+                       $comments .= " (<a href=index.php?mode=editOrderComments>".i18n("Change")."</a>)";
+               else
+                       $comments = "(<a href=index.php?mode=editOrderComments>".i18n("Add")."</a>)";
+               
+               $p->setVar("CUST_SHIPPINGADDRESS", $shippingAddress);
+               $p->setVar("CUST_COMMENTS", $comments);
+       }
        
        $tablerows = "";
        $totalsum = 0;
@@ -161,10 +182,77 @@ function createOrderOverview()
        $p->setVar("TABLEROWS", $tablerows);
        $p->setVar("TOTALSUM", $lang->getPrice($totalsum));
        
+       // set edit links
+       $p->setVar("linkEDIT_SHIPPINGADDRESS", "index.php?mode=editShippingAddress");
+       $p->setVar("linkEDIT_COMMENTS", "index.php?mode=editOrderComments");
+       
        // set buttons
        
+       
        // create page
        $parser->setVAR("PAGE", $p->parseFile("orderoverview.html"));
 }
 
+/** creates the form to edit the shipping address */
+function editShippingAddress()
+{
+       global $parser;
+       
+       $p = new Parser("editshippingaddress.html");
+       
+       // check if loggedin
+       $session = new WebSession();
+       if (!$session->isAuthorized()) {
+               Header("Location: index.php");
+               exit();
+       }
+       
+       // get shipping address
+       $cart = new Cart($_COOKIE[COOKIE_CART]);
+       if ($cart->isValid()) {
+               $p->setVar("SHIPPINGADDRESS", $cart->getShippingAddress());
+       }
+       
+       // set input fields
+       $p->setVar("fieldSHIPPINGADDRESS", "ms_shippingAddress");
+       
+       // set buttons
+       $p->setVar("buttonSAVE_SHIPPINGADDRESS", "ms_saveShippingAddress");
+       $p->setVar("buttonCANCEL_SHIPPINGADDRESS", "ms_cancelShippingAddress");
+       
+       // create page
+       $parser->setVAR("PAGE", $p->parseFile("editshippingaddress.html"));
+}
+
+/** creates the form to edit the order comments */
+function editOrderComments()
+{
+       global $parser;
+       
+       $p = new Parser("editordercomments.html");
+       
+       // check if loggedin
+       $session = new WebSession();
+       if (!$session->isAuthorized()) {
+               Header("Location: index.php");
+               exit();
+       }
+       
+       // get shipping address
+       $cart = new Cart($_COOKIE[COOKIE_CART]);
+       if ($cart->isValid()) {
+               $p->setVar("COMMENTS", $cart->getOrderComments());
+       }
+       
+       // set input fields
+       $p->setVar("fieldCOMMENTS", "ms_comments");
+       
+       // set buttons
+       $p->setVar("buttonSAVE_COMMENTS", "ms_saveComments");
+       $p->setVar("buttonCANCEL_COMMENTS", "ms_cancelComments");
+       
+       // create page
+       $parser->setVAR("PAGE", $p->parseFile("editordercomments.html"));
+}
+
 ?>
\ No newline at end of file
index d270f9d..f1af4e8 100644 (file)
@@ -268,10 +268,53 @@ function registerUser()
        }
 }
 
-/** checks if given value is a valid email address */
-function isEmail($value)
+/** saves the shipping address */
+function saveShippingAddress()
 {
-       return ereg("^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+$", $value);
+       $error = ErrorManager::singleton();
+
+       if (isset($_POST["ms_saveShippingAddress"])) {
+       
+               // check if loggedin
+               $session = new WebSession();
+               if (!$session->isAuthorized()) {
+                       Header("Location: index.php");
+                       exit();
+               }
+               
+               $cart = new Cart($_COOKIE[COOKIE_CART]);
+               if ($cart->isValid()) {
+                       $cart->addShippingAddress($_POST["ms_shippingAddress"]);
+               }
+               
+               Header("Location: index.php?mode=orderOverview");
+       } else if (isset($_POST["ms_cancelShippingAddress"])) {
+               Header("Location: index.php?mode=orderOverview");
+               exit();
+       }
 }
 
+/** saves the order comments */
+function saveOrderComments()
+{
+       if (isset($_POST["ms_saveComments"])) {
+       
+               // check if loggedin
+               $session = new WebSession();
+               if (!$session->isAuthorized()) {
+                       Header("Location: index.php");
+                       exit();
+               }
+               
+               $cart = new Cart($_COOKIE[COOKIE_CART]);
+               if ($cart->isValid()) {
+                       $cart->addOrderComments($_POST["ms_comments"]);
+               }
+               
+               Header("Location: index.php?mode=orderOverview");
+       } else if (isset($_POST["ms_cancelComments"])) {
+               Header("Location: index.php?mode=orderOverview");
+               exit();
+       }
+}
 ?>
\ No newline at end of file
index 23e2d7f..dae6f40 100644 (file)
@@ -3,6 +3,7 @@
 include('inc/loader.php');
 include('inc/loader_nonadmin.php');
 include('inc/global_variables.php');
+include('inc/global_functions.php');
 
 //include process script
 include('inc/rendering/submit.php');
@@ -42,6 +43,14 @@ switch($mode){
        case "orderOverview":
                createOrderOverview();
                break;
+       case "editShippingAddress":
+               saveShippingAddress();
+               editShippingAddress();
+               break;
+       case "editOrderComments":
+               saveOrderComments();
+               editOrderComments();
+               break;
        default:
                createEventList();
                break;
diff --git a/www/template/de/editordercomments.html b/www/template/de/editordercomments.html
new file mode 100644 (file)
index 0000000..4017b69
--- /dev/null
@@ -0,0 +1,16 @@
+<h1>Hinweis ändern</h1>
+<div id="ms_form">
+<form action="@FULLURL@" method="POST">
+<fieldset class="ms_Form">
+<div class="ms_FormRow">
+<textarea id="ms_textfield_comments" name="@fieldCOMMENTS@" rows="3">@COMMENTS@</textarea>
+</div>
+</fieldset>
+
+<div class="ms_ButtonArea">
+<input type="submit" id="ms_button_save" name="@buttonSAVE_COMMENTS@" value="Speichern" />
+<input type="submit" id="ms_button_cancel" name="@buttonCANCEL_COMMENTS@" value="Abbrechen" />
+</div>
+
+</form>
+</div>
\ No newline at end of file
diff --git a/www/template/de/editshippingaddress.html b/www/template/de/editshippingaddress.html
new file mode 100644 (file)
index 0000000..361cf3a
--- /dev/null
@@ -0,0 +1,17 @@
+<h1>Lieferadresse ändern</h1>
+<div id="ms_form">
+<form action="@FULLURL@" method="POST">
+<fieldset class="ms_Form">
+<div class="ms_FormRow">
+<label for="ms_textfield_shippingaddress">Adresse:</label>
+<textarea id="ms_textfield_shippingaddress" name="@fieldSHIPPINGADDRESS@" rows="3">@SHIPPINGADDRESS@</textarea>
+</div>
+</fieldset>
+
+<div class="ms_ButtonArea">
+<input type="submit" id="ms_button_save" name="@buttonSAVE_SHIPPINGADDRESS@" value="Speichern" />
+<input type="submit" id="ms_button_cancel" name="@buttonCANCEL_SHIPPINGADDRESS@" value="Abbrechen" />
+</div>
+</form>
+
+</div>
\ No newline at end of file
index 7b123c3..d8dd93e 100644 (file)
@@ -17,7 +17,7 @@
 </div>
 <div class="ms_FormRow">
 <label for="ms_text_shippingAddress">Lieferadresse:</label>
-<span id="ms_textfield_shippingAddress">&nbsp;</span>
+<span id="ms_textfield_shippingAddress">@CUST_SHIPPINGADDRESS@</span>
 </div>
 <div class="ms_FormRow">
 <label for="ms_text_phone">Tel-Nr:</label>
@@ -25,7 +25,7 @@
 </div>
 <div class="ms_FormRow">
 <label for="ms_text_comment">Hinweis:</label>
-<span id="ms_text_comment"></span>
+<span id="ms_text_comment">@CUST_COMMENTS@</span>
 </div>
 </fieldset>
 </div>