<?php
$vercode=''; //此处取值请自行修改
if(isset($_POST['vercode'])){
if ($_POST['vercode']!=$vercode){
 echo("[err]invalid vercode[/err]");
 exit();
}
}

define('SCR', 'searcher');
require_once ('global.php');
/* check user level */
//!$_G['allowsearch'] && Showmsg('search_group_right');
//if ($groupid!=3 && $groupid!=4) {
// list($db_opensch,$db_schstart,$db_schend) = explode("\t",$db_opensch);
// if ($db_opensch && (($db_schstart > $db_schend) && ($_time['hours']>$db_schend) && ($_time['hours']<$db_schstart) || ($db_schstart < $db_schend) && (($db_schstart>-1 && $_time['hours']<$db_schstart) || ($db_schend>-1 && $_time['hours']>=$db_schend)))) {
//  Showmsg('search_opensch');
// }
//}
//initGP(array("keyword","type","fid","step","username","starttime","endtime","threadrange","diaryusername","diarystarttime","diaryendtime","diaryrange","page","fid","sch_time","digest","ttable","ptable"));
//if($sch_time == 'newatc' || $digest  == 1 ){
// list($type,$conditon) = array( 'special',(($sch_time == 'newatc') ? 'latest' : 'digest') );
//}
//if($type && !in_array($type,array('thread','forum','user','diary','group','special'))){
// showMsg("抱歉,搜索类型不存在");
//}
//$isSphinx = ($db_sphinx['isopen'] > 0) ? true : false;/* is mysql or sphinx */
//$searcherService = L::loadclass('searcher', 'search');
//list($perpage,$searchURL) = array(20,'');
//$threadrange  = ($threadrange > 1) ? $threadrange : 1;
//$diaryrange   = ($diaryrange > 1) ? $diaryrange : 1;
//$page = ($page > 1) ? $page : 1;
/* open thread type to search when no keyword */
//if($type && ( $keyword || ( !$isSphinx && 'thread' == $type  ) || 'special' == $type )){
// (strtolower($GLOBALS['pwServer']['REQUEST_METHOD']) == "post") && checkVerify();
// if(!$isSphinx && 2 == $step ){
//  if(!$searcherService->checkUserLevel()){
//   Showmsg('search_limit');
//  }
//  if(!$searcherService->checkWaitSegment()){
//   Showmsg('search_wait');
//  }
// }
// $keyword = strip_tags($keyword);
 //zzcity add
 initGP(array("keyword","type","fid"));
 
 if(!$keyword){
  echo('[err]keyword is null[/err]');
  exit;
 }
 $type= "thread"; 
 
  function searchSubject($keywords,$forumIds){
   global $db;
   $sql = "";
   if($keywords){
    $sql .= " AND t.subject = ".pwEscape($keywords);
   }
   if($forumIds){
    $forumIds = (is_array($forumIds)) ? $forumIds : explode(',',$forumIds);
    $sql .= " AND t.fid IN(".pwImplode($forumIds).")";
   }
   $sql .= " AND t.ifcheck = 1 AND t.fid != 0 ";
   
   $zzdb = $db->get_one("SELECT COUNT(*) as total FROM pw_threads t WHERE 1 ".$sql);
   $total=$zzdb['total'];
   return $total;
  }
  
 if (searchSubject($keyword,$fid)>0){
  echo('[yes]');
 }else{
  echo('[no]');
 }

 //zzcity add end
// switch($type){
//  case "thread":
   /* search range */
//   $allowSearch = ( $_G['allowsearch'] > 0 && $_G['allowsearch'] == 3 ) ? array(2,3) : array(2);
//   $threadrange = (in_array($threadrange,$allowSearch)) ? $threadrange : 1;
//   $ptable = min(intval($ptable),count($db_plist));
//   $ttable = min(intval($ttable),count($db_tlist));
//   $expand = array( "ttable" => $ttable,"ptable" => $ptable);
//   $threadrange = ( $keyword ) ? $threadrange : 1;
//   list($total,$threads) = $searcherService->searchThreads($keyword,$threadrange,$username,$starttime,$endtime,$fid,$page,$perpage,$expand);
//   $pager = ($total) ? numofpage($total,$page,ceil($total/$perpage),$searchURL."searcher.php?keyword=".urlencode($keyword)."&type=$type&threadrange=$threadrange&username=".urlencode($username)."&starttime=$starttime&endtime=$endtime&fid=$fid&",null,'',true) : '';
//   break;
//  case "forum":
//   list($total,$forums) = $searcherService->searchForums($keyword,$page,$perpage);
//   $pager = ($total) ? numofpage($total,$page,ceil($total/$perpage),$searchURL."searcher.php?keyword=".urlencode($keyword)."&type=$type&",null,'',true) : '';
//   break;
//  case "user":
//   list($total,$users) = $searcherService->searchUsers($keyword,$page,$perpage);
//   $pager = ($total) ? numofpage($total,$page,ceil($total/$perpage),$searchURL."searcher.php?keyword=".urlencode($keyword)."&type=$type&",null,'',true) : '';
//   break;
//  case "diary":
//   list($total,$diarys) = $searcherService->searchDiarys($keyword,$diaryrange,$diaryusername,$diarystarttime,$diaryendtime,$page,$perpage);
//   $pager = ($total) ? numofpage($total,$page,ceil($total/$perpage),$searchURL."searcher.php?keyword=".urlencode($keyword)."&type=$type&diaryrange=$diaryrange&diaryusername=".urlencode($diaryusername)."&diarystarttime=$diarystarttime&diaryendtime=$diaryendtime&",null,'',true) : '';
//   break;
//  case "group":
//   list($total,$groups) = $searcherService->searchGroups($keyword,$page,$perpage);
//   $pager = ($total) ? numofpage($total,$page,ceil($total/$perpage),$searchURL."searcher.php?keyword=".urlencode($keyword)."&type=$type&",null,'',true) : '';
//   break;
//  case "special": 
//   list($total,$threads) = $searcherService->searchSpecial($conditon,1,50);
//   break;
// }
//}
?>
