	<?php
	
	//1509
	
	$type = $_REQUEST['type'];
	$value = $_REQUEST['value'];
	
	//echo "type is ".$type;
	
	
	
	if (isset($_COOKIE['phxcrmclient_id'])){
		 $phxcrmclient_id = $_COOKIE['phxcrmclient_id'];
	}else{
		echo '<br><span>Please  <a style="font-size: 16px" href="login.php">Login/Register</a> to see our range of Organic products</span>';
		
		exit;
		
	}
	
	
	$result = '';
	
	$cart_id	= 0;
	
	$c_shortdisc = 0;
	
	 include 'configi.php';

	$queryclient="SELECT * from ".$_COOKIE['phxcrmclient_id']."_client where uid_client = " . $phxcrmclient_id;
//	$result = $result . $queryclient;
	$resultclient=mysqli_query($conn, $queryclient);

	while($rowclient=mysqli_fetch_array($resultclient)) { 

		$cart_id			 				= $rowclient['curr_cart_id'];
		$c_shortdisc		 				= $rowclient['c_shortdisc'];
		
	}
	
	
	
		
	
	$result = '';
	$title = '';
	
	
	
	 include 'configi.php';
	 
	 
	 if ($type == 0){
		// get cat name
		 
		$querycat="SELECT * from ".$_COOKIE['phxcrmclient_id']."_web_cat where cat_id = " . $value;
		//	$result = $result . $queryclient;
		$resultcat=mysqli_query($conn, $querycat);

//echo $querycat;
		while($rowcat=mysqli_fetch_array($resultcat)) { 

			$cat_name			 				= $rowcat['cat_name'];
			$img_file1 							= "images/category/".$value.".png?q=1518";
	
		}
	
		$title = "<center>
		        <div class='section full mt-2'>
            <div class='wide-block pt-2 pb-2'>
                <div class='dropdown'>
                    <button class='btn btn-secondary dropdown-toggle' type='button' data-toggle='dropdown'>
                        <img height=30px src='".$img_file1."' alt='' class='image'>&nbsp;".htmlspecialchars($cat_name)."
                    </button>
                    <div class='dropdown-menu'>	";
					
									  	include("configi.php");
										
										$title = $title . "<table class='table-striped'><tr><td style='width: 20%'></td><td style='width: 80%'></td></tr>";
				
					$querycat="SELECT * from ".$_COOKIE['phxcrmclient_id']."_web_cat where display_status = 'active' order by cat_name;";
					//	echo $querycat;
					$resultcat=mysqli_query($conn, $querycat);

					while($rowcat=mysqli_fetch_array($resultcat)) { 


						$cat_id			 				= $rowcat['cat_id'];
						$cat_name		 				= $rowcat['cat_name'];
						$cat_count		 				= $rowcat['cat_count'];
						
						$img_file = "images/category/".$cat_id.".png";

							$title = $title . "<tr><td><img loading='lazy' height=20px src='".$img_file."' alt='' class='image'></td><td><a class='dropdown-item' href='shopping.php?getcattype=0&getcat=".$cat_id."'>
                               ".htmlspecialchars($cat_name)."
                        </a>
						</td>
						</tr>";
						
			
						
					}
										$title = $title . "</td></tr></table>";

           $title = $title . "</div>
            </div>
        </div></center>
		";



		

		$queryprod="SELECT ".$_COOKIE['phxcrmclient_id']."_prodserv.retail_price2, ".$_COOKIE['phxcrmclient_id']."_prodserv.prod_cost_price, ".$_COOKIE['phxcrmclient_id']."_web_dept.dept_id, ".$_COOKIE['phxcrmclient_id']."_web_cat.cat_id, ".$_COOKIE['phxcrmclient_id']."_web_cat.cat_name, ".$_COOKIE['phxcrmclient_id']."_prodserv.uid, ".$_COOKIE['phxcrmclient_id']."_prodserv.prod_title, ".$_COOKIE['phxcrmclient_id']."_prodserv.prod_retail, prod_descr FROM ((".$_COOKIE['phxcrmclient_id']."_prod_category INNER JOIN ".$_COOKIE['phxcrmclient_id']."_web_cat ON ".$_COOKIE['phxcrmclient_id']."_prod_category.cat_id = ".$_COOKIE['phxcrmclient_id']."_web_cat.cat_id) INNER JOIN ".$_COOKIE['phxcrmclient_id']."_prodserv ON ".$_COOKIE['phxcrmclient_id']."_prod_category.prod_uid = ".$_COOKIE['phxcrmclient_id']."_prodserv.uid) INNER JOIN ".$_COOKIE['phxcrmclient_id']."_web_dept ON ".$_COOKIE['phxcrmclient_id']."_web_cat.dept_id = ".$_COOKIE['phxcrmclient_id']."_web_dept.dept_id where ".$_COOKIE['phxcrmclient_id']."_web_cat.cat_id = ".$value." and ".$_COOKIE['phxcrmclient_id']."_prodserv.prod_status = 'Active' order by prod_order, prod_title;";
		
	//	echo $queryprod;
		
		
	 }else if ($type == 1){

		$queryprod="SELECT ".$_COOKIE['phxcrmclient_id']."_prodserv.retail_price2, ".$_COOKIE['phxcrmclient_id']."_prodserv.prod_cost_price, ".$_COOKIE['phxcrmclient_id']."_web_dept.dept_id, ".$_COOKIE['phxcrmclient_id']."_web_cat.cat_id, ".$_COOKIE['phxcrmclient_id']."_web_cat.cat_name, ".$_COOKIE['phxcrmclient_id']."_prodserv.uid, ".$_COOKIE['phxcrmclient_id']."_prodserv.prod_title, ".$_COOKIE['phxcrmclient_id']."_prodserv.prod_retail, prod_descr FROM ((".$_COOKIE['phxcrmclient_id']."_prod_category INNER JOIN ".$_COOKIE['phxcrmclient_id']."_web_cat ON ".$_COOKIE['phxcrmclient_id']."_prod_category.cat_id = ".$_COOKIE['phxcrmclient_id']."_web_cat.cat_id) INNER JOIN ".$_COOKIE['phxcrmclient_id']."_prodserv ON ".$_COOKIE['phxcrmclient_id']."_prod_category.prod_uid = ".$_COOKIE['phxcrmclient_id']."_prodserv.uid) INNER JOIN ".$_COOKIE['phxcrmclient_id']."_web_dept ON ".$_COOKIE['phxcrmclient_id']."_web_cat.dept_id = ".$_COOKIE['phxcrmclient_id']."_web_dept.dept_id where ".$_COOKIE['phxcrmclient_id']."_prodserv.title like %".htmlspecialchars($value)."% and ".$_COOKIE['phxcrmclient_id']."_prodserv.prod_status = 'Active';";		 
		
	//	$title = "";
		
	//	echo $queryprod;
	 }else if ($type == 2){

		$queryprod="SELECT * FROM ".$_COOKIE['phxcrmclient_id']."_prodserv where ".$_COOKIE['phxcrmclient_id']."_prodserv.uid = ".htmlspecialchars($value)." and ".$_COOKIE['phxcrmclient_id']."_prodserv.prod_status = 'Active';";		 

//echo $queryprod;
		//echo $queryprod;
		
	//	$title = "";
		
		 		 
	 }
	 
//	 echo "type is" . $type;
	 
	//	echo $queryprod;
		$resultprod=mysqli_query($conn, $queryprod);
		
		$i = 0;

		while($rowprod=mysqli_fetch_array($resultprod)) { 

			$uid			 				= $rowprod['uid'];
			$prod_title		 				= $rowprod['prod_title'];
			$prod_retail	 				= $rowprod['prod_retail'];
			$retail_price2	 				= $rowprod['retail_price2'];
			$prod_cost_price	 			= $rowprod['prod_cost_price'];
			$prod_descr	 					= $rowprod['prod_descr'];
			
			if ($prod_cost_price == 0){
						
				$prod_cost_price_inc = 0;
							
			}else{

				//add gst

				$prod_cost_price_inc = $prod_cost_price + ($prod_cost_price/100*15);

				//add 10% markup

				$prod_cost_price_inc =  $prod_cost_price_inc + ($prod_cost_price_inc/100*10);
				
				$prod_cost_price_inc = number_format((float)$prod_cost_price_inc, 2, '.', '');
							
			}

	

			if ($c_shortdisc == 1){
				
				$item_price = $prod_cost_price_inc;
				
				$price_disp = ' <div class="old-price">$ '.htmlspecialchars($retail_price2).'</div>
				<div class="current-price">$ '.htmlspecialchars($prod_cost_price_inc).'</div>';
				
				
			}else{

				$item_price = $retail_price2;
				
				$price_disp = ' <div class="current-price">$ '.htmlspecialchars($item_price).'</div>';
				
			}
				

			if ($i == 0){
				$result = $result . $title . '<br>';
				
			}
				$result = $result.'
				
			 <div class="section full">
            <div class="wide-block pt-2 pb-2 product-detail-header">
            <div  class="item">
			<center>
                <img  src="images/products/'.$uid.'_1.png?q=1518" alt="" class="imaged w-50 square">
            </center>
			</div>
			<center>
                <h1 class="title">'.htmlspecialchars($prod_title).'</h1></p>';
				
				
		if ($prod_descr == ""){
			
		}else{

			
							$mm = '
  <a class="btn btn-link btn-xl" data-toggle="collapse" href="#ajaxresponses0'.$uid.'" role="button" aria-expanded="false" aria-controls="ajaxresponses0'.$uid.'">
  Further info '.htmlspecialchars($prod_title).'
  </a>


<div  id="ajaxresponses0'.$uid.'" class="collapse" id="ajaxresponses0.'.$uid.'">
  <div class="card card-body">
    <h4>Further details</h4>';
	

$mm = $mm . '<div id="divccrun0results'.$uid.'"> 
<table>
<tr>
<td>
<h4>Description:</h4>
</td>
</tr>
<tr>
<td><div>'.$prod_descr.'</div>

</td>
</tr>
</table>
</div>';
	

  $mm = $mm . '</div></div>';
  
  $result = $result . $mm;
		


		}
		
		

			
				
$result = $result . '
						
</center>            
			
                <div class="detail-footer">
                    <!-- price -->
                    <div class="price">';


$result = $result.$price_disp.'
                       
                    </div>
                    <!-- * price -->
                    <!-- amount -->
                    <div class="amount">
                        <div class="stepper stepper-secondary">
                            <a href="#" class="stepper-button stepper-down">-</a>
                            <input id="qty_'.$uid.'" type="text" class="form-control" value="1" disabled/>
                            <a href="#" class="stepper-button stepper-up">+</a>
                        </div>
                    </div>
                    <!-- * amount -->
                </div>
                <button class="btn btn-success btn-lg btn-block" onclick="javascript: add_cart('.$uid.','.$cart_id.',3,'.$item_price.')">
                    <ion-icon name="cart-outline"></ion-icon>
                    Add to Cart
                </button>';
				

		
		
        $result = $result . '</div>';
		
		

			
			

			

        $result = $result . ' </div>
		';

		
	$i = $i + 1;
	

		}
	

if ($i == 0){
	$result = $result . $title . '<br>';
	$result = $result . "<center>no items found</center>";

}

echo $result;


			
			?>