up
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* API - Actualizar estado de plantilla
|
||||
* Fecha: 3 de enero de 2026
|
||||
*/
|
||||
|
||||
require_once '../config/config.php';
|
||||
|
||||
// Verificar autenticación
|
||||
requireAuthentication();
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Access-Control-Allow-Methods: PUT, POST');
|
||||
header('Access-Control-Allow-Headers: Content-Type');
|
||||
|
||||
if (!in_array($_SERVER['REQUEST_METHOD'], ['PUT', 'POST'])) {
|
||||
http_response_code(405);
|
||||
echo json_encode(['error' => 'Método no permitido']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
if (!$input || !isset($input['id']) || !isset($input['status'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => 'ID y estado requeridos']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$templateId = (int) $input['id'];
|
||||
$status = $input['status'];
|
||||
|
||||
// Validar estado
|
||||
if (!in_array($status, ['pending', 'approved', 'rejected'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => 'Estado inválido']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
|
||||
// Verificar que la plantilla existe
|
||||
$template = $db->fetch(
|
||||
"SELECT * FROM message_templates WHERE id = :id",
|
||||
['id' => $templateId]
|
||||
);
|
||||
|
||||
if (!$template) {
|
||||
http_response_code(404);
|
||||
echo json_encode(['error' => 'Plantilla no encontrada']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Actualizar estado
|
||||
$updated = $db->update('message_templates',
|
||||
['status' => $status],
|
||||
['id' => $templateId]
|
||||
);
|
||||
|
||||
if ($updated) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'Estado de plantilla actualizado correctamente',
|
||||
'template' => $template['name'],
|
||||
'new_status' => $status
|
||||
]);
|
||||
} else {
|
||||
http_response_code(500);
|
||||
echo json_encode(['error' => 'Error actualizando el estado']);
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log("Error in update_template_status.php: " . $e->getMessage());
|
||||
http_response_code(500);
|
||||
echo json_encode(['error' => 'Error interno del servidor: ' . $e->getMessage()]);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user