<?php

/*
*	Copyright VeryIDE,2007-2010
*	http://www.veryide.com/
*
*	$Id: ,v1 10:39 2008-7-27 Leilei $
*/

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

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

	//module
    require("naver.php");
    
	$q = GetQuery("q");
	$s = GetQuery("s");
	$base = $_GET["b"];
	
	$list = GetQuery("list");
	$status = GetNumber("status",1);
	$order = GetQuery("order");
	$action = GetQuery("action");
	
	//mysql open
	reader_mysql();

	if ($action){
	
		switch($action){
			//删除
			case "delete":
			
				//检查权限
				checker_func("mod-pk-mod");		
			
				mysql_query("delete from ".VI_DBMODPRE."forms where id in(".$list.")");
				mysql_query("delete from ".VI_DBMODPRE."groups where fid in(".$list.")");
				mysql_query("delete from ".VI_DBMODPRE."options where fid in(".$list.")");
				mysql_query("delete from ".VI_DBMODPRE."values  where fid in(".$list.")");				
				
				$Project["queries"]+=4;
				
				//删除缓存
				$array = explode(",",$list);
				for($i=0; $i<count($array); $i++){
					$file = VI_ROOT."/".$Project["cache"]."/module-forms-".$array[$i].".php";
					unlink($file);
				}
				
				reader_redirect($appid.".list.php","表单数据删除成功!");
				
			break;
			
			//状态
			case "create":
				//生成缓存
				cache_forms($list,$appid,$mysql);				
				
				reader_redirect($jump,"表单缓存更新成功!");
				
			break;
			
			case "status":
			
				//检查权限
				checker_func("mod-pk-mod");		
			
				$sql="update ".VI_DBMODPRE."forms set status=".$status." where appid='".$appid."' and id in(".$list.")";
				mysql_query($sql);
				
				$Project["queries"]++;
				
				//生成缓存
				cache_forms($list,$appid,$mysql);
				
				reader_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="status" id="status" 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 ($Modules["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 ".VI_DBMODPRE."members where 1=1 ";
    if ($q && $s){
        $sql.=" and  ".$s." like '%".$q."%'";
    }
    $sql.=" order BY id desc";
    
    //查询数据库_总记录数
    $row_count = $db -> getValue( str_replace("*","count(id)",$sql) );   

    
    $Project["queries"]++;

    //分页参数
    $page=GetPage("page");
    $page_start=$Global["pagesize"]*($page-1);
    $sql=$sql." limit $page_start,".$Global["pagesize"];
	
    //分页链接
    $url="?q=".$key."&s=".$s."&".format_get("b",$base)."&page=";
    
    $result=mysql_query($sql,$mysql);
	
    $Project["queries"]++;
    ?>
    
	<?php
    
    //表格统计
    $x = 0;
    
    //用户数据
    if( is_array($base) ){
        foreach ($Modules["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( mysql_num_rows($result)> $Global["pagesize"]/2 ){
		?>
        <tr class="thead">
            <td colspan="<?php echo ($x+6);?>" class="first"><?php echo $Modules[$appid]["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 绝对路径
    $uripath=uripath();
    
    while($row=mysql_fetch_assoc($result)){
        
        //配置
        $config = fix_json( $row["config"] );
		
		//读取用户信息
		$user = array();
		
		if( is_array($base) && $row["id"] ){
			
			$sql="select * from ".VI_DBMODPRE."members where id='".$row["id"]."'";
			
			$db -> query($sql);
			$user = $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 ($Modules["member"]["fieds"] as $fied => $name){
				
				//转换数据					
				switch($fied){
				
					case 'sex':						
						$val = $Project["sex"][$user[$fied]];
					break;
				
					case 'marriage':						
						$val = $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 $Project["status"][$row["status"]];?></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 $Modules[$appid]["tool"];?>
                </td>
                <td colspan="2">
                </td>
            </tr>
        </table>
    <?php
  
    //mysql close
    reader_mysql(true);
    
    ?>
    
    <!--up-->
    
    <div id="saving">
		<?php
            echo GetPageLink($page,$row_count,$Global["pagesize"],$url,"page");
        ?>
    </div>
    
<!--body end-->

<?php html_close();?>