<?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="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="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>
			
			<? if(isset($view_timesheet_for_admin)){ ?>
				<label for="Organisation" class="control-label">Organisation</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); ?>
			<? }else {?>
				<input type="hidden" id="job_id" name="job_id" value="<?php echo $job_id;?>">
			<? }?>
		</div>
		<div class="col-sm-3">
			<label for="Timesheet Date" 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 class="col-sm-3">
			<label for="Consultant" class="control-label">Consultant</label>
			<? 
			
				/* $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);
				} */
				
				Admin::getAdminList("admin_id",$admin_id,"100%",true,"form-control","required");
			?>
		</div>
		<!--<div class="col-sm-3">
			<label for="Job" class="control-label">Job</label>
			<? //$criscrm->getEnqQuoteJobList("job_id",$job_id,"100%",false); ?>
		</div>
		<div class="col-sm-3">
			<label for="Consultant" class="control-label">Consultant</label>
			<? //Admin::getAdminList("admin_id",$admin_id,"100%",false); ?>
		</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="project_id" name="project_id" value="<?php echo $project_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-success">
				<?=$button_value?>
				<i class="fa fa-refresh fa-spin" style="display:none;" id="page_load_div"></i>
			</button>
		</div>
		</div>
	</form>
</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;
		}
	});
	$('#add_form').submit(function(){
		$("#submit_form").attr("disabled", true);
		$('#page_load_div').show();
	});
	<? 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);
	});
	<? } ?>
	/* $("#timesheet_time").focus(function(){
		var from_time = $("#from_time").val();
		var to_time = $("#to_time").val();
		if(from_time != "" && to_time != ""){
			var form_data   = {'from_time':from_time,'to_time':to_time};       
			$.ajax({
				async: false,
				type: "POST",
				url: site_url+"/modules/timesheet_management/index.php?page=ajax_actions&action=calculate_time",
				data: form_data,
				success: function(result){  
					var resultObj = jQuery.parseJSON(result); 
					$('#timesheet_time').val(resultObj.calculate_time);
				}
			});
		}
	}); */
	$("#from_time,#to_time").change(function(){
		var from_time = $("#from_time").val();
		var to_time = $("#to_time").val();		
		if(!((from_time == "00:00" || from_time == "00:00:00") && (to_time == "00:00" || to_time == "00:00:00"))){
			var form_data   = {'from_time':from_time,'to_time':to_time};       
			$.ajax({
				async: false,
				type: "POST",
				url: site_url+"/modules/timesheet_management/index.php?page=ajax_actions&action=calculate_time",
				data: form_data,
				success: function(result){  
					var resultObj = jQuery.parseJSON(result); 
					$('#timesheet_time').val(resultObj.calculate_time);
				}
			});
		}
	});
});
</script>