// Shopping cart created by Ethan Schroeder 5-11-99 modified by Greg Poulson 8-7-99
// To include this shopping cart, use include("shoppingcart.php3"); in your code
// Please note the parameters that you will need to call each function with.
// Every function here needs a $table and $session parameter to be passed in.
// You should create a $table variable in the script that calls this class to
// designate the table you are working with. Email questions to ethan@montana.com. The documentation is at: http://www.montana.com/ethan/shop.php3
// If you significantly modify this script, please email me with the changes so I
// can make it better.
// establishes the session variable so we know who is roaming around the web site.
// this session will only be established the first time that the parent page is loaded.
if(!$session && !$ShoppingCart) //make sure this hasn't already been established
{
$session = md5(uniqid(rand())); //creates a random session value
// sets a cookie with the value of session. On my pages, I do a simple test to see if
// the cookie exists on the user's machine ( if($ShoppingCart) ) if it does exist,
// I don't send the session ID's around with every page they visit, I just use the values
// in the cookie.
//set the cookie to remain for 2 hours
SetCookie("ShoppingCart","$session","","/","",0);
}
/*include ('cart.php3');*/
/*for($i=0;$i<=$totrecs;$i++){
SetCookie("bref[]","$batch[$i]");
SetCookie("brefqty[]","$bqty[$i]");}*/
?>
/*echo "$session";
echo "$ShoppingCart";*/
for($i=0;$i<=$totrecs;$i++){
if (isset($batch[$i])==1)
{
$s="$batch[$i]";
$t="$bqty[$i]";
/*echo "$s $i";
echo "$t $i";
echo "
$batch[$i],$prod[$i],$man[$i],$pn[$i],$pd[$i],$dc[$i],$priceu[$i],$free[$i],$pack[$i],$amber[$i],$green[$i],$bqty[$i]
";*/
// Checks to see if they already have that product in their list
$d1=0;
if(isset($ShoppingCart)==1)
{$d1=$ShoppingCart;}
else
{$d1=$session;}
$password="redorchil5429";
mysql_connect("localhost","componentWeb",$password);
$result = mysql("componentforum","SELECT * FROM selections WHERE session=/*'$ShoppingCart'*/'$d1'AND bref='$batch[$i]'");
$num_rows = mysql_num_rows($result);
// they don't have that product in their cart? Put it in.
if($num_rows == 0)
{
mysql_connect("localhost","componentWeb",$password);
$result=mysql("componentforum","INSERT INTO selections (session,bref,prod_type,mfr,part_no,part_desc,date_code,packsize,price_each,ordqty,amberacem_flag,greenacem_flag,date)VALUES(/*'$ShoppingCart'*//*'$session'*/ '$d1','$batch[$i]','$prod[$i]','$man[$i]','$pn[$i]','$pd[$i]','$dc[$i]','$pack[$i]','$priceu[$i]','$bqty[$i]','$amber[$i]','$green[$i]',\N)");
}
// They have the product in their cart already? Add the quantity they specified
// to the product they have in their cart
else
{
/*$row = mysql_fetch_array($result);
$quantity = $quantity + $row[quantity];*/
$result=mysql("componentforum","UPDATE selections SET ordqty='$bqty[$i]' WHERE session='$ShoppingCart' AND bref='$batch[$i]'");
}
}
}
?>
/*$s="";
for($i=0;$i<=$totrecs;$i++){
if (isset($batch[$i])==1)
{
$s=$s."bref=".$batch[$i]." OR ";
$x=$batch[$i];
}
if (isset($bqty[$i])==1)
{
$q=$q."ordqty=".$bqty[$i]." OR ";
$z=$bqty[$i];
}
}
$d= 'bref='.$x;
$f=$s.$d;
echo "$f";
$t= 'ordqty='.$z;
echo "$q";
echo "$t";
$r=$q.$t;
echo "$r";*/
?>