<?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

	if($_GET['featured'] == 'Y')
	{
							
		
		/*$sql = "SELECT product_id,product_name,product_image_small,product_stock 
				FROM ".$tableprefix."products 
				WHERE (product_image_small IS NOT NULL) AND (product_image_small <> '') 
				 AND featured='Y' 
				AND deleted != 'Y' ORDER BY date_added  DESC";*/
				
		    $sql="SELECT pd.product_id, product_name, product_image_small, product_stock, ar.artist_id
			  FROM ".$tableprefix."products pd, ".$tableprefix."artists ar
			  WHERE pd.product_artist_id=ar.artist_id AND pd.featured='Y' AND pd.vapproved='Y' 
			  AND ar.vapproved='Y' AND pd.deleted !='Y' ORDER BY pd.date_added  DESC";	
				
		$featured_image = "featured_items1.gif";		
		$newitem_image = "new_items.gif";
		
			
	}
	else
	{
									
		/*$sql = "SELECT product_id,product_name,product_image_small,product_stock
				FROM ".$tableprefix."products 
				WHERE (product_image_small IS NOT NULL) AND (product_image_small <> '') 
				AND deleted != 'Y' ORDER BY date_added  DESC";*/
				
		/*$sql = "SELECT product_id,product_name,product_image_small,product_stock
				FROM ".$tableprefix."products 
				WHERE deleted != 'Y' ORDER BY date_added  DESC";*/
				
		$sql="SELECT pd.product_id, product_name, product_image_small, product_stock, ar.artist_id
			  FROM ".$tableprefix."products pd, ".$tableprefix."artists ar
			  WHERE pd.product_artist_id=ar.artist_id 
			  AND ar.vapproved='Y' AND pd.deleted !='Y' AND pd.vapproved='Y'   ORDER BY pd.date_added  DESC";
			  
			  
		$featured_image = "featured_items.gif";		
		$newitem_image = "new_items_h.gif";
	}
	
?>	
	
	<div align="left" id="items"  >
	<!--items display area start -->
				
		<div align="left" id="items_top_area">
		
<?php
$f=$_GET['featured'];
	if(!isset($_GET['featured']) || $_GET['featured'] == 'N')
	{

?>				
				
<img src="<?php echo $active_template[3]?>/<?php echo $newitem_image?>" alt="" width="92" height="33" />				<a href="index.php?featured=Y" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image30','','<?php echo $active_template[3]?>/featured_items1.gif',1)">
		<img src="<?php echo $active_template[3]?>/<?php echo $featured_image?>" alt="Featured Items" name="Image30" width="127" height="33" border="0" id="Image30" />
	</a>
				
<?php

			

	}
	else
	{


			
?>				
				
					
					<a href="index.php?featured=N" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('ImageNew','','<?php echo $active_template[3]?>/new_items1.gif',1)">
						<img src="<?php echo $active_template[3]?>/<?php echo $newitem_image?>" border="0" alt="" name="ImageNew" width="92" height="33" />
					</a>	
				
					<img src="<?php echo $active_template[3]?>/<?php echo $featured_image?>" alt="Featured Items" name="Image30" width="127" height="33" border="0" id="Image30" />
				
				
<?php
	}
?>				
				
		</div>

  <div align="center" id="items_display_area">
  

<?php	
	
	$prodimagedir = "products/";
				
	if(!(isset($pagenum)))
	{
		$pagenum = 1;
	} 
	
	/*$sql=" SELECT product_id,product_name,product_image_small FROM ".$tableprefix."products 
		   WHERE (product_image_small IS NOT NULL) AND (product_image_small <> '') 
		   AND deleted != 'Y' ORDER BY date_added  DESC ";*/
		   
	$result=mysql_query($sql) or die(mysql_error());						
	
	$totalrows = mysql_num_rows($result);
	
	$limitvalue = ($page - 1) * $limit;
	
	$query_string = " LIMIT $limitvalue, $limit";
	
	$sql = $sql.$query_string;
	
	/*$sql=" SELECT product_id,product_name,product_image_small FROM ".$tableprefix."products 
		   WHERE (product_image_small IS NOT NULL) AND (product_image_small <> '') 
		   AND deleted != 'Y' ORDER BY date_added  DESC LIMIT $limitvalue, $limit";*/
		   
	$result=mysql_query($sql) or die(mysql_error());
	
	if(mysql_num_rows($result) > 0 )
	{
		while($row = mysql_fetch_array($result))
		{
			if($row["product_image_small"]=="")
		   { // check if thumnail image is not avilabe select images from 
			$sql_im="select vimage_name from ".$tableprefix."product_view_images  where nimage_productid ='".$row['product_id']."' limit  0,1";
			$result_im=mysql_query($sql_im) or die (mysql_error());
			$numrows=mysql_num_rows($result_im);
			 if($numrows>0)
			  { // check number of rows
			  	$rm=mysql_fetch_array($result_im);
			  	$product_image=$rm['vimage_name'];
				
				$prodimagedir="products/bulk_images/";
			
			  } // end num row check 
			  else
			  { // if images not in the table 
			  	$product_image="";
				$prodimagedir="products/";
			  }	 // end if 
			
		   }  // end if product image null check 
		   
		   else
		   {
		   		$prodimagedir="products/";
		   		$product_image=$row["product_image_small"];
		   }		
			if(checkProductStock($row["product_id"]) > 0)
				{
                                    $productinstock = true;
			}
			else
			{
				$productinstock = false;
			}
			
			if(!empty($product_image))
			{ // Rename Image Thumb;
				$imgexp=explode(".",$product_image);
				//$imagename=$imgexp[0]."_thumb.jpg";
				$extension=$imgexp[1];
				$imagename=$imgexp[0]."_thumb.".$extension;
		    }  // end thumb creation 
			
		
		   if($product_image=="")
		   {
				$imageurl = "<img class='item_thumb' src='".$prodimagedir . "noimage.jpg' width='90' height='70' border='0' >";
		   }
		   else
		   {
				$imageurl = "<img class='item_thumb' src='".$prodimagedir.urlencode($imagename)."' border='0'  class='item_thumb'>";

			}
			
?>			

<!--Display the product details-->

		
				<div align="center" class="item_block1" >
								
						<a href="productdetails.php?productid=<?php echo $row["product_id"]?>"><?php echo $imageurl?><br/></a>
<?php 						

							if(strlen($row["product_name"])>30)
							  $prd_name = substr($row["product_name"],0,30);
							else
							   $prd_name = $row["product_name"];
							   
							     echo ucwords(strtolower($prd_name));
						
?>								
								
								<div align="center" class="item_block_links">
									<!--<a href="viewcart.php"><img src="<? //php echo $active_template[3]?>/view_cart_btn.gif" alt="View Cart" border="0" /></a>
									-->
<?php

							if($productinstock)
							{

?>									
									
									
									<a href="homepage_addtocart.php?productid=<?php echo $row["product_id"]?>">Add To Cart</a>
									
<?php

							}

?>									
									
									
									<a href="productdetails.php?productid=<?php echo $row["product_id"]?>">More</a>
								</div>
								
				
	</div>	
			
<!--Display the product details-->			
			

<?php
			}
		
	
		}
	
			
		if($page > 1)
		{
			$pageprev = $page-1;
			
			$previous_page = "<a href=".$_SERVER['PHP_SELF']."?page=$pageprev&featured=$f alt='Previous' border='0'><img src='".$active_template[3]."/previous_btn.gif' alt='Previous' border='0' /></a>";
			
		}
		
		$numofpages = ceil($totalrows / $limit);
					
		if($page < $numofpages)
		{
			$pagenext = ($page + 1);
			
			$next = "<a href=".$_SERVER['PHP_SELF']."?page=$pagenext&featured=$f alt='Next' border='0'><img src='".$active_template[3]."/next_btn.gif' alt='Next' border='0'/></a>&nbsp;";
			
		}
		
?>				

	
		<div align="left" class="float_clear1">
		
		</div>
			<div align="left" class="more_links">
					<div align="left" class="previous">
							<?php echo $previous_page?>
					</div>
					<div align="left" class="next">
					
							<?php echo $next ?>
							<br>
							
					</div>

			</div>
</div>
	<!--items display area end -->
	</div>		  
				  
				  
				  
						
						
						
						
						<!--
						<div align="center" class="item_block2">
								<img src="images/item2.gif" alt="" class="item_thumb" />
								<div align="center" class="item_block_links">
									<a href="javascript:;"><img src="images/view_cart_btn.gif" alt="View Cart" border="0" /></a>
									<a href="javascript:;"><img src="images/more_btn.gif" alt="More" border="0" /></a>
								</div>
						</div>
						<div align="center" class="item_block3">
								<img src="images/item3.gif" alt="" class="item_thumb" />
								<div align="center" class="item_block_links">
									<a href="javascript:;"><img src="images/view_cart_btn.gif" alt="View Cart" border="0" /></a>
									<a href="javascript:;"><img src="images/more_btn.gif" alt="More" border="0" /></a>
								</div>
						</div>
						<div align="center" class="item_block1">
								<img src="images/item4.gif" alt="" class="item_thumb" />
								<div align="center" class="item_block_links">
									<a href="javascript:;"><img src="images/view_cart_btn.gif" alt="View Cart" border="0" /></a>
									<a href="javascript:;"><img src="images/more_btn.gif" alt="More" border="0" /></a>
								</div>
						</div>
						<div align="center" class="item_block2">
								<img src="images/item5.gif" alt="" class="item_thumb" />
								<div align="center" class="item_block_links">
									<a href="javascript:;"><img src="images/view_cart_btn.gif" alt="View Cart" border="0" /></a>
									<a href="javascript:;"><img src="images/more_btn.gif" alt="More" border="0" /></a>
								</div>
						</div>
						<div align="center" class="item_block3">
								<img src="images/item6.gif" alt="" class="item_thumb" />
								<div align="center" class="item_block_links">
									<a href="javascript:;"><img src="images/view_cart_btn.gif" alt="View Cart" border="0" /></a>
									<a href="javascript:;"><img src="images/more_btn.gif" alt="More" border="0" /></a>
								</div>
						</div>
						
						-->
						
						
						
					

<?php		
				
				/*if($_GET['featured'] == 'N')
				{
				
					$sql = "SELECT product_id,product_name,product_image_small FROM ".$tableprefix."products 
						    WHERE (product_image_small IS NOT NULL) AND (product_image_small <> '') 
						    AND deleted != 'Y' ORDER BY date_added  DESC";
							
					$featured = "&featured=N";							
				
				}
				else
				{
												
					$sql = "SELECT product_id,product_name,product_image_small FROM ".$tableprefix."products 
						    WHERE (product_image_small IS NOT NULL) AND (product_image_small <> '') 
						     AND featured='Y' 
							AND deleted != 'Y' ORDER BY date_added  DESC";
					
					$featured = "";
				
				}
							
				
				
				$prodimagedir = "products/";
				
				if(!(isset($pagenum)))
				{
					$pagenum = 1;
				} */
				
				/*$sql=" SELECT product_id,product_name,product_image_small FROM ".$tableprefix."products 
					   WHERE (product_image_small IS NOT NULL) AND (product_image_small <> '') 
					   AND deleted != 'Y' ORDER BY date_added  DESC ";*/
					   
				/*$result=mysql_query($sql) or die(mysql_error());						
				
				$totalrows = mysql_num_rows($result);

				$limit=6;
				
				if(empty($page))
				{
					$page = 1;
				}
				
				$limitvalue = ($page - 1) * $limit;
				
				$query_string = " LIMIT $limitvalue, $limit";
				
				$sql = $sql.$query_string;*/
				
				/*$sql=" SELECT product_id,product_name,product_image_small FROM ".$tableprefix."products 
					   WHERE (product_image_small IS NOT NULL) AND (product_image_small <> '') 
					   AND deleted != 'Y' ORDER BY date_added  DESC LIMIT $limitvalue, $limit";*/
					   
				/*$result=mysql_query($sql) or die(mysql_error());
				
				if(mysql_num_rows($result) > 0 )
				{
					while($row = mysql_fetch_array($result))
					{
					   if($row["product_image_small"] == "")
					   {
							$imageurl = "<img src='".$prodimagedir . "noimage.jpg' width='100' height='100' border='0' >";
					   }
					   else
					   {
							if(!function_exists('gd_info'))
							{
								$imageurl = "<img src='".$prodimagedir.urlencode($row["product_image_small"])."' border='0' width='100' height='100' class='item_thumb'>";
							}
							else
							{
								$imageurl = "<img src='getimagethumbnail.php?imagename=".urlencode($row["product_image_small"])."' width='90' height='70' border='0' class='item_thumb'>";
							}
						}*/
						
?>

<!--Display the product-->


								
								
								<!--<div align="center" class="item_block1">--><?php //echo $imageurl?>
								
								<?php //echo //substr($row["product_name"],0,10)?>

										


										
<?php 								

/*--Display only the first 10 characters of product name--*/

										//echo substr($row["product_name"],0,10);
																														
										//if(strlen($row["product_name"])>10)
										//{
?>										
			
												

<?php

										//}

?>
									
									
									
									
									
								
<!--Display the product-->								

<?php						
					//}
					
					
					
				//}		
				
									
		
				/*if($page > 1)
				{
					$pageprev = $page-1;
					
					$previous = $_SERVER['PHP_SELF']."?page=$pageprev>PREV&nbsp;";
					
				}
				
				$numofpages = ceil($totalrows / $limit);
							
				if($page < $numofpages)
				{
					$pagenext = ($page + 1);
					
					$next = "<a href=".$_SERVER['PHP_SELF']."?page=$pagenext>NEXT</a>&nbsp;";
					
				}*/					
					
?>						
	
						<!--<form name="frmProductListing" method="post">
						<div align="left" class="float_clear1"></div>
					  	<div align="left" class="more_links">
					  			<div align="left" class="previous">
										<a href="<?php //echo $_SERVER['PHP_SELF']."?page=".$pageprev.$featured?>"><img src="images/previous_btn.gif" alt="Previous" border="0" /></a>
								</div>
								<div align="left" class="next">
										<a href="<?php //echo $_SERVER['PHP_SELF']."?page=".$pagenext.$featured?>"><img src="images/next_btn.gif" alt="Next" border="0" /></a>								
								</div>
				  			</div>
							
				 		 </div>
						 </form>-->			
