<?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['title']) ) die('Missing parameter keyword');
// 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
if ( isset($_GET['order']) ) $strOrder = strip_tags($_GET['order']);
if ( isset($_GET['dir']) ) $strDirec = strip_tags($_GET['dir']);
if ( isset($_GET['page']) ) $intPage = intval(strip_tags($_GET['page']));
if ( isset($_GET['view']) ) $_SESSION[QT]['viewmode'] = strip_tags($_GET['view']);
// security check 2 (no long argument)
if ( strlen($strOrder)>12 ) die('Invalid argument #order');
if ( strlen($strDirec)>4 ) die('Invalid argument #dir');
$intLimit = ($intPage-1)*$_SESSION[QT]['topics_per_page'];
$bAddRef = false;
$s = -1;
$strK = '';
$strSP = '0';
$strTO = '0';
$strAL = '0';
// security check 1
if ( isset($_GET['s']) ) $s = intval(strip_tags($_GET['s']));
if ( isset($_GET['title']) ) $strK = strip_tags($_GET['title']);
if ( isset($_GET['sp']) ) $strSP = strip_tags($_GET['sp']);
if ( isset($_GET['to']) ) $strTO = strip_tags($_GET['to']);
if ( isset($_GET['al']) ) $strAL = strip_tags($_GET['al']);
// security check 2 (no long argument)
if ( strlen($strK)>64 ) die('Invalid argument #title');
if ( strlen($strSP)>2 ) die('Invalid argument #sp');
if ( strlen($strTO)>2 ) die('Invalid argument #to');
if ( strlen($strAL)>2 ) die('Invalid argument #al');
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_kw.php';
$oVIP->selfname = $L['Search_by_key'];
$oVIP->exiturl = 'qti_search.php?'.QTargimplode(QTargexplode());
$oVIP->exitname = $L['Search'];
include('bin/qti_fn_limitsql.php');
// --------
// CHECK CRITERIA
// --------
if ( $strK=='' )
{
// exit
$oVIP->EndMessage(NULL,$L['Keywords'].' K '.$L['E_invalid'],$_SESSION[QT]['skin_dir'],0);
}
$arrKeys = split(' ',$strK);
if ( $strSP!='0' && $strSP!='1' )
{
// exit
$oVIP->EndMessage(NULL,$L['Keywords'].' S= $strSP > '.$L['E_invalid'],$_SESSION[QT]['skin_dir'],0);
exit;
}
if ( $strTO!='0' && $strTO!='1' )
{
// exit
$oVIP->EndMessage(NULL,$L['In_title_only'].' TO '.$L['E_invalid'],$_SESSION[QT]['skin_dir'],0);
exit;
}
if ( !QTisbetween($strAL,0,9) )
{
// exit
$oVIP->EndMessage(NULL,'At_least '.$L['E_invalid'],$_SESSION[QT]['skin_dir'],0);
exit;
}
if ( $strSP=='1' )
{
if ( count($arrKeys)<1 ) $strSP='0';
if ( count($arrKeys)>5 )
{
// exit
$oVIP->EndMessage(NULL,$L['Too_many_keys'],$_SESSION[QT]['skin_dir'],0);
exit;
}
}
// --------
// BUILD CRITERIA
// --------
// full word criteria
$qryTitle = 'UPPER(p.title) LIKE "%'.strtoupper($strK).'%"';
switch ($oDB->type)
{
case 'db2': $qryMessage = 'UPPER(p.textmsg2) LIKE "%'.strtoupper($strK).'%"'; break;
case 'ifx': $qryMessage = 'UPPER(p.textmsg2) LIKE "%'.strtoupper($strK).'%"'; break;
default: $qryMessage = 'UPPER(p.textmsg) LIKE "%'.strtoupper($strK).'%"'; break;
}
// split criteria
if ( $strSP=='1' )
{
$qryTitle = '(';
$qryMessage = '(';
$qryOr = '';
foreach ($arrKeys as $intKey => $strValue)
{
$qryTitle .= $qryOr.'UPPER(p.title) LIKE "%'.strtoupper($strValue).'%"';
switch ($oDB->type)
{
case 'db2': $qryMessage .= $qryOr.'UPPER(p.textmsg2) LIKE "%'.strtoupper($strValue).'%"'; break;
case 'ifx': $qryMessage .= $qryOr.'UPPER(p.textmsg2) LIKE "%'.strtoupper($strValue).'%"'; break;
default: $qryMessage .= $qryOr.'UPPER(p.textmsg) LIKE "%'.strtoupper($strValue).'%"'; break;
}
$qryOr = ' OR ';
}
$qryTitle .= ') ';
$qryMessage .= ') ';
}
// section criteria
$qrySection = 't.forum='.$s;
if ( $s<0 )
{
$qrySection = 't.forum>=0 AND f.type<>"1"';
if ( $oVIP->role=='A' || $oVIP->role=='M' ) $qrySection = 't.forum>=0';
// check if result would have references
if ( count(GetSections($oVIP->role,-1,-1,'numfield<>"N"'))>0 ) $bAddRef=TRUE;
}
else
{
// check if result would have references
if ( count(GetSections('A',-1,-1,'numfield<>"N" AND id='.$s))>0 ) $bAddRef=True;
}
// atleast criteria
$qryAtleast='';
if ( $strAL>0 ) $qryAtleast = ' AND t.replies >= '.$strAL;
// BUILD QUERY
$qryCount = 'SELECT count(t.id) as countid ';
$qryField = 't.*, f.title as sectiontitle,f.prefix, p.icon, p.title, p.textmsg, f.numfield ';
$strFrom = 'FROM '.TABTOPIC.' t INNER JOIN '.TABSECTION.' f ON t.forum = f.id INNER JOIN '.TABPOST.' p ON t.id = p.topic ';
if ( $strTO=='1' )
{
$strWhere = "WHERE $qrySection AND $qryTitle $qryAtleast ";
}
else
{
$strWhere = "WHERE $qrySection AND ($qryTitle OR $qryMessage) $qryAtleast ";
}
// --------
// CONTENT
// --------
$arrSortable = array('status'=>'ASC','numid'=>'DESC','title'=>'ASC','sectiontitle'=>'ASC','firstpostname'=>'ASC','lastpostdate'=>'DESC','replies'=>'DESC');
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> </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"> <a href="qti_search_ov.php?a=last" class="a_button">',$L['Recent_messages'],'</a> </td>',N;
echo '<td style="width:10px"> </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"> <a href="qti_search_ov.php?a=news" class="a_button">',$L['All_news'],'</a> </td>',N;
if ($oVIP->role!='V')
{
echo '<td style="width:10px"> </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"> <a href="qti_search_ov.php?a=user&id=',$oVIP->id,'&n=',urlencode($oVIP->username),'" class="a_button">',$L['All_my_topics'],'</a> </td>',N;
}
echo '</tr>',N,'</table>',N;
// -----
// COUNT
// -----
$oDB->Query($qryCount.$strFrom.$strWhere);
$row = $row = $oDB->Getrow();
$intCount = $row['countid'];
// NO RESULT
if ( $intCount==0 )
{
$strSubtitle='';
if ( $s>=0 ) $strSubtitle = ' ('.$L['Section'].': '.(isset($_SESSION['qtiGoto'][$s]) ? $_SESSION['qtiGoto'][$s] : '').')';
echo '<h2>',$oVIP->selfname,'</h2>',N;
echo $strK,$strSubtitle,' · ',LangS('Result',$intCount),N;
if ( $strSP=='0' && count($arrKeys)>1 )
{
echo ' · <a href="',$oVIP->selfurl,'?title=',$strK,'&sp=1&s=',$s,'&to=',$strTO,'&al=',$strAL,'">',$L['Search_by_words'],'</a>';
}
if ( $strSP=='1' && count($arrKeys)>1 )
{
echo ' · <a href="',$oVIP->selfurl,'?title=',$strK,'&sp=0&s=',$s,'&to=',$strTO,'&al=',$strAL,'">',$L['Search_exact_words'],'</a>';
}
echo '<p>',$L['None'],'</p>',N;
echo '<p>« <a href="',$oVIP->exiturl,'">',$oVIP->exitname,'</a></p>';
include('qti_p_footer.php');
exit;
}
// -----
// QUERY
// -----
// 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';
$strQ = LimitSQL($qryField.$strFrom.$strWhere,$strFullOrder,$intLimit,$_SESSION[QT]['topics_per_page'],$intCount);
$oDB->Query($strQ);
// -- Display result --
echo '<h2>',$oVIP->selfname,'</h2>',N;
echo $strK,' · ',LangS('Result',$intCount);
if ( $strSP=='0' && count($arrKeys)>1 )
{
echo ' · <a href="',$oVIP->selfurl,'?title=',$strK,'&sp=1&s=',$s,'&to=',$strTO,'&al=',$strAL,'">',$L['Search_by_words'],'</a>';
}
if ( $strSP=='1' && count($arrKeys)>1 )
{
echo ' · <a href="',$oVIP->selfurl,'?title=',$strK,'&sp=0&s=',$s,'&to=',$strTO,'&al=',$strAL,'">',$L['Search_exact_words'],'</a>';
}
// --------
// Button line and pager
// --------
// -- build pager --
$pager = MakePager("$oVIP->selfurl?title=$strK&sp=$strSP&s=$s&to=$strTO&al=$strAL",$intCount,$_SESSION[QT]['topics_per_page'],$intPage);
if ($pager!='') $pager = $L['Page'].$pager;
$strCommand = S.$pager;
// -- Displays pager --
echo '<table class="ta_hidden" cellspacing="0"><tr class="tr_hidden"><td class="td_hidden" id="zone_pager_top">',$strCommand,'</td></tr></table>';
// --------
// 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(TRUE, '-', 'th_t th_t_ico th_t_first', 'width:25px');
if ( $bAddRef )
{
$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,"$oVIP->selfurl?title=$strK&sp=$strSP&s=$s&to=$strTO&al=$strAL&page=1",$strOrder,$strDirec);
/* ======== */
echo '</tr>',N;
/* ======== */
$bAddPrefix = true;
$bAddSection = true;
$strExtra='replies';
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;
// -- Displays pager --
echo '<table class="ta_hidden" cellspacing="0"><tr class="tr_hidden"><td class="td_hidden" id="zone_pager_bot">',$strCommand,'</td></tr></table>';
// 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 => $arrMapPoint )
{
$str .= '<option class="gmap" value="new GLatLng('.$arrMapPoint['y'].','.$arrMapPoint['x'].')">'.$arrMapPoint['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>« <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;
}
}
// override symbol
if ( $_SESSION[QT]['m_map']['S']['icon']!='S' ) $arrMapPoints = QTgoverridesymbol($arrMapPoints,$_SESSION[QT]['m_map']['S']['icon']);
$strFooterAddScript = QTgmappoints($L['map'],$y,$x,'click',$arrMapPoints).N.'mapload();';
}}
include('qti_p_footer.php');