xls_alumnos_old.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. use PhpOffice\PhpSpreadsheet\Shared\Date;
  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, 127, 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["fecha_corte"])){
  27. echo "No hay fechas de corte seleccionadas.";
  28. exit();
  29. }
  30. $fechasCorteArr = $_POST["fecha_corte"];
  31. //--------
  32. //
  33. // Create new Spreadsheet object
  34. $spreadsheet = new Spreadsheet();
  35. // Set document properties
  36. $spreadsheet->getProperties()->setCreator('Ingeniería La Salle')
  37. ->setLastModifiedBy('Ingeniería La Salle')
  38. ->setTitle('Estado de Alumnos')
  39. ->setDescription('Estado actual de alumnos.');
  40. $headerStyle = new Style();
  41. $headerStyle->applyFromArray(
  42. [
  43. 'fill' => [
  44. 'fillType' => Fill::FILL_SOLID,
  45. 'color' => ['argb' => 'FF001d68'],
  46. ],
  47. 'borders' => [
  48. 'bottom' => ['borderStyle' => Border::BORDER_THIN],
  49. 'right' => ['borderStyle' => Border::BORDER_MEDIUM],
  50. ],
  51. 'font' => [
  52. 'bold' => true,
  53. 'color' => ['argb' => 'FFFFFFFF'],
  54. ]
  55. ]
  56. );
  57. //--------
  58. $sheet = 0;
  59. // Rename worksheet
  60. $spreadsheet->getActiveSheet()->setTitle('Alumnos');
  61. foreach ($fechasCorteArr as $fecha_hoy){
  62. $query = "";
  63. if(isset($_POST["fecha_inicial"]) && $_POST["fecha_inicial"] !=""){
  64. $filter_fini = fechaGuion(trim(filter_input(INPUT_POST, "fecha_inicial", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
  65. $query .= ":fini, ";
  66. }else{
  67. $query .= "NULL, ";
  68. }
  69. if(isset($_POST["fecha_final"]) && $_POST["fecha_final"] !="") {
  70. $filter_ffin = fechaGuion(trim(filter_input(INPUT_POST, "fecha_final", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
  71. $query .= ":ffin, ";
  72. }else{
  73. $query .= "NULL, ";
  74. }
  75. if(isset($_POST["fecha_hoy"]) && $_POST["fecha_hoy"] !="") {
  76. $filter_fhoy = fechaGuion(trim(filter_input(INPUT_POST, "fecha_hoy", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
  77. }
  78. $query .= ":fhoy, ";
  79. if(isset($_POST["estado"]) && $_POST["estado"] !=""){
  80. $filter_estado = filter_input(INPUT_POST, "estado", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  81. $query .= ":edo, ";
  82. }else{
  83. $query .= "NULL, ";
  84. }
  85. if(isset($_POST["carrera"]) && $_POST["carrera"] !="" ){
  86. $filter_carrera = filter_input(INPUT_POST, "carrera", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  87. $query .= ":carrera, ";
  88. }else{
  89. $query .= "NULL, ";
  90. }
  91. $query .= "0, NULL";
  92. $stmt = $pdo->prepare('Select * from fs_alumnosestado('.$query.')');//sólo activos
  93. if(isset($filter_fini)) $stmt->bindParam(":fini", $filter_fini);
  94. if(isset($filter_ffin)) $stmt->bindParam(":ffin", $filter_ffin);
  95. if(isset($filter_estado)) $stmt->bindParam(":edo", $filter_estado);
  96. if(isset($filter_carrera)) $stmt->bindParam(":carrera", $filter_carrera);
  97. $stmt->bindParam(":fhoy", $filter_fhoy);
  98. if(!$stmt->execute()){
  99. echo "Ocurrió un error al cargar los alumnos.";
  100. //print_r($stmt->errorInfo());
  101. exit();
  102. }
  103. $alumno_rs = $stmt->fetchAll();
  104. $stmt->closeCursor();
  105. $row = 1;
  106. $col = 1;
  107. $spreadsheet->setActiveSheetIndex($sheet)
  108. ->setCellValueByColumnAndRow($col++, 1, "Estado")
  109. ->setCellValueByColumnAndRow($col++, 1, "Subestado")
  110. ->setCellValueByColumnAndRow($col++, 1, "Fecha estado")
  111. ->setCellValueByColumnAndRow($col++, 1, "Clave")
  112. ->setCellValueByColumnAndRow($col++, 1, "Apellidos")
  113. ->setCellValueByColumnAndRow($col++, 1, "Nombre")
  114. ->setCellValueByColumnAndRow($col++, 1, "CURP")
  115. ->setCellValueByColumnAndRow($col++, 1, "Correo")
  116. ->setCellValueByColumnAndRow($col++, 1, "Carrera")
  117. ->setCellValueByColumnAndRow($col++, 1, "Plan")
  118. ->setCellValueByColumnAndRow($col++, 1, "Generación");
  119. $colMax = $col;
  120. $colLetter = numberToLetter($colMax-1);
  121. $spreadsheet->getActiveSheet()->duplicateStyle($headerStyle, 'A1:'.$colLetter.'1');
  122. $row = 2;
  123. foreach($alumno_rs as $alumno){
  124. $col = 1;
  125. $spreadsheet->setActiveSheetIndex($sheet)
  126. ->setCellValueByColumnAndRow($col++, $row, $alumno["EstadoAlumno_desc"])
  127. ->setCellValueByColumnAndRow($col++, $row, $alumno["SubEstadoAlumno_desc"])
  128. ->setCellValueByColumnAndRow($col++, $row, fechaSlash($alumno["SEA_fecha"]))
  129. ->setCellValueByColumnAndRow($col++, $row, $alumno["Usuario_claveULSA"])
  130. ->setCellValueByColumnAndRow($col++, $row, $alumno["Usuario_apellidos"])
  131. ->setCellValueByColumnAndRow($col++, $row, $alumno["Usuario_nombre"])
  132. ->setCellValueByColumnAndRow($col++, $row, $alumno["Usuario_curp"])
  133. ->setCellValueByColumnAndRow($col++, $row, $alumno["Contacto_correo"])
  134. ->setCellValueByColumnAndRow($col++, $row, $alumno["Carrera_desc"])
  135. ->setCellValueByColumnAndRow($col++, $row, $alumno["PlanEstudio_desc"])
  136. //->setCellValueByColumnAndRow($col++, $row, fechaSlash($alumno["Alumno_generacion"]));
  137. ->setCellValueByColumnAndRow($col++, $row, fechaMonthPicker($alumno["Alumno_generacion"]));
  138. /*$colLetter = numberToLetter($col-1);
  139. $spreadsheet->setActiveSheetIndex($sheet)->getStyle($colLetter.$row.':'.$colLetter.$row)->getNumberFormat()
  140. ->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DDMMYYYY);*/
  141. $colLetter = numberToLetter(3);
  142. $spreadsheet->setActiveSheetIndex($sheet)->getStyle($colLetter.$row.':'.$colLetter.$row)->getNumberFormat()
  143. ->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DDMMYYYY);
  144. $row++;
  145. }
  146. //Auto ajustar anchos
  147. for($col = 1; $col < $colMax; $col++)
  148. $spreadsheet->getActiveSheet()->getColumnDimension(numberToLetter($col))->setAutoSize(true);
  149. //$spreadsheet->getActiveSheet()->getStyle('A1:H1')->getFont()->setBold(true);
  150. $spreadsheet->getActiveSheet()->setAutoFilter($spreadsheet->getActiveSheet()->calculateWorksheetDimension());
  151. }
  152. //---------
  153. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  154. $spreadsheet->setActiveSheetIndex(0);
  155. // Redirect output to a client’s web browser (Xlsx)
  156. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  157. header('Content-Disposition: attachment;filename="alumnos.xlsx"');
  158. header('Cache-Control: max-age=0');
  159. // If you're serving to IE 9, then the following may be needed
  160. header('Cache-Control: max-age=1');
  161. // If you're serving to IE over SSL, then the following may be needed
  162. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  163. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
  164. header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  165. header('Pragma: public'); // HTTP/1.0
  166. $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
  167. $writer->save('php://output');
  168. exit;