<div class="collapse" id="collapseEducationInProgress">
	<div class="card card-body">
		<div class="container">
			<div class="row">
				<h4 class="card-title float-left">Education In Progress</h4>
				<div class="btn-group ml-auto float-right">
					<button type="button" class="btn btn-primary btn-sm d-print-none <?php echo $btn_hidden; ?>" style="margin-bottom:15px; width: 200px;" onclick="openStudyModal();" data-trigger="hover" data-tooltip="tooltip" title="Add Education In Progress">
						<i class="fa fa-plus"></i> Add New
					</button>
				</div>
			</div>
		</div>

		<hr>
		<div class="table-responsive">
			<table id="table_study" class="table table-hover table-bordered">
				<thead>
					<tr>
						<th>Details</th>
						<th>Created At</th>
						<?php if($btn_hidden == ''){ ?>
							<th>Action</th>
						<?php } ?>
					</tr>
				</thead>
				<tbody>	

					<?php if($pursuing_study) foreach ($pursuing_study as $key => $pursuing): ?>
					<tr class="link-row" data-id="<" >
						<td>
							<?php
							// $status = ($pursuing->status == 1)?'Completed':'On Going';
							if($pursuing->status == 0) $status = 'On Going';
							else if($pursuing->status == 1) $status = 'Graduated';
							else if($pursuing->status == 2) $status = 'Withdrawn';
							else if($pursuing->status == 3) $status = 'Deferred';
							
							echo '<b>Program : </b>'.$pursuing->program
							.'<br/><b>University / Institution : </b>'.$pursuing->institution
							.'<br/><b>Progress Paper In Hand : </b>'.$pursuing->progress_paper
							.'<br/><b>Start Date : </b>'.date('d-m-Y',strtotime($pursuing->date_start))
							.'<br/><b>Expected Date of Completion : </b>'.date('d-m-Y',strtotime($pursuing->date_end))
							.'<br/><b>Status : </b>'.$status
							.'<br/><b>Attachment : </b>';
							?>
							<a href="<?php echo base_url('hr/myprofile/openAttachment/'.$pursuing->mask_id.'/8')?>" target="_blank"><?php echo $pursuing->attachment_name; ?></a>
						</td>
						<td>
							<?php //echo $pursuing->created_at; ?>
						</td>
						<?php if($btn_hidden == ''){ //debug(date('m-Y', $live_date));?>
							<?php if(strtolower($pursuing->action_type) == 'personal data update' && date('m-Y',strtotime($pursuing->created_at)) == date('m-Y', $live_date)){ ?>	
								<td class="text-center">
									<div class="btn-group">
										<button id="editstudy" type="button" class="btn btn-success btn-sm d-print-none" title="Edit Current Pursuing Study"  onclick="editStudy(<?php echo $pursuing->id; ?>)"><span class="fa fa-edit"></span></button>
										<button type="button" class="btn btn-danger btn-sm d-print-none" onclick="deleteStudy(<?php echo $pursuing->id; ?>)" title="Delete Current Pursuing Study"><span class="fa fa-trash"></span></button>
									</div>
								</td> 
							<?php } else { ?>
								<td class="text-center">
									<div class="btn-group" role="group">
										<button class="btn btn-success btn-sm" disabled style="cursor: not-allowed;" data-trigger="hover" data-tooltip="tooltip" title="Not allowed to update"><i class="fas fa-edit" ></i></button>
										<button class="btn btn-danger btn-sm" disabled style="cursor: not-allowed;" data-trigger="hover" data-tooltip="tooltip" title="Not allowed to delete"><i class="fas fa-trash-alt"></i></button>
									</div>
								</td> 
							<?php } ?>
						<?php } ?>
					</tr>
					<?php endforeach ?>						
				</tbody>
			</table>
		</div><br>

		<div class="container">
			<div class="row">
				<h4 class="card-title float-left">Professional Exam / Courses</h4>
				<div class="btn-group ml-auto float-right">
					<button type="button" class="btn btn-primary btn-sm d-print-none <?php echo $btn_hidden ?>" onclick="openExamModal_ep(1);" style="margin-bottom:15px; width: 200px;"><i class="fas fa-plus"></i> Add New</button>
				</div>
			</div>
		</div>

		<hr>

		<div class="table-responsive">
			<table id="table_education_progress_exam" class="table table-hover table-bordered">
				<thead>
					<tr>
						<th>No.</th>
						<th>Program</th>
						<th>Paper Code</th>
						<th>Title of Paper/Subject</th>
						<th>Exam Date</th>
						<th>Status</th>
						<th>Result</th>
						<?php if($btn_hidden == ''){ ?>	
							<th class="d-print-none">Action</th>
						<?php } ?>
					</tr>
				</thead>
				<tbody>
					<?php $i=0; if($exam_list_ep){ foreach ($exam_list_ep as $value) { ?>
						<tr>
							<td><?php echo ++$i; ?></td>
							<td><?php echo $value['programme']; ?></td>
							<td>
								<?php echo $value['paper_code']; ?>
								<br><br>
								<small><b>Attachment : </b>
									<br><a href="<?php echo base_url('hr/myprofile/openAttachment/'.$value['mask_id'].'/9')?>" target="_blank"><i><?php echo $value['attachment_name']; ?></i></a>
								</small>
							</td>
							<td><?php echo $value['title']; ?></td>
							<td><?php if(($value['exam_date'] != null) && ($value['exam_date'] != '1970-01-01')){ echo date("d-m-Y", strtotime($value['exam_date'])); }else{ echo ''; } ?>
							</td>
							<td>
								<?php if($value['status'] == 0){ ?>
									<span class="badge badge-pill badge-info"> New ! </span>
								<?php } else { ?>
									<span class="badge badge-pill badge-danger"> Repeat ! </span>
								<?php } ?>
								<br> 
								<?php if($value['request_sl_status'] == 0){ ?>
									<button type="button" class="badge badge-pill badge-warning" title="Request for Study Leave" onclick="request_leave_ep(<?php echo $value['id']; ?>)"> Request SL &nbsp;<i class="far fa-hand-point-up"></i></button>
								<?php } else { ?>
									<button type="button" class="badge badge-pill badge-success" title="Study Leave Requested"> SL Requested &nbsp;<i class="fas fa-check"></i></button>
								<?php } ?>
							</td>
							<td><?php if($value['result'] == '0'){ echo "FAILED"; }else if($value['result'] == 1){ echo "PASS"; } ?></td>
							<?php if($value['result'] != NULL){ ?>
								<td class="text-center">
									<div class="btn-group btn-group-sm" role="group" aria-label="Basic example">

										<button type="button" class="btn btn-success" title="Clone" data-toggle="modal" data-target="#cloneModal_ep" onclick="clone_exam_ep(this)"
										data-id="<?php echo $value['id']; ?>"
										data-staffid="<?php echo $value['staff_id']; ?>"
										data-tab_id="<?php echo $value['tab_id']; ?>"
										data-programme="<?php echo $value['programme_id']; ?>"
										data-paper_code="<?php echo $value['paper_code']; ?>"
										data-title="<?php echo $value['title']; ?>"
										data-exam_date="<?php if(($value['exam_date'] != null) && ($value['exam_date'] != '1970-01-01')){ echo date("d-m-Y", strtotime($value['exam_date'])); }else{ echo ''; } ?>"
										data-status="<?php echo $value['status']; ?>"
										data-result="<?php echo $value['result']; ?>"
										><i class="fas fa-redo-alt"></i></button>

										<button type="button" class="btn btn-warning" title="Not allowed to edit this list." disabled><i class="fas fa-edit"></i></button>

										<button type="button" class="btn btn-danger" title="Not allowed to delete this list." disabled><i class="fas fa-trash"></i></button>
									</div>
								</td>
							<?php } else { ?>
								<td class="text-center">
									<div class="btn-group btn-group-sm" role="group" aria-label="Basic example">

										<button type="button" class="btn btn-success" title="Clone" data-toggle="modal" data-target="#cloneModal_ep" onclick="clone_exam_ep(this)"
										data-id="<?php echo $value['id']; ?>"
										data-staffid="<?php echo $value['staff_id']; ?>"
										data-tab_id="<?php echo $value['tab_id']; ?>"
										data-programme="<?php echo $value['programme_id']; ?>"
										data-paper_code="<?php echo $value['paper_code']; ?>"
										data-title="<?php echo $value['title']; ?>"
										data-exam_date="<?php if(($value['exam_date'] != null) && ($value['exam_date'] != '1970-01-01')){ echo date("d-m-Y", strtotime($value['exam_date'])); }else{ echo ''; } ?>"
										data-status="<?php echo $value['status']; ?>"
										data-result="<?php echo $value['result']; ?>"
										><i class="fas fa-redo-alt"></i></button>

										<button type="button" class="btn btn-warning" title="Edit" data-toggle="modal" data-target="#editModal_ep" onclick="edit_exam_ep(this)" 
										data-id="<?php echo $value['id']; ?>"
										data-staffid="<?php echo $value['staff_id']; ?>"
										data-tab_id="<?php echo $value['tab_id']; ?>"
										data-programme="<?php echo $value['programme_id']; ?>"
										data-paper_code="<?php echo $value['paper_code']; ?>"
										data-title="<?php echo $value['title']; ?>"
										data-exam_date="<?php if(($value['exam_date'] != null) && ($value['exam_date'] != '1970-01-01')){ echo date("d-m-Y", strtotime($value['exam_date'])); }else{ echo ''; } ?>"
										data-status="<?php echo $value['status']; ?>"
										data-result="<?php echo $value['result']; ?>"
										><i class="fas fa-edit"></i></button>

										<button type="button" class="btn btn-danger" title="Delete" id="deleteButtonExam" onclick="check_leave(<?php echo $value['id']; ?>);"><i class="fas fa-trash"></i></button>
									</div>
								</td>
							<?php } ?>
							
						</tr>
					<?php } } ?>
				</tbody>
			</table>
		</div>
	</div><br>
</div>

<div class="modal fade d-print-none" role="dialog" aria-hidden="true" id="studyModal">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="racks-modal-title"></h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
			<form id="studyForm" class="form">
				<div class="modal-body">
					<div class="form-row">
						<div class="col-12 col-sm-6">
							<label for="study_date_start">Start Date</label>
							<input type="text" class="form-control datepicker" name="study_date_start" id="study_date_start">
						</div>
						<div class="col-12 col-sm-6">
							<label for="study_date_end">Expectation Of Completion Date</label>
							<input type="text" class="form-control datepicker" name="study_date_end" id="study_date_end">
						</div>
					</div>
					<div class="form-row">
						<div class="col-12">
							<label for="study_institution" class="col-form-label">University / Institution</label>
							<input type="text" class="form-control" name="study_institution" id="study_institution">
						</div>
					</div>
					<div class="form-row">
						<div class="col-12">
							<label for="study_program" class="col-form-label">Program</label>
							<input type="text" class="form-control" name="study_program" id="study_program">
						</div>
					</div>
					<div class="form-row">
						<div class="col-12 col-sm-6">
							<label for="progress_paper">Progress Paper In Hand</label>
							<input type="text" class="form-control" name="progress_paper" id="progress_paper">
						</div>
						<div class="col-12 col-sm-6">
							<label for="study_status">Status</label>
							<select class="form-control" name="study_status" id="study_status">
								<option value="1">Graduated</option>
								<option value="2">Withdrawn</option>
								<option value="3">Deferred</option>
								<option value="0" selected>On Going</option>
							</select>
						</div>
					</div>
					<div class="form-row">
						<div class="col-12">
							<label class="col-form-label">Attachment</label>
							<input type="file" class="form-control" name="edu_attachment" id="edu_attachment">
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<div class="btn-group float-right">
						<button type="button" class="btn btn-light" data-dismiss="modal">Cancel</button>
						<button type="button" id="saveStudyButton" class="btn btn-primary">Save</button>
					</div>
				</div>
			</form>
        </div>
    </div>
</div>

<div class="modal fade" id="addExamModal_ep">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title" id="allocation-modal-title">Add New Professional Exam / Courses</h5>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <form action="<?php echo base_url('hr/myprofile/save_exams'); ?>" method="post" enctype="multipart/form-data" id="examForm_ep"> 
	            <div class="modal-body">
	            	<input type="hidden" name="exam_tab_id" id="exam_tab_id" class="form-control" value="">
	                <div class="form-group">
	                	<div class="row">
	                		<div class="col-6">
			                    <label for="exam_programme">Program</label>
			                    <select class="form-control" id="exam_programme" name="exam_programme">
			                    	<option selected value="">Select Program</option>
			                    	<?php if($pursuing_study){ foreach ($pursuing_study as $key => $row) { ?>
			                    		<option value="<?php echo $row->id; ?>" style=""><?php echo $row->program; ?></option>
			                    	<?php }} ?>
			                    </select>
			                </div>
			                <div class="col-6">
			                    <label for="exam_papercode">Paper Code</label>
			                    <input type="text" name="exam_papercode" id="exam_papercode" class="form-control">
			                </div>
	                	</div>
	                </div>
	                <div class="form-group">
	                	<div class="row">
	                		<div class="col-6">
			                    <label for="exam_papertitle">Title of Paper/Subject</label>
			                    <input type="text" name="exam_papertitle" id="exam_papertitle" class="form-control">
			                </div>
			                <div class="col-6">
			                    <label for="exam_date">Exam Date</label>
			                    <input type="" name="exam_date" id="exam_date" class="form-control datepicker">
			                </div>
	                	</div>
	                </div>
	                <div class="form-group">
	                	<div class="row">
	                		<div class="col-6">
			                    <label for="exam_status">Status</label>
			                    <select class="form-control" name="exam_status" id="exam_status">
			                    	<option selected value="">Select Status</option>
			                    	<option value="0">NEW</option>
			                    	<option value="1">REPEAT</option>
			                    </select>
			                </div>
			                <div class="col-6">
			                    <label for="exam_result">Result</label>
			                    <select class="form-control" name="exam_result" id="exam_result">
			                    	<option selected value="">Select Result</option>
			                    	<option value="0">FAILED</option>
			                    	<option value="1">PASS</option>
			                    </select>
			                </div>
	                	</div>
	                </div>
	                <div class="form-row">
						<div class="col-12">
							<label class="col-form-label">Attachment</label>
							<input type="file" class="form-control" name="exam_attachment" id="exam_attachment">
						</div>
					</div>
	        	</div>
	        	<div class="modal-footer">
	        		<div class="btn-group float-right">
						<button type="button" class="btn btn-light" data-dismiss="modal">Cancel</button>
						<button type="submit" class="btn btn-primary">Save</button>
					</div>
	        	</div>
	        </form>
        </div>
    </div>
</div>

<div class="modal fade" id="editModal_ep">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title" id="allocation-modal-title">Edit Professional Exam / Courses</h5>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
            	<input type="hidden" name="exam_tab_id_edit" id="exam_tab_id_edit" class="form-control" value="">
            	<input type="hidden" id="exam_examid_edit" name="exam_examid_edit">
            	<div class="form-group">
                    <label for="exam_staffid_edit">Staff Name</label>
                	<input type="hidden" value="<?php echo $staff_id; ?>" name="exam_staffid_edit" id="exam_staffid_edit" class="form-control">
                	<input type="text" value="<?php echo $_SESSION['user']['name']; ?>"class="form-control" disabled>
                </div>
                <div class="form-group">
                	<div class="row">
                		<div class="col-6">
		                    <label for="exam_programme_edit">Programme</label>
		                    <select class="form-control" id="exam_programme_edit" name="exam_programme_edit">
		                    	<option selected value="">Select Program</option>
		                    	<?php if($pursuing_study){ foreach ($pursuing_study as $key => $row) { ?>
		                    		<option value="<?php echo $row->id; ?>" style=""><?php echo $row->program; ?></option>
		                    	<?php }} ?>
		                    </select>
		                </div>
		                <div class="col-6">
		                    <label for="exam_papercode_edit">Paper Code</label>
		                    <input type="text" name="exam_papercode_edit" id="exam_papercode_edit" class="form-control">
		                </div>
                	</div>
                </div>
                <div class="form-group">
                	<div class="row">
                		<div class="col-6">
		                    <label for="exam_papertitle_edit">Title of Paper/Subject</label>
		                    <input type="text" name="exam_papertitle_edit" id="exam_papertitle_edit" class="form-control">
		                </div>
		                <div class="col-6">
		                    <label for="exam_date_edit">Exam Date</label>
		                    <input type="" name="exam_date_edit" id="exam_date_edit" class="form-control datepicker">
		                </div>
                	</div>
                </div>
                <div class="form-group">
                	<div class="row">
                		<div class="col-6">
		                    <label for="exam_status_edit">Status</label>
		                    <select class="form-control" name="exam_status_edit" id="exam_status_edit">
		                    	<option selected value="">Select Status</option>
		                    	<option value="0">NEW</option>
		                    	<option value="1">REPEAT</option>
		                    </select>
		                </div>
		                <div class="col-6">
		                    <label for="exam_result_edit">Result</label>
		                    <select class="form-control" name="exam_result_edit" id="exam_result_edit">
		                    	<option selected value="">Select Result</option>
		                    	<option value="0">FAILED</option>
		                    	<option value="1">PASS</option>
		                    </select>
		                </div>
                	</div>
                </div>
        	</div>
        	<div class="modal-footer">
        		<div class="btn-group float-right">
					<button type="button" class="btn btn-light" data-dismiss="modal">Cancel</button>
					<button onclick="saveEditExam_ep();" class="btn btn-primary">Save</button>
				</div>
        	</div>
        </div>
    </div>
</div>

<div class="modal fade" id="cloneModal_ep">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title" id="allocation-modal-title">Clone Professional Exam / Courses</h5>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
            	<input type="hidden" name="exam_tab_id_clone_ep" id="exam_tab_id_clone_ep" class="form-control" value="">
            	<div class="form-group">
                    <label for="exam_staffid_clone">Staff Name</label>
                    <input type="hidden" value="<?php echo $staff_id; ?>" name="exam_staffid_clone_hidden_ep" id="exam_staffid_clone_hidden_ep">
                	<input type="text" value="<?php echo $_SESSION['user']['name']; ?>"class="form-control" name="exam_staffname_clone_ep" id="exam_staffname_clone_ep" disabled>
                </div>
                <div class="form-group">
                	<div class="row">
                		<div class="col-6">
		                    <label for="exam_programme_clone">Programme</label>
		                    <input type="hidden" name="exam_programme_clone_hidden_ep" id="exam_programme_clone_hidden_ep">
		                    <select class="form-control" id="exam_programme_clone_ep" name="exam_programme_clone_ep" disabled>
		                    	<option selected value="">Select Program</option>
		                    	<?php if($pursuing_study){ foreach ($pursuing_study as $key => $row) { ?>
		                    		<option value="<?php echo $row->id; ?>" style=""><?php echo $row->program; ?></option>
		                    	<?php }} ?>
		                    </select>
		                </div>
		                <div class="col-6">
		                    <label for="exam_papercode_clone">Paper Code</label>
		                    <input type="hidden" name="exam_papercode_clone_hidden_ep" id="exam_papercode_clone_hidden_ep">
		                    <input type="text" name="exam_papercode_clone_ep" id="exam_papercode_clone_ep" class="form-control" disabled>
		                </div>
                	</div>
                </div>
                <div class="form-group">
                	<div class="row">
                		<div class="col-6">
		                    <label for="exam_papertitle_clone">Title of Paper/Subject</label>
		                    <input type="hidden" name="exam_papertitle_clone_hidden_ep" id="exam_papertitle_clone_hidden_ep">
		                    <input type="text" name="exam_papertitle_clone_ep" id="exam_papertitle_clone_ep" class="form-control" disabled>
		                </div>
		                <div class="col-6">
		                    <label for="exam_date_clone">Exam Date</label>
		                    <input type="" name="exam_date_clone_ep" id="exam_date_clone_ep" class="form-control datepicker">
		                </div>
                	</div>
                </div>
                <div class="form-group">
                	<div class="row">
                		<div class="col-6">
		                    <label for="exam_status_clone">Status</label>
		                    <select class="form-control" name="exam_status_clone_ep" id="exam_status_clone_ep">
		                    	<option selected value="">Select Status</option>
		                    	<option value="0">NEW</option>
		                    	<option value="1">REPEAT</option>
		                    </select>
		                </div>
		                <div class="col-6">
		                    <label for="exam_result_clone">Result</label>
		                    <select class="form-control" name="exam_result_clone_ep" id="exam_result_clone_ep">
		                    	<option selected value="">Select Result</option>
		                    	<option value="0">FAILED</option>
		                    	<option value="1">PASS</option>
		                    </select>
		                </div>
                	</div>
                </div>
        	</div>
        	<div class="modal-footer">
        		<div class="btn-group float-right">
					<button type="button" class="btn btn-light" data-dismiss="modal">Cancel</button>
					<button onclick="saveCloneExam_ep();" class="btn btn-primary">Save</button>
				</div>
        	</div>
        </div>
    </div>
</div>

<script type="text/javascript">
	function openStudyModal(){

		clearForm("#studyForm");

		$('#studyModal').find('#racks-modal-title').text('Add Study Info');
        $('#saveStudyButton').attr('onclick', 'saveStudy()');
		$('#studyModal').modal('show');
        $('#study_status').val(0);
	}
	
	function saveStudy()
	{
		var postData = new FormData();

		postData.append("profiling_id", $("#profiling_id_new").val());
		postData.append("study_date_start", $("#study_date_start").val());
		postData.append("study_date_end", $("#study_date_end").val());
		postData.append("study_institution", $("#study_institution").val());
		postData.append("study_program", $("#study_program").val());
		postData.append("progress_paper", $("#progress_paper").val());
		postData.append("study_status", $("#study_status").val());

		if($('#edu_attachment').prop('files').length > 0){
			postData.append("attachment_file", $('#edu_attachment').prop('files')[0]);
			postData.append("attachment_name", $('#edu_attachment').prop('files')[0]['name']);
		}else{
			postData.append("attachment_file", null);
			postData.append("attachment_name", null);
		}

		$.ajax({
			url:'<?php echo base_url('hr/Myprofile/saveStudy') ?>',
			data: postData,
			type: 'post',
			dataType: 'json',
			processData: false,
			contentType: false,
			success: (data) => {
				if(data.status == "success") 
				{
					localStorage.setItem("status",data.status);
					localStorage.setItem("msg",data.msg);

					location.replace(data.redirect);
				}
			}
		});
	}

	function editStudy(study_id)
	{
		clearForm("#studyForm");
		var profiling_id = $("#profiling_id_new").val();

		$('#studyModal').find('#racks-modal-title').text('Edit Current Pursuing Study');
        $('#saveStudyButton').attr('onclick', 'save_editStudy('+ study_id +')');
		$('#studyModal').modal('show');

		$.ajax({
			type: 'POST',
			url: '<?php echo base_url('hr/Myprofile/getStudy'); ?>',
			data: {
				'study_id' 		: study_id,
				'profiling_id' 	: profiling_id
			},
			dataType: 'JSON',
			success: function(data) {
				if(data.status == 'success')
				{
					var study_data = data.study_data;

                    $("#study_date_start").val(moment(study_data[0]['date_start']).format('DD-MM-YYYY'));
                    $("#study_date_end").val(moment(study_data[0]['date_end']).format('DD-MM-YYYY'));
                    $("#study_program").val(study_data[0]['program']);
                    $("#study_institution").val(study_data[0]['institution']);
					$("#progress_paper").val(study_data[0]['progress_paper']);
                    $("#study_status").val(study_data[0]['status']);
				}
			}
		});
	}

	function save_editStudy(id) 
	{
		var postData = new FormData();

		postData.append("study_id", id);
		postData.append("profiling_id", $("#profiling_id_new").val());
		postData.append("study_date_start", $("#study_date_start").val());
		postData.append("study_date_end", $("#study_date_end").val());
		postData.append("study_institution", $("#study_institution").val());
		postData.append("study_program", $("#study_program").val());
		postData.append("progress_paper", $("#progress_paper").val());
		postData.append("study_status", $("#study_status").val());

		if($('#edu_attachment').prop('files').length > 0){
			postData.append("attachment_file", $('#edu_attachment').prop('files')[0]);
			postData.append("attachment_name", $('#edu_attachment').prop('files')[0]['name']);
		}else{
			postData.append("attachment_file", null);
			postData.append("attachment_name", null);
		}

		$.ajax({
			url: '<?php echo base_url('hr/Myprofile/save_editStudy'); ?>',
			data: postData,
			type: 'POST',
			dataType: 'json',
			processData: false,
			contentType: false,
			success: function(data) {
				if(data.status == 'success')
				{
					localStorage.setItem("status",data.status);
					localStorage.setItem("msg",data.msg);

					location.replace(data.redirect);
				}
			}
		});
	}

	function deleteStudy(ID)
	{
		toastConfirm("Are you sure you want to delete this Study record?", function(){

			$.ajax({
				type: 'POST',
				url: '<?php echo base_url('hr/Myprofile/deleteStudy'); ?>',
				data: {
					'study_id' 				: ID,
					'profiling_id' 		: $("#profiling_id_new").val(),
				},
				dataType: 'JSON',
				success: function(data) {
					if(data.status == 'success')
					{
						localStorage.setItem("status",data.status);
						localStorage.setItem("msg",data.msg);

						location.replace(data.redirect);
						// location.reload();
					}
				}
			});
		})
	}

	function openExamModal_ep($tab_id) 
	{
		clearForm("#examForm_ep");
		$('#exam_tab_id').val($tab_id);
		$('#addExamModal_ep').modal('show');
	}

	function edit_exam_ep(elem) 
    {
        let exam_id     = $(elem).data('id');
        let staffid     = $(elem).data('staffid');
        let tab_id     	= $(elem).data('tab_id');
        let programme   = $(elem).data('programme');
        let paper_code  = $(elem).data('paper_code');
        let title 		= $(elem).data('title');
        let exam_date   = $(elem).data('exam_date');
        let status   	= $(elem).data('status');
        let result   	= $(elem).data('result');

        $('#exam_examid_edit').val(exam_id);
        $('#exam_staffid_edit').val(staffid);
        $('#exam_tab_id_edit').val(tab_id);
        $('#exam_programme_edit').val(programme);
        $('#exam_papercode_edit').val(paper_code);
        $('#exam_papertitle_edit').val(title);
        $('#exam_date_edit').val(exam_date);
        $('#exam_status_edit').val(status);
        $('#exam_result_edit').val(result);
    }

    function saveEditExam_ep() 
    {
    	var postData = {
			'exam_examid_edit' 		: $('#exam_examid_edit').val(),
	        'exam_staffid_edit' 	: $('#exam_staffid_edit').val(),
	        'exam_tab_id_edit' 		: $('#exam_tab_id_edit').val(),
	        'exam_programme_edit' 	: $('#exam_programme_edit').val(),
	        'exam_papercode_edit' 	: $('#exam_papercode_edit').val(),
	        'exam_papertitle_edit' 	: $('#exam_papertitle_edit').val(),
	        'exam_date_edit' 		: $('#exam_date_edit').val(),
	        'exam_status_edit' 		: $('#exam_status_edit').val(),
	        'exam_result_edit' 		: $('#exam_result_edit').val(),
		};

		$.ajax({
			type: "POST",
			dataType:"json",
			url: "<?php echo base_url() ?>hr/myprofile/edit_exams",
			data: postData,
			success: function(data) {
				if(data.status == 'success')
				{
					localStorage.setItem("status",data.status);
					localStorage.setItem("msg",data.msg);

					location.replace(data.redirect);
				}
			}
		});
    }

    function clone_exam_ep(elem) 
    {
        let exam_id     = $(elem).data('id');
        let staffid     = $(elem).data('staffid');
        let tab_id     	= $(elem).data('tab_id');
        let programme   = $(elem).data('programme');
        let paper_code  = $(elem).data('paper_code');
        let title 		= $(elem).data('title');
        let exam_date   = $(elem).data('exam_date');
        let status   	= $(elem).data('status');
        let result   	= $(elem).data('result');

        $('#exam_staffid_clone_hidden_ep').val(staffid);
        $('#exam_staffid_clone_ep').val(staffid);
        $('#exam_tab_id_clone_ep').val(tab_id);
        $('#exam_programme_clone_hidden_ep').val(programme);
        $('#exam_programme_clone_ep').val(programme);
        $('#exam_papercode_clone_hidden_ep').val(paper_code);
        $('#exam_papercode_clone_ep').val(paper_code);
        $('#exam_papertitle_clone_hidden_ep').val(title);
        $('#exam_papertitle_clone_ep').val(title);
        $('#exam_date_clone_ep').val(exam_date);
        $('#exam_status_clone_ep').val(status);
        $('#exam_result_clone_ep').val(result);
    }

    function saveCloneExam_ep() 
    {
    	var postData = {
			'exam_staffid_clone_hidden' 	: $('#exam_staffid_clone_hidden_ep').val(),
	        'exam_staffid_clone' 			: $('#exam_staffid_clone_ep').val(),
	        'exam_tab_id_clone' 			: $('#exam_tab_id_clone_ep').val(),
	        'exam_programme_clone_hidden' 	: $('#exam_programme_clone_hidden_ep').val(),
	        'exam_programme_clone' 			: $('#exam_programme_clone_ep').val(),
	        'exam_papercode_clone_hidden' 	: $('#exam_papercode_clone_hidden_ep').val(),
	        'exam_papercode_clone' 			: $('#exam_papercode_clone_ep').val(),
	        'exam_papertitle_clone_hidden' 	: $('#exam_papertitle_clone_hidden_ep').val(),
	        'exam_papertitle_clone' 		: $('#exam_papertitle_clone_ep').val(),
	        'exam_date_clone' 				: $('#exam_date_clone_ep').val(),
	        'exam_status_clone' 			: $('#exam_status_clone_ep').val(),
	        'exam_result_clone' 			: $('#exam_result_clone_ep').val(),
		};

		$.ajax({
			type: "POST",
			dataType:"json",
			url: "<?php echo base_url() ?>hr/myprofile/clone_exams",
			data: postData,
			success: function(data) {
				if(data.status == 'success')
				{
					localStorage.setItem("status",data.status);
					localStorage.setItem("msg",data.msg);

					location.replace(data.redirect);
				}
			}
		});
    }

    function request_leave_ep(paper_id) {
		toastConfirm("Confirm request Study Leave for this paper?", function(){
			$.ajax({
				type: 'POST',
				url: '<?php echo base_url('hr/Myprofile/request_study_leave'); ?>',
				data: {
					'paper_id' : paper_id,
				},
				dataType: 'JSON',
				success: function(data) {
					if(data.status == 'success')
					{
						localStorage.setItem("status",data.status);
						localStorage.setItem("msg",data.msg);

						location.reload();
					} else {
						alert(data.msg);
					}
				}
			});
		});
	}
</script>