commit masivo.
[ecomupi.git] / contenido / global+estadisticas.php
blob5410f9add598bb026f64bf7ef6d55397d4147540
1 <?php
2 $inicioCatorcena = Obtener_catorcena_cercana();
3 function CONTENIDO_global_estadisticas($usuario)
5 global $session, $database, $inicioCatorcena;
6 echo '
7 <script type="text/javascript">
8 $(document).ready(function() {
9 $("#toggler_pantallas_activas").click(function() {
10 $("#tabla_pantallas_activas").toggle();
11 });
12 $("#toggler_registros").click(function() {
13 $("#tabla_registros").toggle();
14 });
15 });
16 </script>
18 $NivelesPermitidos = array(ADMIN_LEVEL);
19 if (in_array($session->userlevel, $NivelesPermitidos) && !$usuario) {
20 echo "<h1>Estadísticas y notas administrativas</h1>";
22 echo MOSTRAR_comentarios();
24 //=====================================================================================//
25 // Pantallas activas en esta catorcena
26 //_____________________________________________________________________________________
27 echo "<hr /><h2>Pantallas activas esta catorcena</h2>";
28 $q = "SELECT id_pantalla, tipo_pantalla, codigo_mupi, (SELECT CONCAT(b.codigo_mupi, '. ' , (SELECT ubicacion FROM " . TBL_STREETS . " AS c WHERE c.codigo_calle = b.codigo_calle), ', ' , b.direccion) FROM " . TBL_MUPI . " as b WHERE b.id_mupi=a.codigo_mupi) as codigo_mupi_traducido, codigo_pedido, (SELECT CONCAT(codigo_pedido, '. ' , o.descripcion) FROM " . TBL_MUPI_ORDERS . " as o WHERE o.codigo_pedido = a.codigo_pedido) as codigo_pedido_traducido, catorcena, foto_real, codigo_evento FROM " . TBL_MUPI_FACES . " as a WHERE catorcena = '$inicioCatorcena' ORDER BY codigo_mupi, tipo_pantalla;";
29 $result = $database->query($q);
30 $num_rows = mysql_numrows($result);
31 if ($num_rows == 0) {
32 echo Mensaje("¡No hay pantallas ingresadas!", _M_NOTA);
33 } else {
34 echo "<a id='toggler_pantallas_activas'>Mostrar/Ocultar lista de pantallas activas</a>";
35 echo "<table id='tabla_pantallas_activas' style='display:none'>";
36 echo "<tr><th>Código Eco Mupis</th><th>Cara</th><th>Código pedido</th></tr>";
37 for ($i = 0; $i < $num_rows; $i++) {
38 $tipo_pantalla = mysql_result($result, $i, "tipo_pantalla") == 0 ? 'Vehicular' : 'Peatonal';
39 $codigo_mupi = mysql_result($result, $i, "codigo_mupi_traducido");
40 $codigo_pedido = mysql_result($result, $i, "codigo_pedido_traducido");
41 echo "<tr><td>$codigo_mupi</td><td>$tipo_pantalla</td><td>$codigo_pedido</td></tr>";
43 echo "<tfoot>";
44 echo "<td colspan='2'>Total</td><td>$num_rows</td>";
45 echo "</tfoot>";
46 echo "</table><br>";
48 //=====================================================================================//
50 //=====================================================================================//
51 // Clientes con notas administrativas
52 //_____________________________________________________________________________________
53 echo "<hr /><h2>Clientes con notas administrativas</h2>";
54 $q = "SELECT codigo, notas FROM emupi_usuarios WHERE notas!='' and userlevel!=9;";
55 $result = $database->query($q);
56 $num_rows = mysql_numrows($result);
57 if ($num_rows == 0) {
58 echo Mensaje("¡No hay clientes con notas administativas!", _M_NOTA);
59 } else {
60 echo '<table>';
61 echo "<tr><th>Cliente</th><th>Nota</th></tr>";
62 for ($i = 0; $i < $num_rows; $i++) {
63 $codigo = mysql_result($result, $i, "codigo");
64 $notas = mysql_result($result, $i, "notas");
65 echo "<tr><td>$codigo</td><td>$notas</td></tr>";
67 echo "<tfoot>";
68 echo "<td>Total</td><td>$num_rows</td>";
69 echo "</tfoot>";
70 echo "</table><br>";
72 //=====================================================================================//
73 // Eventos
74 //_____________________________________________________________________________________
75 MOSTRAR_eventos();
76 //=====================================================================================//
78 //=====================================================================================//
79 // Registro
80 //_____________________________________________________________________________________
81 echo "<hr /><h2>Registro</h2>";
82 $q = "SELECT clave, valor, detalle, autor, timestamp FROM " . TBL_REGISTRY . " ORDER BY timestamp DESC LIMIT 10";
83 $result = $database->query($q);
84 $num_rows = mysql_numrows($result);
85 if ($num_rows == 0) {
86 echo Mensaje("¡No hay registros!", _M_NOTA);
87 } else {
88 echo "<a id='toggler_registros'>Mostrar/Ocultar lista de registros (10 últimos, más reciente primero).</a>";
89 echo "<table id=\"tabla_registros\" style=\"display:none\">";
90 echo "<tr><th>Fecha y Hora</th><th>Clave</th><th>Valor</th><th>Autor</th></tr>";
91 for ($i = 0; $i < $num_rows; $i++) {
92 $timestamp = date("h:i:s @ d/m/Y", mysql_result($result, $i, "timestamp"));
93 $clave = mysql_result($result, $i, "clave");
94 $valor = mysql_result($result, $i, "valor");
95 $detalle = mysql_result($result, $i, "detalle");
96 $autor = mysql_result($result, $i, "autor");
97 echo "<tr><td>$timestamp</td><td>$clave</td><td>$valor <acronym title=\"$detalle\">¿?</acronym></td><td>$autor</td></tr>";
99 echo "<tfoot>";
100 echo "<td colspan='3'>Total</td><td>$num_rows</td>";
101 echo "</tfoot>";
102 echo "</table><br>";
104 return;
107 $NivelesPermitidos = array(ADMIN_LEVEL, SALESMAN_LEVEL);
108 if (!in_array($session->userlevel, $NivelesPermitidos)) {
109 $usuario = $session->codigo;
110 $estadisticasPara = "";
111 } else {
112 $estadisticasPara = " para $usuario";
114 echo "<h1>Estadísticas$estadisticasPara</h1>";
115 //Dinamismo en selección de catorcenas.firef
116 echo SCRIPT('
117 function ObtenerEstad(){
118 $("#datos_catorcena").load("contenido/global+estadisticas+dinamico.php?usuario=' . $usuario . '&catorcena="+$(\'#catorcenas_presencia\').val());
120 $("#catorcenas_presencia").change(function (){ObtenerEstad();});
121 ObtenerEstad();
123 /*********************************************************************************************/
124 // Inicio de parte dinámica.
125 /*********************************************************************************************/
126 echo "<br />Seleccione la catorcena de la cúal desee ver las estadísticas " . $database->Combobox_CatorcenasConPresencia("catorcenas_presencia", $usuario);
127 echo '<hr><span id="datos_catorcena"><b>Seleccione una catorcena por favor</b></span>';
128 echo '<hr />';
130 if (!$usuario) {
131 echo MOSTRAR_comentarios();
132 echo MOSTRAR_eventos();
134 return;
137 function MOSTRAR_comentarios()
139 global $session, $database, $inicioCatorcena;
140 echo "<hr /><h2>Comentarios publicados esta catorcena</h2>";
141 $finCatorcena = Obtener_Fecha_Tope(Fin_de_catorcena($inicioCatorcena));
142 $usuario = $tipo = null;
143 if (!$session->isAdmin()) {
144 $tipo = 'AND tipo=1';
145 $usuario = $session->codigo;
147 $q = "SELECT (SELECT nombre FROM emupi_usuarios AS b WHERE b.codigo=a.codigo) AS codigo, comentario, timestamp, tipo FROM emupi_comentarios AS a WHERE timestamp>=$inicioCatorcena AND timestamp<=$finCatorcena $tipo ORDER BY tipo;";
148 DEPURAR($q, 0);
149 $result = $database->query($q);
150 $num_rows = mysql_numrows($result);
151 if ($num_rows == 0) {
152 echo Mensaje("¡No hay comentarios ingresados!", _M_NOTA);
153 } else {
154 echo '<table>';
155 if (!$usuario) {
156 echo "<tr><th>Cliente</th><th>Comentario</th><th>Fecha</th><th>Tipo</th></tr>";
157 } else {
158 echo "<tr><th>Cliente</th><th>Comentario</th><th>Fecha</th></tr>";
160 for ($i = 0; $i < $num_rows; $i++) {
161 $codigo = mysql_result($result, $i, "codigo");
162 $comentario = mysql_result($result, $i, "comentario");
163 $timestamp = date("h:i:s @ d/m/Y", mysql_result($result, $i, "timestamp"));
164 if (!$usuario)
165 $tipo = mysql_result($result, $i, "tipo") == '1' ? 'Público' : 'Privado';
166 if (!$usuario) {
167 echo "<tr><td>$codigo</td><td>$comentario</td><td>$timestamp</td><td>$tipo</td></tr>";
168 } else {
169 echo "<tr><td>$codigo</td><td>$comentario</td><td>$timestamp</td></tr>";
172 echo "<tfoot>";
173 if (!$usuario) {
174 echo "<td colspan='3'>Total</td><td>$num_rows</td>";
175 } else {
176 echo "<td colspan='2'>Total</td><td>$num_rows</td>";
178 echo "</tfoot>";
179 echo "</table><br>";
183 function MOSTRAR_eventos()
185 global $session, $database, $inicioCatorcena;
186 $finCatorcena = Obtener_Fecha_Tope(Fin_de_catorcena($inicioCatorcena));
187 echo "<hr /><h2>Eventos en esta catorcena</h2>";
188 $usuario = $tipo = null;
189 if (!$session->isAdmin()) {
190 $usuario = $session->codigo;
191 $tipo = "AND codigo_pedido IN (SELECT codigo_pedido FROM emupi_mupis_pedidos WHERE codigo='$usuario')";
193 $q = "select id_evento, timestamp, categoria, afectado, (SELECT CONCAT((SELECT ubicacion FROM emupi_calles AS b WHERE c.codigo_calle=@codigo_calle:=b.codigo_calle), ', ', direccion ) FROM emupi_mupis as c WHERE c.id_mupi=(SELECT codigo_mupi FROM emupi_mupis_caras WHERE id_pantalla=afectado)) AS afectado_traducido, descripcion_evento, foto_evento from emupi_mupis_eventos WHERE categoria='PANTALLA' AND afectado IN (SELECT id_pantalla FROM emupi_mupis_caras WHERE catorcena>=$inicioCatorcena AND catorcena<=$finCatorcena $tipo);";
194 $result = $database->query($q);
195 $num_rows = mysql_numrows($result);
196 if ($num_rows == 0) {
197 echo Mensaje("¡No hay eventos ingresados!", _M_NOTA);
198 } else {
199 echo '<table>';
200 if ($usuario) {
201 echo "<tr><th>Fecha y Hora</th><th>Objeto Afectado</th><th>Descripción</th><th>Foto</th></tr>";
202 } else {
203 echo "<tr><th>Código Evento " . _NOMBRE_ . "</th><th>Fecha y Hora</th><th>Categoría</th><th>Objeto Afectado</th><th>Descripción</th><th>Foto</th></tr>";
205 for ($i = 0; $i < $num_rows; $i++) {
206 if (!$usuario)
207 $id_evento = mysql_result($result, $i, "id_evento");
208 $timestamp = date('h:i:s @ d/m/Y', mysql_result($result, $i, "timestamp"));
209 if (!$usuario)
210 $categoria = mysql_result($result, $i, "categoria");
211 $afectado = mysql_result($result, $i, "afectado_traducido");
212 $descripcion_evento = mysql_result($result, $i, "descripcion_evento");
213 $foto_evento = mysql_result($result, $i, "foto_evento");
214 if ($foto_evento) {
215 $foto_evento = CREAR_LINK_GET("ver:" . mysql_result($result, $i, "foto_evento"), "Ver foto", "Muestra la foto del evento");
217 if (!$usuario)
218 $id_evento = CREAR_LINK_GET("gestionar+eventos&amp;evento=" . $id_evento, $id_evento, "Editar los datos de este evento");
219 if ($usuario) {
220 echo "<tr><td>$timestamp</td><td>$afectado</td><td>$descripcion_evento</td><td>$foto_evento</td></tr>";
221 } else {
222 echo "<tr><td>$id_evento</td><td>$timestamp</td><td>$categoria</td><td>$afectado</td><td>$descripcion_evento</td><td>$foto_evento</td></tr>";
225 echo "<tfoot>";
226 if ($usuario) {
227 echo "<td colspan='3'>Total</td><td>$num_rows</td>";
228 } else {
229 echo "<td colspan='5'>Total</td><td>$num_rows</td>";
231 echo "</tfoot>";
232 echo "</table><br>";