Agregada instruccion para reiniciar tablas de horarios.
[CLab.git] / contenido / admin+reportes.php
blob8013be23430b1101e24081fea10ae9b84dd6cdd9
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 = "<h4>$tema</h4><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 Instructores</title>
26 </head>
27 <body>
29 $HTML_FOOT = '</body></html>';
31 function displayUsers_ECHO(){
32 global $database, $link, $base, $motor, $usuario, $clave;
33 $link = @mysql_connect($motor, $usuario, $clave) or die('Por favor revise sus datos, puesto que se produjo el siguiente error:<br /><pre>' . mysql_error() . '</pre>');
34 mysql_select_db($base, $link) or die('!->La base de datos seleccionada "'.$base.'" no existe');
35 //¿Algún WHERE?
36 $where = "";
37 $q = "SELECT username,nombre,userlevel,email,timestamp FROM ".TBL_USERS." $where ORDER BY userlevel DESC;";
38 $result = $database->query($q, $link);
39 /* Error occurred, return given name by default */
40 $num_rows = mysql_numrows($result);
41 if(!$result || ($num_rows < 0)){
42 echo "<hr />Error en la consulta<hr />";
43 return;
45 if($num_rows == 0){
46 $s = "No hay instructores, imposible generar reporte.";
47 return;
49 /* Display table contents */
50 $s = "";
51 $s = '<table border="1" cellspacing="0" cellpadding="3">';
52 $s = $s . "<tr><td><b>Código</b></td><td><b>Nombre</b></td><td><b>Nivel</b></td><td><b>Email</b></td><td><b>Última actividad</b></td></tr>";
53 for($i=0; $i<$num_rows; $i++){
54 $uname = mysql_result($result,$i,"username");
55 $nombre = mysql_result($result,$i,"nombre");
56 $ulevel = mysql_result($result,$i,"userlevel");
57 $email = mysql_result($result,$i,"email");
58 $time = date("c", mysql_result($result,$i,"timestamp"));
59 //$horarios ='<a href="./?x=hr&amp;forzar='.$uname.'">Ver</a>';
60 $uname = $uname;
61 $s = $s . "<tr><td>$uname</td><td>$nombre</td><td>$ulevel</td><td>$email</td><td>$time</td></tr>";
63 $s = $s . "</table>";
64 return $s;
67 function OBTENER_TIPO_R($taller,$dia, $hora) {
68 global $session, $link;
69 // ¿Hay alguien(es) en esa posición?
70 switch ($_SESSION['tipo']) {
71 case 0:
72 case 1:
73 case 3:
74 $q = "SELECT users.username, nombre FROM users, horarios WHERE users.username = horarios.username and taller like '%$taller%' AND tipo = '". $_SESSION['tipo']. "' AND dia='$dia' AND posicion='$hora' AND departamento = '" .$_SESSION['dpto']. "';";
75 break;
76 case 2:
77 $q = "SELECT users.username, nombre FROM users, horarios WHERE users.username = horarios.username AND tipo = '2' AND dia='$dia' AND posicion='$hora' AND departamento = '" . $_SESSION['dpto']. "';";
78 break;
80 //echo $q;
81 $resultados = @mysql_query($q, $link);
82 $num_rows = mysql_numrows($resultados);
84 if($num_rows > 0){
85 $msj="";
86 for($i=0; $i<$num_rows; $i++){
87 $uname = mysql_result($resultados,$i,"nombre");
88 /* Por petición solo el primer nombre es mostrado */
89 unset ($nombre);
90 ereg("([^ ]*)", $uname, $nombre);
91 $uinfo = mysql_result($resultados,$i,"username");
92 $msj = $msj.$nombre[0]."<br />";
94 return "<td bgcolor=\"#EEEEEE\">".$msj."</td>";
95 }else {
96 //$msj="Sin Asignar";
97 $msj="";
99 return "<td>".$msj."</td>";
102 function MOSTRAR_HORARIOS_ECHO() {
103 global $link, $base, $motor, $usuario, $clave;
104 $link = @mysql_connect($motor, $usuario, $clave) or die('Por favor revise sus datos, puesto que se produjo el siguiente error:<br /><pre>' . mysql_error() . '</pre>');
105 mysql_select_db($base, $link) or die('!->La base de datos seleccionada "'.$base.'" no existe');
106 $salida =
108 <hr />
109 <h3>Taller '.$_SESSION['taller'].' - ';
110 switch ($_SESSION['tipo'])
112 case 0: $salida = $salida .TI_0; break;
113 case 1: $salida = $salida .TI_1; break;
114 case 2: $salida = $salida .TI_2; break;
115 case 3: $salida = $salida .TI_3; break;
118 $salida = $salida .
119 '</h3>
120 <hr />
121 <table border="1" cellspacing="0" cellpadding="3">
122 <tr><th>Horario</th><th>Lunes</th><th>Martes</th><th>Miercoles</th><th>Jueves</th><th>Viernes</th><th>Sabado</th></tr>
124 for ($i=450; $i<=1170; $i+=60){
125 $salida = $salida ."<tr><td>". date("h:ia", mktime(0,$i)) . "</td>". OBTENER_TIPO_R($_SESSION['taller'], 1, $i).OBTENER_TIPO_R($_SESSION['taller'], 2, $i).OBTENER_TIPO_R($_SESSION['taller'], 3, $i).OBTENER_TIPO_R($_SESSION['taller'], 4, $i).OBTENER_TIPO_R($_SESSION['taller'], 5, $i).OBTENER_TIPO_R($_SESSION['taller'], 6, $i)."</tr>";
127 $salida = $salida .'</table><br /><p style="page-break-after: always" />';
128 //mysql_close($link);
129 return $salida;
132 function ADMIN_reportes() {
133 global $HTML_HEAD, $HTML_FOOT;
134 echo "<h2>Generador de Reportes</h2>";
135 if ( isset($_POST['generar']) ) {
136 echo '<h3>Reporte(s) generado(s) en base a las opciones de configuración:<br />';
137 $tiempo_ord = date('y\-m\-d\+h.ia', time());
138 if ($_POST['generar_horarios'] == 1 ) {
139 /***************************************************************************************************************************/
140 /* HORARIOS - HTML */
141 /***************************************************************************************************************************/
142 $s = $HTML_HEAD;
143 if (isset($_POST['dpto0'])) {
144 if ($_POST['dpto0'] == 1) {
145 $_SESSION['dpto'] = 0;
146 $s = $s . "<h2>".DE_0. "</h2>";
147 for ($i=0; $i < 4; $i++) {
148 if (isset($_POST["tipo_instructor$i"])) {
149 if ( $_POST["tipo_instructor$i"] == 1 ) {
150 $_SESSION['tipo'] = $i;
151 if ($i != 2 ) {
152 if (isset($_POST['taller0'])) { if ( $_POST['taller0'] ) {$_SESSION['taller'] = 'LSA'; $s = $s . MOSTRAR_HORARIOS_ECHO(); }}
153 if (isset($_POST['taller1'])) { if ( $_POST['taller1'] ) {$_SESSION['taller'] = 'LID'; $s = $s . MOSTRAR_HORARIOS_ECHO(); }}
154 if (isset($_POST['taller2'])) { if ( $_POST['taller2'] ) {$_SESSION['taller'] = 'LAI'; $s = $s . MOSTRAR_HORARIOS_ECHO(); }}
155 if (isset($_POST['taller3'])) { if ( $_POST['taller3'] ) {$_SESSION['taller'] = 'LIV'; $s = $s . MOSTRAR_HORARIOS_ECHO(); }}
156 } else {
157 //Encargado de Taller, solo mostrar 1 horario.
158 $_SESSION['taller'] = 'GENERAL'; $s = $s . MOSTRAR_HORARIOS_ECHO();
165 if (isset($_POST['dpto1'])) {
166 if ($_POST['dpto1'] == 1) {
167 $_SESSION['dpto'] = 1;
168 $s = $s . "<h2>".DE_1. "</h2>";
169 for ($i=0; $i < 4; $i++) {
170 if (isset($_POST["tipo_instructor$i"])) {
171 if ( $_POST["tipo_instructor$i"] == 1 ) {
172 $_SESSION['tipo'] = $i;
173 if ($i != 2 ) {
174 if (isset($_POST['taller4'])) { if ( $_POST['taller4'] ) {$_SESSION['taller'] = 'TPP'; $s = $s . MOSTRAR_HORARIOS_ECHO(); }}
175 if (isset($_POST['taller5'])) { if ( $_POST['taller5'] ) {$_SESSION['taller'] = 'TIS'; $s = $s . MOSTRAR_HORARIOS_ECHO(); }}
176 if (isset($_POST['taller6'])) { if ( $_POST['taller6'] ) {$_SESSION['taller'] = 'TAS'; $s = $s . MOSTRAR_HORARIOS_ECHO(); }}
177 if (isset($_POST['taller7'])) { if ( $_POST['taller7'] ) {$_SESSION['taller'] = 'TEC'; $s = $s . MOSTRAR_HORARIOS_ECHO(); }}
178 } else {
179 //Encargado de Taller, solo mostrar 1 horario.
180 $_SESSION['taller'] = 'GENERAL'; $s = $s . MOSTRAR_HORARIOS_ECHO();
187 $s = $s . $HTML_FOOT;
189 //Haremos HORARIOS_HTML?
190 if ( $_POST['tipo_reporte1'] == 1 ) {
191 $archivo_HTML_HORARIOS = "reportes/+H/+HTML/horarios+".$tiempo_ord.".html";
192 $fh = @fopen($archivo_HTML_HORARIOS, 'w') or die("'/reportes/+HTML/' bloqueado");
193 fwrite($fh, $s);
194 fclose($fh);
197 /***************************************************************************************************************************/
198 /* HORARIOS - PDF */
199 /***************************************************************************************************************************/
201 if ( $_POST['tipo_reporte0'] == 1 ) {
202 @set_time_limit(300);
203 $dompdf = new DOMPDF();
204 $dompdf->load_html($s);
205 $dompdf->render();
206 $PDF_HORARIOS = $dompdf->output();
207 $archivo_PDF_HORARIOS = "reportes/+H/+PDF/horarios+".$tiempo_ord.".pdf";
208 file_put_contents($archivo_PDF_HORARIOS, $PDF_HORARIOS);
209 unset($dompdf);
210 unset($PDF_HORARIOS);
211 @set_time_limit(30);
215 /***************************************************************************************************************************/
216 /* INSTRUCTORES - HTML */
217 /***************************************************************************************************************************/
218 if ( $_POST['generar_instructores'] == 1 ) {
219 $s = $HTML_HEAD. displayUsers_ECHO() . $HTML_FOOT;
221 //Haremos Instructores_HTML?
222 if ( $_POST['tipo_reporte1'] == 1 ) {
223 $archivo_HTML_INSTRUCTORES = "reportes/+I/+HTML/instructores+".$tiempo_ord.".html";
224 $fh = @fopen($archivo_HTML_INSTRUCTORES, 'w') or die("'/reportes/+HTML/' bloqueado");
225 fwrite($fh, $s);
226 fclose($fh);
229 /***************************************************************************************************************************/
230 /* INSTRUCTORES - PDF */
231 /***************************************************************************************************************************/
232 if ( $_POST['tipo_reporte0'] == 1 ) {
233 @set_time_limit(300);
234 $dompdf = new DOMPDF();
235 $dompdf->load_html($s);
236 $dompdf->render();
237 $PDF_INSTRUCTORES = $dompdf->output();
238 $archivo_PDF_INSTRUCTORES = "reportes/+I/+PDF/horarios+".$tiempo_ord.".pdf";
239 file_put_contents($archivo_PDF_INSTRUCTORES, $PDF_INSTRUCTORES);
240 unset($dompdf);
241 unset($PDF_INSTRUCTORES);
242 @set_time_limit(30);
246 /***************************************************************************************************************************/
247 /* GENERACIÓN DE REPORTES TERMINANDA, MOSTRAR LINKS */
248 /***************************************************************************************************************************/
249 echo "<pre>";
250 if ( $_POST['tipo_reporte1'] == 1 && $_POST['generar_horarios'] == 1 ){ echo '<a href="'.$archivo_HTML_HORARIOS.'">Descargar reportes de Horarios[HTML]</a><br />'; }
251 if ( $_POST['tipo_reporte0'] == 1 && $_POST['generar_horarios'] == 1 ) {echo '<a href="'.$archivo_PDF_HORARIOS.'">Descargar reportes de Horarios[PDF]</a><br />'; }
252 if ( $_POST['tipo_reporte1'] == 1 && $_POST['generar_instructores'] == 1 ){ echo '<a href="'.$archivo_HTML_INSTRUCTORES.'">Descargar reportes de Instructores[HTML]</a><br />'; }
253 if ( $_POST['tipo_reporte0'] == 1 && $_POST['generar_instructores'] == 1 ){ echo '<a href="'.$archivo_PDF_INSTRUCTORES.'">Descargar reportes de Instructores[PDF]</a><br />'; }
254 echo "</pre>";
255 echo '<blockquote>Por favor realice clic derecho sobre el enlace de descarga y posteriormente utilice la opción "Guardar como" de su navegador</blockquote>';
257 echo "<hr /><h3>Por favor seleccione el/los tipo(s) de reporte(s) a generar</h3>";
258 echo "<h4>Reporte de horarios</h4>";
260 <form action="./?accion=reportes" method="post">
261 <input type="checkbox" name="generar_horarios" value="1" checked="cheked">Generar reporte de horarios
262 <table>
263 <tr>
264 <td><input type="checkbox" name="dpto0" value="1" checked="cheked"><?echo DE_0;?></td>
265 <td><input type="checkbox" name="dpto1" value="1" checked="cheked"><?echo DE_1;?></td>
266 </tr>
267 </table>
268 <table>
269 <tr>
270 <td><input type="checkbox" name="taller0" value="1" checked="cheked">LSA</td>
271 <td><input type="checkbox" name="taller4" value="1" checked="cheked">TPP</td>
272 </tr>
273 <tr>
274 <td><input type="checkbox" name="taller1" value="1" checked="cheked">LID</td>
275 <td><input type="checkbox" name="taller5" value="1" checked="cheked">TIS</td>
276 </tr>
277 <tr>
278 <td><input type="checkbox" name="taller2" value="1" checked="cheked">LAI</td>
279 <td><input type="checkbox" name="taller6" value="1" checked="cheked">TAS</td>
280 </tr>
281 <tr>
282 <td><input type="checkbox" name="taller3" value="1" checked="cheked">LIV</td>
283 <td><input type="checkbox" name="taller7" value="1" checked="cheked">TEC</td>
284 </tr>
285 </table>
286 <table>
287 <tr>
288 <td><input type="checkbox" name="tipo_instructor0" value="1" checked="cheked"> <?echo TI_0;?></td>
289 <td><input type="checkbox" name="tipo_instructor1" value="1" checked="cheked"> <?echo TI_1;?></td>
290 </tr>
291 <tr>
292 <td><input type="checkbox" name="tipo_instructor2" value="1" checked="cheked"> <?echo TI_2;?></td>
293 <td><input type="checkbox" name="tipo_instructor3" value="1" checked="cheked"> <?echo TI_3;?></td>
294 </tr>
295 </table>
296 <? echo "<h4>Reporte de Instructores</h4>"; ?>
297 <input type="checkbox" name="generar_instructores" value="1" checked="cheked">Generar reporte de instructores
298 <table>
299 <tr>
300 <td><input type="checkbox" name="instructor_nivel0" value="1" checked="cheked"> Administradores</td>
301 <td><input type="checkbox" name="instructor_nivel1" value="1" checked="cheked"> Instructores</td>
302 </tr>
303 </table>
304 <? echo "<hr /><h3>Por favor seleccione el/los tipo(s) de formato de salida a generar</h3>"; ?>
305 <table>
306 <tr>
307 <td><input type="checkbox" name="tipo_reporte0" value="1" checked="cheked">PDF</td>
308 <td><input type="checkbox" name="tipo_reporte1" value="1" checked="cheked">HTML</td>
309 </tr>
310 </table>
311 <input type="hidden" name="generar" value="1">
312 <input type="submit" name="bgenerar" value="Generar" />
313 </form>
315 echo "<hr /><h3>Se han encontrado estos reportes anteriores</h3>";
316 echo Directorios("reportes/+H/+HTML/", "Horarios - HTML");
317 echo Directorios("reportes/+H/+PDF/", "Horarios - PDF");
318 echo Directorios("reportes/+I/+HTML/", "Instructores - HTML");
319 echo Directorios("reportes/+I/+PDF/", "Instructores - PDF");
321 return;