<?
$C_126cmsadmin_tname = 'group_config';

include(dirname(__FILE__)."/global.php");



@$job=$submitted_vars['job'];
@$action=$submitted_vars['action'];
$postdb['gptype']=$submitted_vars['gptype'];



if($job == 'add' AND $action == 'add'){

	$postdb = $_POST['postdb'];
	
	$postdb['pwd']=md5($postdb['pwd']);

	//写入数据库
  $query = "insert into `w6_admin`
            (`userid`,`pwd`,`email`,`gptype`,`note`)
            values
            ('".$postdb['userid']."','".$postdb['pwd']."','".$postdb['email']."','".$postdb['gptype']."','".$postdb['note']."')";

  $result = mysql_query($query) or die(mysql_error());
  if ($result)
     {
       $showmsg = "添加成功！";
	   $formurl = "group.php";
     }
  else
     {
       $showmsg = "添加失败！";
	   $formurl = "group.php";
     }
	 
  include('showmsg.php');
  exit;

}

if($job == 'edit'){

	$id = $_GET['id'];
	
	$query="SELECT * FROM `w6_admin` WHERE `id` ='$id'";

  	$result=mysql_query($query) or die("Could not connect: " . mysql_error());
	
	$postdb['id']        =  stripslashes(mysql_result($result,"0","id"));
	$postdb['gptype']        =  stripslashes(mysql_result($result,"0","gptype"));
	$postdb['userid']        =  stripslashes(mysql_result($result,"0","userid"));
	$postdb['pwd']        =  stripslashes(mysql_result($result,"0","pwd"));
	$postdb['email']        =  stripslashes(mysql_result($result,"0","email"));
	$postdb['note']        =  stripslashes(mysql_result($result,"0","note"));
	$postdb['logintime']        =  stripslashes(mysql_result($result,"0","logintime"));
	$postdb['loginip']        =  stripslashes(mysql_result($result,"0","loginip"));
	
	//print_r($postdb);


}

if($job == 'edit' AND $action == 'edit'){

  $postdb = $_POST['postdb'];
  
 
  //比较有没有修改密码
	
	$query="SELECT * FROM `w6_admin` WHERE `id` ='".$postdb['id']."'";
  	$result=mysql_query($query) or die("Could not connect: " . mysql_error());
	$_pwd        =  stripslashes(mysql_result($result,"0","pwd"));
	
	if($postdb['pwd'] != $_pwd){
		$postdb['pwd']=md5($postdb['pwd']);
	}

  
  
  $query="UPDATE `w6_admin` 
          SET `gptype`='".$postdb['gptype']."' , `userid`='".$postdb['userid']."' , `pwd`='".$postdb['pwd']."' , `email`='".$postdb['email']."' , `note`='".$postdb['note']."' 
		  WHERE `id`=".$postdb['id']; 
		  
  $result = mysql_query($query) or die(mysql_error());
  if ($result)
     {
       $showmsg = "修改成功！";
	   $formurl = "group_add.php?job=edit&id=".$postdb['id'];
     }
  else
     {
       $showmsg = "修改失败！";
	   $formurl = "group_add.php?job=edit&id=".$postdb['id'];
     }

}

?>
<!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=gb2312" />
<title>后台管理</title>
<link href="css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
a:link {
	text-decoration: none;
	color: #000000;
}
a:visited {
	text-decoration: none;
	color: #000000;
}
a:hover {
	text-decoration: underline;
	color: #FF0000;
}
a:active {
	text-decoration: none;
	color: #000000;
}
.font_hs {
	color: #999999;
}
.pwd {
	width: 300px;
}
-->
</style>
</head>

<body>
<div align="center" class="font12">
  <table width="100%"  border="0" cellpadding="3" cellspacing="1" bgcolor="#A4B6D7">
    <tr>
      <td width="100%" height="22" align="center" background="images/titlebg.jpg">&nbsp;</td>
    </tr>
  </table>
  <br />
  <table width="100%" height="25" border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
      <td align="left" bgcolor="#FFFFFF"> [<a href="group.php" class="a_bt">后台管理组</a>] </td>
    </tr>
  </table>
  <br />
  <br />
  <table width="100%" border="0" cellpadding="0" cellspacing="0" class="table">
    <tr>
      <td height="22" align="left" class="head">后台管理组编辑</td>
    </tr>
        <tr>
      <td align="center">
	  <FORM name="formlist" action="" method="post">
	    <table width="99%" border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC" class="table2">
        <tr>
          <td width="34%" height="28" align="left" bgcolor="#FFFFFF">用户名 <span class="red">(*)</span></td>
          <td width="66%" align="left" bgcolor="#FFFFFF"><input name="postdb[userid]" class="pwd" id="postdb[userid]" value="<?=$postdb['userid']?>" /></td>
        </tr>
        <tr>
          <td height="28" align="left" bgcolor="#FFFFFF">用户密码 <span class="red">(*)</span></td>
          <td align="left" bgcolor="#FFFFFF"><input name="postdb[pwd]" type="password" class="pwd" value="<?=$postdb['pwd']?>" /></td>
        </tr>
        <tr>
          <td height="28" align="left" bgcolor="#FFFFFF">email</td>
          <td align="left" bgcolor="#FFFFFF"><input name="postdb[email]" class="pwd" value="<?=$postdb['email']?>" /></td>
        </tr>
        <tr>
          <td height="28" align="left" bgcolor="#FFFFFF">用户组 </td>
          <td align="left" bgcolor="#FFFFFF"><select name="postdb[gptype]" id="postdb[gptype]">
            
           <option value="1" <? if($postdb['gptype'] == 1) echo 'selected="selected"';?>>超级管理员</option>
           <option value="2" <? if($postdb['gptype'] == 2) echo 'selected="selected"';?>>管理员</option>
           <option value="3" <? if($postdb['gptype'] == 3) echo 'selected="selected"';?>>网站编辑</option>
          
          </select>
          </td>
        </tr>
        <tr>
          <td height="28" align="left" bgcolor="#FFFFFF">备注</td>
          <td align="left" bgcolor="#FFFFFF"><textarea name="postdb[note]" id="postdb[note]" cols="45" rows="5"><?=$postdb['note']?></textarea></td>
        </tr>
        <tr>
          <td height="28" bgcolor="#FFFFFF"><input name="postdb[id]" type="hidden" id="postdb[id]" value="<?=$postdb['id']?>" /></td>
          <td align="left" bgcolor="#FFFFFF"><input type="submit" value="提交" name="Submit" />
              <input name="job" type="hidden" id="job" value="<?=$job?>" /><input name="action" type="hidden" id="action" value="<?=$job?>" /></td>
        </tr>
      </table>
	  </form></td>
    </tr>
  </table>
  </div>
</body>
</html>
