<?php
session_start();
include "includes/database.php";
include "includes/security.php";
$email=$_SESSION["pengguna"];
$dataPengguna=mysqli_query($newcon,"SELECT * from tbl_user where email='$email'");
$showData=mysqli_num_rows($dataPengguna);




//rekod pengguna
 if(isset($_SESSION ["pengguna"]))
{
$pid=$_SESSION["pengguna"];
$dataPengguna= mysqli_query($newcon, "SELECT* from tbl_user where email='$pid'");
//$bil_rekod_pengguna=mysqli_num_rows($datawujud);
$showDataPengguna=mysqli_fetch_array($dataPengguna);

}


//retrieved tbl_data2

//simpan data rating

if (isset($_POST["pid4"]))
{
	
	mysqli_query($newcon,"INSERT INTO tbl_rating (product_id,rating,user_id) values ('$_POST[pid4]', '$_POST[rate]','$pid')")or die (mysqli_error($newcon));	
	
	
}



?>

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>MyUniversity MarketPlace</title>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/heroic-features.css" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>

    <!-- Navigation -->
    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">MyUniversity MarketPlace</a>
            </div>
            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li class="nav-item active">
              <a class="nav-link" href="index2.php">HOME
                <span class="sr-only">(current)</span>
              </a>
            </li>
                    <li>
                        <a href="about2.php">ABOUT</a>
                    </li>
                    <li>
                        <a href="shop2.php">SHOP</a>
                    </li>
                     <li>
                        <a href="cart.php">CART</a>
                    </li>
                     <li>
                        <a href="review.php">REVIEW</a>
                    </li>

            
                    <li class="nav-item">
              <a class="nav-link active" href="logout.php">LOGOUT</a>
            </li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container -->
    </nav>

       
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table">
                                    <thead>
                                        <tr>
                                            <th class="bg-warning">#</th>
                                            <th class="bg-warning">Picture</th>
                                            <th class="bg-warning">Product Name</th>
                                            <th class="bg-warning">Product Rating</th>
                                            <th class="bg-warning">Vote</th>
                                        </tr>
                                    </thead>
                                   
                                   
                                   
                              <?php
							  $dataSubjects=mysqli_query($newcon,"SELECT * from tbl_product");
$bil_subjects=mysqli_num_rows($dataSubjects);

?>                              
                                   
<tbody>

<?php
if ($bil_subjects==0)
{
?>
<tr>
<td colspan="5">No record found!</td>

</tr>
<?php
}
else
{


while ($showSubjects=mysqli_fetch_array($dataSubjects))
	{
//calculate rating
$dataRating=mysqli_query($newcon,"SELECT * from tbl_rating where product_id='$showSubjects[product_id]'");
$bil_Rating=mysqli_num_rows($dataRating);

if ($bil_Rating==0)
{$ttlRating="No Rating yet";}
else
{
	$ttlRating=0;
	while ($showRating=mysqli_fetch_array($dataRating))
	{
	$ttlRating+=$showRating['rating'];	
	}
$ttlRating=number_format($ttlRating/$bil_Rating,1);
}
?>


<tr>
<td class="table-warning"><?php echo $showSubjects['product_id'];?></td>
 <td class="table-warning"><img src="product/<?php echo $showSubjects['product_pic'];?>" width="64" width="64"></td>
<td class="table-warning"><?php echo $showSubjects['product_name'];?></td>
<td class="table-warning"><?php echo $ttlRating;?></td>
<td class="table-warning">
<form method="post">
<input type="radio" name="rate" value="1" checked> 1
<input type="radio" name="rate" value="2"> 2
<input type="radio" name="rate" value="3"> 3
<input type="radio" name="rate" value="4"> 4
<input type="radio" name="rate" value="5"> 5
<input type="hidden" name="pid4" value="<?php echo $showSubjects['product_id'];?>">
<button class="btn btn-primary">Vote</button>
</form>
</td>
</tr>

<?php
}
}
?>
                                       
</tbody>
                                </table>
                            </div>
                            <!-- /.table-responsive -->
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-6 -->
            </div>
            <!-- /.row -->
                      
                      
                      
                      
                        
                      
  
  
                    </div>
                    <!-- /.col-lg-12 -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.container-fluid -->
        </div>
        <!-- /#page-wrapper -->

   

 <!-- Bootstrap core JavaScript -->
    <script src="vendor/jquery/jquery.min.js"></script>
    <script src="vendor/boots/js/bootstrap.bundle.min.js"></script>
    
    <script>
// Accordion 
function myAccFunc() {
    var x = document.getElementById("demoAcc");
    if (x.className.indexOf("w3-show") == -1) {
        x.className += " w3-show";
    } else {
        x.className = x.className.replace(" w3-show", "");
    }
}

// Click on the "Jeans" link on page load to open the accordion for demo purposes
document.getElementById("myBtn").click();


// Script to open and close sidebar
function w3_open() {
    document.getElementById("mySidebar").style.display = "block";
    document.getElementById("myOverlay").style.display = "block";
}
 
function w3_close() {
    document.getElementById("mySidebar").style.display = "none";
    document.getElementById("myOverlay").style.display = "none";
}
</script>

  </body>

</html>

