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

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

	foreach ($_POST as $key => $value) {
		if ($key == 'id') continue;

		$query = "	INSERT INTO
					proxy_acl_net
				SET
					idacllist = $key,
					idaclnet = $id,
					stato = $value,
					data = NOW()
				ON DUPLICATE KEY UPDATE 
					stato = $value,
					data = NOW()
		";
		$res = mysql_query( $query, $DB_ID );
	}
} elseif (isset($_GET['id'])) {
	$id = $_GET['id'];
}

$query = "	SELECT 
			net,
			mask
		FROM
			proxy_net
		WHERE
			id = $id
	";
$res = mysql_query( $query, $DB_ID );
$dato = mysql_fetch_array ( $res );
$net = $dato['net']." / ".$dato['mask'];

$query = "	SELECT
			proxy_acl_list.id,
			proxy_acl_list.nome,
			proxy_acl_list.sys,
			proxy_acl_net.stato
		FROM
			proxy_acl_list
		JOIN
			proxy_acl_net
		ON
			proxy_acl_net.idacllist = proxy_acl_list.id
			AND
			proxy_acl_net.idaclnet = $id
			AND
			proxy_acl_list.attivo = 1
		UNION DISTINCT SELECT
			proxy_acl_list.id,
			proxy_acl_list.nome,
			proxy_acl_list.sys,
			proxy_acl_list.dflt
		FROM
			proxy_acl_list
		WHERE
			proxy_acl_list.id NOT IN (SELECT idacllist FROM proxy_acl_net WHERE idaclnet = $id)
			AND
			proxy_acl_list.attivo = 1
		ORDER BY
			sys DESC,
			nome
";
$res = mysql_query( $query, $DB_ID );
?>
<script type="text/javascript">
function do_submit() {
  document.forms['acl'].submit();
}
</script>
<form name="acl" method="post">
<input type="hidden" name="id" value="<?php print $id ?>">
<?php	
$tabella = new html (0,"90%",array(2,20,2,6,6,6,2,20,0));
$tabella->intestazione (array ("","Rete","","Nega","Default","Autorizza","","Nome Lista",""), array("","","","radio","radio","radio","","",""));

$res = mysql_query( $query, $DB_ID );
$conta = 0;
while ($dato = mysql_fetch_array ( $res )) {
?>
	<tr>
		<td class="spaziol"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="descrizione"><?php if (!$conta++) { print $net; } ?></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="radio"><input type="radio" name="<?php print $dato['id']?>" value=-1 <?php if ($dato['stato'] == -1) { print "checked=\"checked\""; } ?> onChange="do_submit()"/></td>
		<td class="radio"><input type="radio" name="<?php print $dato['id']?>" value=0  <?php if ($dato['stato'] ==  0) { print "checked=\"checked\""; } ?> onChange="do_submit()"/></td>
		<td class="radio"><input type="radio" name="<?php print $dato['id']?>" value=1  <?php if ($dato['stato'] ==  1) { print "checked=\"checked\""; } ?> onChange="do_submit()"/></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="descrizione"><?php print $dato['nome'] ?></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
	</tr>
<?php
} 
$tabella->riga();
$tabella->close();
?>
</form>
<?php view_footer(); ?>
