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

?>
<div class="box-header" >
	<form action="<?php echo $submit_url;?>" method="post" name="search_form" id="search_form">
		<div class="col-sm-3">
			<label for="Appointment Text" class="control-label">Description</label>
			<textarea class="form-control" rows="4" id="appointment_text" name="appointment_text" required><?php echo stripslashes($appointment_text);?></textarea>
			
			<? if(isset($view_appointments_for_admin)){ ?>
		
			<label for="Contact" class="control-label">Contact</label>
			<? $gsi->getEnqQuoteJobList("job_id",$job_id,"100%",false,"form-control select2","required",$source); ?>
		
			<? }else {?>
				<input type="hidden" id="job_id" name="job_id" value="<?php echo $job_id;?>">
			<? }?>
		</div>
		<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 assign to this job. First assign consultant.</span>";
				}else{
					Admin::getAdminList("admin_id",$admin_id,"100%",true,"form-control","required",$admin_ids); 
				}
			?>
			</div>
			
			<label for="Appointment" class="control-label">Date</label>
			<input type="text" class="form-control datepicker" id="appointment_date" name="appointment_date" value="<?php (isset($appointment_date) && $appointment_date !="") ? utility::getFormatedDate($appointment_date) : utility::getFormatedDate(date($config->dateFormat));?>" required>
		</div>
		<div class="col-sm-3">
			<label for="Appointment Time" class="control-label">Time From</label>
			<div class="bootstrap-timepicker">
				<!--<input type="text" class="form-control timepicker" id="appointment_time" name="appointment_time" value="<?php //echo $appointment_time;?>">-->
				<? utility::getTimeList("appointment_time", $appointment_time, "Time From", "100%");?>
			</div>
			
			<label for="Appointment Time" class="control-label">Time To</label>
			<div class="bootstrap-timepicker">
				<!--<input type="text" class="form-control timepicker" id="appointment_time_to" name="appointment_time_to" value="<?php //echo $appointment_time_to;?>">-->
				<? utility::getTimeList("appointment_time_to", $appointment_time_to, "Time To", "100%");?>
			</div>
			
			<label for="Full Day" class="control-label">Full Day</label><br>
			<input class="flat-red" type="checkbox" id="is_full_day" name="is_full_day" <? echo ($is_full_day) ? "checked" : ""; ?>>
		</div>
		<!--<div class="col-sm-3">
			<label for="Job" class="control-label">Job</label>
			<? //$gsi->getEnqQuoteJobList("job_id",$job_id,"100%",false); ?>
		</div>-->
		<div class="col-sm-3">
			<label for="Location" class="control-label">Location</label>
			<input type="text" class="form-control" id="appointment_location" name="appointment_location" value="<?php echo $appointment_location;?>">
			
			<div style="clear:both;margin-top:23px;"></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>
	</form>
</div>
<script type="text/javascript">
$(function(){
	$('#search_form').submit(function(){
		$("#add_master_data").attr("disabled", true);
		$('#page_load_div').show();
	});
	$("#search_form").on("click","#admin_id",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/appointment/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 job. First assign consultant.");
						$("#admin_id_div").html(result);
					}
				}
			});
		}
	});
	$("#submit_form").click(function(){	
		if($("#span").text() == "No consultant assign to this job. First assign consultant."){
			alert("First select Consultant");
			return false;
		}
	});
});
</script>