<?php
include("qs.php");
require( '../data/config.php');
$conn=mysql_connect($db_host,$db_user,$db_pass);
mysql_query("set names 'utf8'");
mysql_select_db($db_name);
if (PHP_VERSION >= '5.1' && !empty($timezone))
{
    date_default_timezone_set($timezone);
}
$action=_get('action');
if($action=="")
$action=_post('action');
$id=_get('id');
if($id=="")
$id=_post('id');
$qs=explode(",",$_SESSION["tm_qs"]);
if($qs[0]==0)
   {
   echo "<script>location.href='main.php';</script>";
   exit();
   }
?>
<!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 http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<META http-equiv="Pragma" content="no-cache" />
<LINK href="css/general.css" rel="stylesheet" type="text/css" />
<LINK href="css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.js"></script>
<?php 
if($action=="del")
 {
if(isset($_POST['chkkindid']) && is_array($_POST['chkkindid'])){
foreach(_post('chkkindid') as $tempid){
   mysql_query("delete from tm_admin where id='$tempid' and id<>1");
}
}
 echo "<script>location.href='admin.php';</script>";
 exit();
 }
elseif($action=="add")
{
$user=_post('user');
$name=_post('name');
$pass=md5(_post('pass'));
$show1=1;
$date=date('Y-m-d');
$qs="0,0,0,0,0,0,0,0,0";
if(mysql_fetch_object(mysql_query("select * from tm_admin where user='$user'")))
  {
  echo "<script>alert('存在相同登录名称');history.go(-1);</script>";
  exit();
  }
$sql="insert into tm_admin(user,pass,show1,date,name,qs) values('$user','$pass','$show1','$date','$name','$qs')";
mysql_query($sql);
echo "<script>location.href='admin.php';</script>";
 exit();
}
elseif($action=="edit")
{
$name=_post('name');
$pass=_post('pass');
if($id<>1)
 {
if($pass<>"")
   $sql="update tm_admin set pass='".md5($pass)."',name='$name' where id='$id'";
else
  $sql="update tm_admin set name='$name' where id='$id'";
mysql_query($sql);
 }
else
{
mysql_query("update tm_admin set name='$name' where id=1");
}
if($id<>1)
echo "<script>location.href='admin.php';</script>";
else
{
if($pass<>"")
echo "<script>alert('wztm最高管理员不能在此处修改密码!');location.href='admin.php';</script>";
else
echo "<script>alert('更新成功!');location.href='admin.php';</script>";
}
exit();
}
?>
</HEAD><BODY>
<div class="h2">系统管理 >> 帐号管理 >> <?php if($id=="") echo "添加";else echo "编辑";?>帐号 </div>
<div class="list-div">

<table cellspacing='1' cellpadding='3'>
<tr>
  <th align='left'><table width="100" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><div align="left">&nbsp;&nbsp;帐号管理</div></td>
        <td width="150"><div align="center"><h1><span class="action-span"><a href="admin_w.php">添加</a></span></h1></div></td>
      </tr>
    </table></th>
</tr>
<tr><td align="left" valign="top" style="background:#F5F5F5;padding-bottom:8px;">
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0 CALLPADDING="0">
<?php 			  
if($action=="" and $id=="")
{
?>
<form id="form1" name="form1" method="post" action="admin_w.php">
			<TR BORDER="0" WIDTH="100%">
			                  <TD height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">登录名称：
                                  <input name="user" type="text" id="user" size="50" />
              </span>(提示：请用英文或拼音)</TD>
    </TR>
	<TR BORDER="0" WIDTH="100%">
			                  <TD height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">用户姓名：
                                  <input name="name" type="text" id="name" size="50" />
              </span>			                  </TD>
    </TR>
		<TR BORDER="0" WIDTH="100%">
			                  <TD height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">登录密码：
                                  <input name="pass" type="text" id="pass" size="50" />
          </span>			                  </TD>
    </TR>
			<TR BORDER="0" WIDTH="100%">
              <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left bgColor=#ffffff height=30><span class="help">
                  <input type="image" 
                        src="images/submit.gif" align="absmiddle" border="0" 
                        name="submit" onclick="return checkform(this.form)" />
                <input name="action" type="hidden" id="action" value="add" />
                </span></TD>
              </TR>
 </form>
 <script language="javascript">
function checkform(theform)
{
if(theform.user.value=="")
  {
  alert("登录名称不能为空！");
  theform.user.focus();
  return false;
  }
if(theform.name.value=="")
  {
  alert("用户名称不能为空！");
  theform.name.focus();
  return false;
  }
if(theform.pass.value=="")
  {
  alert("登录密码不能为空！");
  theform.pass.focus();
  return false;
  }
return true;
}
</script>
 <?php 
 }
if($action=="" and $id<>"")
{
$sql="select * from tm_admin where id='$id'";
$rsql=mysql_query($sql);
$rs=mysql_fetch_object($rsql);
if(!$rs)
   {
   echo "<script>alert('无相关会员!');location.href='admin.php'</script>";
   exit();
   }
 ?>
 <form id="form1" name="form1" method="post" action="admin_w.php">
			<TR BORDER="0" WIDTH="100%">
			                  <TD height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">登录名称：
                                  <input name="user" type="text" id="user" value="<?php echo $rs->user;?>" size="50" disabled="disabled" />
              </span>			                  <span style="PADDING-LEFT: 8px; PADDING-TOP: 8px"> </span>(提示：请用英文或拼音)</TD>
    </TR><TR BORDER="0" WIDTH="100%">
			                  <TD height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">用户姓名：
                                  <input name="name" type="text" id="name" value="<?php echo $rs->name;?>" size="50" />
              </span>			                  </TD>
    </TR>
		<TR BORDER="0" WIDTH="100%">
			                  <TD height="30"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">登录密码：
                                  <input name="pass" type="text" id="pass" size="50" />
&nbsp;&nbsp;          (提示：不修改请留空！)</span></TD>
    </TR>
			<TR BORDER="0" WIDTH="100%">
                <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left bgColor=#ffffff height=30><span class="help">
                  <input type="image" 
                        src="images/submit.gif" align="absmiddle" border="0" 
                        name="submit" onclick="return checkform(this.form)" />
                  <input name="action" type="hidden" id="action" value="edit" />
                  <input name="id" type="hidden" id="id" value="<?php echo $id;?>" />
                </span></TD>
    </TR>
 </form>
 <script language="javascript">
function checkform(theform)
{
if(theform.name.value=="")
  {
  alert("用户名称不能为空！");
  theform.name.focus();
  return false;
  }
return true;
}
</script>
 <?PHP }
 ?>
</TABLE>
</td>
</tr></table></div>

<?php include "boot.php";?>
</body></html>