<?php
if( !defined('ISDVBBS') ){
	header('HTTP/1.0 404 Not Found');
	exit;
}
global $objenc;
if ($GLOBALS['action'] == 'isweb') {
	$s = $GLOBALS['s'];
	$keyword = $GLOBALS['keyword'];
	$SelSearch = $GLOBALS['selsearch'];
	if ($SelSearch != '') $SelSearch = strtolower($SelSearch);
	if ($SelSearch == 'page') $SelSearch = 'massist';
	if ($SelSearch == '') $SelSearch = 'massist';
	if ($keyword == '') $keyword = 'dvbbs';
	print <<<EOT
	<div id="Seardata" style="height:500px;">
EOT;
	$t = intval($GLOBALS['t']);
	switch($t){
		case 0:
			print <<<EOT
	<iframe name="isWeb" id="isWebQuery" frameborder="0" width="100%" height="100%" scrolling="auto" src="http://so.dvbbs.net/search.asp?k={$keyword}&s={$SelSearch}"></iframe>
EOT;
			break;
		case 1:
			print <<<EOT
	<iframe name="isWeb" id="isWebQuery" frameborder="0" width="100%" height="100%" scrolling="auto" src="http://so.dvbbs.net/search.asp?k={$keyword}&s={$SelSearch}"></iframe>
EOT;
			break;
	}
	print <<<EOT
	</div>
	<script language="JavaScript">
	<!--
	var obj=parent.document.getElementById("{$s}");
	var SearchData = document.getElementById("Seardata");
	if (obj){
		if (obj.style.display=='none'){
			obj.style.display='';
		}
		obj.style.height=(parent.document.getElementById("SearchMain1").offsetHeight)+'px';
		obj.innerHTML = SearchData.innerHTML;
	}

	//-->
	</script>
EOT;
	exit;
} elseif (!empty($__dbResults) AND is_array($__dbResults)) {
	$ps = ( $page - 1) * $pagesize;
	$pend = $page * ($pagesize+1);
	if ($GLOBALS['action'] == 'manage') {
		print <<<EOT
<script language="javascript" type="text/javascript">
	function CheckAll(form)
	{
		for (var i=0;i<form.elements.length;i++){
		  var e = form.elements[i];
		  if (e.name == 'arrrootid[]')
			 e.checked = form.chkall.checked;
		}
	}
	function clicksubmit(form)
	{
		if(confirm('{$lang['tpl.str1']}')){
			this.document.batch.submit();
			return true;
		}else {
			return false;
		}
	}
</script>
EOT;
	}
	print <<<EOT
<script language="javascript" type="text/javascript">
function ONSearch(act,showobj,val,KeyWord,SelSearch){
	if (val.checked==true){
		var ToUrl="query.php?action=isweb&s="+showobj;
		ToUrl += "&"+act+"="+val.value+"&selsearch="+SelSearch+"&keyword="+KeyWord;
		var HFrame = document.getElementById("hiddenquery")
		if (HFrame){
			HFrame.src=ToUrl;
		}
	}else
	{
		var ShowObj = document.getElementById(showobj);
		if (ShowObj){
			ShowObj.style.display='none';
		}
	}
	ShowQuery()
}

function ShowQuery(){
	var ObjName;
	var s
	s = 1
	for(var i=1;i<=2;i++) {
		ObjName = "SearchMain"+i;
		var Obj = document.getElementById(ObjName);
		if (Obj){
			if (Obj.style.display=='')
			s += 1
		}
	};
	var wideth = 100 / s;
	for(var i=1;i<=2;i++) {
		ObjName = "SearchMain"+i;
		var Obj = document.getElementById(ObjName);
		if (Obj){
			if (Obj.style.display==''){
			Obj.style.width=parseFloat(wideth) + "%";}
		}
	};
}
function SetQuerySize(isWeb,KeyWord,SelSearch){
	var s = 1;
	if (isWeb==0){
		s = 2;
		var ToUrl="query.php?action=isweb&s=searchmain2&selsearch="+SelSearch+"&t=1&keyword="+KeyWord;
		var HFrame = document.getElementById("hiddenquery")
		if (HFrame){
			HFrame.src=ToUrl;
		}
		var wideth = 100 / s;
		for(var i=1;i<=2;i++) {
			ObjName = "SearchMain"+i;
			var Obj = document.getElementById(ObjName);
			if (Obj){
				Obj.style.width=parseFloat(wideth) + "%";
				//alert(Obj.style.width);
			}
		};
	}
	if(isWeb==2){
		s = 2;
		var ToUrl="query.php?action=isweb&s=searchmain2&selsearch="+SelSearch+"&t=1&keyword="+KeyWord;
		var HFrame = document.getElementById("hiddenquery")
		if (HFrame){
			HFrame.src=ToUrl;
		}
		document.getElementById("SearchMain1").style.display='none';
		document.getElementById("SearchMain1").style.width="0";
		document.getElementById("SearchMain2").style.width="100%";
		document.getElementById("iSearch").style.height="1280";
	}
}
</script>

	<table cellPadding="0" cellSpacing="0"  align="center" >
EOT;
	if ($is_more_correlation === false) {
		print <<<EOT
		<form  method="post" action="?">	
		<tr>
			<td align="left" class="tablebody1" valign="middle" colspan="2"><input type="text" size="20" name="keyword" value="{$keyword}"/>&nbsp;&nbsp;&nbsp;
			<select name="boardid" id="boardid">
EOT;
		print boardjumplist($GLOBALS['boardid'],$lang['tpl.str2']);
		print <<<EOT
			</select>
			&nbsp;&nbsp;
EOT;
		if ($stype == 1) {
			print <<<EOT
			<input type="radio" name="stype" value="1" checked="checked" class="radio"/>
EOT;
		} else {
			print <<<EOT
			<input type="radio" name="stype" value="1" class="radio"/>
EOT;
		}
		print <<<EOT
			&nbsp;{$lang['str_12']}
			&nbsp;&nbsp;
EOT;
		if ($stype == 2) {
			print <<<EOT
			<input type="radio" name="stype" value="2" checked="checked" class="radio"/>
EOT;
		} else {
			print <<<EOT
			<input type="radio" name="stype" value="2" class="radio"/>
EOT;
		}
		print <<<EOT
			&nbsp;{$lang['str_13']}
			&nbsp;&nbsp;
EOT;
		if ($stype == 7) {
			print <<<EOT
			<input type="radio" name="stype" value="7" checked="checked" class="radio"/>
EOT;
		} else {
			print <<<EOT
			<input type="radio" name="stype" value="7" class="radio"/>
EOT;
		}
		global $ft_settings;
		if (0 == $ft_settings[0]) {
			$str_ft = $lang['str_15'];
		} else {
			if (0 == $ft_settings[2] OR 1 == $ft_settings[2]) {	//	主题+帖子内容的搜索被禁用
				$str_ft = $lang['str_15'];
			} else {
				$str_ft = $lang['str_14'];
			}
		}
		print <<<EOT
			&nbsp;{$str_ft}
EOT;
		if ($stype == 8) {
		print <<<EOT
			&nbsp;&nbsp;
			<input type="radio" name="stype" value="8" checked="checked" class="radio"/>
			&nbsp;{$lang['tpl.str3']}
EOT;
		} else {
			print <<<EOT
			&nbsp;&nbsp;
EOT;
			if ($isweb == 0) {
				print <<<EOT
			<input type="checkbox" name="isweb" value="0" checked="checked" onclick="ONSearch('t','SearchMain2',this,'{$keyword}','{$SelSearch}')" class="chkbox"/>
EOT;
			} else {
				//Nothing to do
			}
		}
		print <<<EOT
			<INPUT TYPE="hidden" name="submitdBtn" value="0">
			&nbsp;&nbsp;&nbsp;	<button onmousemove="button_move(this)" onmouseout="button_out(this)" onclick="this.form.submitdBtn.value=0" style=" margin:0 0 2px 0; text-indent:0px;" type="submit" name="submit"> {$lang['str_26']} </button>

			</td>
		</tr>
		</form>
EOT;
	}
	print <<<EOT
		
	</table>
		<BR>

<div class="mainbox"> <!-- mainbox start -->
<ul class="tableborder heightd ">
  <h3 class="titlebig">{$lang['tpl.str5']} <font color="{$alertcolor}">{$pagecount}</font> {$lang['tpl.str6']}
EOT;
	if ($Master == 1) {
		if ($action != 'manage') {
			print <<<EOT
		<a href="query.php?{$PageStr}&page={$page}&action=manage" title="{$lang['tpl.str7']}">{$lang['tpl.str8']}</a>
EOT;
		} else {
			print <<<EOT
		<a href="query.php?{$PageStr}&page={$page}" title="{$lang['tpl.str9']}">{$lang['tpl.str10']}</a>
EOT;
		}
	}
			print <<<EOT

  </h3>
EOT;
	if ($is_more_correlation === false AND ( $stype ==1 OR $stype == 2 OR $stype == 3 OR $stype == 7) ) {
		print <<<EOT
  <li><em class="font14">
		<font color="{$alertcolor}">{$keyword}</font> {$lang['tpl.str11']}
EOT;
		if ($stype == 2 OR $stype == 7) {
			$encodekeyword=urlencode($keyword);
			print <<<EOT
		<a href="?stype=2&keyword={$encodekeyword}&boardid={boardid}&isweb={$isweb}&action={$action}">{$lang['tpl.str12']}</a>
EOT;
			foreach ($__tableList as $val) {
				$encodekeyword=urlencode($keyword);
				print <<<EOT
		&nbsp;&nbsp;
		<a href="?stype=7&keyword={$encodekeyword}&boardid={$boardid}&isweb={$isweb}&action={$action}&stable={$val['tablename']}" title="{$lang['tpl.str13']}">{$val['tabletype']}</a>
EOT;
			}
		}
		if ($stype == 1) {
			$encodekeyword=urlencode($keyword);
			print <<<EOT
		<a href="?stype=1&keyword={$encodekeyword}&boardid={$boardid}&isweb={$isweb}&action={$action}&nsearch=1" title="{$lang['tpl.str14']}">{$lang['tpl.str12']}</a>
EOT;
			foreach ($__tableList as $val) {
				$encodekeyword=urlencode($keyword);
				print <<<EOT
		&nbsp;&nbsp;
		<a href="?stype=1&keyword={$encodekeyword}&boardid={$boardid}&isweb={$isweb}&action={$action}&stable={$val['tablename']}&nsearch=2" title="{$lang['tpl.str15']}">{$val['tabletype']}</a>
EOT;
			}
		}
		if ($stype == 3) {
			foreach ($__tableList as $val) {
				$encodekeyword=urlencode($keyword);
				print <<<EOT
		&nbsp;&nbsp;
		<a href="?stype=3&keyword={$encodekeyword}&boardid={$boardid}&isweb={$isweb}&action={$action}&stable={$val['tablename']}&nsearch=2" title="{$lang['tpl.str16']}">{$val['tabletype']}</a>
EOT;
			}
		}
		print <<<EOT
		<br />
  </em>
  </li>
EOT;
	}	  
		print <<<EOT
	<form action="query.php?action=batch" method="post" name="batch" style="margin:0;padding:0">
EOT;
	global $boardid,$_DCACHE;
	include_once CACHE_PATH.'board/board_all.php';
	$ordernum = ($page - 1) * $pagesize;
	if ('manage' === $action) {
		$tmpwidth = '45px';
	} else {
		$tmpwidth = '24px';
	}
	foreach ($__dbResults AS $val) {
		$ordernum++;
		$currBoardid = $val['boardid'];
		$currRootID = intval($val['rootid']);
		$currAnnounceID = intval($val['announceid']);
		$val['body'] = $objenc->SubString(preg_replace('#<[a-zA-Z]+?.*?>|</[a-zA-Z]+?.*?>#is','',$val['body']),0,100);
		$val['topic'] = preg_replace(array('#<[a-zA-Z]+?.*?>|</[a-zA-Z]+?.*?>#is','/</i','/>/i'),array('','&lt;','&gt;'),$val['topic']);
		print <<<EOT
		<li style="margin-left:10px"><em class="font14">
EOT;
		if ($action == 'manage') {
		print <<<EOT
				<!--<input type="checkbox" class="chkbox" name="announceid[]" value="{$val['rootid']}_{$val['announceid']}"/>-->
				<input type="checkbox" class="chkbox" name="arrrootid[]" value="{$currRootID}"/>
				<input type="hidden" name="announceid_{$currRootID}" value="{$currAnnounceID}"/>
EOT;
		} else {
			print <<<EOT
				{$val['querynum']}
EOT;
		}
		print <<<EOT
			{$ordernum}.
		<!--Start主题-->
EOT;
		if ( $loginhidden == 0 AND $_DCACHE['all_forums']["{$currBoardid}"]['hidden'] == 1 ) {
			print <<<EOT
				{$lang['str_40']}
EOT;
		} else {
			if ($currBoardid == '444' OR $currBoardid == '777') {
				print <<<EOT
					&nbsp;&nbsp;
EOT;
				if ($currBoardid == '444') {
					print <<<EOT
					{$lang['str_36']}
EOT;
				}else {
					print <<<EOT
					{$lang['str_37']}
EOT;
				}
			} else {
				$url=($issavvy==1?"savvy_":"")."dispbbs.php?boardid={$currBoardid}&id={$val['rootid']}&replyid={$val['announceid']}&skin=1";
				$url=_urlrewrite($url);
				print <<<EOT
				<a href="{$url}" target="_blank" title="{$val['topic']}">
				<font style="font-size : 15px;">
EOT;
				if ($currBoardid == $boardid AND $_DCACHE['all_forums']["{$currBoardid}"]['checkout'] == 1) {
				print <<<EOT
				{$lang['str_41']}
EOT;
				} else {
					if ($val['topic'] != '' )
						$tmpBody= SetWordColor($fsetting['searchwordcolor'],$keyword,$val['topic']);
					else
						$tmpBody= 'RE:'.$val['body'].'....';

					print <<<EOT
					{$tmpBody}
EOT;
				}
				print <<<EOT
				</font></a>
EOT;
			}
		}
		print <<<EOT
		</em>
		</li>
		<!--End主题-->
		<!--Start版面-->
		<li>
EOT;


		$tempUserName= SetWordColor($fsetting['searchwordcolor'],$keyword,$val['username']);
		if ($stype == 7) {
		//$tmpBody = htmlspecialchars(substr($val['body'],0,100));
		$tmpBody = SetWordColor($fsetting['searchwordcolor'],$keyword,$val['body']);
		print <<<EOT
		{$tmpBody}....<br />
EOT;
		}
		print <<<EOT
		&nbsp;&nbsp;<font color="green">
EOT;
		if ($val['hidename'] == 1 OR $val['signflag'] == 2) {
			print <<<EOT
		{$lang['tpl.str17']}
EOT;
			if ($Master == 1) {
				print <<<EOT
		<a href="dispuser.php?id={$val[postuserid]}" target="_blank"><font color="green">{$tempUserName}</font></a>
EOT;
			}
		print <<<EOT
		{$lang['tpl.str18']}
EOT;
		} else {
		print <<<EOT
		{$lang['tpl.str17']}<a href="dispuser.php?id={$val[postuserid]}" target="_blank"><font color="green">{$tempUserName}</font></a>
EOT;
		}
		if ($isMoreInfo == 1) {
			print <<<EOT
		&nbsp;&nbsp;
		{$lang['tpl.str19']}{$val['hits']}
		&nbsp;&nbsp;
		{$lang['tpl.str20']}{$val['child']}
EOT;
		}
		$val['dateandtime'] = gmdate("Y-m-d H:i:s",$val['dateandtime']+getUserTimeZoneOffset());
		print <<<EOT
		&nbsp;&nbsp;{$lang['template.strings30']}
		&nbsp;&nbsp;
EOT;
		if ($val['boardid'] == 444 OR $val['boardid'] == 777) {
			if ($val['boardid'] == 444) {
			print <<<EOT
		{$lang['str_34']}
EOT;
			} else {
			print <<<EOT
		{$lang['str_35']}
EOT;
			}
		} else {
			if ($_DCACHE['all_forums']["{$currBoardid}"]['boardtype']) {
				if ( $loginhidden == 0 AND $_DCACHE['all_forums']["{$currBoardid}"]['hidden'] == 1 ) {
					print <<<EOT
		{$lang['str_30']}
EOT;
				} else {
					print <<<EOT
				<a href="index.php?boardid={$currBoardid}" target="_blank"><font color="green">{$_DCACHE['all_forums']["{$currBoardid}"]['boardtype']}</font></a>&nbsp;&nbsp;{$val['dateandtime']}
EOT;
				}
			} else {
				print <<<EOT
		{$lang['str_38']}
EOT;
			}
		}
		print <<<EOT
		</font>
		<font color="gray">{$val['dateandtiime']}
		&nbsp;&nbsp;
EOT;
		if (intval($val['isbest']) > 0) {
			print <<<EOT
		{$lang['tpl.str21']}
EOT;
		} else {
			if ($val['locktopic'] > 0) {
				print <<<EOT
		{$lang['tpl.str22']}
EOT;
			} else {
				if ($val['isvote'] == 1) {
					print <<<EOT
		{$lang['tpl.str23']}
EOT;
				}
			}
		}
		print <<<EOT
		</font>
		<!--End版面-->
		<hr style="border-top:1px #B3B3B3 dashed;border-bottom:0px;height:0px;width:98%;"></hr>
       </li>
EOT;
	}#$__dbResults  end

	if ($action == 'manage') {
		print <<<EOT
		<li><em class="font14">
		<select name="newboard" id="newboard">
			<option value="0">{$lang['manage_0']}</option>
EOT;
		global $_DCACHE,$_POST;
		if (file_exists(CACHE_PATH.'board/board_all.php')) {
			include_once CACHE_PATH.'board/board_all.php';
			if (!empty($_DCACHE['all_forums']) AND is_array($_DCACHE['all_forums'])) {
				global $_POST;
				foreach ($_DCACHE['all_forums'] as $currBoardid => $currForum) {
					if ($currForum['parentid'] == 0 ){
						$currBoardType = "{$lang['template.strings31']}{$currForum[boardtype]}";
					} else {
						$currBoardType = "&nbsp;&nbsp;&nbsp;&nbsp;{$lang['template.strings32']}{$currForum[boardtype]}";
					}
					print <<<EOT
			<option value="{$currBoardid}">{$currBoardType}</option>
EOT;
				}
			}
		}
		print <<<EOT
		</select>
		<script type="text/javascript" language="javascript">
		</script>
		&nbsp;&nbsp;
		<input type="checkbox" name="chkall" value="on" onclick="CheckAll(this.form);" class="chkbox"/>{$lang['manage_1']}
		&nbsp;&nbsp;
		<input type="radio" name="maction" value="dele" class="radio"/>{$lang['manage_2']}
		&nbsp;&nbsp;
		<input type="radio" name="maction" value="move" class="radio"/>{$lang['manage_3']}
		&nbsp;&nbsp;
		<input type="radio" name="maction" value="isbest" class="radio"/>{$lang['manage_4']}
		&nbsp;&nbsp;
		<input type="radio" name="maction" value="lock"  checked="checked" class="radio" />{$lang['manage_5']}
		&nbsp;&nbsp;
		<button onmousemove="button_move(this)" onmouseout="button_out(this)" style=" margin-left:5px; text-indent:0px;" type="submit" name="Submit" onclick="return clicksubmit(this.form);" > {$lang['tpl.str24']} </button>

EOT;
	}
print <<<EOT
	</form><br />

	<script language="JavaScript" src="templates/lang/{$GLOBALS['fsetting']['lang']}/js/pagination.js"></script>
	<script language="JavaScript" type="text/javascript">
	PageList({$page},10,20,{$pagecount},'{$PageStr}&action={$action}',2)
	</script>

    </em></li>
EOT;
} else {
	    print <<<EOT
<li><em class="font14">{$lang['str_42']}&nbsp;<a href="query.php?boardid={$boardid}">{$lang['str_43']}</a></em></li>
EOT;
}
print <<<EOT
</div> <!-- mainbox end -->
EOT;

?>