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

	if ($action){
	
		switch($action){
			//删除
			case "delete":
			
				//检查权限
				System :: check_func("mod-member-data-del", false );		
			
				//删除数据
				System :: $db -> execute("DELETE FROM `mod:value` WHERE id in(".$list.")");
				
				//更新统计
				System :: $db -> execute("UPDATE `mod:form` SET stat=stat-".$result." WHERE id = ".$fid);				
				
				System :: redirect($appid.".value.php?fid=".$fid,"用户数据删除成功!");
				
			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="" />
        <input name="fid" value="<?php echo $fid;?>" type="hidden" />
    </form>
     <!--用于动作处理_结束-->
    
    <form name="formSearch" id="formSearch" method="get" action="?">
    
    	<span class="action">
			<button class="button" onclick="toggle('formAdv');" type="button">高级选项</button>
            <?php 
			if( System :: check_func('mod-member-data-dow') ){
			?>
			<button class="cancel" type="button" onclick="location.href=location.href.replace('value.php','report.php');">下载数据</button>
            <?php
			}
			?>
        </span>
    
        <select name="s" id="s">
            <option value="id" checked> I D</option>
            <option value="fid"> FID</option>
	    <option value="uid"> UID</option>
            <option value="account"> 用户名称</option>
            <option value="name" 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();" /> '.$name.'</label>';
            }
            ?>        
        </div>
       
    </form>
    </div>
    
    <script type="text/javascript">
         Mo("#s").value("<?php echo $s;?>");
		
		<?php
		if( is_array($base) ){
			echo "Mo('#formAdv').toggle();";
		}
		?>
    </script>

    <?php
	
    $sql="SELECT * FROM `mod:value` WHERE 1=1 ";
    
    if ($q && $s){    
		if( strpos($s,"id") !== false ){
			$sql.=" and  `".$s."` = '".$q."'";
		}else{
			$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=".$q."&s=".$s."&page=";
    
    $result = System :: $db -> getAll( $sql );
	
    ?>
    
    <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="7" class="first"><?php echo $_G['module']['member']['tool'];?></td>
        </tr>
      	<?php
		}
		?>
      
        <tr class="title" id="thead">
            <td width="30"></td>
            <td width="100">用户名</td>
            <td width="80">活动类型</td>
            <td width="200">活动名称</td>
            <td>提交内容</td>
            <td>提交时间</td>
            <td width="60">IP</td>
        </tr>
      
    <?php
    //VeryIDE 绝对路径
    $url_path=url_path();
    
    foreach( $result as $row ){
        
        ////配置
        $config = fix_json( $row['config'] );
		
		//加载缓存
		Cached :: loader($appid,"forms.".$row["fid"]);
		
		//加载配置		
		$cfg = $_CACHE['system']['module'][$_CACHE[$appid]['form']["appid"]]["config"];
		
		if( $cfg ){
			require($_G['project']['module'].$cfg);
		}
        ?>
          <tr class="line" pid="<?php echo $row['id'];?>">
            <td title="<?php echo $row['id'];?>">
                <input name="id" type="checkbox" class="checkbox" id="id-<?php echo $row['id'];?>" value="<?php echo $row['id'];?>">
            </td>
            <td title='<?php echo $row['name'];?>'>
                <a href="<?php echo "?s=id&q=".$row['id'];?>"><?php echo format_substr($row['account'],30,"...");?></a>
                <?php
				if( $row['uid'] ){
					echo loader_image("icon/user.png","个人信息","","Serv.Manager.profile(".$row['uid']."); return false;");
				}
				?>
            </td>
            <td>
            <?php
			 echo $_G['module']['member'][$_CACHE[$appid]['form']["appid"]]["name"];
			?>
            </td>
            <td>
            <a href="<?php echo "?s=fid&q=".$row["fid"];?>">
            <?php
			 echo $_CACHE[$appid]['form']["name"];
			?>
            </a>
            </td>
            <td>
            <?php
			 echo $row['config'];
			?>
            </td>
            <td title="<?php echo date("Y/m/d H:i:s",$row['dateline']);?>">
                <?php
                echo '<span class="text-yes">'.date("Y/m/d",$row['dateline']).'</span>';
                ?>
            </td>
            <td>
                <?php
                echo $row["ip"];
                ?>
            </td>
            </tr>
        <?php
        }
        ?>
        
        <tr class="tfoot">
            <td colspan="5" 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();?>