feat: complete assessment tasks

This commit is contained in:
Ayobami
2025-08-07 16:34:00 +01:00
parent 463a238503
commit c32a12c13f
7 changed files with 381 additions and 93 deletions
+79 -16
View File
@@ -332,7 +332,7 @@ Route::add('/admin/login', function () {
$_SESSION['is_logged_in'] = true;
$_SESSION['role'] = $result['role'];
$_SESSION['user'] = $result['id'];
header('Location: /admin/users');
header('Location: /admin/accesslog');
} else {
$error = true;
include_once __DIR__ . '/login.php';
@@ -501,27 +501,37 @@ Route::add('/admin/license', function () {
check_login();
$format = isset($_GET['format']) ? $_GET['format'] : 'json';
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$cursor_id = isset($_GET['cursor']) ? intval($_GET['cursor']) : 0;
$per_page = isset($_GET['size']) ? intval($_GET['size']) : 10;
$sort = isset($_GET['sort']) ? $_GET['sort'] : 'id';
$direction = isset($_GET['direction']) ? $_GET['direction'] : 'ASC';
$relationship_num = isset($_GET['relationship_num']) ? $_GET['relationship_num'] : '';
$email_search = isset($_GET['email']) ? trim($_GET['email']) : '';
$licenseModel = new LicenseModel();
$data = [
'page_title' => 'License',
'relationship_num' => $relationship_num
'relationship_num' => $relationship_num,
'email_search' => $email_search
];
$where = [];
if ($relationship_num != '') {
$where['relationship_num'] = '"' . $relationship_num . '"';
// $where['relationship_num'] = '"' . $relationship_num . '"';
// $where[] = '"' . $relationship_num . '"';
$where[] = "relationship_num = '" . addslashes($relationship_num) . "'";
}
$result = $licenseModel->get_paginated($page, $per_page, $where, $sort, $direction);
// Add fuzzy email search using LIKE
if ($email_search != '') {
$where[] = "email LIKE '%" . addslashes($email_search) . "%'";
}
// Use cursor-based pagination instead of offset-based
$result = $licenseModel->get_cursor_paginated($page, $per_page, $where, $sort, $direction, $cursor_id);
if ($result) {
if ($format == 'json') {
@@ -917,19 +927,28 @@ Route::add('/admin/project', function () {
$per_page = isset($_GET['size']) ? intval($_GET['size']) : 15;
$sort = isset($_GET['sort']) ? $_GET['sort'] : 'id';
$direction = isset($_GET['direction']) ? $_GET['direction'] : 'ASC';
// $relationship_num = isset($_GET['relationship_num']) ? $_GET['relationship_num'] : '';
$project_search = isset($_GET['project_search']) ? $_GET['project_search'] : '';
$webhook_search = isset($_GET['webhook_search']) ? $_GET['webhook_search'] : '';
$projectModel = new ProjectModel();
$data = [
'page_title' => 'Project',
'project_search' => $project_search,
'webhook_search' => $webhook_search
];
$where = [];
// if ($relationship_num != '') {
// $where['relationship_num'] = '"' . $relationship_num . '"';
// }
// Add fuzzy search for project_name
if ($project_search != '') {
$where[] = "project_name LIKE '%" . addslashes($project_search) . "%'";
}
// Add fuzzy search for webhook
if ($webhook_search != '') {
$where[] = "webhook LIKE '%" . addslashes($webhook_search) . "%'";
}
$result = $projectModel->get_paginated($page, $per_page, $where, 'id', 'DESC');
// echo json_encode($result);
@@ -1379,19 +1398,42 @@ Route::add('/admin/report', function () {
$sort = isset($_GET['sort']) ? $_GET['sort'] : 'id';
$direction = isset($_GET['direction']) ? $_GET['direction'] : 'ASC';
$date = isset($_GET['date']) ? $_GET['date'] : '';
$start_date = isset($_GET['start_date']) ? $_GET['start_date'] : '';
$end_date = isset($_GET['end_date']) ? $_GET['end_date'] : '';
$project = isset($_GET['project']) ? $_GET['project'] : '';
$reportModel = new ReportModel();
$data = [
'page_title' => 'Report',
'date' => $date
'date' => $date,
"start_date" => $start_date,
"end_date" => $end_date,
"project" => $project
];
$where = [];
$where = [];
if ($date != '') {
$where['date'] = '"' . $date . '"';
}
if ($date != '' && empty($start_date) && empty($end_date)) {
$where['date'] = '"' . $date . '"';
}
if (!empty($start_date) && !empty($end_date)) {
$where[] = "date BETWEEN '" . $start_date . "' AND '" . $end_date . "'";
}
if (!empty($start_date) && empty($end_date)) {
$where[] = "date >= '" . $start_date . "'";
}
if (empty($start_date) && !empty($end_date)) {
$where[] = "date <= '" . $end_date . "'";
}
if($project != '') {
$where[] = "project LIKE '%" . addslashes($project) . "%'";
}
$result = $reportModel->get_paginated($page, $per_page, $where, 'id', 'DESC');
// echo json_encode($result);
@@ -1487,6 +1529,29 @@ Route::add('/admin/license/delete/([0-9]+)', function ($id) {
$licenseModel->real_delete($id);
header('Location: /admin/license');
}, 'get');
Route::add('/admin/license/list/multiselect', function () {
check_login();
$licenseModel = new LicenseModel();
if (isset($_POST['delete'])) {
if (isset($_POST['selected_items']) && !empty($_POST['selected_items'])) {
$ids = explode(',', $_POST['selected_items']);
$ids = array_map('intval', $ids); // Sanitize IDs
$ids_string = implode(', ', $ids);
$licenseModel->real_delete_by_fields([
"id IN ($ids_string)"
]);
}
header('Location: /admin/license');
exit;
}
// If no valid action, redirect back
header('Location: /admin/license');
exit;
}, 'post');
Route::add('/admin/location/delete/([0-9]+)', function ($id) {
check_login();
$locationModel = new LocationModel();
@@ -1927,5 +1992,3 @@ include_once 'cal.php';
include_once 'oauth-routes.php';
Route::run('/');