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

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

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

		$query = "	INSERT INTO
					proxy_acl_ip
				SET
					idacllist = $key,
					idpool = $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 
			ip
		FROM
			proxy_pool
		WHERE
			id = $id
	";
$res = mysql_query( $query, $DB_ID );
$dato = mysql_fetch_array ( $res );
$ip = $dato['ip'];

$query = "	SELECT
			proxy_acl_list.id,
			proxy_acl_list.nome,
			proxy_acl_list.sys,
			proxy_acl_ip.stato
		FROM
			proxy_acl_list
		JOIN
			proxy_acl_ip
		ON
			proxy_acl_ip.idacllist = proxy_acl_list.id
			AND
			proxy_acl_ip.idpool = $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_ip WHERE idpool = $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">
<table cellpadding="0" cellspacing="0" border="0" width="90%">
<input type="hidden" name="id" value="<?php print $id ?>">
	<tr>
		<td class="sep" width="5%"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="sep" width="20%"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="sep" width="5%"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="sep" width="6%" ><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="sep" width="6%" ><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="sep" width="6%" ><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="sep" width="5%" ><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="sep" width="20%"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="sep" width="27%"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
	</tr>
	<tr>
		<td class="spaziol"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="descrizione">Indirizzo IP</td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="radio">Nega</td>
		<td class="radio">Default</td>
		<td class="radio">Autorizza</td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="descrizione">Nome Lista</td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
	</tr>
<?php
$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 $ip; } ?></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
} ?>
</table>
</form>
<img src="<?php print $CONF['base_url'] ?>/img/spazio.gif" width="1" height="20" alt="">
<?php view_footer(); ?>
