<?php
include("require.php");
if(!isset($_GET['searchx']) || $_GET['searchx']=="" || !isset($_GET['searchname']) || $_GET['searchname']=="")
  Header("Location: index.php");
else
{
  $_GET['searchname']=submitfilter(2,$_GET['searchname']);
  if($_GET['searchx']=="gobar")
    Header("Location: create.php?barname=".$_GET['searchname']); 
  else
  {
    if(!isset($_GET['page']))
      $_GET['page']=0;
    $phpcolor->table=$core_mysql_prefix."topic";
    $phpcolor->field="*";
	if($_GET['searchx']=="gotie")
	{
      $phpcolor->where="theme like '%".$_GET['searchname']."%' and state != '0' order by republished desc";
      $count=$phpcolor->exist(2);
	  $phpcolor->where="theme like '%".$_GET['searchname']."%' and state != '0' order by republished desc limit ".($_GET['page']*50).",50";
	}
	elseif($_GET['searchx']=="gouser")
	{
	  $phpcolor->where="author = '".$_GET['searchname']."' and state != '0' order by republished desc";
	  $count=$phpcolor->exist(2);
	  $phpcolor->where="author = '".$_GET['searchname']."' and state != '0' order by republished desc limit ".($_GET['page']*50).",50";
	}
	$page=pages($count,50,$_GET['page'],'search','&searchx='.$_GET['searchx'].'&searchname=',$_GET['searchname'],'0');
	$post=$phpcolor->assignment();
    for ($count=0;$count<count($post);$count++)       
    {
      if(substr($post[$count]['republished'],0,10)==date('Y-m-d',strtotime(date('Y-m-d'))+$core_time*60*60))
	    $post[$count]['republished']=substr($post[$count]['republished'],11,18);
	  else
	    $post[$count]['republished']=substr($post[$count]['republished'],0,10);
	  $post[$count]['authorip'] = is_ip($post[$count]['author']);
	  $post[$count]['reauthorip'] = is_ip($post[$count]['reauthor']);
    }
    $tpl -> assign("post", $post); 
    $tpl -> assign("page", $page);
	$tpl -> assign("core_header_title", $_GET['searchname']." - ");
  }
  $tpl -> display("$core_style/search.htm");
}
?>