<?php
include_once ("../core/config.php");
$UTENTE = login();
$DIRITTI = diritti(1);
view_top();

if (isset($_POST['tempo'])) {
	$tempo = $_POST['tempo'];
} else {
	$tempo = "DAY";
}
?>

<form name="" method="post">
<table cellpadding="0" cellspacing="0" border="0" width="90%">
	<tr>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td colspan="2">
			<select name="tempo" onchange="this.form.submit()">
				<option value="HOUR" <?php if ($tempo == "HOUR") {print "selected=\"selected\""; } ?>>Ultima Ora</option>
				<option value="DAY" <?php if ($tempo == "DAY") {print "selected=\"selected\""; } ?>>Ultimo Giorno</option>
				<option value="WEEK" <?php if ($tempo == "WEEK") {print "selected=\"selected\""; } ?>>Ultima Settimana</option>
				<option value="MONTH" <?php if ($tempo == "MONTH") {print "selected=\"selected\""; } ?>>Ultimo Mese</option>
				<option value="YEAR" <?php if ($tempo == "YEAR") {print "selected=\"selected\""; } ?>>Ultimo Anno</option>
			</select>
		</td>
		<td colspan="10" class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		</td>
	</tr>
	<tr><td class="spaziov" colspan=13><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td></tr>
<?php
$query = "SELECT GREATEST (sum(inviati), sum(ricevuti)) AS max from proxy_dati WHERE data_destroy >= DATE_SUB(NOW(), INTERVAL 1 $tempo)";
$res = mysql_query( $query, $DB_ID );
$valori = mysql_fetch_array ( $res );
$max = $valori['max'];

$query = "	SELECT 
			proxy_pool.attivo,
			proxy_dati.ip, 
			MIN(proxy_dati.data_destroy) AS first, 
			MAX(proxy_dati.data_destroy) AS last, 
			SUM(proxy_dati.inviati) AS inviati,
			SUM(proxy_dati.ricevuti) AS ricevuti
		FROM
			proxy_dati
		JOIN
			proxy_pool
		ON
			proxy_dati.ip = proxy_pool.ip
		WHERE
			data_destroy >= DATE_SUB(NOW(), INTERVAL 1 $tempo)	
		GROUP BY
			ip
		ORDER BY
			ip
	";

$res = mysql_query( $query, $DB_ID );
while ($dato = mysql_fetch_array ( $res )) {
?>

	<tr>
<?php
	if ($dato['attivo']) {
?>
		<td rowspan=2 class="col3btn"><a href="pool_gest.php?azione=libera&ip=<?php print $dato['ip']?>"><img border=0 src="<?php print $CONF['base_url'] ?>/img/non_attivo.gif" ALT="Utente limitato" TITLE="Utente limitato"></a></td>
<?php	} else { ?>
		<td rowspan=2 class="col3btn"><a href="pool_gest.php?azione=limita&ip=<?php print $dato['ip']?>"><img border=0 src="<?php print $CONF['base_url'] ?>/img/attivo.gif" ALT="Utente non limitato" TITLE="Utente non limitato"></a></td>
<?php	} ?>
		<td rowspan=2 class="col3btn"><a href="pool_ip.php?ip=<?php print $dato['ip'] ?>"><img src="<?php print $CONF['base_url'] ?>/img/modify.gif" width="20" height="20" border="0" ALT="Dettaglio" TITLE="Dettaglio"></a></td>
		<td rowspan=2 class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>

		<td rowspan=2 class="colip"><?php print $dato['ip'] ?></td>

		<td rowspan=2 class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="colip"><?php print $dato['first'] ?></td>

		<td rowspan=2 class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="descrizione">Inviati</td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="colspeed"><?php print byteConvert($dato['inviati']) ?></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="colimg"><img border="0" src="barra.php?max=<?php print $max ?>&val=<?php print $dato['inviati'] ?>&col=red"></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		</td>
	</tr>
	<tr>
		<td class="colip"><?php print $dato['last'] ?></td>
		<td class="descrizione">Ricevuti</td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="colspeed"><?php print byteConvert($dato['ricevuti']) ?></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="colimg"><img border="0" src="barra.php?max=<?php print $max ?>&val=<?php print $dato['ricevuti'] ?>&col=blue"></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>

	</tr>
	<tr><td class="spaziov" colspan=13><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td></tr>

<?php
} ?>
</table>
</form>
<img src="<?php print $CONF['base_url'] ?>/img/spazio.gif" width="1" height="20" alt="">
<?php view_footer(); ?>
