34318-vm/users.php
Flatlogic Bot 64b701287d v1
2025-09-23 20:48:22 +00:00

118 lines
4.4 KiB
PHP

<?php
require_once __DIR__ . '/auth.php';
require_once __DIR__ . '/db/config.php';
if (!is_admin()) {
header('Location: index.php');
exit;
}
$pdo = db();
$invite_message = '';
$invitation_link = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['invite_email'])) {
$email = $_POST['invite_email'];
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
$token = bin2hex(random_bytes(32));
$expires_at = date('Y-m-d H:i:s', strtotime('+1 day'));
$stmt = $pdo->prepare("INSERT INTO invitations (email, token, expires_at) VALUES (?, ?, ?)");
$stmt->execute([$email, $token, $expires_at]);
$invitation_link = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/register.php?token=' . $token;
$invite_message = 'Invitation link generated successfully. Please send it to the user.';
} else {
$invite_message = 'Invalid email address.';
}
}
$stmt = $pdo->query("SELECT * FROM users ORDER BY created_at DESC");
$users = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Users</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<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=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
</head>
<body>
<div class="main-container">
<aside class="sidebar">
<div class="logo">SaaSApp</div>
<nav class="nav flex-column">
<a class="nav-link" href="index.php">Dashboard</a>
<a class="nav-link" href="leads.php">Leads</a>
<a class="nav-link" href="calendar.php">Calendar</a>
<a class="nav-link active" href="users.php">Users</a>
<a class="nav-link" href="settings.php">Settings</a>
<a class="nav-link" href="logout.php">Logout</a>
</nav>
</aside>
<main class="main-content">
<header class="header">
<h1>User Management</h1>
</header>
<div class="card mb-4">
<div class="card-body">
<h5 class="card-title">Invite User</h5>
<?php if ($invite_message): ?>
<div class="alert alert-info"><?php echo $invite_message; ?></div>
<?php endif; ?>
<?php if ($invitation_link): ?>
<div class="alert alert-success">
<p>Invitation Link:</p>
<input type="text" class="form-control" value="<?php echo $invitation_link; ?>" readonly>
</div>
<?php endif; ?>
<form method="POST">
<div class="input-group">
<input type="email" class="form-control" name="invite_email" placeholder="Enter email to invite" required>
<button type="submit" class="btn btn-primary">Invite</button>
</div>
</form>
</div>
</div>
<div class="card">
<div class="card-body">
<h5 class="card-title">Existing Users</h5>
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Role</th>
<th>Registered On</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $user): ?>
<tr>
<td><?php echo htmlspecialchars($user['name']); ?></td>
<td><?php echo htmlspecialchars($user['email']); ?></td>
<td><?php echo htmlspecialchars($user['role']); ?></td>
<td><?php echo date('M d, Y', strtotime($user['created_at'])); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</main>
</div>
</body>
</html>