<?php session_start(); ?>
<?php 
	include "database.php";
	include "includes/operations.php";
	if(!isset($_SESSION['admin_id'])){
		echo '<script> window.location.href = "login.php"; </script>';
		header("location:login.php"); exit();
	}
	
	function CheckAccess() {
		
    $result = (isset($_SESSION['role']) &&  $_SESSION['role'] != 'Super Admin' &&  $_SESSION['role'] != 'User');
		return $result;
	}
	
	if (CheckAccess()) {
		header("location:login.php");
			echo '<script> window.location.href = "login.php"; </script>';
			exit();
	}
	
	$admin_id = $_SESSION['admin_id'];
	
		
	$product_id = 0;
	if(isset($_GET['pid'])){
		$product_id = intval($_GET['pid']);
	}
	$result = mysqli_query($con, "SELECT * FROM product WHERE product_id=$product_id");
	$row = mysqli_fetch_array($result);
	$product_title = $row['product_title'];
	$product_price = $row['product_price'];
	$product_description = $row['product_description'];
	
	
?>
<!DOCTYPE html>
<html lang="en">
	<head>
		<?php include "includes/headerlinks.php";?>
		<style>
		b {
			font-weight:600 !important;	
		}
		.form-horizontal label {
			color:black !important;
			font-weight:600 !important;	
		}
		.form-material .form-control {
			color:black !important;
		}
	</style>
	
	<link href="assets/plugins/morrisjs/morris.css" rel="stylesheet">
	</head>
	<body class="fix-header card-no-border">
			<?php include "includes/loader.php";?>
		<div id="main-wrapper">
			<?php 
				include "includes/header.php";
				include "includes/sidebar.php";
			?>
			<div class="page-wrapper">
				<div class="row page-titles">
					<div class="col-md-5 align-self-center">
						<h3 class="text-themecolor">Product Details</h3>
					</div>
				</div>
				<div class="container-fluid">
					<div class="row">
                    <!-- Column -->
						<div class="col-lg-4 col-xlg-3 col-md-5">
							<div class="card">
								<div class="card-body">
									<center class="m-t-5"> <img src="../images/product_images/<?php echo $row['product_image']?>" onerror="this.onerror=null;this.src='assets/images/null.png'" class="img-responsive" width="150">
									</center>
								</div>
							</div>
						</div>
						<!-- Column -->
						<!-- Column -->
						<div class="col-lg-8 col-xlg-9 col-md-7">
							<div class="card">
								<!-- Tab panes -->
								<div class="tab-content">
									<div class="tab-pane show active" id="settings" role="tabpanel">
										<div class="card-body">
											<form class="form-horizontal form-material">
												<div class="form-group">
													<label class="col-md-12">Title</label>
													<div class="col-md-12">
														<input type="text" placeholder="Johnathan Doe" class="form-control form-control-line" value="<?php echo $product_title?>" readonly>
													</div>
												</div>
												<div class="form-group">
													<label class="col-md-12">Price</label>
													<div class="col-md-12">
														<input type="text" placeholder="Johnathan Doe" class="form-control form-control-line" value="$<?php echo $product_price?>" readonly>
													</div>
												</div>
												<div class="form-group">
													<label class="col-md-12">Description</label>
													<div class="col-md-12">
														<?php echo $product_description?>
													</div>
												</div>
											</form>
										</div>
									</div>
								</div>
							</div>
						</div>
						<!-- Column -->
					</div>
				</div>
				<?php 
					include "includes/footer.php";
					include "includes/theme.php";
				?>
			</div>
		</div>
		<script src="assets/plugins/jquery/jquery.min.js"></script>
		<script src="assets/plugins/bootstrap/js/popper.min.js"></script>
		<script src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>
		<script src="js/jquery.slimscroll.js"></script>
		<script src="js/waves.js"></script>
		<script src="js/sidebarmenu.js"></script>
		<script src="assets/plugins/sticky-kit-master/dist/sticky-kit.min.js"></script>
		<script src="assets/plugins/sparkline/jquery.sparkline.min.js"></script>
		<script src="js/custom.min.js"></script>
		<script src="assets/plugins/styleswitcher/jQuery.style.switcher.js"></script>
		<script src="assets/plugins/morrisjs/morris.js"></script>
		<script src="js/morris-data.js"></script>
	</body>
    <script>
    $(document).ready(function() {
        $('#myTable').DataTable();
        $(document).ready(function() {
            var table = $('#example').DataTable({
                "columnDefs": [{
                    "visible": false,
                    "targets": 2
                }],
                "order": [
                    [2, 'asc']
                ],
                "displayLength": 25,
                "drawCallback": function(settings) {
                    var api = this.api();
                    var rows = api.rows({
                        page: 'current'
                    }).nodes();
                    var last = null;
                    api.column(2, {
                        page: 'current'
                    }).data().each(function(group, i) {
                        if (last !== group) {
                            $(rows).eq(i).before('<tr class="group"><td colspan="5">' + group + '</td></tr>');
                            last = group;
                        }
                    });
                }
            });
            // Order by the grouping
            $('#example tbody').on('click', 'tr.group', function() {
                var currentOrder = table.order()[0];
                if (currentOrder[0] === 2 && currentOrder[1] === 'asc') {
                    table.order([2, 'desc']).draw();
                } else {
                    table.order([2, 'asc']).draw();
                }
            });
        });
		$('.summernote').summernote({
            height: 150, // set editor height
            minHeight: null, // set minimum height of editor
            maxHeight: null, // set maximum height of editor
            focus: false // set focus to editable area after initializing summernote
        });

        $('.inline-editor').summernote({
            airMode: true
		});
		window.edit = function() {
			$(".click2edit").summernote()
		},
		window.save = function() {
			$(".click2edit").summernote('destroy');
		}
    });
	$('.select2').select2()
    $('#example23').DataTable({
        dom: 'Bfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ]
    });
	
    </script>
</html>
