diff options
author | Meik Sievertsen <acydburn@phpbb.com> | 2005-01-06 23:03:08 +0000 |
---|---|---|
committer | Meik Sievertsen <acydburn@phpbb.com> | 2005-01-06 23:03:08 +0000 |
commit | 7a1b178fe6454f73c4afd761bb54306d24611287 (patch) | |
tree | ad4805fb03c129a776ebd8dd80e0e617f6be6bba /phpBB/includes/functions_privmsgs.php | |
parent | b66f68a7799a63949779f0092ec88deff2be0f57 (diff) | |
download | forums-7a1b178fe6454f73c4afd761bb54306d24611287.tar forums-7a1b178fe6454f73c4afd761bb54306d24611287.tar.gz forums-7a1b178fe6454f73c4afd761bb54306d24611287.tar.bz2 forums-7a1b178fe6454f73c4afd761bb54306d24611287.tar.xz forums-7a1b178fe6454f73c4afd761bb54306d24611287.zip |
- merged getting of unread pm count function to get_folder function
- made folder usable within the template (especially custom folder)
git-svn-id: file:///svn/phpbb/trunk@5048 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/functions_privmsgs.php')
-rw-r--r-- | phpBB/includes/functions_privmsgs.php | 81 |
1 files changed, 45 insertions, 36 deletions
diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index b2a43ec1e6..1682df0d1e 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -100,63 +100,57 @@ $global_rule_conditions = array( RULE_IS_GROUP => 'group' ); -// Get number of unread messages from all folder -function get_unread_pm($user_id) -{ - global $db; - - $unread_pm = array(); - - $sql = 'SELECT folder_id, SUM(unread) as sum_unread - FROM ' . PRIVMSGS_TO_TABLE . " - WHERE user_id = $user_id - AND folder_id <> " . PRIVMSGS_OUTBOX . ' - GROUP BY folder_id'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - if ($row['sum_unread']) - { - $unread_pm[$row['folder_id']] = $row['sum_unread']; - } - } - $db->sql_freeresult($result); - - return $unread_pm; -} - // Get all folder -function get_folder($user_id, &$folder) +function get_folder($user_id, &$folder, $folder_id = false, $mode = '') { - global $db, $user; + global $db, $user, $template; if (!is_array($folder)) { $folder = array(); } - $sql = 'SELECT folder_id, COUNT(msg_id) as num_messages + if ($mode == 'unread') + { + $folder['unread'] = array('folder_name' => $user->lang['UNREAD_MESSAGES']); + } + + // Get folder informations + $sql = 'SELECT folder_id, COUNT(msg_id) as num_messages, SUM(unread) as num_unread FROM ' . PRIVMSGS_TO_TABLE . " WHERE user_id = $user_id AND folder_id <> " . PRIVMSGS_NO_BOX . ' GROUP BY folder_id'; $result = $db->sql_query($sql); - $num_messages = array(); + $num_messages = $num_unread = array(); while ($row = $db->sql_fetchrow($result)) { $num_messages[(int) $row['folder_id']] = $row['num_messages']; + $num_unread[(int) $row['folder_id']] = $row['num_unread']; } $db->sql_freeresult($result); - if (!isset($num_messages[PRIVMSGS_OUTBOX])) + // Make sure the default boxes are defined + foreach (array(PRIVMSGS_INBOX, PRIVMSGS_OUTBOX, PRIVMSGS_SENTBOX) as $default_folder) { - $num_messages[PRIVMSGS_OUTBOX] = 0; + if (!isset($num_messages[$default_folder])) + { + $num_messages[$default_folder] = 0; + } + + if (!isset($num_unread[$default_folder])) + { + $num_unread[$default_folder] = 0; + } } - $folder[PRIVMSGS_INBOX] = array('folder_name' => $user->lang['PM_INBOX'], 'num_messages' => (int) $num_messages[PRIVMSGS_INBOX]); + // Adjust unread status for outbox + $num_unread[PRIVMSGS_OUTBOX] = $num_messages[PRIVMSGS_OUTBOX]; + + $folder[PRIVMSGS_INBOX] = array('folder_name' => $user->lang['PM_INBOX'], 'num_messages' => $num_messages[PRIVMSGS_INBOX], 'unread_messages' => $num_unread[PRIVMSGS_INBOX]); + // Custom Folder $sql = 'SELECT folder_id, folder_name, pm_count FROM ' . PRIVMSGS_FOLDER_TABLE . " WHERE user_id = $user_id"; @@ -164,12 +158,27 @@ function get_folder($user_id, &$folder) while ($row = $db->sql_fetchrow($result)) { - $folder[$row['folder_id']] = array('folder_name' => $row['folder_name'], 'num_messages' => $row['pm_count']); + $folder[$row['folder_id']] = array('folder_name' => $row['folder_name'], 'num_messages' => $row['pm_count'], 'unread_messages' => ((isset($num_unread[$row['folder_id']])) ? $num_unread[$row['folder_id']] : 0)); } $db->sql_freeresult($result); - $folder[PRIVMSGS_OUTBOX] = array('folder_name' => $user->lang['PM_OUTBOX'], 'num_messages' => (int) $num_messages[PRIVMSGS_OUTBOX]); - $folder[PRIVMSGS_SENTBOX] = array('folder_name' => $user->lang['PM_SENTBOX'], 'num_messages' => (int) $num_messages[PRIVMSGS_SENTBOX]); + $folder[PRIVMSGS_OUTBOX] = array('folder_name' => $user->lang['PM_OUTBOX'], 'num_messages' => $num_messages[PRIVMSGS_OUTBOX], 'unread_messages' => $num_unread[PRIVMSGS_OUTBOX]); + $folder[PRIVMSGS_SENTBOX] = array('folder_name' => $user->lang['PM_SENTBOX'], 'num_messages' => $num_messages[PRIVMSGS_SENTBOX], 'unread_messages' => $num_unread[PRIVMSGS_SENTBOX]); + + // Define Folder Array for template designers (and for making custom folders usable by the template too) + foreach ($folder as $f_id => $folder_ary) + { + $template->assign_block_vars('folder', array( + 'FOLDER_ID' => $f_id, + 'FOLDER_NAME' => $folder_ary['folder_name'], + 'NUM_MESSAGES' => $folder_ary['num_messages'], + 'UNREAD_MESSAGES' => $folder_ary['unread_messages'], + + 'S_CUR_FOLDER' => ($f_id == $folder_id) ? true : false, + 'S_UNREAD_MESSAGES' => ($folder_ary['unread_messages']) ? true : false, + 'S_CUSTOM_FOLDER' => ($f_id > 0) ? true : false) + ); + } return; } |