xls_reprobadosIntentos.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. setlocale(LC_TIME, 'es_MX.UTF-8');
  3. require_once("../../include/nocache.php");
  4. require_once("../../include/constantes.php");
  5. require_once("../../include/bd_pdo.php");
  6. require_once("../../include/util.php");
  7. require_once("../../classes/ValidaSesion.php");
  8. require "../../include/phpSpreadsheet/autoload.php";
  9. use PhpOffice\PhpSpreadsheet\IOFactory;
  10. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  11. use PhpOffice\PhpSpreadsheet\Style\Border;
  12. use PhpOffice\PhpSpreadsheet\Style\Fill;
  13. use PhpOffice\PhpSpreadsheet\Style\Style;
  14. \PhpOffice\PhpSpreadsheet\Cell\Cell::setValueBinder( new \PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder() );
  15. function numberToLetter ($number){
  16. $temp = ($number-1) % 26;
  17. return chr($temp + 65);
  18. };
  19. //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
  20. $objSesion = new ValidaSesion($pdo, 125, GEMA);
  21. if(!$objSesion->tieneAcceso()){
  22. echo "No tienes permiso de ver esta página. Revisa que tu sesión siga activa.";
  23. exit();
  24. }
  25. unset($objValida);
  26. if(isset($_POST["plan"], $_POST["intentos"], $_POST["prefijo"]) ) {
  27. $filter_plan = filter_input(INPUT_POST, "plan", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  28. $filter_generacion = fechaGuion(trim(filter_input(INPUT_POST, "generacion", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
  29. $filter_intentos = filter_input(INPUT_POST, "intentos", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  30. $nom = trim(filter_input(INPUT_POST, "prefijo", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  31. }else{
  32. echo "No se recibieron los datos.";
  33. exit();
  34. }
  35. $query = "";
  36. if($filter_plan != 0){
  37. $query .= ":plan,";
  38. }else
  39. $query .= "NULL,";
  40. if($filter_generacion != ""){
  41. $query .= ":generacion,";
  42. }else
  43. $query .= "NULL,";
  44. $stmt = $pdo->prepare('Select * from fs_materiasintentos('.$query.' :intentos)');
  45. $stmt->bindParam(":intentos", $filter_intentos);
  46. if($filter_plan != 0){ $stmt->bindParam(":plan", $filter_plan); }
  47. if($filter_generacion != ""){ $stmt->bindParam(":generacion", $filter_generacion); }
  48. if(!$stmt->execute()){
  49. echo "Ocurrió un error al cargar los cambios de carrera.";
  50. //print_r($stmt->errorInfo());
  51. exit();
  52. }else{
  53. $intentos_rs = $stmt->fetchAll();
  54. /*$intentosArr = array();
  55. $last = -1;
  56. $matriasArr = array();
  57. $i = 0;
  58. $total = 0;
  59. foreach($intentos_rs as $intento){
  60. if($last != $intento["Usuario_claveULSA"]){
  61. if($last != -1){
  62. $intentosArr[$i]["materiaArr"]=$materiasArr;
  63. $intentosArr[$i]["total"] = $total;
  64. $i++;
  65. $total = 0;
  66. }
  67. $last = $intento["Usuario_claveULSA"];
  68. $materiasArr = array();
  69. }
  70. $intentosArr[$i] = array("id" => $intento["Usuario_claveULSA"], "nombre" =>$intento["Usuario_apellidos"]." ".$intento["Usuario_nombre"], "carrera"=>$intento["Carrera_desc"]." ".$intento["PlanEstudio_desc"],
  71. "fecha"=>$intento["Alumno_fecha_ingreso"], "total"=>0, "materiaArr"=>array());
  72. $materiasArr[] = array("id" => $intento["Materia_id"], "desc" =>$intento["Materia_desc"], "total"=>$intento["Intentos_total"]);
  73. $total+= $intento["Intentos_total"];
  74. }
  75. if($last != -1){
  76. $intentosArr[$i]["materiaArr"]=$materiasArr;
  77. $intentosArr[$i]["total"] = $total;
  78. }
  79. unset($i);*/
  80. }
  81. $stmt->closeCursor();
  82. //--------
  83. //
  84. // Create new Spreadsheet object
  85. $spreadsheet = new Spreadsheet();
  86. // Set document properties
  87. $spreadsheet->getProperties()->setCreator('Ingeniería La Salle')
  88. ->setLastModifiedBy('Ingeniería La Salle')
  89. ->setTitle('Oportunidades de aprobación')
  90. ->setDescription('Oportunidades para aprobar una materia.');
  91. $headerStyle = new Style();
  92. $headerStyle->applyFromArray(
  93. [
  94. 'fill' => [
  95. 'fillType' => Fill::FILL_SOLID,
  96. 'color' => ['argb' => 'FF001d68'],
  97. ],
  98. 'borders' => [
  99. 'bottom' => ['borderStyle' => Border::BORDER_THIN],
  100. 'right' => ['borderStyle' => Border::BORDER_MEDIUM],
  101. ],
  102. 'font' => [
  103. 'bold' => true,
  104. 'color' => ['argb' => 'FFFFFFFF'],
  105. ]
  106. ]
  107. );
  108. //--------
  109. $sheet = 0;
  110. // Rename worksheet
  111. $spreadsheet->getActiveSheet()->setTitle('Oportunidades');
  112. $row = 1;
  113. $col = 1;
  114. $spreadsheet->setActiveSheetIndex($sheet)
  115. ->setCellValueByColumnAndRow($col++, 1, "Clave")
  116. ->setCellValueByColumnAndRow($col++, 1, "Nombre")
  117. ->setCellValueByColumnAndRow($col++, 1, "Carrera")
  118. ->setCellValueByColumnAndRow($col++, 1, "Generación")
  119. ->setCellValueByColumnAndRow($col++, 1, "Materia no acreditadas")
  120. ->setCellValueByColumnAndRow($col++, 1, "Veces no acreditada");
  121. $colMax = $col;
  122. $colLetter = numberToLetter($colMax-1);
  123. $spreadsheet->getActiveSheet()->duplicateStyle($headerStyle, 'A1:'.$colLetter.'1');
  124. $row = 2;
  125. foreach($intentos_rs as $intento){
  126. $col = 1;
  127. $spreadsheet->setActiveSheetIndex($sheet)
  128. ->setCellValueByColumnAndRow($col++, $row, $intento["Usuario_claveULSA"])
  129. ->setCellValueByColumnAndRow($col++, $row, $intento["Usuario_apellidos"]." ".$intento["Usuario_nombre"])
  130. ->setCellValueByColumnAndRow($col++, $row, $intento["Carrera_desc"]." ".$intento["PlanEstudio_desc"])
  131. ->setCellValueByColumnAndRow($col++, $row, $intento["Alumno_generacion"])
  132. ->setCellValueByColumnAndRow($col++, $row, $intento["Materia_desc"])
  133. ->setCellValueByColumnAndRow($col, $row, $intento["Intentos_total"]);
  134. $colLetter = numberToLetter(4);
  135. $spreadsheet->setActiveSheetIndex($sheet)->getStyle($colLetter.$row)->getNumberFormat()
  136. ->setFormatCode('dd/mm/yyyy');
  137. $row++;
  138. }
  139. //Auto ajustar anchos
  140. for($col = 1; $col < $colMax; $col++)
  141. $spreadsheet->getActiveSheet()->getColumnDimension(numberToLetter($col))->setAutoSize(true);
  142. //$spreadsheet->getActiveSheet()->getStyle('A1:H1')->getFont()->setBold(true);
  143. $spreadsheet->getActiveSheet()->setAutoFilter($spreadsheet->getActiveSheet()->calculateWorksheetDimension());
  144. //---------
  145. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  146. $spreadsheet->setActiveSheetIndex(0);
  147. // Redirect output to a client’s web browser (Xlsx)
  148. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  149. header('Content-Disposition: attachment;filename="reprobadosIntentos'.$nom.'.xlsx"');
  150. header('Cache-Control: max-age=0');
  151. // If you're serving to IE 9, then the following may be needed
  152. header('Cache-Control: max-age=1');
  153. // If you're serving to IE over SSL, then the following may be needed
  154. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  155. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
  156. header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  157. header('Pragma: public'); // HTTP/1.0
  158. $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
  159. $writer->save('php://output');
  160. exit;