<?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');
	$state = getnum("state",1);
	$order = getgpc("order");
	$action = getgpc('action');
	
	//连接数据库
	System :: connect();

	if ($action){
	
		switch($action){
			//删除
			case "delete":
			
				//检查权限
				System :: check_func( 'mod-pk-mod', false );		
			
				mysql_query("DELETE FROM `mod:form` WHERE id in(".$list.")");
				mysql_query("DELETE FROM `mod:group` WHERE fid in(".$list.")");
				mysql_query("DELETE FROM `mod:option` WHERE fid in(".$list.")");
				mysql_query("DELETE FROM `mod:value`  WHERE fid in(".$list.")");				
				
				//删除缓存
				$array = explode(",",$list);
				for($i=0; $i<count($array); $i++){
					$file = VI_ROOT.$_G['project']['cache']."/module-forms-".$array[$i].".php";
					unlink($file);
				}
				
				System :: redirect($appid.".list.php","表单数据删除成功!");
				
			break;
			
			//状态
			case "create":
				//生成缓存
				Cached :: form( $appid, $list );				
				
				System :: redirect($jump,"表单缓存更新成功!");
				
			break;
			
			case "state":
			
				//检查权限
				System :: check_func( 'mod-pk-mod', false );		
			
				$sql="UPDATE `mod:form` SET state=".$state." WHERE appid='".$appid."' and id in(".$list.")";
				mysql_query($sql);
				
				
				
				//生成缓存
				Cached :: form( $appid, $list );
				
				System :: redirect($jump,"表单状态更改成功!");

			break;
		}
	}
    
    ?>

    <div id="search">
    <!--用于动作处理_开始-->
    <form name="formPost" id="formPost" method="post" action="?">
        <input name="list" id="list" type="hidden" value="">
        <input name="action" id="action" type="hidden" value="" />
        <input name="url" id="url" type="hidden" value="" />
        <input name="state" id="state" type="hidden" value="" />
    </form>
     <!--用于动作处理_结束-->
    
    <form name="formSearch" id="formSearch" method="get" action="?">
    	<span class="action">
			<button class="button" onclick="toggle('formAdv',function(s){if(!s){setAll('#formAdv input',false); $('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="$(\'formSearch\').submit();" onclick="$(\'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 "toggle('formAdv');";
		}
		?>
        
        Mo.reader(function(){
            
            /*滚动表头*/
            window.setInterval(function(){
                Mo.Thead("thead");
            },100);
            
            /*筛选表格*/
            Mo.Table($T("table")[0],
                [
                    'mousedown',function(o,event){
                        var target=(event.srcElement ? event.srcElement : event.target);
                        var pid = o.getAttribute("pid");
                        var obj = $('id-'+pid);
                        
                        if(!pid || target==obj){return false;};
                        
                        obj.click(); if(obj.checked){o.style.background='#eee';}else{o.style.background='#fff';}
                        
                    },
                    'dblclick',function(o,event){
                        var pid = o.getAttribute("pid");
                        if(!pid){return false;};
                        location.href='<?php echo $appid;?>.edit.php?action=edit&fid='+pid+'&jump='+encodeURIComponent(location.href);
                    }
                ]
            );
            
            <?php
            //只针对新增内容
            if($_GET['mark']){
            ?>
            //操作提示
            Mo.Tips(null,$("mark-<?php echo $_GET['mark'];?>"),'info','点这里开始新增表单选项，鼠标指向“小灯泡”将会有小提示。',document,'click',-20,15);
            <?php
            }
            ?>
            
        });
    </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="30">操作</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="line" pid="<?php echo $row['id'];?>">
            <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="parent.Mo.Window('window','用户个人信息' ,this.href ,'850','85%',{}); return false;"><?php echo $row['account'];?></a>
            </td>
            <td>
				<a href="member.track.php?uid=<?php echo $row['id'];?>" onclick="parent.Mo.Window('dialog','用户个人信息' ,this.href ,'90%','85%',{}); return false;">详细</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('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();
    
    ?>
    
    <!--up-->
    
    <div id="saving">
		<?php
            echo multipage($page,$row_count,$_G['setting']['global']['pagesize'],$url,"page");
        ?>
    </div>
    
<!--body end-->

<?php html_close();?>