<?php
require_once("../web.config.php");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="robots" content="noindex,nofollow" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="../themes/<?php echo $themes_Path; ?>/main.css" rel="stylesheet" type="text/css" />
<script language="javascript">

function form1_onsubmit()
{
	if (document.form1.UserName.value=="")
    {
      document.form1.UserName.focus();
	  window.alert("用户名不能为空！！！");
      return false;  
     }
	 if (document.form1.password1.value=="")
     {
      document.form1.password1.focus();
      window.alert("请输入密码！！！");
      return false;
     }
	 if (document.form1.password2.value=="")
     {
      document.form1.password2.focus();
      window.alert("请输确认入密码！！！");
      return false;
     }
	 if (document.form1.password1.value!= document.form1.password2.value)
     {
      document.form1.password1.focus();
      window.alert("密码输入不一致！！！");
      return false;
     }
}
</script>

</head>
<body  id="bodyBg1">
<br />
&nbsp; <a href="adminUser_Manage.php">用户管理</a> | <a href="adminUser_Add.php">添加用户</a>
<hr color="#0099FF" size="1" />
<br />
<dl class="manageContent">
    <dt>用户修改管理</dt>
    <dd>
    	<br />
<?php
if (isset($_POST["UserName"]) ){
	$UserName=$_POST["UserName"];
	$password1=md5($_POST["password1"]);
	//password2=Request.Form("password2")
	$Purview=$_POST["purview"];
	$id=$_POST["id"];
	
	$sql_serach="select *  from deep_Admin where fuserName='".$UserName."' ";
	$stmt=$conn->query($sql_serach);
	if($row=$stmt->fetch() ){
		
		if($row["id"]==$id){
			userUpdate($UserName,$password1,$Purview,$id,$conn);
		}else{
			echo ("<p align='center'>[". $UserName ."] 已被注册，请注册其它名称</p>");
		}
		
	}else{
		userUpdate($UserName,$password1,$Purview,$id,$conn);
	}
}

if(isset($_GET["id"]) && is_numeric($_GET["id"]) ){
	$id=$_GET["id"];
	$sql="select * from deep_Admin where id=". $id;
	//echo $sql;
	$stmt=$conn->query($sql);
	if($row=$stmt->fetch() ){
?>
        <form id="form1" name="form1" method="post" action="" onsubmit="return form1_onsubmit()">
          <table width="60%" border="0" align="center" class="tableBoderForm">
            <tr>
              <td height="30">用户名称：</td>
              <td><input type="text" name="UserName" value="<?php echo $row["fuserName"]; ?>" />
              &nbsp;&nbsp;* 必添项</td>
            </tr>
            <tr>
              <td height="30">用户密码：</td>
              <td><input type="password" name="password1" /></td>
            </tr>
            <tr>
              <td height="30">确认密码：</td>
              <td><input name="password2" type="password" /></td>
            </tr>
            <tr>
              <td height="30">管理权限：</td>
              <td><select name="purview" id="purview">
                <option value="管理员" selected="selected">管理员</option>
              </select></td>
            </tr>
            <tr>
              <td height="30"><input type="hidden" name="id" value="<?php echo $id;  ?>"/></td>
              <td><input type="submit" name="Submit" value="修改" />
              <input type="reset" name="Reset" value="重置" /></td>
            </tr>
          </table>
        </form>
<?php 
	}
}
?>
<br />
        <br />
    </dd>
</dl>
<br />
</body>
</html>
<?php 
function userUpdate($UserName,$password1,$Purview,$id ,$conn){
		$sql_update="update deep_Admin set fuserName='".$UserName."',fpassword='".$password1."',fpurview='".$Purview."' where id=".$id ;
		//echo $sql_update ;
		$okCount=$conn->exec($sql_update);
		if($okCount>0){
			echo ("<p align='center'>用户：[". $UserName ."] 修改成功</p>");
		}else{
			echo ("<p align='center'>用户：[". $UserName ."] 修改不成功</p>");
		}
	
	}
?>