<div class="collapse" id="collapseProfessionalEducation">
	<div class="card card-body">
		<div class="container">
			<div class="row">
				<h4 class="card-title float-left">Professional Education</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="openProfessionalEducationModal();" data-trigger="hover" data-tooltip="tooltip" title="Add New Professional Education">
						<i class="fa fa-plus"></i> Add New
					</button>
				</div>
			</div>
		</div>

		<hr>

		<div class="table-responsive">
			<table id="table_professional_education" class="table table-hover table-bordered">
				<thead>
					<tr>
						<th>Details</th>
						<th>Created At</th>
						<?php if($btn_hidden == ''){ ?>	
							<th class="d-print-none">Action</th>
						<?php } ?>
						
					</tr>
				</thead>
				<tbody>
					<?php $counter = 0; ?>
					<?php if($professional_academic) foreach ($professional_academic as $key => $row): ?>
						<?php if ($row->type == 0): ?>
							
							<tr class="link-row">
								<td>
									<?php
									echo '<b>Level : </b>'.$row->level
									.'<br><b>Name of Professional Association : </b>'.$row->associate_name
									.'<br/><b>Name of Course Study : </b>'.$row->program
									.'<br/><b>Date Graduated: </b>'.$row->date_finish
									.'<br/><b>Final Result : </b>'.$row->result
									.'<br/><b>Attachment : </b>';
									?>
									<a href="<?php echo base_url('hr/myprofile/openAttachment/'.$row->mask_id.'/6')?>" target="_blank"><?php echo $row->attachment_name; ?></a>
								</td>
								<td><?php echo $row->created_at; ?></td>
								<?php if($btn_hidden == ''){ ?>	
									<?php if(strtolower($row->action_type) == 'personal data update' && date('m-Y',strtotime($row->created_at)) == date('m-Y', $live_date)){ ?>						
										<td class="text-center">
											<div class="btn-group" role="group">
												<button id="editEducationButton" type="button" class="btn btn-success btn-sm d-print-none" onclick="editProfessionalEducation(<?php echo $row->id; ?>)" title="Edit Professional Education" data-profilingID="<?php echo $row->profiling_id; ?>" data-userID="<?php echo $row->user_id; ?>"><span class="fa fa-edit"></span></button>
												<button type="button" class="btn btn-danger btn-sm d-print-none" title="Delete Professional Education"  onclick="deleteProfessionalEducation(<?php echo $row->id; ?>)"><i class="fas fa-trash-alt"></i></button>
											</div>
										</td> 
									<?php } else { ?>
										<td class="text-center">
											<div class="btn-group" role="group">
												<button class="btn btn-success btn-sm d-print-none" disabled style="cursor: not-allowed;" title="Not allowed to update"><i class="fas fa-edit" ></i></button>
												<button class="btn btn-danger btn-sm d-print-none" disabled style="cursor: not-allowed;" title="Not allowed to delete"><i class="fas fa-trash-alt"></i></button>
											</div>
										</td> 
									<?php } ?>
								<?php } ?>
							</tr>
						<?php endif ?>
					<?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(2);" 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_professional_exam" class="table table-hover table-bordered">
				<thead>
					<tr>
						<th>No.</th>
						<th>Course Study</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_pe){ foreach ($exam_list_pe 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(<?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" onclick="clone_exam(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" onclick="clone_exam(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_pe" onclick="edit_exam_pe(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>

<!-- Modal -->
<div class="modal fade d-print-none" role="dialog" aria-hidden="true" id="professionalEducationModal">
    <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="professionalEducationForm" class="form">
				<div class="modal-body">
					<input type="text" class="form-control" name="type_0" id="type_0" value="0" hidden>
					<div class="form-row" id="level_row">
						<div class="col-12">
							<label>Level</label>
							<input type="text" class="form-control" name="level_0" id="level_0" value="Professional" readonly>
						</div>
					</div>

					<div class="form-row">
						<div class="col-12">
							<label>Name of Professional Association</label>
							<input class="form-control " name="associate_name_0" id="associate_name_0">
						</div>
					</div>

					<div class="form-row">
						<div class="col-12">
							<label class="col-form-label">Name of Course Study</label>
							<input type="text" class="form-control" name="program_0" id="program_0">
						</div>
					</div>

					<div class="form-row">
						<div class="col-12 col-sm-6">
							<label class="col-form-label">Date Graduated</label>
							<input type="text" class="form-control datepicker" name="date_finish_0" id="date_finish_0">
						</div>

						<div class="col-12 col-sm-6">
							<label class="col-form-label">Final Result</label>
							<input type="text" class="form-control" name="result_0" id="result_0">
						</div>
					</div>

					<div class="form-row">
						<div class="col-12">
							<label class="col-form-label">Attachment</label>
							<input type="file" class="form-control" name="professional_academic_attachment_0" id="professional_academic_attachment_0">
						</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="saveProfessionalEducationBtn" class="btn btn-primary">Save</button>
					</div>
				</div>
			</form>
        </div>
    </div>
</div>

<div class="modal fade" id="addExamModal">
    <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"> 
	            <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">Course Study</label>
			                    <select class="form-control" id="exam_programme" name="exam_programme">
			                    	<option selected value="">Select Course Study</option>
			                    	<?php if($professional_academic){ foreach ($professional_academic 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="cloneModal">
    <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>
            <form action="<?php echo base_url('hr/myprofile/clone_exams'); ?>" method="post" enctype="multipart/form-data">
	            <div class="modal-body">
	            	<input type="hidden" name="exam_tab_id_clone" id="exam_tab_id_clone" class="form-control" value="">
	            	<div class="form-group">
	                    <label for="exam_staffid_clone">Staff Name</label>
	                    <input type="hidden" name="exam_staffid_clone_hidden" id="exam_staffid_clone_hidden">
	                    <input type="text" value="<?php echo $_SESSION['user']['name']; ?>"class="form-control" name="exam_staffname_clone" id="exam_staffname_clone" disabled>
	                </div>
	                <div class="form-group">
	                	<div class="row">
	                		<div class="col-6">
			                    <label for="exam_programme_clone">Course Study</label>
			                    <input type="hidden" name="exam_programme_clone_hidden" id="exam_programme_clone_hidden">
			                    <select class="form-control" id="exam_programme_clone" name="exam_programme_clone" disabled>
			                    	<option selected value="">Select Course Study</option>
			                    	<?php if($professional_academic){ foreach ($professional_academic 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" id="exam_papercode_clone_hidden">
			                    <input type="text" name="exam_papercode_clone" id="exam_papercode_clone" 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" id="exam_papertitle_clone_hidden">
			                    <input type="text" name="exam_papertitle_clone" id="exam_papertitle_clone" class="form-control" disabled>
			                </div>
			                <div class="col-6">
			                    <label for="exam_date_clone">Exam Date</label>
			                    <input type="" name="exam_date_clone" id="exam_date_clone" 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" id="exam_status_clone">
			                    	<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" id="exam_result_clone">
			                    	<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 type="submit" class="btn btn-primary">Save</button>
					</div>
	        	</div>
	        </form>
        </div>
    </div>
</div>

<div class="modal fade" id="editModal_pe">
    <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_pe" id="exam_tab_id_edit_pe" class="form-control" value="">
	            	<input type="hidden" id="exam_examid_edit_pe" name="exam_examid_edit_pe">
	            	<div class="form-group">
	                    <label for="exam_staffid_edit_pe">Staff Name</label>
                    	<input type="hidden" value="<?php echo $staff_id; ?>" name="exam_staffid_edit_pe" id="exam_staffid_edit_pe" class="form-control">
                    	<input type="text" value="<?php echo $_SESSION['user']['name']; ?>"class="form-control" name="exam_staffname_edit_pe" id="exam_staffname_edit_pe" disabled>
	                </div>
	                <div class="form-group">
	                	<div class="row">
	                		<div class="col-6">
			                    <label for="exam_programme_edit_pe">Programme</label>
			                    <select class="form-control" id="exam_programme_edit_pe" name="exam_programme_edit_pe">
			                    	<option selected value="">Select Course Study</option>
			                    	<?php if($professional_academic){ foreach ($professional_academic 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_pe">Paper Code</label>
			                    <input type="text" name="exam_papercode_edit_pe" id="exam_papercode_edit_pe" class="form-control">
			                </div>
	                	</div>
	                </div>
	                <div class="form-group">
	                	<div class="row">
	                		<div class="col-6">
			                    <label for="exam_papertitle_edit_pe">Title of Paper/Subject</label>
			                    <input type="text" name="exam_papertitle_edit_pe" id="exam_papertitle_edit_pe" class="form-control">
			                </div>
			                <div class="col-6">
			                    <label for="exam_date_edit_pe">Exam Date</label>
			                    <input type="" name="exam_date_edit_pe" id="exam_date_edit_pe" 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_pe" id="exam_status_edit_pe">
			                    	<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_pe" id="exam_result_edit_pe">
			                    	<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_pe();" class="btn btn-primary">Save</button>
					</div>
	        	</div>
        </div>
    </div>
</div>

<script type="text/javascript">
	function openProfessionalEducationModal()
	{
		clearForm("#professionalEducationForm");

		$('#professionalEducationModal').find('#racks-modal-title').text('Add Professional Education');
        $('#saveProfessionalEducationBtn').attr('onclick', 'saveProfessionalEducation()');
		$('#professionalEducationModal').modal('show');

		$('#type_0').val(0);
		$("#level_0").val('Professional');
	}

	function saveProfessionalEducation()
	{
        var postData = new FormData();

        postData.append("profiling_id", $("#profiling_id_new").val());
		postData.append("type", $('#type_0').val());
		postData.append("level", $('#level_0').val());
		postData.append("associate_name", $('#associate_name_0').val());
		postData.append("program", $('#program_0').val());
		postData.append("date_finish", $('#date_finish_0').val());
		postData.append("result", $('#result_0').val());

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

		$.ajax({
			url: '<?php echo base_url('hr/Myprofile/saveProfessionalAcademic') ?>',
			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 editProfessionalEducation(professional_academic_id)
	{
		clearForm("#professionalEducationForm");
		var profiling_id = $("#profiling_id_new").val();

		$('#professionalEducationModal').find('#racks-modal-title').text('Edit Professional Education');
		$('#saveProfessionalEducationBtn').attr('onclick', 'save_editProfessionalEducation('+ professional_academic_id +')');
		$('#professionalEducationModal').modal('show');

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

					$('#type_0').val(professional_academic[0]['type']);
                    $("#level_0").val(professional_academic[0]['level']);
                    $("#associate_name_0").val(professional_academic[0]['associate_name']);
                    $("#program_0").val(professional_academic[0]['program']);
                    $("#date_finish_0").val(professional_academic[0]['date_finish']);
                    $("#result_0").val(professional_academic[0]['result']);
                    // $("#professional_academic_attachment").val(professional_academic[0]['attachment_name']);
				}
			}
		});
	}

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

        postData.append("id", id);
        postData.append("profiling_id", $("#profiling_id_new").val());
		postData.append("type", $('#type_0').val());
		postData.append("level", $('#level_0').val());
		postData.append("associate_name", $('#associate_name_0').val());
		postData.append("program", $('#program_0').val());
		postData.append("date_finish", $('#date_finish_0').val());
		postData.append("result", $('#result_0').val());

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

		$.ajax({
			url: '<?php echo base_url('hr/Myprofile/save_editProfessionalAcademic'); ?>',
			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 deleteProfessionalEducation(ID)
	{
		toastConfirm("Are you sure you want to delete this professional education?", function(){
        var profiling_id = $("#profiling_id_new").val();

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

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

	function openExamModal($tab_id) 
	{
		clearForm("#examForm");
		$('#exam_tab_id').val($tab_id);
		$('#addExamModal').modal('show');
	}

	function request_leave(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);
					}
				}
			});
		});
	}

	function edit_exam_pe(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_pe').val(exam_id);
        $('#exam_staffid_edit_pe').val(staffid);
        $('#exam_tab_id_edit_pe').val(tab_id);
        $('#exam_programme_edit_pe').val(programme);
        $('#exam_papercode_edit_pe').val(paper_code);
        $('#exam_papertitle_edit_pe').val(title);
        $('#exam_date_edit_pe').val(exam_date);
        $('#exam_status_edit_pe').val(status);
        $('#exam_result_edit_pe').val(result);
    }

    function saveEditExam_pe() 
    {
    	var postData = {
			'exam_examid_edit' 		: $('#exam_examid_edit_pe').val(),
	        'exam_staffid_edit' 	: $('#exam_staffid_edit_pe').val(),
	        'exam_tab_id_edit' 		: $('#exam_tab_id_edit_pe').val(),
	        'exam_programme_edit' 	: $('#exam_programme_edit_pe').val(),
	        'exam_papercode_edit' 	: $('#exam_papercode_edit_pe').val(),
	        'exam_papertitle_edit' 	: $('#exam_papertitle_edit_pe').val(),
	        'exam_date_edit' 		: $('#exam_date_edit_pe').val(),
	        'exam_status_edit' 		: $('#exam_status_edit_pe').val(),
	        'exam_result_edit' 		: $('#exam_result_edit_pe').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(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').val(staffid);
        $('#exam_staffid_clone').val(staffid);
        $('#exam_tab_id_clone').val(tab_id);
        $('#exam_programme_clone_hidden').val(programme);
        $('#exam_programme_clone').val(programme);
        $('#exam_papercode_clone_hidden').val(paper_code);
        $('#exam_papercode_clone').val(paper_code);
        $('#exam_papertitle_clone_hidden').val(title);
        $('#exam_papertitle_clone').val(title);
        $('#exam_date_clone').val(exam_date);
        $('#exam_status_clone').val(status);
        $('#exam_result_clone').val(result);
    }

    function check_leave(exam_id) {
		validateForm("#deleteButtonExam", "Delete this list?", function() {
			$.ajax({
	            url:'<?php echo base_url('hr/myprofile/check_study_leave') ?>',
	            data: {
	                exam_id : exam_id,
	            },
	            type: 'post',
	            dataType: 'json',
	            success: (data) => {
	                if(data.status == "Error") {

	                    localStorage.setItem("status", data.status);
	                    localStorage.setItem("msg", data.msg);

	                    location.reload();
	                } else {
	                	delete_exam(exam_id);
	                }
	            }
	        });
        });
	}

    function delete_exam(exam_id) {
        $.ajax({
            url:'<?php echo base_url('hr/myprofile/delete_exam') ?>',
            data: {
                exam_id : exam_id,
            },
            type: 'post',
            dataType: 'json',
            success: (data) => {
                if(data.status == "Success") {

                    localStorage.setItem("status", data.status);
                    localStorage.setItem("msg", data.msg);

                    location.reload();
                }
            }
        });
	}
</script>