150 lines
6.6 KiB
PHP
150 lines
6.6 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
// Hardcoded credentials
|
|
$valid_username = 'admin';
|
|
$valid_password = 'password';
|
|
|
|
$is_logged_in = isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true;
|
|
$error_message = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
if (isset($_POST['logout'])) {
|
|
$_SESSION = [];
|
|
session_destroy();
|
|
header("Location: admin.php");
|
|
exit;
|
|
}
|
|
|
|
$username = $_POST['username'] ?? '';
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
if ($username === $valid_username && $password === $valid_password) {
|
|
$_SESSION['loggedin'] = true;
|
|
header("Location: admin.php");
|
|
exit;
|
|
} else {
|
|
$error_message = "Invalid username or password.";
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Admin - LAMP Demo</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">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body class="bg-light">
|
|
|
|
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="index.php">
|
|
<i class="bi bi-lightbulb-fill text-primary"></i>
|
|
LAMP Demo
|
|
</a>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<ul class="navbar-nav ms-auto">
|
|
<li class="nav-item"><a class="nav-link" href="index.php">Home</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="vibe.php">Vibe</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="sandbox.php">Sandbox</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="seo.php">SEO</a></li>
|
|
<li class="nav-item"><a class="nav-link active" href="admin.php">Admin</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="container my-5">
|
|
<?php if (!$is_logged_in): ?>
|
|
<div class="row justify-content-center">
|
|
<div class="col-lg-6">
|
|
<div class="card shadow-sm mb-4">
|
|
<div class="card-body p-4">
|
|
<h1 class="h3 mb-3 fw-normal text-center">Admin Login</h1>
|
|
<?php if ($error_message): ?>
|
|
<div class="alert alert-danger"><?php echo $error_message; ?></div>
|
|
<?php endif; ?>
|
|
<form method="POST" action="admin.php">
|
|
<div class="form-floating mb-3">
|
|
<input type="text" class="form-control" id="username" name="username" placeholder="Username">
|
|
<label for="username">Username</label>
|
|
</div>
|
|
<div class="form-floating mb-3">
|
|
<input type="password" class="form-control" id="password" name="password" placeholder="Password">
|
|
<label for="password">Password</label>
|
|
</div>
|
|
<button class="w-100 btn btn-lg btn-primary" type="submit">Sign in</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="card shadow-sm">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<h2 class="h4 mb-0">Nokia Facts Management</h2>
|
|
<form method="POST" action="admin.php">
|
|
<button type="submit" name="logout" class="btn btn-sm btn-outline-secondary">Logout <i class="bi bi-box-arrow-right"></i></button>
|
|
</form>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th scope="col">#</th>
|
|
<th scope="col">Fact</th>
|
|
<th scope="col">Created At</th>
|
|
<th scope="col">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
$pdo = db();
|
|
if ($pdo) {
|
|
$stmt = $pdo->query('SELECT id, fact, created_at FROM nokia_facts ORDER BY id DESC');
|
|
$facts = $stmt->fetchAll();
|
|
foreach ($facts as $fact):
|
|
?>
|
|
<tr>
|
|
<th scope="row"><?php echo htmlspecialchars($fact['id']); ?></th>
|
|
<td><?php echo htmlspecialchars($fact['fact']); ?></td>
|
|
<td><?php echo htmlspecialchars($fact['created_at']); ?></td>
|
|
<td>
|
|
<button class="btn btn-sm btn-outline-primary"><i class="bi bi-pencil"></i></button>
|
|
<button class="btn btn-sm btn-outline-danger"><i class="bi bi-trash"></i></button>
|
|
</td>
|
|
</tr>
|
|
<?php
|
|
endforeach;
|
|
} else {
|
|
echo "<tr><td colspan='4'>Database connection not available.</td></tr>";
|
|
}
|
|
?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<button class="btn btn-success"><i class="bi bi-plus-circle"></i> Add New Fact</button>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</main>
|
|
|
|
<footer class="bg-white text-center text-muted py-4 mt-5 border-top">
|
|
<div class="container">
|
|
<p class="mb-0">© 2025 LAMP Demo. All rights reserved.</p>
|
|
</div>
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="assets/js/main.js"></script>
|
|
</body>
|
|
</html>
|