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

if (isset($_POST['rif']) && $_POST['rif'] != "") {
	$id = $_POST['id'];
	$rif = $_POST['rif'];

	$query = "	INSERT INTO
				proxy_acl
			SET
				idacllist = $id,
				rif = '$rif',
				attivo = 1,
				data = NOW()
		";
	$res = mysql_query( $query, $DB_ID );
} elseif (isset($_POST['id'])) {
	$id = $_POST['id'];
	$nome = $_POST['nome'];
	$dflt = $_POST['dflt'];
	if ($id) {
		$query = "	UPDATE
					proxy_acl_list
				SET
					nome = '$nome',
					dflt = $dflt,
					data = NOW()
				WHERE
					id = $id";
		$res = mysql_query( $query, $DB_ID );
	} else {
		$query = "	INSERT INTO
					proxy_acl_list
				SET
					nome = '$nome',
					attivo = 1,
					sys = 0,
					dflt = $dflt,
					data = NOW()
		";
		$res = mysql_query( $query, $DB_ID );
		$id = mysql_insert_id();
	}
} elseif (isset($_GET['id'])) {
	$id = $_GET['id'];
} else {
	$id = 0;
}
?>

<form name="" method="post">
<input type="hidden" name="id" value="<?php print $id ?>">
<?php
if ($id) {
	$query = "	SELECT 
				id,
				nome,
				attivo,
				dflt,
				DATE_FORMAT(data, '%d.%m.%Y %H:%i:%s') AS data
			FROM
				proxy_acl_list
			WHERE
				id = $id
		";

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

	$query = "	SELECT
				id,
				rif,
				attivo,
				DATE_FORMAT(data, '%d.%m.%Y %H:%i:%s') AS data
			FROM
				proxy_acl
			WHERE
				idacllist = $id
			ORDER BY
				rif
			";
	$res = mysql_query( $query, $DB_ID );
}
$tabella = new html (0,"90%", array(3,3,20,2,15,0));
$tabella->intestazione (array("","","Nome ACL","","Ultima Modifica",""));
?>
	<tr>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
<?php
if ($dato['attivo']) {
?>
		<td class="col3btn"><a href="proxy_gest.php?azione=acl_down&id=<?php print $dato['id']?>"><img src="<?php print $CONF['base_url'] ?>/img/attivo.gif" ALT="ACL Attiva" TITLE="ACL Attiva"></a></td>
<?php	} else { ?>
		<td class="col3btn"><a href="proxy_gest.php?azione=acl_up&id=<?php print $dato['id']?>"><img src="<?php print $CONF['base_url'] ?>/img/non_attivo.gif" ALT="ACL non Attiva" TITLE="ACL non Attiva"></a></td>
<?php	} ?>
		<td class="colip"><input type="text" size="16" name=nome value="<?php print $dato['nome'] ?>"></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="colip"><?php print $dato['data'] ?></td>
		<td colspan=3class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
	</tr>
<?php $tabella->riga(); ?>
	<tr>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td colspan="3">
<?php $tabella2 = new html (0,"100%",array(20,20,20,20,0), "center"); ?>
			<tr>
				<td rowspan=2 class="descrizione_c">Default</td>
				<td class="descrizione_c">Nega</td>
				<td class="descrizione_c">Default</td>
				<td class="descrizione_c">Autorizza</td>
				<td rowspan=2 class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
			</tr>
			<tr>
				<td class="radio"><input type="radio" name="dflt" value=-1 <?php if ($dato['dflt'] == -1) { print "checked=\"checked\""; } ?> ></td>
				<td class="radio"><input type="radio" name="dflt" value=0  <?php if ($dato['dflt'] ==  0) { print "checked=\"checked\""; } ?> ></td>
				<td class="radio"><input type="radio" name="dflt" value=1  <?php if ($dato['dflt'] ==  1) { print "checked=\"checked\""; } ?> ></td>
			</tr>
<?php $tabella2->close(); ?>
		</td>
		<td><input type="submit" value="Conferma"></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
	</tr>
<?php if ($id) { 
$tabella->riga();
?>
	<tr>
		<td rowspan=2 colspan=2 class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="descrizione">Nuova destinazione</td>
		<td rowspan=2 colspan=2 class="spazioh"><input type="image" src="<?php print $CONF['base_url'] ?>/img/add_link.png" border="0" alt="Submit" /></td>
		<td rowspan=2 colspan=3 class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
	</tr>
	<tr>
		<td class="colip"><input type="text" size="20" name=rif></td>
	</tr>
<?php $tabella->riga();
 		while ($dato = mysql_fetch_array ( $res )) { ?>
	<tr>
		<td class="spazioh"><a href="proxy_gest.php?azione=link_rm&id=<?php print $dato['id']?>"><img src="<?php print $CONF['base_url'] ?>/img/trash.png"></a></td>
<?php 			if ($dato['attivo']) { ?>
		<td class="col3btn"><a href="proxy_gest.php?azione=link_down&id=<?php print $dato['id']?>"><img src="<?php print $CONF['base_url'] ?>/img/attivo.gif" ALT="ACL Attiva" TITLE="ACL Attiva"></a></td>
<?php			} else { ?>
		<td class="col3btn"><a href="proxy_gest.php?azione=link_up&id=<?php print $dato['id']?>"><img src="<?php print $CONF['base_url'] ?>/img/non_attivo.gif" ALT="ACL non Attiva" TITLE="ACL non Attiva"></a></td>
<?php		} ?>
		<td class="colip"><?php print $dato['rif']?></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="colip"><?php print $dato['data']?></td>
		<td colspan=3 class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
	</tr>
<?php 	} 
} 
$tabella->close();
?>
</form>
<?php view_footer(); ?>
