<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: 			*/
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004-2010 ARMIA INC                                    |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts VistaCart                     |
// +----------------------------------------------------------------------+
// | Authors: Jipson<jipson.thomas@armiasystems.com>             		  |
// +----------------------------------------------------------------------+
?>
<div align="center">
	<h2 class="title text-center">Categories</h2>
</div>

<?php  
  if(empty($products)==false)
	 { ?>	   
		<div id="item_details" class="wid100p">
				<!--items display area start -->				
						<div id="items_display_area">
						
								<h4 class="productHead">Items Under Category <font class="atnsiontxt1">
								<?php echo $pcatdet["Category"]["cname"]; ?>
								</font></h4>
								<br />
								<?php 
									  foreach($products as $ft)
									  {  
											  ?>	
								<div class="cat_item">					
	                           <!--category listing box start-->  
								<div class="row">
								<div class="col-md-4">
								<div id="productBigimage1">
								
								<a href="<?php echo $html->url('/products/show/'.cleanspecialchars($ft["Product"]["pname"]).'/'.$ft["Product"]["id"]); ?>">
								<?php 
							     $img=explode(".",$ft["Productimages"]);
								 $ext='.'.end(explode(".",$ft["Productimages"]));
								 if(!empty($img[0])== true)
							      {
								    echo $html->image('/img/products/'.$img[0]."_thumb".$ext,array('border' => '0','height' => '125', 'width' => '125','title' => 'View More'));
							      }
							     else
							       {
								   echo $html->image('/img/noimagessmall.gif',array('border' => '0','height' => '125', 'width' => '125','title' => 'No Image'));
							       }
							     ?>
								</a>
								</div>								
								</div>
								
								<div id="itemDescription1" class="col-md-8">
									<h4>									
									<?php echo cleanspecialchars($ft["Product"]["pname"]); ?>
									</h4>
								<div class="clearfix"></div>
								
								<div><?php echo substr($ft["Product"]["descr"],0,150); ?></div>
									<div class="maintext">
									  <div class="productPrice1">													  
									 <?php											
														//Setting the Prices & Discount for Wholesale/Retail Users
														$prod_price=0;
														$discnt_type='';
														$discnt_price=0;	
														if($ft["Product"]["wholesale_price"] > 0 || $ft["Product"]["price"] > 0 )
														{
														if(isset($ft["Product"]["discount"]) && $ft["Product"]["discount"] > 0)
														{ 
														$discnt_type=$ft["Product"]["discount_type"];
														$discnt_price=$ft["Product"]["discount"];	
														}				
														}											 					
														if(isset($sus) && empty($sus)===false)
														{
														if($sus["usertype"]=='wholesale')
														{														
														if(isset($ft["Product"]["wholesale_price"]) && $ft["Product"]["wholesale_price"] > 0 )
														{
														$wholesale_price=$ft["Product"]["wholesale_price"];
														$utype='wholesale';
														display_price($utype,$wholesale_price,$discnt_type,$discnt_price,$curlogo);
														}
														else if(isset($ft["Product"]["price"]) && $ft["Product"]["price"] > 0 )
														{
														$retail_price=$ft["Product"]["price"];
														$utype='retail';
														display_price($utype,$retail_price,$discnt_type,$discnt_price,$curlogo);
														}   
														else
														display_price('',0,'',0,$curlogo);
														}	

														else if($sus["usertype"]=='retail')
														{										 		
														if(isset($ft["Product"]["price"]) && $ft["Product"]["price"] > 0 )
														{
														$retail_price=$ft["Product"]["price"];
														$utype='retail';
														display_price($utype,$retail_price,$discnt_type,$discnt_price,$curlogo);
														}   
														else
														display_price('',0,'',0,$curlogo);
														}												 									 
														}	
														else
														{  
														if(isset($ft["Product"]["price"]))
														$retail_price=$ft["Product"]["price"];
														$utype='normal';
														display_price($utype,$retail_price,$discnt_type,$discnt_price,$curlogo);
														}												  
														//Setting the Prices for Wholesale/Retail Users 	
														?>			
									  </div>
									<div>
									   <?php 
										 if($ft["Product"]["stock"] > 0 && $ft["Product"]["combination"]=='Y' )
										  { ?>
										     <a class="btn viewmorebtn get" href="<?php echo $html->url('/products/show/'.cleanspecialchars($ft["Product"]["pname"]).'/'.$ft["Product"]["id"]); ?>">
											 	View more
											 </a>
										 <?php  }
										  else if($ft["Product"]["stock"] > 0 && ($ft["Product"]["combination"]=='' || $ft["Product"]["combination"]=='N'))
										  { ?>
										    <a class="get viewmorebtn buy-now" href="<?php echo $html->url('/carts/add/'.$ft["Product"]["id"]."/".$ft["Product"]["id"]); ?>"> Add To Cart
											 <?php // echo $html->image('/img/addtocart.gif',array('border' =>'0','title' => 'Add to Cart')); ?>
											</a> 
									<?php }
										  ?>
									  </div>
								 </div>
							 </div>	
							 </div>
		                  <!--category listing box end--> 						  
						  <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif',array('border' =>'0','alt' => ''));?></div>
						  
						  </div>		
						  
						  
                        <?php } // end of For loop..?>
                              <div class="result newresult">
								 
								  <?php
    if($pagination->setPaging($paging)):
    $leftArrow = "<";//$html->image("nav/arrowleft.gif", Array('height'=>15));
    $rightArrow = ">";//$html->image("nav/arrowright.gif", Array('height'=>15));
	
    $prev = $pagination->prevPage($leftArrow,false);
    $prev = $prev?$prev:$leftArrow;
    $next = $pagination->nextPage($rightArrow,false);
    $next = $next?$next:$rightArrow;

    $pages = $pagination->pageNumbers(" | ");

    echo $pagination->result();
	echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    echo $prev." ".$pages." ".$next;
	echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	echo "Results per page : ";
    echo $pagination->resultsPerPage(NULL, ' ');
    endif;
?> 
								</div>				
        <div align="left" class="float_clear1"></div>
		</div>


		<?php } else { ?>			
				    <br /><br /><h4 class="productHead" align="center">No Items Found Under Category <font class="atnsiontxt1">
								<?php echo $pcatdet["Category"]["cname"]; ?>
								</font></h4>				
								
		<?php } ?>				
		<!--items display area end -->
		 </div>
		 <div align="left" class="float_clear"><?php echo $html->image('/img/clear.gif',array('border' =>'0','alt' => '','width' => '1', 'height' => '1'));?></div>
		<?php
				//Function to display price for Wholesale and Retail Users
				function display_price($utype='',$prod_price='',$discnt_type='',$discnt_price='',$curlogo='')
				{										
					   if($utype=='wholesale')
					   echo "<b>Wholesale Price : </b>";
					   else if($utype=='retail')
					   echo "<b>Price : </b>";
					   else if($utype=='normal')
					   echo "<b>Price : </b>";
					   
					   if(isset($discnt_type) && $discnt_type <> '')
						{ 
						if($discnt_type=='per')
						{
						if(isset($discnt_price) && $discnt_price <> '' && $discnt_price > 0)
						{
						$discounted_price=($prod_price-(($prod_price * $discnt_price)/100));
						echo "<strike>".$curlogo.number_format($prod_price,2)."</strike>&nbsp;&nbsp;".$curlogo.number_format($discounted_price,2);								 
						}											 
						}
						else if($discnt_type=='amnt')
						{	 
						if(isset($discnt_price) && $discnt_price <> '' && $discnt_price > 0)
						{
						$discounted_price=($prod_price-$discnt_price);
						echo "<strike>".$curlogo.number_format($prod_price,2)."</strike>&nbsp;&nbsp;".$curlogo.number_format($discounted_price,2);								 
						}		
						}
						}
						else
						{
						echo $curlogo.number_format($prod_price,2);		
						}							
				}
				
				function cleanspecialchars($text)
				{
					$code_entities_match = array(' 
		','--','&quot;','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','.','/','*','+','~','`','=');
					$code_entities_replace =
					array('-','-','','','','','','','','','','','','','','','','','','','','','','','','');
					$text = str_replace($code_entities_match, $code_entities_replace, $text);
					return $text;
				}
		?>