Location: PHPKode > projects > News Manager - RSS aggregator > newsmanager/advsearch_qry.php
<?php
/*******************************************************************************
 **  File          :  advsearch_qry.php                                       **
 **  Author        :  G.Ramkumar                                              **
 **  Description   :  Advanced search query	page					          **
 **  Date          :  14/09/2005                                              **
 **  Last Modified :  14/09/2005                                              **
 **  PHP Version   :  5.0.3                                                   **
 **                                                                           **
 *******************************************************************************/
$totalitems="select * from rssurl_newsitem where language='".$_REQUEST['lang']."'";
$totalitem_res=$pg_sql->query_pass($totalitems,"4");

$totalitems_new="select * from new_newsitem where language='".$_REQUEST['lang']."'";
$totalitem_new_res=$pg_sql->query_pass($totalitems_new,"4");

$total_item=count($totalitem_res)+count($totalitem_new_res);

$title=trim(stripslashes($_REQUEST['title']));
$title=str_replace("'","||",$title);
$new_title=str_replace("'","||",$title);

$keyword=trim($_REQUEST['keyword']);
$pubdate=trim($_REQUEST['pubdate']);
if($pubdate!="")
{
	$pubdate_=explode("/",$pubdate);
	$pubdate_=$pubdate_[2]."-".$pubdate_[1]."-".$pubdate_[0];
}

$words=$_REQUEST['words'];
$oldest=$_REQUEST['olddate'];
$category=$_REQUEST['category'];
$source=trim($_REQUEST['source']);
$sort=$_REQUEST['sort'];

?>

<table cellpadding="0" cellspacing="0" border="0" align="center" width="95%">

<?
	$yesterday = strftime ("%e/%m/%Y", strtotime("-1 day"));
	$yday=explode("/",$yesterday);
	/*
	if(substr($yday[1],0,1)==0)
		 $yday[1]=str_replace("0","",$yday[1]);
	  else
	*/
		 $yday[1]=$yday[1];

	if(strlen(trim($yday[0]))==1)
	   $yday[0] ="0".trim($yday[0]);

	$yesterday=trim($yday[0])."/".$yday[1]."/".$yday[2];

	//For oldest days***

	if($oldest!="")
	{
	  $lastday = strftime ("%e/%m/%Y", strtotime("-$oldest day"));
	  $yesterday = strftime ("%e/%m/%Y", strtotime("-1 day"));
  	  $yday=explode("/",$lastday);
	     if(substr($yday[1],0,1)==0)
			$yday[1]=str_replace("0","",$yday[1]);
	     else
	  	    $yday[1]=$yday[1];
	 // $lastday=trim(trim($yday[0])."/".$yday[1]."/".$yday[2]);
	  $lastday=trim($yday[2]."-".$yday[1]."-".trim($yday[0]));

	}

//********** For rss_newsitem Search **********
  if($category !="")
  {
    if($category!="All")
    {
      $cat_name="select * from category where category_id=$category";
      $catname_res=$pg_sql->query_pass($cat_name,"4");
      $category_name=$catname_res[0]['category_name'];
      $catqry="newsitem_category b,";
      $catid ="b.category_id='$category' and a.url_newsitem_id=b.newsitem_id and";
    }else{
      $catqry="";
      $catid ="";
     }
  }

 $search_qry .="select * from $catqry rssurl_newsitem a where $catid a.language='".$_REQUEST['lang']."' and a.frontend_export='Y' and";

 if($title!="")
    {
       $title=strtoupper($title);
       if($words == 'all')
  		 $search_qry .=" upper(a.news_title) like '%$title%' and";
  	  if($words == 'any')
  	     $search_qry .=" upper(a.news_title) like '%$title%' and";
   }
 if($keyword != "")
      $search_qry .=" a.description like '%$keyword%' and";

  if($oldest !="")
  {
     $search_qry .=" a.pubdate >='$lastday' and";
  }else{
    if($pubdate_!=""){
       $search_qry .=" a.pubdate='$pubdate_' and";
    }
  }

  $search_qry =trim($search_qry,"and");

	 if($sort=='relevance')
	   $search_qry .=" order by a.url_newsitem_id asc";
	 elseif($sort=='pubdate')
	   $search_qry .=" order by a.pubdate desc";
     else
         $search_qry .=" order by a.news_title asc";


     if(strstr($search_qry,"="))
	    $search_res=$pg_sql->query_pass($search_qry,"4");

     $Totalsearch_qry=$search_qry;
	 $Total_res=$pg_sql->query_pass($Totalsearch_qry,"4");
	 $total_num = count($Total_res);

     $limit = 10; // Set limit display news item per page
     $offset = 0;

	  if($_REQUEST['offset']>0)
	   {
		   $offset = $_REQUEST['offset'];
	   }

	  $offset_qry=$search_qry." limit $limit offset $offset";
	  $offset_res=$pg_sql->query_pass($offset_qry,"4");
	  $otcnt=count($offset_res);

// for New _newsitem
if($category !="")
  {
    if($category!="All")
    {
      $cat_name_new     = "select * from category where category_id=$category";
      $catname_res_new  = $pg_sql->query_pass($cat_name_new,"4");
      $category_name_new= $catname_res_new[0]['category_name'];
      $catqry_new       = "newsitem_category b,";
      $catid_new        = "b.category_id='$category' and a.newsitem_id=b.newsitem_id and";
    }else{
      $catqry_new ="";
      $catid_new  ="";
    }

  }

  $search_qry_new .="select * from $catqry_new new_newsitem a where $catid_new a.language='".$_REQUEST['lang']."' and";
   if($title!="")
   {
      if($words == 'all')
 		 $search_qry_new .=" upper(a.title) like '%$title%' and";
 	  if($words == 'any')
 	     $search_qry_new .=" upper(a.title) like '%$title%' and";
   }

if($source!="")
        $search_qry_new .=" a.channel_short_name='$source' and";

  if($keyword != "")
      $search_qry_new .=" a.introtext like '%$keyword%' or a.body like '%$keyword%' and";

  if($oldest !="")
  {
     $search_qry_new .=" a.pubdate >='$lastday' and";
  }else{
    if($pubdate_!="")
      $search_qry_new .=" a.pubdate='$pubdate_' and";
  }

  $search_qry_new =trim($search_qry_new,"and");

	 if($sort=='relevance')
	   $search_qry_new .=" order by a.newsitem_id asc";
	 elseif($sort=='pubdate')
	   $search_qry_new .=" order by a.pubdate desc";
     else
         $search_qry_new .=" order by a.title asc";

     if(strstr($search_qry_new,"="))
		$search_res_new=$pg_sql->query_pass($search_qry_new,"4");


  $Totalsearch_qry_new=$search_qry_new;
  $Total_res_new=$pg_sql->query_pass($Totalsearch_qry_new,"4");
  $total_num_new = count($Total_res_new);

  $total_news=$total_num+$total_num_new;

  $limit = 10; // Set limit display news item per page
  $offset = 0;

  if($_REQUEST['offset']>0)
   {
  	   $offset = $_REQUEST['offset'];
   }

  $offset_qry_new=$search_qry_new." limit $limit offset $offset";
  $offset_res_new=$pg_sql->query_pass($offset_qry_new,"4");
  $cnt_new=count($offset_res_new);

 for($xm=0;$xm<$cnt;$xm++)
 {
 $xml_id_ .=$offset_res[$xm]['url_newsitem_id'].",";
 }
 for($xm_=0;$xm_<$cnt_new;$xm_++)
 {
 $xml_id_new .=$offset_res_new[$xm_]['newsitem_id'].",";
 }




 if($otcnt>0 || $cnt_new>0)
  {

 ?>  <tr>
	    <td class="heading5" height="25"><?=$search_results_?></td>
		<td align="right" width="5%" class="heading5" valign="middle">
		   <a target="_new" href="xml.php?id=<?=base64_encode(trim($xml_id_,","))?>&new_id=<?=base64_encode(trim($xml_id_new,","))?>"><?if($display_style_==1){?><img src="images/rss-2.0.jpg" width="80" height="15" border="0" alt="Link to RSS Feed"><?}else{?> <img src="images/<?=$rss_style_?>"  border="0" align="absmiddle" alt="Link to RSS Feed"><?}?></a>
	    </td>
	 </tr>
	 <tr>
	    <td valign="middle" height="25" colspan="2" class="headingsmall"><?=1+$offset?>&nbsp;<?=$search_foundto__?>&nbsp;<?=$otcnt+$cnt_new+$offset?>&nbsp;<?=$search_foundres__?>&nbsp;<?=$total_num+$total_num_new?>&nbsp;<?=$search_foundwith__?>&nbsp;<?=$total_item?>&nbsp;<?=$search_foundnews__?></td>
	 </tr>

 <?
    }
   else{
       $flag=$adv_noresults__;
?>
   <tr>
    <td class="heading5" height="25" colspan="2"><?=$search_results_?></td>
   </tr>
   <tr>
	   <td colspan="2" height="200" align="center" class="msg"><?=$flag?></td>
	 </tr>
<?
}
  for($j=0;$j<$otcnt;$j++)
  {
	  $hour=str_replace(":","h",$offset_res[$j]['hour']);
	  $ch_id=$offset_res[$j]['rss_channel_id'];

	  $desc=html_entity_decode(strip_tags($offset_res[$j]['description']));
      $desc=substr($desc,0,$search_length__);
	  $id=$offset_res[$j]['url_newsitem_id'];
	  $date=explode("-",$offset_res[$j]['pubdate']);
	  $date=$date[2]."/".$date[1]."/".$date[0];

	  $url_=$offset_res[$j]['url'];

	  $today=date('d/m/Y');

	  if($date==$today)
	  	  $pub_date=$today_;
	  elseif($date == $yesterday)
	  	  $pub_date=$yesterday_;
	  else
		 $pub_date=$date;

    $cate_query="select * from newsitem_category where newsitem_id=$id";
    $catitem_res=$pg_sql->query_pass($cate_query,"4");
      for($y=0;$y<count($catitem_res);$y++)
       {
	     if($catitem_res[$y][category_id]!="") //*** Getting category name
 		  {
			 $cat_id=$catitem_res[$y][category_id];
			 $category_id .=$cat_id.",";
			 $cat_nameqry="select * from category where category_id=$cat_id";
			 $cat_nameres=$pg_sql->query_pass($cat_nameqry,"4");
			 $category_name1.=$cat_nameres[0]['category_name']."/";
		  }
	 }
		  $categoryname=rtrim($category_name1,"/");
		  unset($category_name1);


		$title_=str_replace("||","'",$offset_res[$j]['news_title']);
		$rep_title=$title_;
		$rep_title=str_replace("é","é",$rep_title);
		$rep_title=str_replace("’","’",$rep_title);
		$rep_title=str_replace("è","è",$rep_title);
		$rep_title=str_replace("Ã","à",$rep_title);
		$rep_title=str_replace("àª","ê",$rep_title);
		$rep_title=str_replace("‘","‘",$rep_title);
		$rep_title=str_replace("à»",û,$rep_title);
		$title_=$rep_title;

//*** Desc
        $rep_desc=$desc;
		$rep_desc=str_replace("é","é",$rep_desc);
		$rep_desc=str_replace("’","’",$rep_desc);
		$rep_desc=str_replace("è","è",$rep_desc);
		$rep_desc=str_replace("Ã","à",$rep_desc);
		$rep_desc=str_replace("àª","ê",$rep_desc);
		$rep_desc=str_replace("‘","‘",$rep_desc);
		$rep_desc=str_replace("à»",û,$rep_desc);
    	$desc=$rep_desc;

		$channel_image=$offset_res[$j]['image'];
		$dir="login/newsimages/";
		if (is_dir($dir))
		{
		 if ($dh = opendir($dir))
		 {
		   while (($file = readdir($dh)) !== false)
		   {
		 	if(($file != ".") && ($file != ".."))
			{
				$img=explode(".",$file);
				if($img[0]==$ch_id)
				{
				  $path=pathinfo($file);
				  $name=$path['extension'];
				  if($name == "jpg" || $name =="gif" )
					$image_pre='<a href="view_article.php?id='.$id.'&lang='.$lang.'"><img src="login/newsimages/'.$file.'" border="0" width="'.$width__.'" height="'.$height__.'"></a>&nbsp;';

				}

			}
	  	  }
		   closedir($dh);
	     }
	  }

		if(strstr($channel_image,"http://"))
		  $channel_image='<a href="view_article.php?id='.$id.'&lang='.$lang.'"><img border="0" height="'.$height__.'" width="'.$width__.'" src="'.$channel_image.'"></a>&nbsp;';
		else
		  $channel_image=$image_pre;


?>

	<tr>
	  <td colspan="2" class="cont1" valign="top"><a class="contblue" href="<?=$url_?>" target="_new"><?=$title_?></a></td>
   </tr>
   <tr><td valign="top" class="cont1"> <?=str_replace("||","'",$desc).'.....'?>
	     <br><font class="contgrey"><?=$pub_date." ".$hour?></font>
     		 <?if($categoryname!="")
	 	  //   echo "--<font class='contgrey'>".$categoryname."</font>";
	 		?>
         </td>
			<?if($offset_res[$j]['image']!=""){?>
	     <td valign="middle" width="25%" align="center"><?=$channel_image?></td>
		  <?}?>
 </tr>
 <tr><td colspan="4" height='7'></td></tr>
<?
  }

for($i=0;$i<$cnt_new;$i++)
{
  $hour_new=str_replace(":","h",$offset_res_new[$i]['hour']);

  $introcontent=htmlentities(stripslashes(strip_tags($offset_res_new[$i]['introtext'])));
  $intro__res=html_entity_decode(str_replace("images/","login/images/",$introcontent));

  $desc_new=substr($intro__res,0,$search_length__);
  $id_new=$offset_res_new[$i]['newsitem_id'];
  $date_new=explode("-",$offset_res_new[$i]['pubdate']);
  $date_new=$date_new[2]."/".$date_new[1]."/".$date_new[0];

  $today=date('d/m/Y');
    $id=$id_new;
	include("fod_att.php");

    if($date_new==$today)
   	  $pub_date_new=$today_;
    elseif($date_new == $yesterday)
   	  $pub_date_new=$yesterday_;
    else
	  $pub_date_new=$date_new;
   $source_name_new=$offset_res[$i]['channel_short_name'];

   $cate_query_new="select * from newsitem_category where newsitem_id=$id_new";
   $catitem_res_new=$pg_sql->query_pass($cate_query_new,"4");
   for($y=0;$y<count($catitem_res_new);$y++)
       {
	     if($catitem_res_new[$y][category_id]!="") //*** Getting category name
 		  {
			 $cat_id_new=$catitem_res_new[$y][category_id];
			 $category_id_new .=$cat_id_new.",";
			 $cat_nameqry_new="select * from category where category_id=$cat_id_new";
			 $cat_nameres_new=$pg_sql->query_pass($cat_nameqry_new,"4");
			 $category_name1_new.=$cat_nameres_new[0]['category_name']."/";
		  }
	 }
		  $categoryname_new=rtrim($category_name1_new,"/");
		  unset($category_name1_new);


		$title_new=str_replace("||","'",$offset_res_new[$i]['title']);
		$rep_title_new=$title_new;
		$rep_title_new=str_replace("é","é",$rep_title_new);
		$rep_title_new=str_replace("’","’",$rep_title_new);
		$rep_title_new=str_replace("è","è",$rep_title_new);
		$rep_title_new=str_replace("Ã","à",$rep_title_new);
		$rep_title_new=str_replace("àª","ê",$rep_title_new);
		$rep_title_new=str_replace("‘","‘",$rep_title_new);
		$rep_title_new=str_replace("à»",û,$rep_title_new);
		$title_new=$rep_title_new;

//*** Desc
        $rep_desc_new=$desc_new;
		$rep_desc_new=str_replace("é","é",$rep_desc_new);
		$rep_desc_new=str_replace("’","’",$rep_desc_new);
		$rep_desc_new=str_replace("è","è",$rep_desc_new);
		$rep_desc_new=str_replace("Ã","à",$rep_desc_new);
		$rep_desc_new=str_replace("àª","ê",$rep_desc_new);
		$rep_desc_new=str_replace("‘","‘",$rep_desc_new);
		$rep_desc_new=str_replace("à»",û,$rep_desc_new);
    	$desc_new=$rep_desc_new;
?>

<tr>
  <td valign="top" class="cont1" colspan="3"><a class="contblue" href="view_fodarticle.php?id=<?=$id_new?>&lang=<?=$lang?>"><?=$title_new?></a></td>
</tr>
<tr><td class="cont1" valign="top"><?=str_replace("||","'",$desc_new).'.....'?></td>
	<?if($image!=""){?>
    <td valign="middle" width="25%" align="center"><a href="view_fodarticle.php?id=<?=$id_new?>&lang=<?=$lang?>"><?=$image?></a></td>
  <?}
    unset($image);
   ?>
</tr>
<tr><td class="cont1" colspan="2"><font class="grey"><?=$pub_date_new." ".$hour_new?></font>
<?if($categoryname1_new!="")
 //     echo "-<font class='grey'> ".$categoryname1_new."</font>";

  ?>
</td></tr>
<tr><td colspan="4" height='7'></td></tr>

<?
  }

?>
<tr><td colspan="3">&nbsp;</td>
</tr>
<!--tr>
   <td align="center" colspan="3">&nbsp;
      <a href="advsearch.php?lang=<?=$lang?>&title=<?=$new_title?>&keyword=<?=$keyword?>&pubdate=<?=$pubdate?>&words=<?=$words?>&olddate=<?=$oldest?>&category=<?=$category?>&source=<?=$source?>&sort=<?=$sort?>"><img src="images/<?=$new_search__?>" border="0"></a>
  </td>


</tr-->

</table>
Return current item: News Manager - RSS aggregator