<?php
    include("config.php");
?>
	<?php include("inc/header.php") ?>

		<body data-spy="scroll" data-target="#navSection" data-offset="100">
			<?php include("inc/sidebar.php") ?>
				<!-- sidebar -->
				<div class="content">
					<div class="header">
						<div class="header-left"> <a href="#" class="burger-menu"><i data-feather="menu"></i></a> </div>
						<!-- header-left -->
						<div class="header-right"> 
						
							<div class="dropdown dropdown-loggeduser">
								<a href="#" class="dropdown-link" data-toggle="dropdown">
									<div class="avatar avatar-sm"> <img src="https://cdn.iconscout.com/icon/free/png-256/laptop-user-1-1179329.png" class="rounded-circle" alt=""> </div>
									<!-- avatar -->
								</a>
								<div class="dropdown-menu dropdown-menu-right">
									<div class="dropdown-menu-header">
										<div class="media align-items-center">
										 
											<div class="media-body mg-l-10">
												<h6>ExpertAlgos</h6> <span>Administrator</span> </div>
										</div>
										<!-- media -->
									</div>
									<div class="dropdown-menu-body"> <a href="#" class="dropdown-item"><i data-feather="user"></i>
									View Profile</a> <a href="../" class="dropdown-item"><i data-feather="log-out"></i> Sign Out</a> </div>
								</div>
								<!-- dropdown-menu -->
							</div>
						</div>
						<!-- header-right -->
					</div>
					<!-- header -->
				
					<!-- content-header -->
					<div class="content-header">
				        	<div class="row">
						<div class="col-md-12">
							
							<h4 class="content-title" style="padding-left:30px;">Product Table</h4>
							<div class="demo-modal-btn d-block tx-center">
								<div class="card card-body">
									<div class="table-responsive">
										<table class="table table-striped mg-b-0">
											<thead>
												<tr>
													<th scope="col">Name</th>
													<th scope="col">Description</th>
													<th scope="col">Amount</th>
													<th scope="col">Picture</th>
													
													<th scope="col">
														<center>Action</center>
													</th>
													<th scope="col">
														<center>Action 2</center>
													</th>
													
												</tr>
											</thead>
											<?php
                   
                        $db=$conn->prepare("SELECT * FROM product");
                        $db->execute();
                        $db_result = $db->get_result();
                        while($db_fetch = $db_result->fetch_assoc())
                        {
                            
                            $product_title = $db_fetch['product_title'];
                            $product_desc = $db_fetch['product_desc'];
                            $product_amount = $db_fetch['product_amount'];
                            $product_pic = $db_fetch['product_pic'];
                            $product_id = $db_fetch['product_id'];
                            
                   
                   ?>
												<tbody>
													<tr>
														<td>
															<?php echo $product_title; ?>
														</td>
														<td>
															<?php echo $product_desc; ?>
														</td>
													
														<td>
															<?php echo $product_amount; ?>
														</td>
														<td>
															<img src="../img/<?php echo $product_pic; ?>" style="width: 280px; height: 182px; border: 1px solid black;">
														</td>
														<form method="post">
															<td>
															   <input type="hidden" value="<?php echo $product_id; ?>" name="id"> 
																	<button class="btn btn-outline-danger" name="delete" type="submit">DELETE</button>
																	
															</td>
															
														</form>
														<td>
														    <a class="btn btn-outline-primary" type="button" href="edit_product.php?id=<?php echo $product_id ?>">EDIT</a>
														</td>
													</tr>
												 
											</tbody>
												<?php }
  
  if(isset($_POST["delete"])){
      $p_id=$_POST['id'];
	    $dell=$conn->prepare("DELETE FROM product WHERE product_id=?");
	    $dell->bind_param("s", $p_id);
	    $dell->execute();
	   
	    if($dell == true){
	        echo 'Record deleted';
	        $url = 'product.php';   
    
            echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
	    }else{
	        echo 'Operation unsuccessful';
	    }
	}
	
  
  ?>
										</table>
									</div>
									<!-- table-responsive -->
								</div>
							 
								 
							</div>
							
						</div>
					</div>
					</div>
				</div>
				<!-- content-body -->
				<script src="lib/jquery/jquery.min.js"></script>
				<script src="lib/bootstrap/js/bootstrap.bundle.min.js"></script>
				<script src="lib/feather-icons/feather.min.js"></script>
				<script src="lib/perfect-scrollbar/perfect-scrollbar.min.js"></script>
				<script src="lib/prismjs/prism.js"></script>
				<script src="lib/js-cookie/js.cookie.js"></script>
				<script src="assets/js/cassie.js"></script>
				<script>
				$(function() {
					'use strict'
				})
				</script>
				<script>
				$(function() {
					'use strict'
					$('#modal6').on('show.bs.modal', function(event) {
							var animation = $(event.relatedTarget).data('animation');
							$(this).addClass(animation);
						})
						// hide modal with effect
					$('#modal6').on('hidden.bs.modal', function(e) {
						$(this).removeClass(function(index, className) {
							return(className.match(/(^|\s)effect-\S+/g) || []).join(' ');
						});
					});
				})
				</script>
		</body>

		</html>