Search and filter function for StarSol's FAQ in osTicket
OK, I did some copy & paste from other functions in the script and here's the FAQ search & filter function.
I took the faq_list module from faq_admin.php
Stripped away the link to the admin functions and edit/reset/delete
I added a link to the result with target=_top to point to the detailed question/answer
I copied it in the faq.php file and inserted the following code just after the last "break;" (should be somewhere around row 266)
// faq_list code start
case "faq_list":
if (!$_GET){
$_GET = 'All Categories';
}
if (!$_GET){
$_GET = 'qu';
}
if (!$_GET){
$_GET = 'ASC';
}
if (!$_GET){
$_GET = '50';
}
echo'<h1>Questions List</h1>'."\n\n";
echo'<table class="list-table"><tr>'."\n";
echo'<form action="'.$_SERVER.'" method="get">'."\n".'<input type="hidden" name="t" value="faq_list" />'."\n";
echo'<td style="padding: 3px; font-size: 10pt; border: 1px solid #000000;">Category:<br />'."\n".'<select name="category" size="1">'."\n".'<option selected>'.$_GET.'</option>'."\n";
if ($_GET != 'All Categories'){
echo'<option>All Categories</option>'."\n";
}
$categories = <USERMENTION username="mysql_query">@mysql_query</USERMENTION>('SELECT name FROM '.$db_prefix.'c ORDER BY uin ASC') or deal_with_mysql_error('Categories Data Retrieval MySQL Error (faq_list). '.mysql_error(),'admin');
while ($row = mysql_fetch_array($categories, MYSQL_NUM)) {
echo'<option>'.$row.'</option>'."\n";
}
echo'</select>'."\n".'</td>'."\n";
echo'<td style="padding: 3px; font-size: 10pt; border: 1px solid #000000;">Containing:<br />'."\n".'<input type="text" size="10" value="'.$_GET.'" name="containing">'."\n".'</td>'."\n";
echo'<td style="padding: 3px; font-size: 10pt; border: 1px solid #000000;">Order By:<br />'."\n".'<select name="o" size="1">'."\n";
if ($_GET == "qu"){echo'<option selected value="qu">Question</option>'."\n"; $o_show = 'Question';}else{echo'<option value="qu">Question</option>'."\n";}
if ($_GET == "an"){echo'<option selected value="an">Answer</option>'."\n"; $o_show = 'Answer';}else{echo'<option value="an">Answer</option>'."\n";}
if ($_GET == "rating"){echo'<option selected value="rating">Rating</option>'."\n"; $o_show = 'Rating';}else{echo'<option value="rating">Rating</option>'."\n";}
echo'</select>'."\n".' ';
echo'<select name="aod" size="1">'."\n";
if ($aod == "ASC"){echo'<option selected value="ASC">Ascending</option>'."\n";}else{echo'<option value="ASC">Ascending</option>'."\n";}
if ($aod == "DESC"){echo'<option selected value="DESC">Descending</option>'."\n";}else{echo'<option value="DESC">Descending</option>'."\n";}
echo'</select>'."\n".'</td>'."\n";
echo'<td style="padding: 3px; font-size: 10pt; border: 1px solid #000000;">Limit:<br />'."\n".'<input type="text" size="4" value="'.$_GET.'" name="limit">'."\n".'</td>'."\n";
echo'<td style="padding: 3px; font-size: 10pt; border: 1px solid #000000;"><input type="submit" value="Change Filter" /></td>'."\n";
echo'</form>'."\n".'</tr>'."\n".'</table>'."\n\n";
if ($_GET AND $_GET != 'All Categories'){
if (mysql_num_rows(mysql_query('SELECT uin FROM '.$db_prefix.'c WHERE name="'.$_GET.'"')) == '0'){
error_message('The category specified does not exist. Please go back and try again. If the problem persists, please contact technical <a href="'.$_SERVER.'?t=support">support</a>.');
@mysql_close();
exit;
} else {
if ($where){
$where .= ' AND category="'.$_GET.'"';
} else {
$where = 'WHERE category="'.$_GET.'"';
}
}
}
if ($_GET == 'an'){
$qoa = 'Answer';
$sqoa = 'an';
} else {
$qoa = 'Question';
$sqoa = 'qu';
}
if ($_GET){
if ($where){
$where .= ' AND '.$sqoa.' LIKE "%'.$_GET.'%"';
} else {
$where = 'WHERE '.$sqoa.' LIKE "%'.$_GET.'%"';
}
}
echo'<table class="list-table" style="margin-top: 10px;">'."\n";
echo'<tr><td class="list-heading">'.$qoa.'</td><td class="list-heading" nowrap="nowrap">Category</td><td class="list-heading">Rating</td><td class="list-heading" nowrap="nowrap">Tools</td></tr>'."\n";
$faq_query = 'SELECT uin,'.$sqoa.',category,rating,rc FROM '.$db_prefix.'q '.$where.' ORDER BY '.$_GET.' '.$_GET.' LIMIT '.$_GET;
$result = <USERMENTION username="mysql_query">@mysql_query</USERMENTION>($faq_query) or deal_with_mysql_error('FAQs Data Retrieval MySQL Error (faq_list). '.mysql_error(),'admin');
if (mysql_num_rows($result) == "0"){
echo'<tr><td style="padding: 3px; font-size: 10pt; border: 1px solid #000000;" colspan="4">There are no frequently asked questions in the database matching the criteria in the filter above.</td></tr>'."\n";
} else {
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
if (strlen($row) > 77){
$row = substr($row, 0, 75).'...';
}
if (!$row){
$row = 'None';
} else {
$row .= '% of '.$row;
}
echo'<tr><td style="padding: 3px; font-size: 10pt; border: 1px solid #000000;"><a href="faq.php?t=sq&uin='.$row.'" target="_top">'.$row.'</a></td><td style="padding: 3px; font-size: 10pt; border: 1px solid #000000;">'.htmlentities($row, ENT_QUOTES).'</td><td style="padding: 3px; font-size: 10pt; border: 1px solid #000000;">'.$row.'</td></tr>'."\n";
}
}
echo''."\n".'</table>'."\n\n";
break;
// faq_list code end
Now you can call the "public" faq_list with faq.php?t=faq_list.
Then I added this code to the faq.php file to link to the list:
around row 48 replace the code with this one (or just add the bold text with the link)
//start modified code to link to faq_list
$main_content .= '<p class="prose" style="text-align: left;">The following is a list of all categories of frequently asked questions that are currently in our database<STRONG><s>**</s>.<br> Select a category or <a href="faq.php?t=faq_list" target="_top">search/filter FAQ</a><e>**</e></STRONG>:</p>'."\n";
//end modified code to link to faq_list