summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Häusler <msquare@notrademark.de>2012-11-06 00:28:27 +0100
committerPhilip Häusler <msquare@notrademark.de>2012-11-06 00:28:27 +0100
commitddbc5a9db2ff7a56e18f2bf66f7404ec57a29f62 (patch)
tree1fea8b0bc29e14a7d104435d46f994ae5effa575
parent1517422ed85755963e249cc19993116efa98d274 (diff)
old faq version
-rw-r--r--includes/pages/admin_faq.php114
-rw-r--r--includes/pages/guest_faq.php25
-rw-r--r--templates/admin_faq_edit_form.html37
3 files changed, 92 insertions, 84 deletions
diff --git a/includes/pages/admin_faq.php b/includes/pages/admin_faq.php
index 4a0a1170..2cd75955 100644
--- a/includes/pages/admin_faq.php
+++ b/includes/pages/admin_faq.php
@@ -1,98 +1,67 @@
<?php
-function admin_faq_create_edit_table($languages, $prefills = array()) {
- $form_questions = array('Question');
- $form_answers = array('Answer');
- foreach ($languages as $language) {
- $form_questions[] = '<textarea name="question[' . $language . ']" style="height: 4em;">'
- . (!empty($prefills[$language])? $prefills[$language]['question'] : '')
- . '</textarea>';
- $form_answers[] = '<textarea name="answer[' . $language . ']" style="height: 4em;">'
- . (!empty($prefills[$language])? $prefills[$language]['answer'] : '')
- . '</textarea>';
- }
-
- return table(
- array_merge(array(''), $languages),
- array($form_questions, $form_answers),
- false);
-}
-
function admin_faq() {
- $languages = sql_select("SELECT DISTINCT `Sprache` FROM `FAQ`");
- $languages = array_map('array_shift', $languages);
if (!isset ($_REQUEST['action'])) {
- $faqs = array();
- foreach ($languages as $language) {
- $lang_html .= '<th>' . $language . "</th>\n";
- $langfaqs = sql_select("SELECT `QID`, `Frage`, `Antwort` FROM `FAQ` WHERE `Sprache` = '" . sql_escape($language) . "'");
- foreach ($langfaqs as $langfaq) {
- if (!isset($faqs[$langfaq['QID']]))
- $faqs[$langfaq['QID']] = array();
- $faqs[$langfaq['QID']][$language] = sprintf('<dl><dt>%s</dt><dd>%s</dd></dl>', $langfaq['Frage'], $langfaq['Antwort']);
- $faqs[$langfaq['QID']]['edit'] = sprintf('<a href="%s&action=edit&id=%s">Edit</a>', page_link_to('admin_faq'), $langfaq['QID']);
- }
+ $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']);
}
- $faqs_html = table(array_merge(array_combine($languages, $languages), array('edit' => '')), $faqs);
return template_render('../templates/admin_faq.html', array (
'link' => page_link_to("admin_faq"),
- 'faqs' => $faqs_html,
- 'new_form' => admin_faq_create_edit_table($languages)
+ 'faqs' => $faqs_html
));
} else {
switch ($_REQUEST['action']) {
case 'create' :
- case 'save' :
- if ($_REQUEST['action'] == 'create') {
- sql_query("START TRANSACTION");
- $qid = sql_select("SELECT MAX(`QID`)+1 AS QID FROM `FAQ`");
- $qid = $qid[0]['QID'];
- }
- else {
- if (isset ($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id']))
- $qid = $_REQUEST['id'];
- else
- return error("Incomplete call, missing FAQ ID.", true);
+ $frage = strip_request_item_nl('frage');
+ $antwort = strip_request_item_nl('antwort');
+ $question = strip_request_item_nl('question');
+ $answer = strip_request_item_nl('answer');
- $faq = sql_select("SELECT `QID` FROM `FAQ` WHERE `QID`=" . sql_escape($qid));
- if (count($faq) == 0)
- return error("No FAQ found.", true);
- }
- $values = array();
- foreach ($_POST['question'] as $lang => $question) {
- if (!in_array($lang, $languages))
- continue;
- if (empty($question))
- sql_query("DELETE IGNORE FROM `FAQ` WHERE `QID` = $qid AND `Sprache` = '" . sql_escape($lang) . "'");
- else {
- $question = strip_item($question);
- $answer = strip_item($_POST['answer'][$lang]);
- $values[] = "('" . sql_escape($lang) . "', '" . sql_escape($question) . "', '" . sql_escape($answer) . "', $qid)";
- }
- }
- if (!empty($values))
- sql_query("REPLACE INTO `FAQ` (`Sprache`, `Frage`, `Antwort`, `QID`) VALUES " . implode(', ', $values));
- sql_query("COMMIT");
+ 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) . "'");
header("Location: " . page_link_to("admin_faq"));
break;
+ 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");
+
+ header("Location: " . page_link_to("admin_faq"));
+ } else
+ return error("No FAQ found.", true);
+ break;
+
case 'edit' :
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 `Sprache`, `Frage`, `Antwort` FROM `FAQ` WHERE `QID`=" . sql_escape($id));
+ $faq = sql_select("SELECT * FROM `FAQ` WHERE `FID`=" . sql_escape($id) . " LIMIT 1");
if (count($faq) > 0) {
- $prefills = array();
- foreach ($faq as $row) {
- $prefills[$row['Sprache']] = array('question' => $row['Frage'], 'answer' => $row['Antwort']);
- }
+ list ($faq) = $faq;
return template_render('../templates/admin_faq_edit_form.html', array (
'link' => page_link_to("admin_faq"),
'id' => $id,
- 'form' => admin_faq_create_edit_table($languages, $prefills)
+ 'frage' => $faq['Frage_de'],
+ 'antwort' => $faq['Antwort_de'],
+ 'question' => $faq['Frage_en'],
+ 'answer' => $faq['Antwort_en']
));
} else
return error("No FAQ found.", true);
@@ -104,8 +73,11 @@ function admin_faq() {
else
return error("Incomplete call, missing FAQ ID.", true);
- $deleted = sql_query("DELETE FROM `FAQ` WHERE `QID`=" . sql_escape($id));
- if ($deleted) {
+ $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");
header("Location: " . page_link_to("admin_faq"));
} else
return error("No FAQ found.", true);
diff --git a/includes/pages/guest_faq.php b/includes/pages/guest_faq.php
index 9d65bb36..e639731b 100644
--- a/includes/pages/guest_faq.php
+++ b/includes/pages/guest_faq.php
@@ -1,19 +1,22 @@
<?php
function guest_faq() {
$html = "";
- if ($_SESSION['Sprache'] == "DE") {
- $faqs = sql_select("SELECT * FROM `FAQ` WHERE `Sprache` = 'de'");
- } else {
- $faqs = sql_select("SELECT * FROM `FAQ` WHERE `Sprache` = 'en'");
- }
-
+ $faqs = sql_select("SELECT * FROM `FAQ`");
foreach ($faqs as $faq) {
$html .= "<dl>";
- $html .= sprintf(
- '<dt>%s</dt> <dd>%s</dd>',
- $faq['Frage'],
- $faq['Antwort']
- );
+ if ($_SESSION['Sprache'] == "DE") {
+ $html .= sprintf(
+ '<dt>%s</dt> <dd>%s</dd>',
+ $faq['Frage_de'],
+ $faq['Antwort_de']
+ );
+ } else {
+ $html .= sprintf(
+ '<dt>%s</dt> <dd>%s</dd>',
+ $faq['Frage_en'],
+ $faq['Antwort_en']
+ );
+ }
$html .= "</dl>";
}
return $html;
diff --git a/templates/admin_faq_edit_form.html b/templates/admin_faq_edit_form.html
index 2159a82d..1ef791aa 100644
--- a/templates/admin_faq_edit_form.html
+++ b/templates/admin_faq_edit_form.html
@@ -1,8 +1,41 @@
Edit FAQ:
<form action="%link%&action=save" method="post">
-%form%
+ <table>
+ <tr>
+ <td>
+ Frage
+ </td>
+ <td>
+ <textarea name="frage">%frage%</textarea>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ Antwort
+ </td>
+ <td>
+ <textarea name="antwort">%antwort%</textarea>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ Question
+ </td>
+ <td>
+ <textarea name="question">%question%</textarea>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ Answer
+ </td>
+ <td>
+ <textarea name="answer">%answer%</textarea>
+ </td>
+ </tr>
+ </table>
<input type="hidden" name="id" value="%id%" /><input type="submit" name="submit" value="Save" />
</form><hr/>
<form action="%link%&action=delete" method="post">
Delete FAQ: <input type="hidden" name="id" value="%id%" /><input type="submit" name="submit" value="Delete" />
-</form>
+</form> \ No newline at end of file