<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com � 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "includes/config.php";
include "includes/session.php";
include "includes/functions.php";

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}
 if (function_exists('session_register'))
   session_register('SESS_card_id');

if (isset($_GET["productid"]) and $_GET["productid"] != "") {
    $productid = $_GET["productid"];
} else if (isset($_POST["productid"]) and $_POST["productid"] != "") {
    $productid = $_POST["productid"];
}


/*-----------Multicart 2.0 Upgradation------------*/

$check_shipping_enable = checkShippingEnable();


if (($_POST["btnAddToCart"] == "Add to Cart") || (($_GET["action"] == "cart") and ($_GET["productid"] != ""))) {
    $message = "" ;
	if(!isset($_SESSION["sess_userid"]) || ($_SESSION["sess_userid"]=="") ){
		//header("Location:login.php?action=cart&productid=$productid");
		//exit;
		
				
/*----------Checking digital product starts------------*/		

//if($check_shipping_enable == "Y")
//{ // shipping enable checking starts



		$select_cart = "SELECT cart_id FROM ".$tableprefix."cart WHERE visitor_cart_id = ".GetSQLValueString(session_id(),"text");
																
		$result_cart = mysql_query($select_cart);
		
		if(mysql_num_rows($result_cart) > 0)
		{

		
					$select_digital_check = "SELECT ct.cart_id FROM ".$tableprefix."cart ct,".$tableprefix."products  prd
											 WHERE ct.product_id = prd.product_id 
											  AND prd.vdigital_product = 'Y'
											  AND ct.visitor_cart_id = '".addslashes(session_id())."'";
											  
					//echo $select_digital_check;						  
																  
					$result_digital_check = mysql_query($select_digital_check) or die(mysql_error());		
					
					
					/*---checking gift coupon--*/	
							
					$select_gift_coupon = "SELECT prd.product_id FROM ".$tableprefix."products prd,".$tableprefix."categories ctry,
												".$tableprefix."cart ct
										   WHERE prd.product_category = ctry.category_id
										    AND ct.product_id = prd.product_id
											AND ctry.gift_certificate_flag = 'Y'
											AND ct.visitor_cart_id = '".addslashes(session_id())."'";
											
										
					//echo $select_gift_coupon; 					
										
					$result_gift_coupon   = mysql_query($select_gift_coupon) or die(mysql_error());	
					
					
					//echo "digital=".mysql_num_rows($result_digital_check)."<br>";
					//echo "gift=".mysql_num_rows($result_gift_coupon)."<br>";
					
					
																											
					if(mysql_num_rows($result_digital_check) > 0 || mysql_num_rows($result_gift_coupon) > 0)
					{
					
											
					
						$select_digital = "SELECT prd.product_id FROM ".$tableprefix."products prd
										   WHERE prd.vdigital_product = 'Y'
										    AND prd.product_id = '".addslashes($productid)."'";
											
						//echo $select_digital;					
											
											
						$result_digital   = mysql_query($select_digital) or die(mysql_error());
																								
						/*---checking gift coupon--*/	
							
						$select_gift_coupon = "SELECT prd.product_id FROM ".$tableprefix."products prd,".$tableprefix."categories ctry
											   WHERE prd.product_category = ctry.category_id
												AND ctry.gift_certificate_flag = 'Y'
												AND prd.product_id = '".addslashes($productid)."'";
												
						//echo $select_gift_coupon;						
						
						$result_gift_coupon   = mysql_query($select_gift_coupon) or die(mysql_error());	
						
						if(mysql_num_rows($result_digital) == 0 && mysql_num_rows($result_gift_coupon) == 0)
						{
												
							header("Location:viewcart.php?msg=cart_error_nondigital");
							//echo "Since the cart contains digital product adding a non digital product is not possible !!";
							
							exit;
						
						}
						
						
						
					
					}				  
					else
					{
/*----------Checking digital product ends------------*/		
			
			
/*----------Checking non digital product starts------------*/		
					
							$select_digital = "SELECT prd.product_id FROM ".$tableprefix."products prd
										   	   WHERE prd.vdigital_product = 'Y'
											   	AND prd.product_id = '".addslashes($productid)."'";
												
							//echo $select_digital; 					
												
							$result_digital   = mysql_query($select_digital) or die(mysql_error());	
							
							if(mysql_num_rows($result_digital) > 0)
							{
								
								//$cart_error = "Since the cart contains non digital product adding a digital product is not possible !!";
								header("Location:viewcart.php?msg=cart_error_digital");
								exit;
							
							}
							
						/*---checking gift coupon--*/	
							
							$select_gift_coupon = "SELECT prd.product_id FROM ".$tableprefix."products prd,".$tableprefix."categories ctry
										   	       WHERE prd.product_category = ctry.category_id
												    AND ctry.gift_certificate_flag = 'Y'
											   	    AND prd.product_id = '".addslashes($productid)."'";
												
							//echo $select_digital; 					
												
							$result_gift_coupon   = mysql_query($select_gift_coupon) or die(mysql_error());	
							
							if(mysql_num_rows($result_gift_coupon) > 0)
							{
								
								//$cart_error = "Since the cart contains non digital product adding a digital product is not possible !!";
								header("Location:viewcart.php?msg=cart_error_digital");
								exit;
							
							}
							
										
							
					}		  
					
						
/*----------Checking non digital product ends------------*/	
		
					
		}	
		
//} // shipping enable checking ends			


		
		
		$sql = "SELECT cart_id FROM ".$tableprefix."cart  WHERE product_id = '".addslashes($productid)."' and visitor_cart_id = '".addslashes(session_id())."' ";
		$res = mysql_query($sql);
		if(mysql_num_rows($res) > 0 ){
			header("Location:viewcart.php?msg=updateqty");
			exit;
		}
		$time =  time();
		$sql1 = "INSERT INTO ".$tableprefix."cart (visitor_cart_id,product_id,quantity,status,datetime_added) VALUES ('".addslashes(session_id())."','".addslashes($productid)."','1','0','".addslashes($time)."') ";
		$res = mysql_query($sql1);
		//echo $sql1;
		
		$cart_insert_id = mysql_insert_id();
		$_SESSION['SESS_card_id'] = $cart_insert_id;	
		header("Location:viewcart.php");
		
		exit;
	}else{
		
		
//if($check_shipping_enable == "Y")
//{ // shipping enable checking starts		
				
/*----------Checking digital product starts------------*/		



		$select_cart = "SELECT cart_id FROM ".$tableprefix."cart WHERE user_id = '".addslashes($_SESSION["sess_userid"])."'";
		$result_cart = mysql_query($select_cart);
		
		if(mysql_num_rows($result_cart) > 0)
		{

		
					$select_digital_check = "SELECT ct.cart_id FROM ".$tableprefix."cart ct,".$tableprefix."products  prd
											 WHERE ct.product_id = prd.product_id 
											  AND prd.vdigital_product = 'Y'
											  AND ct.user_id = '".addslashes($_SESSION["sess_userid"])."'";
					 
					$result_digital_check = mysql_query($select_digital_check) or die(mysql_error());		
					
					
					/*---checking gift coupon--*/	
							
					$select_gift_coupon = "SELECT prd.product_id FROM ".$tableprefix."products prd,".$tableprefix."categories ctry,
												".$tableprefix."cart ct
										   WHERE prd.product_category = ctry.category_id
										    AND ct.product_id = prd.product_id
											AND ctry.gift_certificate_flag = 'Y'
											AND ct.user_id = '".addslashes($_SESSION["sess_userid"])."'";
											
										
					//echo $select_gift_coupon; 					
										
					$result_gift_coupon   = mysql_query($select_gift_coupon) or die(mysql_error());	
					
					
																							
					if(mysql_num_rows($result_digital_check) > 0 || mysql_num_rows($result_gift_coupon) > 0)
					{
					
						$select_digital = "SELECT prd.product_id FROM ".$tableprefix."products prd
										   WHERE prd.vdigital_product = 'Y'
										    AND prd.product_id = '".addslashes($productid)."'";
						$result_digital   = mysql_query($select_digital) or die(mysql_error());
						
						
						
					/*--gift coupon check---*/	
						
						$select_gift_coupon = "SELECT prd.product_id FROM ".$tableprefix."products prd,".$tableprefix."categories ctry
											   WHERE prd.product_category = ctry.category_id
												AND ctry.gift_certificate_flag = 'Y'
												AND prd.product_id = '".addslashes($productid)."'";
												
						//echo $select_gift_coupon;						
						
						$result_gift_coupon   = mysql_query($select_gift_coupon) or die(mysql_error());
						
						if(mysql_num_rows($result_digital) == 0 && mysql_num_rows($result_gift_coupon) == 0)
						{
												
							header("Location:viewcart.php?msg=cart_error_nondigital");
							//echo "Since the cart contains digital product adding a non digital product is not possible !!";
							
							exit;
						
						}
					
					
					}				  
					else
					{
/*----------Checking digital product ends------------*/		
			
			
/*----------Checking non digital product starts------------*/		
					
							$select_digital = "SELECT prd.product_id FROM ".$tableprefix."products prd
										   	   WHERE prd.vdigital_product = 'Y'
											    AND prd.product_id = '".addslashes($productid)."'";
							$result_digital   = mysql_query($select_digital) or die(mysql_error());	
							
							if(mysql_num_rows($result_digital) > 0)
							{
								
								//$cart_error = "Since the cart contains non digital product adding a digital product is not possible !!";
								header("Location:viewcart.php?msg=cart_error_digital");
								exit;
							
							}
							
							/*---checking gift coupon--*/	
							
							$select_gift_coupon = "SELECT prd.product_id FROM ".$tableprefix."products prd,".$tableprefix."categories ctry
										   	       WHERE prd.product_category = ctry.category_id
												    AND ctry.gift_certificate_flag = 'Y'
											   	    AND prd.product_id = '".addslashes($productid)."'";
												
							//echo $select_digital; 					
												
							$result_gift_coupon   = mysql_query($select_gift_coupon) or die(mysql_error());	
							
							if(mysql_num_rows($result_gift_coupon) > 0)
							{
								
								//$cart_error = "Since the cart contains non digital product adding a digital product is not possible !!";
								header("Location:viewcart.php?msg=cart_error_digital");
								exit;
							
							}
							
										
							
					}		  
					
/*----------Checking non digital product ends------------*/	
			
		}		
		
//} // shipping enable checking ends		
		
		$sql = "SELECT cart_id FROM ".$tableprefix."cart  WHERE product_id = '".addslashes($productid)."' and user_id = '".addslashes($_SESSION["sess_userid"])."' ";
		$res = mysql_query($sql);
		if(mysql_num_rows($res) > 0 ){
			header("Location:viewcart.php?msg=updateqty");
			exit;
		}
		$time =  time();
		$sql1 = "INSERT INTO ".$tableprefix."cart (user_id,product_id,quantity,status,datetime_added) VALUES ('".addslashes($_SESSION["sess_userid"])."','".addslashes($productid)."','1','0','".addslashes($time)."') ";
		$res = mysql_query($sql1);
		
		$cart_insert_id = mysql_insert_id();
		$_SESSION['SESS_card_id'] = $cart_insert_id;		
		
		header("Location:viewcart.php");
		exit;
	}


}


$prodimagedir = "products/";

$sql=" SELECT * FROM ".$tableprefix."products  WHERE product_id = '".addslashes($productid)."' ";
$sess_back= $_SERVER["PHP_SELF"] . "?begin=" . $begin . "&num=" . $num . "&numBegin=" . $numBegin . "&cmbSearchType=" . $cmbSearchType . "&txtSearch=" . $txtSearch."&catid=" . $catid;
//$_SESSION["gbackurl"] = $sess_back;
$rs = mysql_query($sql);
if(mysql_num_rows($rs)!=0){
	$prow = mysql_fetch_array($rs);
	$artistid =$prow["product_artist_id"];
}

/*Report to display the number of times each product viewed*/

if($_SESSION["sess_userid"] != "")
{
	productViewedReport(GetSQLValueString($productid,"text"),$_SESSION["sess_userid"]);
}	

/*display the active template*/

$active_template = displayTemplate();


include "includes/htmltop.php";

/* Top File Name */

include_once ("includes/".$active_template[0]);

?>
<script language="JavaScript" type="text/JavaScript">
function clickSearch()
{
	document.frmCatalog.submit();
}
function openWindow(id)
{
	var url = "viewimage.php?id="+id;
	window.open(url,"Image","height=500,width=500,scrollbars=yes");
}
</script>



			<div align="left" class="detail_pageouterdiv">

			<div align="left" class="main_body">
			<!--mainbody area start -->
			
		<!--center content area start-->		

			<form name="frmProductDetail" action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST" >
			<input type="hidden" name="productid" value="<?php echo $productid ;?>">
			
				
			<div align="left" id="item_details">
				<!--items display area start -->
				
					<div align="left" id="items_top_area">
							
							<div align="left" id="items_top_area_ttl"><?php echo PRODUCT_DETAILS_TEXT;?></div>
					</div>
					
<?php
							if ($prow["product_image_small"]!= "") {
								if ($prow["product_image_big"]!= "") {
									$imageurl =  "<a href='#' onclick='openWindow(".addslashes($productid).");'> ";
									if(!function_exists('gd_info')){
										$imageurl .= "<img src='".$prodimagedir.urlencode($prow["product_image_small"])."' border='0' width='178' height='200' >";
									}else{
										
										$imageurl .= "<img src='products/".$prow["product_image_small"]."' border='0' width='178' height='200' >";
										
									}
							
									$imageurl .= "</a>";
								}else{
									if(!function_exists('gd_info')){
										$imageurl .= "<img src='".$prodimagedir.urlencode($prow["product_image_small"])."' border='0' width='178' height='200' >";
									}else{
										
										
										//$imageurl .= "<img src='getimagethumbnail.php?imagename=".urlencode($prow["product_image_small"])."' border='0'>";
										
										//$resized_image_name = generateThumbNailNew("./products/".$prow["product_image_small"],"./products/".$prow["product_image_small"],100,100);
										
										//echo $resized_image_name;
										
										$imageurl .= "<img src='products/".$prow["product_image_small"]."' border='0' width='178' height='200'>";
										
										
									}
								}
							
							}else{
								$imageurl = "<img src='".$prodimagedir . "noimage.jpg' width='178' height='200' border='0' >";
							}
							if( intval($prow["product_stock"]) > 0){
									$productinstock = true;
							}else{
								$productinstock = false;
							}
							$artistname = getArtistName($artistid);
							
if(mysql_num_rows($rs)>0) // if product found start
{							
?>								
					<div align="center" id="items_display_area">
					<div id="itemBigimage">
						<div id="productBigimage"><?php echo $imageurl?></div>	
					</div>	
								
							<div id="itemDescription">
							  <h4 class="productHead"><?php echo ($prow["product_name"]) ;?></h4>
							 <p>
<?php 
echo stripslashes($prow["product_description"]);
?>
</p>
							  
							<div align="center"><input type="button" name="back" value="&nbsp;&nbsp;&nbsp;<?php echo BACK_TEXT;?>&nbsp;&nbsp;&nbsp;"  class="button" onClick="window.location='productdetails.php?productid=<?php echo $_GET['productid']?>'"></div>
							
							</div>
							
							
<!--Product More Images Begin------->
								
<?php

	if($settings[0] == "Y" && $more_image_flag == 1)
	{
				
		   if($_GET['productid'] != '')
		   {
		   
				$prodimagedir = "products/bulk_images/";
				$i=1;
				$j=1;
				$sql=" SELECT vimage_name,vimage_description
					   FROM ".$tableprefix."product_view_images 
						WHERE vproduct_image_delete_status != 'Y' AND nimage_productid = ".GetSQLValueString($_GET['productid'],"text")." LIMIT 0,9 ";
				$result=mysql_query($sql) or die(mysql_error());
				if(mysql_num_rows($result) > 0 )
				{
				
																				
					while($row = mysql_fetch_array($result))
					{
					   
						$imageurl = "<img src='$prodimagedir".urlencode($row["vimage_name"])."' border='0' height='60' width='80'>";
	
?>							
							
							<div>
<?php 						
							echo $imageurl;
	            			echo $row['vimage_description'];
							 
?>							 
							</div>
							
<?php				 		 
																	 
																							 
						} // end while
					
					} // end if
					
				}	
				
			}
			
}
else
{
?>							
							<div align="center" id="items_display_area"><span class="text_information"><?php echo PRODUCT_NOT_FOUND_TEXT;?></span></div>				
<?php
} // if product found end
?>		

<div class="clear"></div>
        </div>
				</form>	
	</div>	
<!--Product More Images End------->					

							<div class="detailsBotLinks">
								<a href="./postartistfeedback.php?artistid=<?php echo $artistid;?>&productid=<?php echo $productid;?>"><?php echo POST_SELLER_FEEDBACK_TEXT?></a>&nbsp;&nbsp;|&nbsp;&nbsp;
								<a href="./artistfeedbacks.php?artistid=<?php echo $artistid;?>&productid=<?php echo $productid;?>"><?php echo VIEW_SELLER_FEEDBACK_TEXT;?></a>&nbsp;&nbsp;|&nbsp;&nbsp;
								
<?php

/*---------Multicart 2.0 Upgradation---------*/

// show the friendly url  based on config settings

if($enable_seller_friendly == "Y")
{

?>								
								
								
								<a href="store/<?php echo $artistname;?>"><?php echo SELLER_PORTFOLIO_LINK;?></a>
<?php
}
else
{
?>

								<a href="showportfolio.php?artistid=<?php echo $artistid?>"><?php echo SELLER_PORTFOLIO_LINK;?></a>

<?php
}
if($_SESSION["sess_userid"]!="")
{								

?>
								
								&nbsp;&nbsp;|&nbsp;&nbsp;
								<a style="cursor:pointer" onClick="Javascript:window.open('seller_rating.php?artist_id=<?php echo $artistid ?>', 'SellerRating','menubar=0,resizable=0,width=250,height=200')"><?php echo SELLER_RATING_TEXT;?></a>
								
<?php

}

?>								
								
								
							</div>
							
							<div align="left" class="float_clear1"></div>
			  </div>
					
				  <!--items display area end -->
  
				  
		  
		



		<!--mainbody area end -->
        </div>

		

<?php
include "includes/".$active_template[2];	/* Bottom File Name */
?>
</body>
</html>
