134 lines
6.5 KiB
PHP
134 lines
6.5 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'Super Admin') {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
require_once 'db/config.php';
|
|
|
|
$user = null;
|
|
if (isset($_GET['id'])) {
|
|
$user_id = $_GET['id'];
|
|
$db = db();
|
|
$stmt = $db->prepare('SELECT id, name, email, role, agent_tier, cumulative_bookings, phone, company, notes FROM users WHERE id = ?');
|
|
$stmt->execute([$user_id]);
|
|
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$user) {
|
|
header('Location: admin_dashboard.php?error=user_not_found');
|
|
exit;
|
|
}
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$name = $_POST['name'];
|
|
$email = $_POST['email'];
|
|
$role = $_POST['role'];
|
|
$agent_tier = $_POST['agent_tier'];
|
|
$phone = $_POST['phone'];
|
|
$company = $_POST['company'];
|
|
$notes = $_POST['notes'];
|
|
$user_id = $_POST['user_id'];
|
|
|
|
if (empty($name) || empty($email) || empty($role)) {
|
|
header('Location: edit_user.php?id=' . $user_id . '&error=empty_fields');
|
|
exit;
|
|
}
|
|
|
|
$db = db();
|
|
$stmt = $db->prepare('UPDATE users SET name = ?, email = ?, role = ?, agent_tier = ?, phone = ?, company = ?, notes = ? WHERE id = ?');
|
|
$stmt->execute([$name, $email, $role, $agent_tier, $phone, $company, $notes, $user_id]);
|
|
|
|
header('Location: admin_dashboard.php');
|
|
exit;
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Edit User</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/dashboard.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body>
|
|
<div class="sidebar">
|
|
<h3 class="text-center p-3">Admin</h3>
|
|
<a href="admin_dashboard.php" class="active"><i class="bi bi-people-fill me-2"></i> User Management</a>
|
|
<a href="edit_content.php"><i class="bi bi-pencil-square me-2"></i> Edit Content</a>
|
|
<a href="index.php" target="_blank"><i class="bi bi-box-arrow-up-right me-2"></i> View Site</a>
|
|
<a href="logout.php"><i class="bi bi-box-arrow-left me-2"></i> Logout</a>
|
|
</div>
|
|
|
|
<div class="main-content">
|
|
<div class="header">
|
|
<h1>Edit User</h1>
|
|
</div>
|
|
|
|
<div class="card p-4">
|
|
<?php if ($user): ?>
|
|
<form action="edit_user.php" method="POST">
|
|
<input type="hidden" name="user_id" value="<?php echo $user['id']; ?>">
|
|
<div class="mb-3">
|
|
<label for="name" class="form-label">Name</label>
|
|
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($user['name']); ?>" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="email" class="form-label">Email</label>
|
|
<input type="email" class="form-control" id="email" name="email" value="<?php echo htmlspecialchars($user['email']); ?>" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="phone" class="form-label">Phone</label>
|
|
<input type="text" class="form-control" id="phone" name="phone" value="<?php echo htmlspecialchars($user['phone']); ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="company" class="form-label">Company</label>
|
|
<input type="text" class="form-control" id="company" name="company" value="<?php echo htmlspecialchars($user['company']); ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="notes" class="form-label">Notes</label>
|
|
<textarea class="form-control" id="notes" name="notes" rows="3"><?php echo htmlspecialchars($user['notes']); ?></textarea>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="role" class="form-label">Role</label>
|
|
<select class="form-select" id="role" name="role">
|
|
<option value="Agent" <?php if ($user['role'] === 'Agent') echo 'selected'; ?>>Agent</option>
|
|
<option value="Finance" <?php if ($user['role'] === 'Finance') echo 'selected'; ?>>Finance</option>
|
|
<option value="Support" <?php if ($user['role'] === 'Support') echo 'selected'; ?>>Support</option>
|
|
<option value="Admin" <?php if ($user['role'] === 'Admin') echo 'selected'; ?>>Admin</option>
|
|
<option value="Super Admin" <?php if ($user['role'] === 'Super Admin') echo 'selected'; ?>>Super Admin</option>
|
|
</select>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="agent_tier" class="form-label">Agent Tier</label>
|
|
<select class="form-select" id="agent_tier" name="agent_tier">
|
|
<option value="Normal" <?php if ($user['agent_tier'] === 'Normal') echo 'selected'; ?>>Normal</option>
|
|
<option value="Silver" <?php if ($user['agent_tier'] === 'Silver') echo 'selected'; ?>>Silver</option>
|
|
<option value="Gold" <?php if ($user['agent_tier'] === 'Gold') echo 'selected'; ?>>Gold</option>
|
|
<option value="Diamond" <?php if ($user['agent_tier'] === 'Diamond') echo 'selected'; ?>>Diamond</option>
|
|
</select>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="cumulative_bookings" class="form-label">Cumulative Bookings (INR)</label>
|
|
<input type="text" class="form-control" id="cumulative_bookings" name="cumulative_bookings" value="<?php echo htmlspecialchars($user['cumulative_bookings']); ?>" readonly>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Update User</button>
|
|
<a href="admin_dashboard.php" class="btn btn-secondary">Cancel</a>
|
|
</form>
|
|
<?php else: ?>
|
|
<div class="alert alert-danger">User not found.</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|