diff --git a/add_visit.php b/add_visit.php new file mode 100644 index 0000000..66abc4b --- /dev/null +++ b/add_visit.php @@ -0,0 +1,95 @@ +prepare('INSERT INTO visits (client_name, latitude, longitude) VALUES (?, ?, ?)'); + $stmt->execute([$client_name, $latitude, $longitude]); + $success_message = 'Visit captured successfully!'; + } catch (PDOException $e) { + $error_message = 'Database error: ' . $e->getMessage(); + } + } +} +?> + + + + + + Add Client Visit + + + + + + +
+
+
+
+
+

Add Client Visit

+
+
+ +
+ + +
+ + +
+
+ + +
+ + + +
+
+
+ +
+
+
+ + + + + diff --git a/auth.php b/auth.php new file mode 100644 index 0000000..c350c04 --- /dev/null +++ b/auth.php @@ -0,0 +1,47 @@ +prepare('SELECT roles.name FROM users JOIN roles ON users.role_id = roles.id WHERE users.id = ?'); + $stmt->execute([$_SESSION['user_id']]); + $role = $stmt->fetchColumn(); + + return $role; +} + +function has_role($role_names) { + $current_role = current_user_role(); + if (is_array($role_names)) { + return in_array($current_role, $role_names); + } else { + return $current_role === $role_names; + } +} + +function require_role($role_names) { + require_login(); + if (!has_role($role_names)) { + // http_response_code(403); + // echo 'Forbidden'; + header('Location: index.php'); + exit(); + } +} diff --git a/db/migrations/001_create_visits_table.sql b/db/migrations/001_create_visits_table.sql new file mode 100644 index 0000000..ed86608 --- /dev/null +++ b/db/migrations/001_create_visits_table.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS visits ( + id INT AUTO_INCREMENT PRIMARY KEY, + client_name VARCHAR(255) NOT NULL, + latitude DECIMAL(10, 8) NOT NULL, + longitude DECIMAL(11, 8) NOT NULL, + visit_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); diff --git a/db/migrations/002_add_status_to_visits.sql b/db/migrations/002_add_status_to_visits.sql new file mode 100644 index 0000000..f90d1fe --- /dev/null +++ b/db/migrations/002_add_status_to_visits.sql @@ -0,0 +1 @@ +ALTER TABLE visits ADD COLUMN status VARCHAR(20) NOT NULL DEFAULT 'pending'; \ No newline at end of file diff --git a/db/migrations/003_create_roles_and_users_tables.sql b/db/migrations/003_create_roles_and_users_tables.sql new file mode 100644 index 0000000..f605376 --- /dev/null +++ b/db/migrations/003_create_roles_and_users_tables.sql @@ -0,0 +1,14 @@ +CREATE TABLE IF NOT EXISTS `roles` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `name` VARCHAR(50) NOT NULL UNIQUE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +INSERT INTO `roles` (`name`) VALUES ('Loan Officer'), ('Verifier'), ('Branch Manager'), ('Admin'); + +CREATE TABLE IF NOT EXISTS `users` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `username` VARCHAR(50) NOT NULL UNIQUE, + `password` VARCHAR(255) NOT NULL, + `role_id` INT, + FOREIGN KEY (`role_id`) REFERENCES `roles`(`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/index.php b/index.php index 7205f3d..c22f16e 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,107 @@ - +$current_role = current_user_role(); + +// Get username for display +$pdo = db(); +$stmt = $pdo->prepare('SELECT username FROM users WHERE id = ?'); +$stmt->execute([$_SESSION['user_id']]); +$username = $stmt->fetchColumn(); + +?> - - - New Style - - - - - - - - - - - - - - - - - - - + + + <?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'GeoVerify'); ?> + + -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

-
-
- + + +
+
+
+

Geo-verification System

+

Welcome, ! You are logged in as a .

+
+
+ +
+ +
+
+
+ +
Add New Visit
+

Capture GPS coordinates and client details for a new visit.

+ Go » +
+
+
+ + +
+
+
+ +
Review Visits
+

View, verify, or reject recorded client visits.

+ Go » +
+
+
+ +
+
+ + + + + + +sdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"> diff --git a/login.php b/login.php new file mode 100644 index 0000000..94f1e8e --- /dev/null +++ b/login.php @@ -0,0 +1,74 @@ +prepare('SELECT * FROM users WHERE username = ?'); + $stmt->execute([$username]); + $user = $stmt->fetch(PDO::FETCH_ASSOC); + + if ($user && password_verify($password, $user['password'])) { + $_SESSION['user_id'] = $user['id']; + header('Location: index.php'); + exit(); + } else { + $error = 'Invalid username or password.'; + } + } +} +?> + + + + + + Login + + + +
+
+
+
+
+

Login

+
+
+ +
+ +
+
+ + +
+
+ + +
+ +
+
+ +
+
+
+
+ + diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..49263e1 --- /dev/null +++ b/logout.php @@ -0,0 +1,6 @@ +query('SELECT * FROM roles')->fetchAll(PDO::FETCH_ASSOC); + +$error = ''; +$success = ''; + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $username = $_POST['username'] ?? ''; + $password = $_POST['password'] ?? ''; + $role_id = $_POST['role_id'] ?? ''; + + if (empty($username) || empty($password) || empty($role_id)) { + $error = 'Please fill in all fields.'; + } else { + $hashed_password = password_hash($password, PASSWORD_DEFAULT); + + try { + $stmt = $pdo->prepare('INSERT INTO users (username, password, role_id) VALUES (?, ?, ?)'); + $stmt->execute([$username, $hashed_password, $role_id]); + $success = "User registered successfully. You can now login."; + } catch (PDOException $e) { + if ($e->errorInfo[1] == 1062) { // Duplicate entry + $error = 'Username already exists.'; + } else { + $error = 'Database error: ' . $e->getMessage(); + } + } + } +} +?> + + + + + + Register + + + +
+
+
+
+
+

Register

+
+
+ +
+ + +
+ +
+
+ + +
+
+ + +
+
+ + +
+ +
+ +
+ +
+
+
+
+ + diff --git a/update_visit_status.php b/update_visit_status.php new file mode 100644 index 0000000..23f2e58 --- /dev/null +++ b/update_visit_status.php @@ -0,0 +1,24 @@ +prepare('UPDATE visits SET status = :status WHERE id = :id'); + $stmt->bindParam(':status', $status, PDO::PARAM_STR); + $stmt->bindParam(':id', $visit_id, PDO::PARAM_INT); + $stmt->execute(); + } catch (PDOException $e) { + // Optional: Log error to a file + // error_log('Database error: ' . $e->getMessage()); + } + } +} + +// Redirect back to the review page +header('Location: view_visits.php'); +exit; diff --git a/view_visits.php b/view_visits.php new file mode 100644 index 0000000..9ef024c --- /dev/null +++ b/view_visits.php @@ -0,0 +1,154 @@ +query('SELECT id, client_name, latitude, longitude, visit_time, status FROM visits ORDER BY visit_time DESC'); +$visits = $stmt->fetchAll(PDO::FETCH_ASSOC); + +?> + + + + + + <?php echo htmlspecialchars($pageTitle); ?> - Geo-verification App + + + + + + + + +
+
+
+ + Review Client Visits +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDClient NameCoordinatesVisit TimeStatusActions
No visits recorded yet.
+ + + + + " . ucfirst($status) . ""; + ?> + + +
+
+ + + +
+
+ + + +
+
+ + - + +
+
+
+
+
+ + + + + +