<?php
include("sess_page.php");
include("include/protect.php");
include("include/dbconnect.php");
$uname=$_SESSION['uname'];
extract($_POST);
$msg="";
$_SESSION['purchase_id'];

?>
<html>
<head>
<title></title>
<link href="style.css" rel="stylesheet" type="text/css">


<script language="javascript">
function rateWin(id)
{
window.open("rating.php?pid="+id,"Rating","width=400,height=500,menubar=0,toolbar=0,statusbar=0,scrollbars=1");
}
function reviewWin(id)
{
window.open("reviews.php?pid="+id,"Rating","width=400,height=500,menubar=0,toolbar=0,statusbar=0,scrollbars=1");
}
function reviewWin(id)
{
window.open("add_review.php?pid="+id,"Rating","width=400,height=500,menubar=0,toolbar=0,statusbar=0,scrollbars=1");
}
</script>
<link rel="stylesheet" href="../css/bootstrap.min.css">
    <!-- Site CSS -->
    <link rel="stylesheet" href="../css/style.css">
    <!-- Responsive CSS -->
    <link rel="stylesheet" href="../css/responsive.css">
    <!-- Custom CSS -->
    <link rel="stylesheet" href="../css/custom.css">
</head>

<body>
  <nav class="navbar navbar-expand-lg navbar-light bg-light navbar-default bootsnav">
            <div class="container">
 
    <!-- End Main Top -->
                <div class="collapse navbar-collapse" id="navbar-menu">
                    <ul class="nav navbar-nav ml-auto" data-in="fadeInDown" data-out="fadeOutUp">
                        <li class="nav-item active "><a class="nav-link" href="user_page.php">Home</a></li>
						<li class="nav-item "><a class="nav-link" href="user_parchase_order.php">Products</a></li>
						<li class="nav-item "><a class="nav-link" href="user_purch_view.php">View Cart</a></li>
                        <li class="nav-item "><a class="nav-link" href="view_purchase.php">Purchases Details</a></li>
                        <li class="nav-item"><a class="nav-link" href="../index.html" >Logout</a></li>
                    </ul>
                </div>

</div>
</nav>
   
	<form id="form1" name="form1" method="post" action="">
  <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#fff">
   
    <tr>
      <td align="center" valign="top"><p class="txt1">&nbsp;</p>
        <p class="txt1"><strong>Welcome <?php echo $uname; ?></strong></p>
        <p class="style1"><?php echo $msg; ?></p>
        
		<table width="784" height="71" border="0">
          <tr>
            <th align="left" scope="row"></th><p>&nbsp;</p>
            <td align="left"><input type="text" name="prd" class="form-control" placeholder="Search Here..." value="<?php echo $_REQUEST['prd']; ?>">
			<p>&nbsp;</p>
              <input type="submit" name="btn" value="Search" class="btn hvr-hover"></td>
          </tr>
        </table>
		
		
  
		
        <p>&nbsp;</p>
	  <?php
	  if(isset($btn))
	  {
		$gqry=mysql_query("select * from product where product like '%$prd%' || description like '%$prd%' order by rating desc");
		$num=mysql_num_rows($gqry);

	  if($num!=0)
	  {
	  
	  while($img_r=mysql_fetch_array($gqry))
		{
		$img[] = $img_r['id'];
		$rt[] = $img_r['rating'];
		}
		$img2 = array_chunk($img,3);
		//print_r($rt);
		
		@rsort($rt);
		$big=$rt[0];
	  ?>
	  <table width="23%" height="112" border="0" cellpadding="10" cellspacing="10">
        <tr>
          <td bordercolor="#FFFFFF"></td>
        </tr>
		<?php
		foreach($img2 as $img3)
		{
		
		?>
        <tr>
          <?php
		  $b=0;
			for($i=0;$i<count($img3);$i++)
			{
			$q2=mysql_query("select * from product where id=$img3[$i]");
			$r2=mysql_fetch_array($q2);
			$rate=$r2['rating'];
			
			
			$prdn=strtolower($r2['product']);
			$prd2=strtolower($prd);
			$pos = strpos($prdn, $prd2);
				/*if($pos===false)
				{
				$stid="animate";
				}
				else
				{
				$stid="";
				}
				if($rate>$b)
				{
				$b=$rate;
				}*/				
				if($rate==$big)
				{
				$stid="animate";
				}
				else
				{
				$stid="";
				}
			?>
          <td class="border"><table width="225" height="141" border="0" cellpadding="5" cellspacing="5" id="<?php echo $stid; ?>">
  <tr>
    <th colspan="2" bgcolor="#EAF9FF" scope="row"><span class="style3" style="text-decoration:blink"><?php echo $r2['product']." ".$r2['models']; ?></span></th>
  </tr>
  <tr>
    <th colspan="2" scope="row"><?php echo '<a href="product/'.$r2['product_image'].'" target="_blank"><img src="product/'.$r2['product_image'].'" width="80" height="130"></a>'; ?></th>
  </tr>
  
  <tr>
    <th width="77" align="left" scope="row"><strong>Price</strong></th>
    <td width="114" align="left"><strong><?php echo "Rs.".$r2['price']; ?></strong></td>
  </tr>
  <tr>
    <th colspan="2" align="left" scope="row"><strong><?php echo $r2['description']; ?></strong></th>
  </tr>
  <tr>
    <th colspan="2" align="left" scope="row"><?php
						   $n=$rate;
						  for($j=1;$j<=5;$j++)
						  {
						  	if($j<=$n)
							{
							?><img src="images/star1.jpg" /><?php
							}
							else
							{
							?><img src="images/star2.jpg" /><?php
							}
						  }
						  
						  ?></th>
  </tr>
  <tr>
    <th colspan="2" align="right" scope="row">
	
	
<?php echo '<a href="user_purchase_part.php?gid='.$r2['id'].'">Add to Cart</a>'; ?>&nbsp;&nbsp;&nbsp;&nbsp;
<?php echo '<a href="graph_product.php?pid='.$r2['id'].'">View Graph</a>'; ?>
</th>
  </tr>
</table> </td>
          <?php
		  }
		  ?>
        </tr>
        <?php
		}
		?>
      </table>
	  <?php
	  }//num
	  else
	  {
	  echo "No products found!";
	  }
	  }
	  ?>
<p>&nbsp;</p>
<div class="agileinfo-ads-display col-lg-12">
					<div class="wrapper">
						<!-- first section -->
						<div class="product-sec1 px-sm-6 px-3 py-sm-5  py-3 mb-4">
							<h3 class="heading-tittle text-center font-italic">Product Details</h3>
							<div class="row">
		
		<?php
    $qs=mysql_query("select * from product  LIMIT 3");
		  $i=0;
		  while($r1=mysql_fetch_array($qs))
		  { 
		  $i++; 

  ?>
  <table width="23%" height="112" border="0" cellpadding="10" cellspacing="10">
        <tr>
          <td bordercolor="#FFFFFF"></td>
        </tr>
  
  <table width="225" height="141" border="0" cellpadding="5" cellspacing="5" id="<?php echo $stid; ?>">
  <tr>
    <th colspan="2" bgcolor="#EAF9FF" scope="row"><span class="style3" style="text-decoration:blink"><?php echo $r1['product']." ".$r1['models']; ?></span></th>
  </tr>
  <tr>
    <th colspan="2" scope="row"><?php echo '<a href="product/'.$r1['product_image'].'" target="_blank"><img src="product/'.$r1['product_image'].'" width="80" height="130"></a>'; ?></th>
  </tr>
  
  <tr>
    <th width="77" align="left" scope="row"><strong>Price</strong></th>
    <td width="114" align="left"><strong><?php echo "Rs.".$r1['price']; ?></strong></td>
  </tr>
  <tr>
    <th colspan="2" align="left" scope="row"><strong><?php echo $r1['description']; ?></strong></th>
  </tr>
  <tr>
    <th colspan="2" align="left" scope="row"><?php
						   $n=$rate;
						  for($j=1;$j<=5;$j++)
						  {
						  	if($j<=$n)
							{
							?><img src="images/star1.jpg" /><?php
							}
							else
							{
							?><img src="images/star2.jpg" /><?php
							}
						  }
						  
						  ?></th>
  </tr>
  <tr>
    <th colspan="2" align="right" scope="row">
	<?php /*?><a href="javascript:rateWin('<?php echo $img3[$i]; ?>')">Rating</a>&nbsp;&nbsp;&nbsp;&nbsp;<?php */?>
	
<?php echo '<a href="user_purchase_part.php?gid='.$r1['id'].'">Add to Cart</a>'; ?>&nbsp;&nbsp;&nbsp;&nbsp;
<?php echo '<a href="graph_product.php?pid='.$r1['id'].'">View Graph</a>'; ?>
</th>
  </tr>
</table>
  
						
	<?php 
  }
  ?>
      
					
	<!-- //top products -->

    <tr>
      <td align="center" >&nbsp;</td>
    </tr>
	
  </table>
  
  </form>
  <div class="footer-copyright">
        <p class="footer-company">&nbsp;</p>
    </div>

<script src="../js/jquery-3.2.1.min.js"></script>
    <script src="../js/popper.min.js"></script>
    <script src="../js/bootstrap.min.js"></script>
    <!-- ALL PLUGINS -->
    <script src="../js/jquery.superslides.min.js"></script>
    <script src="../js/bootstrap-select.js"></script>
    <script src="../js/inewsticker.js"></script>
    <script src="../js/bootsnav.js."></script>
    <script src="../js/images-loded.min.js"></script>
    <script src="../js/isotope.min.js"></script>
    <script src="../js/owl.carousel.min.js"></script>
    <script src="../js/baguetteBox.min.js"></script>
    <script src="../js/form-validator.min.js"></script>
    <script src="../js/contact-form-script.js"></script>
    <script src="../js/custom.js"></script>
</body>
</html>