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

$search_url = $file_name."?page=view_timesheet_for_admin"; 
$show_all = "page=view_timesheet_for_admin";  
?>
<div class="hide_search_div">
<!--<button data-toggle="collapse" data-target="#booke_timesheet_area" type="button" name="" class="btn btn-primary" style="margin:0 0 5px 10px;" >Add Timesheet</button>-->
<a href="" data-toggle="modal" data-target="#myModal" class="btn btn-primary timesheet" style="margin:0 0 5px 10px;">
	Add Timesheet</a>
<div class="panel box box-primary <?=$collapse_booke_timesheet_area;?>" id="booke_timesheet_area">
	<div class="box-header with-border">
		<form action="<?php echo $submit_url;?>" method="post" name="add_form" id="add_form">
			<div class="row">
				<div class="col-sm-3">
					<label for="Timesheet Text" class="control-label">Description</label>
					<textarea class="form-control" rows="4" id="timesheet_text" name="timesheet_text" required><?php echo stripslashes($timesheet_text);?></textarea>
					
					<label for="Timesheet Option" class="control-label">Timesheet Option</label>
					<? echo Keycode::getKeycodeListValue("timesheet_option", $timesheet_option, $width = "100%", "Timesheet Option", "id", "code", "timesheet_option","","form-control","","required"); ?>
				</div>
				<div class="col-sm-3">
					<label for="Organisation" class="control-label">Organisation</label>
					<? $gsi->getEnqQuoteJobList("job_id",$job_id,"100%",false,"form-control select2"); ?>
					
					<label for="Consultant" class="control-label">Consultant</label>
					<div id="admin_id_div">
					<?
						$admin_ids = "";
						if(isset($_REQUEST['job_id_search']) && $_REQUEST['job_id_search'] !=""){
							$job_id = $_REQUEST['job_id_search'];
						}
						$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_ids ="";
						if(isset($_REQUEST['job_id_search']) && $admin_ids != ""){
							Admin::getAdminList("admin_id",$admin_id,"100%",true,"form-control select_admin_id","required",$admin_ids); 
						}else if(isset($_REQUEST['job_id_search']) && $admin_ids == ""){
							echo "<span style='color:red;' id='span'>No consultant assign to this job. First assign consultant.</span>";
						}else{
							
							Admin::getAdminList("admin_id",$admin_id,"100%",false,"form-control select_admin_id","required",$admin_ids); 
						}
					?>
					</div>
				</div>
				<div class="col-sm-3">
					<label for="From Time" class="control-label">From Time</label>
					<div class="bootstrap-timepicker">
						<!--<input type="text" class="form-control timepicker" id="from_time" name="from_time" value="<?php //echo $from_time;?>">-->
						<? utility::getTimeList("from_time", $from_time, "From Time", "100%");?>
					</div>
					
					<label for="To Time" class="control-label">To Time</label>
					<div class="bootstrap-timepicker">
						<!--<input type="text" class="form-control timepicker" id="to_time" name="to_time" value="<?php //echo $to_time;?>">-->
						<? utility::getTimeList("to_time", $to_time, "To Time", "100%");?>
					</div>
					
					<div class="hide">
						<label for="Project" class="control-label">Project</label>
						<div id="project_div">
							<? //$gsi->getProjectListByJobId("project_id",$project_id,"100%",false,"form-control select2","required",$job_id); ?>
						</div>
					</div>
				</div>
				<div class="col-sm-3">
					<label for="Timesheet" class="control-label ">Date</label>
					<input type="text" class="form-control datepicker" id="timesheet_date" name="timesheet_date" value="<?php (isset($timesheet_date) && $timesheet_date !="") ? utility::getFormatedDate($timesheet_date) : utility::getFormatedDate(date($config->dateFormat));?>" required>
					
					<label for="Timesheet Time" class="control-label">Time</label>
					<div class="bootstrap-timepicker">
						<!--<input type="text" class="form-control timepicker" id="timesheet_time" name="timesheet_time" value="<?php //echo $timesheet_time;?>">-->
						<? utility::getTimeList("timesheet_time", $timesheet_time, "Time", "100%");?>
					</div>
				</div>
				<div style="clear:both;margin-top:23px;"></div>
				<div class="col-sm-3">
				<div style="margin-top:23px;"></div>
					<input type="hidden" id="id" name="id" value="<?php echo $id;?>">
					<input type="hidden" id="search_job_id" name="search_job_id" value="<?php echo $_REQUEST['job_id_search'];?>">
					<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>
			</div>
		</form>
	</div>
</div>

<div class="box-header" >
	<form action="<?php echo $search_url;?>" method="post" name="search_form" id="search_form">		
		<div class="row">
		<div class="col-sm-2 no-padding">
			<label for="Organisation" class="control-label">Organisation</label>
			<? //$gsi->getEnqQuoteJobList("job_id_search",$job_id_search,"100%",false,"form-control select2"); ?>
			<? $gsi->getEnqQuoteJobList("job_id_search",$job_id_search,"100%",false,"form-control select2 job_id","",$source); ?>
		</div>
		<div class="col-sm-2 hide">
			<label for="Project" class="control-label">Project</label>
			<div id="project_search_div">
				<? //$gsi->getProjectList("project_id_search",$project_id_search,"100%",false,"form-control select2","",$job_id_search); ?>
			</div>
		</div>
		<div class="col-sm-2">
			<label for="From timesheet Date" class="control-label">From</label>
			<input type="text" class="form-control datepicker" id="from_timesheet_date" name="from_timesheet_date" value="<?php (isset($from_timesheet_date) && $from_timesheet_date !="") ? utility::getFormatedDate($from_timesheet_date) : "";?>">
		</div>
		<div class="col-sm-2">
			<label for="timesheet" class="control-label">To</label>
			<input type="text" class="form-control datepicker" id="to_timesheet_date" name="to_timesheet_date" value="<?php (isset($to_timesheet_date) && $to_timesheet_date !="") ? utility::getFormatedDate($to_timesheet_date) : "";?>">
		</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="Timesheet Option" class="control-label">Timesheet Option</label>
			<? echo Keycode::getKeycodeListValue("timesheet_option_search", $timesheet_option_search, $width = "100%", "Timesheet Option", "id", "code", "timesheet_option","","form-control"); ?>
		</div>
		<div class="col-sm-3">
			<div style="clear:both;margin-top:23px;"></div>			
			<button type="submit" name="search" class="btn btn-success" style="float:left;clear:right;margin-right:10px;">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 ?>'" style="float:left;clear:right;">Show All</button>
			
			<a href="" onClick="window.print();" class="btn btn-default hide_search_div" style="float:right !important;margin-bottom:4px;"><i class="fa fa-print"></i> Print</a>
		</div>
		</div>
	</form>
</div>
</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 Organisation");
			$(this).val("");
			return false;
		}
	});
	<? if(!(isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit')){ ?>
	$("#timesheet_option").change(function(){
		var timesheet_option_text = $("#timesheet_option option:selected").text();
		var timesheet_text = $("#timesheet_text").val();
		$("#timesheet_text").val(timesheet_option_text+"\n"+timesheet_text);
	});
	<? } ?>
	/* $("#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/activity_management/index.php?page=ajax_actions&action=get_project_by_job",
				data: form_data,
				success: function(result){  
					if(result){
						$("#project_div").html(result);
					}else{
						alert("No project added to this organisation. First add project.");
						$("#project_div").html(result);
					}
				}
			});
		}
	}); */
	/* $("#job_id_search").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/activity_management/index.php?page=ajax_actions&action=get_searched_project_by_job",
				data: form_data,
				success: function(result){  
					if(result){
						$("#project_search_div").html(result);
					}else{
						alert("No project added to this organisation. First add project.");
						$("#project_search_div").html(result);
					}
				}
			});
		}
	}); */
	$("#submit_form").click(function(){	
		if($("#span").text() == "No consultant assign to this organisation. First assign consultant."){
			alert("First select Consultant");
			return false;
		}
	});
	$(".timesheet").click(function(){	
		$("#myModalLabel").text("Timesheets");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var view_timesheet_for_admin = "&view_timesheet_for_admin=show_contact_list";
		//var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/timesheet_management/index?page=view"+view_timesheet_for_admin+hide_top_left);
	});
	$(".close_button").click(function(){
		$(".modal_iframe").attr("src","");
		location.reload();
	});
});
</script>