<?php
/**
 * @version        Somao_Search X1.0 9:23 2012-1-1 Somao $
 * @package        Somao_Search.Site
 * @copyright      Copyright (c) 2009 - 2012, Somao, Inc.
 * @license        http://www.somao123.com/
 * @link           http://www.somao.cc/
**/
require "global.php";
CheckPurview('admin_user',$authoritys,$rank);
?>
<!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=gbk">
<meta http-equiv="x-ua-compatible" content="ie=7" />
<link href="css/admincp.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container">
  <div class="floattop">
    <div class="itemtitle"><h3>会员列表</h3>
      <ul class="tab1">
        <li <?php if($action=="" ){echo 'class="current"';}?>><a href="member.php"><span>会员列表</span></a></li>
        <li <?php if($action=="add"){echo 'class="current"';}?>><a href="?action=addform"><span>添加会员</span></a></li>
      </ul>
     </div>
   </div>
 <div class="floattopempty"></div>
<?php
$action=$_GET["action"];
switch ($action)
{
    case "saveform":
    saveform();
    break;

    case "addform":
	addform($action);
	break;
	
	case "modify":
	addform($action);
	break;
	
	case "del":
	$db->query("delete from ve123_member where user_id='".intval($_GET["user_id"])."'");
	break;
}
if($action==""){
?>
<table class="tb tb2 ">
  <tr class="header">
    <th style="text-align: center">ID</th>
    <th>用户名</th>
    <th>积分</th>
    <th>贡献</th>
    <th>邮箱</th>
    <th><p>客户类型</p><p>（0.普通客户 1.代理）</p></th>
    <th>操作</th>
  </tr>
  <?php
  $sql="select * from ve123_member".$where;
  $result=$db->query($sql);
  $total=$db->num_rows($result);//记录总数
  $pagesize=30;//每页显示数
  $totalpage=ceil($total/$pagesize);
  $page=intval($_GET["page"]);
  if($page<=0){$page=1;}
  $offset=($page-1)*$pagesize;
  
  $result=$db->query($sql." order by user_id desc limit $offset,$pagesize");
  while ($rs=$db->fetch_array($result))
  {
  ?>
  <tr>
    <td width="39" align="center"><?php echo $rs["user_id"];?></td>
    <td width="118"><?php echo $rs["user_name"];?></td>
    <td width="101"><?php echo $rs["points"];?></td>
    <td width="101"><?php echo $rs["scores"];?></td>
    <td width="197"><?php echo $rs["email"];?></td>
    <td width="157"><?php echo $rs["user_group"];?></td>
    <td width="157"><a href="?action=modify&user_id=<?php echo $rs["user_id"];?>">修改</a>&nbsp;&nbsp; <a href="?action=del&user_id=<?php echo $rs["user_id"];?>" onclick="if(!confirm('确定删除吗?')) return false;">删除</a></td>
  </tr>
  <?php

}
?>
   <tr>
    <td height="36" colspan="9" align="center" bgcolor="#F9FCEF">
    <?php echo pageshow($page,$totalpage,$total,"?");?>
    </td>
  </tr>
  </table>
<?php
}
?>
<?php
function addform($do_action)
{
global $db,$p_cid;
  if ($do_action=="modify")
  {
      $user_id=intval($_GET["user_id"]);
	  $sql="select * from ve123_member where user_id='$user_id'";
	  $rs=$db->get_one($sql);
	  $user_name=$rs["user_name"];
	  $password=$rs["password"];
	  $email=$rs["email"];
	  $user_group=$rs["user_group"];
	  $user_id=$rs["user_id"];
	  $points=$rs["points"];
	  $scores=$rs["scores"];
	  $sort_id=$rs["sort_id"];
	  $btn_txt="确定修改";
  }
  else
  {
     $btn_txt="确定添加";
  }
?>
<form id="form1" name="form1" method="post" action="?action=saveform">

<table class="tb tb2">
    <tr><th  class="partition"  colspan="5">管理员信息</th></tr>
  <tr>
    <td width="100" align="right">用户名:</td>
    <td>
      <input name="user_name" type="text" value="<?php echo $user_name?>" size="50" /></td>
  </tr>
    <tr>
      <td align="right">密码:</td>
      <td>
      <input name="password" type="text" value="<?php echo $password?>" size="50" />
      <span class="STYLE3"> 注意：</span><span class="STYLE4">这里可以直接输入密码，无需输入MD5值。</span></td>
  </tr>
  <tr>
    <td align="right">积分:</td>
    <td><input name="points" type="text" value="<?php echo $points?>" size="50" /></td>
  </tr>
  <tr>
    <td align="right">贡献:</td>
    <td><input name="scores" type="text" value="<?php echo $scores?>" size="50" /></td>
  </tr>
  <tr>
    <tr>
      <td align="right">邮箱:</td>
    <td><input name="email" type="text" size="50"  value="<?php echo $email?>"/></td>
  </tr>
  <tr>
    <tr>
      <td align="right">客户类型:</td>
    <td><input name="user_group" type="text" size="50"  value="<?php echo $user_group?>"/>
      <span class="STYLE3">注意：</span><span class="STYLE4">请输入数字：（0.普通客户 2.代理）</span></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>
	<input type="hidden" name="user_id" value="<?php echo $user_id?>">
	<input type="hidden" name="do_action" value="<?php echo $do_action?>">
	<input type="submit" name="Submit" value="<?php echo $btn_txt?>" />	</td>
  </tr>
</table>
  </form>
<?php
}
?>

<?php
function saveform()
{
global $db;
   $user_name=trim($_POST["user_name"]);
   $password=trim($_POST["password"]);
   $email=trim($_POST["email"]);
   $user_group=trim($_POST["user_group"]);
   $user_id=intval($_POST["user_id"]);
   $points=trim($_POST["points"]);
   $scores=trim($_POST["scores"]);
   $do_action=$_POST["do_action"];
   if ($do_action=="modify")
   {
	$array=array('user_name'=>$user_name,'password'=>md5($password),'email'=>$email,'user_group'=>$user_group,'user_id'=>$user_id,'points'=>$points,'scores'=>$scores);
	 $db->update("ve123_member",$array,"user_id='$user_id'");
	 jsalert("修改成功");
   }
   else
   {     
    $array=array('user_name'=>$user_name,'password'=>md5($password),'email'=>$email,'user_group'=>$user_group,'user_id'=>$user_id,'points'=>$points,'scores'=>$scores);
	 $db->insert("ve123_member",$array);  
	 jsalert("提交成功");
   }
}
?>
</div>
</body>
</html>