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

$search_url = $file_name."?page=view_appointment_for_admin"; 
if(isset($source) && $source !=""){
	$show_all = "page=view_appointment_for_admin&source=$source"; 
}else{
	$show_all = "page=view_appointment_for_admin";  
}

?>
<!--<button data-toggle="collapse" data-target="#booke_appointment_area" type="button" name="" class="btn btn-primary" style="margin:0 0 5px 10px;float:left;clear:right;">Add Appointment</button>-->
<a href="" data-toggle="modal" data-target="#myModal" class="btn btn-primary appointments" style="margin:0 0 5px 10px;">
	Add Appointment</a>
<div style="clear:both;"></div>
<div class="panel box box-primary <?=$collapse_booke_appointment_area;?>" id="booke_appointment_area">
	<div class="box-header with-border">
		<form action="<?php echo $submit_url;?>" method="post" name="add_form" id="add_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>
				
				<label for="Contact" class="control-label">Contact</label>
				<? $gsi->getEnqQuoteJobList("job_id",$job_id,"100%",false,"form-control select2","required",$source); ?>
			</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);
					}
					Admin::getAdminList("admin_id",$admin_id,"100%",true,"form-control select_admin_id","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="Location" class="control-label">Location</label>
					<input type="text" class="form-control" id="appointment_location" name="appointment_location" value="<?php echo $appointment_location;?>">
				
					<label for="Full Day" class="control-label">&nbsp;</label><br>
					<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?></button>
			</div>
		</form>
	</div>
</div>

<div class="box-header" >
	<form action="<?php echo $search_url;?>" method="post" name="search_form" id="search_form">		
		<div class="col-sm-3 no-padding">
			<label for="Contact" class="control-label">Contact</label>
			<? $gsi->getEnqQuoteJobList("job_id_search",$job_id_search,"100%",false,"form-control select2","",$source); ?>
		</div>
		<div class="col-sm-2">
			<label for="Consultant" class="control-label">Consultant</label>
			<? Admin::getAdminList("admin_id_search",$admin_id_search,"100%",false,"form-control"); ?>
		</div>
		<div class="col-sm-2">
			<label for="From Appointment Date" class="control-label">From  Date</label>
			<input type="text" class="form-control datepicker" id="from_appointment_date" name="from_appointment_date" value="<?php (isset($from_appointment_date) && $from_appointment_date !="") ? utility::getFormatedDate($from_appointment_date) : "";?>">
		</div>
		<div class="col-sm-2">
			<label for="Appointment" class="control-label">To Date</label>
			<input type="text" class="form-control datepicker" id="to_appointment_date" name="to_appointment_date" value="<?php (isset($to_appointment_date) && $to_appointment_date !="") ? utility::getFormatedDate($to_appointment_date) : "";?>">
		</div>
		<div class="col-sm-1">
			<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-2">
			<div style="clear:both;margin-top:23px;"></div>		
			<input type="hidden" id="source" name="source" value="<?php echo $source;?>">
			<button type="submit" name="search" class="btn btn-success">Search
				<i class="fa fa-refresh fa-spin" style="display:none;" id="page_load_div"></i>
			</button>
			<button type="button" name="search" class="btn btn-info" onclick="javascript:window.location='?<?php echo $show_all ?>'">Show All</button>
		</div>
	</form>
</div>
<script type="text/javascript">
$(function(){
	$('#search_form').submit(function(){
		$("#submit").attr("disabled", true);
		$('#page_load_div').show();
	});
	$("#add_form").on("click",".select_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;
		}
	});
	$(".appointments").click(function(){	
		$("#myModalLabel").text("Appointment");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var view_appointments_for_admin = "&view_appointments_for_admin=show_contact_list";
		//var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/appointment/index?page=view"+view_appointments_for_admin+hide_top_left);
	});
	$(".close_button").click(function(){
		$(".modal_iframe").attr("src","");
		location.reload();
	});
});
</script>