Pārlūkot izejas kodu

! Let's actually save our alert preferences.

Signed-off-by: Peter Spicer <[email protected]>
Peter Spicer 11 gadi atpakaļ
vecāks
revīzija
fcf00e51c8

+ 58 - 4
Sources/Profile-Modify.php

@@ -1847,6 +1847,9 @@ function alert_configuration($memID)
 	global $txt, $scripturl, $user_profile, $user_info, $context, $modSettings, $smcFunc, $sourcedir, $settings;
 
 	$context['token_check'] = 'profile-nt' . $memID;
+	is_not_guest();
+	if (!$context['user']['is_owner'])
+		isAllowedTo('profile_extra_any');
 
 	// What options are set?
 	$context['member'] += array(
@@ -1874,6 +1877,8 @@ function alert_configuration($memID)
 	// Valid values for these keys are 'always', 'yes', 'never'; if using always or never you should add a help string.
 	$alert_types = array(
 		'msg' => array(
+			'topic_notify' => array('alert' => 'yes', 'email' => 'yes'),
+			'board_notify' => array('alert' => 'yes', 'email' => 'yes'),
 			'msg_mention' => array('alert' => 'yes', 'email' => 'yes'),
 			'msg_quote' => array('alert' => 'yes', 'email' => 'yes'),
 			'msg_like' => array('alert' => 'yes', 'email' => 'never'),
@@ -1974,14 +1979,63 @@ function alert_configuration($memID)
 	$context['alert_group_options'] = $group_options;
 	$context['disabled_alerts'] = $disabled_options;
 
-	if (isset($_POST['saving or something']))
+	$context['alert_bits'] = array(
+		'alert' => 0x01,
+		'email' => 0x02,
+	);
+
+	if (isset($_POST['notify_submit']))
 	{
-		is_not_guest();
-		if (!$context['member']['is_owner'])
-			isAllowedTo('profile_extra_any');
 		checkSession('post');
 		validateToken($context['token_check'], 'post');
 
+		// We need to step through the list of valid settings and figure out what the user has set.
+		$update_prefs = array();
+
+		// Now the group level options
+		foreach ($context['alert_group_options'] as $opt_group => $group)
+		{
+			foreach ($group as $this_option)
+			{
+				switch ($this_option[0])
+				{
+					case 'check':
+						$update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0;
+						break;
+					case 'select':
+						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]]))
+							$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
+						else
+						{
+							// We didn't have a sane value. Let's grab the first item from the possibles.
+							$keys = array_keys($this_option['opts']);
+							$first = array_shift($keys);
+							$update_prefs[$this_option[1]] = $first;
+						}
+						break;
+				}
+			}
+		}
+
+		// Now the individual options
+		foreach ($context['alert_types'] as $alert_group => $items)
+		{
+			foreach ($items as $item_key => $this_options)
+			{
+				$this_value = 0;
+				foreach ($context['alert_bits'] as $type => $bitvalue)
+				{
+					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]))
+						$this_value |= $bitvalue;
+				}
+				$update_prefs[$item_key] = $this_value;
+			}
+		}
+
+		setNotifyPrefs($memID, $update_prefs);
+		foreach ($update_prefs as $pref => $value)
+			$context['alert_prefs'][$pref] = $value;
+
 		makeNotificationChanges($memID);
 		$context['profile_updated'] = $txt['profile_updated_own'];
 	}

+ 25 - 0
Sources/Subs-Notify.php

@@ -57,4 +57,29 @@ function getNotifyPrefs($members, $prefs = '')
 	return $result;
 }
 
+/**
+ * Sets the list of preferences for a single user.
+ *
+ * @param int $memID The user whose preferences you are setting
+ * @param array $prefs An array key of pref -> value
+ */
+function setNotifyPrefs($memID, $prefs = array())
+{
+	global $smcFunc;
+
+	if (empty($prefs) || empty($memID))
+		return;
+
+	$update_rows = array();
+	foreach ($prefs as $k => $v)
+		$update_rows[] = array($memID, $k, $v);
+
+	$smcFunc['db_insert']('replace',
+		'{db_prefix}user_alerts_prefs',
+		array('id_member' => 'int', 'alert_pref' => 'string', 'alert_value' => 'int'),
+		$update_rows,
+		array('id_member', 'alert_pref')
+	);
+}
+
 ?>

+ 2 - 9
Themes/default/Profile.template.php

@@ -1848,13 +1848,6 @@ function template_alert_configuration()
 				</tr>';
 	$use_bg2 = true;
 
-	// Before we get into the loop, just quickly set this up.
-	// We store these prefs, generally, as a bitwise thing to save some space.
-	$alert_bits = array(
-		'alert' => 0x01,
-		'email' => 0x02,
-	);
-
 	foreach ($context['alert_types'] as $alert_group => $alerts)
 	{
 		echo '
@@ -1922,7 +1915,7 @@ function template_alert_configuration()
 						break;
 					case 'yes':
 						echo '
-						<input type="checkbox" name="', $type, '_', $alert_id, '"', $this_value & $alert_bits[$type] != 0 ? ' checked="checked"' : '', ' />';
+						<input type="checkbox" name="', $type, '_', $alert_id, '"', $this_value & $context['alert_bits'][$type] != 0 ? ' checked="checked"' : '', ' />';
 						break;
 					case 'never':
 						echo '
@@ -1944,7 +1937,7 @@ function template_alert_configuration()
 			</table>
 			<br />
 			<div>
-				<input id="notify_submit" type="submit" value="', $txt['notify_save'], '" class="button_submit" />
+				<input id="notify_submit" type="submit" name="notify_submit" value="', $txt['notify_save'], '" class="button_submit" />
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />', !empty($context['token_check']) ? '
 				<input type="hidden" name="' . $context[$context['token_check'] . '_token_var'] . '" value="' . $context[$context['token_check'] . '_token'] . '" />' : '', '
 				<input type="hidden" name="u" value="', $context['id_member'], '" />

+ 2 - 0
Themes/default/languages/Profile.english.php

@@ -132,6 +132,8 @@ $txt['alert_opt_msg_notify_pref_instant'] = 'Straight away';
 $txt['alert_opt_msg_notify_pref_first'] = 'Straight away (but only for the first unread message)';
 $txt['alert_opt_msg_notify_pref_daily'] = 'Send me a daily email digest';
 $txt['alert_opt_msg_notify_pref_weekly'] = 'Send me a weekly email digest';
+$txt['alert_topic_notify'] = 'When a topic I follow gets a reply, I normally want to know via...';
+$txt['alert_board_notify'] = 'When a board I follow gets a topic, I normally want to know via...';
 $txt['alert_msg_mention'] = 'When my @name is mentioned in a message';
 $txt['alert_msg_quote'] = 'When a message of mine is quoted (when I\'m not already watching that topic)';
 $txt['alert_msg_like'] = 'When a message of mine is liked';