Kaynağa Gözat

! No more fatal_lang_error when a warning template is missing body or title (error box instead)

emanuele 12 yıl önce
ebeveyn
işleme
8fb1ef8a3b

+ 68 - 57
Sources/ModerationCenter.php

@@ -1974,72 +1974,83 @@ function ModifyWarningTemplate()
 		$_POST['template_title'] = trim($_POST['template_title']);
 
 		// Need something in both boxes.
-		if (empty($_POST['template_body']) || empty($_POST['template_title']))
-			fatal_error($txt['mc_warning_template_error_empty']);
-
-		// Safety first.
-		$_POST['template_title'] = $smcFunc['htmlspecialchars']($_POST['template_title']);
+		if (!empty($_POST['template_body']) && !empty($_POST['template_title']))
+		{
+			// Safety first.
+			$_POST['template_title'] = $smcFunc['htmlspecialchars']($_POST['template_title']);
 
-		// Clean up BBC.
-		preparsecode($_POST['template_body']);
-		// But put line breaks back!
-		$_POST['template_body'] = strtr($_POST['template_body'], array('<br />' => "\n"));
+			// Clean up BBC.
+			preparsecode($_POST['template_body']);
+			// But put line breaks back!
+			$_POST['template_body'] = strtr($_POST['template_body'], array('<br />' => "\n"));
 
-		// Is this personal?
-		$recipient_id = !empty($_POST['make_personal']) ? $user_info['id'] : 0;
+			// Is this personal?
+			$recipient_id = !empty($_POST['make_personal']) ? $user_info['id'] : 0;
 
-		// If we are this far it's save time.
-		if ($context['is_edit'])
-		{
-			// Simple update...
-			$smcFunc['db_query']('', '
-				UPDATE {db_prefix}log_comments
-				SET id_recipient = {int:personal}, recipient_name = {string:title}, body = {string:body}
-				WHERE id_comment = {int:id}
-					AND comment_type = {string:warntpl}
-					AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})'.
-					($recipient_id ? ' AND id_member = {int:current_member}' : ''),
-				array(
-					'personal' => $recipient_id,
-					'title' => $_POST['template_title'],
-					'body' => $_POST['template_body'],
-					'id' => $context['id_template'],
-					'warntpl' => 'warntpl',
-					'generic' => 0,
-					'current_member' => $user_info['id'],
-				)
-			);
+			// If we are this far it's save time.
+			if ($context['is_edit'])
+			{
+				// Simple update...
+				$smcFunc['db_query']('', '
+					UPDATE {db_prefix}log_comments
+					SET id_recipient = {int:personal}, recipient_name = {string:title}, body = {string:body}
+					WHERE id_comment = {int:id}
+						AND comment_type = {string:warntpl}
+						AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})'.
+						($recipient_id ? ' AND id_member = {int:current_member}' : ''),
+					array(
+						'personal' => $recipient_id,
+						'title' => $_POST['template_title'],
+						'body' => $_POST['template_body'],
+						'id' => $context['id_template'],
+						'warntpl' => 'warntpl',
+						'generic' => 0,
+						'current_member' => $user_info['id'],
+					)
+				);
+
+				// If it wasn't visible and now is they've effectively added it.
+				if ($context['template_data']['personal'] && !$recipient_id)
+					logAction('add_warn_template', array('template' => $_POST['template_title']));
+				// Conversely if they made it personal it's a delete.
+				elseif (!$context['template_data']['personal'] && $recipient_id)
+					logAction('delete_warn_template', array('template' => $_POST['template_title']));
+				// Otherwise just an edit.
+				else
+					logAction('modify_warn_template', array('template' => $_POST['template_title']));
+			}
+			else
+			{
+				$smcFunc['db_insert']('',
+					'{db_prefix}log_comments',
+					array(
+						'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'id_recipient' => 'int',
+						'recipient_name' => 'string-255', 'body' => 'string-65535', 'log_time' => 'int',
+					),
+					array(
+						$user_info['id'], $user_info['name'], 'warntpl', $recipient_id,
+						$_POST['template_title'], $_POST['template_body'], time(),
+					),
+					array('id_comment')
+				);
 
-			// If it wasn't visible and now is they've effectively added it.
-			if ($context['template_data']['personal'] && !$recipient_id)
 				logAction('add_warn_template', array('template' => $_POST['template_title']));
-			// Conversely if they made it personal it's a delete.
-			elseif (!$context['template_data']['personal'] && $recipient_id)
-				logAction('delete_warn_template', array('template' => $_POST['template_title']));
-			// Otherwise just an edit.
-			else
-				logAction('modify_warn_template', array('template' => $_POST['template_title']));
+			}
+
+			// Get out of town...
+			redirectexit('action=moderate;area=warnings;sa=templates');
 		}
 		else
 		{
-			$smcFunc['db_insert']('',
-				'{db_prefix}log_comments',
-				array(
-					'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'id_recipient' => 'int',
-					'recipient_name' => 'string-255', 'body' => 'string-65535', 'log_time' => 'int',
-				),
-				array(
-					$user_info['id'], $user_info['name'], 'warntpl', $recipient_id,
-					$_POST['template_title'], $_POST['template_body'], time(),
-				),
-				array('id_comment')
-			);
-
-			logAction('add_warn_template', array('template' => $_POST['template_title']));
+			$context['warning_errors'] = array();
+			$context['template_data']['title'] = !empty($_POST['template_title']) ? $_POST['template_title'] : '';
+			$context['template_data']['body'] = !empty($_POST['template_body']) ? $_POST['template_body'] : $txt['mc_warning_template_body_default'];
+			$context['template_data']['personal'] = !empty($_POST['make_personal']);
+			if (empty($_POST['template_title']))
+				$context['warning_errors'][] = $txt['mc_warning_template_error_no_title'];
+			if (empty($_POST['template_body']))
+				$context['warning_errors'][] = $txt['mc_warning_template_error_no_body'];
 		}
-
-		// Get out of town...
-		redirectexit('action=moderate;area=warnings;sa=templates');
 	}
 
 	createToken('mod-wt');

+ 10 - 0
Themes/default/ModerationCenter.template.php

@@ -821,6 +821,16 @@ function template_warn_template()
 			<div class="windowbg">
 				<span class="topslice"><span></span></span>
 				<div class="content">
+					<div class="errorbox"', empty($context['warning_errors']) ? ' style="display: none"' : '', ' id="errors">
+						<dl>
+							<dt>
+								<strong id="error_serious">', $txt['error_while_submitting'] , '</strong>
+							</dt>
+							<dd class="error" id="error_list">
+								', empty($context['warning_errors']) ? '' : implode('<br />', $context['warning_errors']), '
+							</dd>
+						</dl>
+					</div>
 					<dl class="settings">
 						<dt>
 							<strong><label for="template_title">', $txt['mc_warning_template_title'], '</label>:</strong>

+ 2 - 1
Themes/default/languages/ModerationCenter.english.php

@@ -123,7 +123,8 @@ $txt['mc_warning_template_body_desc'] = 'The content of the notification message
 $txt['mc_warning_template_body_default'] = '{MEMBER},' . "\n\n" . 'You have received a warning for inappropriate activity. Please cease these activities and abide by the forum rules otherwise we will take further action.' . "\n\n" . '{REGARDS}';
 $txt['mc_warning_template_personal'] = 'Personal Template';
 $txt['mc_warning_template_personal_desc'] = 'If you select this option only you will be able to see, edit and use this template. If not selected all moderators will be able to use this template.';
-$txt['mc_warning_template_error_empty'] = 'You must set both a title and notification body.';
+$txt['mc_warning_template_error_no_title'] = 'You must set title.';
+$txt['mc_warning_template_error_no_body'] = 'You must set a notification body.';
 
 $txt['mc_prefs'] = 'Preferences';
 $txt['mc_settings'] = 'Change Settings';