<?php
	if( !is_array($Project) ){
		ob_clean();
		exit("Forbidden");	
	}
?>
  
<?php

	//日期筛选
	$start = GetQuery("start");
	$end = GetQuery("end");
	
	//sql
	$sql="SELECT * FROM ".$Modules[$s]["search"]["table"]." where 1=1 ".$Modules[$s]["search"]["where"]." ";

	//转换表前辍
	$sql = format_table($sql);
	
	//重组查询
	$arr = explode(" ",$q);						
	$txt = implode( "%' or ".$Modules[$s]["search"]["keyword"]."  like '%",$arr);						
	$sql.=" and (".$Modules[$s]["search"]["keyword"]." like '%".$txt."%')";
	
	if ($start && $end){
	
		//开始时间
		$e_array=explode("-",$start);
		$t1=mktime(0, 0, 0, $e_array[1], $e_array[2], $e_array[0]);
		
		//到期时间
		$e_array=explode("-",$end);
		$t2=mktime(23, 59, 59, $e_array[1], $e_array[2], $e_array[0]);
		
		$sql.=" and  l_start >=".$t1." and l_end <= ".$t2;
	}
	
	$sql.=" order BY ".$Modules[$s]["search"]["order"]." desc";


	//总记录数
	$row_count = $Modules[$s]["search"]["result"];
	
	$Project["queries"]++;

	$page=GetPage("page");
	$page_start=$Global["pagesize"]*($page-1);
	$sql=$sql." limit $page_start,".$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($Modules[$s]["search"]["fieds"] as $cfg => $val){
			echo '<td>'.$val.'</td>';
		}
		
	echo '</tr>';
	
	$result=mysql_query($sql,$mysql);
	
	$Project["queries"]++;
	
	while($row=mysql_fetch_assoc($result)){

		echo ("<tr class='line'>");
		
		foreach($Modules[$s]["search"]["fieds"] as $cfg => $val){
		
			//搜索扩展
			if($Modules[$s]["search"]["extra"][$cfg]){
			
				$str = $Modules[$s]["search"]["extra"][$cfg];
				
				foreach($Modules[$s]["search"]["fieds"] as $fied => $name){
					
					$value = $row[$fied];
					
					if( $Modules[$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>';

	//mysql close
	reader_mysql(true);

?>
    <div id="saving">
		<?php
            echo GetPageLink($page,$row_count,$Global["pagesize"],$url,"page");
        ?>
    </div>
