Browse Source

Restuctured the array to match ['ban'], working on concistency and few fixes coming from testing

Signed-off-by: emanuele <[email protected]>
emanuele 13 years ago
parent
commit
4df6a1e984
3 changed files with 36 additions and 75 deletions
  1. 32 23
      Sources/ManageBans.php
  2. 2 50
      Themes/default/ManageBans.template.php
  3. 2 2
      Themes/default/Wireless.template.php

+ 32 - 23
Sources/ManageBans.php

@@ -366,13 +366,14 @@ function BanEdit()
 {
 	global $txt, $modSettings, $context, $ban_request, $scripturl, $smcFunc;
 
-	if ((isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && empty($context['ban_errors']))
+	if ((isset($_POST['add_ban']) || isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && empty($context['ban_errors']))
 		BanEdit2();
 
+	$ban_group_id = isset($context['ban']['id']) ? $context['ban']['id'] : (isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0);
+
 	// Template needs this to show errors using javascript
 	loadLanguage('Errors');
 
-
 	if (!empty($context['ban_errors']))
 	{
 		foreach ($context['ban_errors'] as $error)
@@ -403,7 +404,7 @@ function BanEdit()
 	else
 	{
 		// If we're editing an existing ban, get it from the database.
-		if (!empty($_REQUEST['bg']))
+		if (!empty($ban_group_id))
 		{
 			$context['ban_items'] = array();
 			$request = $smcFunc['db_query']('', '
@@ -418,7 +419,7 @@ function BanEdit()
 					LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = bi.id_member)
 				WHERE bg.id_ban_group = {int:current_ban}',
 				array(
-					'current_ban' => $_REQUEST['bg'],
+					'current_ban' => $ban_group_id,
 				)
 			);
 			if ($smcFunc['db_num_rows']($request) == 0)
@@ -432,7 +433,7 @@ function BanEdit()
 						'id' => $row['id_ban_group'],
 						'name' => $row['name'],
 						'expiration' => array(
-							'status' => $row['expire_time'] === null ? 'never' : ($row['expire_time'] < time() ? 'expired' : 'still_active_but_we_re_counting_the_days'),
+							'status' => $row['expire_time'] === null ? 'never' : ($row['expire_time'] < time() ? 'expired' : 'one_day'),
 							'days' => $row['expire_time'] > time() ? floor(($row['expire_time'] - time()) / 86400) : 0
 						),
 						'reason' => $row['reason'],
@@ -446,6 +447,7 @@ function BanEdit()
 						'is_new' => false,
 					);
 				}
+
 				if (!empty($row['id_ban']))
 				{
 					$context['ban_items'][$row['id_ban']] = array(
@@ -607,7 +609,7 @@ function BanEdit()
 
 function banEdit2()
 {
-	global $context;
+	global $smcFunc, $context;
 
 	checkSession();
 	validateToken('admin-bet');
@@ -619,16 +621,22 @@ function banEdit2()
 	{
 		// Let's collect all the information we need
 		$ban_info['id'] = isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0;
-		$ban_info['expire_date'] = !empty($_POST['ban_time']) ? (int) $_POST['ban_time'] : 0;
-		$ban_info['expiration'] = empty($_POST['ban_time']) ? 'NULL' : ($ban_info['expire_date'] != 0 ? time() + 24 * 60 * 60 * $ban_info['expire_date'] : 'expire_time');
-		$ban_info['full_ban'] = empty($_POST['ban_time']) ? 0 : 1;
+		$ban_info['is_new'] = empty($ban_info['id']);
+		$ban_info['expire_date'] = !empty($_POST['expire_date']) ? (int) $_POST['expire_date'] : 0;
+		$ban_info['expiration'] = array(
+			'status' => isset($_POST['expiration']) && in_array($_POST['expiration'], array('never', 'one_day', 'expired')) ? $_POST['expiration'] : 'never',
+			'days' => $ban_info['expire_date'],
+		);
+		$ban_info['db_expiration'] = $ban_info['expiration'] == 'never' ? 'NULL' : ($ban_info['expiration'] == 'one_day' ? time() + 24 * 60 * 60 * $ban_info['expire_date'] : 0);
+		$ban_info['full_ban'] = empty($_POST['full_ban']) ? 0 : 1;
 		$ban_info['reason'] = !empty($_POST['ban_reason']) ? $smcFunc['htmlspecialchars']($_POST['ban_reason'], ENT_QUOTES) : '';
 		$ban_info['name'] = !empty($_POST['ban_name']) ? $smcFunc['htmlspecialchars']($_POST['ban_name'], ENT_QUOTES) : '';
 		$ban_info['notes'] = isset($_POST['notes']) ? $smcFunc['htmlspecialchars']($_POST['notes'], ENT_QUOTES) : '';
 		$ban_info['notes'] = str_replace(array("\r", "\n", '  '), array('', '<br />', '&nbsp; '), $ban_info['notes']);
-		$ban_info['cannot_post'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_post']) ? 0 : 1;
-		$ban_info['cannot_register'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_register']) ? 0 : 1;
-		$ban_info['cannot_login'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_login']) ? 0 : 1;	
+		$ban_info['cannot']['access'] = !empty($ban_info['full_ban']) ? 1 : 0;
+		$ban_info['cannot']['post'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_post']) ? 0 : 1;
+		$ban_info['cannot']['register'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_register']) ? 0 : 1;
+		$ban_info['cannot']['login'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_login']) ? 0 : 1;	
 
 		// Adding a new ban group
 		if (empty($_REQUEST['bg']))
@@ -637,10 +645,10 @@ function banEdit2()
 		else
 			$ban_group_id = updateBanGroup($ban_info);
 
-		if (!is_numeric($ban_group_id))
-			$context['ban'] = $ban_info;
-		else
+		if (is_numeric($ban_group_id))
 			$ban_info['id'] = $ban_group_id;
+
+		$context['ban'] = $ban_info;
 	}
 
 	if (isset($_POST['ban_suggestion']))
@@ -732,6 +740,7 @@ function validateTriggers(&$triggers)
 		$context['ban_erros'][] = 'ban_empty_triggers';
 
 	$ban_triggers = array();
+	$log_info = array();
 
 	foreach ($triggers as $key => $value)
 	{
@@ -1064,11 +1073,11 @@ function updateBanGroup($ban_info = array())
 			cannot_login = {int:cannot_login}
 		WHERE id_ban_group = {int:id_ban_group}',
 		array(
-			'expiration' => $ban_info['expiration'],
-			'cannot_access' => $ban_info['full_ban'],
-			'cannot_post' => $ban_info['cannot_post'],
-			'cannot_register' => $ban_info['cannot_register'],
-			'cannot_login' => $ban_info['cannot_login'],
+			'expiration' => $ban_info['db_expiration'],
+			'cannot_access' => $ban_info['cannot']['access'],
+			'cannot_post' => $ban_info['cannot']['post'],
+			'cannot_register' => $ban_info['cannot']['register'],
+			'cannot_login' => $ban_info['cannot']['login'],
 			'id_ban_group' => $ban_info['id'],
 			'ban_name' => $ban_info['name'],
 			'reason' => $ban_info['reason'],
@@ -1111,7 +1120,7 @@ function insertBanGroup($ban_info = array())
 
 	if ($smcFunc['db_num_rows']($request) == 1)
 	{
-		list($id_ban) = $smcfunc['db_fetch_row']($request);
+		list($id_ban) = $smcFunc['db_fetch_row']($request);
 		$smcFunc['db_free_result']($request);
 		return $id_ban;
 	}
@@ -1125,8 +1134,8 @@ function insertBanGroup($ban_info = array())
 			'cannot_post' => 'int', 'cannot_login' => 'int', 'reason' => 'string-255', 'notes' => 'string-65534',
 		),
 		array(
-			$ban_info['name'], time(), $ban_info['expiration'], $ban_info['full_ban'], $ban_info['cannot_register'],
-			$ban_info['cannot_post'], $ban_info['cannot_login'], $ban_info['reason'], $ban_info['notes'],
+			$ban_info['name'], time(), $ban_info['db_expiration'], $ban_info['cannot']['access'], $ban_info['cannot']['register'],
+			$ban_info['cannot']['post'], $ban_info['cannot']['login'], $ban_info['reason'], $ban_info['notes'],
 		),
 		array('id_ban_group')
 	);

+ 2 - 50
Themes/default/ManageBans.template.php

@@ -29,55 +29,7 @@ function template_ban_edit()
 
 	echo '
 			<div class="content">
-				<dl class="settings">
-					<dt>
-						<strong><label for="ban_name">', $txt['ban_name'], ':</label></strong>
-					</dt>
-					<dd>
-						<input type="text" name="ban_name" id="ban_name" value="', $context['ban']['name'], '" size="47" maxlength="60" class="input_text" />
-					</dd>
-					<dt>
-						<strong><label for="reason">', $txt['ban_reason'], ':</label></strong><br />
-						<span class="smalltext">', $txt['ban_reason_desc'], '</span>
-					</dt>
-					<dd>
-						<textarea name="reason" id="reason" cols="40" rows="3" style="min-height: 64px; max-height: 64px; min-width: 50%; max-width: 99%;">', $context['ban']['reason'], '</textarea>
-					</dd>
-					<dt>
-						<strong><label for="ban_notes">', $txt['ban_notes'], ':</label></strong><br />
-						<span class="smalltext">', $txt['ban_notes_desc'], '</span>
-					</dt>
-					<dd>
-						<textarea name="notes" id="ban_notes" cols="40" rows="3" style="min-height: 64px; max-height: 64px; min-width: 50%; max-width: 99%;">', $context['ban']['notes'], '</textarea>
-					</dd>
-				</dl>
-				<fieldset class="ban_settings floatleft">
-					<legend>
-						', $txt['ban_expiration'], '
-					</legend>
-					<input type="radio" name="expiration" value="never" id="never_expires" onclick="fUpdateStatus();"', $context['ban']['expiration']['status'] == 'never' ? ' checked="checked"' : '', ' class="input_radio" /> <label for="never_expires">', $txt['never'], '</label><br />
-					<input type="radio" name="expiration" value="one_day" id="expires_one_day" onclick="fUpdateStatus();"', $context['ban']['expiration']['status'] == 'still_active_but_we_re_counting_the_days' ? ' checked="checked"' : '', ' class="input_radio" /> <label for="expires_one_day">', $txt['ban_will_expire_within'], '</label>: <input type="text" name="expire_date" id="expire_date" size="3" value="', $context['ban']['expiration']['days'], '" class="input_text" /> ', $txt['ban_days'], '<br />
-					<input type="radio" name="expiration" value="expired" id="already_expired" onclick="fUpdateStatus();"', $context['ban']['expiration']['status'] == 'expired' ? ' checked="checked"' : '', ' class="input_radio" /> <label for="already_expired">', $txt['ban_expired'], '</label>
-				</fieldset>
-				<fieldset class="ban_settings floatright">
-					<legend>
-						', $txt['ban_restriction'], '
-					</legend>
-					<input type="radio" name="full_ban" id="full_ban" value="1" onclick="fUpdateStatus();"', $context['ban']['cannot']['access'] ? ' checked="checked"' : '', ' class="input_radio" /> <label for="full_ban">', $txt['ban_full_ban'], '</label><br />
-					<input type="radio" name="full_ban" id="partial_ban" value="0" onclick="fUpdateStatus();"', !$context['ban']['cannot']['access'] ? ' checked="checked"' : '', ' class="input_radio" /> <label for="partial_ban">', $txt['ban_partial_ban'], '</label><br />
-					<input type="checkbox" name="cannot_post" id="cannot_post" value="1"', $context['ban']['cannot']['post'] ? ' checked="checked"' : '', ' class="ban_restriction input_radio" /> <label for="cannot_post">', $txt['ban_cannot_post'], '</label> (<a href="', $scripturl, '?action=helpadmin;help=ban_cannot_post" onclick="return reqOverlayDiv(this.href);">?</a>)<br />
-					<input type="checkbox" name="cannot_register" id="cannot_register" value="1"', $context['ban']['cannot']['register'] ? ' checked="checked"' : '', ' class="ban_restriction input_radio" /> <label for="cannot_register">', $txt['ban_cannot_register'], '</label><br />
-					<input type="checkbox" name="cannot_login" id="cannot_login" value="1"', $context['ban']['cannot']['login'] ? ' checked="checked"' : '', ' class="ban_restriction input_radio" /> <label for="cannot_login">', $txt['ban_cannot_login'], '</label><br />
-				</fieldset>
-				<br class="clear_right" />';
-
-	if (!empty($context['ban_suggestions']))
-	{
-		echo '
-				<fieldset>
-					<legend>
-						', $txt['ban_triggers'], '
-					</legend>
+				<form action="', $scripturl, '?action=admin;area=ban;sa=edit', isset($context['ban']['id']) ? ';bg=' . $context['ban']['id'] : '', '" method="post" accept-charset="', $context['character_set'], '" onsubmit="if (this.ban_name.value == \'\') {alert(\'', $txt['ban_name_empty'], '\'); return false;} if (this.partial_ban.checked &amp;&amp; !(this.cannot_post.checked || this.cannot_register.checked || this.cannot_login.checked)) {alert(\'', $txt['ban_restriction_empty'], '\'); return false;}">
 					<dl class="settings">
 						<dt id="ban_name_label">
 							<strong>', $txt['ban_name'], ':</strong>
@@ -107,7 +59,7 @@ function template_ban_edit()
 							', $txt['ban_expiration'], '
 						</legend>
 						<input type="radio" name="expiration" value="never" id="never_expires" onclick="fUpdateStatus();"', $context['ban']['expiration']['status'] == 'never' ? ' checked="checked"' : '', ' class="input_radio" /> <label for="never_expires">', $txt['never'], '</label><br />
-						<input type="radio" name="expiration" value="one_day" id="expires_one_day" onclick="fUpdateStatus();"', $context['ban']['expiration']['status'] == 'still_active_but_we_re_counting_the_days' ? ' checked="checked"' : '', ' class="input_radio" /> <label for="expires_one_day">', $txt['ban_will_expire_within'], '</label>: <input type="text" name="expire_date" id="expire_date" size="3" value="', $context['ban']['expiration']['days'], '" class="input_text" /> ', $txt['ban_days'], '<br />
+						<input type="radio" name="expiration" value="one_day" id="expires_one_day" onclick="fUpdateStatus();"', $context['ban']['expiration']['status'] == 'one_day' ? ' checked="checked"' : '', ' class="input_radio" /> <label for="expires_one_day">', $txt['ban_will_expire_within'], '</label>: <input type="text" name="expire_date" id="expire_date" size="3" value="', $context['ban']['expiration']['days'], '" class="input_text" /> ', $txt['ban_days'], '<br />
 						<input type="radio" name="expiration" value="expired" id="already_expired" onclick="fUpdateStatus();"', $context['ban']['expiration']['status'] == 'expired' ? ' checked="checked"' : '', ' class="input_radio" /> <label for="already_expired">', $txt['ban_expired'], '</label>
 					</fieldset>
 					<fieldset class="ban_settings floatright">

+ 2 - 2
Themes/default/Wireless.template.php

@@ -808,7 +808,7 @@ function template_imode_ban_edit()
 			<tr><td>
 				<strong>', $txt['ban_expiration'], ': </strong><br />
 				<input type="radio" name="expiration" value="never" ', $context['ban']['expiration']['status'] == 'never' ? ' checked="checked"' : '', ' class="input_radio" /> ', $txt['never'], '<br />
-				<input type="radio" name="expiration" value="one_day" ', $context['ban']['expiration']['status'] == 'still_active_but_we_re_counting_the_days' ? ' checked="checked"' : '', ' class="input_radio" /> ', $txt['ban_will_expire_within'], ' <input type="text" name="expire_date" size="3" value="', $context['ban']['expiration']['days'], '" /> ', $txt['ban_days'], '<br />
+				<input type="radio" name="expiration" value="one_day" ', $context['ban']['expiration']['status'] == 'one_day' ? ' checked="checked"' : '', ' class="input_radio" /> ', $txt['ban_will_expire_within'], ' <input type="text" name="expire_date" size="3" value="', $context['ban']['expiration']['days'], '" /> ', $txt['ban_days'], '<br />
 				<input type="radio" name="expiration" value="expired" ', $context['ban']['expiration']['status'] == 'expired' ? ' checked="checked"' : '', ' class="input_radio" /> ', $txt['ban_expired'], '<br />
 			</td></tr>
 			<tr><td>
@@ -1440,7 +1440,7 @@ function template_wap2_ban_edit()
 		<p class="windowbg">
 			<strong>', $txt['ban_expiration'], ': </strong><br />
 			<input type="radio" name="expiration" value="never" ', $context['ban']['expiration']['status'] == 'never' ? ' checked="checked"' : '', ' class="input_radio" /> ', $txt['never'], '<br />
-			<input type="radio" name="expiration" value="one_day" ', $context['ban']['expiration']['status'] == 'still_active_but_we_re_counting_the_days' ? ' checked="checked"' : '', ' class="input_radio" /> ', $txt['ban_will_expire_within'], ' <input type="text" name="expire_date" size="3" value="', $context['ban']['expiration']['days'], '" /> ', $txt['ban_days'], '<br />
+			<input type="radio" name="expiration" value="one_day" ', $context['ban']['expiration']['status'] == 'one_day' ? ' checked="checked"' : '', ' class="input_radio" /> ', $txt['ban_will_expire_within'], ' <input type="text" name="expire_date" size="3" value="', $context['ban']['expiration']['days'], '" /> ', $txt['ban_days'], '<br />
 			<input type="radio" name="expiration" value="expired" ', $context['ban']['expiration']['status'] == 'expired' ? ' checked="checked"' : '', ' class="input_radio" /> ', $txt['ban_expired'], '<br />
 		</p>
 		<p class="windowbg">