36522-vm/add_visit.php
Flatlogic Bot 1cff3c750d 1.1
2025-12-01 13:32:48 +00:00

96 lines
4.0 KiB
PHP

<?php
require_once 'auth.php';
require_role('Loan Officer');
require_once __DIR__ . '/db/config.php';
$success_message = '';
$error_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$client_name = $_POST['client_name'] ?? '';
$latitude = $_POST['latitude'] ?? '';
$longitude = $_POST['longitude'] ?? '';
if (empty($client_name) || empty($latitude) || empty($longitude)) {
$error_message = 'Client name and GPS coordinates are required.';
} else {
try {
$pdo = db();
$stmt = $pdo->prepare('INSERT INTO visits (client_name, latitude, longitude, user_id) VALUES (?, ?, ?, ?)');
$stmt->execute([$client_name, $latitude, $longitude, $_SESSION['user_id']]);
$success_message = 'Visit captured successfully!';
} catch (PDOException $e) {
$error_message = 'Database error: ' . $e->getMessage();
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add Client Visit</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container-fluid">
<a class="navbar-brand" href="/"><?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'GeoVerify'); ?></a>
</div>
</nav>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h1 class="h4 mb-0">Add Client Visit</h1>
</div>
<div class="card-body">
<?php if ($success_message): ?>
<div class="alert alert-success"><?php echo $success_message; ?></div>
<?php endif; ?>
<?php if ($error_message): ?>
<div class="alert alert-danger"><?php echo $error_message; ?></div>
<?php endif; ?>
<form id="visitForm" method="POST" action="add_visit.php">
<div class="mb-3">
<label for="client_name" class="form-label">Client Name</label>
<input type="text" class="form-control" id="client_name" name="client_name" required>
</div>
<input type="hidden" id="latitude" name="latitude">
<input type="hidden" id="longitude" name="longitude">
<button type="submit" class="btn btn-primary w-100">Capture and Save Visit <i class="bi bi-geo-alt-fill"></i></button>
</form>
</div>
</div>
<div class="text-center mt-3">
<a href="/" class="btn btn-secondary">Back to Home</a>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
document.getElementById('latitude').value = position.coords.latitude;
document.getElementById('longitude').value = position.coords.longitude;
}, function(error) {
console.error("Error getting location: ", error);
alert('Could not get your location. Please enable location services and try again.');
});
} else {
alert('Geolocation is not supported by this browser.');
}
});
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>