Location: PHPKode > projects > QuickTicket > quickticket/qti_find.php
<?php

/**
* PHP versions 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to hide@address.com so we can mail you a copy immediately.
*
* @package    QuickTicket
* @author     Philippe Vandenberghe <hide@address.com>
* @copyright  2008-2012 The PHP Group
* @version    2.5 build:20101222
*/

session_start();
require_once('bin/qti_init.php');
if ( !$oVIP->CanView('V5') ) HtmlPage(11);
if ( !isset($_GET['a']) ) die('Missing parameter a');
$a = strip_tags($_GET['a']); // action search type: ref, kw, tst, db, user, actor

include('bin/qti_fn_sql.php');

// --------
// INITIALISE
// --------

$oVIP->selfname = $L['Search_result'];

include('qti_find_inc.php');

$oVIP->selfurl = 'qti_find.php';
$oVIP->exiturl = 'qti_search.php?'.QTargimplode(QTargexplode());
$oVIP->exitname = $L['Search'];

// MAP MODULE

if ( UseModule('map') ) { $strCheck='S'; include('qtim_map_ini.php'); }  else { $bMap=false; }

// --------
// HTML START
// --------

if ( $a=='tst' )
{
$strHeadScript = '
<script type="text/javascript" src="bin/qt_jquery.js"></script>
<script type="text/javascript">
<!--
$(document).ready(function() {
  $(".tag").hover(function() {
    var oTag = $(this);
    $.post("qti_j_tag.php",{s:oTag.attr("title"),val:oTag.html(),lang:"'.GetIso().'",na:""}, function(data) { oTag.attr({title:data}); } );
    });
  });
-->
</script>
';
}

$oHtml->scripts = array();
include('qti_p_header.php');

include('qti_search_inc.php');

echo '<h2>',$oVIP->selfname,'</h2>',N;

// -----
// COUNT
// -----

if ( isset($_GET['debug']) ) $oDB->debug=true;
$oDB->Query( $strCount );
$row = $oDB->Getrow();
$intCount = $row['countid'];

// FOUND

switch($a)
{
case 'ref':
  $strSubtitle = $k1;
  if ( $s>=0 ) $strSubtitle .= ' ('.$L['Section'].': '.(isset($oVIP->sections[$s]) ? $oVIP->sections[$s] : '').')';
  $strSubtitle = $L['Ref'].': '.$strSubtitle.'&nbsp;&nbsp;&middot;&nbsp;&nbsp;'.LangS('Result',$intCount);
  break;
case 'kw':
  $strSubtitle = '"'.$k1.'"&nbsp;&nbsp;&middot;&nbsp;&nbsp;'.LangS('Result',$intCount);
  if ( $k2!='1' && count($arrKeys)>1 )
  {
    $strSubtitle .= '&nbsp;&nbsp;&middot;&nbsp;&nbsp;<a href="'.Href().'?a=kw&amp;k1='.urlencode($k1).'&amp;k2=1&amp;s='.$s.'&amp;k3='.urlencode($k3).'">'.$L['Search_by_words'].'</a>';
  }
  if ( $k2=='1' && count($arrKeys)>1 )
  {
    $strSubtitle = '"'.implode('" '.$L['or'].' "',$arrKeys).'"&nbsp;&nbsp;&middot;&nbsp;&nbsp;'.LangS('Result',$intCount);
    $strSubtitle .= '&nbsp;&nbsp;&middot;&nbsp;&nbsp;<a href="'.Href().'?a=kw&amp;k1='.urlencode($k1).'&amp;k2=0&amp;s='.$s.'&amp;k3='.urlencode($k3).'">'.$L['Search_exact_words'].' "'.$k1.'"</a>';
  }
  break;
case 'news':
  $strSubtitle = $L['All_news'];
  if ( $s>=0 ) $strSubtitle .= ' ('.$L['Section'].': '.(isset($oVIP->sections[$s]) ? $oVIP->sections[$s] : '').')';
  $strSubtitle .= '&nbsp;&nbsp;&middot;&nbsp;&nbsp;'.LangS('Result',$intCount);
  break;
case 'last':
  $strSubtitle = $L['Recent_messages'];
  if ( $s>=0 ) $strSubtitle .= ' ('.$L['Section'].': '.(isset($oVIP->sections[$s]) ? $oVIP->sections[$s] : '').')';
  $strSubtitle .= '&nbsp;&nbsp;&middot;&nbsp;&nbsp;'.LangS('Result',$intCount);
  break;
case 'user':
  $strSubtitle = $L['Topics'].' '.strtolower($L['By']).' '.$k2;
  if ( $s>=0 ) $strSubtitle .= ' ('.$L['Section'].': '.(isset($oVIP->sections[$s]) ? $oVIP->sections[$s] : '').')';
  $strSubtitle .= '&nbsp;&nbsp;&middot;&nbsp;&nbsp;'.LangS('Result',$intCount);
  break;
case 'actor':
  $strSubtitle = $L['Topics_handled'].' '.strtolower($L['By']).' '.$k2;
  if ( $s>=0 ) $strSubtitle .= ' ('.$L['Section'].': '.(isset($oVIP->sections[$s]) ? $oVIP->sections[$s] : '').')';
  $strSubtitle .= '&nbsp;&nbsp;&middot;&nbsp;&nbsp;'.LangS('Result',$intCount);
  break;
case 'tst':
  $strSubtitle='';
  if ( $k1=='-1' )    { $strSubtitle = $L['Any_time']; }
  elseif ( $k1=='w' ) { $strSubtitle = $L['This_week']; }
  elseif ( $k1=='m' ) { $strSubtitle = $L['This_month']; }
  elseif ( $k1=='y' ) { $strSubtitle = $L['This_year']; }
  elseif ( is_numeric($k1) ) $strSubtitle = $L['dateMMM'][intval($k1)].' '.$intYear;
  if ( $k2=='-1' )
  {
    $strSubtitle .= ', '.$L['Any_status'];
  }
  else
  {
    $strSubtitle .= ', '.$oVIP->statuses[$k2]['statusname'];
  }
  if ( count($arrTags)>0 )  $strSubtitle .= ', '.$L['Tag_only'].' '.implode(' or ',$arrTags);
  if ( $s>=0 ) $strSubtitle .= ' ('.$L['Section'].': '.(isset($oVIP->sections[$s]) ? $oVIP->sections[$s] : '').')';
  $strSubtitle = '<p>'.$strSubtitle.' &middot; '.LangS('Result',$intCount).'</p>';
  break;

}

// NO RESULT

if ($intCount==0)
{
  echo '<p>',$strSubtitle,'</p>',N;
  TableEmpty($L['E_no_topic'].'...');
  echo '<p>&laquo;&nbsp;<a href="',Href($oVIP->exiturl),'">',$oVIP->exitname,'</a></p>';
  include('qti_p_footer.php');
  exit;
}

// -----
// QUERY
// -----

  // order
  $strFullOrder = 't.'.$strOrder.' '.$strDir;
  if ( $strOrder=='title' ) $strFullOrder='p.title'.' '.$strDir;
  if ( $strOrder=='sectiontitle' ) $strFullOrder='s.title'.' '.$strDir;
  // second order
  if ( $strOrder!='lastpostdate' ) $strFullOrder .= ',t.lastpostdate DESC';

if ( QTI_LIST_ME && $oVIP->numpost>0 )
{
  $oDB->Query( 'SELECT p.topic,p.issuedate FROM '.TABPOST.' p INNER JOIN '.TABSECTION.' s ON p.forum=s.id WHERE '.str_replace('t.forum','p.forum',$strSection).' AND p.type="R" AND p.userid='.$oVIP->id.' AND p.issuedate>"'.DateAdd(date('Ymd'),-2,'year').'" ORDER BY p.issuedate DESC' );
  while($row=$oDB->Getrow()) { $i=intval($row['topic']); if ( !isset($arrMe[$i]) ) $arrMe[$i]=$row['issuedate']; if ( count($arrMe)>100 ) break; }
}
$oDB->Query( LimitSQL($strField.$strFrom.$strWhere,$strFullOrder,$intLimit,$_SESSION[QT]['topics_per_page'],$intCount) );

// --------
// DISPLAY
// --------

echo '<p>',$strSubtitle,'</p>',N;

// Button line and pager

$strPager = MakePager("$oVIP->selfurl?a=$a&amp;page=1&amp;order=$strOrder&amp;dir=$strDir".$strOptions,$intCount,$_SESSION[QT]['topics_per_page'],$intPage);
if ($strPager!='') $strPager = $L['Page'].$strPager;

// -- Displays pager --

echo '<table class="hidden" cellspacing="0"><tr class="hidden"><td class="hidden" id="pager_zt">&nbsp;',$strPager,'</td></tr></table>
';

// -- result --

echo '<table class="data_t" cellspacing="0">',N;
echo '<tr class="data_t data_t0">',N;

// ========
$arrFLD = array();
$oFLD = new cFLD('icon','&bull;','colhd colhdico colhdfirst','','colct colico colfirst'); $oFLD->uid='status'; $oFLD->sort='ASC'; $arrFLD['icon']=$oFLD;
$oFLD = new cFLD('numid',$L['Ref'],'colhd colhdref','','colct colref','background-color:%bg'); $oFLD->sort='DESC'; if ( $bAddRef ) $arrFLD['numid']=$oFLD;
$oFLD = new cFLD('smile','&nbsp;','colhd colhdsmi','','colct colsmi'); $arrFLD['smile']=$oFLD;
$oFLD = new cFLD('title',$L['Topics'],'colhd','','colct'); $oFLD->sort='DESC'; $arrFLD['title']=$oFLD;
$oFLD = new cFLD('you','&nbsp;','colhd center','width:10px','colct center'); if ( QTI_LIST_ME ) $arrFLD['you']=$oFLD;
$oFLD = new cFLD('sectiontitle',$L['Section'],'colhd','','colct'); $oFLD->sort='ASC'; $arrFLD['sectiontitle']=$oFLD;
$oFLD = new cFLD('firstpostname',$L['Author'],'colhd','width:125px','colct'); $oFLD->sort='ASC'; $arrFLD['firstpostname']=$oFLD;
$oFLD = new cFLD('lastpostdate',$L['Last_message'],'colhd','width:135px','colct'); $oFLD->sort='ASC'; $arrFLD['lastpostdate']=$oFLD;
if ( $a=='tst' && !empty($k3) )
{
$oFLD = new cFLD('tags',$L['Tags'],'colhd center colhdlast','width:80px','colct center collast'); $arrFLD['tags']=$oFLD;
}
else
{
$oFLD = new cFLD('replies',$L['Replys'],'colhd center colhdlast','width:70px','colct center collast'); $oFLD->sort='DESC'; $arrFLD['replies']=$oFLD;
}
// ========
TableHeader($arrFLD,$intCount,"qti_find.php?a=$a&amp;page=1".$strOptions,$strOrder,$strDir);
// ========

echo '</tr>',N;

// ========
$intWhile=0;
$strAlt='r1';
while($row=$oDB->Getrow())
{
  TableRowShow($arrFLD,TableRowFormat($arrFLD,$row,true,null),'data_t'.$strAlt,$row);
  if ( $strAlt=='r1' ) { $strAlt='r2'; } else { $strAlt='r1'; }
  $intWhile++; 
  //odbcbreak
  if ( $intWhile>=$_SESSION[QT]['topics_per_page'] ) break;  
}
// ========

echo '<tr class="colft">',N;
echo '<td class="colft colftfirst"></td>',N;
For ($i=0;$i<(count($arrFLD)-2);$i++)
{
echo '<td class="colft"></td>',N;
}
echo '<td class="colft colftlast"></td>',N;
echo '</tr>',N;

echo '</table>',N;

// -- no data --
if ( $intWhile==0 ) echo '<p>',$L['None'],'...</p>',N;

// -- Displays pager --

// define csv options according to $intCount (max 10000)

$strCsv ='';
if ( $oVIP->role!='V' )
{
  if ( $intCount<=$_SESSION[QT]['topics_per_page'] )
  {
  $strCsv = '<a class="csv" href="'.Href('qti_find_csv.php').'?a='.$a.'&amp;size=all&amp;n='.$intCount.$strOptions.'&amp;order='.$strOrder.'&amp;dir='.$strDir.'" title="'.$L['H_Csv'].'">'.$L['Csv'].'</a>';
  }
  else
  {
  $strCsv = '<a class="csv" href="'.Href('qti_find_csv.php').'?a='.$a.'&amp;size=p'.$intPage.'&amp;n='.$intCount.$strOptions.'&amp;order='.$strOrder.'&amp;dir='.$strDir.'" title="'.$L['H_Csv'].'">'.$L['Csv'].' ('.strtolower($L['Page']).')</a>';
  if ( $intCount<=1000 )                   $strCsv .= ' &middot; <a class="csv" href="'.Href('qti_find_csv.php').'?a='.$a.'&amp;size=all&amp;n='.$intCount.$strOptions.'&amp;order='.$strOrder.'&amp;dir='.$strDir.'" title="'.$L['H_Csv'].'">'.$L['Csv'].' ('.strtolower($L['All']).')</a>';
  if ( $intCount>1000 && $intCount<=2000 ) $strCsv .= ' &middot; <a class="csv" href="'.Href('qti_find_csv.php').'?a='.$a.'&amp;size=m1&amp;n='.$intCount.$strOptions.'&amp;order='.$strOrder.'&amp;dir='.$strDir.'" title="'.$L['H_Csv'].'">'.$L['Csv'].' (1-1000)</a> &middot; <a class="csv" href="'.Href('qti_find_csv.php').'?a='.$a.'&amp;size=m2&amp;n='.$intCount.$strOptions.'" title="'.$L['H_Csv'].'">'.$L['Csv'].' (1000-'.$intCount.')</a>';
  if ( $intCount>2000 && $intCount<=5000 ) $strCsv .= ' &middot; <a class="csv" href="'.Href('qti_find_csv.php').'?a='.$a.'&amp;size=m5&amp;n='.$intCount.$strOptions.'&amp;order='.$strOrder.'&amp;dir='.$strDir.'" title="'.$L['H_Csv'].'">'.$L['Csv'].' (1-5000)</a>';
  if ( $intCount>5000 )                    $strCsv .= ' &middot; <a class="csv" href="'.Href('qti_find_csv.php').'?a='.$a.'&amp;size=m5&amp;n='.$intCount.$strOptions.'&amp;order='.$strOrder.'&amp;dir='.$strDir.'" title="'.$L['H_Csv'].'">'.$L['Csv'].' (1-5000)</a> &middot; <a class="csv" href="'.Href('qti_find_csv.php').'?a='.$a.'&amp;size=m10&amp;n='.$intCount.$strOptions.'" title="'.$L['H_Csv'].'">'.$L['Csv'].' (5000-10000)</a>'; 
  }
}
if ( !empty($strCsv) )
{
  $strPager = $strCsv.' &middot; '.$strPager;
  if ( substr($strPager,-10,10)==' &middot; ' ) $strPager = substr($strPager,0,-10);
}

echo '<table class="hidden" cellspacing="0"><tr class="hidden"><td class="hidden" id="pager_zb">&nbsp;',$strPager,'</td></tr></table>
';

// MAP MODULE

if ( $bMap )
{
  if ( count($arrExtData)==0 )
  {
  echo '<p class="gmap">'.$L['map']['E_noposition'].'</p>';
  }
  else
  {
     //select zoomto (maximum 15 items in the list)
     if ( count($arrExtData)>1 )
     {
       $str = '<p class="gmap" style="margin:0 0 4px 0"><a class="gmap" href="javascript:void(0)" onclick="zoomToFullExtend(); return false;">'.$L['map']['zoomtoall'].'</a> | '.$L['Goto'].' <select class="gmap" id="zoomto" name="zoomto" size="1" onchange="map.setCenter(eval(this.value));">';
       $str .= '<option class="gmap" value="new GLatLng('.QTgety($_SESSION[QT]['m_map_gcenter']).','.QTgetx($_SESSION[QT]['m_map_gcenter']).')"> </option>';
       $i=0;
       foreach($arrExtData as $intKey=>$oMapPoint)
       {
       $str .= '<option class="gmap" value="new GLatLng('.$oMapPoint->y.','.$oMapPoint->x.')">'.$oMapPoint->title.'</option>';
       $i++; if ( $i>15 ) break;
       }
       $str .= '</select></p>';
     }
  echo '
  <table class="hidden" style="margin-top:5px;">
  <tr class="hidden">
  <td class="gmap">
  ',( count($arrExtData)>1 ? $str :'' ),'
  <div id="map_canvas" style="width:100%; height:350px;"></div>
  <p class="gmap" style="margin:4px 0 0 0">',sprintf($L['map']['items'],strtolower( LangS('Topic',count($arrExtData))),strtolower(LangS('Topic',$intCount)) ),'</p>
  </td>
  </tr>
  </table>
  ';
  }
}

echo '<p>&laquo;&nbsp;<a href="',Href($oVIP->exiturl),'">',$oVIP->exitname,'</a></p>';

// --------
// HTML END
// --------

// MAP MODULE

if ( $bMap )
{
  if ( count($arrExtData)>0 ) { include('qtim_map_load.php'); } else { echo '<script type="text/javascript">function GUnload() { return true; }</script>'; }
}

include('qti_p_footer.php');
Return current item: QuickTicket