File "guardar_firma.php"
Full Path: C:/wamp64/www/APPSST/Admin/firmadot/guardar_firma.php
File size: 1.31 KB
MIME-type: text/x-php
Charset: utf-8
<?php
session_start();
include("../../bd/conexion.php");
header('Content-Type: application/json');
$response = ['success' => false, 'message' => ''];
try {
if (!isset($_POST['id']) || !isset($_POST['cedula']) || !isset($_POST['firma'])) {
throw new Exception('Datos incompletos');
}
$id = $_POST['id'];
$cedula = $_POST['cedula'];
$firma = $_POST['firma'];
// Validar que la firma sea una imagen base64 válida
if (!preg_match('/^data:image\/(png|jpeg);base64,/', $firma)) {
throw new Exception('Formato de firma no válido');
}
// Preparar la consulta
$query = $conexion->prepare("UPDATE entregasst SET FIRMA = ? WHERE ID = ? AND cedula = ?");
$query->bind_param("sis", $firma, $id, $cedula);
if ($query->execute()) {
// Guardar el ID de la entrega firmada en la sesión para la redirección
$_SESSION['ultimo_id_firmado'] = $id;
$response['success'] = true;
$response['message'] = 'Firma guardada correctamente';
$response['redirect'] = 'FORMFIRM.PHP?id=' . $id;
} else {
throw new Exception('Error al guardar en la base de datos: ' . $conexion->error);
}
} catch (Exception $e) {
$response['message'] = $e->getMessage();
}
echo json_encode($response);