<?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_admin',$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="admin.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_admin where admin_id='".intval($_GET["admin_id"])."'");
	break;
}
if($action==""){	
?>
<table class="tb tb2 ">
  <tr class="header">
    <th style="text-align: center">ID</th>
    <th>用户名</th>
    <th>管理等级</th>
    <th>本次登录IP</th>
    <th>上次登录IP</th>
    <th>操作</th>
  </tr>
  <?php
  $sql="select * from ve123_admin".$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 admin_id desc limit $offset,$pagesize");
  while ($rs=$db->fetch_array($result))
  {
  ?>
   <tr>
    <td width="75" align="center"><?php echo $rs["admin_id"];?></td>
    <td width="174" ><?php echo $rs["adminname"];?></td>
	<td width="198" ><?php if($rs["arank"]==1) {echo "普通管理员";}elseif($rs["arank"]==10) {echo "超级管理员";};?></td>
    <td width="219" ><?php echo $rs["loginip"];?></td>
    <td width="185" ><?php echo $rs["lastloginip"];?></td>
    <td width="100" >
	<a href="?action=modify&admin_id=<?php echo $rs["admin_id"];?>">修改</a>&nbsp;&nbsp;
	<a href="?action=del&admin_id=<?php echo $rs["admin_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")
  {
      $admin_id=intval($_GET["admin_id"]);
	  $sql="select * from ve123_admin where admin_id='$admin_id'";
	  $rs=$db->get_one($sql);
	  $adminname=$rs["adminname"];
	  $arank=$rs["arank"];
	  $password=$rs["password"];
	  $admin_id=$rs["admin_id"];
	  $authoritys=$rs["authoritys"];
	  $rank=$rs["rank"];
	  $btn_txt="确定修改";
  }
  else
  {
     $btn_txt="确定添加";
  }
?>
<form id="form1" name="form1" method="post" action="?action=saveform">
<table class="tb tb2">
  <tr>
    <tr><th  class="partition"  colspan="5">管理员信息</th></tr>
  <tr>
    <td width="100" align="right">用户名:</td>
    <td>
      <input name="adminname" type="text" value="<?php echo $adminname?>" size="50" /></td>
  </tr>
  <tr>
      <td width="100" align="right">密码:</td>
      <td>
      <input name="password" type="text" size="50" /></td>
  </tr>
  <tr>
      <td width="100" align="right">管理等级:</td>
      <td>
      <input type="radio" name="arank" value="1" <?php if($arank==1){echo 'checked="checked"';}?> />普通管理员<input type="radio" name="arank" value="10" <?php if($arank==10){echo 'checked="checked"';}?> />超级管理员</td>
  </tr>
    <tr>
        <td width="100"style='text-align:right;'>1、日常管理</td>
        <td align="right"></td></tr>
    <tr>
        <td width="100"></td>
        <td align="left">
          	<input name='authoritys[]' type='checkbox' value='about' <?php if(TestPurview('about',$authoritys,$rank)){echo "checked";}?> class="checkbox">关于我们
            <input name='authoritys[]' type='checkbox' value='s_url' <?php if(TestPurview('s_url',$authoritys,$rank)){echo "checked";}?> class="checkbox">提交网址 
            <input name='authoritys[]' type='checkbox' value='keyadmin' <?php if(TestPurview('keyadmin',$authoritys,$rank)){echo "checked";}?> class="checkbox">关键词管理            <input name='authoritys[]' type='checkbox' value='msgadmin' <?php if(TestPurview('msgadmin',$authoritys,$rank)){echo "checked";}?> class="checkbox">留言管理 
        </td>
    </tr>
    <tr><td width="100"style='text-align:right;'>2、推广管理</td>
        <td align="right"></td></tr>
    <tr>
        <td width="100"></td>
        <td align="left">
        	<input name='authoritys[]' type='checkbox' value='tg_keysys' <?php if(TestPurview('tg_keysys',$authoritys,$rank)){echo "checked";}?> class="checkbox">竞价关键词设置 
          	<input name='authoritys[]' type='checkbox' value='tg_keyadmin' <?php if(TestPurview('tg_keyadmin',$authoritys,$rank)){echo "checked";}?> class="checkbox">竞价管理 
            <input name='authoritys[]' type='checkbox' value='tg_rightad' <?php if(TestPurview('tg_rightad',$authoritys,$rank)){echo "checked";}?> class="checkbox">右侧推广管理 
            <input name='authoritys[]' type='checkbox' value='tg_openadmin' <?php if(TestPurview('tg_openadmin',$authoritys,$rank)){echo "checked";}?> class="checkbox">开放平台管理 
        </td>
    </tr>
    <tr><td width="100"style='text-align:right;'>3、蜘蛛管理</td>
        <td align="right"></td></tr>
    <tr>
        <td width="100"></td>
        <td align="left">
        	<input name='authoritys[]' type='checkbox' value='spider' <?php if(TestPurview('spider',$authoritys,$rank)){echo "checked";}?> class="checkbox">登录蜘蛛 
          	<input name='authoritys[]' type='checkbox' value='spider_list' <?php if(TestPurview('spider_list',$authoritys,$rank)){echo "checked";}?> class="checkbox">网站列表 
            <input name='authoritys[]' type='checkbox' value='spider_list_all' <?php if(TestPurview('spider_list_all',$authoritys,$rank)){echo "checked";}?> class="checkbox">收录管理 
        </td>
    </tr>
    <tr><td width="100"style='text-align:right;'>4、流量联盟</td>
        <td align="right"></td></tr>
    <tr>
        <td width="100"></td>
        <td align="left">
        	<input name='authoritys[]' type='checkbox' value='union_web' <?php if(TestPurview('union_web',$authoritys,$rank)){echo "checked";}?> class="checkbox">网站管理  
          	<input name='authoritys[]' type='checkbox' value='union_code' <?php if(TestPurview('union_code',$authoritys,$rank)){echo "checked";}?> class="checkbox">联盟代码管理  
            <input name='authoritys[]' type='checkbox' value='union_make' <?php if(TestPurview('union_make',$authoritys,$rank)){echo "checked";}?> class="checkbox">流量管理 
        </td>
    </tr>
    <tr><td width="100"style='text-align:right;'>5、财务管理</td>
        <td align="right"></td></tr>
    <tr>
        <td width="100"></td>
        <td align="left">
        	<input name='authoritys[]' type='checkbox' value='card_type' <?php if(TestPurview('card_type',$authoritys,$rank)){echo "checked";}?> class="checkbox">点卡产品分类
          	<input name='authoritys[]' type='checkbox' value='card_admin' <?php if(TestPurview('card_admin',$authoritys,$rank)){echo "checked";}?> class="checkbox">点卡产品管理   
            <input name='authoritys[]' type='checkbox' value='card_make' <?php if(TestPurview('card_make',$authoritys,$rank)){echo "checked";}?> class="checkbox">点卡生成向导  
            <input name='authoritys[]' type='checkbox' value='card_log' <?php if(TestPurview('card_log',$authoritys,$rank)){echo "checked";}?> class="checkbox">会员充值记录  
            <input name='authoritys[]' type='checkbox' value='aipay' <?php if(TestPurview('aipay',$authoritys,$rank)){echo "checked";}?> class="checkbox">支付宝充值记录  
        </td>
    </tr>
    <tr><td width="100"style='text-align:right;'>6、系统设置</td>
        <td align="right"></td></tr>
    <tr>
        <td width="100"></td>
        <td align="left">
        	<input name='authoritys[]' type='checkbox' value='sys_skin' <?php if(TestPurview('sys_skin',$authoritys,$rank)){echo "checked";}?> class="checkbox">风格管理
            <input name='authoritys[]' type='checkbox' value='admin_sys' <?php if(TestPurview('admin_sys',$authoritys,$rank)){echo "checked";}?> class="checkbox">网站配置 
          	<input name='authoritys[]' type='checkbox' value='admin_admin' <?php if(TestPurview('admin_admin',$authoritys,$rank)){echo "checked";}?> class="checkbox">管理员(谨慎操作)            
            <input name='authoritys[]' type='checkbox' value='admin_user' <?php if(TestPurview('admin_user',$authoritys,$rank)){echo "checked";}?> class="checkbox">会员管理   
            <input name='authoritys[]' type='checkbox' value='admin_db' <?php if(TestPurview('admin_db',$authoritys,$rank)){echo "checked";}?> class="checkbox">数据库管理   
        </td>
    </tr>

  <tr>
    <td>&nbsp;</td>
    <td>
	<input type="hidden" name="admin_id" value="<?php echo $admin_id?>">
	<input type="hidden" name="do_action" value="<?php echo $do_action?>">
	<input type="submit" name="Submit" value="<?php echo $btn_txt?>" />	</td>
  </tr>
  </form>
</table>

<?php
}
function saveform(){
global $db;
   $adminname=trim($_POST["adminname"]);
   $password=$_POST["password"];
   $admin_id=intval($_POST["admin_id"]);
   $arank=intval($_POST["arank"]);
   $do_action=$_POST["do_action"];
   if($password==""){
	  $sql="select * from ve123_admin where admin_id='$admin_id'";
	  $rs=$db->get_one($sql);
	  $password=$rs["password"];
   }else{
	  $password=md5($password);   
   }
   foreach($_POST["authoritys"] as  $val){ 
     $authoritys.=$val.","; 
   }
   
   if($do_action=="modify"){
	  $array=array('adminname'=>$adminname,'password'=>$password,'admin_id'=>$admin_id,'arank'=>$arank,'authoritys'=>$authoritys);
	  $db->update("ve123_admin",$array,"admin_id='$admin_id'");
	  jsalert("修改成功");
   }else{     
      $array=array('adminname'=>$adminname,'password'=>$password,'admin_id'=>$admin_id,'arank'=>$arank,'authoritys'=>$authoritys);
	  $db->insert("ve123_admin",$array);  
	  jsalert("提交成功");
   }
}
?>
</div>
</body>
</html>