<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">
					<?php if ($role == 'admin'): ?>
						<a class="btn btn-info btn-sm" style="margin-bottom:15px; width: 200px;" href="<?php echo base_url('/hr/StaffProfile/actionReport/'.$staff_id.'/19_1'); ?>" target="_blank">
							<i class="fa fa-print"></i> Print
						</a>
					<?php endif ?>
				</div>
			</div>
		</div>

		<hr>

		<div class="table-responsive">
			<table id="table_professional_certificate" class="table table-hover table-bordered">
				<thead>
					<tr>
						<th>Action Type (effective date)</th>
						<th>Details</th>
						<th>Created At</th>
						<!-- <?php if ($role == 'admin'): ?>
						<th>Action</th>
						<?php endif ?> -->
						
					</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 $row->action_type.' <br/><b>('.$row->action_efective_date.')</b>'; ?></td>
							<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/staffprofile/openAttachment/'.$row->mask_id.'/6')?>" target="_blank"><?php echo $row->attachment_name; ?></a>
							</td>
							<td><?php echo $row->created_at; ?></td>
							<?php if ($role == 'admin'): ?>					
								<!-- <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" title="Delete Professional Certificate"  onclick="deleteProfessionalCertificate(<?php //echo $row->id; ?>)"><i class="fas fa-trash-alt"></i></button>
									</div>
								</td>  -->
							<?php endif; ?>
						</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">
				</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>
					</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){ ?>
									<span class="badge badge-pill badge-warning" title="No Study Leave Requested" > No Request &nbsp;<i class="far fa-hand-point-up"></i></span>
								<?php } else { ?>
									<span class="badge badge-pill badge-success" title="Study Leave Requested"> SL Requested &nbsp;<i class="fas fa-check"></i></span>
								<?php } ?>
							</td>
							<td><?php if($value['result'] == '0'){ echo "FAILED"; }else if($value['result'] == 1){ echo "PASS"; } ?></td>
							
						</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">
					<button type="button" class="btn btn-danger btn-sm" style="margin-bottom:15px; width: 200px;" data-dismiss="modal">Cancel</button>
					<button type="button" id="saveProfessionalCertificateBtn" class="btn btn-success btn-sm" style="margin-bottom:15px; width: 200px;">Save</button>
				</div>
			</form>
        </div>
    </div>
</div>

<script type="text/javascript">
	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);
					location.reload();
				}
			}
		});
	}

	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);
						location.reload();
					}
				}
			});
		})
	}
</script>