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

if (isset($_POST['id'])) {
	$id = $_POST['id'];
	$query = "	INSERT INTO
				condes_macchine
			SET
				id_proxy_pool = $id,
				data = NOW(),
				attivo = 1
	";
	$res = mysql_query( $query, $DB_ID );
}

$query = "	SELECT
			id,
			ip,
			nome
		FROM
			proxy_pool
		WHERE
			id NOT IN (SELECT id_proxy_pool FROM condes_macchine)
		ORDER BY
			-nome DESC,
			INET_ATON(ip) ASC
";

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

$tabella = new html (0,"90%",array(3,3,2,15,2,15,2,15,0));
?>
<form name="" method="post">
	<tr>
		<td colspan=3 class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="spazioh"><input type="image" src="<?php print $CONF['base_url'] ?>/img/addresource.png" border="0" alt="Inserisci" /></td>
		<td colspan=4 class="spazioh">
			<select name="id">
				<option value="" selected="selected">---</option>
<?php while ($dato = mysql_fetch_array ( $res )) { ?>
				<option value="<?php print $dato['id'] ?>"><?php print $dato['nome']." - ".$dato['ip'] ?></option>
<?php } ?>
			</select>
		</td>
		<td class="spaziov"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
	</tr>
</form>
<?php
$query = "	SELECT 
			condes_macchine.id, 
			condes_macchine.data, 
			condes_macchine.attivo,
			proxy_pool.ip,
			proxy_pool.nome
		FROM 
			condes_macchine 
		JOIN
			proxy_pool
			ON
				condes_macchine.id_proxy_pool = proxy_pool.id
		ORDER BY
			INET_ATON(ip) ASC
	";

$res = mysql_query( $query, $DB_ID );
while ($dato = mysql_fetch_array ( $res )) {
?>
	<tr>
		<td rowspan=2 class="col3btn">
<?php	if ($dato['attivo']) { ?>
		<a href="condes_gest.php?azione=macchina_down&id=<?php print $dato['id']?>"><img src="<?php print $CONF['base_url'] ?>/img/attivo.gif" ALT="Utente attivo" TITLE="Utente attivo"></a>
<?php	} else { ?>
		<a href="condes_gest.php?azione=macchina_up&id=<?php print $dato['id']?>"><img src="<?php print $CONF['base_url'] ?>/img/non_attivo.gif" ALT="Utente non attivo" TITLE="Utente non attivo"></a>
<?php	} ?>
		</td>
		<td rowspan=2 class="spazioh"><a href="condes_gest.php?azione=macchina_rm&id=<?php print $dato['id']?>"><img src="<?php print $CONF['base_url'] ?>/img/trash.png"></a></td>
		<td rowspan=2 class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="descrizione">IP</td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="descrizione">Nome</td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="descrizione">Ultima Modifica</td>
		<td rowspan=2 class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		</td>
	</tr>
	<tr>
		<td class="colip"><?php print $dato['ip'] ?></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="colip"><?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>
	</tr>
<?php	
$tabella->riga (); 
} 
$tabella->close();
view_footer(); 
?>
