reporte_cambioestado.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <?php
  2. require_once("../include/constantes.php");
  3. require_once("../include/bd_pdo.php");
  4. require_once("../classes/ValidaSesion.php");
  5. require_once("../classes/MainMenu.php");
  6. require_once("../include/util.php");
  7. require_once("./include/charts_util.php");
  8. $menu = 12;
  9. $submenu = 121;
  10. //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
  11. $objSesion = new ValidaSesion($pdo, $submenu, GEMA);
  12. if(!$objSesion->tieneAcceso()){
  13. $objSesion->terminaSesion();
  14. }
  15. $objSesion->validaPeriodoUsuario();//si no tiene periodo manda a main
  16. ?>
  17. <!DOCTYPE html>
  18. <html lang="es" prefix="og: http://ogp.me/ns#">
  19. <head>
  20. <title>GEMA - Facultad de Ingeniería</title>
  21. <meta charset="utf-8">
  22. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  23. <link rel="icon" type="image/png" href="../img/favicon.png" />
  24. <link rel="stylesheet" href="../css/bootstrap-ulsa.min.css" type="text/css">
  25. <link rel="stylesheet" href="../css/indivisa.css" type="text/css">
  26. <link rel="stylesheet" href="../css/sgi.css?rand=<?php echo rand();?>" type="text/css">
  27. <link rel="stylesheet" href="../css/fa_all.css" type="text/css">
  28. <link rel="stylesheet" href="../css/jquery-ui.css" type="text/css">
  29. <link rel="stylesheet" href="../css/calendar.css" type="text/css">
  30. <style>
  31. .text-donut{position: absolute; top:50%; margin-top: 6px; z-index:1; padding-bottom:0; left:50%; transform: translateX(-50%); -ms-transform: translateX(-50%);-webkit-transform:translateX(-50%); font-size:45px; line-height:55px}
  32. </style>
  33. </head>
  34. <body>
  35. <div>
  36. <?php
  37. //--- Objeto que pinta menu
  38. $menuObj = new MainMenu($_SESSION["usuario_id"], $menu, $pdo, GEMA, "Cambios de estado de alumnos");//usr, menu, pdo, sist
  39. $menuObj->printMenu();
  40. if($_SESSION["periodo_id"] != ""){
  41. //Plan de estudios
  42. $stmt = $pdo->prepare('Select * from fs_planestudio_alumnos(:nivel, NULL, true)');
  43. $stmt->bindParam(":nivel", $_SESSION["nivel_id"]);
  44. if(!$stmt->execute()){
  45. $errorDesc = "Ocurrió un error al cargar los planes de estudio";
  46. }else{
  47. $plan_rs = $stmt->fetchAll();
  48. }
  49. $stmt->closeCursor();
  50. $filter_periodo = $_SESSION["periodo_id"];
  51. $query = "";
  52. if(isset($_POST["plan"]) && $_POST["plan"] != 0 && $_POST["plan"] != ""){
  53. //$filter_plan = $_POST["plan"];
  54. $filter_plan = filter_input(INPUT_POST, "plan", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  55. $query = ":plan, ";
  56. }else
  57. $query = "NULL, ";
  58. $prefijo = "";
  59. $nivel = "";
  60. foreach($plan_rs as $plan){
  61. if($nivel == "")
  62. $nivel = $plan["Nivel_desc"];
  63. if(isset($filter_plan) && $plan["PlanEstudio_id"] == $filter_plan)
  64. $prefijo = $plan["Carrera_prefijo"];
  65. break;
  66. }
  67. //busca datos del periodo
  68. $stmt = $pdo->prepare('Select * from fs_periodo(:periodo, NULL, NULL, NULL)');
  69. $stmt->bindParam(":periodo", $filter_periodo);
  70. if(!$stmt->execute()){
  71. $errorDesc = "Ocurrió un error al obtener las fechas del periodo";
  72. //print_r($stmt->errorInfo());
  73. }else{
  74. $periodo_rs = $stmt->fetch();
  75. //Obtiene total de cambios de estado
  76. if(isset($_POST["fecha_inicial"]) && $_POST["fecha_inicial"]!=""){
  77. $filter_fini = fechaGuion(trim(filter_input(INPUT_POST, "fecha_inicial", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
  78. }else{
  79. $filter_fini = $periodo_rs["Periodo_fecha_inicial"];
  80. }
  81. $query.= ':fini, ';
  82. if(isset($_POST["fecha_final"]) && $_POST["fecha_final"]!=""){
  83. $filter_ffin = fechaGuion(trim(filter_input(INPUT_POST, "fecha_final", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
  84. }else{
  85. $filter_ffin = $periodo_rs["Periodo_fecha_final"];
  86. }
  87. $query.= ':ffin, ';
  88. if(isset($_POST["revalida"]) && $_POST["revalida"] == 1){
  89. $filter_revalida = 1;
  90. $query .= "true";
  91. }else{
  92. $filter_revalida = 0;
  93. $query .= "false";
  94. }
  95. $stmt = $pdo->prepare('Select * from fs_estadoalumno_cambios(:nivel, '.$query.')');//sólo no revalidadas
  96. $stmt->bindParam(":nivel", $_SESSION["nivel_id"]);
  97. $stmt->bindParam(":fini", $filter_fini);
  98. $stmt->bindParam(":ffin", $filter_ffin);
  99. if(isset($filter_plan)) $stmt->bindParam(":plan", $filter_plan);
  100. if(!$stmt->execute()){
  101. $errorDesc = "Ocurrió un error al cargar el total de estados.";
  102. //print_r($stmt->errorInfo());
  103. }else{
  104. $estado_rs = $stmt->fetchAll();
  105. $estadoArr = array();
  106. $estado_last = -1;
  107. $subestadoArr = array();
  108. $e = 0;
  109. $total = 0;
  110. foreach($estado_rs as $estado){
  111. if($estado_last != $estado["EstadoAlumno_id"]){
  112. if($estado_last != -1){
  113. $estadoArr[$e]["subestadoArr"]=$subestadoArr;
  114. $estadoArr[$e]["total"] = $total;
  115. $e++;
  116. $total = 0;
  117. }
  118. $estado_last = $estado["EstadoAlumno_id"];
  119. $subestadoArr = array();
  120. }
  121. $estadoArr[$e] = array("id" => $estado["EstadoAlumno_id"], "desc" =>$estado["EstadoAlumno_desc"], "color"=>$estado["EstadoAlumno_color"], "total"=>0, "subestadoArr"=>array());
  122. $subestadoArr[] = array("id" => $estado["SubEstadoAlumno_id"], "desc" =>$estado["SubEstadoAlumno_desc"], "color"=>$estado["SubEstadoAlumno_color"], "total"=>$estado["SubEstadoAlumno_total"]);
  123. $total+= $estado["SubEstadoAlumno_total"];
  124. }
  125. if($estado_last != -1){
  126. $estadoArr[$e]["subestadoArr"]=$subestadoArr;
  127. $estadoArr[$e]["total"] = $total;
  128. }
  129. unset($e);
  130. }
  131. $stmt->closeCursor();
  132. }
  133. }//hay periodo seleccionado
  134. ?>
  135. <main class="container-fluid content marco">
  136. <?php include_once("../include/errorMessage.php"); ?>
  137. <?php include("../include/periodoCambio.php");?>
  138. <?php if($_SESSION["periodo_id"] != ""){ ?>
  139. <!-- Filtro -->
  140. <div class="row">
  141. <div class="col-12">
  142. <form action="#" method="post">
  143. <div class="form-box form-box-info">
  144. <div class="form-group row">
  145. <label for="plan-nueva" class="col-4 col-form-label">Programa académico</label>
  146. <div class="col-8 col-sm-4">
  147. <div class="datalist datalist-select mb-1 w-100">
  148. <div class="datalist-input">Todos en <?php echo $nivel;?></div>
  149. <span class="ing-buscar icono"></span>
  150. <ul style="display:none">
  151. <li data-id="0">Todos en <?php echo $nivel;?></li>
  152. <?php foreach($plan_rs as $plan) { ?>
  153. <li data-id="<?php echo $plan["PlanEstudio_id"];?>" <?php if(isset($filter_plan) && $filter_plan==$plan["PlanEstudio_id"]){ echo 'class="selected"'; }?>><?php echo $plan["Carrera_desc"]." ".$plan["PlanEstudio_desc"];?></li>
  154. <?php }?>
  155. </ul>
  156. <input type="hidden" id="plan-nueva" name="plan" value="">
  157. </div>
  158. </div>
  159. </div>
  160. <div class="form-group row">
  161. <label for="fecha_inicial" class="col-4 col-form-label">Fecha Inicial de cambio</label>
  162. <div class="col-8 col-sm-4">
  163. <input id="fecha_inicial" name="fecha_inicial" type="text" class="form-control date-picker" placeholder="dd/mm/aaaa" maxlength="10" readonly="readonly" required="required" value="<?php if(isset($filter_fini)){ echo fechaSlash($filter_fini);}?>">
  164. <div class="invalid-feedback">No es una fecha válida.</div>
  165. </div>
  166. </div>
  167. <div class="form-group row">
  168. <label for="fecha_final" class="col-4 col-form-label">Fecha Final de cambio</label>
  169. <div class="col-8 col-sm-4">
  170. <input id="fecha_final" name="fecha_final" type="text" class="form-control date-picker" placeholder="dd/mm/aaaa" maxlength="10" readonly="readonly" required="required" value="<?php if(isset($filter_ffin)){ echo fechaSlash($filter_ffin);}?>">
  171. <div class="invalid-feedback">No es una fecha válida.</div>
  172. </div>
  173. </div>
  174. <div class="form-group row align-items-center">
  175. <label class="col-4 col-form-label">¿Incluir con revalidación?</label>
  176. <div class="col-8 col-sm-4">
  177. <div class="row">
  178. <div class="col-6 col-sm-4 text-center">
  179. <div class="form-check form-check-inline">
  180. <input class="form-check-input radio-lg revalida" type="radio" id="revalida_no" name="revalida" value="0" <?php if(!isset($filter_revalida) || (isset($filter_revalida) && intval($filter_revalida) == 0) ){ echo 'checked="checked"'; }?>>
  181. <label for="revalida_no" class="col-form-label">No</label>
  182. </div>
  183. </div>
  184. <div class="col-6 col-sm-4 text-center">
  185. <div class="form-check form-check-inline">
  186. <input class="form-check-input radio-lg revalida" type="radio" id="revalida_si" name="revalida" value="1" <?php if(isset($filter_revalida) && intval($filter_revalida) == 1 ){ echo 'checked="checked"'; }?>>
  187. <label for="revalida_si" class="col-form-label">Sí</label>
  188. </div>
  189. </div>
  190. </div>
  191. </div>
  192. </div>
  193. </div>
  194. <div class="form-group row mt-4">
  195. <div class="col-12 text-center">
  196. <button type="submit" class="btn btn-outline-primary"><?php echo $ICO["buscar"]; ?> Filtrar</button>
  197. <!--<button type="button" class="btn btn-outline-danger btn-reset"><?php echo $ICO["borrar"]?> Limpiar</button>!-->
  198. </div>
  199. </div>
  200. </form>
  201. </div>
  202. </div>
  203. <!-- end Filtro -->
  204. <?php } ?>
  205. <?php if(count($estadoArr) > 0){ ?>
  206. <form action="./export/xls_estados.php" target="_blank" method="post">
  207. <input type="hidden" name="plan" value="<?php echo isset($filter_plan)?$filter_plan:0;?>">
  208. <input type="hidden" name="fini" value="<?php echo $filter_fini;?>">
  209. <input type="hidden" name="ffin" value="<?php echo $filter_ffin;?>">
  210. <input type="hidden" name="prefijo" value="<?php echo ($prefijo!="")?$prefijo:$nivel;?>">
  211. <input type="hidden" name="revalida" value="<?php echo $filter_revalida;?>">
  212. <p class="pb-4"><button type="submit" class="btn btn-outline-secondary float-right"><?php echo $ICO["descargar"];?> Descargar datos</button></p>
  213. </form>
  214. <!-- Graficas -->
  215. <div class="row justify-content-center">
  216. <?php foreach($estadoArr as $estado){?>
  217. <div class="col-6 mb-5">
  218. <div class="card">
  219. <div class="card-header font-weight-bold" style="color:<?php echo $estado["color"];?>">
  220. <?php echo $ICO_LG["circulo"]; ?> <?php echo $estado["desc"];?>
  221. </div>
  222. <div class="card-body">
  223. <div>
  224. <canvas id="graficaEstado<?php echo $estado["id"];?>" height="500"></canvas>
  225. </div>
  226. <span class="text-donut">0</span>
  227. </div>
  228. </div>
  229. </div>
  230. <?php }//foreach ?>
  231. </div>
  232. <?php }else{ ?>
  233. <p class="text-center text-danger">No hay alumnos para el programa y/o periodo especificados.</p>
  234. <?php } ?>
  235. </main>
  236. <!--- FOOTER--->
  237. <?php require_once("../include/footer.php"); ?>
  238. </div>
  239. <script src="../js/jquery.min.js"></script>
  240. <script src="../js/jquery-ui.js"></script>
  241. <script src="../js/datepicker-es.js"></script>
  242. <script src="../js/bootstrap/popper.min.js"></script>
  243. <script src="../js/bootstrap/bootstrap.min.js"></script>
  244. <script src="../js/sidebarmenu.js"></script>
  245. <script src="../js/chart.min.js"></script>
  246. <script src="../js/chartjs-plugin-datalabels.min.js"></script>
  247. <script src="../js/datalist.js"></script>
  248. <script>
  249. <?php if(count($estadoArr) > 0){ ?>
  250. var options = {
  251. tooltips: false,
  252. cutoutPercentage:25,
  253. maintainAspectRatio: false,
  254. padding: 64,
  255. plugins: {
  256. datalabels: {
  257. color: 'white',
  258. anchor: 'center',
  259. }
  260. },
  261. };
  262. function draw_grafica(){
  263. <?php foreach($estadoArr as $estado){?>
  264. new Chart($("#graficaEstado<?php echo $estado["id"];?>"), {
  265. type: 'doughnut',
  266. data: {
  267. labels: [
  268. <?php
  269. foreach($estado["subestadoArr"] as $subedo){
  270. echo '"'.$subedo["desc"].'", ';
  271. }?>
  272. ],
  273. datasets: [{
  274. data: [
  275. <?php
  276. foreach($estado["subestadoArr"] as $subedo){
  277. $data = $subedo["total"];
  278. echo $data.", ";
  279. }
  280. ?>
  281. ],
  282. backgroundColor: [<?php
  283. foreach($estado["subestadoArr"] as $subedo){
  284. echo '"'.$subedo["color"].'", ';
  285. }?>
  286. ],
  287. borderColor: "white",
  288. borderWidth: 2,
  289. datalabels: {
  290. labels: {
  291. name: {
  292. align: 'top',
  293. borderWidth: 0,
  294. font: {size: 12},
  295. formatter: function(value, ctx) {
  296. let datasets = ctx.chart.data.datasets;
  297. if (datasets.indexOf(ctx.dataset) === datasets.length - 1) {
  298. let sum = datasets[0].data.reduce((a, b) => a + b, 0);
  299. let percentage = Math.round((value / sum) * 100) + '%';
  300. return percentage;
  301. } else {
  302. return percentage;
  303. }
  304. },
  305. offset:0
  306. },
  307. value: {
  308. align: 'bottom',
  309. backgroundColor: 'white',
  310. borderColor: 'white',
  311. borderWidth: 2,
  312. borderRadius: 4,
  313. font: {size: 14, weight: 'bold'},
  314. /*color: function(ctx) {
  315. return ctx.dataset.backgroundColor;
  316. },*/
  317. color: "black",
  318. padding:{left: 6,right: 6,top: 2,bottom: 2},
  319. offset:0
  320. }
  321. }
  322. }
  323. }]//datasets
  324. },
  325. options: options
  326. });
  327. $("#graficaEstado<?php echo $estado["id"];?>").parents('.card-body').find('.text-donut').html("<?php echo $estado["total"];?>");
  328. <?php }//multiples graficas ?>
  329. }
  330. <?php }?>
  331. $(document).ready(function(){
  332. <?php if(count($estadoArr) > 0){ ?>
  333. draw_grafica();
  334. <?php } ?>
  335. setDatalist("#periodo", <?php echo $_SESSION["periodo_id"]; ?>);
  336. $(document).on('click', '#dlPeriodo ul li' ,function(){
  337. $("#formaPeriodo").submit();
  338. });
  339. $(".date-picker" ).datepicker({ dateFormat: "dd/mm/yy", changeMonth: true, changeYear: true});
  340. $(".date-picker" ).datepicker( $.datepicker.regional[ "es" ] );
  341. });
  342. </script>
  343. </body>
  344. </html>