Rhys ! avatar Rhys ! committed 60f1443

fixed shipping + receipt pages and added some validation

Comments (0)

Files changed (5)

         $.cookie 'cart', cart.join ';'
     $.cookie code, null
 
+window.clear_cart = ->
+    for code in cart_items()
+        $.cookie code, null
+    $.cookie 'cart', null
+
 item_row = (code, editable) ->
     data = retr_item code
     quantity = $.cookie(code) or 1
     store_item checkbox.value, props
 
 $ ->
+    if window.url_basename(document.location.pathname) is 'receipt.php'
+        $.cookie 'receipt', 'yes'
+    else if $.cookie 'receipt'
+        clear_cart()
+        $.cookie 'receipt', null
+
     $('form.cartadd').submit ->
         map_to_items this, store_item_from_row
         map_to_items this, (item) -> update_cart item.value, 1
                 store_item this.id, props
                 update_cart this.id, this.value
                 $(this).closest('tr').attr 'class', ''
+            $(this).closest('form').find('input[type="submit"]').each ->
+                this.disabled = cart_items().length is 0
         else
             alert 'Please enter a valid quantity.'
             this.value = this.defaultValue
+    $('form#shipping').submit ->
+        if $(this).serializeArray().length > 0
+            return true
+        else
+            alert 'You must select a shipping option.'
+            return false

site/global.coffee

-url_basename = (url) ->
+get_parameter = (name) ->
+    match = RegExp('[?&]' + name + '=([^&]*)').exec window.location.search
+    return match && decodeURIComponent match[1].replace /\+/g, ' '
+
+window.url_basename = (url) ->
     li = url.lastIndexOf('/') + 1
     if li is 0
         return url
         return url.substring li, url.length
 
 $ ->
-    cur_bn = url_basename(document.location.pathname) or 'index.html'
+    cur_bn = url_basename(document.location.pathname) or 'index.php'
     $('#left a').each ->
         link_bn = url_basename $(this).attr 'href'
         if link_bn is cur_bn or link_bn is '#'
             $(this).attr 'class', 'selected'
     $('a.print').click ->
         window.print()
+    $('input[type="text"][name="query"]').each ->
+        query = get_parameter 'query'
+        if query
+            this.value = query
+    search_by = get_parameter 'by'
+    if search_by
+        $('input[type="radio"][name="by"]').each ->
+            if this.value is search_by
+                this.checked = true

site/purchase.shpaml

 h1 | Complete purchase
 table.cart.static
     tr
+        th | Quantity
         th | Item
         th | Type
         th | Author/Supplier

site/receipt.shpaml

         span | Print
 table.cart.static
     tr
+        th | Quantity
         th | Item
         th | Type
         th | Author/Supplier
 		"160892"
 	);
 	mysql_select_db("s9510621_db",$DB);
-	$query = "select * from bookShop where ".$searchParam." like '%".$searchValue."%';";
+	$query = "select * from bookShop where ".mysql_real_escape_string($searchParam)." like '%".mysql_real_escape_string($searchValue)."%';";
 	$result = mysql_query($query);
-	if(!$result)
+	if(!$result || mysql_num_rows($result) == 0)
 	{
 		echo "<p>No items found.</p>";
 	}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.