<?php

require_once('include/config.php');
session_start();
if(!isset($_SESSION['admin_name'])){
   header("location:admin_login.php");
}

if(isset($_GET['act']) && $_GET['act']=='mod')
{
$id=$_GET['id'];
$username=$_POST['username'];
$password=$_POST['password'];
$oldpassword=$_POST['oldpassword'];
$oldpass=$_POST['oldpass'];

if(empty($oldpassword)){
   echo "<script>window.alert('旧密码不能为空！');window.history.back();</script>";
   exit;
}
if(empty($password)){
   echo "<script>window.alert('新密码不能为空！');window.history.back();</script>";
   exit;
}
if(md5($oldpassword) != $oldpass){
   echo "<script>window.alert('旧密码不正确！');window.history.back();</script>";
   exit;
}

//判断密码是否修改，如果修改则md5加密，不修改则为原值
if($password==$oldpassword)
{
   $newpassword=$password;
}
else
{
   $newpassword=md5($password);
}

//echo $newpassword;

$exec="update admin set username='".$username."',password='".$newpassword."' where id='$id'";
mysql_query($exec);

session_destroy();
die("<script>window.alert('密码修改成功，请重新登录！');window.document.location.href='admin_login.php';</script>");
}
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo webname.version ?></title>
<link rel="stylesheet" type="text/css" href="include/main.css" />
</head>

<body>
<?php 
require_once('head.php');

$exec="select * from admin where username='".$_SESSION['admin_name']."'";
$result=mysql_query($exec);
$rs=mysql_fetch_array($result)
?>
<br>
<table width="240" border="0" cellspacing="0" cellpadding="0" align="center">
<form action="" method="post" name="modpass">
  <tr>
    <td height="25"></td>
    <td height="25"><strong>修改管理密码</strong></td>
  </tr>
  <tr>
    <td width="59" height="25" align="right">用户名：&nbsp;</td>
    <td width="181" height="25"><label>
      <?php echo $rs['username'];?><input name="username" type="hidden" class="loginput" id="username" value="<?php echo $rs['username'];?>" />
    </label></td>
  </tr>
  <tr>
    <td height="25" align="right">旧密码：&nbsp;</td>
    <td height="25"><label>
      <input name="oldpassword" type="password" class="loginput" id="oldpassword" />
      <input type="hidden" name="oldpass" id="oldpass" value="<?php echo $rs['password'];?>">
    </label></td>
  </tr>
  <tr>
    <td height="25" align="right">新密码：&nbsp;</td>
    <td height="25"><label>
      <input name="password" type="password" class="loginput" id="password" />
    </label></td>
  </tr>
  <tr>
    <td height="25">&nbsp;</td>
    <td height="25"><label>
      <input name="Submit" type="submit" class="botton" value="修 改" />
    </label></td>
  </tr></form>
</table>
<br />
</body>
</html>
