aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorMeik Sievertsen <acydburn@phpbb.com>2006-05-19 21:08:48 +0000
committerMeik Sievertsen <acydburn@phpbb.com>2006-05-19 21:08:48 +0000
commit8e800e333ceae99945cb818709a4aba4de3362b0 (patch)
tree48eb98a09be564dd57b2df95753a56a0f2d5319f /phpBB/includes
parentc0e3a86ebb9297f15681de6107acaef58eb41ccb (diff)
downloadforums-8e800e333ceae99945cb818709a4aba4de3362b0.tar
forums-8e800e333ceae99945cb818709a4aba4de3362b0.tar.gz
forums-8e800e333ceae99945cb818709a4aba4de3362b0.tar.bz2
forums-8e800e333ceae99945cb818709a4aba4de3362b0.tar.xz
forums-8e800e333ceae99945cb818709a4aba4de3362b0.zip
- fixed dotted topics on some occassions being wrong
- fixed post author change - fixed moving topics (they should not count into read tracking now) - think about having only one column for shadow topics/similar to forum links - moved a function from functions.php to functions_display.php (this function is only used by viewtopic and viewforum which already include this file) - some rather tiny fixes for mssql git-svn-id: file:///svn/phpbb/trunk@5933 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/functions.php109
-rw-r--r--phpBB/includes/functions_admin.php155
-rw-r--r--phpBB/includes/functions_display.php109
-rw-r--r--phpBB/includes/mcp/mcp_main.php4
-rwxr-xr-xphpBB/includes/mcp/mcp_notes.php2
-rw-r--r--phpBB/includes/mcp/mcp_post.php151
6 files changed, 332 insertions, 198 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index dc435b4814..70e8cb7c6c 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -425,115 +425,6 @@ function tz_select($default = '')
// Functions handling topic/post tracking/marking
/**
-* Topic and forum watching common code
-*/
-function watch_topic_forum($mode, &$s_watching, &$s_watching_img, $user_id, $forum_id, $topic_id, $notify_status = 'unset', $start = 0)
-{
- global $template, $db, $user, $phpEx, $SID, $start, $phpbb_root_path;
-
- $table_sql = ($mode == 'forum') ? FORUMS_WATCH_TABLE : TOPICS_WATCH_TABLE;
- $where_sql = ($mode == 'forum') ? 'forum_id' : 'topic_id';
- $match_id = ($mode == 'forum') ? $forum_id : $topic_id;
-
- $u_url = ($mode == 'forum') ? 'f' : 'f=' . $forum_id . '&amp;t';
-
- // Is user watching this thread?
- if ($user_id != ANONYMOUS)
- {
- $can_watch = true;
-
- if ($notify_status == 'unset')
- {
- $sql = "SELECT notify_status
- FROM $table_sql
- WHERE $where_sql = $match_id
- AND user_id = $user_id";
- $result = $db->sql_query($sql);
-
- $notify_status = ($row = $db->sql_fetchrow($result)) ? $row['notify_status'] : NULL;
- $db->sql_freeresult($result);
- }
-
- if (!is_null($notify_status))
- {
- if (isset($_GET['unwatch']))
- {
- if ($_GET['unwatch'] == $mode)
- {
- $is_watching = 0;
-
- $sql = 'DELETE FROM ' . $table_sql . "
- WHERE $where_sql = $match_id
- AND user_id = $user_id";
- $db->sql_query($sql);
- }
-
- meta_refresh(3, "view$mode.$phpEx$SID&amp;$u_url=$match_id&amp;start=$start");
-
- $message = $user->lang['NOT_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . "view$mode.$phpEx$SID&amp;" . $u_url . "=$match_id&amp;start=$start" . '">', '</a>');
- trigger_error($message);
- }
- else
- {
- $is_watching = true;
-
- if ($notify_status)
- {
- $sql = 'UPDATE ' . $table_sql . "
- SET notify_status = 0
- WHERE $where_sql = $match_id
- AND user_id = $user_id";
- $db->sql_query($sql);
- }
- }
- }
- else
- {
- if (isset($_GET['watch']))
- {
- if ($_GET['watch'] == $mode)
- {
- $is_watching = true;
-
- $sql = 'INSERT INTO ' . $table_sql . " (user_id, $where_sql, notify_status)
- VALUES ($user_id, $match_id, 0)";
- $db->sql_query($sql);
- }
-
- meta_refresh(3, "view$mode.$phpEx$SID&amp;$u_url=$match_id&amp;start=$start");
-
- $message = $user->lang['ARE_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . "view$mode.$phpEx$SID&amp;" . $u_url . "=$match_id&amp;start=$start" . '">', '</a>');
- trigger_error($message);
- }
- else
- {
- $is_watching = 0;
- }
- }
- }
- else
- {
- if (isset($_GET['unwatch']) && $_GET['unwatch'] == $mode)
- {
- login_box();
- }
- else
- {
- $can_watch = 0;
- $is_watching = 0;
- }
- }
-
- if ($can_watch)
- {
- $s_watching['link'] = "{$phpbb_root_path}view$mode.$phpEx$SID&amp;$u_url=$match_id&amp;" . (($is_watching) ? 'unwatch' : 'watch') . "=$mode&amp;start=$start";
- $s_watching['title'] = $user->lang[(($is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)];
- }
-
- return;
-}
-
-/**
* Marks a topic/forum as read
* Marks a topic as posted to
*
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php
index 5751e39290..9010599d0b 100644
--- a/phpBB/includes/functions_admin.php
+++ b/phpBB/includes/functions_admin.php
@@ -367,12 +367,21 @@ function move_topics($topic_ids, $forum_id, $auto_sync = true)
{
global $db;
+ if (empty($topic_ids))
+ {
+ return;
+ }
+
$forum_ids = array($forum_id);
- $sql_where = (is_array($topic_ids)) ? 'IN (' . implode(', ', $topic_ids) . ')' : '= ' . $topic_ids;
+
+ if (!is_array($topic_ids))
+ {
+ $topic_ids = array($topic_ids);
+ }
- $sql = 'DELETE FROM ' . TOPICS_TABLE . "
- WHERE topic_moved_id $sql_where
- AND forum_id = " . $forum_id;
+ $sql = 'DELETE FROM ' . TOPICS_TABLE . '
+ WHERE topic_moved_id IN (' . implode(', ', $topic_ids) . ')
+ AND forum_id = ' . $forum_id;
$db->sql_query($sql);
if ($auto_sync)
@@ -388,13 +397,16 @@ function move_topics($topic_ids, $forum_id, $auto_sync = true)
}
$db->sql_freeresult($result);
}
-
- $table_ary = array(TOPICS_TABLE, POSTS_TABLE, LOG_TABLE);
+
+ /**
+ * @todo watch for undesired results on marked topics for moving topics, maybe handle it seperatly to cover cookie tracking
+ */
+ $table_ary = array(TOPICS_TABLE, POSTS_TABLE, LOG_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE);
foreach ($table_ary as $table)
{
$sql = "UPDATE $table
SET forum_id = $forum_id
- WHERE topic_id " . $sql_where;
+ WHERE topic_id IN (" . implode(', ', $topic_ids) . ')';
$db->sql_query($sql);
}
unset($table_ary);
@@ -418,54 +430,54 @@ function move_posts($post_ids, $topic_id, $auto_sync = true)
$post_ids = array($post_ids);
}
- if ($auto_sync)
- {
- $forum_ids = array();
- $topic_ids = array($topic_id);
+ $forum_ids = array();
+ $topic_ids = array($topic_id);
- $sql = 'SELECT DISTINCT topic_id, forum_id
- FROM ' . POSTS_TABLE . '
- WHERE post_id IN (' . implode(', ', $post_ids) . ')';
- $result = $db->sql_query($sql);
+ $sql = 'SELECT DISTINCT topic_id, forum_id
+ FROM ' . POSTS_TABLE . '
+ WHERE post_id IN (' . implode(', ', $post_ids) . ')';
+ $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result))
- {
- $forum_ids[] = $row['forum_id'];
- $topic_ids[] = $row['topic_id'];
- }
- $db->sql_freeresult($result);
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $forum_ids[] = $row['forum_id'];
+ $topic_ids[] = $row['topic_id'];
}
+ $db->sql_freeresult($result);
$sql = 'SELECT forum_id
FROM ' . TOPICS_TABLE . '
WHERE topic_id = ' . $topic_id;
$result = $db->sql_query($sql);
+ $forum_row = $db->sql_fetchrow($result);
+ $db->sql_freeresult($result);
- if (!$row = $db->sql_fetchrow($result))
+ if (!$forum_row)
{
trigger_error('NO_TOPIC');
}
- $db->sql_freeresult($result);
$sql = 'UPDATE ' . POSTS_TABLE . '
- SET forum_id = ' . $row['forum_id'] . ", topic_id = $topic_id
+ SET forum_id = ' . $forum_row['forum_id'] . ", topic_id = $topic_id
WHERE post_id IN (" . implode(', ', $post_ids) . ')';
$db->sql_query($sql);
$sql = 'UPDATE ' . ATTACHMENTS_TABLE . "
- SET topic_id = $topic_id
- AND in_message = 0
+ SET topic_id = $topic_id, in_message = 0
WHERE post_msg_id IN (" . implode(', ', $post_ids) . ')';
$db->sql_query($sql);
if ($auto_sync)
{
- $forum_ids[] = $row['forum_id'];
+ $forum_ids[] = $forum_row['forum_id'];
sync('topic_reported', 'topic_id', $topic_ids);
sync('topic', 'topic_id', $topic_ids, true);
sync('forum', 'forum_id', $forum_ids, true);
}
+
+ // Update posted informations
+ update_posted_info($topic_ids);
}
/**
@@ -865,6 +877,76 @@ function delete_topic_shadows($max_age, $forum_id = '', $auto_sync = true)
}
/**
+* Update/Sync posted informations for topics
+*/
+function update_posted_info($topic_ids)
+{
+ global $db;
+
+ if (empty($topic_ids))
+ {
+ return;
+ }
+
+ // First of all, let us remove any posted information for these topics
+ $sql = 'DELETE FROM ' . TOPICS_POSTED_TABLE . '
+ WHERE topic_id IN (' . implode(', ', $topic_ids) . ')';
+ $db->sql_query($sql);
+
+ // Now, let us collect the user/topic combos for rebuilding the information
+ $sql = 'SELECT topic_id, poster_id
+ FROM ' . POSTS_TABLE . '
+ WHERE topic_id IN (' . implode(', ', $topic_ids) . ')';
+ $result = $db->sql_query($sql);
+
+ $posted = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ if (empty($posted[$row['topic_id']]))
+ {
+ $posted[$row['topic_id']] = array();
+ }
+
+ // Add as key to make them unique (grouping by) and circumvent empty keys on array_unique
+ $posted[$row['topic_id']][$row['poster_id']] = 1;
+ }
+ $db->sql_freeresult($result);
+
+ // Now add the information...
+ $sql_ary = array();
+ foreach ($posted as $topic_id => $poster_row)
+ {
+ foreach ($poster_row as $user_id => $null)
+ {
+ $sql_ary[] = array(
+ 'user_id' => $user_id,
+ 'topic_id' => $topic_id,
+ 'topic_posted' => 1,
+ );
+ }
+ }
+
+ if (sizeof($sql_ary))
+ {
+ switch (SQL_LAYER)
+ {
+ case 'mysql':
+ case 'mysql4':
+ case 'mysqli':
+ $db->sql_query('INSERT INTO ' . TOPICS_POSTED_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $sql_ary));
+ break;
+
+ default:
+ foreach ($sql_ary as $ary)
+ {
+ $db->sql_query('INSERT INTO ' . TOPICS_POSTED_TABLE . ' ' . $db->sql_build_array('INSERT', $ary));
+ }
+ break;
+ }
+ }
+}
+
+/**
* Delete File
*/
function phpbb_unlink($filename, $mode = 'file')
@@ -1365,8 +1447,19 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
// NOTE: 't.post_approved' in the GROUP BY is causing a major slowdown.
$sql = 'SELECT t.topic_id, t.post_approved, COUNT(t.post_id) AS total_posts, MIN(t.post_id) AS first_post_id, MAX(t.post_id) AS last_post_id
FROM ' . POSTS_TABLE . " t
- $where_sql
- GROUP BY t.topic_id"; //, t.post_approved";
+ $where_sql";
+
+ switch (SQL_LAYER)
+ {
+ case 'mssql':
+ case 'mssql-odbc':
+ $sql .= 'GROUP BY t.topic_id, t.post_approved';
+ break;
+
+ default:
+ $sql .= 'GROUP BY t.topic_id';
+ break;
+ }
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
@@ -1485,7 +1578,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p
$where_sql_and p.topic_id = t.topic_id
AND p.post_reported = 1
- GROUP BY t.topic_id";
+ GROUP BY t.topic_id, p.post_id";
$result = $db->sql_query($sql);
$fieldnames[] = 'reported';
@@ -1501,7 +1594,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p
$where_sql_and p.topic_id = t.topic_id
AND p.post_attachment = 1
- GROUP BY t.topic_id";
+ GROUP BY t.topic_id, p.post_id";
$result = $db->sql_query($sql);
$fieldnames[] = 'attachment';
diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php
index 43b0caf794..e99e387b12 100644
--- a/phpBB/includes/functions_display.php
+++ b/phpBB/includes/functions_display.php
@@ -1075,4 +1075,113 @@ function display_user_activity(&$userdata)
);
}
+/**
+* Topic and forum watching common code
+*/
+function watch_topic_forum($mode, &$s_watching, &$s_watching_img, $user_id, $forum_id, $topic_id, $notify_status = 'unset', $start = 0)
+{
+ global $template, $db, $user, $phpEx, $SID, $start, $phpbb_root_path;
+
+ $table_sql = ($mode == 'forum') ? FORUMS_WATCH_TABLE : TOPICS_WATCH_TABLE;
+ $where_sql = ($mode == 'forum') ? 'forum_id' : 'topic_id';
+ $match_id = ($mode == 'forum') ? $forum_id : $topic_id;
+
+ $u_url = ($mode == 'forum') ? 'f' : 'f=' . $forum_id . '&amp;t';
+
+ // Is user watching this thread?
+ if ($user_id != ANONYMOUS)
+ {
+ $can_watch = true;
+
+ if ($notify_status == 'unset')
+ {
+ $sql = "SELECT notify_status
+ FROM $table_sql
+ WHERE $where_sql = $match_id
+ AND user_id = $user_id";
+ $result = $db->sql_query($sql);
+
+ $notify_status = ($row = $db->sql_fetchrow($result)) ? $row['notify_status'] : NULL;
+ $db->sql_freeresult($result);
+ }
+
+ if (!is_null($notify_status))
+ {
+ if (isset($_GET['unwatch']))
+ {
+ if ($_GET['unwatch'] == $mode)
+ {
+ $is_watching = 0;
+
+ $sql = 'DELETE FROM ' . $table_sql . "
+ WHERE $where_sql = $match_id
+ AND user_id = $user_id";
+ $db->sql_query($sql);
+ }
+
+ meta_refresh(3, "view$mode.$phpEx$SID&amp;$u_url=$match_id&amp;start=$start");
+
+ $message = $user->lang['NOT_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . "view$mode.$phpEx$SID&amp;" . $u_url . "=$match_id&amp;start=$start" . '">', '</a>');
+ trigger_error($message);
+ }
+ else
+ {
+ $is_watching = true;
+
+ if ($notify_status)
+ {
+ $sql = 'UPDATE ' . $table_sql . "
+ SET notify_status = 0
+ WHERE $where_sql = $match_id
+ AND user_id = $user_id";
+ $db->sql_query($sql);
+ }
+ }
+ }
+ else
+ {
+ if (isset($_GET['watch']))
+ {
+ if ($_GET['watch'] == $mode)
+ {
+ $is_watching = true;
+
+ $sql = 'INSERT INTO ' . $table_sql . " (user_id, $where_sql, notify_status)
+ VALUES ($user_id, $match_id, 0)";
+ $db->sql_query($sql);
+ }
+
+ meta_refresh(3, "view$mode.$phpEx$SID&amp;$u_url=$match_id&amp;start=$start");
+
+ $message = $user->lang['ARE_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . "view$mode.$phpEx$SID&amp;" . $u_url . "=$match_id&amp;start=$start" . '">', '</a>');
+ trigger_error($message);
+ }
+ else
+ {
+ $is_watching = 0;
+ }
+ }
+ }
+ else
+ {
+ if (isset($_GET['unwatch']) && $_GET['unwatch'] == $mode)
+ {
+ login_box();
+ }
+ else
+ {
+ $can_watch = 0;
+ $is_watching = 0;
+ }
+ }
+
+ if ($can_watch)
+ {
+ $s_watching['link'] = "{$phpbb_root_path}view$mode.$phpEx$SID&amp;$u_url=$match_id&amp;" . (($is_watching) ? 'unwatch' : 'watch') . "=$mode&amp;start=$start";
+ $s_watching['title'] = $user->lang[(($is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)];
+ }
+
+ return;
+}
+
?> \ No newline at end of file
diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php
index dc4df52f50..918b368949 100644
--- a/phpBB/includes/mcp/mcp_main.php
+++ b/phpBB/includes/mcp/mcp_main.php
@@ -469,10 +469,6 @@ function mcp_move_topic($topic_ids)
);
$db->sql_query('INSERT INTO ' . TOPICS_TABLE . $db->sql_build_array('INSERT', $shadow));
-
- // $next_id = $db->sql_nextid();
- // Mark Shadow topic read
- // markread('topic', $row['forum_id'], $next_id);
}
}
unset($topic_data);
diff --git a/phpBB/includes/mcp/mcp_notes.php b/phpBB/includes/mcp/mcp_notes.php
index 0bc6a28f3f..44265d2475 100755
--- a/phpBB/includes/mcp/mcp_notes.php
+++ b/phpBB/includes/mcp/mcp_notes.php
@@ -49,7 +49,7 @@ class mcp_notes
case 'user_notes':
$user->add_lang('acp/common');
-
+
mcp_notes_user_view($id, $mode, $action);
$this->tpl_name = 'mcp_notes_user';
break;
diff --git a/phpBB/includes/mcp/mcp_post.php b/phpBB/includes/mcp/mcp_post.php
index 8bacc21f97..d226a0b545 100644
--- a/phpBB/includes/mcp/mcp_post.php
+++ b/phpBB/includes/mcp/mcp_post.php
@@ -35,6 +35,7 @@ function mcp_post_details($id, $mode, $action)
switch ($action)
{
case 'whois':
+
$ip = request_var('ip', '');
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
@@ -47,48 +48,37 @@ function mcp_post_details($id, $mode, $action)
'RETURN_POST' => sprintf($user->lang['RETURN_POST'], "<a href=\"{$phpbb_root_path}mcp.$phpEx$SID&amp;i=$id&amp;mode=$mode&amp;p=$post_id\">", '</a>'),
'WHOIS' => trim($whois))
);
- // We're done with the whois page so return
- return;
-
- case 'chgposter':
- $username = request_var('username', '', true);
-
- $sql = 'SELECT user_id
- FROM ' . USERS_TABLE . '
- WHERE username = \'' . $db->sql_escape($username) . '\'';
- $result = $db->sql_query($sql);
+ // We're done with the whois page so return
+ return;
- if (!($row = $db->sql_fetchrow($result)))
- {
- trigger_error($user->lang['NO_USER']);
- }
- $new_user = $row['user_id'];
-
- if ($auth->acl_get('m_', $post_info['forum_id']))
- {
- change_poster($post_info, $new_user);
- }
break;
+ case 'chgposter':
case 'chgposter_ip':
- $new_user = request_var('u', 0);
+ $username = request_var('username', '', true);
+ $new_user_id = request_var('u', 0);
+
+ $sql_where = ($new_user_id) ? 'user_id = ' . $new_user_id : "username = '" . $db->sql_escape($username) . "'";
- $sql = 'SELECT user_id
- FROM ' . USERS_TABLE . '
- WHERE user_id = ' . $new_user;
+ $sql = 'SELECT *
+ FROM ' . USERS_TABLE . '
+ WHERE ' . $sql_where;
$result = $db->sql_query($sql);
+ $row = $db->sql_fetchrow($result);
+ $db->sql_freeresult($result);
- if (!($row = $db->sql_fetchrow($result)))
+ if (!$row)
{
trigger_error($user->lang['NO_USER']);
}
if ($auth->acl_get('m_', $post_info['forum_id']))
{
- change_poster($post_info, $new_user);
+ change_poster($post_info, $row);
}
+
break;
}
@@ -101,11 +91,12 @@ function mcp_post_details($id, $mode, $action)
$message = $post_info['post_text'];
if ($post_info['bbcode_bitfield'])
{
- include_once($phpbb_root_path . 'includes/bbcode.'.$phpEx);
+ include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
$bbcode = new bbcode($post_info['bbcode_bitfield']);
$bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
}
$message = smiley_text($message);
+ $message = str_replace("\n", '<br />', $message);
$template->assign_vars(array(
'U_MCP_ACTION' => "$url&amp;i=main&amp;quickmod=1", // Use this for mode paramaters
@@ -117,15 +108,15 @@ function mcp_post_details($id, $mode, $action)
'S_CAN_LOCK_POST' => $auth->acl_get('m_lock', $post_info['forum_id']),
'S_CAN_DELETE_POST' => $auth->acl_get('m_delete', $post_info['forum_id']),
- 'S_POST_REPORTED' => $post_info['post_reported'],
- 'S_POST_UNAPPROVED' => !$post_info['post_approved'],
- 'S_POST_LOCKED' => $post_info['post_edit_locked'],
- 'S_USER_NOTES' => $auth->acl_gets('m_', 'a_') ? true : false,
+ 'S_POST_REPORTED' => ($post_info['post_reported']) ? true : false,
+ 'S_POST_UNAPPROVED' => (!$post_info['post_approved']) ? true : false,
+ 'S_POST_LOCKED' => ($post_info['post_edit_locked']) ? true : false,
+ 'S_USER_NOTES' => ($auth->acl_gets('m_', 'a_')) ? true : false,
'S_CLEAR_ALLOWED' => ($auth->acl_get('a_clearlogs')) ? true : false,
'U_FIND_MEMBER' => "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=searchuser&amp;form=mcp_chgposter&amp;field=username",
'U_VIEW_PROFILE' => "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=viewprofile&amp;u=" . $post_info['user_id'],
- 'U_MCP_USER_NOTES' => $auth->acl_gets('m_', 'a_') ? "{$phpbb_root_path}mcp.$phpEx$SID&amp;i=notes&amp;mode=user_notes&amp;u=" . $post_info['user_id'] : '',
+ 'U_MCP_USER_NOTES' => ($auth->acl_gets('m_', 'a_')) ? "{$phpbb_root_path}mcp.$phpEx$SID&amp;i=notes&amp;mode=user_notes&amp;u=" . $post_info['user_id'] : '',
'U_MCP_WARN_USER' => "{$phpbb_root_path}mcp.$phpEx$SID&amp;i=warn&amp;mode=warn_user&amp;u=" . $post_info['user_id'],
'U_EDIT' => ($auth->acl_get('m_edit', $post_info['forum_id'])) ? "{$phpbb_root_path}posting.$phpEx$SID&amp;mode=edit&amp;f={$post_info['forum_id']}&amp;p={$post_info['post_id']}" : '',
@@ -226,7 +217,7 @@ function mcp_post_details($id, $mode, $action)
$sql = 'SELECT u.user_id, u.username, COUNT(*) as postings
FROM ' . USERS_TABLE . ' u, ' . POSTS_TABLE . " p
WHERE p.poster_id = u.user_id
- AND p.poster_ip = '{$post_info['poster_ip']}'
+ AND p.poster_ip = '" . $db->sql_escape($post_info['poster_ip']) . "'
AND p.poster_id <> {$post_info['user_id']}
GROUP BY u.user_id, u.username
ORDER BY COUNT(*) DESC";
@@ -236,7 +227,7 @@ function mcp_post_details($id, $mode, $action)
$sql = 'SELECT u.user_id, u.username, COUNT(*) as postings
FROM ' . USERS_TABLE . ' u, ' . POSTS_TABLE . " p
WHERE p.poster_id = u.user_id
- AND p.poster_ip = '{$post_info['poster_ip']}'
+ AND p.poster_ip = '" . $db->sql_escape($post_info['poster_ip']) . "'
AND p.poster_id <> {$post_info['user_id']}
GROUP BY u.user_id, u.username
ORDER BY postings DESC";
@@ -306,6 +297,7 @@ function mcp_post_details($id, $mode, $action)
$user_select = '';
ksort($users_ary);
+
foreach ($users_ary as $row)
{
$user_select .= '<option value="' . $row['user_id'] . '">' . $row['username'] . "</option>\n";
@@ -316,37 +308,90 @@ function mcp_post_details($id, $mode, $action)
}
/**
-* Changes a post's poster_id
+* Change a post's poster
*/
-function change_poster(&$post_info, $new_user)
+function change_poster(&$post_info, $userdata)
{
global $auth, $db;
- if ($new_user && $new_user != $post_info['user_id'])
+ if (empty($userdata) || $userdata['user_id'] == $post_info['user_id'])
{
- $post_id = $post_info['post_id'];
+ return;
+ }
+
+ $post_id = $post_info['post_id'];
- $sql = 'UPDATE ' . POSTS_TABLE . "
- SET poster_id = $new_user
- WHERE post_id = " . $post_id;
+ $sql = 'UPDATE ' . POSTS_TABLE . "
+ SET poster_id = {$userdata['user_id']}
+ WHERE post_id = $post_id";
+ $db->sql_query($sql);
+
+ // Resync topic/forum if needed
+ if ($post_info['topic_last_post_id'] == $post_id || $post_info['forum_last_post_id'] == $post_id)
+ {
+ sync('topic', 'topic_id', $post_info['topic_id'], false, false);
+ sync('forum', 'forum_id', $post_info['forum_id'], false, false);
+ }
+
+ // Adjust post counts
+ $auth_user_from = new auth();
+ $auth_user_from->acl($post_info);
+
+ $auth_user_to = new auth();
+ $auth_user_to->acl($userdata);
+
+ // Decrease post count by one for the old user
+ if ($auth_user_from->acl_get('f_postcount', $post_info['forum_id']))
+ {
+ $sql = 'UPDATE ' . USERS_TABLE . '
+ SET user_posts = user_posts - 1
+ WHERE user_id = ' . $post_info['user_id'];
$db->sql_query($sql);
+ }
- if ($post_info['topic_last_post_id'] == $post_id || $post_info['forum_last_post_id'] == $post_id)
- {
- sync('topic', 'topic_id', $post_info['topic_id'], false, false);
- sync('forum', 'forum_id', $post_info['forum_id'], false, false);
- }
+ // Increase post count by one for the new user
+ if ($auth_user_to->acl_get('f_postcount', $post_info['forum_id']))
+ {
+ $sql = 'UPDATE ' . USERS_TABLE . '
+ SET user_posts = user_posts + 1
+ WHERE user_id = ' . $userdata['user_id'];
+ $db->sql_query($sql);
+ }
- // Renew post info
- $post_info = get_post_data(array($post_id));
+ // Add posted to information for this topic for the new user
+ markread('post', $post_info['forum_id'], $post_info['topic_id'], time(), $userdata['user_id']);
- if (!sizeof($post_info))
- {
- trigger_error($user->lang['POST_NOT_EXIST']);
- }
+ // Remove the dotted topic option if the old user has no more posts within this topic
+ $sql = 'SELECT topic_id
+ FROM ' . POSTS_TABLE . '
+ WHERE topic_id = ' . $post_info['topic_id'] . '
+ AND poster_id = ' . $post_info['user_id'];
+ $result = $db->sql_query_limit($sql, 1);
+ $topic_id = (int) $db->sql_fetchfield('topic_id');
+ $db->sql_freeresult($result);
- $post_info = $post_info[$post_id];
+ if (!$topic_id)
+ {
+ $sql = 'DELETE FROM ' . TOPICS_POSTED_TABLE . '
+ WHERE user_id = ' . $post_info['user_id'] . '
+ AND topic_id = ' . $post_info['topic_id'];
+ $db->sql_query($sql);
+ }
+
+ // Do not change the poster_id within the attachments table, since they were still posted by the original user
+
+ // Renew post info
+ $post_info = get_post_data(array($post_id));
+
+ if (!sizeof($post_info))
+ {
+ trigger_error($user->lang['POST_NOT_EXIST']);
}
+
+ $post_info = $post_info[$post_id];
+
+ // Now add log entry
+ add_log('mod', $post_info['forum_id'], $post_info['topic_id'], 'LOG_MCP_CHANGE_POSTER', $post_info['topic_title'], $post_info['username'], $userdata['username']);
}
?> \ No newline at end of file