<? include "top.php"; ?>
<!DOCTYPE html>
<html>
<head>
	<?php include('include/head.php'); ?>
	<title>Ticket List</title>
	<link rel="stylesheet" type="text/css" href="https://sarmac.b-cdn.net/plugins/datatables/media/css/jquery.dataTables.css">
	<link rel="stylesheet" type="text/css" href="https://sarmac.b-cdn.net/plugins/datatables/media/css/dataTables.bootstrap4.css">
	<link rel="stylesheet" type="text/css" href="https://sarmac.b-cdn.net/plugins/datatables/media/css/responsive.dataTables.css">
	<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
</head>
<body>
	<?php include('include/header.php'); ?>
	<?php include('include/sidebar.php'); 
	$csadded=$_SESSION['murgibhai'];
	$getlog=f(q("SELECT * FROM tbl_login WHERE l_uid='$csadded'"));
				$ltype=$getlog['l_type'];
	$action=$_REQUEST['action'];
	if($action=='update'){
		
		if($pupdate==1){
		
		$cid=$_REQUEST['cid'];

		
		$stat=$_REQUEST['stat'];
		

				$res=mysqli_query($con,"UPDATE tbl_ticket SET stat='$stat',suser='$getlog[l_read]',sdate=CURDATE() WHERE tkt_id='$cid'");

if($res){?>

					 <script type="text/javascript">
            Swal.fire('Data Updated Successfully','','success')
             </script>
				<?}else{?>

					<script type="text/javascript">
            Swal.fire('Error Saving Data','','error')
             </script>

				<? }
		}else{

			?>
				<script type="text/javascript">
			Swal.fire('You are not Authorized to perform this Action','','error')
			 </script>
			<?
		}

	}elseif($action=='delete'){

		if($pdelete==1){
		$cid=$_REQUEST['cid'];

		$res=mysqli_query($con,"DELETE FROM tbl_ticket WHERE tkt_id='$cid'");
		if($res){?>

					 <script type="text/javascript">
            Swal.fire('Data Deleted Successfully','','success')
             </script>
				<?}else{?>

					<script type="text/javascript">
            Swal.fire('Error Deleting Data','','error')
             </script>

				<? }

		}else{

			?>
				<script type="text/javascript">
			Swal.fire('You are not Authorized to perform this Action','','error')
			 </script>
			<?
		}

	}

	


	?>
	<style type="text/css">
		.form-control:focus{
        border: 1px solid red;

    }
    td{

    	font-size: 12px;
    }
    th{

    	font-size: 13px;
    }
    .btn:focus{
        border: 1px solid red;

    }
	</style>

	<?

		
				

	?>
	<div class="main-container">
		<div class="pd-ltr-20 customscroll customscroll-10-p height-100-p xs-pd-20-10">
			<div class="min-height-200px">
				<div class="page-header">
					<div class="row">
						<div class="col-md-6 col-sm-12">
							<div class="title">
								<h4>Ticket List</h4>
							</div>
							<nav aria-label="breadcrumb" role="navigation">
								<ol class="breadcrumb">
									<li class="breadcrumb-item"><a href="index.php">Home</a></li>
									<li class="breadcrumb-item active" aria-current="page">Ticket List</li>
								</ol>
							</nav>
						</div>
						<div class="col-md-6 col-sm-12 text-right">
							<!-- <div class="dropdown">
								<a class="btn btn-secondary dropdown-toggle" href="#" role="button" data-toggle="dropdown">
									January 2018
								</a>
								<div class="dropdown-menu dropdown-menu-right">
									<a class="dropdown-item" href="#">Export List</a>
									<a class="dropdown-item" href="#">Policies</a>
									<a class="dropdown-item" href="#">View Assets</a>
								</div>
							</div> -->
						</div>
					</div>
				</div>
				<!-- Default Basic Forms Start -->
				
				<div class="pd-20 bg-white border-radius-4 box-shadow mb-30">
					<div class="clearfix mb-20">
						<div class="pull-left">
							<h5 class="text-blue">Ticket List</h5>
						</div>
					</div>
					<div class="row">
						<table class="stripe hover multiple-select-row data-table-export nowrap">
							<thead>
								<tr>
									
									<th class="table-plus">Date</th>
									<th>Customer</th>
									<th>Type</th>
									<th>Details</th>
									<th>Status</th>
									<? if($ltype!='3'){?><th>Update</th>
									<th>Action</th>	<? } ?>
								</tr>
							</thead>
							<tbody>
								<?	$i=0;


									if($ltype=='2'){


										$query="SELECT * FROM tbl_ticket ORDER BY strtdt ASC";
									}elseif($ltype=='1'){

										$query="SELECT * FROM tbl_ticket ORDER BY strtdt ASC";

									}else{

											$getu=f(q("SELECT * FROM adduser WHERE custid='$getlog[l_read]'"));
											$query="SELECT * FROM tbl_ticket WHERE custid='$getu[id]' ORDER BY strtdt ASC";

									}

									//echo $query;	

									$getticket=mysqli_query($con,$query);
									while($arr=mysqli_fetch_array($getticket)){
										$i++;
										$getc=f(q("SELECT * FROM adduser WHERE id='$arr[custid]'"));
								?>
								<tr <? if($arr['stat']=='PENDING'){?> style="background-color: #c65b1a;color: white;"<? }elseif($arr['stat']=='SOLVED'){ ?>style="background-color: #44882c;color: white;" <? } ?>>
									
									<td class="table-plus"><?=$arr['strtdt']?></td>
									<td><?=$getc['name']?><br>
										<?=$getc['address']?><br>
										Landmark: <?=$getc['landmark']?><br>
										Phone: <a href="tel:<?=$getc['phone']?>"><?=$getc['phone']?></a><br>

										


									</td>
									<td><?=$arr['pticket']?></td>
									<td><?=$arr['pdet']?></td>
									<td><?=$arr['stat']?></td>
									<? if($ltype!='3'){?><td>
										<div class="dropdown">
											<a class="btn btn-outline-primary dropdown-toggle" href="#" role="button" data-toggle="dropdown" style="color: black;">
												<i class="fa fa-ellipsis-h"></i>
											</a>
											<div class="dropdown-menu dropdown-menu-right">
												
												<? if($arr['stat']=='PENDING'){?><a class="dropdown-item" href="<?=$_SERVER['PHP_SELF']?>?action=update&cid=<?=$arr['tkt_id']?>&stat=SOLVED"><i class="fa fa-thumbs-o-up"></i> Solved</a><? } ?>

												<? if($ltype=='1'){ ?>

													<? if($arr['stat']=='SOLVED'){?>
														<a class="dropdown-item" href="<?=$_SERVER['PHP_SELF']?>?action=update&cid=<?=$arr['tkt_id']?>&stat=PENDING"><i class="fa fa-thumbs-o-down"></i> Pending</a>

													<? } ?>
												<? } ?>

												
											</div>
										</div>

									
									

									</td>
									<td>
										<div class="dropdown">
											<a class="btn btn-outline-primary dropdown-toggle" href="#" role="button" data-toggle="dropdown" style="color: black;">
												<i class="fa fa-ellipsis-h"></i>
											</a>
											<div class="dropdown-menu dropdown-menu-right">
												
												<a class="dropdown-item" href="new-ticket.php?action=edit&cid=<?=$arr['tkt_id']?>"><i class="fa fa-pencil"></i> Edit</a>
													<? if($ltype=='1'){?><<a class="dropdown-item" href="<?=$_SERVER['PHP_SELF']?>?action=delete&cid=<?=$arr['tkt_id']?>" onclick="return confirm('Are you sure you want to delete this item?');"><i class="fa fa-trash"></i> Delete</a><? } ?>
											</div>
										</div>

									
									

									</td>
								<? } ?>
								</tr>
								<? } ?>	
							</tbody>
						</table>
					</div>
				</div>
				

			</div>
			<?php include('include/footer.php'); ?>
		</div>
	</div>
	<?php include('include/script.php'); ?>

	<script src="src/plugins/datatables/media/js/jquery.dataTables.min.js"></script>
	<script src="src/plugins/datatables/media/js/dataTables.bootstrap4.js"></script>
	<script src="src/plugins/datatables/media/js/dataTables.responsive.js"></script>
	<script src="src/plugins/datatables/media/js/responsive.bootstrap4.js"></script>
	<!-- buttons for Export datatable -->
	<script src="src/plugins/datatables/media/js/button/dataTables.buttons.js"></script>
	<script src="src/plugins/datatables/media/js/button/buttons.bootstrap4.js"></script>
	<script src="src/plugins/datatables/media/js/button/buttons.print.js"></script>
	<script src="src/plugins/datatables/media/js/button/buttons.html5.js"></script>
	<script src="src/plugins/datatables/media/js/button/buttons.flash.js"></script>
	<script src="src/plugins/datatables/media/js/button/pdfmake.min.js"></script>
	<script src="src/plugins/datatables/media/js/button/vfs_fonts.js"></script>
	<script>
		$('document').ready(function(){
			$('.data-table').DataTable({
				scrollCollapse: true,
				autoWidth: false,
				responsive: true,
				columnDefs: [{
					targets: "datatable-nosort",
					orderable: false,
				}],
				"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
				"language": {
					"info": "_START_-_END_ of _TOTAL_ entries",
					searchPlaceholder: "Search"
				},
			});
			$('.data-table-export').DataTable({
				scrollCollapse: true,
				autoWidth: false,
				responsive: true,
				columnDefs: [{
					targets: "datatable-nosort",
					orderable: true,
				}],
				"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
				"language": {
					"info": "_START_-_END_ of _TOTAL_ entries",
					searchPlaceholder: "Search"
				},
				dom: 'Bfrtip',
				buttons: [
				'copy', 'csv', 'pdf', 'print'
				]
			});
			var table = $('.select-row').DataTable();
			$('.select-row tbody').on('click', 'tr', function () {
				if ($(this).hasClass('selected')) {
					$(this).removeClass('selected');
				}
				else {
					table.$('tr.selected').removeClass('selected');
					$(this).addClass('selected');
				}
			});
			var multipletable = $('.multiple-select-row').DataTable();
			$('.multiple-select-row tbody').on('click', 'tr', function () {
				$(this).toggleClass('selected');
			});
		});
	</script>
</body>
</html>