function faq() {
global $tc_db, $tpl_page;
$this->AdministratorsOnly();
$disptable = true; $formval = 'add'; $title = _gettext('FAQ Management');
if(isset($_GET['act'])) {
if ($_GET['act'] == 'edit') {
if (isset($_POST['faq'])) {
$tc_db->Execute("UPDATE `" . KU_DBPREFIX . "front` SET `subject` = " . $tc_db->qstr($_POST['heading']) . ", `message` = " . $tc_db->qstr($_POST['faq']) . ", `order` = " . intval($_POST['order']) . " WHERE `id` = " . $tc_db->qstr($_GET['id']) . "");
$tpl_page .= '<hr /><h3>'. _gettext('FAQ entry edited') .'</h3><hr />';
management_addlogentry(_gettext('Edited a FAQ entry'), 9);
}
$formval = 'edit&id='. $_GET['id']; $title .= ' - Edit';
$results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "front` WHERE `id` = " . $tc_db->qstr($_GET['id']));
$values = $results[0];
$disptable = false;
} elseif ($_GET['act'] == 'del') {
$results = $tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "front` WHERE `id` = " . $tc_db->qstr($_GET['id']));
$tpl_page .= '<hr /><h3>'. _gettext('FAQ entry deleted') .'</h3><hr />';
management_addlogentry(_gettext('Deleted a FAQ entry'), 9);
} elseif ($_GET['act'] == 'add') {
if (isset($_POST['faq']) && isset($_POST['heading']) && isset($_POST['order'])) {
if (!empty($_POST['faq']) || !empty($_POST['heading'])) {
$tpl_page .= '<hr />';
$tc_db->Execute("INSERT HIGH_PRIORITY INTO `" . KU_DBPREFIX . "front` ( `page`, `subject` , `message` , `order` ) VALUES ( '1', " . $tc_db->qstr($_POST['heading']) . " , " . intval($_POST['faq']) . " , " . intval($_POST['order']) . " )");
$tpl_page .= '<h3>'. _gettext('FAQ entry successfully added.') . '</h3>';
management_addlogentry(_gettext('Added a FAQ entry'), 9);
$tpl_page .= '<hr />';
} else {
$tpl_page .= '<hr />'. _gettext('You must enter a heading as well as a post.') .'<hr />';
}
}
}
}
$tpl_page .= '<h2>'. $title . '</h2><br />
<form method="post" action="?action=faq&act='. $formval . '">
<label for="heading">'. _gettext('Heading') . ':</label>
<input type="text" id="heading" name="heading" value="'. (isset($values['subject']) ? $values['subject'] : '') . '" />
<div class="desc">'. _gettext('Can not be left blank.') . '</div><br />
<label for="faq"> '. _gettext('Post') . ':</label>
<textarea id="faq" name="faq" rows="25" cols="80">' . (isset($values['message']) ? htmlspecialchars($values['message']) : '') . '</textarea><br /><br />
<label for="order">'. _gettext('Order') . ':</label>
<input type="text" id="order" name="order" value="' . (isset($values['order']) ? $values['order'] : '') . '" />
<div class="desc">'. _gettext('This can be left blank, however it will appear at the very top of the list') . '</div><br />
<input type="submit" value="'. _gettext('Add') . '" />
</form>';
if ($disptable) {
$tpl_page .= '<br /><hr /><h1>'. _gettext('Edit/Delete FAQ Entries') .'</h1>';
$results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "front` WHERE `page` = 1 ORDER BY `order` ASC");
if (count($results) > 0) {
$tpl_page .= '<table border="1" width="100%"><tr><th>'. _gettext('Order') .'</th><th>'. _gettext('Heading') .'</th><th>'. _gettext('Message') .'</th><th>'. _gettext('Edit/Delete') .'</th></tr>';
foreach ($results as $line) {
$tpl_page .= '<tr><td>'. $line['order'] . '</td><td>'. $line['subject'] . '</td><td>'. $line['message'] . '</td><td>[<a href="?action=faq&act=edit&id='. $line['id'] . '">'. _gettext('Edit') .'</a>] [<a href="?action=faq&act=del&id='. $line['id'] . '">'. _gettext('Delete') .'</a>]</td></tr>';
}
$tpl_page .= '</table>';
} else {
$tpl_page .= _gettext('No FAQ entries yet.');
}
}
}