"; #print_r($_REQUEST); if($gift_registry_enabled=='N'){error(15);exit;} $shop=1; ($_POST) ? ($all = $_POST) : ($all = $_GET); $gr_itemid = isset($all['gr_itemid']) ? $all['gr_itemid'] : ""; $gr_id = isset($all['gr_id']) ? $all['gr_id'] : ""; $cart = isset($all['cart']) ? $all['cart'] : ""; $cat = isset($all['cat']) ? $all['cat'] : ""; $productandqty = isset($all['productandqty']) ? $all['productandqty'] : ""; $submitact = isset($all['submitact']) ? $all['submitact'] : ""; $order_by = isset($all['order_by']) ? $all['order_by'] : ""; $checkedproductoptionids = isset($all['checkedproductoptionids']) ? $all['checkedproductoptionids'] : ""; #changed, as on line 29 it was setting to "" anyway if($gr_id == ""){ header("Location: gr_main.php?cart=$cart"); exit; } if($_SESSION['shopuserid'] == "") { header("Location: gr_main.php"); exit; } else { echo ''; } if($all['process']=='up'){ $prod_sequence = (isset($_POST['prod_sequence']) && $_POST['prod_sequence'] != "" && $_POST['prod_sequence'] >= 1) ? $_POST['prod_sequence'] : 1; $order_by = 'grp.sequence'; $seq = mysql_result_(mysql_query_("SELECT sequence FROM gift_registry_products WHERE gift_reg_products_id=$gr_itemid AND gift_registry_id=$gr_id"),0); $qry = "UPDATE gift_registry_products SET sequence=sequence-$prod_sequence WHERE gift_reg_products_id=$gr_itemid AND gift_registry_id=$gr_id"; mysql_query_($qry); $current_seq = mysql_result_(mysql_query_("SELECT sequence FROM gift_registry_products WHERE gift_reg_products_id=$gr_itemid AND gift_registry_id=$gr_id"),0); $previous_seq = $seq-1; //$prev_item = $item_array[$seq-1]; $qry = "UPDATE gift_registry_products SET sequence=sequence+1 WHERE sequence>=$current_seq AND sequence<=$previous_seq AND gift_reg_products_id<>$gr_itemid AND gift_registry_id=$gr_id"; mysql_query_($qry); $item_name = mysql_result_(mysql_query_("select p.name from product p, gift_registry_products grp, productoption po where gift_reg_products_id=$gr_itemid AND gift_registry_id=$gr_id and grp.productoptionid=po.id and po.productid= p.id and p.is_deleted='N'"),0); $msg = "Item \"$item_name\" has been moved up."; } if($all['process']=='down'){ $prod_sequence = (isset($_POST['prod_sequence']) && $_POST['prod_sequence'] != "" && $_POST['prod_sequence'] >= 1) ? $_POST['prod_sequence'] : 1; $order_by = 'grp.sequence'; $seq = mysql_result_(mysql_query_("SELECT sequence FROM gift_registry_products WHERE gift_reg_products_id=$gr_itemid AND gift_registry_id=$gr_id"),0); $qry = "UPDATE gift_registry_products SET sequence=sequence+$prod_sequence WHERE gift_reg_products_id=$gr_itemid AND gift_registry_id=$gr_id"; mysql_query_($qry); $current_seq = mysql_result_(mysql_query_("SELECT sequence FROM gift_registry_products WHERE gift_reg_products_id=$gr_itemid AND gift_registry_id=$gr_id"),0); $previous_seq = $seq-1; //$prev_item = $item_array[$seq+1]; $qry = "UPDATE gift_registry_products SET sequence=sequence-1 WHERE sequence>=$previous_seq AND sequence<=$current_seq AND gift_reg_products_id<>$gr_itemid AND gift_registry_id=$gr_id"; mysql_query_($qry); //$qry = "UPDATE gift_registry_products SET sequence=sequence-1 WHERE gift_reg_products_id=$prev_item AND gift_registry_id=$gr_id"; //mysql_query_($qry); $item_name = mysql_result_(mysql_query_("select p.name from product p, gift_registry_products grp, productoption po where gift_reg_products_id=$gr_itemid AND gift_registry_id=$gr_id and grp.productoptionid=po.id and po.productid= p.id and p.is_deleted='N'"),0); $msg = "Item \"$item_name\" has been moved down."; } //echo "
";print_r($_REQUEST);
$i=0;
$gr_id = intval($gr_id);
$cart  = intval($cart);

$quantity = intval($quantity);
if ($quantity < 1)  $quantity = 1;

# if they've not got a valid existing gift registry,
# redirect to this page again need to check this piece of code
$result = mysql_query_("SELECT customer_id, registry_title, registry_custom_text, eventdate, eventtype, creationdate FROM gift_registry WHERE gift_registry_id='".$gr_id."'");
if($result && mysql_num_rows_($result)){
	list($customer_id, $registry_title, $registry_custom_text, $eventdate, $eventtype, $creationdate) = mysql_fetch_row_($result);
	mysql_free_result_($result);    
}

$customer_email_registery = mysql_result_(mysql_query_("Select email From customer Where id = ".$customer_id), 0);
$customer_email = mysql_result_(mysql_query_("Select email From customer Where id = ".$_SESSION['shopuserid']), 0);

$guest = 1;
if($customer_email_registery == $customer_email){
	$guest = 0;
}

switch ($submitact) 
{
	# if they pressed a button on this Gift Registry page, do the relevant action...
	# an array of arrays called $actionresult[] is filled in as stuff is done
	# each element contains ...
	#	a productoption id
	#       AND
	#  a result code
	#		0 = added OK
	#		1 = qty updated OK
	#		2 = removed OK
	#		3 = qty updated on adding
	#		4 = qty=0, removed OK
	#		5 = invalid quantity (when updating)
	#		6 = invalid quantity (when adding)
	#		7 = quantity exceeds stock limit (but thats OK)
	#		8 = quantity exceeds stock limit (couldnt set)

	case BTN_ALPHABETIZE:
		$order_by = "p.name";
		break;
		
	case BTN_DELITEMS:
		if ($checkedproductoptionids) 
		{
			while (list ($key, $value) = each ($checkedproductoptionids)) 
			{
				list($productoptioncode,$CustText)   = explode("::",$value);
				deletegiftregistry($gr_id,$productoptioncode,$CustText);
				$actionresult[] = array($productoptioncode,2);
			}
		}
		break;
		
	case BTN_UPDGRQTYS:
		if ($productandqty) 
		{
			for($i = 0; $i < sizeof($productandqty);$i++)
			{
				$k = "";
				list($k,$v) = explode("::",$productandqty[$i]);
				$arr[] = $k;
			}
	
			for ($i = 0; $i < sizeof($arr); $i+= 2)
			{
				 if (empty($qty[$arr[$i]])){
					$qty["" .$arr[$i]. ""] += $arr[$i+1];
				 } else{
					$qty["" .$arr[$i]. ""] += $arr[$i+1];
				 }
			}
			$odd = true;
			while (list ($key, $element) = each ($productandqty)) 
			{
				if ($odd) 
				{
					list($productoptioncode,$ItemCustomText) = explode("::", $element);
					$odd = false;
				}
				else
				{
					$newquantity = $element;
					if (validquantityforupdate($newquantity)) {
						switch (updateqtygiftregistry($gr_id,$productoptioncode,$newquantity,$ItemCustomText)) 
						{
						case 0: # no change required
							break;
						case 1: # quantity updated ok
							$actionresult[] = array($productoptioncode,1);  break;
						case 2: # deleted
							$actionresult[] = array($productoptioncode,4);  break;
						case 3: # quantity updated but not enough stock warning
							$actionresult[] = array($productoptioncode,7);  break;
						case 4: # quantity NOT updated - not enough stock
							$actionresult[] = array($productoptioncode,8);  break;
						}
					} else {
						$actionresult[] = array($productoptioncode,5);
					}
					$odd = true;
				}
			}
		}
		break;
	case "":
		# fall through
	case NULL:
		break;
	default:
		exit("You submitted from an unknown button - $submitact!");
		break;
}
//if(!isset($order_by)) $order_by='c.id';
if($order_by == "") $order_by='grp.sequence';
#echo $order_by;
# now display the cart
echo showhead($shop,$cat,$cart,'');

if(is_array($actionresult) && in_array(9,$actionresult[0]))
{
	echo ""; 
	while (list ($key , $value) = each ($actionresult)) 
	{
		echo "";
	}
	echo "
"; switch ($value[1]) { case 9: //$qry_getprodoption = mysql_query_("Select * $ProId = explode('-', $prodoptscode); $Sql_Qry = "select productid FROM productoption where id =". $ProId[$i+1]; $qry_res = mysql_query_($Sql_Qry); list($idd) = mysql_fetch_row_($qry_res); $qry_getitle = mysql_query_("SELECT name FROM productoptionlevel WHERE 1 AND productid = $idd and level= $restorelevel[$i]"); list($getname) = mysql_fetch_row_($qry_getitle); if ($HTTP_REFERER <> "" ){ $linkback = $HTTP_REFERER; } elseif($_SESSION['myreferer'] <> ""){ $linkback = $_SESSION['myreferer']; } echo "Product not added to the cart as the required product option ( ".$getname." ) is not selected. back
"; $i++; break; } echo "
"; } ?>
0){ $j = 0; while($row_categories = mysql_fetch_array_($rs_categories)){ $grpid = $row_categories['gift_reg_products_id']; $poid = $row_categories['productoptionid']; $sql_categories = "select c.id from category c, product_category pc, gift_registry_products grp, productoption po where grp.gift_reg_products_id=$grpid and grp.productoptionid=$poid and grp.productoptionid=po.id and po.productid= pc.product_pc_id and pc.category_pc_id=c.id and po.level='1' and c.is_deleted='N'"; $j += 1; $cat_id = mysql_result_(mysql_query_($sql_categories),0); mysql_query_("Update gift_registry_products Set product_category = $cat_id, sequence=$j Where gift_reg_products_id=$grpid And productoptionid=$poid"); } } ##################### To Link Gift Registry Items with Categories ############## product_category = $cat_id $sql = "SELECT p.isgiftcert,p.isebook,p.sku_pno, po.id, p.CustomText, grp.product_custom_text AS ItemCustomText, p.name, po.description, p.price, grp.products_wants, grp.productoptioncombo, p.imageurl, c.name as catname, c.id as catid, grp.products_has, p.id, gift_reg_products_id, grp.sequence FROM product p INNER JOIN productoption po ON po.productid=p.id INNER JOIN gift_registry_products grp ON grp.productoptionid=po.id INNER JOIN product_category pc ON pc.product_pc_id=p.id INNER JOIN category c ON c.id=pc.category_pc_id WHERE grp.gift_registry_id='$gr_id' AND po.level='1' AND grp.product_category = c.id ORDER BY $order_by"; $qry_getproducts = mysql_query_($sql); if(!$guest){ ?> "; } ?> \n"; $hasitem = false; $totalsofar = $oldcatid = 0; // Display each item //start listing if(!mysql_num_rows_($qry_getproducts)){?>
here"); if($guest) echo(" | Go to Search Page

"); ?>
Title:      Event Type:
$msg
There are no items at present in the Registry!
Seq.";}?> Category"; }?>  "); } ?> Qty"); echo(""); }?> ", "", "", "", "", "", ""; } $hasitem = true; // Level 1 has description - start brackets and description.... $prodname .= " ($prodoptdesc"; // build rest of description out of level 2+ product options $prodoptcodewithout1 = preg_replace("/^[0-9]+(\-)?(.*)/","\\2",$prodoptcode); // get rid of first productoption code $prodoptcodes = explode("-",$prodoptcodewithout1); $prodoptprice = 0;$ind=1; $opttypeflag = false; while (list($key,$prodopt) = each($prodoptcodes)) { if($prodopt != '') { if($guest){ $ind++; echo ""; } $qry_getprodoptdesc = mysql_query_("SELECT description, weight, price, type,level FROM productoption WHERE id='$prodopt'"); list ($description, $optweight, $optprice, $opttype,$optlevel) = mysql_fetch_row_($qry_getprodoptdesc); if ($description != '') { $prodname .= ", $description"; } if ($opttypeflag == false) { if ($opttype == 1){ // Option ADD $prodoptprice = $prodoptprice + $optprice; } elseif ($opttype == 2) { // Option SUBTRACT $prodoptprice = $prodoptprice - $optprice; } elseif ($opttype == 3) { // Option OVERRIDE if ($optprice != 0) { $prodoptprice = $optprice; $opttypeflag = true; } } } } } $prodname = str_replace("(, ", "(", $prodname); $prodname .= ")"; $prodname = str_replace(" ()", "", $prodname); $price = ($opttypeflag == true) ? $prodoptprice : ($pprice + $prodoptprice); if($oldcatid != $catid && !$guest) { $oldcatid = $catid; echo "\n\n", "\n"; } echo ($alternateColor) ? "\n" : "\n"; //"\n" $alternateColor = $alternateColor; if(!$guest){ echo ""; } $ii++; if(!$guest){ echo "\n"; } echo "\n", "\n"; echo "\n"; if(!$guest) { echo ""; } else { echo "\n"; } echo "\n"; if($guest) { if($wants-$has > 0) { echo(""); }else{ echo(""); } } echo "\n\n"; if($guest) echo(""); //product show loop ends here echo ""; } ?>
Item Image Price Wants Has  
$catname
"; if($ii != 1){ echo ""; } if($ii != $total_itmes){ echo "\n"; } echo ""; $hrefActionSet = "href=\"\" onClick=\"javascript:window.open('". URL_START . "item_detail.php?prod_id=$prod_id','$largerimagewin','width=500, height=450, toolbar=no, resizable=yes'); return false;\""; echo "$prodname
"; if($isgiftcert == 0 && $sku_pno_display == 1){ echo ($sku_pno != "") ? "SKU/Part No: $sku_pno
" : "SKU/Part No: *
"; } if ($ItemCustomText != ''){ $ItemCustomTextString = fnGetCustomTextString($ItemCustomText, $prod_id); echo "
this is test $ItemCustomTextString  "; } echo "
\n"; //this section is to make it javascript compatible $name_for_link = $name; $name_for_link = str_replace("\"", "'", $name_for_link); $name_for_link = str_replace("'", "\'", $name_for_link); if ($imageurl) { if ($isgiftcert && strpos($imageurl, "giftcert.jpg")) { if(file_exists(IMGS_DIR."giftcert_th.jpg")){ $thumbimage = str_replace("giftcert.jpg","giftcert_th.jpg",$imageurl); echo "\"$name\"
Click for image
\n"; } else{ //echo "Thumbnail Unavailable
"; if(file_exists(IMGS_DIR."giftcert.jpg")) echo "Click for image\n"; } } else { $thumbimage = $imgext = ""; if($imageurl != ""){ if (preg_match("/.*\.(jpg|jpeg|jpe|gif)$/i",$imageurl,$eregarray)) { $imgext = $eregarray[1]; } } /* if (strpos($imageurl, $prod_id.".".$imgext)) { $thumbimage = str_replace($prod_id .".". $imgext, $prod_id ."_th.". $imgext, $imageurl); } */ $lpos = strrpos($imageurl,"/"); $imgname = trim(substr($imageurl,$lpos+1,strlen($imageurl))); $IsThumbAlreadyExists = substr($imgname,0,strrpos($imgname,".")); $thumbimage = "./images/".$IsThumbAlreadyExists."_th.".$imgext;//IMGS_DIR_URL_ALIAS.$IsThumbAlreadyExists."_th.".$imgext; if($thumbimage != "" && file_exists(IMGS_DIR.$IsThumbAlreadyExists."_th.".$imgext)){ echo "\"$name\"
Click for image
\n"; } else { //echo "Thumbnail Unavailable
"; if(file_exists(IMGS_DIR.$IsThumbAlreadyExists.".".$imgext)) echo "Click for image"; } } } else { echo " "; } echo "
", showmoney($price, $shop), "\n"; echo "\n"; # quantity text box echo "$wants".$has.""); if($data[0]['addtocart_as_image'] == "Y") { //if(preg_match("/^http:\/\//",$data[0]['addcartimagename'],$matches)) if(1==2){ ?> "); } echo("  
   
"); ?> \n"; } ?>
"; // Make description from code $prodoptcode = $value[0]; preg_match("/^([0-9]+)/",$prodoptcode,$eregarray); $prodopt1 = $eregarray[1]; $qry_getproductdesc = mysql_query_("SELECT product.name, productoption.description FROM product, productoption WHERE product.is_deleted='N' AND productoption.productid = product.id AND productoption.id = '$prodopt1'"); list ($prodname,$prodoptdesc) = mysql_fetch_row_($qry_getproductdesc); if ($prodoptdesc) { // Level 1 has description - start brackets and description.... $prodname .= " ($prodoptdesc"; // build rest of description out of level 2+ product options $prodoptcode = preg_replace("/^[0-9]+\-(.*)/","\\1",$prodoptcode); // get rid of first productoption code $prodoptcodes = explode("-",$prodoptcode); while (list($key,$prodopt) = each($prodoptcodes)) { $qry_getprodoptdesc = mysql_query_("SELECT description FROM productoption WHERE id='$prodopt'"); list ($description) = mysql_fetch_row_($qry_getprodoptdesc); $prodname .= ", $description"; } $prodname .= ")"; } ?> 0) echo "The item '$prodname' was added to your gift registry."; break; case 1 : echo "The quantity for the item '$prodname' was updated in your gift registry."; break; case 2: echo "The item '$prodname' was removed from your registry."; break; case 3: echo "The quantity for the item '$prodname' was updated (you added it when it was already in your gift registry.)"; break; case 4: echo "The item '$prodname' was removed from your gift registry (you selected 0 quantity)."; break; case 5: echo "You gave the item '$prodname' an invalid quantity so it couldn't be updated."; break; case 6: echo "You gave the item '$prodname' an invalid quantity so it couldn't be added."; break; } echo "