<?php 

function our_academic_staff_cb() {
	$user = new user;
	do_action('display_staff_filter');
	
    if(!isset($_POST['role'])) return;

	$sorting = new sorting;

	if($_POST['role'] == 'all') {
		$staff = $user->get_user_by_meta_data(['role' => 'super_admin', 'status' => 'active']);
		$staff = array_merge($staff, $user->get_user_by_meta_data(['role' => 'admin', 'status' => 'active']));
		$staff = array_merge($staff, $user->get_user_by_meta_data(['role' => 'teacher', 'status' => 'active']));
	} else {
		$staff = $user->get_user_by_meta_data(['role' => $_POST['role'], 'status' => 'active']);
	}

	$sorting = new sorting;
	if(isset($_POST['to']) && isset($_POST['from'])) {
		$from = strtotime($_POST['from']);
		$to = strtotime($_POST['to']);
		$staff = filter_user_result_by_date_range($staff, $from, $to, 'date_created');
	}
	$output = $sorting->sort_by_meta_value($staff, 'id', 'desc');
	$token = new_token();
	?>

	<div class="row">
		<div class="col-md-12">
            <div class="card">
                <div class="card-header">
                    <strong class="card-title">Staff</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>Staff Number</th>
				<th>Image</th>
				<th>Role</th>
				<th>Phone Number</th>
				<th>Date Registered</th>
				<th class="not-export">Action</th>
              </tr>
            </thead>
            <tbody>
<?php
$i = 1;
if(_count($output) > 0) : 
	foreach ($output as $key => $value) {
		// var_dump($value);
	 ?>
	 			<tr>
	 				<td><?=$i ?></td>
	 				<td><?=$value['surname'].' '.$value['other_names']; ?>
	 				</td>
	 				<td><i class="fas fa-user"></i>&nbsp;<?=strtoupper($value['username']);?></td>
	 				<td><img class="img img-72" src="<?php echo get_user_image($value['id']); ?>"></td>
	 				<td><?=$value['role'];?></td>
	 				<td><?=$value['phone'];?></td>
	 				<td><?= date(_DATE_FORMAT_, $value['date_created']); ?></td>
	 				<td><?php action(['profile' => 'profile?id='.$value['id'].'&token='.$token], ['staff_profile'], [false]); ?></td>
	 			</tr>

	<?php $i++; } 
endif;
			?>
            </tbody>
          </table>
                </div>
            </div>
        </div>
    </div>
	<?php
}