Browse Source

+ Preview of warnings in the issue warning page

emanuele 12 years ago
parent
commit
0429a581b6

+ 39 - 9
Sources/Profile-Actions.php

@@ -79,6 +79,10 @@ function issueWarning($memID)
 	if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning'))
 		fatal_lang_error('no_access', false);
 
+	// Get the base (errors related) stuff done.
+	loadLanguage('Errors');
+	$context['custom_error_title'] = $txt['profile_warning_errors_occured'];
+
 	// Make sure things which are disabled stay disabled.
 	$modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
 	$modSettings['warning_moderate'] = !empty($modSettings['warning_moderate']) && !empty($modSettings['postmod_active']) ? $modSettings['warning_moderate'] : 110;
@@ -212,15 +216,6 @@ function issueWarning($memID)
 		}
 		else
 		{
-			// Get the base stuff done.
-			loadLanguage('Errors');
-			$context['custom_error_title'] = $txt['profile_warning_errors_occured'];
-
-			// Fill in the suite of errors.
-			$context['post_errors'] = array();
-			foreach ($issueErrors as $error)
-				$context['post_errors'][] = $txt[$error];
-
 			// Try to remember some bits.
 			$context['warning_data'] = array(
 				'reason' => $_POST['warn_reason'],
@@ -234,6 +229,41 @@ function issueWarning($memID)
 		$context['member']['warning'] = $_POST['warning_level'];
 	}
 
+	if (isset($_POST['preview']))
+	{
+		$warning_body = !empty($_POST['warn_body']) ? trim(censorText($_POST['warn_body'])) : '';
+		$context['preview_subject'] = !empty($_POST['warn_sub']) ? trim($smcFunc['htmlspecialchars']($_POST['warn_sub'])) : '';
+		if (empty($_POST['warn_sub']) || empty($_POST['warn_body']))
+			$issueErrors[] = 'warning_notify_blank';
+
+		if (!empty($_POST['warn_body']))
+		{
+			require_once($sourcedir . '/Subs-Post.php');
+
+			preparsecode($warning_body);
+			$warning_body = parse_bbc($warning_body, true);
+		}
+
+		// Try to remember some bits.
+		$context['warning_data'] = array(
+			'reason' => $_POST['warn_reason'],
+			'notify' => !empty($_POST['warn_notify']),
+			'notify_subject' => isset($_POST['warn_sub']) ? $_POST['warn_sub'] : '',
+			'notify_body' => isset($_POST['warn_body']) ? $_POST['warn_body'] : '',
+			'body_preview' => $warning_body,
+		);
+// 		print_r($context['warning_data']);die();
+	}
+
+	if (!empty($issueErrors))
+	{
+		// Fill in the suite of errors.
+		$context['post_errors'] = array();
+		foreach ($issueErrors as $error)
+			$context['post_errors'][] = $txt[$error];
+	}
+
+
 	$context['page_title'] = $txt['profile_issue_warning'];
 
 	// Work our the various levels.

+ 1 - 1
Sources/Profile.php

@@ -458,7 +458,7 @@ function ModifyProfile($post_errors = array())
 		isAllowedTo($security_checks['permission']);
 
 	// Create a token if needed.
-	if (isset($security_checks['needsToken']))
+	if (isset($security_checks['needsToken']) || isset($security_checks['validateToken']))
 	{
 		createToken($token_name, $token_type);
 		$context['token_check'] = $token_name;

+ 22 - 13
Sources/Xml.php

@@ -236,23 +236,28 @@ function warning_preview()
 	$context['post_error']['messages'] = array();
 	if (allowedTo('issue_warning'))
 	{
-		$warning_body = !empty($_POST['template_body']) ? trim(censorText($_POST['template_body'])) : '';
-		$context['preview_subject'] = !empty($_POST['template_title']) ? trim($smcFunc['htmlspecialchars']($_POST['template_title'])) : '';
-		if (empty($_POST['template_title']))
-			$context['post_error']['messages'][] = $txt['mc_warning_template_error_no_title'];
-		if (empty($_POST['template_body']))
-			$context['post_error']['messages'][] = $txt['mc_warning_template_error_no_body'];
+		$warning_body = !empty($_POST['body']) ? trim(censorText($_POST['body'])) : '';
+		$context['preview_subject'] = !empty($_POST['title']) ? trim($smcFunc['htmlspecialchars']($_POST['title'])) : '';
+		if (isset($_POST['issuing']))
+		{
+			if (empty($_POST['title']) || empty($_POST['body']))
+				$context['post_error']['messages'][] = $txt['warning_notify_blank'];
+		}
 		else
 		{
+			if (empty($_POST['title']))
+				$context['post_error']['messages'][] = $txt['mc_warning_template_error_no_title'];
+			if (empty($_POST['body']))
+				$context['post_error']['messages'][] = $txt['mc_warning_template_error_no_body'];
 			// Add in few replacements.
 			/**
-			 * These are the defaults:
-			 * - {MEMBER} - Member Name. => current user for review
-			 * - {MESSAGE} - Link to Offending Post. (If Applicable) => not applicable here, so not replaced
-			 * - {FORUMNAME} - Forum Name.
-			 * - {SCRIPTURL} - Web address of forum.
-			 * - {REGARDS} - Standard email sign-off.
-			 */
+			* These are the defaults:
+			* - {MEMBER} - Member Name. => current user for review
+			* - {MESSAGE} - Link to Offending Post. (If Applicable) => not applicable here, so not replaced
+			* - {FORUMNAME} - Forum Name.
+			* - {SCRIPTURL} - Web address of forum.
+			* - {REGARDS} - Standard email sign-off.
+			*/
 			$find = array(
 				'{MEMBER}',
 				'{FORUMNAME}',
@@ -266,6 +271,10 @@ function warning_preview()
 				$txt['regards_team'],
 			);
 			$warning_body = str_replace($find, $replace, $warning_body);
+		}
+
+		if (!empty($_POST['body']))
+		{
 			preparsecode($warning_body);
 			$warning_body = parse_bbc($warning_body, true);
 		}

+ 1 - 1
Themes/default/ModerationCenter.template.php

@@ -890,7 +890,7 @@ function template_warn_template()
 			$.ajax({
 				type: "POST",
 				url: "' . $scripturl . '?action=xmlhttp;sa=previews;xml",
-				data: {item: "warning_preview", template_title: $("#template_title").val(), template_body: $("#template_body").val(), user: $(\'input[name="u"]\').attr("value")},
+				data: {item: "warning_preview", title: $("#template_title").val(), body: $("#template_body").val(), user: $(\'input[name="u"]\').attr("value")},
 				context: document.body,
 				success: function(request){
 					$("#box_preview").css({display:""});

+ 59 - 5
Themes/default/Profile.template.php

@@ -2111,6 +2111,7 @@ function template_issueWarning()
 			document.getElementById(\'warn_body\').disabled = disable;
 			document.getElementById(\'warn_temp\').disabled = disable;
 			document.getElementById(\'new_template_link\').style.display = disable ? \'none\' : \'\';
+			document.getElementById(\'preview_button\').style.display = disable ? \'none\' : \'\';
 		}
 
 		function changeWarnLevel(amount)
@@ -2215,6 +2216,17 @@ function template_issueWarning()
 					</dd>
 				</dl>
 				<hr />
+				<div id="box_preview"', !empty($context['warning_data']['body_preview']) ? '' : ' style="display:none"', '>
+					<dl class="settings">
+						<dt>
+							<strong>', $txt['preview'] , '</strong>
+						</dt>
+						<dd id="body_preview">
+							', !empty($context['warning_data']['body_preview']) ? $context['warning_data']['body_preview'] : '', '
+						</dd>
+					</dl>
+					<hr />
+				</div>
 				<dl class="settings">
 					<dt>
 						<strong>', $txt['profile_warning_notify'], ':</strong>
@@ -2252,10 +2264,11 @@ function template_issueWarning()
 
 	if (!empty($context['token_check']))
 		echo '
-				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
+					<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
 
 	echo '
 					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="submit" name="preview" id="preview_button" value="', $txt['preview'], '" class="button_submit" />
 					<input type="submit" name="save" value="', $context['user']['is_owner'] ? $txt['change_profile'] : $txt['profile_warning_issue'], '" class="button_submit" />
 				</div>
 			</div>
@@ -2264,7 +2277,8 @@ function template_issueWarning()
 	</form>';
 
 	// Previous warnings?
-	echo '<br />
+	echo '
+		<br />
 		<div class="cat_bar">
 			<h3 class="catbg">
 				', $txt['profile_warning_previous'], '
@@ -2323,11 +2337,49 @@ function template_issueWarning()
 	echo '
 	<script type="text/javascript"><!-- // --><![CDATA[
 		document.getElementById(\'warndiv1\').style.display = "";
+		document.getElementById(\'preview_button\').style.display = "none";
 		document.getElementById(\'warndiv2\').style.display = "none";';
 
 	if (!$context['user']['is_owner'])
 		echo '
-		modifyWarnNotify();';
+		modifyWarnNotify();
+		$(document).ready(function() {
+			$("#preview_button").click(function() {
+				return ajax_getTemplatePreview();
+			});
+		});
+
+		function ajax_getTemplatePreview ()
+		{
+			$.ajax({
+				type: "POST",
+				url: "' . $scripturl . '?action=xmlhttp;sa=previews;xml",
+				data: {item: "warning_preview", title: $("#warn_sub").val(), body: $("#warn_body").val(), issuing: true},
+				context: document.body,
+				success: function(request){
+					$("#box_preview").css({display:""});
+					$("#body_preview").html($(request).find(\'body\').text());
+					if ($(request).find("error").text() != \'\')
+					{
+						$("#profile_error").css({display:""});
+						var errors_html = \'<span>\' + $("#profile_error").find("span").html() + \'</span>\' + \'<ul class="list_errors" class="reset">\';
+						var errors = $(request).find(\'error\').each(function() {
+							errors_html += \'<li>\' + $(this).text() + \'</li>\';
+						});
+						errors_html += \'</ul>\';
+
+						$("#profile_error").html(errors_html);
+					}
+					else
+					{
+						$("#profile_error").css({display:"none"});
+						$("#error_list").html(\'\');
+					}
+				return false;
+				},
+			});
+			return false;
+		}';
 
 	echo '
 	// ]]></script>';
@@ -2464,7 +2516,7 @@ function template_error_message()
 		echo '
 		<div class="errorbox" id="profile_error">
 			<span>', !empty($context['custom_error_title']) ? $context['custom_error_title'] : $txt['profile_errors_occurred'], ':</span>
-			<ul class="reset">';
+			<ul id="list_errors">';
 
 		// Cycle through each error and display an error message.
 		foreach ($context['post_errors'] as $error)
@@ -2477,7 +2529,9 @@ function template_error_message()
 	}
 	else
 		echo '
-		<div class="errorbox" style="display:none" id="profile_error"></div>';
+		<div class="errorbox" style="display:none" id="profile_error">
+			<span>', !empty($context['custom_error_title']) ? $context['custom_error_title'] : $txt['profile_errors_occurred'], ':</span>
+		</div>';
 }
 
 // Display a load of drop down selectors for allowing the user to change group.