<?php
/*
*****************************************************************
Mod_FaqManagement.php
*****************************************************************
LSP: Lunabyte Systems Portal
Open-Source Project Inspired by Zef Hemel (hide@address.com)
*****************************************************************
Software Version: LSP 2.0 "Enigma 2"
Software by: Lunabyte Systems (http://www.lunabyte.net)
Copyright 2002-2005 by: Lunabyte Systems (http://www.lunabyte.net)
Support, News, Updates at: http://www.lunabyte.net
*****************************************************************
This program is free software; you may redistribute it and/or modify it
under the terms of the provided license as published by Lunabyte Systems.
This program is distributed in the hope that it is and will be useful,
but WITHOUT ANY WARRANTIES; without even any implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the "LSP_license.txt" file for details of the LSP license.
The latest version can always be found at http://www.lunabyte.net.
*****************************************************************
*/
if (!defined('ENIGMA'))
die('<b>Access Violation</b><br />Direct Access to this location is not allowed.');
else
AdminFAQHub();
function AdminFAQHub()
{
global $context, $txt, $user_info;
isAllowedTo('manage_faqs');
// Load the common admin stuff... select 'Faq_Management'.
if ($user_info['is_admin'])
adminIndex('Faq_Management');
loadMLanguage('Faq');
loadMTemplate('FaqManagement');
if (!isset($context['page_title']))
$context['page_title'] = &$txt['faq00'];
$sa = !empty($_REQUEST['sa']) ? $_REQUEST['sa'] : NULL;
$subActions = array(
'faqcatadd',
'faqcatdel',
'faqcatedit',
'faqcatsave',
'faqcatgo',
'faqcatgoadd',
'faqcatgoedit',
'faqcatgosave',
'faqcatgodel',
);
if (in_array($sa, $subActions))
$sa();
elseif (isset($subActions[$sa]))
$subActions[$sa]();
else
AdminFAQ();
unset($subActions);
}
function AdminFAQ()
{
global $context, $db_prefix, $scripturl, $txt;
$context['faqcats'] = array();
$request = db_query("
SELECT c.id_cat, c.categories, count(a.id_cat) AS answers
FROM ({$db_prefix}faqcategories AS c)
LEFT JOIN {$db_prefix}faqanswer AS a ON (c.id_cat = a.id_cat)
GROUP BY c.id_cat", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
$context['faqcats'][] = array(
'categories' => $row['categories'],
'id_cat' => $row['id_cat'],
'answers' => $row['answers'],
'rowcat' => urlencode($row['categories']),
);
$context['sub_template'] = 'Faq_Admin';
}
function faqcatadd()
{
global $db_prefix;
$categories = $_REQUEST['categories'];
db_query("
INSERT INTO {$db_prefix}faqcategories
VALUES (NULL, '$categories')", __FILE__, __LINE__);
redirectexit('module=FaqManagement');
}
function faqcatdel()
{
global $context, $db_prefix, $txt;
$id_cat = $_REQUEST['id_cat'];
if($_GET['ok'] == '1')
{
db_query("
DELETE FROM {$db_prefix}faqcategories
WHERE id_cat = '$id_cat'
LIMIT 1", __FILE__, __LINE__);
db_query("
DELETE FROM {$db_prefix}faqanswer
WHERE id_cat = '$id_cat'", __FILE__, __LINE__);
redirectexit('module=FaqManagement');
}
$context['id_cat'] = $id_cat;
$context['sub_template'] = 'Faq_Delete';
}
function faqcatgo()
{
global $context, $db_prefix, $txt;
$context['id_cat'] = $_REQUEST['id_cat'];
$context['faqcatsasw'] = array();
$result = db_query("
SELECT *
FROM {$db_prefix}faqanswer
WHERE id_cat='$context[id_cat]'
order by id", __FILE__, __LINE__);
while($row = mysql_fetch_array($result))
{
$context['faqcatsasw'][] = array(
'question' => $row['question'],
'answer' => $row['answer'],
'id' => $row['id'],
);
}
$context['sub_template'] = 'Faq_CatGo';
}
function faqcatgoadd()
{
global $db_prefix, $boardurl;
$id_cat = $_REQUEST['id_cat'];
$question = $_REQUEST['question'];
$answer = $_REQUEST['answer'];
db_query("
INSERT INTO {$db_prefix}faqanswer
VALUES (NULL, '$id_cat', '$question', '$answer')", __FILE__, __LINE__);
redirectexit('module=FaqManagement;sa=faqcatgo;id_cat=' . $id_cat);
}
function faqcatedit()
{
global $context, $db_prefix, $txt;
$context['id_cat'] = $_REQUEST['id_cat'];
$result = db_query("
SELECT categories
FROM {$db_prefix}faqcategories
WHERE id_cat = '$context[id_cat]'", __FILE__, __LINE__);
list($context['categories']) = mysql_fetch_row($result);
$context['sub_template'] = 'Faq_CatEdit';
}
function faqcatsave()
{
global $db_prefix;
$id_cat = $_REQUEST['id_cat'];
$categories = $_REQUEST['categories'];
db_query("
UPDATE {$db_prefix}faqcategories
SET categories='$categories'
WHERE id_cat='$id_cat'
LIMIT 1", __FILE__, __LINE__);
redirectexit('module=FaqManagement');
}
function faqcatgoedit()
{
global $context, $db_prefix, $txt, $scripturl;
$context['id'] = $_REQUEST['id'];
$result = db_query("
SELECT *
FROM {$db_prefix}faqanswer
WHERE id = '$context[id]'
LIMIT 1", __FILE__, __LINE__);
$context['asw_edit'] = mysql_fetch_assoc($result);
$context['sub_template'] = 'Faq_CatGoEdit';
}
function faqcatgosave()
{
global $db_prefix;
$id = $_REQUEST['id'];
$id_cat = $_REQUEST['id_cat'];
$question = $_REQUEST['question'];
$answer = $_REQUEST['answer'];
db_query("
UPDATE {$db_prefix}faqanswer
SET question='$question', answer='$answer'
WHERE id='$id'
LIMIT 1", __FILE__, __LINE__);
redirectexit('module=FaqManagement;sa=faqcatgo;id_cat=' . $id_cat);
}
function faqcatgodel()
{
global $context, $db_prefix, $txt;
$context['id'] = (int) $_REQUEST['id'];
$context['id_cat'] = (int) $_REQUEST['id_cat'];
if ($_REQUEST['ok'] == '1')
{
db_query("
DELETE FROM {$db_prefix}faqanswer
WHERE id = '$context[id]'
LIMIT 1", __FILE__, __LINE__);
redirectexit('module=FaqManagement;sa=faqcatgo;id_cat=' . $context['id_cat']);
}
$context['sub_template'] = 'Faq_Delete_asw';
}
?>