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

/*
 * PHP versions 4 and 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.
 *
 * @category   Troubleticket
 * @package    QuickTicket
 * @author     Philippe Vandenberghe <hide@address.com>
 * @copyright  2008-2012 The PHP Group
 * @license    http://www.php.net/license  PHP License 3.0
 * @version    1.9.0.3 build:20081001
 * @link       http://www.qt-cute.org/doc/package/qti
 * @since      File available since Release 1.0.0
 * @deprecated File deprecated in Release 2.0.0
 *
 */

session_start();
require_once('bin/qti_init.php');
if ( !$oVIP->CanAccess('MUV',5,true) ) $oVIP->EndMessage('!',$L['R_member'],$_SESSION[QT]['skin_dir'],0);

if ( !isset($_GET['ti']) ) die('Missing parameter ti');
if ( !isset($_GET['y']) ) die('Missing parameter y');
if ( !isset($_GET['s']) ) die('Missing parameter s');

// INITIALISE

$bMap = UseModule('map');
if ( $bMap ) { if ( empty($_SESSION[QT]['m_map_gkey']) ) $bMap=false; }
if ( $bMap ) { require_once('qtim_map_lib.php'); if ( !QTgcanmap('S',$oVIP->role) ) $bMap=false; }
if ( $bMap ) include(Translate('qtim_map.inc'));

$strOrder = 'lastpostdate';
$strDirec = 'DESC';
$intLimit = 0;
$intPage = 1;

// security check 1
$strTime = strip_tags($_GET['ti']);
$intYear = intval($_GET['y']);
$s = intval($_GET['s']);

// security check 2 (no long argument)
if ( strlen($strTime)>2 ) die('Invalid argument #ti');
if ( $intYear<1970 || $intYear>2070 ) die('Invalid argument #y');

$intLimit = ($intPage-1)*$_SESSION[QT]['topics_per_page'];

if ($oVIP->numpost>0)
{
$oDB2 = new cDB($qti_dbsystem,$qti_host,$qti_database,$qti_user,$qti_pwd,$qti_port,$qti_dsn);
}

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

include('bin/qti_fn_limitsql.php');

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

// criteria section

if ( $s<0 )
{
  $strSection = 't.forum>=0 AND f.type<>"1"';
  if ( $oVIP->role=='A' || $oVIP->role=='M' ) $strSection = 't.forum>=0';
}
else
{
  $strSection = 't.forum='.$s;
}

if ( $bMap )
{
  $arrMapPoints = array();
  $strHeaderAddScript = QTgmapheader('http://gmaps-utility-library.googlecode.com/svn/trunk/markermanager/release/src/markermanager.js');
  $strBodyAddOnunload='GUnload()';
}

$arrJava = array('com'=>false);

include('qti_p_header.php');

echo '<table class="ta_button" cellspacing="0">',N;
echo '<tr class="tr_button">',N;
echo '<td>&nbsp;</td>',N;
echo '<td style="width:25px" class="td_button">',AsImg($_SESSION[QT]['skin_dir'].'/ico_topic_t_0.gif','T',$L['Ico_topic_t_0'],'ico ico_t'),'</td>',N;
echo '<td style="width:120px" class="td_button">&nbsp;<a href="qti_search_ov.php?a=last" class="a_button">',$L['Recent_messages'],'</a>&nbsp;</td>',N;
echo '<td style="width:10px">&nbsp;</td>',N;
echo '<td style="width:25px" class="td_button">',AsImg($_SESSION[QT]['skin_dir'].'/ico_topic_a_0.gif','T',$L['Ico_topic_a_0'],'ico ico_t'),'</td>',N;
echo '<td style="width:120px" class="td_button">&nbsp;<a href="qti_search_ov.php?a=news" class="a_button">'.$L['All_news'].'</a>&nbsp;</td>',N;
if ($oVIP->role!='V')
{
  echo '<td style="width:10px">&nbsp;</td>',N;
  echo '<td style="width:25px" class="td_button">',AsImg($_SESSION[QT]['skin_dir'].'/ico_user_p_1.gif','T',$L['Ico_user_p_1'],'ico ico_user'),'</td>',N;
  echo '<td style="width:120px" class="td_button">&nbsp;<a href="qti_search_ov.php?a=user&amp;id=',$oVIP->id,'&amp;n=',urlencode($oVIP->username),'" class="a_button">',$L['All_my_topics'],'</a>&nbsp;</td>',N;
}
echo '</tr>',N;
echo '</table>',N;

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

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

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

  // date this week (by default)
  if ( $strTime=='m' ) $strTime=date('n');
  if ( $strTime=='y' )
  {
    // this year
    switch(substr($oDB->type,0,5))
    {
    case 'mysql': $strDate = 'LEFT(t.firstpostdate,4)="'.$intYear.'"'; break;
    case 'mssql': $strDate = 'LEFT(t.firstpostdate,4)="'.$intYear.'"'; break;
    case 'pg':    $strDate = 'SUBSTRING(t.firstpostdate,1,4)="'.$intYear.'"'; break;
    case 'ibase': $strDate = 'SUBSTRING(t.firstpostdate FROM 1 FOR 4)="'.$intYear.'"'; break;
    case 'sqlit': $strDate = 'SUBSTR(t.firstpostdate,1,4)="'.$intYear.'"'; break;
    case 'acces': $strDate = 'LEFT(t.firstpostdate,4)="'.$intYear.'"'; break;
    case 'db2':   $strDate = 'SUBSTR(t.firstpostdate,1,4)="'.$intYear.'"'; break;
    case 'ifx':   $strDate = 'SUBSTRING(t.firstpostdate,1,4)="'.$intYear.'"'; break;
    case 'oci':   $strDate = 'SUBSTR(t.firstpostdate,1,4)="'.$intYear.'"'; break;
    default: die('Unknown db type '.$oDB->type);
    }
  }
  elseif ( $strTime=='w' )
  {
    // this week
    switch(substr($oDB->type,0,5))
    {
    case 'mysql': $strDate = 'LEFT(t.firstpostdate,8)>"'.DateAdd(date('Ymd'),-8,'day').'"'; break;
    case 'mssql': $strDate = 'LEFT(t.firstpostdate,8)>"'.DateAdd(date('Ymd'),-8,'day').'"'; break;
    case 'pg':    $strDate = 'SUBSTRING(t.firstpostdate,1,8)>"'.DateAdd(date('Ymd'),-8,'day').'"'; break;
    case 'ibase': $strDate = 'SUBSTRING(t.firstpostdate FROM 1 FOR 8)>"'.DateAdd(date('Ymd'),-8,'day').'"'; break;
    case 'sqlit': $strDate = 'SUBSTR(t.firstpostdate,1,8)>"'.DateAdd(date('Ymd'),-8,'day').'"'; break;
    case 'acces': $strDate = 'LEFT(t.firstpostdate,8)>"'.DateAdd(date('Ymd'),-8,'day').'"'; break;
    case 'db2':   $strDate = 'SUBSTR(t.firstpostdate,1,8)>"'.DateAdd(date('Ymd'),-8,'day').'"'; break;
    case 'ifx':   $strDate = 'SUBSTRING(t.firstpostdate,1,8)>"'.DateAdd(date('Ymd'),-8,'day').'"'; break;
    case 'oci':   $strDate = 'SUBSTR(t.firstpostdate,1,8)>"'.DateAdd(date('Ymd'),-8,'day').'"'; break;
    default: die('Unknown db type '.$oDB->type);
    }
  }
  else
  {
    // the month
    $intMonth = intval($strTime);
    // check if month from previous year
    if ( $intYear==date('Y') && $intMonth>date('n') ) $intYear = $intYear-1;

    switch(substr($oDB->type,0,5))
    {
    case 'mysql': $strDate = 'LEFT(t.firstpostdate,6)="'.($intYear*100+$intMonth).'"'; break;
    case 'mssql': $strDate = 'LEFT(t.firstpostdate,6)="'.($intYear*100+$intMonth).'"'; break;
    case 'pg':    $strDate = 'SUBSTRING(t.firstpostdate,1,6)="'.($intYear*100+$intMonth).'"'; break;
    case 'ibase': $strDate = 'SUBSTRING(t.firstpostdate FROM 1 FOR 6)="'.($intYear*100+$intMonth).'"'; break;
    case 'sqlit': $strDate = 'SUBSTR(t.firstpostdate,1,6)="'.($intYear*100+$intMonth).'"'; break;
    case 'acces': $strDate = 'LEFT(t.firstpostdate,6)="'.($intYear*100+$intMonth).'"'; break;
    case 'db2':   $strDate = 'SUBSTR(t.firstpostdate,1,6)="'.($intYear*100+$intMonth).'"'; break;
    case 'ifx':   $strDate = 'SUBSTRING(t.firstpostdate,1,6)="'.($intYear*100+$intMonth).'"'; break;
    case 'oci':   $strDate = 'SUBSTR(t.firstpostdate,1,6)="'.($intYear*100+$intMonth).'"'; break;
    default: die('Unknown db type '.$oDB->type);
    }
  }

$oDB->Query
(
'SELECT count(*) as countid FROM '.TABTOPIC.' t INNER JOIN '.TABSECTION.' f ON t.forum=f.id WHERE '.$strSection.' AND '.$strDate
);
$row = $oDB->Getrow();
$intCount = $row['countid'];

// FOUND

$strSubtitle='';
if ( $strTime=='w' ) $strSubtitle = $L['This_week'];
if ( $strTime=='m' ) $strSubtitle = $L['This_month'];
if ( $strTime=='y' ) $strSubtitle = $L['This_year'];
if ( is_numeric($strTime) ) $strSubtitle = $L['dateMMM'][intval($strTime)].' '.$intYear;
if ( $s>=0 ) $strSubtitle .= ' ('.$L['Section'].': '.(isset($_SESSION['qtiGoto'][$s]) ? $_SESSION['qtiGoto'][$s] : '').')';
$strSubtitle = '<p>'.$L['Topics'].': '.$strSubtitle.'&nbsp;&nbsp;&middot;&nbsp;&nbsp;'.LangS('Result',$intCount).'</p>';

// NO RESULT

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

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

$oDB->Query
(
'SELECT t.*, f.title as sectiontitle, p.icon, p.title, p.textmsg, f.numfield, f.prefix
 FROM '.TABTOPIC.' t INNER JOIN '.TABSECTION.' f ON t.forum = f.id INNER JOIN '.TABPOST.' p ON t.firstpostid = p.id
 WHERE '.$strSection.' AND '.$strDate.' ORDER BY '.$strFullOrder
);

echo $strSubtitle;

// --------
// Post content
// --------

echo '<table class="ta ta_t" cellspacing="0">',N;
echo '<tr class="tr_t tr_t0">',N;

$arrFields = array(); // SORT LABEL CLASS STYLE
$arrFields['status'] = array(FALSE,S, 'th_t th_t_ico th_t_first', 'width:25px');
$arrFields['numid'] = array(TRUE, $L['Ref'], 'th_t th_t_ref', 'width:50px');
$arrFields['smile'] = array(FALSE,S, 'th_t th_t_inf', 'width:20px');
$arrFields['title'] = array(TRUE, $L['Topics'], 'th_t th_t_tit', '');
$arrFields['you'] = array(FALSE,S, 'th_t th_t_inf', 'width:10px');
$arrFields['sectiontitle'] = array(TRUE, $L['Section'], 'th_t th_t_inf', '');
$arrFields['firstpostname'] = array(TRUE, $L['Topic_starter'], 'th_t th_t_inf', 'width:125px');
$arrFields['lastpostdate'] = array(TRUE, $L['Last_message'], 'th_t th_t_inf', 'width:125px');
$arrFields['replies'] = array(TRUE, $L['Last_column_label']['replies'], 'th_t th_t_inf th_t_last', 'width:70px;text-align:center');

/* ======== */
TableHeader($arrFields,$intCount,'qti_search_ti.php?y='.$intYear.'&amp;ti='.$strTime.'&amp;s='.$s.'&amp;page=1',$strOrder,$strDirec);
/* ======== */

echo '</tr>',N;

// insert topics rows
$bAddPrefix = true;
$bAddSection = true;
$bAddRef = true;
$strExtra='replies';
if ( $bMap ) { if ( $_SESSION[QT]['m_map']['S']['icon']!='S' ) { $arrSymbol = array($_SESSION[QT]['m_map']['S']['icon'],$_SESSION[QT]['m_map']['S']['shadow'],$_SESSION[QT]['m_map']['S']['printicon'],$_SESSION[QT]['m_map']['S']['printshadow']); } }
include('qti_topics_inc.php');

echo '<tr class="tr_t tr_t9">',N;
echo '<td class="tf_t tf_t_first"></td>',N;
For ($i=0;$i<(count($arrFields)-2);$i++)
{
echo '<td class="tf_t"></td>',N;
}
echo '<td class="tf_t tf_t_last"></td>',N;
echo '</tr>',N;

echo '</table>',N;

// -- no data --
if ( $intWhile==0 ) echo '<tr><td class="td_t td_t_tit1" colspan="6">',$L['None'],'...</td></tr>',N;

// MAP MODULE

if ( $bMap )
{
  if ( count($arrMapPoints)==0 )
  {
  echo '<p class="p_gmap">'.$L['map']['E_noposition'].'</p>';
  }
  else
  {
     //select zoomto (maximum 15 items in the list)
     if ( count($arrMapPoints)>1 )
     {
       $str = '<p class="p_gmap" style="margin:0 0 4px 0"><a class="a_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 ( $arrMapPoints 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="ta_hidden" style="margin-top:5px;">
  <tr class="tr_hidden">
  <td class="div_gmap">
  ',( count($arrMapPoints)>1 ? $str :'' ),'
  <div id="map_canvas" style="width:100%; height:350px;"></div>
  <p class="p_gmap" style="margin:4px 0 0 0">',sprintf($L['map']['items'],strtolower( LangS('Topic',count($arrMapPoints))),strtolower(LangS('Topic',$intCount)) ),'</p>
  </td>
  </tr>
  </table>
  ';
  }
}

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

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

if ( $bMap ) {
if ( count($arrMapPoints)>0 ) {

  $x = QTgetx($_SESSION[QT]['m_map_gcenter']);
  $y = QTgety($_SESSION[QT]['m_map_gcenter']);

  // center on the first ticket
  foreach ($arrMapPoints as $intKey => $oMapPoint)
  {
    if ( !empty($oMapPoint->y) && !empty($oMapPoint->x) )
    {
    $y = $oMapPoint->y;
    $x = $oMapPoint->x;
    break;
    }
  }

  $strFooterAddScript = QTgmappoints($L['map'],$y,$x,'click',$arrMapPoints).N.'mapload();';

}}

include('qti_p_footer.php');

?>
Return current item: QuickTicket