engelsystem/includes/pages/admin_faq.php

89 lines
3.2 KiB
PHP
Raw Normal View History

2011-06-03 01:03:39 +02:00
<?php
function admin_faq() {
if (!isset ($_REQUEST['action'])) {
2012-11-06 00:28:27 +01:00
$faqs_html = "";
$faqs = sql_select("SELECT * FROM `FAQ`");
foreach ($faqs as $faq) {
$faqs_html .= sprintf('<tr><td> <dl><dt>%s</dt><dd>%s</dd></dl> </td>' . '<td> <dl><dt>%s</dt><dd>%s</dd></dl> </td>' . '<td><a href="%s&action=edit&id=%s">Edit</a></td></tr>', $faq['Frage_de'], $faq['Antwort_de'], $faq['Frage_en'], $faq['Antwort_en'], page_link_to('admin_faq'), $faq['FID']);
2011-06-03 01:03:39 +02:00
}
return template_render('../templates/admin_faq.html', array (
'link' => page_link_to("admin_faq"),
2012-11-06 00:28:27 +01:00
'faqs' => $faqs_html
2011-06-03 01:03:39 +02:00
));
} else {
switch ($_REQUEST['action']) {
case 'create' :
2012-11-06 00:28:27 +01:00
$frage = strip_request_item_nl('frage');
$antwort = strip_request_item_nl('antwort');
$question = strip_request_item_nl('question');
$answer = strip_request_item_nl('answer');
2011-06-03 11:09:25 +02:00
2012-11-06 00:28:27 +01:00
sql_query("INSERT INTO `FAQ` SET `Frage_de`='" . sql_escape($frage) . "', `Frage_en`='" . sql_escape($question) . "', `Antwort_de`='" . sql_escape($antwort) . "', `Antwort_en`='" . sql_escape($answer) . "'");
2011-06-03 11:09:25 +02:00
2012-12-30 18:27:45 +01:00
redirect(page_link_to("admin_faq"));
2011-06-03 01:03:39 +02:00
break;
2012-11-06 00:28:27 +01:00
case 'save' :
if (isset ($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id']))
$id = $_REQUEST['id'];
else
return error("Incomplete call, missing FAQ ID.", true);
$faq = sql_select("SELECT * FROM `FAQ` WHERE `FID`=" . sql_escape($id) . " LIMIT 1");
if (count($faq) > 0) {
list ($faq) = $faq;
$frage = strip_request_item_nl('frage');
$antwort = strip_request_item_nl('antwort');
$question = strip_request_item_nl('question');
$answer = strip_request_item_nl('answer');
sql_query("UPDATE `FAQ` SET `Frage_de`='" . sql_escape($frage) . "', `Frage_en`='" . sql_escape($question) . "', `Antwort_de`='" . sql_escape($antwort) . "', `Antwort_en`='" . sql_escape($answer) . "' WHERE `FID`=" . sql_escape($id) . " LIMIT 1");
2012-12-30 18:27:45 +01:00
redirect(page_link_to("admin_faq"));
2012-11-06 00:28:27 +01:00
} else
return error("No FAQ found.", true);
break;
2011-06-03 01:03:39 +02:00
case 'edit' :
if (isset ($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id']))
$id = $_REQUEST['id'];
else
2011-12-21 23:18:57 +01:00
return error("Incomplete call, missing FAQ ID.", true);
2011-06-03 01:03:39 +02:00
2012-11-06 00:28:27 +01:00
$faq = sql_select("SELECT * FROM `FAQ` WHERE `FID`=" . sql_escape($id) . " LIMIT 1");
2011-06-03 01:03:39 +02:00
if (count($faq) > 0) {
2012-11-06 00:28:27 +01:00
list ($faq) = $faq;
2011-06-03 01:03:39 +02:00
return template_render('../templates/admin_faq_edit_form.html', array (
'link' => page_link_to("admin_faq"),
'id' => $id,
2012-11-06 00:28:27 +01:00
'frage' => $faq['Frage_de'],
'antwort' => $faq['Antwort_de'],
'question' => $faq['Frage_en'],
'answer' => $faq['Antwort_en']
2011-06-03 01:03:39 +02:00
));
} else
2011-12-21 23:18:57 +01:00
return error("No FAQ found.", true);
2011-06-03 01:03:39 +02:00
break;
case 'delete' :
if (isset ($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id']))
$id = $_REQUEST['id'];
else
2011-12-21 23:18:57 +01:00
return error("Incomplete call, missing FAQ ID.", true);
2011-06-03 01:03:39 +02:00
2012-11-06 00:28:27 +01:00
$faq = sql_select("SELECT * FROM `FAQ` WHERE `FID`=" . sql_escape($id) . " LIMIT 1");
if (count($faq) > 0) {
list ($faq) = $faq;
sql_query("DELETE FROM `FAQ` WHERE `FID`=" . sql_escape($id) . " LIMIT 1");
2012-12-30 18:27:45 +01:00
redirect(page_link_to("admin_faq"));
2011-06-03 01:03:39 +02:00
} else
2011-12-21 23:18:57 +01:00
return error("No FAQ found.", true);
2011-06-03 01:03:39 +02:00
break;
}
}
}
2011-06-03 11:09:25 +02:00
?>