浏览代码

Merge pull request #1367 from Oldiesmann/release-2.1

+ Allow admins to delete a user's poll votes when deleting their account...
Michael Eshom 10 年之前
父节点
当前提交
3f2dbe737d
共有 3 个文件被更改,包括 46 次插入0 次删除
  1. 44 0
      Sources/Profile-Actions.php
  2. 1 0
      Themes/default/Profile.template.php
  3. 1 0
      Themes/default/languages/Profile.english.php

+ 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

@@ -2670,6 +2670,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

@@ -188,6 +188,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.';