<?php include('../config/setup.php'); ?>
<?php 
session_start();
if($_SERVER['REQUEST_METHOD'] == 'POST'){
    
    $action = $_POST['action'];

// package_master
    
    // package_master update query starts
    if($action == 'pack_edit'){
        $pack_id = $_POST['pack_id'];
        $pack_name = $_POST['pack_name'];
        $pack_duration = $_POST['pack_duration'];
        $pack_cost = $_POST['pack_cost'];
        $pack_sub_cate = $_POST['pack_sub_cate'];
        $pack_status = $_POST['pack_status'];
        
        $sql = "UPDATE package_master SET pack_name = '$pack_name', pack_duration = '$pack_duration', pack_cost = '$pack_cost', pack_sub_cate = '$pack_sub_cate', pack_status = '$pack_status' WHERE pack_id = '$pack_id' " ;
        if($config->query($sql) === TRUE){
            $_SESSION['status'] = "Updated Successfully";
		    $_SESSION['alert'] = "success";
        } else {
            $_SESSION['status'] = "Update Failed";
		    $_SESSION['alert'] = "error";
        }
    }
    // package_master update query ends
    
    // package_master delete query starts
    if($action == 'pack_del'){
        $pack_id = $_POST['pack_id'];
        
        $sql = "DELETE FROM package_master WHERE pack_id = '$pack_id' " ;
        if($config->query($sql) === TRUE){
            $_SESSION['status'] = "Deleted Successfully";
		    $_SESSION['alert'] = "success";
        } else {
            $_SESSION['status'] = "Delete Failed";
		    $_SESSION['alert'] = "error";
        }
    }
    // package_master delete query ends

}


?>

<?php include "head.php" ?>
	<div class="wrapper">
		<div class="main-header">
			<!-- Logo Header -->
			<?php include('logo.php'); ?>
			<!-- End Logo Header -->

			<!-- Navbar Header -->
			<?php include('topbar.php'); ?>
			<!-- End Navbar -->
		</div>
		<!-- Sidebar -->
		<?php include('sidebar.php'); ?>


		<div class="main-panel">
			<div class="content">
				<div class="page-inner">
					<div class="page-header">
						<h4 class="page-title">Inactive Package</h4>
					</div>
					<div class="row">
						<div class="col-md-12">
							<div class="card">
								<div class="card-body">
									<div class="table-responsive">
										<table id="basic-datatables" class="display table table-striped table-hover">
											<thead>
												<tr>
													<th>S.No</th>
													<th>Package</th>
													<th>Sub Category</th>
													<th>Duration</th>
													<th>Cost</th>
													<!--<th>Commission</th>-->
													<th>Action</th>
												</tr>
											</thead>
											<tbody>
											    <?php 
											        $sno = 1;
											        $sql = "SELECT * FROM package_master WHERE pack_status = 0 ";
											        $res = $config->query($sql);
											        while($pack = $res->fetch_assoc()){
											            $sub_id = $pack['pack_sub_cate'];
											    ?>
												<tr>
													<td><?= $sno;?></td>
													<td><?= $pack['pack_name'] ?></td>
													<td>
													    <?php 
													        $cate_sql = "SELECT * FROM sub_category WHERE Sub_Category_id = '$sub_id' AND Sub_Category_Status = 1 ";
                    								        $cate_res = $config->query($cate_sql);
                    								        $cate = $cate_res->fetch_assoc();
					                                        echo $cate['Sub_Category_Name'] ;
					                                   ?>
													</td>
													<td><?= $pack['pack_duration'] ?></td>
													<td><?= $pack['pack_cost'] ?></td>
													<!--<td><?#= $pack['pack_commission'] ?></td>-->
													<td class="d-flex align-items-center justify-content-between">
													    <?php
    														$status = $pack['pack_status'];
    														if ($status == 1) { ?>
    															<label class="btn btn-success btn-sm text-white">Active</label>
    														<?php
    														} else {
    														?>
    															<label class="btn btn-danger btn-sm text-white">In-Active</label>
    														<?php
    														}
														?>
														<a href="" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#editpack<?php echo $sno; ?>"> <i class="fas fa-pencil-alt"></i> </a>
														<form method="post">
															<input type="hidden" class="form-control" id="pack_id" name="pack_id" value="<?= $pack['pack_id'] ?>">
															<input type="hidden" class="form-control" name="action" value="pack_del">
															<button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('Are you confirm to delete this category?');"><i class="fas fa-trash"></i> </button>
														</form>
													</td>
														<!-- Modal -->
													<div class="modal fade" id="editpack<?php echo $sno; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
														<div class="modal-dialog" role="document">
															<div class="modal-content">
																<div class="modal-header">
																	<h5 class="modal-title" id="exampleModalLabel">Package Edit</h5>
																	<button type="button" class="close" data-dismiss="modal" aria-label="Close">
																		<span aria-hidden="true">&times;</span>
																	</button>
																</div>
																<div class="modal-body">
																	<form method="post" enctype="multipart/form-data">
																		<div class="form-group">
																			<label for="pack_name">Package Name</label>
																			<input type="hidden" class="form-control" id="pack_id" name="pack_id" value="<?= $pack['pack_id'] ?>">
																			<input type="text" class="form-control" id="pack_name" name="pack_name" placeholder="" value="<?= $pack['pack_name'] ?>">
																		</div>
																		<div class="form-group">
																			<label for="pack_duration">Package Duration</label>
																			<input type="text" class="form-control" id="pack_duration" name="pack_duration" placeholder="" value="<?= $pack['pack_duration'] ?>">
																		</div>
																		<div class="form-group">
																			<label for="pack_cost">Package Cost</label>
																			<input type="text" class="form-control" id="pack_cost" name="pack_cost" placeholder="" value="<?= $pack['pack_cost'] ?>">
																		</div>
																		<!--<div class="form-group">-->
																		<!--	<label for="pack_commission">Package Commission</label>-->
																		<!--	<input type="text" class="form-control" id="pack_commission" name="pack_commission" placeholder="" value="<?= $pack['pack_commission'] ?>">-->
																		<!--</div>-->
																		<div class="form-group">
                                                                            <label for="pack_sub_cate">Sub Category</label>
                                                                            <select class="form-control" name="pack_sub_cate" id="pack_sub_cate">
                                                                                <option value="<?= $pack['pack_sub_cate'] ?>"><?= $cate['Sub_Category_Name'] ?></option>
                                                                            <?php 
                                        								        $sub_sql = "SELECT * FROM sub_category WHERE Sub_Category_Status = 1 ";
                                        								        $sub_res = $config->query($sub_sql);
                                        								        while($sub = $sub_res->fetch_assoc()){
                                        								    ?>
                                                                                <option value="<?= $sub['Sub_Category_id'] ?>"><?= $sub['Sub_Category_Name'] ?></option>
                                                                            <?php } ?>
                                                                            </select>
                                                                        </div>
																		<div class="form-group">
																			<label for="pack_status"> Status</label>
																			<select class="form-control" id="pack_status" name="pack_status">
																				<?php
																				$status = $pack['pack_status'];
																				if ($status == 1) { ?>
																					<option value="1" selected>Active</option>
																					<option value="0">In-Active</option>
																				<?php } else if ($status == 0) { ?>
																					<option value="1">Active</option>
																					<option value="0" selected>In-Active</option>
																				<?php } else { ?>
																					<option value="1">Active</option>
																					<option value="0">In-Active</option>
																				<?php } ?>
																			</select>
																		</div>
																		<div class="form-group">
															                <input type="hidden" class="form-control" name="action" value="pack_edit">
																			<button class="btn btn-success" type="submit" name="submit">Submit</button>
																		</div>
																	</form>
																</div>
																<div class="modal-footer">
																	<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
																</div>
															</div>
														</div>
													</div>
												</tr>
												<?php $sno++; } ?>
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>

			<?php include('footer.php'); ?>
		</div>
		<!-- End Custom template -->
	</div>
	<!--   Core JS Files   -->
	<script src="../assets/js/core/jquery.3.2.1.min.js"></script>
	<script src="../assets/js/core/popper.min.js"></script>
	<script src="../assets/js/core/bootstrap.min.js"></script>
	<!-- jQuery UI -->
	<script src="../assets/js/plugin/jquery-ui-1.12.1.custom/jquery-ui.min.js"></script>
	<script src="../assets/js/plugin/jquery-ui-touch-punch/jquery.ui.touch-punch.min.js"></script>

	<!-- jQuery Scrollbar -->
	<script src="../assets/js/plugin/jquery-scrollbar/jquery.scrollbar.min.js"></script>
	<!-- Datatables -->
	<script src="../assets/js/plugin/datatables/datatables.min.js"></script>
	<!-- Atlantis JS -->
	<script src="../assets/js/atlantis.min.js"></script>
	<!-- Atlantis DEMO methods, don't include it in your project! -->
	<script src="../assets/js/setting-demo2.js"></script>
	<script>
		$(document).ready(function() {
			$('#basic-datatables').DataTable({});




		});
	</script>
</body>

</html>