
<?php 
 
$PID = "change_pass";
$SC = $_SERVER["SCRIPT_NAME"];

require_once("lib/dbconn.php");
require_once("lib/form.php");
require_once("lib/functions.php");

title("Change Password");

$r = mysql_query("select * from tbl_user where nama_user = '".$_SESSION[uid]."' ");
$n = mysql_num_rows($r);
if($n > 0) $d = mysql_fetch_object($r);
mysql_free_result($r);

if($_GET[act] == "update"){
	$md5paz = md5($_GET[old_pass]);
	$md5paz1 = md5($_GET[new_pass]);
	//echo $md5paz."<br>".$d->pass_user;
	if ($md5paz != $d->pass_user;){
		echo "<script>alert('The password is not the same !')</script>";
		
	} else {
		mysql_query("update tbl_user set pass_user = '".$md5paz1."' where  nama_user = '".$_SESSION[uid]."' ");
		echo "<script>alert('Change password Sucess!')</script>";
	}
	echo "<script language='JavaScript'>document.location='index.php?p=$PID'</script>";
} else {


?>
<script type="text/javascript">
	function cek() {
    console.log("good");
    submitFlag = true;
    if(document.form2.new_pass.value.length!=6){
        submitFlag=false;
        alert("invalid length - 6 characters needed!");
    }
    return submitFlag;
}
</script>  

<form name="form2" id="form2" method="GET" onsubmit="return cek()" >
<input type="hidden" name="p" value="<?php echo $PID;?>"/>
<input type="hidden" name="idx" value="<?php echo $d->id;?>"/>
<input type="hidden" name="act" value="update"/>

<table class="gridtable_form" width="40%">
	<tr>
		<td><b>Name</b></td>
		<td>: 
			<input type="text" name="name" value="<?php echo $d->nama_lengkap; ?>" readonly="readonly">
		</td>
	</tr>
	<tr>
		<td><b>Old Password</b></td>
		<td>: 
			<input type="password" name="old_pass" id="old_pass" value="" required="required">
		</td>
	</tr>
	<tr>
		<td><b>New Password</b></td>
		<td>: 
			<input type="password" name="new_pass" id="new_pass" value="" required="required">
		</td>
	</tr>
	<tr>
		<td>&nbsp;</td>
		<td><input type="submit" onClick="cek();" value="Save"/></td>
	</tr>
</table>
</form>
<?php } ?>