<?php

/*
*	Copyright VeryIDE,2007-2010
*	http://www.veryide.com/
*
*	$Id:veryide.user.php ,v1 10:39 2008-09-05 Leilei $
*/

require("../../include/header.php");
html_start("系统用户 - VeryIDE");
?>

<!--body start-->
	<?php
	
	//loader
	loader_setting("naver.admin");
	
	//菜单处理
	$action = GetQuery("action");
	$jump = GetQuery("jump");
	
	//mysql open
	reader_mysql();	
	
	$id = GetNumber("id",0);
	$status = GetNumber("status",0);
	
	if($action){
	
		//动作处理
		switch ($action){
			
			case "status":
			
				//检查权限
				$func = "sys-admin-mod";
				checker_func($func);
				
				//更新数据
				$sql="update ".VI_DBMANPRE."admin set status='".$status."' where id=".$id;
				mysql_query($sql,$mysql);
				
				$Project["queries"]++;
				
				if( mysql_affected_rows($mysql) ){					
					
					//写入日志
					event_insert($mysql,$func,time(),time(),"更新用户：".$VICACHE["sys.admin"][$id]["name"]);				
					
					//$Project["message"]="成功更改用户状态!";
					reader_redirect($jump,"成功更改用户状态!");
				}else{
					//$Project["message"]="未找到指定用户!";
					reader_redirect($jump,"未找到指定用户!");
				}
				
				//$Project["jump"] = '';
					
			break;
			
			case "delete":
			
				//检查权限
				$func = "sys-admin-del";
				checker_func($func);
					
				//删除数据
				$sql="delete from ".VI_DBMANPRE."admin where id=".$id;
				mysql_query($sql,$mysql);
				
				$Project["queries"]++;
	
				if(mysql_affected_rows($mysql)){
					$Project["message"]="成功删除用户!";
				}else{
					$Project["message"]="未找到指定用户!";
				}
				
				$Project["jump"] = '';				
					
				//写入日志
				event_insert($mysql,$func,time(),time(),"删除用户：".$VICACHE["sys.admin"][$id]["name"]);				
				
			break;
			
		}
		
		//缓存系统用户
		cache_table('system',$mysql,VI_DBMANPRE."admin",'<option value=\'{table:id}\'>{table:account}</option>');
	
	}
	

	//search
	$s = GetQuery("s");
	$q = GetQuery("q");
	$line = GetQuery("line");	
	$gid = GetNumber("gid",0);
	
	//查看方式
	$v = GetQuery("v");
	$v=$v?$v:"list";
	
	?>
    
    <div id="search">
        <form name="form1" method="get" action="">
            <span class="action">
                <button type="button" class="button" onclick="location.href='admin.edit.php';">添加用户</button>
                <button type="button" class="cancel" onclick="location.href='<?php echo VI_BASE;?>api/get.csv.php?do=admins';">数据下载</button>
            </span>
            
             <select name="s" id="s">
               <option value="account">用户名</option>
               <option value="blog">主页</option>
               <option value="email">电子邮件</option>
            </select>
            <input name="q" type="text" class="text" title="请输入关键字" id="q" value="<?php echo $q;?>">
             
             <select name="line" id="line">
               <option value="">全部状态</option>
               <option value="on">在线</option>
               <option value="off">离线</option>
            </select>
			
             <select name="gid" id="gid">
               <option value="">全部分组</option>
				<?php
				
				foreach( $VICACHE["sys.group"] as $g => $cfg ){				   
				   echo '<option value="'.$g.'">'.$cfg["name"].'</option>';				   
				}
				
				?>
            </select>
			
           <button class="go" type="submit"></button>
        </form>
        
        <script type="text/javascript">
			Mo("#s").value("<?php echo $s;?>");
			Mo("#line").value("<?php echo $line;?>");
			Mo("#gid").value("<?php echo $gid;?>");
        </script>
    </div>
    
		
	<?php
	
	$sql="SELECT * FROM ".VI_DBMANPRE."admin where 1=1 ";
	
	if ($s && $q){
		$sql.=" and  $s like '%".$q."%'";
	}
	
	switch( $line ){
		
		case "on":			
			$sql.=" and ".time()." - last_active <= 30";
		break;
		
		case "off":			
			$sql.=" and ".time()." - last_active >= 30";
		break;
	}
	
	if ( $gid ) $sql.=" and gid = ".$gid;
	
	$sql.=" order by id desc,status desc";
	
	//查询数据库_总记录数
	$result=mysql_query($sql,$mysql);		
	$row_count=mysql_num_rows($result);	
	
	$Project["queries"]++;

	//分页参数
	$page=GetPage("page");
	$page_start=$Global["pagesize"]*($page-1);
	$sql=$sql." limit $page_start,".$Global["pagesize"];
	
	//分页链接
	$url="?s=".$s."&q=$q&line=$line&gid=$gid&v=$v&page=";	
	
	//var_dump($VICACHE);
	
	$result=mysql_query($sql,$mysql);
	
	
    echo '
    <p id="viewer">
        <strong>查看方式：</strong> 
		<a href="'.preg_replace("/&v=(.*?)&/","&v=list&",$url).'" '.($v=="list"?'class="active"':'').'>通讯录</a>
		<a href="'.preg_replace("/&v=(.*?)&/","&v=show&",$url).'" '.($v=="show"?'class="active"':'').'>成员秀</a>
    </p>
    ';
    
    /********************/
	
	$active = array('list','show');
		
    if( in_array($v,$active) ){
    
   		require("include/admin.".$v.".php");
	
	}
    
    /********************/   
	
  
    //mysql close
    reader_mysql(true);
    
    ?>
    
    <div id="saving">
		<?php
            echo GetPageLink($page,$row_count,$Global["pagesize"],$url,"page");
        ?>
    </div>
    
<!--body end-->

<?php html_close();?>