<? include "top.php"; ?>
<!DOCTYPE html>
<html>
<head>
	<?php include('include/head.php'); ?>
	<title>Lanes</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'); 

	$action=$_REQUEST['action'];
	 if($action=='save'){
	 $cid=$_REQUEST['cid'];
    $name=addslashes($_POST['name']);
     $dob=addslashes($_POST['dob']);
    $gender=addslashes($_POST['gender']);
    $email=addslashes($_POST['email']);
    $custid=addslashes($_POST['custid']);
    $phone=addslashes($_POST['phone']);
    $price=addslashes($_POST['price']);
    $address=addslashes($_POST['address']);
    $payid=addslashes($_POST['pay_ch']);

    $getp=f(q("SELECT * FROM tbl_pack WHERE pid='$payid'"));
    $pay_ch=$getp['pname'];
    $price=$getp['prc'];

    $vc=addslashes($_POST['vc']);
    $stb=addslashes($_POST['stb']);
    $area_id=$_POST['area_id'];
    $l_pass=addslashes($_POST['l_pass']);
    $slisql="INSERT INTO `adduser` SET 
    `name`='$name',
    `dob`='$dob',
    `gender`='$gender',
    `email`='$email',
    `custid`='$custid',
    `phone`='$phone',
    `address`='$address',
    `price`='$price',pay_ch='$pay_ch',is_cable=0,vc='$vc',stb='$stb',area_id='$area_id',packid='$payid'";
    
    //echo $slisql; die();
    $res=mysqli_query($con,$slisql);
    $msid=mysqli_insert_id($con);
    $newsuer=f(q("SELECT * FROM `adduser` WHERE user_id='$msid'"));
    $nwuser=$newsuer['stb'];
    if($res){
        mysqli_query($con,"INSERT INTO tbl_login SET l_pass=md5('$l_pass'),l_uid=md5('$nwuser'),l_name='$name',l_read='admin',l_type='4',l_act='1',user_id='$msid'");
        
    }else{?>
 <script type="text/javascript">
            Swal.fire('Data Saved','','success')
             </script>


    <?}
    
    }elseif($action=='update'){
    $cid=$_REQUEST['cid'];
    $name=addslashes($_POST['name']);
     $dob=addslashes($_POST['dob']);
    $gender=addslashes($_POST['gender']);
    $email=addslashes($_POST['email']);
    $custid=addslashes($_POST['custid']);
    $phone=addslashes($_POST['phone']);
    $price=addslashes($_POST['price']);
    $address=addslashes($_POST['address']);
    $payid=addslashes($_POST['pay_ch']);

    $getp=f(q("SELECt * FROM tbl_pack WHERE pid='$payid'"));
    $pay_ch=$getp['pname'];
    $price=$getp['prc'];


    $vc=addslashes($_POST['vc']);
    $stb=addslashes($_POST['stb']);
    $area_id=$_POST['area_id'];

    $slisql="UPDATE `adduser` SET 
    `name`='$name',
    `dob`='$dob',
    `gender`='$gender',
    `email`='$email',
    `custid`='$custid',
    `phone`='$phone',
    `address`='$address',
    `price`='$price',pay_ch='$pay_ch',vc='$vc',stb='$stb',area_id='$area_id',packid='$payid' 
     WHERE id='$cid'";
    
    //echo $slisql;
    $res=mysqli_query($con,$slisql);
    if(!$res){
        //echo mysql_error();
        
    }else{?>

         <script type="text/javascript">
            Swal.fire('Data Updated','','success')
             </script>


    <?}




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

          $cid=$_REQUEST['cid'];
          $edit=f(q("SELECT * FROM `adduser` WHERE `id`='$cid'"));




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


          $cid=$_REQUEST['cid'];
          $edit=f(q("DELETE FROM `adduser` WHERE `id`='$cid'"));
          ?>
           <script type="text/javascript">
            Swal.fire('Data Deleted','','success')
             </script>

   <? }
    
?>
	<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>Lanes</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">Lanes</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">
					<small style="color: red;"><?=$msg?></small>
					<form action="<?=$_SERVER['PHP_SELF']?>?action=<? if($action=='edit'){?>update&cid=<?=$cid?><? }else{?>save<?} ?>" method="POST">
					
					<div class="clearfix" style="min-height: 30px;"></div>

						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Select Area</label>
							<div class="col-sm-12 col-md-10">
								<select name="area_id" class="form-control">
									<option value="0">Choose Area</option>
									<?
										$areas=mysqli_query($con,"SELECT * FROM tbl_area");
										while($arrr=mysqli_fetch_array($areas)){
									?>
									<option value="<?=$arrr['arid']?>"  <? if($edit['area_id']==$arrr['arid']){?> selected <? } ?>><?=$arrr['arname']?></option>
 
									<? } ?>
								</select>
							</div>
						</div>
					
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Name</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control" type="text" name="name" placeholder="enter name" value="<?=$edit['name']?>" required>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Ac No</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control" type="text" name="custid" placeholder="enter Ac NO" value="<?=$edit['custid']?>" required>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Email</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control" type="email" name="email" placeholder="enter Email" value="<?=$edit['email']?>">
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Phone</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control" type="text" name="phone" placeholder="enter Phone" value="<?=$edit['phone']?>" required>
							</div>
						</div>
						
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">IP Address</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control" type="text" name="vc" placeholder="enter IP" value="<?=$edit['vc']?>" required>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Username</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control" type="text" name="stb" placeholder="enter Username" value="<?=$edit['stb']?>" required>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Password</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control" type="password" name="l_pass" placeholder="Enter Password" value="<?=$edit['l_pass']?>" required>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Details</label>
							<div class="col-sm-12 col-md-10">
								<select name="pay_ch" class="form-control" required="">
									<option value="0"> Choose Package</option>
									<?
										$ipack=mysqli_query($con,"SELECT * FROM tbl_pack WHERE ptype='1'");
										while($arri=mysqli_fetch_array($ipack)){

									?>
									<option value="<?=$arri['pid']?>" <? if($edit['packid']==$arri['pid']){?> selected <? } ?>><?=$arri['pname']?> (<?=$arri['prc']?>)</option>

									<? } ?>
								</select>
								
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">MRP</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control" type="text" name="price" placeholder="enter MRP" value="<?=$edit['price']?>" readonly>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Expiry Date</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control" type="date" name="dob" placeholder="" value="<? if($action=='edit'){?><?=$edit['dob']?><? }else{ ?><? echo date('Y-m-d');?><? } ?>" required>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">GST</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control" type="text" name="gender" placeholder="Enter GST Number" value="<?=$edit['gender']?>">
							</div>
						</div>
						
						
						<div class="clearfix">
						<div class="pull-left">
							<!-- <h4 class="text-blue">Default Basic Forms</h4>
							<p class="mb-30 font-14">All bootstrap element classies</p> -->
						</div>
						<div class="pull-right">
							<button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-save"></i> Save</button>
							<!-- <a href="#basic-form1" class="btn btn-primary btn-sm scroll-click" rel="content-y"  data-toggle="collapse" role="button"><i class="fa fa-code"></i> Source Code</a> -->
						</div>
					</div>
					</form>
					<div class="collapse collapse-box" id="basic-form1" >
						
					</div>
				</div>
				<!-- <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">Lane List</h5>
						</div>
					</div>
					<div class="row">
						<table class="stripe hover multiple-select-row data-table-export nowrap">
							<thead>
								<tr>
									<th class="table-plus datatable-nosort">Name</th>
									<th>Area Name</th>	
									
									<th>Action</th>	
								</tr>
							</thead>
							<tbody>
								<?
									$getc=mysqli_query($con,"SELECT * FROM tbl_lane ORDER BY lnname");
									while($arr=mysqli_fetch_array($getc)){

										$getar=f(q("SELECT * FROM tbl_area WHERE arid='$arr[lnarid]'"));
								?>
								<tr>
									<td class="table-plus"><?=$arr['lnname']?></td>
									<td><?=$getar['arname']?></td>	
									
									<td>
									<a href="<?=$_SERVER['PHP_SELF']?>?action=edit&cid=<?=$arr['lnid']?>">EDIT</a><br>
									<a href="<?=$_SERVER['PHP_SELF']?>?action=delete&cid=<?=$arr['lnid']?>" onclick="return confirm('Are you sure you want to delete this item?');">DELETE</a><br>
									

									</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: false,
				}],
				"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>