Kaynağa Gözat

+ Allow admins to delete a user's poll votes when deleting their account (fixes #1185)

Signed-off-by: Michael Eshom <[email protected]>
Michael Eshom 10 yıl önce
ebeveyn
işleme
ca9f7eab72

+ 44 - 0
Sources/Profile-Actions.php

@@ -590,6 +590,50 @@ function deleteAccount2($memID)
 	{
 		isAllowedTo('profile_remove_any');
 
+		// Before we go any further, handle possible poll vote deletion as well
+		if (!empty($_POST['deleteVotes']) && allowedTo('moderate_forum'))
+		{
+			// First we find any polls that this user has voted in...
+			$get_voted_polls = $smcFunc['db_query']('', '
+				SELECT DISTINCT id_poll
+				FROM {db_prefix}log_polls
+				WHERE id_member = {int:selected_member}',
+				array(
+					'selected_member' => $memID,
+				)
+			);
+
+			$polls_to_update = array();
+			
+			while ($row = $smcFunc['db_fetch_assoc']($get_voted_polls))
+			{
+				$polls_to_update[] = $row['id_poll'];
+			}
+
+			$smcFunc['db_free_result']($get_voted_polls);
+
+			// Now we delete the votes and update the polls
+			if (!empty($polls_to_update))
+			{
+				$smcFunc['db_query']('', '
+					DELETE FROM {db_prefix}log_polls
+					WHERE id_member = {int:selected_member}',
+					array(
+						'selected_member' => $memID,
+					)
+				);
+
+				$smcFunc['db_query']('', '
+					UPDATE {db_prefix}polls
+					SET votes = votes - 1
+					WHERE id_poll IN {array_int:polls_to_update}',
+					array(
+						'polls_to_update' => $polls_to_update
+					)
+				);
+			}
+		}
+
 		// Now, have you been naughty and need your posts deleting?
 		// @todo Should this check board permissions?
 		if (!empty($_POST['deletePosts']) && in_array($_POST['remove_type'], array('posts', 'topics')) && allowedTo('moderate_forum'))

+ 1 - 0
Themes/default/Profile.template.php

@@ -2702,6 +2702,7 @@ function template_deleteAccount()
 		if ($context['can_delete_posts'])
 			echo '
 					<div>
+						<label for="deleteVotes"><input type="checkbox" name="deleteVotes" id="deleteVotes" value="1" class="input_check"> ', $txt['deleteAccount_votes'], ':</label><br>
 						<label for="deletePosts"><input type="checkbox" name="deletePosts" id="deletePosts" value="1" class="input_check"> ', $txt['deleteAccount_posts'], ':</label>
 						<select name="remove_type">
 							<option value="posts">', $txt['deleteAccount_all_posts'], '</option>

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

@@ -187,6 +187,7 @@ $txt['deleteAccount_member'] = 'Delete this member\'s account';
 $txt['deleteAccount_posts'] = 'Remove posts made by this member';
 $txt['deleteAccount_all_posts'] = 'Replies to Topics';
 $txt['deleteAccount_topics'] = 'Topics and Posts';
+$txt['deleteAccount_votes'] = 'Remove poll votes made by this member';
 $txt['deleteAccount_confirm'] = 'Are you completely sure you want to delete this account?';
 $txt['deleteAccount_approval'] = 'Please note that the forum moderators will have to approve this account\'s deletion before it will be removed.';