/* CamelCityBuyer Copyright (c) 1996 Noel Hunter */
/* This section must appear FIRST. Please see licensing information below */
if (! $sessionid);
/* Check for a sessionid cookie, and assign one if needed */
$temp1=date("U");
$temp2=getmypid();
$sessionid="s"+strval($temp1)+strval($temp2)+strval(Rand()%1000);
/* Cookie is date + process number + random number */
/* Cookie will expire in one day (60 sec * 60 min * 24 hours) */
SetCookie("sessionid",$sessionid,time()+60*60*24,"/");
endif;
if (! $copyright);
$copyright=1>
endif >
/* CUSTOMIZE THE FOLLOWING: */
$database="camelcityB"; /* The msql database to open */
$table="orders"; /* The msql table to use */
$order="order by sessionid"; /* How to order results from msql select */
/* END OF CUSTOMIZABLE SECTION */
$home_url=$PHP_SELF; /* Pointer to this script for HREFs etc */
$full_url="http://www.camelcity.com";
$main_url="/php/shop.htm";
$list_url="/php/shop-list.phtml";
/* Pointer main menu */
setType($sql,"string"); /* The sql query to send to msql */
Function Add (
/* Adds an item ordered to the database */
global $database,$full_url,$home_url,$list_url,$sessionid,$sql,$table,$itemnumber,$quantity,$color,$size,$print,$price,$description;
/* Assign an order number */
setType($temp1,"string");
setType($temp2,"string");
$temp1=date("U");
$temp2=getmypid();
$orderid="o"+$temp1+$temp2;
$sql = "insert into $table values ('$sessionid','$orderid',$itemnumber,$quantity,'$color','$size','$print',$price,'$description')";
msql($database,"$sql")
>
echo $description >
was added to your order.
);
>
if($add) >
Add() >
endif >
Function Delete (
/* Deletes an item ordered from the database */
global $database,$sql,$sessionid,$table,$to_delete;
if($to_delete=="All");
$sql="delete from $table where sessionid='$sessionid'";
else;
$sql="delete from $table where orderid='$to_delete'";
endif;
msql($database,"$sql") >
The item was deleted from your order.
);
>
if($delete) >
Delete() >
endif >
Function TextButton $action,$name,$value (
/* Prints out the text buttons for you (just a convenience) */
global $database,$full_url,$home_url,$list_url,$sessionid,$sql,$table;
>
);
>
if ($home_url == $list_url) >
else >
Review your order
endif>
if ($home_url == $main_url) >
else >
Shop Main Menu
endif>
Function ImageButton $action,$name,$value,$src,$border,$height,$width (
/* Prints out an image button for you */
global $database,$full_url,$home_url,$list_url,$sessionid,$sql,$table;
>
);
>
Function AddForm $itemnumber,$colors,$sizes,$prints,$price,$description (
/* Prints out a form for ordering an item with form fields nicely formatted */
global $database,$full_url,$home_url,$list_url,$sessionid,$sql,$table;
>
);
>
Function Review (
/* Reviews an order, and allows for deletion of items and or submission */
global $database,$full_url,$home_url,$list_url,$mail,$sessionid,$sql,$table,$Name,$Address,$City,$State,$Zip,$Fax,$Email,$email_to,$to_delete;
/* Fetch the data from msql database and dump it into $result */ ;
$result = msql($database,"select * from $table where sessionid = '$sessionid' $order");
$num_rows = msql_numrows($result);
$num_fields = msql_numfields($result);
$msg="";
setType($amount,"double");
setType($total,"double");
setType($msg,"string");
$total=0.00;
$amount=0.00;
/* Print out the table headers */
$msg="Your Order
";
$msg=$msg+"(if items do not appear as expected, try reloading this page) ";
$field=2;
while ($field < $num_fields);
$msg=$msg+"| "+msql_fieldname($result,$field)+" | \n";
$field++;
endwhile;
$msg=$msg+"Amount | Action |
\n";
/* Output results in a table */ ;
$row=0;
while ($row < $num_rows);
$msg=$msg+"";
$field=2;
/* Output all fields */ ;
while ($field < $num_fields);
/* Determine field type, and set the alignment */ ;
$field_type = msql_fieldtype($result,$field);
switch ($field_type);
case "char";
$align="left"; /* Characters left-aligned */
break;
default;
$align="right"; /* Numbers right-aligned */
break;
endswitch ;
/* Output the data */
$msg=$msg+"| ";
$field_name = msql_fieldname($result,$field);
$msg=$msg+msql_result($result,$row,$field_name)+"  | \n";
$field++;
endwhile;
$msg=$msg+"";
$amount=msql_result($result,$row,"quantity")*msql_result($result,$row,"price");
$msg=$msg+strval(sprintf("%5.2f",$amount));
$total=$total+$amount;
$msg=$msg+" | ";
if ($PHP_SELF == $list_url);
/* Output a delete form, using orderid as the key for deleting */ >
$field_name = msql_fieldname($result,2);
$msg=$msg+"\n |
\n";
else;
$msg=$msg+"Submitted";
endif;
$row++;
endwhile;
$msg=$msg+"
Total of order:" + sprintf("%5.2f",$total)+"\n";
if($mail);
if ($email_to == "order@nowhere" );
>
Your order would have been emailed if an address were entered.
else;
$fp = popen("/usr/sbin/sendmail $email_to","w");
fputs($fp,"Subject: Order $sessionid\n");
fputs($fp,"Reply-To: $Email\n");
fputs($fp,"Content-type: text/html\n\n");
fputs($fp,"\n");
$msg2="Name: $Name
Address: $Address
City: $City
";
$msg2=$msg2 + "State: $State
Zip: $Zip
Fax: $Fax
Email: $Email";
$msg2=$msg2 + "
Order session id: $sessionid
";
fputs($fp,$msg2);
fputs($fp,$msg);
fputs($fp,"\n");
pclose($fp);
$msg="Thank you for your order! The following order information has been emailed to "+$email_to+"
"+$msg2+$msg;
$to_delete="All";
Delete();
endif;
endif;
echo $msg;
);
>