<?
$job_id = $_REQUEST['job_id'];

$button_value 	= "Add";
$page_action 	= "add";
if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit'){
	$page_action 	= "update";
	$button_value 	= "Update";
	
	$id = $_REQUEST['id'];
	$sql= "SELECT * FROM notes WHERE id = $id";
    $result_edit = mysqli_query($conn,$sql);
    $row_edit = mysqli_fetch_array($result_edit);

    $id= $row_edit['id'];
    $job_id= $row_edit['job_id'];
    //$admin_id= explode(",",$row_edit['admin_id']);
	$admin_id= $row_edit['admin_id'];
	$note_text= $row_edit['note_text'];
	$note_date= $row_edit['note_date'];
	$scorecard_notes_option= $row_edit['scorecard_notes_option'];
}
?>
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<div class="box box-primary">
				<div class="box-body">
				<form action="" method="post" name="add_form" id="add_form">
					<div class="col-sm-3 hide">
						<!--<label for="Project" class="control-label">Project</label>-->
						<? //echo $gsi->getClientProjectList("project_id",$project_id,"100%",false,"form-control","",$job_id); ?>
						
						<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-6">
						<label for="Description" class="control-label">Description</label>
						<textarea class="form-control" rows="4" id="note_text" name="note_text" placeholder="Description"><?php echo stripslashes($note_text);?></textarea>
					</div>
					
					<div style="clear:both;margin-top:13px;"></div>
					<div class="col-sm-3">
						<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="page_action" name="page_action" value="<?php echo $page_action;?>">
						<button type="submit" name="add_master_data" id="add_master_data" class="btn btn-primary"><?=$button_value;?></button>
						<i class="fa fa-refresh fa-spin" style="display:none;" id="page_load_div_for_post_out"></i>
						<i class="fa fa-check" id="post_out_done" style="color:#bad23a;font-size: 20px;display:none;"></i>
					</div>
				</form>
				</div>
			</div>
		</div>
	</div>
</section>
<script type="text/javascript">
$(function(){
	 //$("#add_form").submit(function(e) {
	 $(document).on('submit','form#add_form',function(e){
		$(this).find('#post_out_done').hide();
		$(this).find('#page_load_div_for_post_out').show();
		$(this).find("#add_master_data").attr("disabled", true);
		//document.getElementById("add_master_data").disabled = true;
		
		e.preventDefault(); //prevent Default functionality
		var page_action = $("#page_action").val();
		var flag = 0;
		if(page_action == "add"){
			flag = 1;
		}
		
		var form_data = $('form').serialize();     
		$.ajax({
			async: true,
			type: "POST",
			url: "<?php echo $siteURL?>/enquiry_management/index?page=ajax_post_out&action=add_post_out",
			data: form_data,
			success: function(result){  
				if(flag == 1){
					var frm = document.getElementsByName('add_form')[0];
					frm.reset();  // Reset all form data
				}
				$('#post_out_done').show();
				$('#page_load_div_for_post_out').hide();
				$("#add_master_data").attr("disabled", false);
				//return false; // Prevent page refresh
			}
		});
	});
});
</script>