Cuestionario.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <?php
  2. require_once 'Proyecto.php';
  3. require_once 'Template.php';
  4. class Cuestionario {
  5. private $concurso;
  6. private $etapa;
  7. private $pdo;
  8. private $rubros = array();
  9. private $especiales = array();
  10. private $periodoValido = false;
  11. private $usr;
  12. private $tipoDato;
  13. function __construct($pdo, $usr, $concurso, $etapa){
  14. $this->concurso = $concurso;
  15. $this->etapa = $etapa;
  16. $this->usr = $usr;
  17. $this->pdo = $pdo;
  18. $this->tipoDato = Proyecto::determinaAccionXEtapa($pdo, $etapa);
  19. $this->obtenerRubros();
  20. }
  21. private function obtenerRubros(){
  22. $stmt = $this->pdo->prepare('Select * from cidit_fs_rubrosxetapa(:etapa)');
  23. $stmt->bindParam(':etapa', $this->etapa);
  24. if($stmt->execute()){
  25. $rubro_rs = $stmt->fetchAll();
  26. $stmt->closeCursor();
  27. $stmt = null;
  28. foreach ($rubro_rs as $rubro) {
  29. if ($rubro['orden'] != '')
  30. array_push($this->rubros, array('id' => $rubro['idrubro'],'rubro' => $rubro['rubro'], 'prefijo' => $rubro['prefijo'],'orden' => $rubro['orden'], 'porcentaje' => $rubro['porcentaje']));
  31. else
  32. array_push($this->especiales, array('id' => $rubro['idrubro'],'rubro' => $rubro['rubro'], 'prefijo' => $rubro['prefijo'], 'porcentaje' => $rubro['porcentaje']));
  33. }
  34. }
  35. else{
  36. $stmt->closeCursor();
  37. $stmt = null;
  38. }
  39. }
  40. private function obtenerPreguntas($rubro){
  41. $preguntas = array();
  42. $stmt = $this->pdo->prepare('Select * from cidit_fs_preguntasxrubro(:rubro)');
  43. $stmt->bindParam(':rubro', $rubro);
  44. if($stmt->execute()){
  45. $preguntas_rs = $stmt->fetchAll();
  46. $stmt->closeCursor();
  47. $stmt = null;
  48. foreach ($preguntas_rs as $pregunta) {
  49. array_push($preguntas, array('id' => $pregunta['idpregunta'],'pregunta' => $pregunta['pregunta'], 'instrucciones' => $pregunta['instrucciones'], 'orden' => $pregunta['orden'], 'tipo' => $pregunta['tipo'], 'obligatoria' => $pregunta['obligatoria']));
  50. }
  51. }
  52. else{
  53. $stmt->closeCursor();
  54. $stmt = null;
  55. }
  56. return $preguntas;
  57. }
  58. private function obtenerOpciones($pregunta){
  59. $opciones = array();
  60. $stmt = $this->pdo->prepare('Select * from cidit_fs_opcionesxpregunta(:pregunta)');
  61. $stmt->bindParam(':pregunta', $pregunta);
  62. if($stmt->execute()){
  63. $opciones_rs = $stmt->fetchAll();
  64. $stmt->closeCursor();
  65. $stmt = null;
  66. foreach ($opciones_rs as $opcion) {
  67. array_push($opciones, array('id' => $opcion['idopcion'],'opcion' => $opcion['opcion'],'valor' => $opcion['valor']));
  68. }
  69. }
  70. else{
  71. $stmt->closeCursor();
  72. $stmt = null;
  73. }
  74. return $opciones;
  75. }
  76. private function preguntasRanking($pregunta, $opciones, $indice){ ?>
  77. <div class="star-rating">
  78. <div class="d-flex justify-content-center flex-row-reverse fieldset" data-tipo="radiobutton">
  79. <?php $cont = count($opciones);
  80. foreach ($opciones as $opcion){?>
  81. <input data-indice="<?php echo $indice; ?>" type="radio" id="star<?php echo $cont; ?>" name="pregunta[<?php echo $pregunta; ?>]" value="<?php echo $opcion['id']; ?>" />
  82. <label for="star<?php echo $cont; ?>"><div></div><span><?php echo $opcion['opcion']; ?></span></label>
  83. <?php $cont--;
  84. } ?>
  85. </div>
  86. </div>
  87. <?php }
  88. private function preguntasOpciones($pregunta, $opciones, $indice){
  89. $preg=1; ?>
  90. <div class="opciones" data-tipo="radiobutton">
  91. <?php foreach ($opciones as $opcion){ ?>
  92. <div>
  93. <input type="radio" data-indice="<?php echo $indice; ?>" id="preg<?php echo $pregunta . '-' . $preg; ?>" name="pregunta[<?php echo $pregunta; ?>]" value="<?php echo $opcion['id']; ?>">
  94. <label class="op<?php echo $preg; ?>" for="preg<?php echo $pregunta . '-' . $preg; ?>"><?php echo $opcion['opcion']; ?></label>
  95. </div>
  96. <?php $preg++;
  97. } ?>
  98. </div>
  99. <?php }
  100. private function preguntasAbiertas($pregunta, $indice){ ?>
  101. <div class="abierta" data-tipo="texto">
  102. <textarea class="richtext" data-indice="<?php echo $indice; ?>" name="pregunta-<?php echo $pregunta; ?>" rows="5" placeholder="Escribe aquí"></textarea>
  103. </div>
  104. <?php }
  105. private function tipoPregunta($pregunta, $indice){
  106. if ($pregunta['instrucciones'] != ''){ ?>
  107. <div class="instrucciones"><?php echo $pregunta['instrucciones']; ?></div>
  108. <?php }
  109. $opciones = $this->obtenerOpciones($pregunta['id']);
  110. switch (mb_strtoupper($pregunta['tipo'])){
  111. case 'ESTRELLA':
  112. case 'ESTRELLAS':
  113. case 'RANKING':
  114. $this->preguntasRanking($pregunta['id'], $opciones, $indice);
  115. break;
  116. case 'OPCION MULTIPLE':
  117. case 'OPCIÓN MULTIPLE':
  118. case 'OPCIÓN MÚLTIPLE':
  119. case 'OPCION MÚLTIPLE':
  120. case 'OPCIONES':
  121. $this->preguntasOpciones($pregunta['id'], $opciones, $indice);
  122. break;
  123. case 'ABIERTA':
  124. case 'ABIERTAS':
  125. $this->preguntasAbiertas($pregunta['id'], $indice);
  126. }
  127. }
  128. private function generaPreguntas(){?>
  129. <div class="formaVoto">
  130. <form class="d-flex flex-column" id="formaVoto" method="post" action="action/cuestionario_action.php">
  131. <?php if (count($this->rubros) > 0){
  132. $cont = 1;
  133. foreach($this->rubros as $rubro) {?>
  134. <h3 class='mb-3 eval <?php echo strtolower($rubro['rubro']); ?>'>
  135. Evaluación <?php if(isset($rubro['prefijo'])){ echo $rubro['prefijo'] . ' '; } echo $rubro['rubro'];
  136. if(isset($rubro['porcentaje'])){ ?>
  137. <small>(<?php echo Proyecto::estandarizaNumeros($rubro['porcentaje']); ?>% de la calificación final)</small>
  138. <?php } ?>
  139. </h3>
  140. <section class="<?php echo strtolower($rubro['rubro']); ?>">
  141. <?php $preguntas = $this->obtenerPreguntas($rubro['id']);
  142. foreach ($preguntas as $pregunta){ ?>
  143. <div class="pregunta" data-tipo="<?php echo (int)$pregunta['obligatoria']; ?>">
  144. <div class='subtituloEval'><h5><?php echo $pregunta['pregunta']; if ($pregunta['obligatoria']) { ?><label class="text-danger errorTit" style="display:none">*</label><?php } ?></h5></div>
  145. <?php $this->tipoPregunta($pregunta, $cont);
  146. $cont++; ?>
  147. </div>
  148. <?php } ?>
  149. </section>
  150. <?php } ?>
  151. <div id="errorLblEval" style="display:none">
  152. <div class="d-flex flex-column justify-content-center align-items-center text-danger">
  153. <div class="indivisa-text-bold-italic">Es necesario contestar todas las preguntas.</div>
  154. <div>Las preguntas faltantes se encuentran marcadas en rojo.</div>
  155. </div>
  156. </div>
  157. <div class="d-flex mx-auto mt-3">
  158. <button type="submit" class="btn btn-ing btn-outline-primary arrow mx-2" id="btnVotar" name="voto" data-etapa="<?php echo $this->etapa; ?>" value=""><?php /*echo ucfirst($this->tipoDato['accion']);*/ echo 'Guardar'; ?></button>
  159. <button type="reset" class="btn btn-ing btn-outline-danger arrow mx-2" id="btnLimpiar">Cancelar</button>
  160. </div>
  161. <?php } else { ?>
  162. <div class="fondoAnuncio">
  163. <div class="d-flex flex-column justify-content-center align-items-center">
  164. <div class="text-primary text-center mt-5 tit">¡Lo sentimos!</div>
  165. <div class="text-primary text-center small m-3 msg">Por el momento no podemos mostrar la <?php echo $this->tipoDato['accion']; ?> de proyectos participantes.</div>
  166. <div><div class="ing-no-cargado mb-2"></div></div>
  167. </div>
  168. </div>
  169. <?php } ?>
  170. </form>
  171. </div>
  172. <?php }
  173. private function generaPreguntasEspeciales(){ ?>
  174. <section class="formaVoto fondoAnuncio">
  175. <div class="d-flex flex-column justify-content-center align-items-center p-4" id="formaVoto" method="post" action="action/cuestionario_action.php">
  176. <?php if (count($this->especiales) > 0){
  177. $cont = 1;
  178. foreach($this->especiales as $rubro) { ?>
  179. <?php $preguntas = $this->obtenerPreguntas($rubro['id']);
  180. foreach ($preguntas as $pregunta){ ?>
  181. <div class="pregunta" data-tipo="<?php echo (int)$pregunta['obligatoria']; ?>">
  182. <div class="text-primary text-center mb-3 msg"><?php echo $pregunta['pregunta']; if ($pregunta['obligatoria']) { ?><label class="text-danger errorTit" style="display:none">*</label><?php } ?></div>
  183. <?php $this->tipoPregunta($pregunta, $cont);
  184. $cont++; ?>
  185. </div>
  186. <?php }
  187. } ?>
  188. <div id="errorLblEval" style="display:none">
  189. <div class="d-flex flex-column justify-content-center align-items-center text-danger">
  190. <div class="indivisa-text-bold-italic">Es necesario contestar las preguntas.</div>
  191. </div>
  192. </div>
  193. <button type="submit" class="btn btn-ing btn-outline-primary arrow mx-auto mt-4" id="btnVotar" name="voto" data-etapa="<?php echo $this->etapa; ?>" value="">Votar</button>
  194. <?php } else { ?>
  195. <div class="d-flex flex-column justify-content-center align-items-center">
  196. <div class="text-primary text-center mt-5 tit">¡Lo sentimos!</div>
  197. <div class="text-primary text-center small my-3 msg">Por el momento no podemos mostrar la <?php echo $this->tipoDato['accion']; ?> de proyectos participantes.</div>
  198. <div><div class="ing-no-cargado mb-2"></div></div>
  199. </div>
  200. <?php } ?>
  201. </div>
  202. </section>
  203. <?php }
  204. function generaCuestionario(){
  205. $idasignacion = Proyecto::existeAsignacion($this->pdo, $this->usr, 0, $this->etapa); // 0 para mostrar todos los carteles
  206. if ($idasignacion > -1) {
  207. if ($idasignacion == 0)
  208. $this->generaPreguntasEspeciales();
  209. else
  210. $this->generaPreguntas();
  211. }
  212. }
  213. function estaEvaluado($proyecto){
  214. $evaluado = false;
  215. $stmt = $this->pdo->prepare("Select * from cidit_fs_existenevaluacionesxetapa(:usr,:proyecto,:etapa)");
  216. $stmt->bindParam(':usr', $this->usr);
  217. $stmt->bindParam(':proyecto', $proyecto);
  218. $stmt->bindParam(':etapa', $this->etapa);
  219. if($stmt->execute()){
  220. $evalua_rs = $stmt->fetch();
  221. $evaluado = (bool)$evalua_rs["existe"];
  222. }
  223. $stmt->closeCursor();
  224. $stmt = null;
  225. return $evaluado;
  226. }
  227. function faltantes() {
  228. $espacio = '';
  229. if (Proyecto::existeAsignacion($this->pdo, $this->usr, 0, $this->etapa) > 0) {
  230. if (strpos($_SERVER["SCRIPT_FILENAME"],'galeria'))
  231. $espacio = ' mb-3';
  232. $total = Etapa::totalFaltantes($this->pdo, $this->usr, $this->etapa);
  233. if ($total > 0){ ?>
  234. <div id="faltantes" class="<?php echo $espacio; ?>">
  235. <div class="d-flex flex-row align-items-center">
  236. <div class="ing-importante mr-2"></div>
  237. <div id="msgFaltantes" class="d-flex flex-row">
  238. <?php if ($total == 1)
  239. echo 'Sólo te falta ' . $this->tipoDato['verbo'] . ' <div class="num mx-2">1</div> proyecto.';
  240. else
  241. echo 'Te faltan <div class="num mx-2">' . $total . '</div> proyectos por ' . $this->tipoDato['verbo'] . '.'; ?>
  242. </div>
  243. </div>
  244. </div>
  245. <div class="modal fade modalMarco" id="modalAlerta">
  246. <div class="modal-dialog modal-lg modal-dialog-centered">
  247. <div class="modal-content p-3">
  248. <?php Template::agregaLoading('loaderFaltantes', 'h-100', false) ?>
  249. <div id="contenidoFaltantes" style="display:none">
  250. <div class="modal-header p-0" >
  251. <div class="d-flex flex-row align-items-center justify-content-start w-100 m-3">
  252. <div class="ing-importante text-warning display-4"></div>
  253. <div id="tituloAlerta" class="text-danger display-5 indivisa-text-bold-italic ml-3 flex-grow-1"></div>
  254. </div>
  255. <button type="button" class="cerrar" data-dismiss="modal"><div class="ing-cancelar"></div></button>
  256. </div>
  257. <div class="modal-body d-flex flex-row align-items-start justify-content-center p-0" style="display:none">
  258. <div id="listaAlerta" class="d-flex flex-column w-100 px-3 mb-3"></div>
  259. </div>
  260. </div>
  261. </div>
  262. </div>
  263. </div>
  264. <?php }
  265. }
  266. }
  267. }