<?php
include_once ("core/config.php");
$UTENTE = login();
//isadmin();

$id = $_GET['id'];
$nome = creanome ($id);

$query = "SELECT * FROM rule WHERE iddefrule = $id ORDER BY ipin";
$res = mysql_query( $query, $DB_ID );
$quanti = mysql_num_rows ($res);

?>

<?php include_once ("top_mini.php"); ?>

<script language="JavaScript" type="text/javascript">
<!--
var num=<?php print $quanti ?>;
function accoda(){
	if(document.createElement && document.getElementById && document.getElementsByTagName) {
		// crea elementi
		var oTr=document.createElement("TR");
		var oTd1=document.createElement("TD");
		var oTd2=document.createElement("TD");
		var oTd3=document.createElement("TD");
		var oTd4=document.createElement("TD");
		var oTd5=document.createElement("TD");
		var oField1=document.createElement("INPUT");
		var oField2=document.createElement("INPUT");
		var oField3=document.createElement("INPUT");
		var oField4=document.createElement("INPUT");
		var oButt=document.createElement("INPUT");

		// setta attributi
  		oField1.setAttribute("type","text");
		oField1.setAttribute("name","fromip"+num);
		oField1.setAttribute("size",15);
  		oField2.setAttribute("type","text");
		oField2.setAttribute("name","fromport"+num);
		oField2.setAttribute("size",5);
		oField2.setAttribute("value",0);
  		oField3.setAttribute("type","text");
		oField3.setAttribute("name","toip"+num);
		oField3.setAttribute("size",15);
  		oField4.setAttribute("type","text");
		oField4.setAttribute("name","toport"+num);
		oField4.setAttribute("size",5);
		oField4.setAttribute("value",0);
		oTd5.setAttribute("align","center");
		oButt.setAttribute("type","checkbox");
		oButt.setAttribute("name","check"+num);

		// appendi al relativo padre
		oTd1.appendChild(oField1);
		oTd2.appendChild(oField2);
		oTd3.appendChild(oField3);
		oTd4.appendChild(oField4);
		oTd5.appendChild(oButt);
		oTr.appendChild(oTd1);
		oTr.appendChild(oTd2);
		oTr.appendChild(oTd3);
		oTr.appendChild(oTd4);
		oTr.appendChild(oTd5);
		document.getElementById('tabella').getElementsByTagName('TBODY')[0].appendChild(oTr);

		// incrementa variabile globale
		num++;
		document.forms.modulo.quanti.value=num;
	}
}
//-->
</script>
</head>
<body>
<form name="modulo" id="modulo" action="modrule.php" method="post">
<input type="hidden" name="iddefrule" value="<?php print $id ?>">
<input type="hidden" name="quanti" value="<?php print $quanti ?>">
<table cellpadding="0" cellspacing="0" border="0" width="90%" id="tabella">
<tbody>

	<tr><td colspan="5" align="left"><?php print "Regole per $nome <br>"?></td></tr>
	<tr><td colspan="5"><img src="img/spazio.gif" width="1" height="10" alt=""></td></tr>

	<tr>
		<td>Dall'IP</td>
		<td>Dalla porta</td>
		<td>All'IP</td>
		<td>Alla porta</td>
		<td>Attiva</td>
	</tr>
<?php for ($conta = 0; $conta < $quanti; $conta++) { 
		$dato = mysql_fetch_array ( $res ); 
?>
	<tr>
		<input type="hidden" name="idrule<?php print $conta?>" value="<?php print $dato['id'] ?>">
		<td class="campo"><input type="text" size="15" name="fromip<?php print $conta?>" value="<?php print $dato['ipin'] ?>"/></td>
		<td><input type="text" size="5" name="fromport<?php print $conta?>" value="<?php print $dato['portin'] ?>"/></td>
		<td><input type="text" size="15" name="toip<?php print $conta?>" value="<?php print $dato['ipout'] ?>"/></td>
		<td><input type="text" size="5" name="toport<?php print $conta?>" value="<?php print $dato['portout'] ?>"/></td>
		<td align="center"><input type="checkbox" name="check<?php print $conta?>" checked /></td>
	</tr>

<?php } ?>
</tbody>
</table>
<table cellpadding="0" cellspacing="0" border="0" width="90%" id="pulsanti">
<tbody>
	<tr><td colspan="3"><img src="img/spazio.gif" width="1" height="7" alt=""></td></tr>
	<tr><td colspan="3" align="center"><input type="button" value="accoda" onclick="accoda()" /></td></tr>
	<tr><td colspan="3"><img src="img/spazio.gif" width="1" height="7" alt=""></td></tr>
	<tr>
		<td width="33%" align="center"><input type="submit" value="Inserisci" onclick="accoda()" /></td>
		<td width="33%" align="center"><img src="img/spazio.gif" width="1" height="1" alt=""></td>
		<td width="33%" align="center"><input type="button" value="Annulla" onclick="window.opener.location.reload(); window.close(); return false;""></button></td>
	</tr>
	<tr><td colspan="3"><img src="img/spazio.gif" width="1" height="7" alt=""></td></tr>
</tbody>
</table>
</form>

<?php include_once ("footer_mini.php"); ?>
