From c32a12c13f37cd475a82492e77f38850c6bb5538 Mon Sep 17 00:00:00 2001 From: Ayobami Date: Thu, 7 Aug 2025 16:34:00 +0100 Subject: [PATCH] feat: complete assessment tasks --- client-routes.php | 4 +- docker-compose.yml | 6 +- index.php | 95 +++++++++++--- licenseListing.php | 255 +++++++++++++++++++++++++++++-------- mysql-database-service.php | 2 +- projectListing.php | 45 ++++++- reportListing.php | 67 +++++++--- 7 files changed, 381 insertions(+), 93 deletions(-) diff --git a/client-routes.php b/client-routes.php index 201359e..49a22fa 100644 --- a/client-routes.php +++ b/client-routes.php @@ -22,7 +22,7 @@ Route::add('/client/login', function () { $data = []; - if (empty($_POST['pasword']) || empty($_POST['email'])) { + if (empty($_POST['password']) || empty($_POST['email'])) { $error = true; // include_once __DIR__ . '/layout/header/Clientleft_sidebar.php'; include_once __DIR__ . '/client-login.php'; @@ -41,7 +41,7 @@ Route::add('/client/login', function () { // Insert data into the database using LicenseModel $userModel = new UserModel(); - $result = $userModel->get_by_field('id', $email); + $result = $userModel->get_by_field('email', $email); // var_dump($result);exit; if ($result) { if (password_verify($raw_password, $result['password']) && diff --git a/docker-compose.yml b/docker-compose.yml index 782e7d2..1a60aee 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.8' +version: "3.8" services: php: @@ -26,7 +26,7 @@ services: MYSQL_USER: tfu_user MYSQL_PASSWORD: tfu_password ports: - - "3306:3306" + - "3307:3306" volumes: - mysql_data:/var/lib/mysql command: --sql_mode="" @@ -42,4 +42,4 @@ services: - mysql volumes: - mysql_data: \ No newline at end of file + mysql_data: diff --git a/index.php b/index.php index 6315984..144aaa9 100644 --- a/index.php +++ b/index.php @@ -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('/'); - - diff --git a/licenseListing.php b/licenseListing.php index 6361357..34cf70c 100644 --- a/licenseListing.php +++ b/licenseListing.php @@ -5,27 +5,67 @@ color: white; /* White text color */ } + .bulk-actions { + margin-bottom: 15px; + padding: 10px; + background-color: #f8f9fa; + border-radius: 5px; + display: none; + } + .bulk-actions.show { + display: block; + }

Licenses   Add

+ + +
+
+
+ Selected items: 0 + + +
+ +
+
-
-
-
- - - - -
+
+ +
+ + +
+
+ + +
+ + + + + Clear + -
+
+ @@ -38,6 +78,7 @@ $value) { echo ' '; + echo ' '; echo ' '; echo ' '; echo ' '; @@ -53,49 +94,163 @@ 0 ? ($currentPage - $range) : 1; - $endPage = ($currentPage + $range) < $totalPages ? ($currentPage + $range) : $totalPages; - + $lastId = isset($data['id']) ? $data['id'] : 0; + $currentCursor = isset($_GET['cursor']) ? intval($_GET['cursor']) : 0; + $relationshipNum = isset($_GET['relationship_num']) ? $_GET['relationship_num'] : ''; + $emailSearch = isset($_GET['email']) ? $_GET['email'] : ''; + + // Build query parameters for pagination links + $queryParams = []; + if (!empty($relationshipNum)) { + $queryParams['relationship_num'] = $relationshipNum; + } + if (!empty($emailSearch)) { + $queryParams['email'] = $emailSearch; + } + + // Helper function to build query string + function buildQueryString($params) { + return !empty($params) ? '&' . http_build_query($params) : ''; + } + + $queryString = buildQueryString($queryParams); + + // Determine if we have previous/next pages + $hasPrevious = $currentCursor > 0; + $hasNext = count($data['data']) >= $perPage; // If we got a full page, assume there might be more + ?> - -
+ + + ID Relationship # Email
' . $value->id . '
edit delete
' . $value->relationship_num . ' ' . $value->email . '