<?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_type.php', 600);

$table = <<<EOT
(
SELECT id, name, status FROM exam_types
) temp
EOT;

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


$columns = array(
array( 'db' => 'name',   'dt' => 0 ),
array(
'db'        => 'status',
'dt'        => 1,
'formatter' => function( $d, $row ) {
switch ($d) {
case 'enabled':
return '<span class="badge bg-success">ENABLED</span>';
break;

default:
return '<span class="badge bg-danger">DISABLED</span>';
break;
}
}
),
array(
'db'        => 'id',
'dt'        => 2,
'formatter' => function( $d, $row ) {

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

return "
<button data-function='get_type' data-id='$d' data-name='".$row['0']."' data-status='".$row['1']."' 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-edit'></i></button>
<button data-url='app/routes/delete_type?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)
);

}
?>
