diff --git a/db/update.d/01_faq.php b/db/update.d/01_faq.php
index 1e32f1ad..759cc109 100644
--- a/db/update.d/01_faq.php
+++ b/db/update.d/01_faq.php
@@ -1,16 +1,20 @@
', $row['Frage'], 2);
- $answer = explode(' ', $row['Antwort'], 2);
+ $question = preg_split('#(?:<|<)br(?:>|>)#i', $row['Frage'], 2, PREG_SPLIT_NO_EMPTY);
+ $answer = preg_split('#(?:<|<)br(?:>|>)#i', $row['Antwort'], 2, PREG_SPLIT_NO_EMPTY);
if(count($question) == 2 && count($answer) == 2)
- sql_query("INSERT INTO `FAQ` (`Frage`, `Antwort`, `Sprache`) VALUES ('" . sql_escape(trim($question[1])) . "', '" . sql_escape(trim($answer[1])) . "', 'en')");
- sql_query("UPDATE `FAQ` SET `Frage` = '" . sql_escape(trim($question[0])) . "', `Antwort` = '" . sql_escape(trim($answer[0])) . "', `Sprache` = 'de' WHERE `FID` = " . $row['FID']);
+ sql_query("INSERT INTO `FAQ` (`Frage`, `Antwort`, `Sprache`, `QID`) VALUES ('" . sql_escape(trim($question[1])) . "', '" . sql_escape(trim($answer[1])) . "', 'en', $i)");
+ sql_query("UPDATE `FAQ` SET `Frage` = '" . sql_escape(trim($question[0])) . "', `Antwort` = '" . sql_escape(trim($answer[0])) . "', `Sprache` = 'de', `QID` = $i WHERE `FID` = " . $row['FID']);
+ $i++;
}
+ _add_index('FAQ', array('QID', 'Sprache'), 'UNIQUE');
$applied = true;
}
diff --git a/includes/pages/admin_faq.php b/includes/pages/admin_faq.php
index 2cd75955..4a0a1170 100644
--- a/includes/pages/admin_faq.php
+++ b/includes/pages/admin_faq.php
@@ -1,67 +1,98 @@
'
+ . (!empty($prefills[$language])? $prefills[$language]['question'] : '')
+ . '';
+ $form_answers[] = '';
+ }
+
+ 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_html = "";
- $faqs = sql_select("SELECT * FROM `FAQ`");
- foreach ($faqs as $faq) {
- $faqs_html .= sprintf('
%s %s ' . ' %s %s ' . 'Edit ', $faq['Frage_de'], $faq['Antwort_de'], $faq['Frage_en'], $faq['Antwort_en'], page_link_to('admin_faq'), $faq['FID']);
+ $faqs = array();
+ foreach ($languages as $language) {
+ $lang_html .= '' . $language . " \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('%s %s ', $langfaq['Frage'], $langfaq['Antwort']);
+ $faqs[$langfaq['QID']]['edit'] = sprintf('Edit ', page_link_to('admin_faq'), $langfaq['QID']);
+ }
}
+ $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
+ 'faqs' => $faqs_html,
+ 'new_form' => admin_faq_create_edit_table($languages)
));
} else {
switch ($_REQUEST['action']) {
case 'create' :
- $frage = strip_request_item_nl('frage');
- $antwort = strip_request_item_nl('antwort');
- $question = strip_request_item_nl('question');
- $answer = strip_request_item_nl('answer');
+ 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);
- 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) . "'");
+ $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");
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 * FROM `FAQ` WHERE `FID`=" . sql_escape($id) . " LIMIT 1");
+ $faq = sql_select("SELECT `Sprache`, `Frage`, `Antwort` FROM `FAQ` WHERE `QID`=" . sql_escape($id));
if (count($faq) > 0) {
- list ($faq) = $faq;
+ $prefills = array();
+ foreach ($faq as $row) {
+ $prefills[$row['Sprache']] = array('question' => $row['Frage'], 'answer' => $row['Antwort']);
+ }
return template_render('../templates/admin_faq_edit_form.html', array (
'link' => page_link_to("admin_faq"),
'id' => $id,
- 'frage' => $faq['Frage_de'],
- 'antwort' => $faq['Antwort_de'],
- 'question' => $faq['Frage_en'],
- 'answer' => $faq['Antwort_en']
+ 'form' => admin_faq_create_edit_table($languages, $prefills)
));
} else
return error("No FAQ found.", true);
@@ -73,11 +104,8 @@ function admin_faq() {
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;
-
- sql_query("DELETE FROM `FAQ` WHERE `FID`=" . sql_escape($id) . " LIMIT 1");
+ $deleted = sql_query("DELETE FROM `FAQ` WHERE `QID`=" . sql_escape($id));
+ if ($deleted) {
header("Location: " . page_link_to("admin_faq"));
} else
return error("No FAQ found.", true);
diff --git a/templates/admin_faq.html b/templates/admin_faq.html
index 5dacf522..0eee8d20 100644
--- a/templates/admin_faq.html
+++ b/templates/admin_faq.html
@@ -1,56 +1,6 @@
-
-
-
-
- Deutsch
-
-
- English
-
-
-
-
-
-
-
- %faqs%
-
-
+%faqs%
Create new FAQ:
\ No newline at end of file
+
diff --git a/templates/admin_faq_edit_form.html b/templates/admin_faq_edit_form.html
index 1ef791aa..2159a82d 100644
--- a/templates/admin_faq_edit_form.html
+++ b/templates/admin_faq_edit_form.html
@@ -1,41 +1,8 @@
Edit FAQ:
-
-
-
- Frage
-
-
- %frage%
-
-
-
-
- Antwort
-
-
- %antwort%
-
-
-
-
- Question
-
-
- %question%
-
-
-
-
- Answer
-
-
- %answer%
-
-
-
+%form%
Delete FAQ:
-
\ No newline at end of file
+