114 lines
2.7 KiB
PHP
114 lines
2.7 KiB
PHP
|
|
<?php
|
||
|
|
error_reporting(0);
|
||
|
|
require_once "../config.php";
|
||
|
|
require_once "../runtime/mencrypt.php";
|
||
|
|
|
||
|
|
$idevaluacion = $desencriptar($_POST['evaluacion']);
|
||
|
|
$numempl = $_POST['numempl'];
|
||
|
|
$mode = $_POST['mode'];
|
||
|
|
$orden= $_POST['orden'];
|
||
|
|
|
||
|
|
|
||
|
|
global $link;
|
||
|
|
dbConnect();
|
||
|
|
$return = new stdClass();
|
||
|
|
$sql = "";
|
||
|
|
|
||
|
|
if ($mode == 'new') {
|
||
|
|
$sql.="SELECT
|
||
|
|
ep.idpregunta,
|
||
|
|
ep.idevaluacion,
|
||
|
|
ep.titulo,
|
||
|
|
ep.descripcion,
|
||
|
|
ep.puntos,
|
||
|
|
ep.tipo,
|
||
|
|
ep.orden
|
||
|
|
FROM
|
||
|
|
evaluaciones_preguntas as ep
|
||
|
|
WHERE
|
||
|
|
ep.habilitado = 1 AND ep.idevaluacion = $idevaluacion";
|
||
|
|
}else{
|
||
|
|
$sql.="SELECT
|
||
|
|
*
|
||
|
|
FROM evaluaciones_preguntas as ep
|
||
|
|
WHERE
|
||
|
|
ep.idpregunta NOT IN (
|
||
|
|
SELECT er.idpregunta
|
||
|
|
FROM evaluaciones_estado as ee
|
||
|
|
INNER JOIN evaluaciones_respuestas as er ON er.idestado = ee.idevaestado
|
||
|
|
WHERE ee.numempl = '$numempl' AND ee.idevaluacion = $idevaluacion AND ee.estado = 'incomplete'
|
||
|
|
ORDER BY er.idpregunta ASC
|
||
|
|
)
|
||
|
|
AND
|
||
|
|
ep.habilitado = 1";
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($orden == 'Aleatorio') {
|
||
|
|
$sql .= " ORDER BY RAND()";
|
||
|
|
}else{
|
||
|
|
$sql .= " ORDER BY ep.orden ASC";
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
if($result = mysqli_query($link, $sql)){
|
||
|
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||
|
|
$return->code = "300";
|
||
|
|
$return->icon = "warning";
|
||
|
|
$return->msg ="No se encontraron preguntas vigentes para esta evaluación, intente más tarde.";
|
||
|
|
}else{
|
||
|
|
while ($row = mysqli_fetch_assoc($result)){
|
||
|
|
$questions[] = $row;
|
||
|
|
}
|
||
|
|
|
||
|
|
$alerts = [];
|
||
|
|
$totalPreguntasRespuestas = 0;
|
||
|
|
|
||
|
|
foreach ($questions as $key => $q) {
|
||
|
|
$answers = [];
|
||
|
|
$sqlAns = "SELECT
|
||
|
|
*
|
||
|
|
FROM
|
||
|
|
evaluaciones_opciones as eo
|
||
|
|
WHERE
|
||
|
|
eo.idpregunta = ".$q['idpregunta']." AND eo.habilitado = 1
|
||
|
|
ORDER BY RAND()";
|
||
|
|
|
||
|
|
if($resultAns = mysqli_query($link, $sqlAns)){
|
||
|
|
if ( mysqli_num_rows($resultAns) <= 0) {
|
||
|
|
array_push($alerts, "Sin respuestas");
|
||
|
|
$answers = [];
|
||
|
|
}else{
|
||
|
|
$totalPreguntasRespuestas++;
|
||
|
|
while ($row = mysqli_fetch_assoc($resultAns)){
|
||
|
|
$answers[] = $row;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$questions[$key]['respuestas'] = $answers;
|
||
|
|
}else{
|
||
|
|
$return->code = "300";
|
||
|
|
$return->icon = "warning";
|
||
|
|
$return->msg="Sin respuestas";
|
||
|
|
array_push($alerts, "Consulta fallo! SQL: ".$sqlAns."<br><br> Error: ".mysqli_error($link));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($totalPreguntasRespuestas == sizeof($questions)) {
|
||
|
|
$return->preguntas = $questions;
|
||
|
|
$return->code = "200";
|
||
|
|
$return->icon = "success";
|
||
|
|
$return->msg="Evaluaciones";
|
||
|
|
}else{
|
||
|
|
$return->code = "300";
|
||
|
|
$return->icon = "error";
|
||
|
|
$return->msg="Ocurrio un error al recuperar las respuestas";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
$return->code = "400";
|
||
|
|
$return->icon = "error";
|
||
|
|
$return->msg ="No se pudieron cargar los datos de la evaluación intenta más tarde.";
|
||
|
|
}
|
||
|
|
|
||
|
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||
|
|
exit;
|
||
|
|
?>
|