erdata['user_id'];
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Could not update private message new/read status (2) for user', '', __LINE__, __FILE__, $sql);
}
//
// Reset PM counters
//
$userdata['user_new_privmsg'] = 0;
$userdata['user_unread_privmsg'] = ( $userdata['user_new_privmsg'] + $userdata['user_unread_privmsg'] );
//
// Generate page
//
$page_title = $lang['Private_Messaging'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
//
// Load templates
//
$template->set_filenames(array(
'body' => 'privmsgs_body.tpl')
);
make_jumpbox('viewforum.'.$phpEx);
$orig_word = array();
$replacement_word = array();
obtain_word_list($orig_word, $replacement_word);
//
// New message
//
$post_new_mesg_url = '
';
//
// General SQL to obtain messages
//
$sql_tot = "SELECT COUNT(privmsgs_id) AS total
FROM " . PRIVMSGS_TABLE . " ";
$sql = "SELECT pm.privmsgs_type, pm.privmsgs_id, pm.privmsgs_date, pm.privmsgs_subject, u.user_id, u.username
FROM " . PRIVMSGS_TABLE . " pm, " . USERS_TABLE . " u ";
switch( $folder )
{
case 'inbox':
$sql_tot .= "WHERE privmsgs_to_userid = " . $userdata['user_id'] . "
AND ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
OR privmsgs_type = " . PRIVMSGS_READ_MAIL . "
OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
$sql .= "WHERE pm.privmsgs_to_userid = " . $userdata['user_id'] . "
AND u.user_id = pm.privmsgs_from_userid
AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
OR pm.privmsgs_type = " . PRIVMSGS_READ_MAIL . "
OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
break;
case 'outbox':
$sql_tot .= "WHERE privmsgs_from_userid = " . $userdata['user_id'] . "
AND ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
$sql .= "WHERE pm.privmsgs_from_userid = " . $userdata['user_id'] . "
AND u.user_id = pm.privmsgs_to_userid
AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
break;
case 'sentbox':
$sql_tot .= "WHERE privmsgs_from_userid = " . $userdata['user_id'] . "
AND privmsgs_type = " . PRIVMSGS_SENT_MAIL;
$sql .= "WHERE pm.privmsgs_from_userid = " . $userdata['user_id'] . "
AND u.user_id = pm.privmsgs_to_userid
AND pm.privmsgs_type = " . PRIVMSGS_SENT_MAIL;
break;
case 'savebox':
$sql_tot .= "WHERE ( ( privmsgs_to_userid = " . $userdata['user_id'] . "
AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " )
OR ( privmsgs_from_userid = " . $userdata['user_id'] . "
AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . ") )";
$sql .= "WHERE u.user_id = pm.privmsgs_from_userid
AND ( ( pm.privmsgs_to_userid = " . $userdata['user_id'] . "
AND pm.privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " )
OR ( pm.privmsgs_from_userid = " . $userdata['user_id'] . "
AND pm.privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " ) )";
break;
default:
message_die(GENERAL_MESSAGE, $lang['No_such_folder']);
break;
}
//
// Show messages over previous x days/months
//
if ( $submit_msgdays && ( !empty($HTTP_POST_VARS['msgdays']) || !empty($HTTP_GET_VARS['msgdays']) ) )
{
$msg_days = ( !empty($HTTP_POST_VARS['msgdays']) ) ? intval($HTTP_POST_VARS['msgdays']) : intval($HTTP_GET_VARS['msgdays']);
$min_msg_time = time() - ($msg_days * 86400);
$limit_msg_time_total = " AND privmsgs_date > $min_msg_time";
$limit_msg_time = " AND pm.privmsgs_date > $min_msg_time ";
if ( !empty($HTTP_POST_VARS['msgdays']) )
{
$start = 0;
}
}
else
{
$limit_msg_time = $limit_msg_time_total = '';
$msg_days = 0;
}
$sql .= $limit_msg_time . " ORDER BY pm.privmsgs_date DESC LIMIT $start, " . $board_config['topics_per_page'];
$sql_all_tot = $sql_tot;
$sql_tot .= $limit_msg_time_total;
//
// Get messages
//
if ( !($result = $db->sql_query($sql_tot)) )
{
message_die(GENERAL_ERROR, 'Could not query private message information', '', __LINE__, __FILE__, $sql_tot);
}
$pm_total = ( $row = $db->sql_fetchrow($result) ) ? $row['total'] : 0;
if ( !($result = $db->sql_query($sql_all_tot)) )
{
message_die(GENERAL_ERROR, 'Could not query private message information', '', __LINE__, __FILE__, $sql_tot);
}
$pm_all_total = ( $row = $db->sql_fetchrow($result) ) ? $row['total'] : 0;
//
// Build select box
//
$previous_days = array(0, 1, 7, 14, 30, 90, 180, 364);
$previous_days_text = array($lang['All_Posts'], $lang['1_Day'], $lang['7_Days'], $lang['2_Weeks'], $lang['1_Month'], $lang['3_Months'], $lang['6_Months'], $lang['1_Year']);
$select_msg_days = '';
for($i = 0; $i < count($previous_days); $i++)
{
$selected = ( $msg_days == $previous_days[$i] ) ? ' selected="selected"' : '';
$select_msg_days .= '';
}
//
// Define correct icons
//
switch ( $folder )
{
case 'inbox':
$l_box_name = $lang['Inbox'];
break;
case 'outbox':
$l_box_name = $lang['Outbox'];
break;
case 'savebox':
$l_box_name = $lang['Savebox'];
break;
case 'sentbox':
$l_box_name = $lang['Sentbox'];
break;
}
$post_pm = append_sid("privmsg.$phpEx?mode=post");
$post_pm_img = '
';
$post_pm = '' . $lang['Post_new_pm'] . '';
//
// Output data for inbox status
//
if ( $folder != 'outbox' )
{
$inbox_limit_pct = ( $board_config['max_' . $folder . '_privmsgs'] > 0 ) ? round(( $pm_all_total / $board_config['max_' . $folder . '_privmsgs'] ) * 100) : 100;
$inbox_limit_img_length = ( $board_config['max_' . $folder . '_privmsgs'] > 0 ) ? round(( $pm_all_total / $board_config['max_' . $folder . '_privmsgs'] ) * $board_config['privmsg_graphic_length']) : $board_config['privmsg_graphic_length'];
$inbox_limit_remain = ( $board_config['max_' . $folder . '_privmsgs'] > 0 ) ? $board_config['max_' . $folder . '_privmsgs'] - $pm_all_total : 0;
$template->assign_block_vars('switch_box_size_notice', array());
switch( $folder )
{
case 'inbox':
$l_box_size_status = sprintf($lang['Inbox_size'], $inbox_limit_pct);
break;
case 'sentbox':
$l_box_size_status = sprintf($lang['Sentbox_size'], $inbox_limit_pct);
break;
case 'savebox':
$l_box_size_status = sprintf($lang['Savebox_size'], $inbox_limit_pct);
break;
default:
$l_box_size_status = '';
break;
}
}
else
{
$inbox_limit_img_length = $inbox_limit_pct = $l_box_size_status = '';
}
//
// Dump vars to template
//
$template->assign_vars(array(
'BOX_NAME' => $l_box_name,
'INBOX_IMG' => $inbox_img,
'SENTBOX_IMG' => $sentbox_img,
'OUTBOX_IMG' => $outbox_img,
'SAVEBOX_IMG' => $savebox_img,
'INBOX' => $inbox_url,
'SENTBOX' => $sentbox_url,
'OUTBOX' => $outbox_url,
'SAVEBOX' => $savebox_url,
'POST_PM_IMG' => $post_pm_img,
'POST_PM' => $post_pm,
'INBOX_LIMIT_IMG_WIDTH' => $inbox_limit_img_length,
'INBOX_LIMIT_PERCENT' => $inbox_limit_pct,
'BOX_SIZE_STATUS' => $l_box_size_status,
'L_INBOX' => $lang['Inbox'],
'L_OUTBOX' => $lang['Outbox'],
'L_SENTBOX' => $lang['Sent'],
'L_SAVEBOX' => $lang['Saved'],
'L_MARK' => $lang['Mark'],
'L_FLAG' => $lang['Flag'],
'L_SUBJECT' => $lang['Subject'],
'L_DATE' => $lang['Date'],
'L_DISPLAY_MESSAGES' => $lang['Display_messages'],
'L_FROM_OR_TO' => ( $folder == 'inbox' || $folder == 'savebox' ) ? $lang['From'] : $lang['To'],
'L_MARK_ALL' => $lang['Mark_all'],
'L_UNMARK_ALL' => $lang['Unmark_all'],
'L_DELETE_MARKED' => $lang['Delete_marked'],
'L_DELETE_ALL' => $lang['Delete_all'],
'L_SAVE_MARKED' => $lang['Save_marked'],
'S_PRIVMSGS_ACTION' => append_sid("privmsg.$phpEx?folder=$folder"),
'S_HIDDEN_FIELDS' => '',
'S_POST_NEW_MSG' => $post_new_mesg_url,
'S_SELECT_MSG_DAYS' => $select_msg_days,
'U_POST_NEW_TOPIC' => append_sid("privmsg.$phpEx?mode=post"))
);
//
// Okay, let's build the correct folder
//
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not query private messages', '', __LINE__, __FILE__, $sql);
}
if ( $row = $db->sql_fetchrow($result) )
{
$i = 0;
do
{
$privmsg_id = $row['privmsgs_id'];
$flag = $row['privmsgs_type'];
$icon_flag = ( $flag == PRIVMSGS_NEW_MAIL || $flag == PRIVMSGS_UNREAD_MAIL ) ? $images['pm_unreadmsg'] : $images['pm_readmsg'];
$icon_flag_alt = ( $flag == PRIVMSGS_NEW_MAIL || $flag == PRIVMSGS_UNREAD_MAIL ) ? $lang['Unread_message'] : $lang['Read_message'];
$msg_userid = $row['user_id'];
$msg_username = $row['username'];
$u_from_user_profile = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=$msg_userid");
$msg_subject = $row['privmsgs_subject'];
if ( count($orig_word) )
{
$msg_subject = preg_replace($orig_word, $replacement_word, $msg_subject);
}
$u_subject = append_sid("privmsg.$phpEx?folder=$folder&mode=read&" . POST_POST_URL . "=$privmsg_id");
$msg_date = create_date($board_config['default_dateformat'], $row['privmsgs_date'], $board_config['board_timezone']);
if ( $flag == PRIVMSGS_NEW_MAIL && $folder == 'inbox' )
{
$msg_subject = '' . $msg_subject . '';
$msg_date = '' . $msg_date . '';
$msg_username = '' . $msg_username . '';
}
$row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
$i++;
$template->assign_block_vars('listrow', array(
'ROW_COLOR' => '#' . $row_color,
'ROW_CLASS' => $row_class,
'FROM' => $msg_username,
'SUBJECT' => $msg_subject,
'DATE' => $msg_date,
'PRIVMSG_FOLDER_IMG' => $icon_flag,
'L_PRIVMSG_FOLDER_ALT' => $icon_flag_alt,
'S_MARK_ID' => $privmsg_id,
'U_READ' => $u_subject,
'U_FROM_USER_PROFILE' => $u_from_user_profile)
);
}
while( $row = $db->sql_fetchrow($result) );
$template->assign_vars(array(
'PAGINATION' => generate_pagination("privmsg.$phpEx?folder=$folder", $pm_total, $board_config['topics_per_page'], $start),
'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $pm_total / $board_config['topics_per_page'] )),
'L_GOTO_PAGE' => $lang['Goto_page'])
);
}
else
{
$template->assign_vars(array(
'L_NO_MESSAGES' => $lang['No_messages_folder'])
);
$template->assign_block_vars("switch_no_messages", array() );
}
$template->pparse('body');
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
?>