Flush causa problemas para cerrar sesion.
[ecomupi.git] / contenido / admin+reportes.php
blob4ec6342ff707c12fb5dee0df67a755be75e30ca6
1 <?php
2 function byteConvert($bytes)
4 $s = array('B', 'Kb', 'MB', 'GB', 'TB', 'PB');
5 $e = floor(log($bytes)/log(1024));
7 return sprintf('%.2f '.$s[$e], ($bytes/pow(1024, floor($e))));
9 function Directorios($base, $tema) {
10 $dir=dir($base);
11 $s = "<h3>$tema</h3><blockquote cite=\"$tema\"><ol>";
12 while($filename=$dir->read()) {
13 if ( $filename != "." && $filename != ".." && $filename != "index.php" ) { $s = $s."<li>".CREAR_LINK("$base$filename", $filename, "Abrir $filename").' [<b>'.byteConvert(filesize($base.$filename)).'</b>]</li><br />'; }
15 $dir->close();
16 $s = $s."</ol></blockquote>";
17 return $s;
20 $HTML_HEAD = '
21 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
22 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
23 <head>
24 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
25 <title>Reporte de Eco Mupis - CEPASA de C.V.</title>
26 </head>
27 <body>
29 $HTML_FOOT = '</body></html>';
31 function ADMIN_reportes() {
32 global $HTML_HEAD, $HTML_FOOT, $database, $session;
33 echo "<h1>Reportes</h1>";
34 /***************************************************************************************************************************/
35 /* USER */
36 /***************************************************************************************************************************/
37 //Nos pasaron un nombre?, entonces quieren un reporte SOLO de ese usuario:
38 if ( isset($_GET['user']) ) {
39 $_SESSION['user'] = $_GET['user'];
40 $req_user_info = $database->getUserInfo($_SESSION['user']);
41 $_SESSION['tipo'] = $req_user_info['tipo'];
42 $_SESSION['nombre'] = $req_user_info['nombre'];
43 $_SESSION['dpto'] = $req_user_info['departamento'];
44 unset($_SESSION['taller']);
45 /***************************************************************************************************************************/
46 /* USER - HTML */
47 /***************************************************************************************************************************/
48 $s = $HTML_HEAD. MOSTRAR_HORARIOS_UNICO_ECHO() . $HTML_FOOT;
49 $archivo_HTML_INSTRUCTORES_IND = "reportes/+I/+HTML/instructores+".$_SESSION['user']."+".$tiempo_ord.".html";
50 $fh = @fopen($archivo_HTML_INSTRUCTORES_IND, 'w') or die("'/reportes/+HTML/' bloqueado");
51 fwrite($fh, $s);
52 fclose($fh);
53 /***************************************************************************************************************************/
54 /* USER - PDF */
55 /***************************************************************************************************************************/
56 @set_time_limit(300);
57 $dompdf = new DOMPDF();
58 $dompdf->load_html($s);
59 $dompdf->render();
60 $PDF_INSTRUCTORES_IND = $dompdf->output();
61 $archivo_PDF_INSTRUCTORES_IND = "reportes/+I/+PDF/horarios+".$_SESSION['user']."+".$tiempo_ord.".pdf";
62 file_put_contents($archivo_PDF_INSTRUCTORES_IND, $PDF_INSTRUCTORES_IND);
63 unset($dompdf);
64 unset($PDF_INSTRUCTORES);
65 @set_time_limit(30);
67 /* LINKS */
68 echo "<pre>";
69 echo '<a href="'.$archivo_HTML_INSTRUCTORES_IND.'" target="_blank">Descargar reportes de horario para '.$_SESSION['user'].'[HTML]</a><br />';
70 echo '<a href="'.$archivo_PDF_INSTRUCTORES_IND.'" target="_blank">Descargar reportes de horario para '.$_SESSION['user'].'[PDF]</a><br />';
71 echo "</pre>";
72 echo '<blockquote>Por favor realice clic derecho sobre el enlace de descarga y posteriormente utilice la opción "Guardar como" de su navegador</blockquote>';
73 /* FIN USER */
74 return;
76 if ( isset($_POST['generar']) ) {
77 echo '<h3>Reporte(s) generado(s) en base a las opciones de configuración:<br />';
78 $tiempo_ord = date('y\-m\-d\+h.ia', time());
79 if ($_POST['generar_horarios'] == 1 ) {
80 /***************************************************************************************************************************/
81 /* HORARIOS - HTML */
82 /***************************************************************************************************************************/
83 $s = $HTML_HEAD;
84 if (isset($_POST['dpto0'])) {
85 if ($_POST['dpto0'] == 1) {
86 $_SESSION['dpto'] = 0;
87 $s = $s . "<h2>".DE_0. "</h2>";
88 for ($i=0; $i < 4; $i++) {
89 if (isset($_POST["tipo_instructor$i"])) {
90 if ( $_POST["tipo_instructor$i"] == 1 ) {
91 $_SESSION['tipo'] = $i;
92 if ($i != 2 ) {
93 if (isset($_POST['taller0'])) { if ( $_POST['taller0'] ) {$_SESSION['taller'] = 'LSA'; $s = $s . MOSTRAR_HORARIOS_ECHO(); }}
94 if (isset($_POST['taller1'])) { if ( $_POST['taller1'] ) {$_SESSION['taller'] = 'LID'; $s = $s . MOSTRAR_HORARIOS_ECHO(); }}
95 if (isset($_POST['taller2'])) { if ( $_POST['taller2'] ) {$_SESSION['taller'] = 'LAI'; $s = $s . MOSTRAR_HORARIOS_ECHO(); }}
96 if (isset($_POST['taller3'])) { if ( $_POST['taller3'] ) {$_SESSION['taller'] = 'LIV'; $s = $s . MOSTRAR_HORARIOS_ECHO(); }}
97 } else {
98 //Encargado de Taller, solo mostrar 1 horario.
99 $_SESSION['taller'] = 'GENERAL'; $s = $s . MOSTRAR_HORARIOS_ECHO();
106 if (isset($_POST['dpto1'])) {
107 if ($_POST['dpto1'] == 1) {
108 $_SESSION['dpto'] = 1;
109 $s = $s . "<h2>".DE_1. "</h2>";
110 for ($i=0; $i < 4; $i++) {
111 if (isset($_POST["tipo_instructor$i"])) {
112 if ( $_POST["tipo_instructor$i"] == 1 ) {
113 $_SESSION['tipo'] = $i;
114 if ($i != 2 ) {
115 if (isset($_POST['taller4'])) { if ( $_POST['taller4'] ) {$_SESSION['taller'] = 'TPP'; $s = $s . MOSTRAR_HORARIOS_ECHO(); }}
116 if (isset($_POST['taller5'])) { if ( $_POST['taller5'] ) {$_SESSION['taller'] = 'TIS'; $s = $s . MOSTRAR_HORARIOS_ECHO(); }}
117 if (isset($_POST['taller6'])) { if ( $_POST['taller6'] ) {$_SESSION['taller'] = 'TAS'; $s = $s . MOSTRAR_HORARIOS_ECHO(); }}
118 if (isset($_POST['taller7'])) { if ( $_POST['taller7'] ) {$_SESSION['taller'] = 'TEC'; $s = $s . MOSTRAR_HORARIOS_ECHO(); }}
119 } else {
120 //Encargado de Taller, solo mostrar 1 horario.
121 $_SESSION['taller'] = 'GENERAL'; $s = $s . MOSTRAR_HORARIOS_ECHO();
128 $s = $s . $HTML_FOOT;
130 //Haremos HORARIOS_HTML?
131 if ( $_POST['tipo_reporte1'] == 1 ) {
132 $archivo_HTML_HORARIOS = "reportes/+H/+HTML/horarios+".$tiempo_ord.".html";
133 $fh = @fopen($archivo_HTML_HORARIOS, 'w') or die("'/reportes/+HTML/' bloqueado");
134 fwrite($fh, $s);
135 fclose($fh);
138 /***************************************************************************************************************************/
139 /* HORARIOS - PDF */
140 /***************************************************************************************************************************/
142 if ( $_POST['tipo_reporte0'] == 1 ) {
143 @set_time_limit(300);
144 $dompdf = new DOMPDF();
145 $dompdf->load_html($s);
146 $dompdf->render();
147 $PDF_HORARIOS = $dompdf->output();
148 $archivo_PDF_HORARIOS = "reportes/+H/+PDF/horarios+".$tiempo_ord.".pdf";
149 file_put_contents($archivo_PDF_HORARIOS, $PDF_HORARIOS);
150 unset($dompdf);
151 unset($PDF_HORARIOS);
152 @set_time_limit(30);
156 /***************************************************************************************************************************/
157 /* INSTRUCTORES - HTML */
158 /***************************************************************************************************************************/
159 if ( $_POST['generar_instructores'] == 1 ) {
160 $s = $HTML_HEAD. displayUsers_ECHO() . $HTML_FOOT;
162 //Haremos Instructores_HTML?
163 if ( $_POST['tipo_reporte1'] == 1 ) {
164 $archivo_HTML_INSTRUCTORES = "reportes/+I/+HTML/instructores+".$tiempo_ord.".html";
165 $fh = @fopen($archivo_HTML_INSTRUCTORES, 'w') or die("'/reportes/+HTML/' bloqueado");
166 fwrite($fh, $s);
167 fclose($fh);
170 /***************************************************************************************************************************/
171 /* INSTRUCTORES - PDF */
172 /***************************************************************************************************************************/
173 if ( $_POST['tipo_reporte0'] == 1 ) {
174 @set_time_limit(300);
175 $dompdf = new DOMPDF();
176 $dompdf->load_html($s);
177 $dompdf->render();
178 $PDF_INSTRUCTORES = $dompdf->output();
179 $archivo_PDF_INSTRUCTORES = "reportes/+I/+PDF/horarios+".$tiempo_ord.".pdf";
180 file_put_contents($archivo_PDF_INSTRUCTORES, $PDF_INSTRUCTORES);
181 unset($dompdf);
182 unset($PDF_INSTRUCTORES);
183 @set_time_limit(30);
187 /***************************************************************************************************************************/
188 /* GENERACIÓN DE REPORTES TERMINANDA, MOSTRAR LINKS */
189 /***************************************************************************************************************************/
190 echo "<pre>";
191 if ( $_POST['tipo_reporte1'] == 1 && $_POST['generar_horarios'] == 1 ){ echo '<a href="'.$archivo_HTML_HORARIOS.'" target="_blank">Descargar reportes de Horarios[HTML]</a><br />'; }
192 if ( $_POST['tipo_reporte0'] == 1 && $_POST['generar_horarios'] == 1 ) {echo '<a href="'.$archivo_PDF_HORARIOS.'" target="_blank">Descargar reportes de Horarios[PDF]</a><br />'; }
193 if ( $_POST['tipo_reporte1'] == 1 && $_POST['generar_instructores'] == 1 ){ echo '<a href="'.$archivo_HTML_INSTRUCTORES.'" target="_blank">Descargar reportes de Instructores[HTML]</a><br />'; }
194 if ( $_POST['tipo_reporte0'] == 1 && $_POST['generar_instructores'] == 1 ){ echo '<a href="'.$archivo_PDF_INSTRUCTORES.'" target="_blank">Descargar reportes de Instructores[PDF]</a><br />'; }
195 echo "</pre>";
196 echo '<blockquote>Por favor realice clic derecho sobre el enlace de descarga y posteriormente utilice la opción "Guardar como" de su navegador</blockquote>';
198 if ( $session->isAdmin() ) {
199 echo '<form action="./?accion=reportes" method="post">';
200 echo "<hr /><h2>Por favor seleccione el/los tipo(s) de reporte(s) a generar</h2>";
201 echo "<h3>Reporte de clientes</h3>";
202 echo '<td><input type="checkbox" name="reporte_clientes_0" value="1" checked="cheked">Listado breve de clientes</td><br />';
203 echo "<h3>Reporte de Eco Mupis</h3>";
204 echo '
205 <td><input type="checkbox" name="reporte_eco_0" value="1" checked="cheked">Listado de Eco Mupis</td><br />
206 <td><input type="checkbox" name="reporte_eco_0" value="1" checked="cheked">Listado de Eco Mupis Activos</td><br />
207 <td><input type="checkbox" name="reporte_eco_1" value="1" checked="cheked">Listado de Pedidos</td><br />
208 <td><input type="checkbox" name="reporte_eco_2" value="1" checked="cheked">Listado de Eventos</td><br />
209 <td><input type="checkbox" name="reporte_eco_2" value="1" checked="cheked">Listado de Calles</td><br />
210 <td><input type="checkbox" name="reporte_eco_2" value="1" checked="cheked">Listado de Referencias</td><br />
211 <td><input type="checkbox" name="reporte_eco_2" value="1" checked="cheked">Listado de Comentarios</td><br />
213 echo "<hr /><h3>Por favor seleccione el/los tipo(s) de formato de salida a generar</h3>";
214 echo '
215 <table>
216 <tr>
217 <td><input type="checkbox" name="tipo_reporte0" value="1" checked="cheked">PDF</td>
218 <td><input type="checkbox" name="tipo_reporte1" value="1" checked="cheked">HTML</td>
219 </tr>
220 </table>
221 <input type="hidden" name="generar" value="1">
222 <input type="submit" name="bgenerar" value="Generar" />
223 </form>
225 echo "<hr /><h2>Se han encontrado los siguientes reportes anteriormente generados</h2>";
226 echo Directorios("reportes/+HTML/", "HTML");
227 echo Directorios("reportes/+PDF/", "PDF");
228 return;
229 } else {