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

$search_url = $file_name."?page=view_notes_for_admin"; 
if(isset($source) && $source !=""){
	$show_all = "page=view_notes_for_admin&source=$source"; 
}else{
	$show_all = "page=view_notes_for_admin";
}
?>
<div class="hide_search_div">
<!--<button data-toggle="collapse" data-target="#booke_note_area" type="button" name="" class="btn btn-primary" style="margin:0 0 5px 10px;" >Add Note</button>-->
<a href="" data-toggle="modal" data-target="#myModal" class="btn btn-primary notes" style="margin:0 0 5px 10px;">
	Add Note</a>
<div class="panel box box-primary <?=$collapse_booke_notes_area;?>" id="booke_note_area">
	<div class="box-header with-border">
		<form action="<?php echo $submit_url;?>" method="post" name="search_form" id="search_form">
			<div class="col-sm-6">
				<label for="Description" class="control-label">Description</label>
				<textarea class="form-control" rows="4" id="note_text" name="note_text" required><?php echo stripslashes($note_text);?></textarea>
			</div>
			<div class="col-sm-3 hide">
				<label for="Date" class="control-label">Date</label>
				<input type="text" class="form-control" id="note_date" name="note_date" value="<?php (isset($note_date) && $note_date !="") ? utility::getFormatedDate($note_date) : utility::getFormatedDate(date($config->dateFormat));?>" required>
			</div>
			<div class="col-sm-3">
				<label for="Contact" class="control-label">Contact</label>
				<? $gsi->getEnqQuoteJobList("job_id",$job_id,"100%",false,"form-control select2 job_id","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%",false,"form-control","required",$admin_ids); 
				?>
				</div>
			</div>	
			<!--<div class="col-sm-3">
				<label for="Consultant" class="control-label">Consultant</label>
				<? //Admin::getAdminList("admin_id",$admin_id,"100%",false,"form-control"); ?>
			</div>-->
			<div class="col-sm-3">
				<div style="clear:both;margin-top:23px;"></div>
				<input type="hidden" id="id" name="id" value="<?php echo $id;?>">
				<!--<input type="hidden" id="job_id" name="job_id" value="<?php echo $job_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_form1" id="search_form1">		
		<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 job_id","",$source); ?>
		</div>
		<!--<div class="col-sm-3">
			<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</label>
			<input type="text" class="form-control datepicker" id="from_note_date" name="from_note_date" value="<?php (isset($from_note_date) && $from_note_date !="") ? utility::getFormatedDate($from_note_date) : "";?>">
		</div>
		<div class="col-sm-2">
			<label for="Appointment" class="control-label">To</label>
			<input type="text" class="form-control datepicker" id="to_note_date" name="to_note_date" value="<?php (isset($to_note_date) && $to_note_date !="") ? utility::getFormatedDate($to_note_date) : "";?>">
		</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>
</div>
<script type="text/javascript">
$(function(){
	$('#search_form1').submit(function(){
		$("#submit").attr("disabled", true);
		$('#page_load_div').show();
	});
	$("#admin_id").change(function(){	
		if($("#job_id").val() == ""){
			alert("First select Client");
			$(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/notes/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 client. First assign consultant.");
						$("#admin_id_div").html(result);
					}
				}
			});
		}
	});
	$("#submit_form").click(function(){	
		if($("#span").text() == "No consultant assign to this client. First assign consultant."){
			alert("First select Consultant");
			return false;
		}
	});
	$(".notes").click(function(){	
		$("#myModalLabel").text("Notes");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var view_notes_for_admin = "&view_notes_for_admin=hide_contact_list";
		//var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/notes/index?page=view"+view_notes_for_admin+hide_top_left);
	});
	$(".close_button").click(function(){
		$(".modal_iframe").attr("src","");
		location.reload();
	});
});
</script>