44 lines
1.5 KiB
PHP
44 lines
1.5 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$template_name = $_POST['template_name'] ?? '';
|
|
$template_content = $_POST['template_content'] ?? '';
|
|
|
|
if (!empty($template_name)) { // Allow empty content to reset
|
|
try {
|
|
// Check if the config exists
|
|
$stmt = db()->prepare("SELECT id FROM configuracion WHERE nombre_config = ?");
|
|
$stmt->execute([$template_name]);
|
|
$exists = $stmt->fetchColumn();
|
|
|
|
if ($exists) {
|
|
// Update
|
|
$update_stmt = db()->prepare("UPDATE configuracion SET valor_config = ? WHERE nombre_config = ?");
|
|
$update_stmt->execute([$template_content, $template_name]);
|
|
} else {
|
|
// Insert
|
|
$insert_stmt = db()->prepare("INSERT INTO configuracion (nombre_config, valor_config) VALUES (?, ?)");
|
|
$insert_stmt->execute([$template_name, $template_content]);
|
|
}
|
|
|
|
// Redirect back to configuration page with a success message
|
|
header('Location: configuracion.php?success=1');
|
|
exit;
|
|
|
|
} catch (PDOException $e) {
|
|
// Handle DB error
|
|
header('Location: configuracion.php?error=db');
|
|
exit;
|
|
}
|
|
} else {
|
|
// Handle empty fields
|
|
header('Location: configuracion.php?error=empty');
|
|
exit;
|
|
}
|
|
} else {
|
|
// Redirect if not a POST request
|
|
header('Location: configuracion.php');
|
|
exit;
|
|
}
|
|
?>
|