<?php 

function candidate_list_cb() {
	do_action("candidate_filter");
	if(!isset($_POST['adm_class']))
		return;
	$offer_admission_btn = false;
	switch ($_POST['grp']) {
		case 'all_candidates':
			$candidates = get_all_candidates($_POST['adm_class'], $_POST['adm_term']);
			$offer_admission_btn = true;
			$delete_btn = false;
			break;

		case 'waiting_list':
			$candidates = get_waiting_list($_POST['adm_class'], $_POST['adm_term']);
			$offer_admission_btn = true;
			$delete_btn = false;
			break;

		case 'passed_candidates':
			$candidates = get_passed_candidates($_POST['adm_class'], $_POST['adm_term']);
			$offer_admission_btn = true;
			$delete_btn = true;
			break;

		case 'failed_candidates':
			$candidates = get_failed_candidates($_POST['adm_class'], $_POST['adm_term']);
			$offer_admission_btn = true;
			$delete_btn = true;
			break;

		case 'no_record_candidates':
			$candidates = get_no_record_candidates($_POST['adm_class'], $_POST['adm_term']);
			$delete_btn = true;
			break;
		
		default:
			
			break;
		}

	$sorting = new sorting;
	$output = $sorting->sort_by_meta_value($candidates, 'surname', 'asc');
	
	?>

	<div class="row">
		<div class="col-md-12">
            <div class="card">
                <div class="card-header">
                    <strong class="card-title">Showing <?php echo $classname ?> Students</strong>
                </div>
                <div class="card-body">
          <table id="bootstrap-data-table-export" class="table table-striped table-bordered">
            <thead>
              <tr>
                <th>SN</th>
				<th>Name</th>
				<th class="notexport">Image</th>
				<th>Gender</th>
				<th>Class of Admission</th>
				<th>Sponsor</th>
				<th>Contact</th>
				<th>Remark</th>
				<th class="notexport">Action</th>
              </tr>
            </thead>
            <tbody>
<?php
$i = 1;
if(_count($output) > 0) : 
	foreach ($output as $key => $value) {
		$exam_status = $value['exam_status'];
		unset($value['exam_status']);
	 ?>
	 			<tr>
	 				<td><?=$i ?></td>
	 				<td><?=get_fullname($value); ?></td>
	 				<td><img class="img img-72" src="<?php echo get_user_image($value['id']); ?>"></td>
	 				<td><?=display_gender($value['gender']); ?></td>
	 				<td><?=get_class_name($value['class_of_admission']); ?></td>
	 				<td><?= $value['n1_fullname']; ?></td>
	 				<td><?= $value['n1_phone']; ?></td>
	 				<td class="text-center"><?= $exam_status; ?></td>
	 				<td><?php action(['profile' => 'candidate-profile?id='.$value['id']], ['candidate_profile'], [false]); ?>
	 				<?php if (current_user_can("offer_admission") && $offer_admission_btn): ?>
	 					<span id="offer-admission-btn-<?php echo $value['id']; ?>"><a data-studentmeta='<?php echo json_encode($value); ?>' class="btn btn-sm pt-0 pb-0 btn-success offer-admission" href="javascript:void(0);">Offer Admission</a></span>
	 					<?php if (current_user_can("delete_user") && $delete_btn): ?>
			    			<br><a href="javascript:void(0)" class="ajax-action" data-id="<?php echo $value['id'] ?>" data-action-callback="delete_user" data-content="Are you sure you want to delete this <?php echo get_fullname($value) ?>'s account? <br>By so doing, all the information about this particular user will be lost. If you still have need to access user information, please click on cancel and consider using the deactivation button instead.">Delete Profile</a>
			    		<?php endif ?>
	 				<?php endif ?>
	 				</td>
	 			</tr>

	<?php $i++; } 
endif;
			?>
            </tbody>
          </table>
                </div>
            </div>
        </div>
    </div>
	<?php
	do_action('display_offer_admission_form', ['adm_term' => $_POST['adm_term'], 'adm_class' => $_POST['adm_class']]);
}