Browse Source

Merge pull request #930 from Oldiesmann/release-2.1

! Don't throw errors if there aren't any questions when saving spam sett...
Michael Eshom 11 years ago
parent
commit
ac798b5f8d
1 changed files with 50 additions and 47 deletions
  1. 50 47
      Sources/ManageSettings.php

+ 50 - 47
Sources/ManageSettings.php

@@ -577,58 +577,61 @@ function ModifyAntispamSettings($return_config = false)
 						$changes['delete'][] = $q_id;
 
 			// Now let's see if there are new questions or ones that need updating.
-			foreach ($_POST['question'][$lang_id] as $q_id => $question)
+			if (isset($_POST['question'][$lang_id]))
 			{
-				// Ignore junky ids.
-				$q_id = (int) $q_id;
-				if ($q_id <= 0)
-					continue;
-
-				// Check the question isn't empty (because they want to delete it?)
-				if (empty($question) || trim($question) == '')
+				foreach ($_POST['question'][$lang_id] as $q_id => $question)
 				{
-					if (isset($context['question_answers'][$q_id]))
-						$changes['delete'][] = $q_id;
-					continue;
-				}
-				$question = $smcFunc['htmlspecialchars'](trim($question));
+					// Ignore junky ids.
+					$q_id = (int) $q_id;
+					if ($q_id <= 0)
+						continue;
 
-				// Get the answers. Firstly check there actually might be some.
-				if (!isset($_POST['answer'][$lang_id][$q_id]) || !is_array($_POST['answer'][$lang_id][$q_id]))
-				{
-					if (isset($context['question_answers'][$q_id]))
-						$changes['delete'][] = $q_id;
-					continue;
-				}
-				// Now get them and check that they might be viable.
-				$answers = array();
-				foreach ($_POST['answer'][$lang_id][$q_id] as $answer)
-					if (!empty($answer) && trim($answer) !== '')
-						$answers[] = $smcFunc['htmlspecialchars'](trim($answer));
-				if (empty($answers))
-				{
-					if (isset($context['question_answers'][$q_id]))
-						$changes['delete'][] = $q_id;
-					continue;
-				}
-				$answers = serialize($answers);
+					// Check the question isn't empty (because they want to delete it?)
+					if (empty($question) || trim($question) == '')
+					{
+						if (isset($context['question_answers'][$q_id]))
+							$changes['delete'][] = $q_id;
+						continue;
+					}
+					$question = $smcFunc['htmlspecialchars'](trim($question));
 
-				// At this point we know we have a question and some answers. What are we doing with it?
-				if (!isset($context['question_answers'][$q_id]))
-				{
-					// New question. Now, we don't want to randomly consume ids, so we'll set those, rather than trusting the browser's supplied ids.
-					$changes['insert'][] = array($lang_id, $question, $answers);
-				}
-				else
-				{
-					// It's an existing question. Let's see what's changed, if anything.
-					if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers'])
-						$changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers);
-				}
+					// Get the answers. Firstly check there actually might be some.
+					if (!isset($_POST['answer'][$lang_id][$q_id]) || !is_array($_POST['answer'][$lang_id][$q_id]))
+					{
+						if (isset($context['question_answers'][$q_id]))
+							$changes['delete'][] = $q_id;
+						continue;
+					}
+					// Now get them and check that they might be viable.
+					$answers = array();
+					foreach ($_POST['answer'][$lang_id][$q_id] as $answer)
+						if (!empty($answer) && trim($answer) !== '')
+							$answers[] = $smcFunc['htmlspecialchars'](trim($answer));
+					if (empty($answers))
+					{
+						if (isset($context['question_answers'][$q_id]))
+							$changes['delete'][] = $q_id;
+						continue;
+					}
+					$answers = serialize($answers);
 
-				if (!isset($qs_per_lang[$lang_id]))
-					$qs_per_lang[$lang_id] = 0;
-				$qs_per_lang[$lang_id]++;
+					// At this point we know we have a question and some answers. What are we doing with it?
+					if (!isset($context['question_answers'][$q_id]))
+					{
+						// New question. Now, we don't want to randomly consume ids, so we'll set those, rather than trusting the browser's supplied ids.
+						$changes['insert'][] = array($lang_id, $question, $answers);
+					}
+					else
+					{
+						// It's an existing question. Let's see what's changed, if anything.
+						if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers'])
+							$changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers);
+					}
+	
+					if (!isset($qs_per_lang[$lang_id]))
+						$qs_per_lang[$lang_id] = 0;
+					$qs_per_lang[$lang_id]++;
+				}
 			}
 		}