128 lines
5.2 KiB
PHP
128 lines
5.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
session_start();
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
// Authentication and Authorization check
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
if (($_SESSION['role'] ?? 'user') !== 'admin') {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
$message = '';
|
|
$pdo = db();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
if (isset($_POST['logout'])) {
|
|
session_destroy();
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$head_ads = $_POST['head_ads'] ?? '';
|
|
$body_ads = $_POST['body_ads'] ?? '';
|
|
$openai_api_key = $_POST['openai_api_key'] ?? '';
|
|
|
|
$stmt = $pdo->prepare("UPDATE site_settings SET setting_value = ? WHERE setting_key = 'head_ads'");
|
|
$stmt->execute([$head_ads]);
|
|
|
|
$stmt = $pdo->prepare("UPDATE site_settings SET setting_value = ? WHERE setting_key = 'body_ads'");
|
|
$stmt->execute([$body_ads]);
|
|
|
|
$stmt = $pdo->prepare("UPDATE site_settings SET setting_value = ? WHERE setting_key = 'openai_api_key'");
|
|
$stmt->execute([$openai_api_key]);
|
|
|
|
$message = "Settings updated successfully!";
|
|
}
|
|
|
|
// Fetch current settings
|
|
$stmt = $pdo->query("SELECT setting_key, setting_value FROM site_settings");
|
|
$settings = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
|
|
$head_ads = $settings['head_ads'] ?? '';
|
|
$body_ads = $settings['body_ads'] ?? '';
|
|
$openai_api_key = $settings['openai_api_key'] ?? '';
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>Admin Panel - TikTok Live AI</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?= time() ?>">
|
|
<style>
|
|
body { font-family: 'Inter', sans-serif; background-color: #0f0f0f; color: #fff; }
|
|
.card-admin { background-color: #1a1a1a; border: 1px solid #333; border-radius: 12px; }
|
|
.form-control { background-color: #262626; border-color: #444; color: #fff; }
|
|
.form-control:focus { background-color: #2d2d2d; border-color: #00f2ea; color: #fff; box-shadow: 0 0 0 0.25rem rgba(0, 242, 234, 0.25); }
|
|
.btn-save { background-color: #00f2ea; color: #000; font-weight: 700; border-radius: 8px; border: none; padding: 12px 24px; }
|
|
.btn-save:hover { background-color: #00d8d1; color: #000; }
|
|
.text-tiktok-cyan { color: #00f2ea; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<nav class="navbar navbar-dark bg-black border-bottom border-secondary mb-5">
|
|
<div class="container">
|
|
<a class="navbar-brand fw-bold" href="/">
|
|
<span class="text-tiktok-cyan">TikTok</span> Live Admin
|
|
</a>
|
|
<div class="d-flex align-items-center">
|
|
<span class="text-secondary small me-3">Logged in as <?= htmlspecialchars($_SESSION['username']) ?></span>
|
|
<a href="/" class="btn btn-outline-light btn-sm me-2">Back to Home</a>
|
|
<form action="admin.php" method="POST" class="m-0 d-inline">
|
|
<button type="submit" name="logout" class="btn btn-danger btn-sm">Logout</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="container">
|
|
<div class="row justify-content-center">
|
|
<div class="col-lg-8">
|
|
<div class="card-admin p-4 shadow-lg">
|
|
<h2 class="mb-4 fw-bold">Site Settings</h2>
|
|
|
|
<?php if ($message): ?>
|
|
<div class="alert alert-success bg-dark text-success border-success"><?= $message ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST">
|
|
<div class="mb-4">
|
|
<label for="openai_api_key" class="form-label fw-semibold text-secondary small">OpenAI API Key</label>
|
|
<input type="password" name="openai_api_key" id="openai_api_key" class="form-control" placeholder="sk-..." value="<?= htmlspecialchars($openai_api_key) ?>">
|
|
<div class="form-text text-muted">If left empty, the application will use the Flatlogic AI Proxy.</div>
|
|
</div>
|
|
|
|
<hr class="border-secondary my-4">
|
|
|
|
<div class="mb-4">
|
|
<label for="head_ads" class="form-label fw-semibold text-secondary small">Head Scripts (for JS Ads, Meta tags, etc.)</label>
|
|
<textarea name="head_ads" id="head_ads" rows="4" class="form-control" placeholder="Paste your <head> scripts here..."><?= htmlspecialchars($head_ads) ?></textarea>
|
|
<div class="form-text text-muted">These scripts will be placed inside the <head> tag.</div>
|
|
</div>
|
|
|
|
<div class="mb-4">
|
|
<label for="body_ads" class="form-label fw-semibold text-secondary small">Body Scripts (for floating ads, analytics, etc.)</label>
|
|
<textarea name="body_ads" id="body_ads" rows="4" class="form-control" placeholder="Paste your <body> scripts here..."><?= htmlspecialchars($body_ads) ?></textarea>
|
|
<div class="form-text text-muted">These scripts will be placed at the bottom of the <body> tag.</div>
|
|
</div>
|
|
|
|
<div class="d-grid mt-5">
|
|
<button type="submit" class="btn btn-save">Save All Settings</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
</body>
|
|
</html>
|