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

if (isset($_POST['id'])) {
	$id = $_POST['id'];
	$net = $_POST['net'];
	$mask = $_POST['mask'];

	if ($id) {
		$query = "	UPDATE
					proxy_net
				SET
					net = '$net',
					mask = '$mask',
					modifica = NOW()
				WHERE
					id = $id	
		";
	} else {
		$query = "	INSERT INTO
					proxy_net
				SET
					net = '$net',
					mask = '$mask',
					modifica = NOW()
					data = NOW(),
					attivo = 1
		";
	}

	$res = mysql_query( $query, $DB_ID );
} elseif (isset($_GET['id'])) {
	$id = $_GET['id'];
}
?>
<form name="" method="post">
<input type="hidden" name="id" value="<?php print $id ?>">
<?php
$query = "	SELECT 
			id,
			net,
			mask,
			attivo,
			DATE_FORMAT(data, '%d.%m.%Y %H:%i:%s') AS data,
			DATE_FORMAT(modifica, '%d.%m.%Y %H:%i:%s') AS modifica
		FROM
			proxy_net
		WHERE
			id = $id
	";

$res = mysql_query( $query, $DB_ID );
$dato = mysql_fetch_array ( $res );

$tabella = new html (0,"90%",array(3,20,2,20,2,15,2,15,0));
$tabella->intestazione (array("","Rete","","NetMask","","Data attivazione","","Ultima Modifica",""));
?>
	<tr>
<?php
if ($dato['attivo']) {
?>
		<td class="col3btn"><a href="proxy_gest.php?azione=net_down&id=<?php print $dato['id']?>"><img src="<?php print $CONF['base_url'] ?>/img/attivo.gif" ALT="Net Attiva" TITLE="Net Attiva"></a></td>
<?php	} else { ?>
		<td class="col3btn"><a href="proxy_gest.php?azione=net_up&id=<?php print $dato['id']?>"><img src="<?php print $CONF['base_url'] ?>/img/non_attivo.gif" ALT="Net non Attiva" TITLE="Net non Attiva"></a></td>
<?php	} ?>
		<td class="colip"><input type="text" size="15" name=net value="<?php print $dato['net'] ?>"></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="colip">
			<select name="mask">
				<option value="255.255.255.255" <?php if ($dato['mask'] == "255.255.255.255") { print "selected=\"selected\"";}?>>/32 (255.255.255.255)</option>
				<option value="255.255.255.252" <?php if ($dato['mask'] == "255.255.255.252") { print "selected=\"selected\"";}?>>/30 (255.255.255.252)</option>
				<option value="255.255.255.248" <?php if ($dato['mask'] == "255.255.255.248") { print "selected=\"selected\"";}?>>/29 (255.255.255.248)</option>
				<option value="255.255.255.240" <?php if ($dato['mask'] == "255.255.255.240") { print "selected=\"selected\"";}?>>/28 (255.255.255.240)</option>
				<option value="255.255.255.224" <?php if ($dato['mask'] == "255.255.255.224") { print "selected=\"selected\"";}?>>/27 (255.255.255.224)</option>
				<option value="255.255.255.192" <?php if ($dato['mask'] == "255.255.255.192") { print "selected=\"selected\"";}?>>/26 (255.255.255.192)</option>
				<option value="255.255.255.128" <?php if ($dato['mask'] == "255.255.255.128") { print "selected=\"selected\"";}?>>/25 (255.255.255.128)</option>
				<option value="255.255.255.0" <?php if ($dato['mask'] == "255.255.255.0") { print "selected=\"selected\"";}?>>/24 (255.255.255.0)</option>
				<option value="255.255.254.0" <?php if ($dato['mask'] == "255.255.254.0") { print "selected=\"selected\"";}?>>/23 (255.255.254.0)</option>
				<option value="255.255.252.0" <?php if ($dato['mask'] == "255.255.252.0") { print "selected=\"selected\"";}?>>/22 (255.255.252.0)</option>
				<option value="255.255.248.0" <?php if ($dato['mask'] == "255.255.248.0") { print "selected=\"selected\"";}?>>/21 (255.255.248.0)</option>
				<option value="255.255.240.0" <?php if ($dato['mask'] == "255.255.240.0") { print "selected=\"selected\"";}?>>/20 (255.255.240.0)</option>
				<option value="255.255.224.0" <?php if ($dato['mask'] == "255.255.224.0") { print "selected=\"selected\"";}?>>/19 (255.255.224.0)</option>
				<option value="255.255.192.0" <?php if ($dato['mask'] == "255.255.192.0") { print "selected=\"selected\"";}?>>/18 (255.255.192.0)</option>
				<option value="255.255.128.0" <?php if ($dato['mask'] == "255.255.128.0") { print "selected=\"selected\"";}?>>/17 (255.255.128.0)</option>
				<option value="255.255.0.0" <?php if ($dato['mask'] == "255.255.0.0") { print "selected=\"selected\"";}?>>/16 (255.255.0.0)</option>
			</select>
		</td>

		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="colip"><?php print $dato['data'] ?></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="colip"><?php print $dato['modifica'] ?></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
	</tr>
<?php $tabella->riga(); ?>
	<tr><td class="spaziov" colspan=9><input type="submit" value="Conferma"></td></tr>
<?php $tabella->close(); ?>
</form>
<?php view_footer(); ?>
