2
Hi tvn,
Replace modules/smartfaq/include/search.inc.php with these codes (thanks to photositelinks.com)
// $Id: search.inc.php,v 1.0 2007/06/10 21:29:00 photosite
// FILE :: search.inc.php
// AUTHOR :: photosite
// WEB :: Photo Site Links
//
function smartfaq_search($queryarray, $andor, $limit, $offset, $userid)
{
global $xoopsDB ;
$showcontext = isset( $_GET['showcontext'] ) ? $_GET['showcontext'] : 0 ;
if( $showcontext == 1){
$sql = "SELECT f.faqid, f.categoryid, f.question, f.datesub, f.status, a.answer, a.uid FROM ".$xoopsDB->prefix("smartfaq_faq")." f LEFT JOIN ".$xoopsDB->prefix("smartfaq_answers")." a ON f.faqid = a.faqid WHERE ( f.status = 5 OR f.status = 6 )";
}else{
$sql = "SELECT f.faqid, f.categoryid, f.question, f.datesub, f.status, a.uid FROM ".$xoopsDB->prefix("smartfaq_faq")." f LEFT JOIN ".$xoopsDB->prefix("smartfaq_answers")." a ON f.faqid = a.faqid WHERE ( f.status = 5 OR f.status = 6 )";
}
if ( $userid != 0 ) {
$sql .= " AND a.uid=".$userid." ";
}
// because count() returns 1 even if a supplied variable
// is not an array, we must check if $querryarray is really an array
if ( is_array($queryarray) && $count = count($queryarray) ) {
$sql .= " AND ((f.question LIKE '%$queryarray[0]%' OR a.answer LIKE '%$queryarray[0]%')";
for($i=1;$i<$count;$i++){
$sql .= " $andor ";
$sql .= "(f.question LIKE '%$queryarray[$i]%' OR a.answer LIKE '%$queryarray[$i]%')";
}
$sql .= ") ";
}
$sql .= "ORDER BY f.datesub DESC";
// get twice records
$result = $xoopsDB->query($sql, 2*$limit, $offset);
$module_handler = &xoops_gethandler('module');
$module = $module_handler->getByDirname('smartfaq');
$mid = $module->getVar('mid');
$gperm_handler = &xoops_gethandler('groupperm');
global $xoopsUser;
if ( is_object($xoopsUser) )
{
$groups = $xoopsUser->getGroups();
}
else
{
$groups = XOOPS_GROUP_ANONYMOUS;
}
$ret = array();
$i = 0;
$myts =& MyTextSanitizer::getInstance();
while($myrow = $xoopsDB->fetchArray($result) )
{
$faqid = $myrow['faqid'];
$catid = $myrow['categoryid'];
// permission
if ( !$gperm_handler->checkRight('category_read', $catid, $groups, $mid) )
{
continue;
}
if ( !$gperm_handler->checkRight('item_read', $faqid, $groups, $mid) )
{
continue;
}
$ret[$i]['image'] = 'images/smartfaq.gif';
$ret[$i]['link'] = 'faq.php?faqid='.$myrow['faqid'];
$ret[$i]['title'] = $myts->htmlSpecialChars($myrow['question']);
$ret[$i]['time'] = $myrow['datesub'];
$ret[$i]['uid'] = $myrow['uid'];
if( function_exists( 'search_make_context' ) && ! empty( $_GET['showcontext'] ) ) {
$context = $myrow['answer'];
$context = strip_tags($myts->displayTarea(strip_tags($context)));
$ret[$i]['context'] = search_make_context($context,$queryarray);
}
$i++;
// show twice of limit
if (($limit > 0) && ($i >= $limit)) break;
}
return $ret;
}
?>