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

123 lines
6.9 KiB
PHP

<?php
require_once __DIR__ . '/auth.php';
require_once __DIR__ . '/db/config.php';
if (!is_admin()) {
// Redirect to a different page or show an error
header('Location: index.php');
exit;
}
$pdo = db();
$message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$apiKey = $_POST['apiKey'] ?? '';
$metaUrl = $_POST['metaUrl'] ?? '';
$aiPrompt = $_POST['aiPrompt'] ?? '';
// Insert or update API Key
$stmt = $pdo->prepare("INSERT INTO settings (`key`, `value`) VALUES ('api_key', ?) ON DUPLICATE KEY UPDATE `value` = ?");
$stmt->execute([$apiKey, $apiKey]);
// Insert or update Meta URL
$stmt = $pdo->prepare("INSERT INTO settings (`key`, `value`) VALUES ('meta_url', ?) ON DUPLICATE KEY UPDATE `value` = ?");
$stmt->execute([$metaUrl, $metaUrl]);
// Insert or update AI Prompt
$stmt = $pdo->prepare("INSERT INTO settings (`key`, `value`) VALUES ('ai_prompt', ?) ON DUPLICATE KEY UPDATE `value` = ?");
$stmt->execute([$aiPrompt, $aiPrompt]);
$message = 'Settings saved successfully!';
}
// Fetch existing settings
$stmt = $pdo->query("SELECT * FROM settings");
$settings = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
$apiKey = $settings['api_key'] ?? '';
$metaUrl = $settings['meta_url'] ?? '';
$aiPrompt = $settings['ai_prompt'] ?? '';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Settings</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">
<svg class="icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z" /></svg>
Dashboard
</a>
<a class="nav-link" href="leads.php">
<svg class="icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" /></svg>
Leads
</a>
<?php if (is_admin()): ?>
<a class="nav-link" href="users.php">
<svg class="icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M15 21a6 6 0 00-9-5.197m0 0A5.975 5.975 0 0112 13a5.975 5.975 0 013-1.197M15 21a9 9 0 00-9-9m9 9a9 9 0 00-9-9" /></svg>
Users
</a>
<a class="nav-link" href="calendar.php">
<svg class="icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" /></svg>
Calendar
</a>
<a class="nav-link active" href="settings.php">
<svg class="icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.096 2.572-1.065z" /><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" /></svg>
Settings
</a>
<?php endif; ?>
<a class="nav-link" href="logout.php">
<svg class="icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1" /></svg>
Logout
</a>
</nav>
</aside>
<main class="main-content">
<header class="header">
<h1>Settings</h1>
</header>
<div class="card">
<div class="card-body">
<?php if ($message): ?>
<div class="alert alert-success"><?php echo $message; ?></div>
<?php endif; ?>
<form method="POST">
<div class="mb-3">
<label for="apiKey" class="form-label">API Key</label>
<input type="text" class="form-control" id="apiKey" name="apiKey" placeholder="Enter your API Key" value="<?php echo htmlspecialchars($apiKey); ?>">
</div>
<div class="mb-3">
<label for="metaUrl" class="form-label">Meta URL</label>
<input type="url" class="form-control" id="metaUrl" name="metaUrl" placeholder="Enter your Meta URL for WhatsApp" value="<?php echo htmlspecialchars($metaUrl); ?>">
</div>
<div class="mb-3">
<label for="aiPrompt" class="form-label">AI Prompt</label>
<textarea class="form-control" id="aiPrompt" name="aiPrompt" rows="5" placeholder="Enter the prompt for the conversational AI."><?php echo htmlspecialchars($aiPrompt); ?></textarea>
</div>
<button type="submit" class="btn btn-primary">Save Settings</button>
</form>
</div>
</div>
</main>
</div>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
</body>
</html>