DASHBOARD:
Panel de control | 25 Aniversario
TICKETS AUTO
| FOLIO |
NOMBRE/S |
APELLIDOS |
ESTADO |
TELEFONO |
CORREO |
FECHA NACIMIENTO |
FECHA REGISTRO |
ACIERTOS |
IMAGEN |
VALIDAR |
fetch_assoc()) {
?>
|
|
|
|
|
|
|
|
/5 |
|
|
---
REGISTRO:
'SET NAMES utf8');
try {
$con = new PDO("mysql:host=" . servidor . "; dbname=" . nombre_bd, usuario, password, $opciones);
return $con;
} catch (Exception $e) {
die("El error de Conexión es: " . $e->getMessage());
}
}
}
$objeto = new Conexion();
$con = $objeto->Conectar();
date_default_timezone_set('America/Mexico_City');
$fecha = date("d-m-Y");
$folio = (isset($_POST['ticket'])) ? $_POST['ticket'] : '';
$nombre = (isset($_POST['nombre'])) ? $_POST['nombre'] : '';
$apellido = (isset($_POST['last'])) ? $_POST['last'] : '';
$edo = (isset($_POST['estate'])) ? $_POST['estate'] : '';
$num = (isset($_POST['num'])) ? $_POST['num'] : '';
$mail = (isset($_POST['mail'])) ? $_POST['mail'] : '';
$day = (isset($_POST['day'])) ? $_POST['day'] : '';
$month = (isset($_POST['month'])) ? $_POST['month'] : '';
$year = (isset($_POST['year'])) ? $_POST['year'] : '';
$nac = $day . '-' . $month . '-' . $year;
$directorio = "img/";
$file_src = $_FILES['img']['tmp_name'];
$name_file = $_FILES['img']['name'];
// Definimos las preguntas y respuestas
$preguntas = [
[
"respuesta_correcta" => "a"
],
[
"respuesta_correcta" => "c"
],
[
"respuesta_correcta" => "b"
],
[
"respuesta_correcta" => "b"
],
[
"respuesta_correcta" => "b"
]
];
// Contamos las respuestas correctas
$aciertos = 0;
foreach ($preguntas as $index => $pregunta) {
if (isset($_POST["q-$index"]) && $_POST["q-$index"] === $pregunta['respuesta_correcta']) {
$aciertos++;
}
}
if (vfolio($folio, $edo, $con) == 1) {
echo 3;
exit();
}else if (!move_uploaded_file($file_src, $directorio . $name_file)){
error_log("Error al mover el archivo: " . $_FILES['img']['error']);
echo 4;
exit();
}else if(!preg_match("/^[a-zA-Z0-9]+([ \-][a-zA-Z0-9]+)*$/", $folio)){
echo 2;
exit();
}else if (!preg_match("/^[\p{L}]+(?:[\s-][\p{L}]+)*$/u", $nombre) || !preg_match("/^[\p{L}]+(?:[\s-][\p{L}]+)*$/u", $apellido)) {
echo 2;
exit();
} else if (!filter_var($mail, FILTER_VALIDATE_EMAIL)) {
echo 2;
exit();
} else {
try {
$sql = "INSERT INTO user (FOLIO, NAME, LAST_NAME, STATE, PHONE, MAIL, DATE_BORN, DATE, ok, IMG) VALUES (:folio, :name, :last_name, :state, :phone, :mail, :date_born, :date, :ok, :img)";
$stmt = $con->prepare($sql);
$stmt->bindParam(':folio', $folio);
$stmt->bindParam(':name', $nombre);
$stmt->bindParam(':last_name', $apellido);
$stmt->bindParam(':state', $edo);
$stmt->bindParam(':phone', $num);
$stmt->bindParam(':mail', $mail);
$stmt->bindParam(':date_born', $nac);
$stmt->bindParam(':date', $fecha);
$stmt->bindParam(':ok', $aciertos);
$stmt->bindParam(':img', $name_file);
$stmt->execute();
echo 1;
} catch (PDOException $e) {
error_log("Error al insertar en la base de datos: " . $e->getMessage());
echo 2;
}
}
function vfolio($fol, $edo, $con)
{
try {
$stmt = $con->prepare("SELECT ID FROM user WHERE STATE = :state AND FOLIO = :folio");
$stmt->bindParam(':state', $edo);
$stmt->bindParam(':folio', $fol);
$stmt->execute();
if ($stmt->rowCount() > 0) {
return 1;
} else {
return 0;
}
} catch (PDOException $e) {
return 1;
}
}
?>