39 lines
1.2 KiB
PHP
39 lines
1.2 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)) {
|
|
try {
|
|
$pdo = db();
|
|
// Use INSERT ... ON DUPLICATE KEY UPDATE to either create or update the template
|
|
$sql = "INSERT INTO configuracion (clave, valor) VALUES (:clave, :valor)
|
|
ON DUPLICATE KEY UPDATE valor = :valor";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute([
|
|
':clave' => $template_name,
|
|
':valor' => $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;
|
|
}
|
|
?>
|