<?php session_start();
	include_once("functions/init.php"); 
	$tmp = $thisUrl."adm1n/functions/koneksi.php";
	include_once ($tmp);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<?php
		$tmp = $thisUrl."adm1n/functions/head_section.php";
		include ($tmp);
		?>
    </head>	
	<body>
		<div class="se-pre-con"></div>
        <center>
			<table width="500">
				<tr valign="top">
					<td align="center">
						<br><br><br><br>
						<?php 
						$tmp = $thisUrl."adm1n/functions/logo.php";
						include ($tmp);
						
						$err = 1;		
						$aksi = (isset($_REQUEST["aksi"]) ? $_REQUEST["aksi"] : null);	
						if($aksi=="Change") {
							echo '
							<img src="'.$thisPage.'adm1n/images/loading.gif" border="0">';
							$oldpass =  $_REQUEST["oldpass"];
							$newpass  = $_REQUEST["newpass"];
							$renewpass = $_REQUEST["renewpass"];
							
							if ($newpass != $renewpass) {
								$err_msg = 1;
							} else {
								$sql = 
								"SELECT username, admin_id FROM user " .
								"WHERE admin_id = '".$_SESSION["iduser"]."' " .  
								"AND password = '".$oldpass."' ";
								
								if ($hasil = mysql_query($sql)) {
									if (mysql_num_rows($hasil) > 0) {
										while ($data = mysql_fetch_array($hasil)) {
											$sql2 = 
											"UPDATE user SET password = '".$newpass."' ". 
											"WHERE admin_id = '".$data["admin_id"]."'";
											//echo $sql2;
											if (mysql_query($sql2)) {
												$err_msg = 2;
											} else {
												$err_msg = 3;		
											}
										}
									} else {
										$err_msg = 4;
									}
								} 
							}
							//echo $err_msg;
							$_COOKIE["err_msg"] = $err_msg;
							//echo $_COOKIE["err_msg"];
							echo "<script language=JavaScript>";
							echo "	location.href = '".$thisPage."adm1n/?err_msg=$err_msg';";
							echo "</script>";
						} else {
							?>
                            <form method="post" action="" enctype="multipart/form-data" name="form1">
                                <table width="80%" cellpadding="3" cellspacing="1" border="0" bgcolor="#cccccc">
                                    <tr height="25" bgcolor="#006666">
                                        <td align="left" colspan="2">
                                            <font color="#FFFFFF">&nbsp;<strong>Change Password</strong></font>
                                        </td>
                                    </tr>
                                    <tr bgcolor="#FFFFFF" height="30">
                                        <td width="58%" align="left">Old Password</td>
                                        <td align="left"><input type="password" name="oldpass" size="25"></td>
                                    </tr>
                                    <tr bgcolor="#FFFFFF" height="30">
                                        <td align="left">New Password</td>
                                        <td align="left"><input type="password" name="newpass" size="25"></td>
                                    </tr>
                                    <tr bgcolor="#FFFFFF" height="30">
                                        <td align="left">Retype New Password</td>
                                        <td align="left"><input type="password" name="renewpass" size="25"></td>
                                    </tr>
                                    <tr bgcolor="#FFFFFF">
                                        <td colspan="2" align="right">
                                            <input type="submit" name="aksi" id="aksi" value="Change">
                                        </td>
                                    </tr>
                                </table>
                            </form>
                            <?php						
						}
						?>
					</td>
				</tr>
			</table>
		</center>
	</body>
</html>	
