<?php
	if( !is_array($_G['project']) ){
		ob_clean();
		exit("Forbidden");	
	}
?>
  
<?php

	//日期筛选
	$start = getgpc('start');
	$end = getgpc('end');
	
	//sql
	$sql="SELECT * FROM ".$_G['module'][$s]["search"]["table"]." WHERE 1=1 ".$_G['module'][$s]["search"]["where"]." ";

	//转换表前辍
	$sql = format_table($sql);
	
	//重组查询
	$arr = explode(" ",$q);						
	$txt = implode( "%' or ".$_G['module'][$s]["search"]["keyword"]."  like '%",$arr);						
	$sql.=" and (".$_G['module'][$s]["search"]["keyword"]." like '%".$txt."%')";
	
	if ($start && $end){
		$sql.=" and  start >=".strtotime($start)." and end <= ".strtotime($end.' 23:59:59');
	}
	
	$sql.=" order BY ".$_G['module'][$s]["search"]["order"]." desc";


	//总记录数
	$row_count = $_G['module'][$s]["search"]["result"];
	
	

	$page=getpage("page");
	$page_start=$_G['setting']['global']['pagesize']*($page-1);
	$sql=$sql." limit $page_start,".$_G['setting']['global']['pagesize'];
	
	//分页链接
	$url="?do=module&s=".$s."&q=".urlencode($q)."&page=";

	echo '<table width="100%" border="0" cellpadding="1" cellspacing="1" class="table">
	  <tr class="title">';
		
		foreach($_G['module'][$s]["search"]["fieds"] as $cfg => $val){
			echo '<td>'.$val.'</td>';
		}
		
	echo '</tr>';
	
	$result = System :: $db -> getAll( $sql );
	
	foreach( $result as $row ){

		echo ("<tr class='line'>");
		
		foreach($_G['module'][$s]["search"]["fieds"] as $cfg => $val){
		
			//搜索扩展
			if($_G['module'][$s]["search"]["extra"][$cfg]){
			
				$str = $_G['module'][$s]["search"]["extra"][$cfg];
				
				foreach($_G['module'][$s]["search"]["fieds"] as $fied => $name){
					
					$value = $row[$fied];
					
					if( $_G['module'][$s]["search"]["keyword"] == $fied ){
						
						foreach($arr as $key){
							$value = str_replace($key,'<span class="text-key">'.$key.'</span>',$value);
						}
										
					}
					
					$str = str_replace("{".$fied."}",$value,$str);
				}					
			
				echo '<td>'.$str.'</td>';
			}else{
				echo '<td>'.$row[$cfg].'</td>';
			}
		}
		
		echo ("</tr>");
		
	}
	echo '</table>';

        //关闭数据库
        System :: connect();

?>
    <div id="saving">
		<?php
            echo multipage($page,$row_count,$_G['setting']['global']['pagesize'],$url,"page");
        ?>
    </div>
