<?php
include_once ("core/config.php");
include_once ("proxy/ext/function_proxy.php");
$UTENTE = login_proxy();
view_top_proxy();

if (isset ($_POST['id'])) {
	$modifica = 2;
	$id 		= $_POST['id'];
	$utente 	= $_POST['utente'];
	$password1 	= $_POST['password1'];
	$password2	= $_POST['password2'];

	if (($password1 != "ahg5t!frtb5@u&^!") && ($password1 == $password2)) {
		$querypwd = "pass = ENCRYPT('$password1'),";
	} else {
		$querypwd = "";
	}

	$testo = "L'utente e' stato correttamente modificato";
	$query = "UPDATE proxy_utenti SET $querypwd modifica = NOW() WHERE `id`=$id";
?>
<table cellpadding="0" cellspacing="0" border="0" width="90%">
	<tr>
		<td><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif" width="1" height="10" alt=""><td>
	</tr>
	<tr>
		<td>
<?php	if (mysql_query( $query, $DB_ID )) { ?>
<?php print $testo ?><br>
<?php	} else { ?>
Non e' stato possibile eseguire l'operazione richiesta a causa di un errore: <?php print mysql_error() ?><br>
<?php print $query ?><br>
<?php	} ?>
		</td>
	</tr>
	<tr>
		<td><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif" width="1" height="5" alt=""></td>
	</tr>
	<tr>
		<td><input type="button" value="Ok" onclick="location.href = 'main_proxy.php';"></button></td>
	</tr>
	<tr>
		<td><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif" width="1" height="10" alt=""></td>
	</tr>
</table>
<?php
} else {

	$bottone = "Modifica";
	$modifica = 1;
	$query = "SELECT * FROM proxy_utenti WHERE user = '".$UTENTE['user']."'";
	$res = mysql_query( $query, $DB_ID );
	$dato = mysql_fetch_array ( $res );
	$dato['password'] = "ahg5t!frtb5@u&^!";
}
?>

<?php if (($modifica == 0 || $modifica == 1) && !isset($_GET['rm'])) { ?>

<script type="text/javascript" src="<?php print $CONF['base_url'] ?>/jquery/jquery.js"></script>
<script type="text/javascript" src="<?php print $CONF['base_url'] ?>/jquery/jquery.validate.js"></script>
<script type="text/javascript" src="<?php print $CONF['base_url'] ?>/jquery/jquery.validate.password.js"></script>
<link rel="stylesheet" type="text/css" href="<?php print $CONF['base_url'] ?>/jquery/jquery.validate.password.css" />

<script type="text/javascript">
$(document).ready(function() 
{
	$("#modulo").validate( {
		rules: {
			password1: {
				password: "#utente",
				minlength: 0
			},
			password2: {
				equalTo: "#password1"
			}
		},
		messages: {
			password2: {
				equalTo: "Le due password devono essere uguali"
			}
		},

		errorPlacement: function(error, element) {
			error.prependTo( element.parent().next() );
		},
		success: function(label) {
			label.html("&nbsp;").addClass("checked");
		}
	});
});
</script>

<form action="chkpasswd_proxy.php" method="post" id="modulo">
<table cellpadding="0" cellspacing="0" border="0" width="90%">
<input type="hidden" name="id" value="<?php print $dato['id'] ?>">
<tr>
	<td><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif" width="30" height="1" alt=""></td>
	<td>Nome Utente</td>
	<td><?php print $dato['user']?></td>
	<td class="status" colspan="6"></td>
</tr>
<tr><td colspan="9"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif" width="1" height="5" alt=""></td></tr>
<tr>
	<td class="col1" colspan="9">
	<table cellpadding="0" cellspacing="0" border="0" width="100%">
		<tr>
			<td><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif" width="40" height="50" alt=""></td>
			<td class="label"><label id="lpassword" for="password">Password</label></td>
			<td><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif" width="10" height="1" alt=""></td>
			<td class="field" width="30"><input id="password1" name="password1" type="password" size="30" maxlength="32" value="<?php print $dato['password'] ?>" /></td>
			<td class="status" width="400">
				<div class="password-meter">
					<div class="password-meter-message">&nbsp;</div>
					<div class="password-meter-bg">
						<div class="password-meter-bar"></div>
					</div>
				</div>
			</td>
		</tr>
		<tr>
			<td><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif" width="40" height="50" alt=""></td>
			<td class="label"><label id="lpassword_confirm" for="password_confirm">Password</label></td>
			<td><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif" width="10" height="1" alt=""></td>
			<td class="field" width="30"><input id="password2" name="password2" type="password" size="30" maxlength="32" value="<?php print $dato['password'] ?>" /></td>
			<td class="status" width="400"></td>
		</tr>
		<tr><td colspan="9" class="spaziov"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif" width="1" alt=""></td></tr>
	</table>
	</td>
</tr>

<tr><td colspan="9"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif" width="1" height="5" alt=""></td></tr>
<tr><td align="center" colspan="9">
	<input type="submit" value="<?php print $bottone ?>">
	&nbsp;&nbsp;&nbsp;
	<input type="button" value="Annulla" onclick="location.href = 'main_proxy.php';"></button>
</td></tr>

<tr><td colspan="9"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif" width="1" height="10" alt=""></td></tr>
</table>
</form>
<?php } ?>

<?php view_footer_proxy(); ?>
