<?php
chdir('../');
require_once 'autoload.php';
$admin = new admin_controller;
$session = new session;
$uni = new university_controller;

$info = $uni->index();

require_once 'includes/session_validator.php';

if (!empty($is_authenticated) && $is_authenticated == 1 ) {

$csrf = $waf->csrf_generate('delete_enrollment.php', 600);

$table = <<<EOT
(
SELECT b.id, a.reference_no, CONCAT(b.first_name, ' ',b.last_name) as name, b.nrc, b.telephone, b.email_address FROM exam_enrollments a
JOIN students b ON a.student_id = b.id
) temp
EOT;

$primaryKey = 'id';
$orderColumn = 'id';
$orderType = 'DESC';


$columns = array(
array( 'db' => 'reference_no',   'dt' => 0 ),
array( 'db' => 'name',   'dt' => 1 ),
array( 'db' => 'nrc',   'dt' => 2 ),
array( 'db' => 'telephone',   'dt' => 3 ),
array( 'db' => 'email_address',   'dt' => 4 ),
array(
'db'        => 'id',
'dt'        => 5,
'formatter' => function( $d, $row ) {

$csrf = $GLOBALS['csrf'];
$e = $csrf['token'];
$f = $csrf['formId'];
$l = 'Delete Enrollment?';
$y = 'Yes';
$n = 'No';

return "
<button data-function='get_enrollment' data-id='$d' data-ref='".$row['0']."'  data-pc-animate='3d-rotate-InLeft' type='button' class='btn btn-primary btn-sm edit_btn' data-bs-toggle='modal' data-bs-target='#modal-edit'><i class='fa fa-eye'></i></button>
<button data-url='app/routes/delete_enrollment?id=$d&csrf_token=$e&csrf_form_id=$f' data-message='$l' data-yes='$y' data-no='$n' type='button' class='btn btn-danger btn-sm delete_btn'><i class='fa far fa-trash-can'></i></button>
";
}
)
);


$sql_details = array(
'user' => getenv("DB_USERNAME"),
'pass' => getenv("DB_PASSWORD"),
'db'   => getenv("DB_NAME"),
'host' => getenv("DB_HOST")
,'charset' => 'utf8'
);

require('includes/ssp.class.php');

echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns, $orderColumn, $orderType)
);

}
?>
