Location: PHPKode > projects > QuickTicket > quickticket/qti_search.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');
require_once('bin/qti_fn_tags.php');
if ( !$oVIP->CanView('V5') ) HtmlPage(11);

// INITIALISE

$oVIP->selfurl = 'qti_search.php';
$oVIP->selfname = $L['Search'];
$oVIP->exitname = $L['Search'];

$a = 'ref';
$s = -1;
$k1 = '';
$k2 = '';
$k3 = '';
QThttpvar('a s k1 k2 k3','str int str str str');
if ( isset($_POST['s_ref']) ) $s = strip_tags($_POST['s_ref']);
if ( isset($_POST['s_tst']) ) $s = strip_tags($_POST['s_tst']);
if ( isset($_POST['s_kw']) ) $s = strip_tags($_POST['s_kw']);

$strOptions = '';
foreach(array('s','k1','k2','k3') as $key) $strOptions .= '&amp;'.$key.'='.urlencode($$key);

// --------
// SUBMITTED
// --------

if ( isset($_POST['okref']) )
{
  if ( empty($k1) ) $error = $L['Ref'].' '.$L['E_invalid'];
  if ( empty($error) ) { $oVIP->exiturl = 'qti_find.php?a=ref'.$strOptions; $oVIP->EndMessage('0'); exit; }
}
if ( isset($_POST['oktst']) )
{
  if ( $k1=='-' || $k1=='--' || $k2=='-' ) $error = $L['Date'].' & '.$L['Status'].' '.$L['E_invalid'];
  if ( $k1=='-1' && $k2=='-1' && empty($k3) ) $error = $L['Date'].' & '.$L['Status'].' & Tag '.$L['E_invalid'];
  if ( $k3==';' ) $error = 'Tag '.$L['E_invalid'];
  if ( empty($error) ) { $oVIP->exiturl = 'qti_find.php?a=tst&amp;y='.intval($_POST['y']).$strOptions; $oVIP->EndMessage('0'); exit; }
}
if ( isset($_POST['okkw']) )
{
  if ( empty($k1) ) $error = $L['Keywords'].' '.$L['E_invalid'];
  if ( empty($error) ) { $oVIP->exiturl = 'qti_find.php?a=kw'.$strOptions; $oVIP->EndMessage('0'); exit; }
}

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

$arrTags = cSection::GetTagsUsed(-1);
if ( count($arrTags)>0 ) $arrTags = TagsDesc($arrTags);
$str  = '';
foreach($arrTags as $strKey=>$strDesc) { $str .= '{n:"'.$strKey.'",d:"'.($strKey==$strDesc ? ' ' : substr($strDesc,0,64)).'"},'; }
$str = substr($str,0,-1);

$strHeadScript = '
<script type="text/javascript" src="bin/qt_jquery.js"></script>
<script type="text/javascript" src="bin/qt_jquery_auto.js"></script>
<script type="text/javascript">
<!--
$(document).ready(function() {
  $("#datav").autocomplete("qti_j_data.php", {
    minChars:2,
    matchContains:true,
    selectFirst: false,
    extraParams: { dataf: function() { return $("#dataf").val(); } }
    });
  $("#tag").autocomplete(['.$str.'],{
    minChars:0,
    matchContains:true,
    width:200,
    multiple:true,
    multipleSeparator:";",
    formatItem: function(row) { return (row.d==" ") ? row.n : (row.n + "<span class=small> - " + row.d + "</span>"); },
    formatResult: function(row) { return row.n; }
    });
});
-->
</script>
';  

$oHtml->links[] = '<link rel="stylesheet" type="text/css" href="bin/css/qt_jquery.css" />';

include('qti_p_header.php');
include('qti_search_inc.php');

// SEARCH OPTION

echo '<h2>',$L['Search_option'],'</h2>
<div style="width:500px">
<form method="post" action="',Href(),'">
<table class="data_s" cellspacing="0">
<tr class="data_s">
<td class="colhd colhdfirst colhdempty"></td>
<td class="colhd colhdempty"></td>
<td class="colhd colhdlastt colhdempty"></td>
</tr>
<tr class="data_s">
<td class="colct colico colfirst">',AsImg($_SESSION[QT]['skin_dir'].'/ico_section_option.gif','search',$L['Search'],'ico ico_s'),'</td>
<td class="colct">',$L['Section'],' <select id="s" name="s" size="1" class="small" onchange="SearchOption(this.value);">
<option value="-1"',($s<0 ? QSEL : ''),'>',$L['In_all_sections'],'</option>',Gotolist($s),'
</select>
<input type="submit" id="o_ok" name="o_ok" value="',$L['Ok'],'" />
</td>
<td class="colct"></td>
</tr>
<tr class="colft">
<td class="colft colftfirst"></td>
<td class="colft"></td>
<td class="colft colflast"></td>
</tr>
</table>
</form>
</div>
';

echo '
<h2>',$L['Search_criteria'],'</h2>
';

// ERROR MESSAGE

if ( !empty($error) ) echo '<p class="error">',$error,'</p>';

// SEARCH BY REF

if ( isset($oVIP) ) {
if ( count($oVIP->sections)>0 ) { $arrSections = QTarrget(GetSections($oVIP->role,-1,-1,'s.numfield<>"N"'));
if ( count($arrSections)>0 ) {
echo '<form method="post" action="',Href(),'">
<table class="data_s" cellspacing="0">
<tr class="data_s">
<td class="colhd colhdfirst colhdempty"></td>
<td class="colhd colhdempty"></td>
<td class="colhd colhdlastt colhdempty"></td>
</tr>
<tr class="data_s">
<td class="colct colico colfirst">',AsImg($_SESSION[QT]['skin_dir'].'/ico_section_search.gif','search',$L['Search'],'ico ico_s'),'</td>
<td class="colct">',$L['Ref'],' <input type="text" id="ref" name="k1" size="5" maxlength="10" value="'.($a=='ref' ? $k1 : '').'" onkeyup="qtKeypress(event,\'okref\')" />&nbsp;<span class="small">',$L['H_Reference'],'</span></td>
<td class="colct" style="padding:7px; text-align:right">
<input type="hidden" id="s_ref" name="s_ref" value="',$s,'" />
<input type="submit" id="okref" name="okref" value="',$L['Search'],'" onclick="return ValidateForm(\'ref\');" />
</td>
</tr>
<tr class="colft">
<td class="colft colftfirst"></td>
<td class="colft"></td>
<td class="colft colflast"></td>
</tr>
</table>
</form>
<br />
';
}}}

// SEARCH BY KEY

echo '<form method="post" action="',Href(),'">
<table class="data_s" cellspacing="0">
<tr class="data_s">
<td class="colhd colhdfirst colhdempty"></td>
<td class="colhd colhdempty"></td>
<td class="colhd colhdlastt colhdempty"></td>
</tr>
<tr class="data_s">
<td class="colct colico colfirst">',AsImg($_SESSION[QT]['skin_dir'].'/ico_section_search.gif','search',$L['Search'],'ico ico_s'),'</td>
<td class="colct">',$L['Keywords'],' <input type="text" id="kw" name="k1" size="40" maxlength="64" value="'.($a=='kw' ? $k1 : '').'" onkeyup="qtKeypress(event,\'okkw\')" />&nbsp;<input type="checkbox" id="to" name="k3"',($a=='kw' && !empty($k3) ? QCHE : ''),' value="1" /> <label for="to">',$L['In_title_only'],'</label>
</td>
<td class="colct" style="padding:7px; text-align:right">
<input type="hidden" id="s_kw" name="s_kw" value="',$s,'" />
<input type="submit" id="okkw" name="okkw" value="',$L['Search'],'" onclick="return ValidateForm(\'kw\');" />
</td>
</tr>
<tr class="colft">
<td class="colft colftfirst"></td>
<td class="colft"></td>
<td class="colft colflast"></td>
</tr>
</table>
</form>
<br />
';

// SEARCH BY DATE & STATUS & TAGS

echo '<form method="post" action="',Href(),'">
<table class="data_s" cellspacing="0">
<tr class="data_s">
<td class="colhd colhdfirst colhdempty"></td>
<td class="colhd colhdempty"></td>
<td class="colhd colhdlastt colhdempty"></td>
</tr>
<tr class="data_s">
<td class="colct colico colfirst">',AsImg($_SESSION[QT]['skin_dir'].'/ico_section_search.gif','search',$L['Search'],'ico ico_s'),'</td>
<td class="colct">',$L['Date'],' <select id="ti" name="k1" size="1" class="small">
<option value="w"',($k1=='w' ? QSEL : ''),'>',$L['This_week'],'</option>
<option value="m"',($k1=='m' ? QSEL : ''),'>',$L['This_month'],'</option>
<option value="y"',($k1=='y' ? QSEL : ''),'>',$L['This_year'],'</option>
<option value="-" disabled="disabled">-----------</option>
<option value="-1"',($k1=='-1' ? QSEL : ''),'>',$L['Any_time'],'</option>
<option value="--" disabled="disabled">-----------</option>
',QTasTag($L['dateMMM'],$k1),'
</select><input type="hidden" name="y" value="',date('Y'),'" />
',$L['Status'],' <select id="st" name="k2" size="1" class="small">
<option value="-1"',($k2=='-1' ? QSEL : ''),'>',$L['Any_status'],'</option>
<option value="-" disabled="disabled">-----------</option>
 ',QTasTag($oVIP->statuses,$k2),'
</select>
 ';
if ( $_SESSION[QT]['tags']!='0' ) echo $L['With_tag'],' <input type="text" id="tag" name="k3" size="30" value="'.($a=='tst' ? $k3 : '').'" onkeyup="qtKeypress(event,\'okti\')" class="small" />*';
echo '</td>
<td class="colct" style="padding:7px; text-align:right">
<input type="hidden" id="s_tst" name="s_tst" value="',$s,'" />
<input type="submit" id="oktst" name="oktst" value="',$L['Search'],'" />
</td>
</tr>
<tr class="colft">
<td class="colft colftfirst"></td>
<td class="colft"></td>
<td class="colft colflast"></td>
</tr>
</table>
</form>
';
if ( $_SESSION[QT]['tags']!='0' ) echo '<p class="small">* ',$L['H_Tag_input'],'</p>';

// HTML END

echo '<script type="text/javascript">
<!--
document.getElementById("o_ok").style.visibility="hidden";
document.getElementById("kw").focus();
function SearchOption(strValue)
{
  if (document.getElementById("s_ref")) document.getElementById("s_ref").value=strValue;
  if (document.getElementById("s_tst")) document.getElementById("s_tst").value=strValue;
  if (document.getElementById("s_kw")) document.getElementById("s_kw").value=strValue;
}
function ValidateForm(strId)
{
  strError = strId;
  if (strId=="kw") strError = "',str_replace('"','',$L['Keywords']),'"; 
  if (document.getElementById(strId).value.length==0) { alert(strError.toUpperCase()+" - "+qtHtmldecode("',$L['Missing'],'")); return false; }
  return null;
}
-->
</script>
';

include('qti_p_footer.php');

?>
Return current item: QuickTicket