Error . php ?php Cart . php ?php
13. Error . php ?php
require_once libraryconfig.php; pageTitle = Checkout Error;
require_once includeheader.php; ?
pnbsp;ptable width=500 border=0 align=center cellpadding=1 cellspacing=0
tr td align=left valign=top bgcolor=333333 table width=100 border=0
cellspacing=0 cellpadding=0 tr
td align=center bgcolor=EEEEEE pnbsp;p pWe are really sorry for this inconvenience but there was an error when processing
your order. Please contact the site administrator. To go to the main page please a href=plaincart1index.phpclick hereap
pnbsp;ptd tr
tabletd tr
table br
br ?php
require_once includefooter.php; ?
14. Cart . php ?php
require_once libraryconfig.php; require_once librarycart-functions.php;
action = isset_GET[action] _GET[action] = ? _GET[action] : view; switch action
{
case add : addToCart;
break; case update :
updateCart; break;
case delete : deleteFromCart;
break;
Universitas Sumatera Utara
case view : }
cartContent = getCartContent; numItem = countcartContent;
pageTitle = Shopping Cart; require_once includeheader.php;
require_once includemenu.php; show the error message if we have any
displayError; if numItem 0
{ ?
form action=?php echo _SERVER[plaincart1PHP_SELF] . ?action=update; ? method=post name=frmCart id=frmCart
table width=780 border=0 align=center cellpadding=5 cellspacing=1 class=entryTable
tr class=entryTableHeader td colspan=2 align=centerItemtd
td align=centerUnit Pricetd td width=75 align=centerQuantitytd
td align=centerTotaltd td width=75 align=centernbsp;td
tr ?php
subTotal = 0; for i = 0; i numItem; i++
{
extractcartContent[i]; productUrl = home.php?c=cat_idp=pd_id;
subTotal += pd_price ct_qty; ?
tr class=content td width=80 align=centera href=?php echo productUrl; ?img
src=?php echo pd_thumbnail; ? border=0atd tda href=?php echo productUrl; ??php echo pd_name; ?atd
td align=right?php echo displayAmountpd_price; ?td td width=75input name=txtQty[] type=text id=txtQty[] size=5
value=?php echo ct_qty; ? class=box onKeyUp=checkNumberthis; input name=hidCartId[] type=hidden value=?php echo ct_id; ?
input name=hidProductId[] type=hidden value=?php echo pd_id; ? td
td align=right?php echo displayAmountpd_price ct_qty; ?td td width=75 align=center input name=btnDelete type=button
id=btnDelete value=Delete onClick=window.location.href=?php echo _SERVER[PHP_SELF] . ?action=deletecid=ct_id; ?;
style=background:urlimagessubmit.gif
Universitas Sumatera Utara
td tr
?php }
? tr class=content
td colspan=4 align=rightSub-totaltd td align=right?php echo displayAmountsubTotal; ?td
td width=75 align=centernbsp;td tr
tr class=content td colspan=4 align=rightShipping td
td align=right?php echo displayAmountshopConfig[shippingCost]; ?td td width=75 align=centernbsp;td
tr tr class=content
td colspan=4 align=rightTotal td td align=right?php echo displayAmountsubTotal +
shopConfig[shippingCost]; ?td td width=75 align=centernbsp;td
tr tr class=content
td colspan=5 align=rightnbsp;td td width=75 align=center
input name=btnUpdate type=submit id=btnUpdate value=Update Cart style=background:urlimagessubmit.gif
td tr
table form
?php } else
{ ?
pnbsp;ptable width=550 border=0 align=center cellpadding=10 cellspacing=0
tr tdp align=centerYou shopping cart is emptyp
pIf you find you are unable to add anything to your cart, please ensure that your internet browser has cookies enabled and that any other security software is not blocking
your shopping session.p td
tr table
?php }
Universitas Sumatera Utara
shoppingReturnUrl = isset_SESSION[shop_return_url] ? _SESSION[shop_return_url] : index.php;
? table width=550 border=0 align=center cellpadding=10 cellspacing=0
tr align=center tdinput name=btnContinue type=button id=btnContinue value=lt;lt;
Continue Shopping onClick=window.location.href=?php echo shoppingReturnUrl; ?; style=background:urlimagessubmit.giftd
?php if numItem 0
{ ?
tdinput name=btnCheckout type=button id=btnCheckout value=Proceed To Checkout gt;gt; onClick=window.location.href=checkout.php?step=1;
style=background:urlimagessubmit.giftd ?php
} ?
trtrtd ?php
require_once includefooter.php; ?tdtr
table 15. Category-function . php
?php require_once config.php;
CATEGORY FUNCTIONS
Return the current category list which only shows the currently selected category and its children.This function is made so it can also handle deep category levels more
than two levels function formatCategoriescategories, parentId
{
navCat stores all children categories of parentId
navCat = array;
Universitas Sumatera Utara
expand only the categories with the same parent id all other remain compact
ids = array; foreach categories as category
{ if category[cat_parent_id] == parentId
{ navCat[] = category;
} save the ids for later use
ids[category[cat_id]] = category; }
tempParentId = parentId; keep looping until we found the
category where the parent id is 0 while tempParentId = 0
{ parent = arrayids[tempParentId];
currentId = parent[0][cat_id]; get all categories on the same level as the parent
tempParentId = ids[tempParentId][cat_parent_id]; foreach categories as category
{ found one category on the same level as parent
put in parent if its not already in it if category[cat_parent_id] == tempParentId in_arraycategory,
parent {
parent[] = category; }}
sort the category alphabetically array_multisortparent;
merge parent and child n = countparent;
navCat2 = array; for i = 0; i n; i++
{ navCat2[] = parent[i];
if parent[i][cat_id] == currentId { navCat2 = array_mergenavCat2, navCat;
}} navCat = navCat2;
} return navCat;
}
Universitas Sumatera Utara
Get all top level categories function getCategoryList
{
sql = SELECT cat_id, cat_name, cat_image FROM tbl_category
WHERE cat_parent_id = 0 ORDER BY cat_name;
result = dbQuerysql; cat = array;
while row = dbFetchAssocresult {
extractrow; if cat_image
{ cat_image = WEB_ROOT . imagescategory . cat_image;
} else {
cat_image = WEB_ROOT . imagesno-image-small.png; }
cat[] = arrayurl = _SERVER[PHP_SELF] . ?c= . cat_id, image = cat_image,
name = cat_name; }
return cat; }
Fetch all children categories of id. Used for display categories function getChildCategoriescategories, id, recursive = true
{
if categories == NULL {
categories = fetchCategories; }
n = countcategories; child = array;
for i = 0; i n; i++ {
catId = categories[i][cat_id]; parentId = categories[i][cat_parent_id];
if parentId == id {
child[] = catId; if recursive
{
Universitas Sumatera Utara
child = array_mergechild, getChildCategoriescategories, catId; }}}
return child; }
function fetchCategories {
sql = SELECT cat_id, cat_parent_id, cat_name, cat_image, cat_description FROM tbl_category
ORDER BY cat_id, cat_parent_id ; result = dbQuerysql;
cat = array; while row = dbFetchAssocresult
{ cat[] = row;
} return cat;
} ?
16. Cart-function . php ?php