<?php
# Name: PHP版程氏文章CMS管理系统 v3.0
# Author: 程氏<web@chshcms.com> [QQ:848769359]
# Homepage:http://www.chshcms.cn/
include_once("../../lib/cs_label.php");
include_once("../loginstate.php");
SystemPer('0_1');
$ac=CS_Request("ac");
$op=CS_Request("op");
if(empty($ac)) $ac='main';
?>
<!doctype html>
<html>
<head>
<meta charset="gbk">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>chshdjcms management</title>
<link href="../res/css/admin_style.css" rel="stylesheet" />
<link href="../../public/css/webox.css" rel="stylesheet" />
<script type="text/javascript" src="../res/js/ajax.js"></script>
<script language="javascript" src="../res/js/jquery.js"></script>
<script src="../../public/js/webox.js"></script>
<script language="javascript">

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function del(_id){ 
  if (confirm("确定删除吗,确定将删除该会员的所有有关信息？")){
    window.location='?op=del&id='+_id;
    return true;
  }else{
     return false;
  }		
}
</script>
</head>
<body>
<div class="wrap">
<?php
   //主列表
   if($ac=='main'){
                $op=CS_Request("op");
                $key=CS_Request("key");
                $vip=CS_Request("vip");
                $so=CS_Request("so");
                $sid=CS_Request("sid");
		global $db;
                $sql="select * from ".Getdbname('user')." where 1=1 ";
                if($vip){
                      $sql.=" and cs_vip=".$vip."";
                }
                if($sid){
                      $sql.=" and cs_sid=".$sid."";
                }
                if($key){
                      $sql.="and ".$so." like '%".$key."%' ";
                }
                $sql.=" order by CS_AddTime desc";
		$newsnum=$db->num_rows($db->query($sql));
		$Arr=getpagerow($sql,20);//sql,每页显示条数
		$result=$db->query($Arr[2]);

?>
<div class="nav">
	<ul class="cc">
		<li<?php if($ac=="main") echo ' class="current"';?>><a href="?">会员列表</a></li>
		<li<?php if($ac=="edit") echo ' class="current"';?>><a href="javascript:Popsboxif('添加会员',450,470,'user_add.php');">添加会员</a></li>
	</ul>
</div>
	<div class="h_a">搜索</div>	<form method="get" action="user.php">
	<div class="search_type cc mb10">
		<div class="ul_wrap">
			<ul class="cc">
				<li>
					<label>关键字：</label><select class="select_1" name='so'><option value='CS_Name' >名称</option><option value='CS_QQ' >QQ</option><option value='CS_Email' >Enail</option></select><input name="key" value="" type="text" class="input length_2" placeholder="会员名搜索">&nbsp;&nbsp;<button class="btn mr20" type="submit">搜索</button>
				</li>
				<li>
					<label>按级别：</label><select class="select_3" onchange="MM_jumpMenu('self',this,0)">
                                                <option value="user.php">选择级别</option>
                                                <option value="?">全部会员</option>
            					<option value='?vip=0' >普通会员</option>   
            					<option value='?vip=1' >VIP会员</option>            
                                         </select>
				</li>
				<li>
					<label>按状态：</label><select class="select_3" onchange="MM_jumpMenu('self',this,0)">
                                                <option value="user.php">选择状态</option>
            					<option value='?sid=1' >已锁定</option>   
            					<option value='?sid=0' >未锁定</option>            
                                         </select>
				</li>
			</ul>
		</div>
	</div>
</form>
<form class="J_ajaxForm" action="news.php?op=delall" method="post" name="formb">
<div class="table_list">
<?php
	if($newsnum==0){
                echo "<table width=\"100%\">
				<tbody>
					<tr><td class=\"tac\">啊哦，没有符合条件的内容！</td></tr>
				</tbody>
		</table>";

        }else{
                echo "<table width=\"100%\" id=\"dellist\">
		<thead>
			<tr>
				<td><label>选</label></td>
				<td>名称</td>
				<td><span>QQ</span></td>
				<td><span>Email</span></td>
				<td><span>地区</span></td>
				<td><span>登入次数</span></td>
				<td><span>登入IP</span></td>
				<td><span>金币</span></td>
				<td><span>推荐</span></td>
				<td><span>VIP</span></td>
				<td><span>审核</span></td>
				<td><span>注册时间</span></td>
				<td>编辑/删除</td>
			</tr>
		</thead>";
        }
        if($result){
	     while ($row = $db ->fetch_array($result)){
			if(date("Y-m-d",strtotime($row['CS_AddTime']))==date('Y-m-d')){
				$addtime="<font color=red>".date("Y-m-d",strtotime($row['CS_AddTime']))."</font>";
			}else{
				$addtime=date("Y-m-d",strtotime($row['CS_AddTime']));
			}
                        if($row['CS_Vip']==1){
				$Uvip="<img src=\"../res/images/yes.gif\" title=\"VIP会员\" style=\"cursor:pointer\">";
			}else{
				$Uvip="<img src=\"../res/images/no.gif\" title=\"普通会员\" style=\"cursor:pointer\">";
			}
			if($row['CS_SID']==1){
                                $shenhe='<a href="?op=jiesuo&id='.$row["CS_ID"].'&sid=0" title="点击解锁"><img src="../res/images/no.gif"/></a>';
                        }else{
                                $shenhe='<a title="点击锁定该会员" href="?op=jiesuo&id='.$row["CS_ID"].'&sid=1"><img src="../res/images/yes.gif"/></a>';
                        }
			if($row['CS_TID']==0){
                                $Utui='<a href="?op=tui&id='.$row["CS_ID"].'&tid=1" title="点击推荐"><img src="../res/images/no.gif"/></a>';
                        }else{
                                $Utui='<a title="点击取消" href="?op=tui&id='.$row["CS_ID"].'&tid=0"><img src="../res/images/yes.gif"/></a>';
                        }
                  echo "<tr>
				<td><input type=\"checkbox\" class=\"J_check\" name=\"CS_ID[]\" value=\"".$row['CS_ID']."\" id=\"CS_ID\"/>&nbsp;".$row['CS_ID']."</td>
				<td><a href=\"".userlink('index',$row['CS_ID'])."\" target=\"web\">".$row['CS_Name']."</a></td>
				<td>".$row['CS_QQ']."</td>
				<td>".$row['CS_Email']."</td>
				<td>".$row['CS_City']."</td>
				<td>".$row['CS_LogNum']."</td>
				<td>".$row['CS_LogIP']."</td>
				<td>".$row['CS_Cion']."</td>
				<td>".$Utui."</td>
				<td>".$Uvip."</td>
				<td>".$shenhe."</td>
				<td>".$addtime."</td>
				<td><a href=\"javascript:Popsboxif('添加会员',450,470,'user_add.php?id=".$row['CS_ID']."');\">编辑</a> &nbsp;&nbsp;<a style=\"cursor:pointer;\"  onclick=\"del(".$row['CS_ID'].")\">删除</a></td>
			</tr>";
             }
        }
?>
	</table>
			<div class="p10">
				<div class="pages">
				     <?php if($newsnum>20) echo $Arr[0];?>
                                </div>
			</div>
</div>
<div class="btn_wrap">
	<div class="btn_wrap_pd">
                <label class="mr20"><input type="checkbox" class="J_check_all" id="chkall" onClick="return CheckAll(this.form)" value="on">全选</label>
		<input name="button1" type="button" class="btn J_ajax_submit_btn" value="批量删除" onClick="UserInfo(this.form)">
		<input name="button2" type="button" class="btn btn_submit" value="发送消息" onClick="UserInfo(this.form,'xiaoxi')">
		<input name="button3" type="button" class="btn btn_submit" value="发送邮件" onClick="UserInfo(this.form,'mail')">
                <div class="tips_error" id="Msg"></div>
	</div>
</div>
</form>
<?php
          //审核
          if($op=='jiesuo'){
		global $db;
		$CS_ID=CS_Request("id");
		$CS_SID=CS_Request("sid");
                $sql="update ".Getdbname('user')." set CS_SID=".$CS_SID." where CS_ID=".$CS_ID;
		if($db->query($sql)){
			echo "<script>window.location='javascript:history.go(-1);';</script>";
		}
          }
          //推荐
          if($op=='tui'){
		global $db;
		$CS_ID=CS_Request("id");
		$CS_TID=CS_Request("tid");
                $sql="update ".Getdbname('user')." set CS_TID=".$CS_TID." where CS_ID=".$CS_ID;
		if($db->query($sql)){
			echo "<script>window.location='javascript:history.go(-1);';</script>";
		}
          }
          //删除
          if($op=='del'){
		global $db;
		$CS_ID=CS_Request("id");
                $us=$db->Getrow("select CS_Name from ".Getdbname('user')." where CS_ID=".$CS_ID."");
		if($us){
                        ###############################删除相册###########################################################
	                $rs=$db->query("select * from ".Getdbname('pic')." where CS_User='".$us['CS_Name']."' order by CS_id desc");
	                $num=$db->num_rows($rs);
	                for($i=0;$i<$num;$i++){
		                $row=$db->fetch_array($rs);
	 	                $fileurl="../../annex/pic/".$row['CS_Pic'];
	 	                if(file_exists($fileurl)){
	   	                     @unlink($fileurl);
	 	                }
	                }
                        ###############################删除图片###########################################################
	                $rss=$db->query("select * from ".Getdbname('photo')." where CS_User='".$us['CS_Name']."' order by CS_id desc");
	                $nums=$db->num_rows($rss);
	                for($i=0;$i<$nums;$i++){
		                $row1=$db->fetch_array($rss);
	 	                $fileurl="../../annex/pic/".$row1['CS_Url'];
	 	                if(file_exists($fileurl)){
	   	                     @unlink($fileurl);
	 	                }
	                }
                        ###############################删除头像###########################################################
                        $fileurl="../../annex/logo/big/".$us['CS_Logo'];
                        $fileurl2="../../annex/logo/small/".$us['CS_Logo'];
	 	        if(file_exists($fileurl)){
	   	            @unlink($fileurl);
                            @unlink($fileurl2);
	 	        }
                        ###############################删除歌曲###########################################################
	                $rs2=$db->query("select * from ".Getdbname('dance')." where CS_User='".$us['CS_Name']."' order by CS_id desc");
	                $nums=$db->num_rows($rs2);
	                for($i=0;$i<$nums;$i++){
		                $row2=$db->fetch_array($rs2);
	 	                $fileurl="../../annex/music/".$row2['CS_PlayUrl'];
	 	                if(file_exists($fileurl)){
	   	                     @unlink($fileurl);
	 	                }
	                }
                        ###############################删除专集图片###########################################################
	                $rs3=$db->query("select * from ".Getdbname('topic')." where CS_User='".$us['CS_Name']."' order by CS_id desc");
	                $nums=$db->num_rows($rs3);
	                for($i=0;$i<$nums;$i++){
		                $row3=$db->fetch_array($rs3);
	 	                $fileurl="../../annex/topic/".$row3['CS_Pic'];
	 	                if(file_exists($fileurl)){
	   	                     @unlink($fileurl);
	 	                }
	                }

                        $db->query("delete from ".Getdbname('dt')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('fav')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('down')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('dance')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('news')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('topic')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('pl')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('blog')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('pay')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('pic')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('photo')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('xiaoxi')." where CS_Usera='".$us['CS_Name']."' or  CS_Userb='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('funco')." where CS_Usera='".$us['CS_Name']."' or  CS_Userb='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('fans')." where CS_Usera='".$us['CS_Name']."' or  CS_Userb='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('friend')." where CS_Usera='".$us['CS_Name']."' or  CS_Userb='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('gbook')." where CS_Usera='".$us['CS_Name']."' or  CS_Userb='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('user')." where CS_ID=".$CS_ID."");
                        echo '<script>document.getElementById("Msg").className="tips_success";$("#Msg").text("恭喜,删除成功!").css("color","#026E12");</script>';
	                echo "<script>setTimeout(\"window.location='javascript:history.go(-1);'\",2000);</script>";
		}
          }

          //批量删除
          if($op=='delall'){
		global $db;
		$CS_ID=CS_RequestBox("CS_ID");
	        $Arr=explode(',',$CS_ID);
		for($i=0;$i<count($Arr);$i++){
                        $us=$db->Getrow("select CS_Name from ".Getdbname('user')." where CS_ID=".$Arr[$i]."");

                        ###############################删除相册###########################################################
	                $rs=$db->query("select * from ".Getdbname('pic')." where CS_User='".$us['CS_Name']."' order by CS_id desc");
	                $num=$db->num_rows($rs);
	                for($i=0;$i<$num;$i++){
		                $row=$db->fetch_array($rs);
	 	                $fileurl="../../annex/pic/".$row['CS_Pic'];
	 	                if(file_exists($fileurl)){
	   	                     @unlink($fileurl);
	 	                }
	                }
                        ###############################删除图片###########################################################
	                $rss=$db->query("select * from ".Getdbname('photo')." where CS_User='".$us['CS_Name']."' order by CS_id desc");
	                $nums=$db->num_rows($rss);
	                for($i=0;$i<$nums;$i++){
		                $row1=$db->fetch_array($rss);
	 	                $fileurl="../../annex/pic/".$row1['CS_Url'];
	 	                if(file_exists($fileurl)){
	   	                     @unlink($fileurl);
	 	                }
	                }
                        ###############################删除头像###########################################################
                        $fileurl="../../annex/logo/big/".$us['CS_Logo'];
                        $fileurl2="../../annex/logo/small/".$us['CS_Logo'];
	 	        if(file_exists($fileurl)){
	   	            @unlink($fileurl);
                            @unlink($fileurl2);
	 	        }
                        ###############################删除歌曲###########################################################
	                $rs2=$db->query("select * from ".Getdbname('dance')." where CS_User='".$us['CS_Name']."' order by CS_id desc");
	                $nums=$db->num_rows($rs2);
	                for($i=0;$i<$nums;$i++){
		                $row2=$db->fetch_array($rs2);
	 	                $fileurl="../../annex/music/".$row2['CS_PlayUrl'];
	 	                if(file_exists($fileurl)){
	   	                     @unlink($fileurl);
	 	                }
	                }
                        ###############################删除专集图片###########################################################
	                $rs3=$db->query("select * from ".Getdbname('topic')." where CS_User='".$us['CS_Name']."' order by CS_id desc");
	                $nums=$db->num_rows($rs3);
	                for($i=0;$i<$nums;$i++){
		                $row3=$db->fetch_array($rs3);
	 	                $fileurl="../../annex/topic/".$row3['CS_Pic'];
	 	                if(file_exists($fileurl)){
	   	                     @unlink($fileurl);
	 	                }
	                }

                        $db->query("delete from ".Getdbname('dt')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('fav')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('down')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('dance')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('news')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('topic')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('pl')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('blog')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('pic')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('photo')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('pay')." where CS_User='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('xiaoxi')." where CS_Usera='".$us['CS_Name']."' or  CS_Userb='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('funco')." where CS_Usera='".$us['CS_Name']."' or  CS_Userb='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('fans')." where CS_Usera='".$us['CS_Name']."' or  CS_Userb='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('friend')." where CS_Usera='".$us['CS_Name']."' or  CS_Userb='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('gbook')." where CS_Usera='".$us['CS_Name']."' or  CS_Userb='".$us['CS_Name']."'");
                        $db->query("delete from ".Getdbname('user')." where CS_ID=".$Arr[$i]."");
		}
                        echo '<script>document.getElementById("Msg").className="tips_success";$("#Msg").text("恭喜,删除成功!").css("color","#026E12");</script>';
	                echo "<script>setTimeout(\"window.location='javascript:history.go(-1);'\",2000);</script>";
          }
   }
?>
</div>
</body>
</html>