<?php
require_once __DIR__ . '/../magic/auth.php';

$auth = bdr_require_privilege(15, '../logout.php');
$user = $auth['user_id'];
$father = $auth['user_id'];
$branch = $auth['branch'];
$conn = $auth['conn'];
$db = $auth['conn'];
$sr = 0 ; $Car = 0 ;
$Car = $_REQUEST['id'];
if($Car < 1){
	$sr = $_REQUEST['sr'];
	if($sr>0){
		$car_sr = $db->prepare("SELECT carid from naql where car_serial = ?");
		$car_sr->bindParam(1,$sr);
		$car_sr->execute();
			  if($car_sr->rowCount()>0)
			  {
				$row = $car_sr->fetch(PDO::FETCH_ASSOC);
				$Car = $row['carid'];
				}
	}
}

$today = date("Y-m-d");
?>
<!DOCTYPE html>
<html lang="ar" dir="rtl">

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta name="robots" content="index,follow">
	<meta name="author" content="سامح دياب">
	<link rel="icon" href="../images/perfect.ico">
	<title>تحديث بيانات النقل</title>
	<link rel="stylesheet" href="../dist/css/bootstrap.css" />
	<link rel="stylesheet" href="../css/font-awesome.min.css">
	<link rel="stylesheet" href="../hj2/humanity.calendars.picker.css">
	<link rel="stylesheet" href="../css/myCar.css" />
	<script src="../js/jquery.js"></script>
	<script src="../dist/js/umd/popper.min.js"></script>
	<script src="../dist/js/bootstrap.js"></script>
	<script src="../hj2/jquery.plugin.js"></script>
	<script src="../hj2/jquery.calendars.js"></script>
	<script src="../hj2/jquery.calendars.plus.js"></script>
	<script src="../hj2/jquery.calendars.picker.js"></script>
	<script src="../hj2/jquery.calendars.ummalqura.js"></script>
</head>

<body style="background-color:#EDF0F2;">
	<div class="container-fluid">
		<br />
		<button type="submit" class="btn btn-danger" name="close" id="close"><i style="font-size:14pt ;" class="fa fa-times" aria-hidden="true"></i></button>
		<br />
		<h3 style="text-align:center">تحديث بيانات هيئة النقل لسيارة <span id="hd_kind" style="font-size: 1.75rem;color:green"></span> لوحة رقم <span id="hd_numbers" style="font-size: 1.75rem;color:darkgreen;"></span> موديل <span id="hd_model" style="font-size: 1.75rem;"></span></h3>
		<br /><br /><br />

		<div class="row">
			<div class="col-2">
				<div class="row">
					<div class="col-12">
						<a id="ins1" href="" target="_blank"><button type="button" style="font-weight:bold;font-size:17px;padding:5px;" class="btn btn-outline-primary form-control"> صورة التأمين <i class="fa fa fa-film" aria-hidden="true"></i></button></a>
					</div>
				</div>
				<div class="row">
					<div class="col-12">
						<a id="card1" href="" target="_blank"><button type="button" style="font-weight:bold;font-size:17px;padding:5px;" class="btn btn-outline-danger form-control"> كارت التشغيل <i class="fa fa-heartbeat" aria-hidden="true"></i></button></a>
					</div>
				</div>
				<div class="row">
					<div class="col-12">
						<a href="lic_print.php?J=<?php echo $Car; ?>" target="_blank"><button type="button" style="font-weight:bold;font-size:17px;padding:5px;" class="btn btn-outline-success form-control"> رخصة <i class="fa fa-id-card" aria-hidden="true"></i> </button></a>
					</div>
				</div>
				<div class="row">
					<div class="col-12">
						<a id="check1" href="" target="_blank"><button type="button" style="font-weight:bold;font-size:17px;padding:5px;" class="btn btn-outline-danger form-control">فحص دوري<i class="fa fa-heartbeat" aria-hidden="true"></i></button></a>
					</div>
				</div>
				<div class="row">
					<div class="col-12">
						<a href="../ment/car_ment_br.php?id=<?php echo $Car; ?>" target="_blank"><button type="button" style="font-weight:bold;font-size:17px;padding:5px;" class="btn btn-outline-danger form-control"> كارتة الصيانة<i class="fa fa-shopping-cart" aria-hidden="true"></i></button></a>
					</div>
				</div>
				<div class="row">
					<div class="col-12">
					<a href="../a/ment_b_r.php?id=<?php echo $Car; ?>" target="_blank"><button type="button" style="font-weight:bold;font-size:17px;padding:5px;" class="btn btn-outline-danger form-control"> طلب صيانة <i class="fa fa-shopping-cart" aria-hidden="true"></i></button></a>
					</div>
				</div>
				<div class="row">
					<div class="col-12">
				<a href="../a/ment_respond.php?id=<?php echo $Car . '&req_id=' . $req_idd; ?>" target="_blank"><button type="button" style="font-weight:bold;font-size:17px;padding:5px;" class="btn btn-outline-danger form-control"> صيانة <i class="fa fa-heartbeat" aria-hidden="true"></i></button></a>
			</div>
				</div>
				<div class="row">
					<div class="col-12">
					<a href="../ment/car_contracts.php?dd=<?php echo $Car;?>" target="_blank"><button type="button" style="font-weight:bold;font-size:17px;padding:5px;" class="btn btn-success form-control"> عقود السيارة </button></a>
				</div>
				</div>
				
			</div>
			<div class="col-10">
				<input type="hidden" id="carid" />
				<br /> <!-- Nav tabs -->
				<ul class="nav nav-pills navbar-right">
					<li class="nav-item"><a class="nav-link active" style="float:right;" href="#tab_insurance" aria-controls="profile" role="tab" data-toggle="tab">تأمينات </a></li>
					<li class="nav-item"><a class="nav-link" style="float:right;" href="#tab_operation" aria-controls="profile" role="tab" data-toggle="tab">كارت تشغيل </a></li>
					<li class="nav-item"><a class="nav-link" style="float:right;" href="#tab_check" aria-controls="profile" role="tab" data-toggle="tab">فحص دوري</a></li>
					<li class="nav-item"><a class="nav-link" style="float:right;" href="#tab_gps"  role="tab" data-toggle="tab">تتبع</a></li>
				</ul>
				<!-- Tab panes -->
				<div id="form_msg"></div>
			<div class="tab-content" style="width:100% ;">
				<div role="tabpanel" class="tab-pane fad active" id="tab_insurance" >
					<form class="form-horizontal" id="form_insurance" method="POST" enctype="multipart/form-data" >
						<input type="hidden" id="naql_ins" name="naql_ins" value="<?php echo $Car; ?>" />
						<br /><br />
						<div id="form_ins_msg"></div>
						<div class="form-row align-items-center">
							<div class="col-1">
								<label for="insurance_id" class="control-label " style="float:left;">شركة التأمين</label>
							</div>
							<div class="col-4">
								<select class="form-control" id="insurance_id" name="insurance_id" style="padding:3px;">
									<?php
									$sql = $db->prepare("SELECT insurance_id , ins_name from insurance");
									$sql->execute();
									if ($sql->rowCount() > 0) {
										while ($row = $sql->fetch()) {
											$insurance_id   = $row["insurance_id"];
											$ins_name  = $row["ins_name"];
											echo "<option value= $insurance_id >$ins_name</option>";
										}
									} ?>
								</select>
							</div>
							<div class="col-1">
								<label for="insurance_money" class="control-label" style="float:left;">قسط التحمل</label>
							</div>
							<div class="col-2">
								<input type="number" class="form-control" id="insurance_money" name="insurance_money" value="" />
							</div>
							<div class="col-2">
								<label for="insurance_expire" class="control-label" style="float:left;">نهاية التأمين</label>
							</div>
							<div class="col-2">
								<input type="text" class="form-control" id="insurance_expire" name="insurance_expire" readonly value="" />
							</div>
						</div>
						<br />
						<div class="form-row">
							<div class="col-2">
								<label for="insurance_kind" class="control-label " style="float:left;">نوع التغطية التأمينية</label>
							</div>
							<div class="col-3">
								<select class="form-control" id="insurance_kind" name="insurance_kind" style="padding:3px;">
									<option value="1">المسئولية المدنية تجاه الغير</option>
									<option value="2">تغطية ضد الغير - وافي</option>
									<option value="3">تأمين شامل</option>
								</select>
							</div>
							<div class="col-2">
								<label for="insurance_no" class="control-label" style="float:left;">رقم الوثيقة</label>
							</div>
							<div class="col-5">
								<input type="text" class="form-control" id="insurance_no" name="insurance_no" value="" />
							</div>
						</div>
						<br /><br />
						<div class="form-row">
							<div class="col-6">
								<div class="row">
							<input style="font-weight:bold;" type="file" class="btn btn-primary" name="insurance_lic" id="insurance_lic" />
								</div>
								<br /><hr><br/>
								<div class="row">
							<button type="submit" class="btn btn-outline-success save" id="save_ins"><i style="font-size:14pt ;" class="fa fa-check-square-o" aria-hidden="true"></i></button>
								</div>
							</div>
							<div class="col-6">
							<img id="lic_preview" src="" class="img-fluid rounded" width="70%" height="auto" style="float:left;" alt="صورة الرخصة غير متاحة " disabled="disabled" readonly />
							</div>
						</div>
					</form> <!-- /.form -->
				</div><!-- /tab ins -->
				<!-- كارت تشغيل السيارة  -->
				<div role="tabpanel" class="tab-pane" id="tab_operation" >
					<form class="form-horizontal" id="form_operation" method="POST" enctype="multipart/form-data" >
						<input type="hidden" id="naql_oper" name="naql_oper" value="<?php echo $Car; ?>" />
						<br /><br />
						<div id="form_ins_msg"></div>
						<div class="form-row align-items-center">
							<div class="col-2">
								<label for="insurance_no" class="control-label " style="float:left;">رقم بطاقة التشغيل</label>
							</div>
							<div class="col-2">
								<input type="text" class="form-control" id="operation_no" name="operation_no" value="" />
							</div>
							<div class="col-2">
								<label for="car_serial" class="control-label" style="float:left;">الرقم التسلسلي</label>
							</div>
							<div class="col-2">
								<input type="text" class="form-control" id="car_serial" name="car_serial" value="" />
							</div>
							<div class="col-2">
								<label for="operation_expire" class="control-label" style="float:left;">نهاية بطاقة التشغيل</label>
							</div>
							<div class="col-2">
								<input type="text" class="form-control" id="operation_expire" name="operation_expire" value="" readonly/>
							</div>
						</div>
						<br />
						<br />
						<div class="form-row">
							<div class="col-6">
								<div class="row">
							<input style="font-weight:bold;" type="file" class="btn btn-primary" name="operationCard" id="operationCard" />
								</div>
								<br /><hr><br/>
								<div class="row">
							<button type="submit" class="btn btn-outline-success save" id="save_oper"><i style="font-size:14pt ;" class="fa fa-check-square-o" aria-hidden="true"></i></button>
								</div>
							</div>
							<div class="col-6">
							<embed id="oper_preview" src="" width="300px" height="410px" />
							</div>
						</div>
					</form> 
					
				</div><!-- operationCard end here -->

				<!-- الفحص الدوري -->
				<div role="tabpanel" class="tab-pane" id="tab_check" >
					<form class="form-horizontal" id="form_preCheck" method="POST" enctype="multipart/form-data" >
						<input type="hidden" id="naql_check" name="naql_check" value="<?php echo $Car; ?>" />
						<br /><br />
						
						<div class="form-row">
							<div class="col-6">
								<div class="row">
								<div class="col-4">
								<label for="pre_expire" class="control-label" style="float:left;">نهاية الفحص الدوري</label>
							</div>
							<div class="col-4">
								<input type="text" class="form-control" id="pre_expire" name="pre_expire" value="" readonly/>
								<script>
									$(function() {
										var calendar = $.calendars.instance('');
										$('#insurance_expire').calendarsPicker({
											calendar: calendar
										});
										$('#operation_expire').calendarsPicker({
											calendar: calendar
										});
										$('#pre_expire').calendarsPicker({
											calendar: calendar
										});
									});
								</script>
							</div>
								</div>
								<br /><br />
								<div class="row">
							<input style="font-weight:bold;" type="file" class="btn btn-primary" name="pre_check" id="pre_check" />
								</div>
								<br /><hr><br/>
								<div class="row">
							<button type="submit" class="btn btn-outline-success" id="save_check"><i style="font-size:14pt ;" class="fa fa-check-square-o" aria-hidden="true"></i></button>
								</div>
							</div>
							<div class="col-6">
							<img id="check_preview" src="" class="img-fluid rounded" width="70%" height="auto" style="float:left;" alt="صورة الفحص الدوري غير متاحة " disabled="disabled" readonly />
							</div>
						</div>
					</form> <!-- /.form -->
				</div><!-- /tab preCheck-->
					<!-- gps link code -->
					<div role="tabpanel" class="tab-pane" id="tab_gps" >
					<form class="form-horizontal" id="form_gps" method="POST" enctype="multipart/form-data" >
						<input type="hidden" id="naql_gps" name="naql_gps" value="<?php echo $Car; ?>" />
						<br /><br />
						
						<div class="form-row">
								<div class="col-2">
								<label for="gpsid" class="control-label" style="float:left;">كود متابعة السيارة</label>
							</div>
							<div class="col-2">
								<input type="number" class="form-control" id="gpsid" name="gpsid"/>
								<script>
									$(function() {
										var calendar = $.calendars.instance('');
										$('#insurance_expire').calendarsPicker({
											calendar: calendar
										});
										$('#operation_expire').calendarsPicker({
											calendar: calendar
										});
										$('#pre_expire').calendarsPicker({
											calendar: calendar
										});
									});
								</script>
							</div>
							<div class="col-3">
								<label for="serviceid" class="control-label" style="float:left;">كود خدمةالسيارة</label>
							</div>
							<div class="col-2">
								<input type="number" class="form-control" id="serviceid" name="serviceid"/>
								</div>
								
								</div>
								<br /><hr><br/>
								<div class="row">
							<button type="submit" class="btn btn-outline-success" id="gps"><i style="font-size:14pt ;" class="fa fa-check-square-o" aria-hidden="true"></i></button>
								</div>
						</div>
					</form> <!-- /.form -->
				</div><!-- /tab gps-->
			</div><!-- end tab area -->
		</div>
								</div>
</div><!-- container -->
		<script>
			$(document).ready(function(){
				fetch('<?php echo $Car ?>');
				function fetch(carid) {
					$.ajax({
						url: "naql_single.php",
						method: "POST",
						data: {
							carid: carid
						},
						dataType: "json",
						success: function(data) {
							$("#carid").val(data.carid);
							$("#naql_ins").val(data.carid);
							$("#car_ins").val(data.carid);
							$('#lic_preview').attr('src', '../photo/insurance/' + data.insurance_lic);
							$('#ins1').attr('href', '../photo/insurance/' + data.insurance_lic);
							$("#hd_kind").html(data.kind);
							var numb = data.numbers ;
							$("#hd_numbers").html(data.letters +" " +numb);
							$("#hd_model").html(data.model);
							
							$("#insurance_id").val(data.insurance_id);
							$("#insurance_no").val(data.insurance_no);
							$("#insurance_kind").val(data.insurance_kind);
							$("#insurance_money").val(data.insurance_money);
							$("#insurance_expire").val(data.insurance_expire);

							$("#operation_no").val(data.operation_no);
							$("#car_serial").val(data.car_serial);
							$("#operation_expire").val(data.operation_expire);
							$("#oper_preview").attr('src','../photo/operationCard/' + data.operationCard+"#toolbar=0");
							$("#card1").attr('href','../photo/operationCard/' + data.operationCard+"#toolbar=0");

							$("#pre_expire").val(data.pre_expire);
							$('#check_preview').attr('src', '../photo/preCheck/' + data.pre_check);
							$("#gpsid").val(data.gpsid);
							$("#serviceid").val(data.serviceid);
						},
						error: function(data) {
							alert(data.statusText);
						}
					});
				} //end of fetch car

				$('#close').click(function() {
					close();
				});

			$('#form_insurance').on('submit', function(event){
					event.preventDefault();
					var filee = $('#insurance_lic').val()
					if(filee !=""){
						var extension = $('#insurance_lic').val().split('.').pop().toLowerCase();
					if (extension != '') {
						if (jQuery.inArray(extension, ['png', 'jpg', 'jpeg']) == -1) {
							alert("صور jpg فقط");
							$('#insurance_lic').val('');
							return false;
						}
					var oFReader = new FileReader();
						oFReader.readAsDataURL(document.getElementById("insurance_lic").files[0]);
						var f = document.getElementById("insurance_lic").files[0];
						var fsize = f.size || f.fileSize;
						if (fsize > 1900000) {
							alert("حجم الصورة كبير جدا ...");
							return false;
						}
					}}
						$.ajax({
							url			: "naql_actions.php",
							method		: "POST",
							data		: new FormData(this),
							contentType	: false,
							processData	: false,
							success		: function(data) {
								// $('#form_photo')[0].reset();
								// $('#lic_preview').attr("src", "../photo/insurance/" + data);
								$('#form_msg').html(data);
								$("#form_msg").delay(3000).slideUp(function() {
								$("#form_msg").html('');
								});
							}
						});
				}); //end of button add image

				$('#form_operation').on('submit', function(event){
					event.preventDefault();
					var filee = $('#operationCard').val()
					if(filee !=""){
						var extension = $('#operationCard').val().split('.').pop().toLowerCase();
					if (extension != '') {
						if (jQuery.inArray(extension, ['pdf', 'jpg', 'jpeg']) == -1) {
							alert("صور pdf فقط");
							$('#operationCard').val('');
							return false;
						}
					var oFReader = new FileReader();
						oFReader.readAsDataURL(document.getElementById("operationCard").files[0]);
						var f = document.getElementById("operationCard").files[0];
						var fsize = f.size || f.fileSize;
						if (fsize > 1900000) {
							alert("حجم الصورة كبير جدا ...");
							return false;
						}
					}}
						$.ajax({
							url			: "naql_actions.php",
							method		: "POST",
							data		: new FormData(this),
							contentType	: false,
							processData	: false,
							success		: function(data) {
								$('#form_msg').html(data);
								$("#form_msg").delay(3000).slideUp(function() {
								$("#form_msg").html('');
								});
							}
						});
				}); //end of button add image

				$('#form_preCheck').on('submit', function(event){
					event.preventDefault();
					var filee = $('#pre_check').val()
					if(filee !=""){
						var extension = $('#pre_check').val().split('.').pop().toLowerCase();
					if (extension != '') {
						if (jQuery.inArray(extension, ['png', 'jpg', 'jpeg']) == -1) {
							alert("صور jpg فقط");
							$('#pre_check').val('');
							return false;
						}
					var oFReader = new FileReader();
						oFReader.readAsDataURL(document.getElementById("pre_check").files[0]);
						var f = document.getElementById("pre_check").files[0];
						var fsize = f.size || f.fileSize;
						if (fsize > 1900000) {
							alert("حجم الصورة كبير جدا ...");
							return false;
						}
					}}
						$.ajax({
							url			: "naql_actions.php",
							method		: "POST",
							data		: new FormData(this),
							contentType	: false,
							processData	: false,
							success		: function(data) {
								$('#form_msg').html(data);
								// $("#form_msg").delay(3000).slideUp(function() {
								// $("#form_msg").html('');
								// });
							}
						});
				}); //end of pre check form

				$('#form_gps').on('submit', function(event){
					event.preventDefault();
							$.ajax({
							url			: "naql_actions.php",
							method		: "POST",
							data		: new FormData(this),
							contentType	: false,
							processData	: false,
							success		: function(data) {
								$('#form_msg').html(data);
								$("#form_msg").delay(3000).slideUp(function() {
								$("#form_msg").html('');
								});
							}
						});
				}); //end of pre check form


			});
		</script>
</body>

</html>
