create('faqs/list/all', false, 'full=1&noencode=1');
header('Location: '.$url);
exit;
}
else
{
e107::includeLan(e_PLUGIN."faqs/languages/".e_LANGUAGE."/".e_LANGUAGE."_front.php");
}
require_once (e_HANDLER."form_handler.php"); // TODO - Remove outdated code
require_once (e_HANDLER."userclass_class.php");
require_once (e_HANDLER."ren_help.php"); // TODO - Remove outdated code
require_once (e_HANDLER."comment_class.php");
/*
if (!vartrue($FAQ_VIEW_TEMPLATE))
{
if (file_exists(THEME."faqs_template.php"))
{
// require_once (THEME."faqs_template.php");
}
else
{
// require_once (e_PLUGIN."faqs/templates/faqs_template.php");
}
}
*/
e107::css('faqs','faqs.css');
// require_once(HEADERF);
// $pref['add_faq']=1;
$rs = new form; // TODO - Remove outdated code
$cobj = new comment;
$tp = e107::getParser();
$frm = e107::getForm();
if (!vartrue($_GET['elan']) && empty($_GET))
{
$qs = explode(".", e_QUERY);
$action = $qs[0];
$id = $qs[1];
$idx = $qs[2];
}
$from = (vartrue($from) ? $from : 0);
$amount = 50;
if (isset($_POST['faq_submit']))
{
$message = "-";
if ($_POST['faq_question'] != "" || $_POST['data'] != "")
{
$faq_question = $tp->toDB($_POST['faq_question']);
$data = $tp->toDB($_POST['data']);
$count = ($sql->count("faqs", "(*)", "WHERE faq_parent='".intval($_POST['faq_parent'])."' ") + 1);
$sql->insert("faqs", " 0, '".$_POST['faq_parent']."', '$faq_question', '$data', '".filter_var($_POST['faq_comment'], FILTER_SANITIZE_STRING)."', '".time()."', '".USERID."', '".$count."' ");
$message = FAQ_ADLAN_32;
unset($faq_question, $data);
}
else
{
$message = FAQ_ADLAN_30;
}
$id = $_POST['faq_parent'];
}
if (isset($_POST['faq_edit_submit']))
{
if ($_POST['faq_question'] != "" || $_POST['data'] != "")
{
$faq_question = $tp->toDB($_POST['faq_question']);
$data = $tp->toDB($_POST['data']);
$sql->update("faqs", "faq_parent='".intval($_POST['faq_parent'])."', faq_question ='$faq_question', faq_answer='$data', faq_comment='".$_POST['faq_comment']."' WHERE faq_id='".$idx."' ");
$message = FAQ_ADLAN_29;
unset($faq_question, $data);
}
else
{
$message = FAQ_ADLAN_30;
}
}
if (isset($_POST['commentsubmit']))
{
$pid = (IsSet($_POST['pid']) ? $_POST['pid'] : 0);
$cobj->enter_comment($_POST['author_name'], $_POST['comment'], "faq", $idx, $pid, $_POST['subject']);
}
// Actions +++++++++++++++++++++++++++++
$faq = new faq;
$faqpref = e107::getPlugConfig('faqs')->getPref();
if (empty($action) || $action == "main")
{
if(vartrue($faqpref['classic_look']))
{
$ftmp = $faq->show_existing_parents($action, $sub_action, $id, $from, $amount);
$caption = FAQLAN_41;
}
else
{
$srch = vartrue($_GET['srch']);
$ftmp = $faq->view_all($srch);
$caption = LAN_FAQS_011;
}
$pageTitle = '';
// define("e_PAGETITLE", $ftmp['caption']);
if (vartrue($faqpref['page_title']))
{
$pageTitle = $faqpref['page_title'][e_LANGUAGE];
}
else
{
$pageTitle = $ftmp['caption'];
}
if(!empty($ftmp['pagetitle']))
{
$pageTitle .= ": ".$ftmp['pagetitle'];
}
e107::getMessage()->addDebug("TITLE: " . $pageTitle);
e107::meta('og:title', $pageTitle);
if(!empty($ftmp['pagedescription']))
{
e107::meta('og:description', $ftmp['pagedescription']);
}
define('e_PAGETITLE', $pageTitle);
require_once (HEADERF);
e107::getRender()->tablerender($ftmp['caption'], $ftmp['text']);
}
if($action == "cat" && $idx)
{
$ftmp = $faq->view_faq($idx) ;
if(!defined("e_PAGETITLE"))
{
e107::title( LAN_FAQS_011." - ". $ftmp['title']);
}
require_once(HEADERF);
e107::getRender()->tablerender($ftmp['caption'], $ftmp['text']);
}
if ($action == "cat")
{
$ftmp = $faq->view_cat_list($action, $id);
e107::title( strip_tags($ftmp['title'].$ftmp['caption']));
require_once (HEADERF);
e107::getRender()->tablerender($ftmp['caption'], $ftmp['text']);
}
if((check_class($faqpref['add_faq']) || ADMIN) && ($action == "new" || $action == "edit"))
{
require_once (HEADERF);
$faq->add_faq($action, $id, $idx);
}
require_once (FOOTERF);
exit;
// ====== +++++++++++++++++++++++++++++
class faq
{
var $pref = array();
protected $sc = null;
protected $template = null;
protected $pageTitle = null;
protected $pageDescription = null;
function __construct()
{
$sc = e107::getScBatch('faqs', true);
$this->pref = e107::pref('faqs'); // Short version of e107::getPlugConfig('faqs')->getPref(); ;
$sc->pref = $this->pref;
if(!empty($_POST['submit_a_question']))
{
$sql = e107::getDb();
$existing = $sql->select('faqs','faq_id',"faq_answer='' AND faq_author_ip = '".USERIP."' ");
if(!empty($this->pref['submit_question_limit']) && $existing >= $this->pref['submit_question_limit'])
{
e107::getMessage()->setTitle(LAN_WARNING,E_MESSAGE_INFO)->addInfo(LAN_FAQS_005);
return;
}
$question = filter_input(INPUT_POST, 'ask_a_question', FILTER_SANITIZE_STRING);
$insert = array(
'faq_id' => 0,
'faq_parent' => 0, // meaning 'unassigned/unanswered'.
'faq_question' => $question,
'faq_answer' => '',
'faq_comment' => 0,
'faq_datestamp' => time(),
'faq_author' => USERID,
'faq_author_ip' => USERIP,
'faq_tags' => '',
'faq_order' => 99999
);
if($sql->insert('faqs', $insert))
{
$message = !empty($this->pref['submit_question_acknowledgement']) ? e107::getParser()->toHTML($this->pref['submit_question_acknowledgement'],true, 'BODY') : LAN_FAQS_004;
e107::getMessage()->addSuccess($message);
}
}
}
function view_all($srch) // new funtion to render all FAQs
{
$tp = e107::getParser();
$ret = array();
$template = e107::getTemplate('faqs');
$this->template = $template;
$this->sc = e107::getScBatch('faqs',TRUE);
$text = $tp->parseTemplate($template['start'], true, $this->sc); // header
// var_dump($sc);
$text .= "
";
$text .= $this->view_all_query($srch);
$text .= "
";
$text .= $tp->parseTemplate($template['end'], true, $this->sc); // footer
$ret['title'] = LAN_FAQS_011;
$ret['text'] = $text;
if (!empty($this->pref['page_title'][e_LANGUAGE]))
{
$ret['caption'] = e107::getParser()->toHTML($this->pref['page_title'][e_LANGUAGE], true, 'TITLE');
}
else
{
$ret['caption'] = varset($template['caption']) ? $tp->parseTemplate($template['caption'], true, $this->sc) : LAN_PLUGIN_FAQS_FRONT_NAME;
}
if(!empty($this->pageTitle))
{
$ret['pagetitle'] = e107::getParser()->toText($this->pageTitle);
}
if(!empty($this->pageDescription))
{
$ret['pagedescription'] = e107::getParser()->toText($this->pageDescription,true,'RAWTEXT');
}
return $ret;
}
function view_all_query($srch='')
{
$sql = e107::getDb();
$tp = e107::getParser();
$text = "";
$insert = "";
$item = false;
$removeUrl = e107::url('faqs','index');
if(!empty($srch))
{
$srch = $tp->toDB($srch);
$insert = " AND (f.faq_question LIKE '%".$srch."%' OR f.faq_answer LIKE '%".$srch."%' OR FIND_IN_SET ('".$srch."', f.faq_tags) ) ";
// $message = "".$srch." ×";
// e107::getMessage()->setClose(false,E_MESSAGE_INFO)->setTitle(LAN_FAQS_002,E_MESSAGE_INFO)->addInfo($message);
// $text = e107::getMessage()->render();
}
if(!empty($_GET['id'])) // pull out just one specific FAQ.
{
$srch = intval($_GET['id']);
// $insert = " AND (f.faq_id = ".$srch.") ";
$item = $srch;
}
if(!empty($_GET['cat']))
{
$srch = $tp->toDB($_GET['cat']);
$insert = " AND (cat.faq_info_sef = '".$srch."') ";
}
if(!empty($_GET['tag']))
{
$srch = $tp->toDB($_GET['tag']);
$insert = " AND FIND_IN_SET ('".$srch."', f.faq_tags) ";
$message = "".$srch." ×";
e107::getMessage()->setClose(false,E_MESSAGE_INFO)->setTitle(LAN_FAQS_002,E_MESSAGE_INFO)->addInfo($message);
$text = e107::getMessage()->render();
}
list($orderBy, $ascdesc) = explode('-', vartrue($this->pref['orderby'],'faq_order-ASC'));
$query = "SELECT f.*,cat.* FROM #faqs AS f LEFT JOIN #faqs_info AS cat ON f.faq_parent = cat.faq_info_id WHERE cat.faq_info_class IN (".USERCLASS_LIST.") ".$insert." ORDER BY cat.faq_info_order, f.".$orderBy." ".$ascdesc." ";
if(!$data = $sql->retrieve($query, true))
{
$message = (!empty($srch)) ? e107::getParser()->lanVars(LAN_FAQS_008, $srch)."".LAN_FAQS_007."" : LAN_FAQS_003;
return "".$message."
" ;
}
// -----------------
$FAQ_LISTALL = e107::getTemplate('faqs', true, 'all');
$prevcat = "";
$sc = e107::getScBatch('faqs', true);
$sc->counter = 1;
$sc->tag = htmlspecialchars(varset($tag), ENT_QUOTES, 'utf-8');
$sc->category = varset($category);
if(!empty($_GET['id'])) // expand one specific FAQ.
{
$sc->item =intval($_GET['id']);
$js = "
$( document ).ready(function() {
$('html, body').animate({ scrollTop: $('div#faq_".$sc->item."').offset().top - 300 }, 4000);
});
";
e107::js('footer-inline', $js);
}
// $text = $tp->parseTemplate($FAQ_START, true, $sc);
// $text = "";
if($this->pref['list_type'] == 'ol')
{
$reversed = ($ascdesc == 'DESC') ? 'reversed ' : '';
$tsrch = array('";
if(varset($faq))
{
$sql->select("faqs_info", "*", "faq_info_id='$faq'");
$row = $sql->fetch();
extract($row); // get rid of this
}
$ns->tablerender(LAN_PLUGIN_FAQS_FRONT_NAME.$faq_info_title, "".$text."
".$this->faq_footer());
}
}