From 6b6f35920642db067a99d4c3e5bc3bfa0b44fade Mon Sep 17 00:00:00 2001 From: peter Date: Sun, 9 Mar 2008 16:05:52 +0000 Subject: [PATCH] - added pages to edit order comments and the shipping address git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@108 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- www/inc/classes/cart.php | 26 ++++++++- www/inc/classes/customer.php | 53 ++++++++++++------ www/inc/db/db_scheme.php | 4 +- www/inc/global_functions.php | 25 +++++++++ www/inc/rendering/order_listing.php | 88 ++++++++++++++++++++++++++++++ www/inc/rendering/submit.php | 49 ++++++++++++++++- www/index.php | 9 +++ www/template/de/editordercomments.html | 16 ++++++ www/template/de/editshippingaddress.html | 17 ++++++ www/template/de/orderoverview.html | 4 +- 10 files changed, 266 insertions(+), 25 deletions(-) create mode 100644 www/inc/global_functions.php create mode 100644 www/template/de/editordercomments.html create mode 100644 www/template/de/editshippingaddress.html diff --git a/www/inc/classes/cart.php b/www/inc/classes/cart.php index 10ca092..cec8e8d 100644 --- a/www/inc/classes/cart.php +++ b/www/inc/classes/cart.php @@ -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 diff --git a/www/inc/classes/customer.php b/www/inc/classes/customer.php index 8c630fa..8a92e26 100644 --- a/www/inc/classes/customer.php +++ b/www/inc/classes/customer.php @@ -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*/ diff --git a/www/inc/db/db_scheme.php b/www/inc/db/db_scheme.php index 6092457..77d5bbd 100644 --- a/www/inc/db/db_scheme.php +++ b/www/inc/db/db_scheme.php @@ -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 index 0000000..3e05163 --- /dev/null +++ b/www/inc/global_functions.php @@ -0,0 +1,25 @@ + +// +---------------------------------------------------------------------- +// | +// | 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); +} + + +?> diff --git a/www/inc/rendering/order_listing.php b/www/inc/rendering/order_listing.php index 0ec3661..d49f83e 100644 --- a/www/inc/rendering/order_listing.php +++ b/www/inc/rendering/order_listing.php @@ -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 .= " (".i18n("Change").")"; + else + $shippingAddress = "(".i18n("Add").")"; + + if (!isEmpty($comments = $cart->getOrderComments())) + $comments .= " (".i18n("Change").")"; + else + $comments = "(".i18n("Add").")"; + + $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 diff --git a/www/inc/rendering/submit.php b/www/inc/rendering/submit.php index d270f9d..f1af4e8 100644 --- a/www/inc/rendering/submit.php +++ b/www/inc/rendering/submit.php @@ -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 diff --git a/www/index.php b/www/index.php index 23e2d7f..dae6f40 100644 --- a/www/index.php +++ b/www/index.php @@ -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 index 0000000..4017b69 --- /dev/null +++ b/www/template/de/editordercomments.html @@ -0,0 +1,16 @@ +

Hinweis ändern

+
+
+
+
+ +
+
+ +
+ + +
+ +
+
\ No newline at end of file diff --git a/www/template/de/editshippingaddress.html b/www/template/de/editshippingaddress.html new file mode 100644 index 0000000..361cf3a --- /dev/null +++ b/www/template/de/editshippingaddress.html @@ -0,0 +1,17 @@ +

Lieferadresse ändern

+
+
+
+
+ + +
+
+ +
+ + +
+
+ +
\ No newline at end of file diff --git a/www/template/de/orderoverview.html b/www/template/de/orderoverview.html index 7b123c3..d8dd93e 100644 --- a/www/template/de/orderoverview.html +++ b/www/template/de/orderoverview.html @@ -17,7 +17,7 @@
-  +@CUST_SHIPPINGADDRESS@
@@ -25,7 +25,7 @@
- +@CUST_COMMENTS@
-- 1.7.2.5