<?php
# Auther: Tariq Al-Saleem.
# Created 11/08/2004.
# email: hide@address.com
# This is some changes on the faq_viewer class to display links and messages in
# multi languages systems.
# Arabic and english language is included.
# For arabic usage go to: www.tsbs.net/news.htm?id=2 .
# The original class is class.faqmanager.inc. must be available.
# there is no guarantee that this file will be updated if the original class changes.
# you can find the original class and copyright information
# on hide@address.com, http://php.amnuts.com/
#
#
// Example of use
//
// include "faqlang.ar.inc"; for arabic
// or include "faqlang.en.inc"; for english
// include "class.faqlang.inc";
// $faq = new faq_viewer("user","pass","localhost");
// $faq->setDBvars("test","faq_questions","faq_categories");
// $faq->connectDB();
//
// if (isset($search)) $faq->searchQuestions();
// else if (isset($cat)) $faq->showQuestionList();
// else $faq->showCategoryList();
require_once("class.faqmanager.inc");
class faq_viewer_lang extends faq_viewer{
function showSearchForm()
{
echo "<form action=\"{$this->_self}\">".FQ_MSG1." ";
echo "<input type=\"text\" name=\"search\" size=\"10\"> ";
echo "<input type=\"submit\" value=\"".FQ_MSG2."\"></form>";
}
function showQuestionList()
{
// get current id and category title
$cresult = @mysql_query("SELECT id,title FROM {$this->tbl_cats} WHERE id={$this->gpcVars['cat']}",$this->id)
or die("Unable to perform query: SELECT id,title FROM {$this->tbl_cats} WHERE id={$this->gpcVars['cat']}");
$crow = @mysql_fetch_array($cresult,MYSQL_ASSOC);
// if no category exists any more
if (!$crow['id'])
{
$this->showCategoryList();
return;
}
// show current title
echo "<p class=\"category\">{$crow['title']}</p>\n";
// get categories into array to get first/last/total
$cresult = @mysql_query("SELECT * FROM {$this->tbl_cats}",$this->id)
or die("Unable to perform query: SELECT * FROM {$this->tbl_cats}");
while ($crow = @mysql_fetch_array($cresult,MYSQL_ASSOC))
{
$cats[] = $crow;
}
@mysql_free_result($cresult);
$at = $this->_indexValue($cats,$this->gpcVars['cat']);
// get 'back to' if needs be
if ($at > 0)
{
$cresult = @mysql_query("SELECT id,title FROM {$this->tbl_cats} WHERE id={$cats[$at-1]['id']}",$this->id);
$crow = @mysql_fetch_array($cresult,MYSQL_ASSOC);
echo "<span class=\"navigation\">".FQ_MSG5." <a href=\"{$this->_self}?cat={$crow['id']}\">",stripslashes($crow['title']),"</a></span><br>\n";
}
@mysql_free_result($cresult);
// get 'forward to' if needs be
if (($at < count($cats)-1) && ($at != -1))
{
$cresult = @mysql_query("SELECT id,title FROM {$this->tbl_cats} WHERE id={$cats[$at+1]['id']}",$this->id);
$crow = @mysql_fetch_array($cresult,MYSQL_ASSOC);
echo "<span class=\"navigation\">".FQ_MSG4." <a href=\"{$this->_self}?cat={$crow['id']}\">",stripslashes($crow['title']),"</a></span><br>\n";
}
@mysql_free_result($cresult);
echo "\n<hr width=\"100%\" size=\"2\" color=\"#000000\" noshade>\n\n";
// print out the questions
$qresult = @mysql_query("SELECT * FROM {$this->tbl_ques} WHERE cnum={$this->gpcVars['cat']}",$this->id)
or die("Unable to perform query: SELECT * FROM {$this->tbl_ques} WHERE cnum={$this->gpcVars['cat']}");
if (!@mysql_num_rows($qresult))
{
echo "<p class=\"answer\">".FQ_MSG9."</p>\n";
echo "<p class=\"small\">[ <a href=\"{$this->_self}\">".FQ_MSG3."</a> ]</p>\n";
}
else
{
$num = 1;
while ($qrow = @mysql_fetch_array($qresult,MYSQL_ASSOC))
{
echo "<p><a name=\"{$num}\" class=\"question\">{$num}. ",stripslashes($qrow['question']), "</a><p>\n";
if ($qrow['answer'] != "") echo "<p class=\"answer\">",stripslashes($qrow['answer']), "</p>\n";
else echo "<p class=\"answer\">No answer has been given to this question.</p>\n";
echo "<p class=\"small\">[ <a href=\"{$this->_self}\">".FQ_MSG3."</a> | <a href=\"{$this->_self}?cat={$this->gpcVars['cat']}\">".FQ_MSG6."</a> ]</p>\n";
if ($num++ < (@mysql_num_rows($qresult))) echo "<p><table width=\"100%\" border=\"0\" cellpadding=\"0\"><tr><td><hr width=\"100%\" size=\"1\" color=\"#AAAAAA\" noshade></td></tr></table></p>\n";
}
@mysql_free_result($qresult);
}
}
function searchQuestions()
{
$cresult = @mysql_query("SELECT * FROM {$this->tbl_cats} ORDER BY id",$this->id)
or die("Unable to perform query: SELECT * FROM {$this->tbl_cats} ORDER BY id");
if (!@mysql_num_rows($cresult))
{
echo "<p class=\"answer\">".FQ_MSG10."</p>\n";
return; // There are currently no categories in the FAQ.
}
else
{
// do the list
while ($crow = @mysql_fetch_array($cresult,MYSQL_ASSOC))
{
echo "<p class=\"category\">", stripslashes($crow['title']), "</p>\n";
// check existence in a general category
if (@mysql_num_rows(@mysql_query("SELECT * FROM {$this->tbl_ques} WHERE cnum={$crow['id']} AND (answer LIKE '%$gpcVars[search]%' OR question LIKE '%$gpcVars[search]%')",$this->id)))
{
// now get actual questions that match
$qresult = @mysql_query("SELECT * FROM {$this->tbl_ques} WHERE cnum={$crow['id']}",$this->id);
$num = 1;
$found = 0;
while ($qrow = @mysql_fetch_array($qresult,MYSQL_ASSOC))
{
if (eregi($this->gpcVars['search'],$qrow['answer']) || eregi($this->gpcVars['search'],$qrow['question']))
{
if (++$found==1) echo "<ol>\n";
echo " <li class=\"question\"> <a href=\"{$this->_self}?cat={$crow['id']}#{$num}\" class=\"question\">",stripslashes($qrow['question']),"</a></li><br>\n";
$found++;
}
$num++;
}
if ($found) echo "</ol>\n";
else echo "<p class=\"answer\">".FQ_MSG8."</p>\n";
}
else
{
echo "<p class=\"answer\">".FQ_MSG8."</p>\n";
}
@mysql_free_result($qresult);
}
}
@mysql_free_result($cresult);
echo "<p><a href=\"{$this->_self}\">".FQ_MSG7."</a></p>\n";
}
function showCategoryList()
{
$cresult = @mysql_query("SELECT * FROM {$this->tbl_cats} ORDER BY id",$this->id)
or die("Unable to perform query: SELECT * FROM {$this->tbl_cats} ORDER BY id");
if (!@mysql_num_rows($cresult))
{
echo "<p>".FQ_MSG10."</p>\n";
return;
}
else
{
// do the list
while ($crow = @mysql_fetch_array($cresult,MYSQL_ASSOC))
{
echo "<p class=\"category\">", stripslashes($crow['title']), "</p>\n";
unset($qresult);
unset($qrow);
$qresult = @mysql_query("SELECT * FROM {$this->tbl_ques} WHERE cnum={$crow['id']}",$this->id)
or die("Unable to perform query: SELECT * FROM {$this->tbl_ques} WHERE cnum={$crow['id']}");
if (!@mysql_num_rows($qresult))
{
echo "<dl><dd class=\"question\">".FQ_MSG9."</dd></dl><br>\n";
}
else
{
echo " <ol>\n";
$num = 1;
while ($qrow = @mysql_fetch_array($qresult,MYSQL_ASSOC))
{
echo " <li class=\"question\"> <a href=\"{$this->_self}?cat={$crow['id']}#",($num++),"\">", stripslashes($qrow['question']), "</a></li><br>\n";
}
echo " </ol>\n";
}
@mysql_free_result($qresult);
}
@mysql_free_result($cresult);
}
}
}
?>