You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
267 lines
8.3 KiB
267 lines
8.3 KiB
<?php |
|
|
|
/** |
|
* Класс работы с модулем Вопрос-Ответ |
|
* |
|
* @package AVE.cms |
|
* @subpackage module_FAQ |
|
* @filesource |
|
*/ |
|
|
|
class Faq |
|
{ |
|
/** |
|
* Вывод списка рубрик |
|
* |
|
* @param string $tpl_dir путь к директории с шаблонами модуля |
|
*/ |
|
public static function faqList($tpl_dir) |
|
{ |
|
global $AVE_DB, $AVE_Template; |
|
|
|
$faq = array(); |
|
$sql = $AVE_DB->Query("SELECT * FROM ". PREFIX ."_module_faq"); |
|
while ($row = $sql->FetchRow()) array_push($faq, $row); |
|
|
|
$AVE_Template->assign("faq_arr", $faq); |
|
$AVE_Template->assign("content", $AVE_Template->fetch($tpl_dir . "admin_faq_list.tpl")); |
|
} |
|
|
|
/** |
|
* Создание новой рубрики |
|
* |
|
*/ |
|
public static function faqNew() |
|
{ |
|
global $AVE_DB; |
|
|
|
if (isset($_POST['new_faq_title']) && trim($_POST['new_faq_title'])) |
|
{ |
|
$AVE_DB->Query("INSERT INTO " . PREFIX . "_module_faq SET id = '', faq_title = '" . mb_substr($_POST['new_faq_title'], 0, 100) . "', faq_description = '" . mb_substr($_POST['new_faq_desc'], 0, 255) . "'"); |
|
} |
|
|
|
header("Location:index.php?do=modules&action=modedit&mod=faq&moduleaction=1&cp=" . SESSION); |
|
exit; |
|
} |
|
|
|
/** |
|
* Удаление рубрики вместе с вопросами и ответами |
|
* |
|
* @param string $tpl_dir путь к директории с шаблонами модуля |
|
*/ |
|
public static function faqDelete($tpl_dir) |
|
{ |
|
global $AVE_DB, $AVE_Template; |
|
|
|
if (isset($_GET['fid']) && is_numeric($_GET['fid']) && $_GET['fid'] > 0) |
|
{ |
|
$AVE_DB->Query("DELETE FROM " . PREFIX . "_module_faq WHERE id = '" . $_GET['fid'] . "'"); |
|
$AVE_DB->Query("DELETE FROM " . PREFIX . "_module_faq_quest WHERE faq_id = '" . $_GET['fid'] . "'"); |
|
|
|
$AVE_Template->clear_cache($tpl_dir . 'show_faq.tpl', $_GET['fid']); |
|
} |
|
|
|
header("Location:index.php?do=modules&action=modedit&mod=faq&moduleaction=1&cp=" . SESSION); |
|
exit; |
|
} |
|
|
|
/** |
|
* Запись изменений в наименованиях и описаниях рубрик |
|
* |
|
* @param string $tpl_dir путь к директории с шаблонами модуля |
|
*/ |
|
public static function faqListSave($tpl_dir) |
|
{ |
|
global $AVE_DB, $AVE_Template; |
|
|
|
foreach($_POST['faq_title'] as $id => $faq_title) |
|
{ |
|
if (is_numeric($id) && $id > 0 && trim($faq_title)) |
|
{ |
|
$AVE_DB->Query("UPDATE " . PREFIX . "_module_faq SET faq_title = '" . mb_substr($faq_title, 0, 100) . "', faq_description = '" . mb_substr($_POST['faq_description'][$id], 0, 255) . "' WHERE id = '" . $id . "'"); |
|
|
|
$AVE_Template->clear_cache($tpl_dir . 'show_faq.tpl', $id); |
|
} |
|
} |
|
|
|
header("Location:index.php?do=modules&action=modedit&mod=faq&moduleaction=1&cp=" . SESSION); |
|
exit; |
|
} |
|
|
|
/** |
|
* Вывод списка вопросов и ответов определённой рубрики |
|
* |
|
* @param string $tpl_dir путь к директории с шаблонами модуля |
|
*/ |
|
public static function faqQuestionList($tpl_dir) |
|
{ |
|
global $AVE_DB, $AVE_Template; |
|
|
|
if (!(isset($_GET['fid']) && is_numeric($_GET['fid']) && $_GET['fid'] > 0)) |
|
{ |
|
header("Location:index.php?do=modules&action=modedit&mod=faq&moduleaction=1&cp=" . SESSION); |
|
exit; |
|
} |
|
|
|
$questions = array(); |
|
$sql = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_module_faq_quest WHERE faq_id = '" . $_GET['fid'] . "'"); |
|
while ($row = $sql->FetchRow()) array_push($questions, $row); |
|
|
|
$r_name = $AVE_DB->Query("SELECT * FROM ". PREFIX ."_module_faq WHERE id = '" . $_GET['fid'] . "'")->FetchRow(); |
|
|
|
$AVE_Template->assign("questions", $questions); |
|
$AVE_Template->assign("RubricName", $r_name->faq_title); |
|
$AVE_Template->assign("content", $AVE_Template->fetch($tpl_dir . "admin_faq_edit.tpl")); |
|
} |
|
|
|
/** |
|
* Вывод формы редактирования вопроса и ответа на него |
|
* |
|
* @param string $tpl_dir путь к директории с шаблонами модуля |
|
*/ |
|
public static function faqQuestionEdit($tpl_dir) |
|
{ |
|
global $AVE_DB, $AVE_Template; |
|
|
|
if (! (isset($_GET['fid']) && is_numeric($_GET['fid']) && $_GET['fid'] > 0)) |
|
{ |
|
header("Location:index.php?do=modules&action=modedit&mod=faq&moduleaction=1&cp=" . SESSION); |
|
exit; |
|
} |
|
|
|
if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0) |
|
{ |
|
$faq = $AVE_DB->Query(" |
|
SELECT * |
|
FROM |
|
" . PREFIX . "_module_faq_quest |
|
WHERE |
|
faq_id = '" . (int)$_GET['fid'] . "' |
|
AND |
|
id = '" . (int)$_GET['id'] . "' |
|
")->FetchAssocArray(); |
|
|
|
if ($faq === false) |
|
{ |
|
header("Location:index.php?do=modules&action=modedit&mod=faq&moduleaction=1&cp=" . SESSION); |
|
exit; |
|
} |
|
} |
|
else |
|
{ |
|
$faq = array( |
|
'id' => '', |
|
'faq_quest' => '', |
|
'faq_answer' => '', |
|
'faq_id' => $_GET['fid'] |
|
); |
|
} |
|
|
|
switch ($_SESSION['use_editor']) |
|
{ |
|
case '0': // CKEditor |
|
$oCKeditor = new CKeditor(); |
|
$oCKeditor->returnOutput = true; |
|
$oCKeditor->config['toolbar'] = 'Verysmall'; |
|
$oCKeditor->config['height'] = 100; |
|
$config = array(); |
|
$faq['faq_quest'] = $oCKeditor->editor('faq_quest', $faq['faq_quest'], $config); |
|
|
|
$oCKeditor2 = new CKeditor(); |
|
$oCKeditor2->returnOutput = true; |
|
$oCKeditor2->config['toolbar'] = 'Small'; |
|
$oCKeditor2->config['height'] = 400; |
|
$config2 = array(); |
|
$faq['faq_answer'] = $oCKeditor2->editor('faq_answer', $faq['faq_answer'], $config2); |
|
break; |
|
|
|
case '1': |
|
// Elrte и Elfinder |
|
break; |
|
} |
|
|
|
|
|
$AVE_Template->assign($faq); |
|
|
|
$AVE_Template->assign("content", $AVE_Template->fetch($tpl_dir . "admin_quest_edit.tpl")); |
|
} |
|
|
|
/** |
|
* Запись нового или изменённого вопроса и ответа на него |
|
* |
|
* @param string $tpl_dir путь к директории с шаблонами модуля |
|
*/ |
|
public static function faqQuestionSave($tpl_dir) |
|
{ |
|
global $AVE_DB, $AVE_Template; |
|
|
|
if (!(isset($_POST['fid']) && is_numeric($_POST['fid']) && $_POST['fid'] > 0)) |
|
{ |
|
header("Location:index.php?do=modules&action=modedit&mod=faq&moduleaction=1&cp=" . SESSION); |
|
exit; |
|
} |
|
|
|
if (isset($_POST['id']) && is_numeric($_POST['id']) && $_POST['id'] > 0) |
|
{ |
|
$AVE_DB->Query("UPDATE " . PREFIX . "_module_faq_quest SET faq_quest = '" . $_POST['faq_quest'] . "', faq_answer = '" . $_POST['faq_answer'] . "' WHERE id = '" . $_POST['id'] . "'"); |
|
} |
|
else |
|
{ |
|
if ($AVE_DB->Query("SELECT 1 FROM " . PREFIX . "_module_faq WHERE id = '" . $_POST['fid'] . "'")->GetCell()) |
|
{ |
|
$AVE_DB->Query("INSERT INTO " . PREFIX . "_module_faq_quest SET id = '', faq_id = '" . $_POST['fid'] . "', faq_quest = '" . $_POST['faq_quest'] . "', faq_answer = '" . $_POST['faq_answer'] . "'"); |
|
} |
|
} |
|
|
|
$AVE_Template->clear_cache($tpl_dir . 'show_faq.tpl', $_POST['fid']); |
|
|
|
header("Location:index.php?do=modules&action=modedit&mod=faq&moduleaction=questlist&fid=" . $_POST['fid'] . "&cp=" . SESSION); |
|
exit; |
|
} |
|
|
|
/** |
|
* Удаление вопроса и ответа на него |
|
* |
|
* @param string $tpl_dir путь к директории с шаблонами модуля |
|
*/ |
|
public static function faqQuestionDelete($tpl_dir) |
|
{ |
|
global $AVE_DB, $AVE_Template; |
|
|
|
if (!(isset($_GET['fid']) && isset($_GET['id']) |
|
&& is_numeric($_GET['fid']) && is_numeric($_GET['id']) |
|
&& $_GET['fid'] > 0 && $_GET['id'] > 0)) |
|
{ |
|
header("Location:index.php?do=modules&action=modedit&mod=faq&moduleaction=1&cp=" . SESSION); |
|
exit; |
|
} |
|
|
|
$AVE_DB->Query("DELETE FROM " . PREFIX . "_module_faq_quest WHERE faq_id = '" . $_GET['fid'] . "' AND id = '" . $_GET['id'] . "'"); |
|
|
|
$AVE_Template->clear_cache($tpl_dir . 'show_faq.tpl', $_GET['fid']); |
|
|
|
header("Location:index.php?do=modules&action=modedit&mod=faq&moduleaction=questlist&fid=" . $_GET['fid'] . "&cp=" . SESSION); |
|
exit; |
|
} |
|
|
|
/** |
|
* Вывод модуля вопросов и ответов в публичной части |
|
* |
|
* @param int $id идентификатор рубрики вопросов и ответов |
|
*/ |
|
public static function faqShow($id) |
|
{ |
|
global $AVE_DB, $AVE_Template; |
|
|
|
$faq = $AVE_DB->Query("SELECT faq_title, faq_description FROM " . PREFIX . "_module_faq WHERE id = '" . (int)$id . "'")->fetchArray(); |
|
|
|
$questions = array(); |
|
$sql = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_module_faq_quest WHERE faq_id = '" . (int)$id . "'"); |
|
while ($row = $sql->FetchRow()) array_push($questions, $row); |
|
|
|
$AVE_Template->assign($faq); |
|
$AVE_Template->assign('questions', $questions); |
|
} |
|
} |
|
|
|
?>
|
|
|