diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html
index 5a23be76cd..d6aaf9e38f 100644
--- a/phpBB/docs/CHANGELOG.html
+++ b/phpBB/docs/CHANGELOG.html
@@ -198,6 +198,7 @@
[Fix] Do not display topic approval status image for shadow topic if a user is not a moderator in the forum the topic has been moved to. (Bug #43295)
[Fix] Fix email problems on servers with PHP installations not accepting RFC-compliant subject string passed to the the mail()-function. (Bug #46725)
[Fix] Correctly orientate Control-Panel-Navigation background-image on RTL languages. (Bug #49945)
+ [Fix] Sort private messages by message time and not message id. (Bug #50015)
[Change] submit_post() now accepts force_approved_state key passed to $data to indicate new posts being approved (true) or unapproved (false).
[Change] Change the data format of the default file ACM to be more secure from tampering and have better performance.
[Change] Add index on log_time to the log table to prevent slowdown on boards with many log entries. (Bug #44665 - Patch by bantu)
diff --git a/phpBB/includes/ucp/ucp_pm_viewfolder.php b/phpBB/includes/ucp/ucp_pm_viewfolder.php
index f947518ba8..11e7f5e7e8 100644
--- a/phpBB/includes/ucp/ucp_pm_viewfolder.php
+++ b/phpBB/includes/ucp/ucp_pm_viewfolder.php
@@ -386,12 +386,12 @@ function get_pm_from($folder_id, $folder, $user_id)
if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX)
{
$sort_by_text = array('t' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
- $sort_by_sql = array('t' => 'p.msg_id', 's' => 'p.message_subject');
+ $sort_by_sql = array('t' => 'p.message_time', 's' => array('p.message_subject', 'p.message_time'));
}
else
{
$sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
- $sort_by_sql = array('a' => 'u.username_clean', 't' => 'p.msg_id', 's' => 'p.message_subject');
+ $sort_by_sql = array('a' => array('u.username_clean', 'p.message_time'), 't' => 'p.message_time', 's' => array('p.message_subject', 'p.message_time'));
}
$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
@@ -462,16 +462,26 @@ function get_pm_from($folder_id, $folder, $user_id)
}
// Select the sort order
- $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC');
+ $directioin = ($sort_dir == 'd') ? 'ASC' : 'DESC';
$sql_start = max(0, $pm_count - $sql_limit - $start);
}
else
{
// Select the sort order
- $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
+ $direction = ($sort_dir == 'd') ? 'DESC' : 'ASC';
$sql_start = $start;
}
+ // Sql sort order
+ if (is_array($sort_by_sql[$sort_key]))
+ {
+ $sql_sort_order = implode(' ' . $direction . ', ', $sort_by_sql[$sort_key]) . ' ' . $direction;
+ }
+ else
+ {
+ $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . $direction;
+ }
+
$sql = 'SELECT t.*, p.root_level, p.message_time, p.message_subject, p.icon_id, p.to_address, p.message_attachment, p.bcc_address, u.username, u.username_clean, u.user_colour
FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . " u
WHERE t.user_id = $user_id
diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php
index e743a92651..ed4b60cf2c 100644
--- a/phpBB/viewtopic.php
+++ b/phpBB/viewtopic.php
@@ -907,6 +907,7 @@ else
$direction = (($sort_dir == 'd') ? 'DESC' : 'ASC');
$sql_start = $start;
}
+
if (is_array($sort_by_sql[$sort_key]))
{
$sql_sort_order = implode(' ' . $direction . ', ', $sort_by_sql[$sort_key]) . ' ' . $direction;
@@ -916,7 +917,6 @@ else
$sql_sort_order = $sort_by_sql[$sort_key] . ' ' . $direction;
}
-
// Container for user details, only process once
$post_list = $user_cache = $id_cache = $attachments = $attach_list = $rowset = $update_count = $post_edit_list = array();
$has_attachments = $display_notice = false;
@@ -1604,7 +1604,7 @@ if ($topic_data['topic_type'] == POST_GLOBAL)
$result = $db->sql_query_limit($sql, 1);
$topic_data['forum_last_post_time'] = (int) $db->sql_fetchfield('forum_last_post_time');
$db->sql_freeresult($result);
-
+
$sql = 'SELECT mark_time as forum_mark_time
FROM ' . FORUMS_TRACK_TABLE . '
WHERE forum_id = 0