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

if (isset($_POST['id'])) {
	$prefisso 	= 	$_POST['prefisso'];
	$da	 	= 	$_POST['da'];
	$a	 	= 	$_POST['a'];
	$a	 	= 	$_POST['a'];
	$lung 		= 	$_POST['lung'];
	$lpwd 		= 	$_POST['lpwd'];
	$tempo 		= 	$_POST['tempo'];

	if ($a == "") $a = $da;

	$lunghezza = $lung - strlen ($prefisso);
	$parametro = "0".$lunghezza."d";
	for ($i=$da;$i<=$a;$i++) {
		$utgruppo = sprintf ("%s%$parametro",$prefisso,$i);
		$pwgruppo = generateStrongPassword($length = $lpwd, $add_dashes = false, $available_sets = 'lud');

		$query = "	INSERT INTO
					proxy_utenti
				SET
					user = '$utgruppo',
					pass = ENCRYPT('$pwgruppo'),
					fullname = 'Utente Guest',
					data = NOW(),
					modifica = NOW(),
					guest = 1,
					attivo = 1,
					tempo = $tempo
		";
		$res = mysql_query( $query, $DB_ID );
	}
?>
<script type="text/javascript">
        document.location.href="users_group_lista.php"
</script>
<?php

}
?>

<form name="" method="post">
<input type="hidden" name="id" value="0">
<?php
$tabella = new html (0,"90%",array(2,10,10,16,2,10,0));
$tabella->intestazione (array ("","Prefisso","","Intervallo","","Lunghezza",""), array("","","","radio","","",""));
?>
	<tr>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="colip"><input type="text" size="16" name="prefisso"></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="radio">
			<input type="text" size="4" name="da">
			&nbsp;-&nbsp;
			<input type="text" size="4" name="a">
		</td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="colip"><input type="text" size="3" name="lung" value=8></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		</td>
	</tr>
<?php 
$tabella->riga();
$tabella->intestazione (array ("","Lunghezza Password","","Tempo assegnato (h)","","","")); 
?>
	<tr>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="colip"><input type="text" size="3" name="lpwd" value=8></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="colip"><input type="text" size="3" name="tempo" value=24></td>
		<td colspan=3 class="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 class="spaziov" colspan=6><input type="submit" value="Conferma"></td>
	</tr>
<?php $tabella->close(); ?>
</form>
<?php view_footer(); ?>
