
<?php
session_start();
$usersFile = 'C:/inetpub/Authentication/OldiesAndMore/users.json';
$tempUser = 'admin';
$tempPass = 'admin123';
$error = '';
if (isset($_SESSION['user'])) { header('Location: index.php'); exit; }
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $username = trim($_POST['username'] ?? '');
    $password = trim($_POST['password'] ?? '');
    $loginSuccess = false; $role = 'viewer'; $permissions = '';
    if (is_file($usersFile)) {
        $users = json_decode((string)file_get_contents($usersFile), true);
        if (is_array($users)) {
            foreach ($users as $user) {
                if (($user['username'] ?? '') === $username && ($user['password'] ?? '') === $password) {
                    $loginSuccess = true; $role = $user['role'] ?? 'viewer'; $permissions = $user['permissions'] ?? ''; break;
                }
            }
        }
    }
    if (!$loginSuccess && $username === $tempUser && $password === $tempPass) { $loginSuccess = true; $role = 'admin'; $permissions = 'all'; }
    if ($loginSuccess) {
        session_regenerate_id(true);
        $_SESSION['user'] = $username; $_SESSION['role'] = $role; $_SESSION['permissions'] = $permissions; $_SESSION['last_activity'] = time();
        header('Location: index.php'); exit;
    }
    $error = 'Invalid username or password.';
}
?>
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Admin Login - Oldies And More</title><link rel="stylesheet" href="../css/site.css"><style>
body{margin:0;min-height:100vh;display:flex;align-items:center;justify-content:center;padding:24px;background:url('../assets/images/background.png') center top / cover no-repeat fixed;font-family:"Segoe UI",system-ui,sans-serif;color:#fff7de;}
.login-wrap{width:min(100%,580px);padding:32px 28px;border-radius:24px;background:linear-gradient(180deg,rgba(12,8,5,.92),rgba(21,13,8,.95));border:1px solid rgba(255,194,92,.34);box-shadow:0 28px 60px rgba(0,0,0,.45);text-align:center;}
.login-wrap h1{margin:0 0 10px;color:#fff2cf;text-shadow:0 0 15px rgba(0,234,255,.24);} .login-wrap p{color:#ffd98a;} .input-field{width:100%;box-sizing:border-box;margin-bottom:14px;text-align:left;background:rgba(0,0,0,.55);border:1px solid rgba(0,234,255,.46);box-shadow:0 0 0 1px rgba(255,153,0,.12);} .input-field::placeholder{color:rgba(255,241,201,.72)} .button{min-width:180px;} .msg{margin-bottom:14px;text-align:left;} .login-actions{display:flex;justify-content:center;gap:12px;flex-wrap:wrap;margin-top:14px;} .login-actions a{color:#fff2cf;text-decoration:none;padding:10px 14px;border-radius:999px;background:rgba(255,194,92,.12);border:1px solid rgba(255,194,92,.25);} code{color:#00eaff;}
</style></head><body>
<div class="login-wrap"><h1>🔐 Oldies And More Admin</h1><p>Professional temporary test login enabled while external auth is unavailable.</p><?php if ($error): ?><div class="msg error"><?= htmlspecialchars($error) ?></div><?php endif; ?><?php if (isset($_GET['timeout'])): ?><div class="msg error">Your session expired. Please sign in again.</div><?php endif; ?><form method="post"><input class="input-field" type="text" name="username" placeholder="Username" required><input class="input-field" type="password" name="password" placeholder="Password" required><button class="button" type="submit">Login</button></form><div class="login-actions"><a href="../index.php">🏠 Back to main site</a></div><p style="margin-top:16px;font-size:.95rem;">Temp login for testing: <code>admin</code> / <code>admin123</code></p></div>
</body></html>
