<?php
/*
 * Ourphp - CMS建站系统
 * Copyright (C) 2016 www.ourphp.net
 * 开发者：哈尔滨伟成科技有限公司
*/
if(!defined('OURPHPNO')){exit('no!');}

$content = dowith_sql($_REQUEST['content']);
$sid = dowith_sql($_REQUEST['sid']);
$lang = dowith_sql($_REQUEST['lang']);
$inputno = $ourphp_adminfont['inputno'];
$strlength = $ourphp_adminfont['strlength'];
$sensitivefont = $ourphp_adminfont['sensitive'];
$type = dowith_sql($_REQUEST['type']);

if($content == '' || $sid == '' || $lang == '' || $type == ''){
	$type == "wap" ? $a = $ourphp['webpath']."client/wap/" : $a = $ourphp['webpath'];
	exit("<script language=javascript> alert('".$inputno."');location.replace('".$a."');</script>");
}

if(strlen($content) > 40){
	$type == "wap" ? $a = $ourphp['webpath']."client/wap/" : $a = $ourphp['webpath'];
	exit("<script language=javascript> alert('".$strlength."');location.replace('".$a."');</script>");
}

$sensitive = ourphp_sensitive($content);
if(strpos($sensitive,'*') !== false)
{
	exit("<script language=javascript> alert('".$sensitivefont."');history.go(-1);</script>");
}

if(@dowith_sql($_GET['temp']) == 'search'){
	header("location: search.php?".$lang."-&content=".$content."&lang=".$lang."&sid=".$sid."&type=".$type);
	exit;
}

$searchtime = strtotime(date("Y-m-d H:i:s"));
if (empty($_SESSION['searchtime'])){
	
	$_SESSION['searchtime'] = $searchtime;
	
}else{
	
	if($Parameterse['searchtime'] == 0){
		
		$_SESSION['searchtime'] = $searchtime;
		
	}else{
		
		$ourphptime = $searchtime - $_SESSION['searchtime'];
		if(intval($ourphptime) < intval($Parameterse['searchtime'])){
			
			echo "<script language=javascript> alert('搜索间隔为: ".$Parameterse['searchtime']." 秒,请稍后在试!');location.replace('".$ourphp['webpath']."');</script>";
			exit;
			
		}else{
			$_SESSION['searchtime'] = $searchtime;
		}
		
	}

}
	
if($sid == 'article'){

	$top = '`id` as aid,`OP_Articletitle` as atitle,`OP_Articlecontent` as acontent,`OP_Minimg` as aminimg,`OP_Class` as aclass';
	$where = "(`OP_Articletitle` LIKE '%$content%' || `OP_Description` LIKE '$content%' || `OP_Tag` LIKE '%$content%')";
	$array = array('aid','atitle','acontent','aminimg','aclass');

}elseif($sid == 'product'){

	$top = '`id` as bid,`OP_Title` as btitle,`OP_Content` as bcontent,`OP_Minimg` as bminimg,`OP_Class` as bclass';
	$where = "(`OP_Title` LIKE '%$content%' || `OP_Description` LIKE '$content%' || `OP_Tag` LIKE '%$content%')";
	$array = array('bid','btitle','bcontent','bminimg','bclass');
	
}elseif($sid == 'photo'){

	$top = '`id` as cid,`OP_Phototitle` as ctitle,`OP_Photocontent` as ccontent,`OP_Photocminimg` as cminimg,`OP_Class` as cclass';
	$where = "(`OP_Phototitle` LIKE '%$content%' || `OP_Description` LIKE '$content%' || `OP_Tag` LIKE '%$content%')";
	$array = array('cid','ctitle','ccontent','cminimg','cclass');
	
}elseif($sid == 'video'){

	$top = '`id` as did,`OP_Videotitle` as dtitle,`OP_Videocontent` as dcontent,`OP_Videoimg` as dminimg,`OP_Class` as dclass';
	$where = "(`OP_Videotitle` LIKE '%$content%' || `OP_Description` LIKE '$content%' || `OP_Tag` LIKE '%$content%')";
	$array = array('did','dtitle','dcontent','dminimg','dclass');
	
}elseif($sid == 'down'){

	$top = '`id` as eid,`OP_Downtitle` as etitle,`OP_Downcontent` as econtent,`OP_Downimg` as eminimg,`OP_Class` as eclass';
	$where = "(`OP_Downtitle` LIKE '%$content%' || `OP_Description` LIKE '$content%' || `OP_Tag` LIKE '%$content%')";
	$array = array('eid','etitle','econtent','eminimg','eclass');
	
}elseif($sid == 'job'){

	$top = '`id` as fid,`OP_Jobtitle` as ftitle,`OP_Jobcontent` as fcontent,`OP_Jobwork` as fminimg,`OP_Class` as fclass';
	$where = "(`OP_Jobtitle` LIKE '%$content%' || `OP_Description` LIKE '$content%' || `OP_Tag` LIKE '%$content%')";
	$array = array('fid','ftitle','fcontent','fminimg','fclass');
	
}else{

	exit("<script language=javascript> alert('".$ourphp_adminfont['accessno']."');history.go(-1);</script>");
}

$sql = $ourphp['prefix'].$sid;
$i = 1;
$listpage = 10;
if (intval(isset($_GET['page'])) == 0){
	$listpagesum = 1;
		}else{
	$listpagesum = intval($_GET['page']);
}
$start=($listpagesum-1)*$listpage;

$ourphptotal = $db -> listgo("count(id) as tiaoshu", $sql, "where ".$where." && `OP_Lang` = '".$lang."'");
$ourphptotal = $db -> whilego($ourphptotal);

$query = $db -> listgo($top, $sql, "where ".$where." && `OP_Lang` = '".$lang."' order by OP_Searchtop desc,id desc LIMIT ".$start.",".$listpage); 
$rows = array();

while($ourphp_rs = $db -> whilego($query)){
	$title = str_replace($content,'<font color=red><b>'.$content.'</b></font>',$ourphp_rs[$array[1]]);
	$scontent = str_replace($content,'<font color=red><b>'.$content.'</b></font>',strip_tags(strstr($ourphp_rs[$array[2]],$content)));
	if($sid == 'job')
	{
		$minimg = $ourphp['webpath'].'skin/noimage.png';
		
	}else{
		
			if(substr($ourphp_rs[$array[3]],0,4) == 'http'){
				
				$minimg = $ourphp_rs[$array[3]];
				
				}elseif($ourphp_rs[$array[3]] == ''){
					
					$minimg = $ourphp['webpath'].'skin/noimage.png';
					
				}else{
					
					$minimg = $ourphp['webpath'].$ourphp_rs[$array[3]];
			}
	}
	
	$rows[] = array(
		'i' => $i,
		'sid' => $sid,
		'title' => $title,
		'content' => $scontent,
		'url' => $ourphp['webpath'].'?'.$lang.'-'.$sid.'view-'.$ourphp_rs[$array[4]].'-'.$ourphp_rs[$array[0]].'.html',
		'minimg' => $minimg,
		'wapurl' => $ourphp['webpath'].'client/wap/?'.$lang.'-'.$sid.'view-'.$ourphp_rs[$array[4]].'-'.$ourphp_rs[$array[0]].'.html',
	);
	$i+=1;
}



$rs = $db -> select("`id`","`ourphp_search`","where `OP_Searchtext` = '".$content."'");
if($rs)
{
	$db -> update("`ourphp_search`","`OP_Searchclick` = `OP_Searchclick` + 1","where `id` = ".$rs[0]);
}else{
	$db -> insert("`ourphp_search`","`OP_Searchtext` = '".$content."',`OP_Searchclick` = 1,`time` = '".date("Y-m-d H:i:s")."'","");
}

$_page = new Page($ourphptotal['tiaoshu'],$listpage);
$smarty->assign('ourphppage',$_page -> showpage());
$smarty->assign('search',$rows);
$smarty->assign('searchcontent',$content);
?>