<?php

/*
*	Copyright VeryIDE,2007-2010
*	http://www.veryide.com/
*
*	2011/6/5 Lay
*/

require '../../include/loader.php';
html_start("会员列表 - VeryIDE");
?>

<!--body start-->
<?php

	//module
    require 'naver.php';
    
	$q = getgpc('q');
	$s = getgpc("s");
	$base = $_GET["b"];
	
 	//批处理列表
	$list = getgpc('list');
	$list = is_array($list) ? implode(",", $list) : $list;
    
	//上一页
	$jump = getgpc('jump');
    
	$state = getnum("state",1);
	$order = getgpc("order");
	$action = getgpc('action');
	
	//连接数据库
	System :: connect();

	if ($action){
	
		switch($action){
			//删除
			case "delete":
			
				//检查权限
				System :: check_func("mod-member-del", false );		
			
				System :: $db -> execute("DELETE FROM `mod:member`  WHERE id in(".$list.")");
				
				System :: redirect($appid.".list.php","用户删除成功!");
				
			break;
			
			case "state":
			
				//检查权限
				System :: check_func("mod-member-mod", false );		
			
				$sql="UPDATE `mod:member` SET state=".$state." WHERE id in(".$list.")";
				System :: $db -> execute($sql);
				
				System :: redirect($jump,"用户状态更改成功!");

			break;
		}
	}
    
    ?>

    <div id="search">
    <form name="formSearch" id="formSearch" method="get" action="?">
    	<span class="action">
			<button class="button" onclick="Mo('#formAdv').toggle(0,function(ele,s){if(!s){ Mo('#formAdv input').checked(false); Mo('#formSearch').submit(); }});" type="button">高级选项</button>
        </span>
        
        <select name="s" id="s">
            <option value="id" checked> I D</option>
            <option value="name" checked> 真实姓名</option>
            <option value="account"> 用户名称</option>
            <option value="qq" checked> QQ 号码</option>
            <option value="phone"> 电话号码</option>
            <option value="idcard" checked> 身份证</option>
        </select>
        <input name="q" type="text" class="text" id="q" value="<?php echo $q;?>">
        
        <button class="go" type="submit"></button>
        
        <div id="formAdv" class="advanced" style="display:none;">        
			<?php
            foreach ($_G['module']['member']["fieds"] as $fied => $name){
                echo '<label><input name="b['.$fied.']" value="1" type="checkbox" class="checkbox" '.($base[$fied]?' checked="checked"':'').' onchange="Mo(\'#formSearch\').submit();" onclick="Mo(\'#formSearch\').submit();" ignore="true" /> '.$name.'</label>';
            }
            ?>        
        </div>
        
    </form>
    </div>
    
    <script type="text/javascript">
         Mo("#s").value("<?php echo $s;?>");
		
		<?php
		if( is_array($base) ){
			echo "Mo('#formAdv').toggle();";
		}
		?>
        
        Mo.reader(function(){
            
            <?php
            //只针对新增内容
            if($_GET['mark']){
            ?>
            //操作提示
            Mo.Tips(null,$("mark-<?php echo $_GET['mark'];?>"),'info','点这里开始新增表单选项，鼠标指向“小灯泡”将会有小提示。',document,'click',-20,15);
            <?php
            }
            ?>
            
        });
    </script>

    <!--用于动作处理_开始-->
    <form name="formPost" id="formPost" method="post">
        <input name="action" id="action" type="hidden" value="" />        
        <input name="state" id="state" type="hidden" value="" />
        
        <input name="jump" type="hidden" value="" />
        <script>Mo('#formPost input[name=jump]').value( location.href );</script>
    
    <?php		
    $sql="SELECT * FROM `mod:member` WHERE 1=1 ";
    if ($q && $s){
        $sql.=" and `".$s."` like '%".$q."%'";
    }
    $sql.=" order BY id desc";
    
    //查询数据库_总记录数
    $row_count = System :: $db -> getCount( $sql );

    //分页参数
    $page=getpage("page");
    $page_start=$_G['setting']['global']['pagesize']*($page-1);
    $sql=$sql." limit $page_start,".$_G['setting']['global']['pagesize'];
	
    //分页链接
    $url="?q=".$key."&s=".$s."&".format_get("b",$base)."&page=";
    
    $result = System :: $db -> getAll( $sql );
	
    ?>
    
	<?php
    
    //表格统计
    $x = 0;
    
    //用户数据
    if( is_array($base) ){
        foreach ($_G['module']['member']["fieds"] as $fied => $name){
            if( $base[$fied] ){
				$thead .= '<td>'.$name.'</td>';
				$x++;
			}
            
        }
    }
    
    ?>
    
    <table width="100%" border="0" cellpadding="1" cellspacing="1" id="table" class="table">
		<?php
		if( count($result)> $_G['setting']['global']['pagesize']/2 ){
		?>
        <tr class="thead">
            <td colspan="<?php echo ($x+6);?>" class="first"><?php echo $_G['module']['member']['tool'];?></td>
        </tr>
      	<?php
		}
		?>
      
        <tr class="title" id="thead">
            <td width="30"></td>
            <td>ID</td>
            <td>用户名</td>
            <td>活动</td>
            <?php echo $thead;?>
            <td>状态</td>
            <td width="70">操作</td>
        </tr>
      
    <?php
    //VeryIDE 绝对路径
    $url_path=url_path();
    
    foreach( $result as $row ){
        
        //配置
        $config = fix_json( $row['config'] );
		
		//读取用户信息
		$user = array();
		
		if( is_array($base) && $row['id'] ){
			
			$sql="SELECT * FROM `mod:member` WHERE id='".$row['id']."'";
			
			System :: $db -> query($sql);
			$user = System :: $db -> fetchRow();
		}
        
        ?>
          <tr class="<?php echo zebra( $i, array( "line" , "band" ) );?>" mark="<?php echo $row['id'];?>" edit="<?php echo $appid;?>.edit.php?action=edit&id=<?php echo $row['id'];?>&jump={jump}">
            <td title="<?php echo $row['id'];?>" width="30">
                <input name="list[]" type="checkbox" class="checkbox" value="<?php echo $row['id'];?>">
            </td>
            <td title="<?php echo $row['id'];?>">
                <?php echo $row['id'];?>
            </td>
            <td title='<?php echo $row['name'];?>'>
                <a href="member.profile.php?uid=<?php echo $row['id'];?>" onclick="Serv.Manager.profile(<?php echo $row['id'];?>); return false;"><?php echo $row['account'];?></a>
            </td>
            <td>
		<a href="member.event.php?s=uid&q=<?php echo $row['id'];?>">详细</a>
            </td>
            <?php
			
			//用户数据
			foreach ($_G['module']['member']["fieds"] as $fied => $name){
				
				//转换数据					
				switch($fied){
				
					case 'sex':						
						$val = $_G['project']['sex'][$user[$fied]];
					break;
				
					case 'marriage':						
						$val = $_G['project']['marriage'][$user[$fied]];
					break;
				
					case 'dateline':						
						$val = date("Y/m/d H:i:s",$user[$fied]);
					break;
				
					default:						
						$val = $user[$fied];
					break;
				
				}
				
				if( $base[$fied] )	echo '<td> '.$val.' </td>';
			}
			
			?>
			
            <td><?php echo $_G['project']['state'][$row['state']];?></td>
            <td>
                <script type='text/javascript'>
                    Mo.Tools('RsEdit','<?php echo $appid;?>.edit.php?action=edit&id=<?php echo $row['id'];?>','');
                    Mo.Tools('RsDelete','<?php echo $appid;?>.list.php?action=delete&list=<?php echo $row['id'];?>','');
                </script>
            </td>
            </tr>
        <?php
        }
        ?>
        
            <tr class="tfoot">
                <td colspan="<?php echo ($x+4);?>" class="first">
                    <?php echo $_G['module']['member']['tool'];?>
                </td>
                <td colspan="2">
                </td>
            </tr>
        </table>
    <?php
  
	//关闭数据库
	System :: connect();
    
    ?>
    </form>
    <!--用于动作处理_结束-->
    
    <div id="saving">
		<?php
            echo multipage($page,$row_count,$_G['setting']['global']['pagesize'],$url,"page");
        ?>
    </div>
    
<!--body end-->

<?php html_close();?>