<?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-group-mod";
				checker_func($func);
					
				//更新数据
				$sql="update ".VI_DBMANPRE."group set status='".$status."' where id=".$id;
				mysql_query($sql,$mysql);
				
				$Project["queries"]++;
				
				if(mysql_affected_rows($mysql)){
					
					$Project["message"]="成功更改用户组状态!";					
					
					//写入日志
					event_insert($mysql,$func,time(),time(),"更改用户组状态：".$VICACHE["sys.group"][$id]["name"]);					
					
				}else{
					$Project["message"]="未找到指定用户组！";
				}
				
			break;
			
			case "delete":
			
				//检查权限
				$func = "sys-group-del";
				checker_func($func);
					
				//删除数据
				$sql="delete from ".VI_DBMANPRE."group where id=".$id;
				mysql_query($sql,$mysql);
				
				$Project["queries"]++;
	
				if(mysql_affected_rows($mysql)){
					
					$Project["message"]="成功删除用户组!";
					
					//写入日志
					event_insert($mysql,$func,time(),time(),"删除用户组：".$VICACHE["sys.group"][$id]["name"]);
					
				}else{
					$Project["message"]="未找到指定用户组!";
				}
				
			break;
			
		}	
			
		//缓存系统用户组
		cache_table('system',$mysql,VI_DBMANPRE."group",'<option value=\'{table:id}\'>{table:name}</option>');			
	
	}
	

	//search
	$s = GetQuery("s");
	$q = GetQuery("q");
	?>
		
	
    <div id="search">
        <form name="form1" method="get" action="">
            <span class="action">
            	<?php
				if( $Group["sys-group-add"]=="Y" ){
				?>
                	<button type="button" class="button" onclick="location.href='group.edit.php';">添加分组</button>
                <?php
				}
				?>
            </span>
            
             <select name="s" id="s" size="1">
               <option value="name">组名称</option>
               <option value="account">用户名</option>
               <option value="id">ID</option>
            </select>
            <input name="q" type="text" class="text" title="请输入关键字" id="q" value="<?php echo $q;?>">
            <button class="go" type="submit"></button>
        </form>
        
        <script type="text/javascript">
         Mo("#s").value("<?php echo $s;?>");
        </script>
    </div>

    <?php
    
    $sql="SELECT * FROM ".VI_DBMANPRE."group where 1=1 ";
    if ($s && $q){
        $sql.=" and  $s like '%".$q."%'";
    }
    
    $sql.=" order BY id 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&page=";	
    
    ?>
    
    <table width="100%" border="0" cellpadding="1" cellspacing="1" class="table" id="table">
      <tr class="title" id="thead">
        <td></td>
        <td>ID</td>
        <td>组名</td>
        <td>用户数</td>
        <td>创建者</td>
        <td>权限</td>
        <td>创建时间</td>
        <td>修改时间</td>
        <td>状态</td>
        <td width="70">操作</td>
      </tr>
    
    <?php
    
    $result=mysql_query($sql,$mysql);
    
    $Project["queries"]++;
    
    while($row=mysql_fetch_assoc($result)){
		
		$count = $db -> getValue("select count(id) from ".VI_DBMANPRE."admin where gid=".$row["id"]);
        
    ?>
        <tr class="line" edit="group.edit.php?action=edit&id=<?php echo $row["id"];?>&jump={jump}">
            <td width="30"><img src="<?php echo VI_BASE;?>image/medal/<?php echo "mini_".$row["medal"];?>" /></td>
            <td><?php echo $row["id"];?></td>
            <td><?php echo $row["name"];?></td>
            <td><a href="admin.list.php?s=gid&q=<?php echo $row["id"];?>"><?php echo $count;?></a></td>
            <td><a href="admin.edit.php?action=edit&id=<?php echo $row["aid"];?>"><?php echo $row["account"];?></a></td>
            <td><a href="group.power.php?gid=<?php echo $row["id"];?>" onclick="parent.Mo.Dialog('dialog','用户组配置 - <?php echo $row["name"];?>' , '<iframe src='+this.href+' frameborder=0></iframe>' ,'950','70%',{ 'remove' : true, 'draged' : true, 'create' : true }); return false;">查看</a></td>
            <td title="<?php echo date("Y-m-t H:i:s",$row["dateline"]);?>"><?php echo date("Y-m-t",$row["dateline"]);?></td>
            <td title="<?php echo date("Y-m-t H:i:s",$row["modify"]);?>"><?php echo date("Y-m-t",$row["modify"]);?></td>
            <td><?php echo $Project["status"][$row["status"]];?></td>
            <td>
            <script type="text/javascript">
				Mo.Tools("RsEdit","group.edit.php?action=edit&id=<?php echo $row["id"];?>","");
				Mo.Tools("RsDelete","?action=delete&id=<?php echo $row["id"];?>","");
            </script>
            </td>
        </tr>
        
    <?php
        
    }
    
    ?>
    </table>
    <?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();?>