50 lines
1.9 KiB
PHP
50 lines
1.9 KiB
PHP
|
|
<?php
|
|
|
|
require_once __DIR__ . '/../../db/config.php';
|
|
|
|
$pdo = db();
|
|
$stmt = $pdo->query("SELECT * FROM settings ORDER BY id DESC LIMIT 1");
|
|
$settings = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$stripe_secret_key = $_POST['stripe_secret_key'] ?? '';
|
|
$stripe_publishable_key = $_POST['stripe_publishable_key'] ?? '';
|
|
|
|
// Check if settings exist
|
|
$stmt = $pdo->query("SELECT id FROM settings");
|
|
$exists = $stmt->fetch();
|
|
|
|
if ($exists) {
|
|
$stmt = $pdo->prepare("UPDATE settings SET stripe_publishable_key = ?, stripe_secret_key = ? WHERE id = ?");
|
|
$stmt->execute([$stripe_publishable_key, $stripe_secret_key, $settings['id']]);
|
|
} else {
|
|
$stmt = $pdo->prepare("INSERT INTO settings (stripe_publishable_key, stripe_secret_key) VALUES (?, ?)");
|
|
$stmt->execute([$stripe_publishable_key, $stripe_secret_key]);
|
|
}
|
|
|
|
header('Location: /admin/settings/index.php?success=1');
|
|
exit;
|
|
}
|
|
|
|
include __DIR__ . '/../includes/header.php';
|
|
?>
|
|
|
|
<div class="container mt-4">
|
|
<h2>Settings</h2>
|
|
<?php if (isset($_GET['success'])): ?>
|
|
<div class="alert alert-success">Settings saved successfully.</div>
|
|
<?php endif; ?>
|
|
<form method="POST">
|
|
<div class="form-group">
|
|
<label for="stripe_secret_key">Stripe Secret Key</label>
|
|
<input type="text" class="form-control" id="stripe_secret_key" name="stripe_secret_key" value="<?php echo htmlspecialchars($settings['stripe_secret_key'] ?? ''); ?>">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="stripe_publishable_key">Stripe Publishable Key</label>
|
|
<input type="text" class="form-control" id="stripe_publishable_key" name="stripe_publishable_key" value="<?php echo htmlspecialchars($settings['stripe_publishable_key'] ?? ''); ?>">
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Save Settings</button>
|
|
</form>
|
|
</div>
|