<?php
include_once ("../core/config.php");
$UTENTE = login();
$DIRITTI = diritti(1);
view_top();
?>
<form name="" method="post">
<table cellpadding="0" cellspacing="0" border="0" width="90%">

<?php
if (isset($_GET['ip'])) { 
	$ip = $_GET['ip'];
	if (isset($_POST['tempo'])) {
		$tempo = $_POST['tempo'];
	} else {
		$tempo = "DAY";
	}

	$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
				proxy_dati.ip = '$ip'
			AND
				proxy_dati.data_destroy >= DATE_SUB(NOW(), INTERVAL 1 $tempo)
		";

	$res = mysql_query( $query, $DB_ID );
	$dato = mysql_fetch_array ( $res );
?>
	<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="6" class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
	</tr>
	<tr><td class="spaziov" colspan=9><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td></tr>

	<tr>
<?php
	if ($dato['attivo']) {
?>
		<td rowspan=2 class="col3btn"><a href="pool_gest.php?azione=libera&ip=<?php print $dato['ip']?>"><img 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 src="<?php print $CONF['base_url'] ?>/img/attivo.gif" ALT="Utente non limitato" TITLE="Utente non limitato"></a></td>
<?php	} ?>
		<td rowspan=2 class="colip"><?php print $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>
	</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>

	</tr>
	<tr><td class="spaziov" colspan=9><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td></tr>
	<tr><td colspan=9 align="center"><img src="<?php print $CONF['base_url'] ?>/proxy/graph.php?ip=<?php print $dato['ip'] ?>&tempo=<?php print $tempo ?>"></td></tr>
	<tr><td class="spaziov" colspan=9><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td></tr>

<?php
} else {
	if (isset($_POST['ip'])) {
		$ip = $_POST['ip'];
		if (isset($_POST['attivo'])) {
			$attivo = $_POST['attivo'];
		} else {
			$attivo = 0;
		}

		$query = "	INSERT INTO
					proxy_pool
				SET
					ip = '$ip',
					pool = 1,
					attivo = $attivo,
					ins = NOW()
		";
		$res = mysql_query( $query, $DB_ID );

		if (!$res) {
			$error_code = mysql_errno();
			if ($error_code == 1062) { ?>
	<tr><td class="spaziov" colspan=11><center>Indirizzo IP gia' esistente</center></td></tr>
			
<?php			}
		} else { ?>
	<script type="text/javascript">
           window.location = "pool_lista.php"
      </script>
<?php		exit;
		}


	}
?>
	<tr>
		<td width="10%"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td width="10%"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td width="2%"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td width="23%"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td width="10%"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td width="10%"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td width="2%"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td width="23%"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td width="10%"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
	</tr>
	<tr>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="colip">Indirizzo IP:</td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="colip"><input type="text" size="15" name="ip"></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="colip">Limitazione:</td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="colip"><input type="checkbox" name="attivo" value="1"></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
	</tr>
	<tr><td class="spaziov" colspan=11><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td></tr>
	<tr>
		<td align="center" colspan="11">
			<input type="submit" value="Aggiungi">
			&nbsp;&nbsp;&nbsp;
			<input type="button" value="Annulla" onclick="location.href = 'pool_lista.php';"></button>
		</td>
	</tr>



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