This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/faq/faq.inc.php

231 lines
7.0 KiB
PHP
Raw Normal View History

<?php
/**
* AgileBill - Open Billing Software
*
* This body of work is free software; you can redistribute it and/or
* modify it under the terms of the Open AgileBill License
* License as published at http://www.agileco.com/agilebill/license1-4.txt
2009-08-03 04:10:16 +00:00
*
* Originally authored by Tony Landis, AgileBill LLC
*
* Recent modifications by Deon George
*
* @author Deon George <deonATleenooksDOTnet>
* @copyright 2009 Deon George
* @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
2009-08-03 04:10:16 +00:00
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
2009-08-03 04:10:16 +00:00
* @subpackage Module:FAQ
*/
2009-08-03 04:10:16 +00:00
/**
* The main AgileBill FAQ Class
*
* @package AgileBill
* @subpackage Module:FAQ
*/
class faq extends OSB_module {
### autofill for admin 'canned messages' in ticket reply
function autofill($VAR)
{
$db = &DB();
if(!empty($VAR['faq_autofill']) && strlen($VAR['faq_autofill']) > 3) {
$result = $db->Execute(
$sql = sqlSelect(
$db,
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)",
""
)
);
}
echo '<ul>';
# Create the alert for no records found
if (@$result != false && $result->RecordCount() > 0) {
$i=0;
while(!$result->EOF && $i < 10) {
echo '<li><div class="name"><b>' . stripcslashes( substr( ereg_replace("\r\n", " ", $result->fields['question']), 0, 65 ) ). '</b></div>'.
'<div class="email"><span class="informal">' . stripcslashes( substr( ereg_replace("\r\n", " ", $result->fields['answer']),0, 75 ) ) . '</span></div>'.
'<div class="index" style="display:none">'. stripcslashes( $result->fields['answer'].'</div></li>'). "\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 '<li><div class="name"><b>'. $C_translate->translate('admin_no_match','faq') .'</b></div>' .
'<div class="email"><span class="informal">'. $C_translate->translate('admin_no_match_help','faq') .'</span></div>'.
'<div class="index" style="display:none">null</div></li>' . "\r\n";
}
echo "</ul>";
}
### Get the faq details:
function faq_show($VAR)
{
if (!empty($VAR['id'])) {
$db = &DB();
$rs = $db->Execute(
$sql = sqlSelect(
$db,
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 ",
""
)
);
}
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 '<p><u>' . ereg_replace("\r\n", "<BR>", stripcslashes( htmlentities( $rs->fields['question']) ) ). '</u></p>' .
'<p>' . ereg_replace("\r\n", "<BR>", $this->linkalize(stripcslashes( htmlentities( $rs->fields['answer']) ) ) ). '</p>';
}
}
### Get the faq translation:
function faq_search($VAR)
{
$db = &DB();
if(!empty($VAR['search']) && strlen($VAR['search']) > 3) {
$result = $db->Execute(
$sql = sqlSelect(
$db,
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",
""
)
);
} elseif (!empty($VAR['category_id'])) {
$result = $db->Execute(
$sql = sqlSelect(
$db,
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",
""
)
);
}
echo '<ul>';
if (@$result != false && $result->RecordCount() > 0) {
$i=0;
while(!$result->EOF) {
global $C_auth;
if( $C_auth->auth_group_by_id( unserialize($result->fields['group_avail'] ))) {
echo '<li><div><a href="?_page=faq:faq&id='.$result->fields['faq_id'].'">' . stripcslashes( htmlentities( ereg_replace("\r\n", " ", $result->fields['question']) ) ). '</a></div> </li>'. "\r\n";
$i++;
}
$result->MoveNext();
}
} else {
include_once(PATH_CORE.'translate.inc.php');
include_once(PATH_CORE.'xml.inc.php');
$C_translate = new CORE_translate;
echo '<li><div class="name"><b>'. $C_translate->translate('admin_no_match','faq') .'</b></div> </div></li>' . "\r\n";
}
echo "</ul>";
}
### Get the authorized/active categories
function faq_categories($VAR)
{
$db = &DB();
$rs = $db->Execute( $sql=
$sql = sqlSelect(
$db,
'faq_category',
'*' ,
" status=1 ",
"sort_order,name,date_orig"
)
);
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);
}
2009-08-03 04:10:16 +00:00
/**
* Add a entry to the database
*/
public function add($VAR) {
global $VAR;
2009-08-03 04:10:16 +00:00
if (empty($VAR['faq_translate_question']))
return false;
2009-08-03 04:10:16 +00:00
$q = $VAR['faq_translate_question'];
unset($VAR['faq_translate_question']);
2009-08-03 04:10:16 +00:00
$a = '';
if (isset($VAR['faq_translate_answer'])) {
$a = $VAR['faq_translate_answer'];
unset($VAR['faq_translate_answer']);
}
2009-08-03 04:10:16 +00:00
$id = parent::add($VAR);
2009-08-03 04:10:16 +00:00
# Insert translation
if ($id) {
$db = &DB();
2009-08-03 04:10:16 +00:00
$db->Execute(sqlInsert($db,'faq_translate',array('faq_id'=>$id,'date_orig'=>time(),'date_last'=>time(),'language_id'=>DEFAULT_LANGUAGE,'question'=>$q,'answer'=>$a)));
}
}
##############################
## DELETE ##
##############################
function delete($VAR)
{
$this->associated_DELETE[] =
Array(
'table' => 'faq_translate',
'field' => 'faq_id'
);
$db = new CORE_database;
$db->mass_delete($VAR, $this, "");
}
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", "<A TARGET=\"_blank\" HREF=\"$1\">$1</A>", $text); //make all URLs links
$text = preg_replace("/[\w-\.]+@(\w+[\w-]+\.){0,3}\w+[\w-]+\.[a-zA-Z]{2,4}\b/i","<ahref=\"mailto:$0\">$0</a>",$text);
return $text;
}
}
?>