<?php
session_start();
require_once "../init.php";
$GLOBALS["parentpath"] = file_exists("authority.inc.php")?".":"..";
if($_POST['UserID'])
{
	$UserID = $_POST['UserID'];
}
else
{
	$UserID = $_GET['UserID'];
}
if($_POST['key'])
{
	$key = $_POST['key'];
}
else
{
	$key = $_GET['key'];
}
$Password = $_POST['Password'];
$Password_C = $_POST['Password_C'];
$RealName = $_POST['RealName'];
$Email = $_POST['Email'];
$Tel = $_POST['Tel'];
$Zip = $_POST['Zip'];
$Addr = $_POST['Addr'];
$iStatus = $_POST['iStatus'];
$nicecall_line = $_POST['nicecall_line'];
$nicecall_user = $_POST['nicecall_user'];
$nicecall_pwd = $_POST['nicecall_pwd'];
$nicecall_name = $_POST['nicecall_name'];
$nicecall_group = $_POST['nicecall_group'];
$Edit = $_POST['Edit'];

if(!CheckHashKey('admins'.$UserID,$key)){
   $DB->close();
   die("非法入侵");
}
if($UserID != $_SESSION['AdmUserID_S'])require_once "../authority.inc.php";
if(!$Edit){
	$sql = "select * from admins where UserID='$UserID'";
	$AdminInfo = $DB->getdata($sql);

	$NiceCallInfo = explode("||",$AdminInfo[NiceCall]);
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" 
/>
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="/admin/lib/html5.js"></script>
<script type="text/javascript" src="/admin/lib/respond.min.js"></script>
<script type="text/javascript" src="/admin/lib/PIE_IE678.js"></script>
<![endif]-->


<!--[if IE 6]>
<script type="text/javascript" src="/admin/static/h-ui.admin/js/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>修改管理员</title>
<LINK href="../share/style.css" rel=stylesheet>
<script>
function check(form){
   if(form.UserID.value==""){
       alert("请输入用户名");
	   form.UserID.focus();
	   return false;
   }
   if(form.Password.value!=""){
	   if(form.Password.value!=form.Password_C.value){
		   alert("密码与确认密码不相同");
		   form.Password.focus();
		   return false;
	   }
   }
   if(form.RealName.value==""){
       alert("请输入真实姓名");
	   form.RealName.focus();
	   return false;
   }
}
</script>
<script src='../share/global.js'></script>
</head>
<body>


<? include "../share/top.php"?>
<div id="topLink">
<div id="topInfo">
	<span class="tTitle">员工管理</span>
	<span class="sarr"> >> </span>
	修改管理员<?=$AdminInfo['RealName']?>资料
	<span class="sarr"> >> </span>
	<a href="<?=$GLOBALS["parentpath"]?>/admins/admins_list.php">返回到员工管理</a>
</div>
</div><div class="page-container">
<!--子导航-->
<? include "admins_nav.inc.php"?>
<!--结束-->


	  <?
	  if($Edit==1){
		  $Password = trim($Password);
		  if($Password !='' && $Password == $Password_C ) $plus = "Password='".md5($Password)."',";
		  if($nicecall_line && $nicecall_user && $nicecall_pwd && $nicecall_name){
		  	$plus .= "NiceCall='$nicecall_line||$nicecall_user||$nicecall_pwd||$nicecall_name||$nicecall_group',";
		  }else{
			$plus .= "NiceCall='',";
		  }
		  $sql="update admins set $plus RealName='$RealName',".
			   "Email='$Email',Tel='$Tel',iStatus='$iStatus',Zip='$Zip',Addr='$Addr' where UserID='$UserID'";
		  $DB->query($sql);
		  echo "<center><br><br><br>修改管理员 $RealName 成功";
		  echo "<center><br><br><br><a href='admins_list.php'>[ 返 回 ]</a><br><br>";
	  }else{ 
	  ?>
      <form action="admins_edit.php" method="post" onSubmit="return check(this)">
        <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="table"  class="table table-border table-bordered table-hover table-bg table-sort">
          <tr id="tr">
            <td colspan="2">修改管理员<?=$AdminInfo['RealName']?>资料</td>
          </tr>
          <tr>
            <td width="45%" align="right">用户ID</td>
            <td>
			<input name="UserID" type="text" class="inputline" value="<?=$AdminInfo['UserID']?>" readonly>
             <font color='red'>*</font>
			 </td>
          </tr>
          <tr>
            <td align="right">密码:</td>
            <td><input name="Password" type="password" class="inputline">(如不修改密码请不要输入)</td>
          </tr>
          <tr>
            <td align="right">确认密码:</td>
            <td><input name="Password_C" type="password" class="inputline">(如不修改密码请不要输入)</td>
          </tr>
          <tr>
            <td align="right">真实姓名:</td>
            <td><input name="RealName" type="text" class="inputline" value="<?=$AdminInfo['RealName']?>">
                <font color='red'>*</font></td>
          </tr>
          <tr>
            <td align="right">E-Mail:</td>
            <td><input name="Email" type="text" class="inputline" value="<?=$AdminInfo['Email']?>"></td>
          </tr>
          <tr>
            <td align="right">电话:</td>
            <td><input name="Tel" type="text" class="inputline" value="<?=$AdminInfo['Tel']?>">
            </td>
          </tr>
          <tr>
            <td align="right">邮编:</td>
            <td><input name="Zip" type="text" class="inputline" value="<?=$AdminInfo['Zip']?>"></td>
          </tr>
          <tr>
            <td align="right">地址:</td>
            <td><input name="Addr" type="text" class="inputline" size="40" value="<?=$AdminInfo['Addr']?>"></td>
          </tr>
          <tr>
            <td align="right">是否激活:</td>
            <td>
              <input type="radio" name='iStatus' value="1" <?if($AdminInfo['iStatus']==1) echo 'checked' ?>>
              是
              <input type="radio" name='iStatus' value="0" <?if($AdminInfo['iStatus']==0) echo 'checked' ?>>
              否 </td>
          </tr>
          <tr>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr align="center">
            <td colspan="2">以下是该管理员的NiceCall网络秘书设置(相关的线路号和用户号, 请登陆网站秘书查询)</td>
          </tr>
          <tr>
            <td align="right">NiceCall路线号(系统号):</td>
            <td><input name="nicecall_line" type="text" class="inputline" id="nicecall_line" value="<?=$NiceCallInfo[0]?>"></td>
          </tr>
          <tr>
            <td align="right">NiceCall用户号:</td>
            <td><input name="nicecall_user" type="text" class="inputline" id="nicecall_user" value="<?=$NiceCallInfo[1]?>"></td>
          </tr>
          <tr>
            <td align="right">NiceCall用户密码:</td>
            <td><input name="nicecall_pwd" type="password" class="inputline" id="nicecall_pwd" value="<?=$NiceCallInfo[2]?>"></td>
          </tr>
          <tr>
            <td align="right">NiceCall显示名称:</td>
            <td><input name="nicecall_name" type="text" class="inputline" id="nicecall_name" value="<?=$NiceCallInfo[3]?>"></td>
          </tr>
          <tr>
            <td align="right">NiceCall所属组:</td>
            <td><input name="nicecall_group" type="text" class="inputline" id="nicecall_group" value="<?=$NiceCallInfo[4]?>"></td>
          </tr>
          <tr>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td colspan="2" align="center">
			    <input name="Edit" type="hidden" value="1">
				<input name="key" type="hidden" value="<?=$key?>">
				<input name="submit" type="submit" class="bt2" value="提交"> &nbsp; &nbsp;
                <input name="reset" type="reset" class="bt2" value="重置">
			</td>
          </tr>
        </table>
    </form>
	<?}?>
</div>
<? 
$DB->close();
include "../share/bottom.php"?>
</body>
</html>
