<?php
	if( !is_array($_G['project']) ){
		ob_clean();
		exit("Forbidden");	
	}
	
	/////////////////////////////////
        
	//载入模块配置和函数包
	require VI_ROOT."module/".$hash['appid']."/config.php";
	require VI_ROOT."module/".$hash['appid']."/function.php";

	//载入客户端函数包
	require VI_ROOT."function/client.php";
	
	////////////////////////

	$groups = $_CACHE[$hash['appid']]["group"];

	$options = $_CACHE[$hash['appid']]["option"];

	$config = $_CACHE[$hash['appid']]["form"]["config"];

	////////////////////
	
	//连接数据库
	System :: connect();	
	
	$q = getgpc('q');
	$s = getgpc("s");
        
    $sql="SELECT * FROM `mod:value` WHERE fid=".$hash['fid']." ";
        
    if ( $q && $s ){
        $sql.=" and `".$s."` like '%".$q."%'";
    }
        
    if ( $filter >- 1){
        $sql.=" and state = ".$filter;
    }
        
	if ($ect) $sql.= $ect;
    
    //排序
    $sql.=" order BY id desc";
    
    //查询数据库_总记录数
    $row_count = System :: $db -> getCount( $sql );
        
	if( $model<1 ){

                //分页参数
                $page=getpage("page");
                $page_start=$_G['setting']['global']['pagesize']*($page-1);
                $sql=$sql." limit $page_start,".$_G['setting']['global']['pagesize'];
	}
    
    //分页链接
    $url="?keys=".rawurlencode($keys)."&q=".urlencode($q)."&s=".$s."&appid=".$_CACHE[$hash['appid']]['form']["appid"]."&fid=".$hash['fid']."&".format_get("b",$base)."&filter=$filter&model=$model&page=";
    
    $result = System :: $db -> getAll( $sql );
    
    //表格统计
    $x = 0;
    
    //表单数据
    foreach( $_CACHE[$hash['appid']]['group'] as $id => $array ){
        $thead .= '<td title="GID '.$id.'">'.$array["name"].'</td>';
        $x++;
    }
    
    //用户数据
    if( is_array($base) ){
        foreach ($_G['module']['member']["fieds"] as $fied => $name){
            if( $base[$fied] ){
				$thead .= '<td title="会员 '.$fied.'">'.$name.'</td>';
				$x++;	
			}            
        }
    }
    
    //数据扩展
    if( isset($_G['module']['member'][$hash['appid']]["value"]) ){
	    foreach( $_G['module']['member'][$hash['appid']]["value"] as $fied => $name ){
		$thead .= '<td title="扩展 '.$fied.'">'.$name.'</td>';
		$x++;
	    }
    }
            
    ?>
        
    <!--用于动作处理_开始-->
    <form name="formPost" id="formPost" method="post" action="?">
            <input name="action" id="action" type="hidden" value="" />
            <input name="state" id="state" type="hidden" value="" />
            <input name="fid" value="<?php echo $fid;?>" type="hidden" />
            <input name="appid" value="<?php echo $appid;?>" type="hidden" />
            
            <input name="jump" type="hidden" value="" />
            <script>Mo('#formPost input[name=jump]').value( location.href );</script>
    
        <table width="100%" border="0" cellpadding="1" cellspacing="1" id="table" class="table">      
                <tr class="title" id="thead">
                <td>用户名</td>
                <?php echo $thead;?>
                <td width="60">状态</td>
                <td width="100">IP 地址</td>
                <td>地理位置</td>
                <td width="130">提交时间</td>
                </tr>
      
    <?php
    //VeryIDE 绝对路径
    $url_path=url_path();
    
    foreach( $result as $row ){
		
		//删除空白字符
		$row['config'] = preg_replace("/([\r\n\t\f])/"," ",$row['config']);
                
        $data = fix_json( $row['config'] );	
                
		//读取用户信息
		$user = array();
		
		if( is_array($base) && $row['uid'] ){
				
			$sql="SELECT * FROM `mod:member` WHERE id='".$row['uid']."'";
			
			System :: $db -> query($sql);
			$user = System :: $db -> fetchRow();
		}
		
		//var_dump($config);
		//exit();
        
        ?>
          <tr class="<?php echo zebra( $i, array( "line" , "band" ) );?>" mark="<?php echo $row['id'];?>">
            <td title='<?php echo $row['name'];?>'>
                <?php //echo $row['state']?loader_image("icon/online.png","已确认"):loader_image("icon/offline.png","未确认");?>
                <a href="?keys=<?php echo rawurlencode($keys);?>&s=account&q=<?php echo $row['account'];?>"><?php echo format_substr($row['account'],30,"...");?></a>
            </td>
            <?php
                        
                        //表单数据
                        foreach( $groups as $gid => $array ){
                                
                                //echo '<td>'.'G-'.$gid." : ".$data['G-'.$gid].'</td>';
                                
                                if( in_array($groups[$gid]["type"],array("text","textarea","file")) ){
                                        
                                        $value = $data['G-'.$gid];
                                        
                                        if( $groups[$gid]["type"] == "file" ){
                                                echo '<td><a href="'.$value.'" target="_blank">'.$value.'</a></td>';
                                        }else{
                                                echo '<td>'.$value.'</td>';
                                        }
                                
                                }else{
                                        
                                        $array = explode(",", $data['G-'.$gid]);
                                        
                                        $value = "";
                                        
                                        $n = 1;
                                        foreach( $array as $oid ){					
                                                $value .= $options[$gid][$oid]["name"].($n!=count($array)?'、 ':'');
                                                $n++;
                                        }
                                        
                                        if( $data['G-'.$gid.'-EXT'] ){
                                                $value .= ($value?'、 ':'').$data['G-'.$gid.'-EXT'];
                                        }
                                        
                                        echo '<td>'.$value.'</td>';
                                
                                }
                                
                        }
                        
                        //用户数据
                        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;
                                
                                        //没有从字段中取得信息就从内容中获取
                                        case 'account':						
										case 'name':						
										case 'email':						
										case 'phone':						
										case 'idcard':						
										case 'company':						
										case 'qq':						
											$val = $data[strtoupper($fied)] ? $data[strtoupper($fied)] : $user[$fied];
										break;
                                
                                        default:						
                                                $val = $user[$fied];
                                        break;
                                
                                }
                                
                                if( $base[$fied] )	echo '<td> '.$val.' </td>';
                        }
                        
                        //数据扩展
			if( isset($_G['module']['member'][$hash['appid']]["value"]) ){
				foreach( $_G['module']['member']["value"] as $fied => $name ){					
					echo '<td>'.call_user_func(array($appid, 'parse_value'), $fied, $row, $data, $config ).'</td>';
				}
			}
                                        
                        ?>
            <td><?php echo $_G['module']['member']['sign'][$row['state']];?></td>
            <td><?php echo '<span class="text-no">'.$row["ip"].'</span>';?></td>
            <td><?php echo convertip( $row["ip"] );?></td>
            <td title="<?php echo date("Y-m-d H:i:s",$row['dateline']);?>">
                <?php
                echo '<span class="text-yes">'.date("y-m-d H:i:s",$row['dateline']).'</span>';
                ?>
            </td>
            </tr>
        <?php
        }
        ?>
        </table>
    <?php
  
	//关闭数据库
	System :: connect();
    
    ?>
    
        </form>
        <!--用于动作处理_结束-->
        
    <!--up-->
    
    <div id="saving">
        <?php
        echo multipage($page,$row_count,$_G['setting']['global']['pagesize'],$url,"page");
        ?>
    </div>