<div class="collapse" id="collapseEducationInProgress">
	<div class="card card-body">
	    <h4 class="card-title">Education In Progress</h4>
			<hr>
			<div class="container">
				<div class="row">
					<div class="btn-group ml-auto">
						<?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.'/20'); ?>" target="_blank">
								<i class="fa fa-print"></i> Print
							</a>
						<?php endif ?>
					</div>
				</div>
			</div>
			<div class="table-responsive">
				<table id="table_academic" 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 if($pursuing_study) foreach ($pursuing_study as $key => $pursuing): ?>
							<tr class="link-row" data-id="<" >
								<td scope="row">
									<?php
										echo $pursuing->action_type.'<br><b>( '.date('d-F-Y',strtotime($pursuing->action_efective_date)).' )</b>';
									?>
								</td>
								<td>
									<?php
										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/staffprofile/openAttachment/'.$pursuing->mask_id.'/8')?>" target="_blank"><?php echo $pursuing->attachment_name; ?></a>
								</td>
								<td>
									<?php echo $pursuing->created_at; ?>
								</td>
								<?php if($role == 'admin') : ?>
									<!-- <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 endif; ?>
							</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">
					</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>
						</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){ ?>
										<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="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 Hande</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">On Going</option>
							</select>
						</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="saveStudyButton" class="btn btn-success btn-sm" style="margin-bottom:15px; width: 200px;">Save</button>
				</div>
			</form>
        </div>
    </div>
</div>

<script type="text/javascript">
	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/StaffProfile/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 = {
        	'study_id'			: id,
			'profiling_id' 		: $("#profiling_id_new").val(),
			'study_date_start' 	: $("#study_date_start").val(),
			'study_date_end' 	: $("#study_date_end").val(),
			'study_institution' : $("#study_institution").val(),
			'study_program' 	: $("#study_program").val(),
			'progress_paper' 	: $("#progress_paper").val(),
			'study_status' 		: $("#study_status").val()
		};

		$.ajax({
			url: '<?php echo base_url('hr/StaffProfile/save_editStudy'); ?>',
			data: postData,
			type: 'POST',
			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 deleteStudy(ID)
	{
		toastConfirm("Are you sure you want to delete this Study record?", function(){

			$.ajax({
				type: 'POST',
				url: '<?php echo base_url('hr/StaffProfile/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();
					}
				}
			});
		})
	}
</script>