123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- <?php
- setlocale(LC_TIME, 'es_MX.UTF-8');
- require_once("../../include/nocache.php");
- require_once("../../include/constantes.php");
- require_once("../../include/bd_pdo.php");
- require_once("../../include/util.php");
- require_once("../../classes/ValidaSesion.php");
- require "../../include/phpSpreadsheet/autoload.php";
- use PhpOffice\PhpSpreadsheet\IOFactory;
- use PhpOffice\PhpSpreadsheet\Spreadsheet;
- use PhpOffice\PhpSpreadsheet\Style\Border;
- use PhpOffice\PhpSpreadsheet\Style\Fill;
- use PhpOffice\PhpSpreadsheet\Style\Style;
- use PhpOffice\PhpSpreadsheet\Shared\Date;
- function numberToLetter ($number){
- $temp = ($number-1) % 26;
- return chr($temp + 65);
- };
- //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
- $objSesion = new ValidaSesion($pdo, 331, GEMA);
- if(!$objSesion->tieneAcceso()){
- echo "No tienes permiso de ver esta página. Revisa que tu sesión siga activa.";
- exit();
- }
- unset($objValida);
- if(!isset($_POST["generacion"], $_POST["carrera"])){
- echo "No se recibieron los datos necesarios.";
- exit();
- }
- $filter_carrera = filter_input(INPUT_POST, "carrera", FILTER_SANITIZE_NUMBER_INT);//limpia texto
- //$filter_gen = fechaGuion(trim(filter_input(INPUT_POST, "generacion", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
- $prefijo = (trim(filter_input(INPUT_POST, "prefijo", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
- $query = "NULL, NULL, NULL, :carr, NULL, ";
- if(isset($_POST["estado"]) && $_POST["estado"]!=""){
- $query .= ":edo, ";
- $filter_estado = filter_input(INPUT_POST, "estado", FILTER_SANITIZE_NUMBER_INT);//limpia texto
- }else{
- $query .= "NULL, ";
- }
- $query .= "0, NULL";
- $stmt = $pdo->prepare('Select * from fs_alumnobusca_carrera('.$query.') ORDER BY "Usuario_apellidos", "Usuario_nombre", "PlanEstudio_desc"');
- $stmt->bindParam(":carr", $filter_carrera);
- //$stmt->bindParam(":gen", $filter_gen);
- if(isset($filter_estado)) $stmt->bindParam(":edo", $filter_estado);
- if(!$stmt->execute()){
- $errorDesc = "Ocurrió un error al cargar los alumnos.";
- //print_r($stmt->errorInfo());
- }else{
- $alumnos_rs = $stmt->fetchAll();
- }
- $stmt->closeCursor();
- $stmt = null;
- //--------
- //
- // Create new Spreadsheet object
- $spreadsheet = new Spreadsheet();
- // Set document properties
- $spreadsheet->getProperties()->setCreator('Ingeniería La Salle')
- ->setLastModifiedBy('Ingeniería La Salle')
- ->setTitle('Alumnos por carrera')
- ->setDescription('Alumnos por carrera por generación.');
- $headerStyle = new Style();
- $headerStyle->applyFromArray(
- [
- 'fill' => [
- 'fillType' => Fill::FILL_SOLID,
- 'color' => ['argb' => 'FF001d68'],
- ],
- 'borders' => [
- 'bottom' => ['borderStyle' => Border::BORDER_THIN],
- 'right' => ['borderStyle' => Border::BORDER_MEDIUM],
- ],
- 'font' => [
- 'bold' => true,
- 'color' => ['argb' => 'FFFFFFFF'],
- ]
- ]
- );
- $titleStyle = new Style();
- $titleStyle->applyFromArray(
- [
- 'font' => [
- 'bold' => true,
- 'size' => 14,
- ]
- ]
- );
- //--------
- $sheet = 0;
- $spreadsheet->setActiveSheetIndex($sheet)->setTitle('Alumnos '.$prefijo);
- $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow(1, 1, "Alumnos ".$prefijo);
- $spreadsheet->getActiveSheet()->mergeCells('A1:D1');
- $spreadsheet->getActiveSheet()->duplicateStyle($titleStyle, 'A1:D1');
- $row = 3;
- $col = 1;
- $spreadsheet->getActiveSheet()
- ->setCellValueByColumnAndRow($col++, $row, "Estado")
- ->setCellValueByColumnAndRow($col++, $row, "Subestado")
- ->setCellValueByColumnAndRow($col++, $row, "Clave")
- ->setCellValueByColumnAndRow($col++, $row, "Apellidos")
- ->setCellValueByColumnAndRow($col++, $row, "Nombre")
- ->setCellValueByColumnAndRow($col++, $row, "Generación")
- ->setCellValueByColumnAndRow($col++, $row, "CURP")
- ->setCellValueByColumnAndRow($col++, $row, "Correo")
- ->setCellValueByColumnAndRow($col++, $row, "Carrera")
- ->setCellValueByColumnAndRow($col++, $row, "Plan");
- $colMax = $col;
- $colLetter = numberToLetter($colMax-1);
- $spreadsheet->getActiveSheet()->duplicateStyle($headerStyle, 'A'.$row.':'.$colLetter.$row);
- $row++;
- $startRow = $row;
- foreach($alumnos_rs as $alumno){
- $col = 1;
- //$spreadsheet->setActiveSheetIndex($sheet)
- $correo = "";
- $stmt = $pdo->prepare('SELECT "Contacto_valor" from fs_contacto(:id, 3, NULL) WHERE "Contacto_valor" ILIKE \'%\' || \'lasallistas.org.mx\'');
- $stmt->bindParam(":id", $alumno["Usuario_id"]);
- if($stmt->execute()){
- $contacto_rs = $stmt->fetch();
- $correo = $contacto_rs["Contacto_valor"];
- }
- $stmt->closeCursor();
- if($correo == ""){
- $stmt = $pdo->prepare('SELECT "Contacto_valor" from fs_contacto(:id, 3, NULL) WHERE "Contacto_valor" NOT ILIKE \'%\' || \'lasallistas.org.mx\'');
- $stmt->bindParam(":id", $alumno["Usuario_id"]);
- if($stmt->execute()){
- $contacto_rs = $stmt->fetch();
- $correo = $contacto_rs["Contacto_valor"];
- }
- $stmt->closeCursor();
- }
- $spreadsheet->getActiveSheet()
- ->setCellValueByColumnAndRow($col++, $row, $alumno["EstadoAlumno_desc"])
- ->setCellValueByColumnAndRow($col++, $row, $alumno["SubEstadoAlumno_desc"])
- ->setCellValueByColumnAndRow($col++, $row, $alumno["Usuario_claveULSA"])
- ->setCellValueByColumnAndRow($col++, $row, $alumno["Usuario_apellidos"])
- ->setCellValueByColumnAndRow($col++, $row, $alumno["Usuario_nombre"])
- ->setCellValueByColumnAndRow($col++, $row, fechaMonthPicker($alumno["Alumno_generacion"]))
- ->setCellValueByColumnAndRow($col++, $row, $alumno["Usuario_curp"])
- ->setCellValueByColumnAndRow($col++, $row, $correo)
- ->setCellValueByColumnAndRow($col++, $row, $alumno["Carrera_desc"])
- ->setCellValueByColumnAndRow($col++, $row, $alumno["PlanEstudio_desc"]);
- $spreadsheet->getActiveSheet()->getStyle(numberToLetter(1).$row)->applyFromArray(['font' => [ 'color' => ['argb' => str_replace("#", "FF", $alumno["EstadoAlumno_color"])] ] ]);
- $spreadsheet->getActiveSheet()->getStyle(numberToLetter(3).$row)->getNumberFormat()->setFormatCode('000000');
- $row++;
- }
- $row--;
- //Auto ajustar anchos
- for($col = 1; $col < $colMax; $col++)
- $spreadsheet->getActiveSheet()->getColumnDimension(numberToLetter($col))->setAutoSize(true);
- //---------
- // Set active sheet index to the first sheet, so Excel opens this as the first sheet
- $spreadsheet->setActiveSheetIndex(0);
- // Redirect output to a client’s web browser (Xlsx)
- header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
- //header('Content-Disposition: attachment;filename="alumnos'.$prefijo.'_'.str_replace(array(',', ' '), array('',''), fechaMonthPicker($filter_gen)).'.xlsx"');
- header('Content-Disposition: attachment;filename="alumnos'.$prefijo.'.xlsx"');
- header('Cache-Control: max-age=0');
- // If you're serving to IE 9, then the following may be needed
- header('Cache-Control: max-age=1');
- // If you're serving to IE over SSL, then the following may be needed
- header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
- header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
- header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
- header('Pragma: public'); // HTTP/1.0
- $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
- $writer->save('php://output');
- exit;
|