* @package AgileBill
* @version 1.4.93
*/
class faq
{
# Open the constructor for this mod
function faq()
{
# name of this module:
$this->module = "faq";
$this->version = "1.0.0a";
if(!defined('AJAX'))
{
# location of the construct XML file:
$this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
# open the construct file for parsing
$C_xml = new CORE_xml;
$construct = $C_xml->xml_to_array($this->xml_construct);
$this->method = $construct["construct"]["method"];
$this->trigger = $construct["construct"]["trigger"];
$this->field = $construct["construct"]["field"];
$this->table = $construct["construct"]["table"];
$this->module = $construct["construct"]["module"];
$this->cache = $construct["construct"]["cache"];
$this->order_by = $construct["construct"]["order_by"];
$this->limit = $construct["construct"]["limit"];
}
}
### autofill for admin 'canned messages' in ticket reply
function autofill($VAR)
{
$db = &DB();
if(!empty($VAR['faq_autofill']) && strlen($VAR['faq_autofill']) > 3) {
$dbm = new CORE_database();
$result = $db->Execute(
$sql = $dbm->sql_select(
Array( 'faq_translate', 'faq' ),
Array( 'A.*', 'B.name' ),
" A.faq_id = B.id AND MATCH(A.question, A.answer) AGAINST(".$db->qstr($VAR['faq_autofill'].'*')." IN BOOLEAN MODE)",
"",
&$db
)
);
}
echo '
';
# Create the alert for no records found
if (@$result != false && $result->RecordCount() > 0) {
$i=0;
while(!$result->EOF && $i < 10) {
echo '' . stripcslashes( substr( ereg_replace("\r\n", " ", $result->fields['question']), 0, 65 ) ). '
'.
'' . stripcslashes( substr( ereg_replace("\r\n", " ", $result->fields['answer']),0, 75 ) ) . '
'.
''. stripcslashes( $result->fields['answer'].'
'). "\r\n";
$result->MoveNext();
$i++;
}
} else {
include_once(PATH_CORE.'translate.inc.php');
include_once(PATH_CORE.'xml.inc.php');
$C_translate = new CORE_translate;
echo ''. $C_translate->translate('admin_no_match','faq') .'
' .
''. $C_translate->translate('admin_no_match_help','faq') .'
'.
'null
' . "\r\n";
}
echo "
";
}
### Get the faq details:
function faq_show($VAR)
{
if (!empty($VAR['id'])) {
$db = &DB();
$dbm = new CORE_database();
$rs = $db->Execute(
$sql = $dbm->sql_select(
Array( 'faq_translate', 'faq', 'faq_category' ),
Array( 'A.*', 'B.name', 'C.group_avail' ),
" B.id = ::".$VAR['id'].":: AND B.id = A.faq_id AND A.language_id = '".SESS_LANGUAGE."' AND B.status = 1 AND C.status = 1 ",
"",
&$db
)
);
}
global $C_auth;
if( !$rs || $rs->RecordCount() == 0 || !$C_auth->auth_group_by_id( unserialize( $rs->fields['group_avail'] ))) {
include_once(PATH_CORE.'translate.inc.php');
include_once(PATH_CORE.'xml.inc.php');
$C_translate = new CORE_translate;
echo $C_translate->translate('no_faqs','faq');
} else {
echo '' . ereg_replace("\r\n", "
", stripcslashes( htmlentities( $rs->fields['question']) ) ). '
' .
'' . ereg_replace("\r\n", "
", $this->linkalize(stripcslashes( htmlentities( $rs->fields['answer']) ) ) ). '
';
}
}
### Get the faq translation:
function faq_search($VAR)
{
$db = &DB();
if(!empty($VAR['search']) && strlen($VAR['search']) > 3) {
$dbm = new CORE_database();
$result = $db->Execute(
$sql = $dbm->sql_select(
Array( 'faq_translate', 'faq', 'faq_category' ),
Array( 'A.*', 'B.name', 'C.group_avail' ),
" A.faq_id = B.id AND B.faq_category_id = C.id AND MATCH(A.question, A.answer) AGAINST(".$db->qstr($VAR['search'].'*')." IN BOOLEAN MODE) AND B.status = 1 AND C.status=1",
"",
&$db
)
);
} elseif (!empty($VAR['category_id'])) {
$dbm = new CORE_database();
$result = $db->Execute(
$sql = $dbm->sql_select(
Array( 'faq_translate', 'faq', 'faq_category' ),
Array( 'A.*', 'B.name', 'C.group_avail' ),
" B.faq_category_id = ::".$VAR['category_id'].":: AND B.id = A.faq_id AND B.faq_category_id = C.id AND A.language_id = '".SESS_LANGUAGE."' AND B.status = 1 AND C.status=1",
"",
&$db
)
);
}
echo '";
}
### Get the authorized/active categories
function faq_categories($VAR)
{
$db = &DB();
$dbm = new CORE_database();
$rs = $db->Execute( $sql=
$sql = $dbm->sql_select(
'faq_category',
'*' ,
" status=1 ",
"sort_order,name,date_orig",
&$db
)
);
if(!$rs || $rs->RecordCount() == 0) {
//
} else {
while(!$rs->EOF) {
// validate groups
global $C_auth;
if( $C_auth->auth_group_by_id( unserialize($rs->fields['group_avail']) )) {
$smart[] = $rs->fields;
}
$rs->MoveNext();
}
}
global $smarty;
$smarty->assign('faq_category_list', @$smart);
}
##############################
## ADD ##
##############################
function add($VAR)
{
$type = "add";
$this->method["$type"] = split(",", $this->method["$type"]);
$db = new CORE_database;
$id = $db->add($VAR, $this, $type);
if($id && !empty($VAR['faq_question']))
{
# Insert translation
$db = &DB();
$idx = $db->GenID(AGILE_DB_PREFIX. 'faq_translate_id');
$sql = "INSERT INTO ".AGILE_DB_PREFIX."faq_translate
SET
site_id = ".DEFAULT_SITE.",
id = $idx,
faq_id = $id,
date_orig = ".time().",
date_last = ".time().",
language_id = '".DEFAULT_LANGUAGE."',
answer = ".$db->qstr( @$VAR['faq_answer'] ).",
question = ".$db->qstr( @$VAR['faq_question']);
$db->Execute($sql);
}
}
##############################
## VIEW ##
##############################
function view($VAR)
{
$type = "view";
$this->method["$type"] = split(",", $this->method["$type"]);
$db = new CORE_database;
$db->view($VAR, $this, $type);
}
##############################
## UPDATE ##
##############################
function update($VAR)
{
$type = "update";
$this->method["$type"] = split(",", $this->method["$type"]);
$db = new CORE_database;
$db->update($VAR, $this, $type);
}
##############################
## DELETE ##
##############################
function delete($VAR)
{
$this->associated_DELETE[] =
Array(
'table' => 'faq_translate',
'field' => 'faq_id'
);
$db = new CORE_database;
$db->mass_delete($VAR, $this, "");
}
##############################
## SEARCH FORM ##
##############################
function search_form($VAR)
{
$type = "search";
$this->method["$type"] = split(",", $this->method["$type"]);
$db = new CORE_database;
$db->search_form($VAR, $this, $type);
}
##############################
## SEARCH ##
##############################
function search($VAR)
{
$type = "search";
$this->method["$type"] = split(",", $this->method["$type"]);
$db = new CORE_database;
$db->search($VAR, $this, $type);
}
##############################
## SEARCH SHOW ##
##############################
function search_show($VAR)
{
$type = "search";
$this->method["$type"] = split(",", $this->method["$type"]);
$db = new CORE_database;
$db->search_show($VAR, $this, $type);
}
function linkalize($text)
{
$text = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i", "$1http://$2", $text);
$text = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i", "$1", $text); //make all URLs links
$text = preg_replace("/[\w-\.]+@(\w+[\w-]+\.){0,3}\w+[\w-]+\.[a-zA-Z]{2,4}\b/i","$0",$text);
return $text;
}
}
?>