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

		<hr>

		<div class="table-responsive">
			<table id="table_professional_certificate" 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 == 1): ?>
						
						<tr class="link-row">
							<td>
								<?php
								echo '<b>Name of Certification Body : </b>'.$row->associate_name
								.'<br/><b>Name of Certification Programme : </b>'.$row->program
								.'<br/><b>Date Finish: </b>'.$row->date_finish
								.'<br/><b>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="editProfessionalCertificate(<?php echo $row->id; ?>)" title="Edit Professional Certificate" 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 Certificate"  onclick="deleteProfessionalCertificate(<?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_pc(3);" 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_cert_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_pc){ foreach ($exam_list_pc 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="professionalCertificateModal">
    <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="professionalCertificateForm" class="form">
				<div class="modal-body">
					<input type="text" class="form-control" name="type_1" id="type_1" value="1" hidden>
					<div class="form-row">
						<div class="col-12">
							<label>Name of Certification Body</label>
							<input class="form-control " name="associate_name_1" id="associate_name_1">
						</div>
					</div>

					<div class="form-row">
						<div class="col-12">
							<label class="col-form-label">Name of Certification Programme</label>
							<input type="text" class="form-control" name="program_1" id="program_1">
						</div>
					</div>

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

						<div class="col-12 col-sm-6">
							<label class="col-form-label">Result</label>
							<input type="text" class="form-control" name="result_1" id="result_1">
						</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_1" id="professional_academic_attachment_1">
						</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="saveProfessionalCertificateBtn" class="btn btn-primary">Save</button>
					</div>
				</div>
			</form>
        </div>
    </div>
</div>

<div class="modal fade" id="addExam_pc_modal">
    <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 id="examForm_pc"> 
	            <div class="modal-body">
	            	<input type="hidden" name="exam_tab_id_pc" id="exam_tab_id_pc" class="form-control" value="">
	                <div class="form-group">
	                	<div class="row">
	                		<div class="col-6">
			                    <label for="exam_programme_pc">Course Study</label>
			                    <select class="form-control" id="exam_programme_pc" name="exam_programme_pc">
			                    	<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_pc">Paper Code</label>
			                    <input type="text" name="exam_papercode_pc" id="exam_papercode_pc" class="form-control">
			                </div>
	                	</div>
	                </div>
	                <div class="form-group">
	                	<div class="row">
	                		<div class="col-6">
			                    <label for="exam_papertitle_pc">Title of Paper/Subject</label>
			                    <input type="text" name="exam_papertitle_pc" id="exam_papertitle_pc" class="form-control">
			                </div>
			                <div class="col-6">
			                    <label for="exam_date_pc">Exam Date</label>
			                    <input type="" name="exam_date_pc" id="exam_date_pc" class="form-control datepicker">
			                </div>
	                	</div>
	                </div>
	                <div class="form-group">
	                	<div class="row">
	                		<div class="col-6">
			                    <label for="exam_status_pc">Status</label>
			                    <select class="form-control" name="exam_status_pc" id="exam_status_pc">
			                    	<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_pc">Result</label>
			                    <select class="form-control" name="exam_result_pc" id="exam_result_pc">
			                    	<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 onclick="saveExam_pc();" class="btn btn-primary">Save</button>
					</div>
	        	</div>
	        </form>
        </div>
    </div>
</div>

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

		$('#professionalCertificateModal').find('#racks-modal-title').text('Add Professional Certificate');
        $('#saveProfessionalCertificateBtn').attr('onclick', 'saveProfessionalCertificate()');
		$('#professionalCertificateModal').modal('show');

		$('#type_1').val(1);
	}

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

        postData.append("profiling_id", $("#profiling_id_new").val());
		postData.append("type", $('#type_1').val());
		postData.append("associate_name", $('#associate_name_1').val());
		postData.append("program", $('#program_1').val());
		postData.append("date_finish", $('#date_finish_1').val());
		postData.append("result", $('#result_1').val());

		if($('#professional_academic_attachment_1').prop('files').length > 0){
			postData.append("attachment_file", $('#professional_academic_attachment_1').prop('files')[0]);
			postData.append("attachment_name", $('#professional_academic_attachment_1').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 editProfessionalCertificate(professional_academic_id)
	{
		clearForm("#professionalCertificateForm");
		var profiling_id = $("#profiling_id_new").val();

		$('#professionalCertificateModal').find('#racks-modal-title').text('Edit Professional Certificate');
		$('#saveProfessionalCertificateBtn').attr('onclick', 'save_editProfessionalCertificate('+ professional_academic_id +')');
		$('#professionalCertificateModal').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_1').val(professional_academic[0]['type']);
                    $("#associate_name_1").val(professional_academic[0]['associate_name']);
                    $("#program_1").val(professional_academic[0]['program']);
                    $("#date_finish_1").val(professional_academic[0]['date_finish']);
                    $("#result_1").val(professional_academic[0]['result']);
                    // $("#professional_academic_attachment").val(professional_academic[0]['attachment_name']);
				}
			}
		});
	}

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

        postData.append("id", id);
        postData.append("profiling_id", $("#profiling_id_new").val());
		postData.append("type", $('#type_1').val());
		postData.append("associate_name", $('#associate_name_1').val());
		postData.append("program", $('#program_1').val());
		postData.append("date_finish", $('#date_finish_1').val());
		postData.append("result", $('#result_1').val());

		if($('#professional_academic_attachment_1').prop('files').length > 0){
			postData.append("attachment_file", $('#professional_academic_attachment_1').prop('files')[0]);
			postData.append("attachment_name", $('#professional_academic_attachment_1').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 deleteProfessionalCertificate(ID)
	{
		toastConfirm("Are you sure you want to delete this professional certificate?", 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'  		: 1,
				},
				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_pc($tab_id) 
	{
		clearForm("#examForm_pc");
		$('#exam_tab_id_pc').val($tab_id);
		$('#addExam_pc_modal').modal('show');
	}

	function saveExam_pc() {

		var postData = new FormData();

		postData.append("exam_examid", $("#exam_examid_pc").val());
	    postData.append("exam_staffid", $("#exam_staffid_pc").val());
	    postData.append("exam_tab_id", $("#exam_tab_id_pc").val());
	    postData.append("exam_programme", $("#exam_programme_pc").val());
	    postData.append("exam_papercode", $("#exam_papercode_pc").val());
	    postData.append("exam_papertitle", $("#exam_papertitle_pc").val());
	    postData.append("exam_date", $("#exam_date_pc").val());
	    postData.append("exam_status", $("#exam_status_pc").val());
	    postData.append("exam_result", $("#exam_result_pc").val());

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

		$.ajax({
			url: "<?php echo base_url() ?>hr/myprofile/save_exams",
			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);
				}
			}
		});
	}
</script>