<?php 
$submit_url = $file_name."?page=view&action=$action"; 
$status_submit_url = $file_name."?page=view&name=$name"; 

?>
<div class="box-header" >
	<div class="">
	<form action="<?php echo $submit_url;?>" method="post" name="search_form" id="search_form">
		<div class="row">
		<div class="col-sm-3">
			<label for="Mileage Text" class="control-label">Description</label>
			<textarea class="form-control" rows="4" id="mileage_text" name="mileage_text" required><?php echo stripslashes($mileage_text);?></textarea>
		</div>
		<? if(isset($view_mileage_for_admin)){ ?>
		<div class="col-sm-3">
			<label for="Job" class="control-label">Enquiry/Quote/Job</label>
			<?// $gsi->getEnqQuoteJobList("job_id",$job_id,"100%",false,"form-control select2","required",$source); ?>
			<? $gsi->getEnqQuoteJobList("job_id",$job_id,"100%",false,"form-control select2 job_id","required",$source); ?>
		</div>	
		<? }else {?>
			<input type="hidden" id="job_id" name="job_id" value="<?php echo $job_id;?>">
		<? }?>
		<div class="col-sm-3">
			<label for="Consultant" class="control-label">Consultant</label>
			<div id="admin_id_div">
			<? 
				$admin_ids = "";
				$sql_for_admin = "SELECT * FROM job_admin_mapping WHERE job_id = $job_id";
				$rs_for_admin = mysqli_query($conn,$sql_for_admin);
				if(mysqli_num_rows($rs_for_admin) > 0){
					while($row_for_admin = mysqli_fetch_assoc($rs_for_admin)){
						$admin_ids .= $row_for_admin["admin_id"].",";
					}
					$admin_ids = substr($admin_ids,0,-1);
				}
				if($admin_ids == ""){
					echo "<br><span style='color:red;' id='span'>No consultant. First select contact.</span>";
				}else{
					Admin::getAdminList("admin_id",$admin_id,"100%",false,"form-control","required",$admin_ids); 
				}
			?>
			</div>
			
			<label for="Mileage" class="control-label">Miles</label>
			<input type="text" class="form-control" id="mileage" name="mileage" value="<?php echo $mileage;?>" required>
		</div>
		<div class="col-sm-3">
			<label for="Mileage" class="control-label">Mileage Date</label>
			<input type="text" class="form-control datepicker" id="mileage_date" name="mileage_date" value="<?php (isset($mileage_date) && $mileage_date !="") ? utility::getFormatedDate($mileage_date) : utility::getFormatedDate(date($config->dateFormat));?>" required>
		</div>
		<!--<div class="col-sm-3">
			<label for="Job" class="control-label">Job</label>
			<? //$bebcrm->getEnqQuoteJobList("job_id",$job_id,"100%",false); ?>
		</div>-->
		<div class="col-sm-3">
			<div style="clear:both;margin-top:30px;"></div>
			<input type="hidden" id="id" name="id" value="<?php echo $id;?>">
			<input type="hidden" id="query_string" name="query_string" value="<?php echo $query_string;?>">
			<input type="hidden" id="source" name="source" value="<?php echo $source;?>">
			<button type="submit" name="add_master_data" id="submit_form" class="btn btn-primary"><?=$button_value?>
				<i class="fa fa-refresh fa-spin" style="display:none;" id="page_load_div"></i>
			</button>
		</div>
		</div>
	</form>
	</div>
</div>
<script type="text/javascript">
$(function(){
	$("#submit_form").click(function(){	
		if($("#span").text() == "No consultant assign to this job. First assign consultant."){
			alert("First select Consultant");
			return false;
		}
	});
	$('#search_form').submit(function(){
		$("#submit_form").attr("disabled", true);
		$('#page_load_div').show();
	});
	$("#admin_id").change(function(){	
		if($("#job_id").val() == ""){
			alert("First select Contact");
			$(this).val("");
			return false;
		}
	});
	$("#job_id").change(function(){	
		var job_id = $(this).val();
		if(job_id != ""){
		var form_data   = {'job_id':job_id};       
			$.ajax({
				async: false,
				type: "POST",
				url: site_url+"/modules/mileage/index.php?page=ajax_actions&action=get_admin_by_job",
				data: form_data,
				success: function(result){  
					if(result){
						$("#admin_id_div").html(result);
					}else{
						alert("No consultant assign to this contact. First assign consultant.");
						$("#admin_id_div").html(result);
					}
				}
			});
		}
	});
});
</script>