<?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');
		return $result;
	}
	
	if (CheckAccess()) {
		header("location:login.php");
			echo '<script> window.location.href = "login.php"; </script>';
			exit();
	}
	
	$admin_id = $_SESSION['admin_id'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <?php include "includes/headerlinks.php";?>
	<style>
		b {
			font-weight:600 !important;
		}
	</style>
	<link href="assets/plugins/Magnific-Popup-master/dist/magnific-popup.css" rel="stylesheet">
</head>

<body class="fix-header card-no-border">
    <!-- ============================================================== -->
    <!-- Preloader - style you can find in spinners.css -->
    <!-- ============================================================== -->
    <?php include "includes/loader.php";?>
    <!-- ============================================================== -->
    <!-- Main wrapper - style you can find in pages.scss -->
    <!-- ============================================================== -->
    <div id="main-wrapper">
        <!-- ============================================================== -->
        <!-- Topbar header - style you can find in pages.scss -->
        <!-- ============================================================== -->
        <?php include "includes/header.php";?>
        <!-- ============================================================== -->
        <!-- End Topbar header -->
        <!-- ============================================================== -->
        <!-- ============================================================== -->
        <!-- Left Sidebar - style you can find in sidebar.scss  -->
        <!-- ============================================================== -->
        <?php include "includes/sidebar.php";?>
        <!-- ============================================================== -->
        <!-- End Left Sidebar - style you can find in sidebar.scss  -->
        <!-- ============================================================== -->
        <!-- ============================================================== -->
        <!-- Page wrapper  -->
        <!-- ============================================================== -->
        <div class="page-wrapper">
            <!-- ============================================================== -->
            <!-- Bread crumb and right sidebar toggle -->
            <!-- ============================================================== -->
            <div class="row page-titles">
                <div class="col-md-5 align-self-center">
                    <h3 class="text-themecolor">Manage Testimonials </h3>
                </div>
                <div>
                    <button class="right-side-toggle waves-effect waves-light btn-inverse btn btn-circle btn-sm pull-right m-l-10"><i class="ti-settings text-white"></i></button>
                </div>
            </div>
            <!-- ============================================================== -->
            <!-- End Bread crumb and right sidebar toggle -->
            <!-- ============================================================== -->
            <!-- ============================================================== -->
            <!-- Container fluid  -->
            <!-- ============================================================== -->
            <div class="container">
                <!-- ============================================================== -->
                <!-- Start Page Content -->
                <!-- ============================================================== -->
                <!-- Row -->
				<div class="card">
                    <div class="card-body">
                        <h6 class="card-subtitle"><a href="#" class="btn btn-success" data-toggle="modal" data-target="#addCategory">+ Add Testimonial</a></h3></h6>
						<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="addCategory" class="modal fade">
							<div class="modal-dialog modal-md">
								<div class="modal-content">
									<div class="modal-header">
										<h4 class="modal-title"><b>Add Testimonial</b></h4>
										<button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
									</div>
									<div class="modal-body">
										<form method="post" enctype="multipart/form-data">
											<div class="row">
												<div class="col-md-12">
													<div class="form-group">
														<label for="exampleInputEmail1"><b>Image</b></label>
														<div class="custom-file mb-3">
														  <input type="file" class="custom-file-input" name="item_image_1" id="customFile" accept="image/png, image/gif, image/jpeg" / required>
														  <label class="custom-file-label form-control" for="customFile">Choose file</label>
														</div>
													</div>
												</div>
											</div>
											<div class="modal-footer" style="padding: 15px 0px !important">
												<button type="submit" name="add_testimonial" class="btn btn-success">Save</button>
												<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
											</div>
										</form>
									</div>
								</div>
							</div>
						</div>
						<div class="row el-element-overlay">
							
							<?php
								$result_category = mysqli_query($con,"SELECT * FROM category order by c_name ASC");
								if(mysqli_num_rows($result_category)>0){
								while($row_category=mysqli_fetch_array($result_category)){
									$cate_id = $row_category['c_id'];
							?>
							<div class="col-lg-4 col-md-6">
								<br>
								<div class="card">
									<div class="el-card-item">
										<div class="el-card-avatar el-overlay-1">
											<a class="image-popup-vertical-fit" href="uploads/testimonials/<?php echo $row_category['picture'];?>"> <img src="uploads/testimonials/<?php echo $row_category['picture'];?>" alt="user"> </a>
										</div><hr>
										<div class="el-card-content">
											<a class="btn default btn-sm btn-warning btn-outline mt-2" data-toggle="modal" data-target="#edit<?=$cate_id;?>" style="color:white"><i class="icon-pencil"></i></a>
											<a class="btn default btn-sm btn-danger btn-outline mt-2" data-toggle="modal" data-target="#delete<?=$cate_id;?>" style="color:white"><i class="icon-trash"></i></a>
											
											<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="edit<?=$cate_id;?>" class="modal fade">
												<div class="modal-dialog modal-md">
													<div class="modal-content">
														<div class="modal-header">
															<h4 class="modal-title"><b>Edit Testimonial</b></h4>
															<button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
														</div>
														<div class="modal-body">
															<form method="post" enctype="multipart/form-data">
																<div class="row">
																	<div class="col-md-12">
																		<div class="form-group">
																			<input type="hidden" name="category_id" value="<?=$cate_id?>">
																			<label for="exampleInputEmail1" style="float:left"><b>Image</b></label>
																			<center><img src="uploads/testimonials/<?php echo $row_category['picture'];?>" class="img-responsive" style="width:30% !important" alt="image not found"/></center>
																			<br><div class="custom-file mb-3" style="float:left">
																			  <input type="file" class="custom-file-input" name="item_image_1" id="customFile" accept="image/png, image/gif, image/jpeg" />
																			  <label class="custom-file-label form-control" for="customFile" style="float:left">Choose file</label>
																			</div>
																		</div>
																	</div>
																</div>
																<div class="modal-footer" style="padding: 15px 0px !important">
																	<button type="submit" name="edit_testimonial" class="btn btn-success">Save</button>
																	<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
																</div>
															</form>
														</div>
													</div>
												</div>
											</div>
											
											
											<div class="modal fade in" id="delete<?=$cate_id;?>"  role="dialog" aria-hidden="true">
												<div class="modal-dialog" role="document">
													<div class="modal-content">
													  <div class="modal-body">
														<h4 style="float:left !important">Are you sure you want to delete this ?</h4>
													  </div>
													  <div class="modal-footer">
														<form method="post">
															<input type="hidden" name="c_id" value="<?=$cate_id;?>">
															<input type="hidden" name="picture_name" value="<?php echo $row_category['picture'];?>">
															<button type="submit" class="btn btn-danger" name="delete_testimonial" >Delete</button>
															<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
														</form>
													  </div>
													</div>
												</div>
											</div>
											<br>
										</div>
									</div>
								</div>
							</div>
							<?php
									}
								} else {
									echo '<h6 class="text-center text-capitalize" style="color:red;">No record found. </h6>';
								}
							?>
						</div>
                    </div>
                </div>
            <!-- ============================================================== -->
            <!-- End Container fluid  -->
            <!-- ============================================================== -->
            <!-- ============================================================== -->
            <!-- footer -->
            <!-- ============================================================== -->
            <?php include "includes/footer.php";?>
            <?php include "includes/theme.php";?>
            <!-- ============================================================== -->
            <!-- End footer -->
            <!-- ============================================================== -->
        </div>
		
        <!-- ============================================================== -->
        <!-- End Page wrapper  -->
        <!-- ============================================================== -->
    </div>
    <?php include "includes/footerlinks.php";?>
    <script>
		$(".custom-file-input").on("change", function() {
		  var fileName = $(this).val().split("\\").pop();
		  $(this).siblings(".custom-file-label").addClass("selected").html(fileName);
		});
	</script>
</body>

</html>
