/** * Execute message options */ function message_options($id, $mode, $global_privmsgs_rules, $global_rule_conditions) { global $src_root_path, $phpEx, $user, $template, $auth, $config, $db; $redirect_url = append_sid("{$src_root_path}ucp.{$phpEx}", "i=pm&mode=options"); add_form_key('ucp_pm_options'); // Change "full folder" setting - what to do if folder is full if (isset($_POST['fullfolder'])) { if (!check_form_key('ucp_pm_options')) { trigger_error('FORM_INVALID'); } $full_action = request_var('full_action', 0); $set_folder_id = 0; switch ($full_action) { case 1: $set_folder_id = FULL_FOLDER_DELETE; break; case 2: $set_folder_id = request_var('full_move_to', PRIVMSGS_INBOX); break; case 3: $set_folder_id = FULL_FOLDER_HOLD; break; default: $full_action = 0; break; } if ($full_action) { $sql = 'UPDATE ' . USERS_TABLE . ' SET user_full_folder = ' . $set_folder_id . ' WHERE user_id = ' . $user->data['user_id']; $db->sql_query($sql); $user->data['user_full_folder'] = $set_folder_id; $message = $user->lang['FULL_FOLDER_OPTION_CHANGED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $redirect_url . '">', '</a>'); meta_refresh(3, $redirect_url); trigger_error($message); } } // Add Folder if (isset($_POST['addfolder'])) { if (check_form_key('ucp_pm_options')) { $folder_name = utf8_normalize_nfc(request_var('foldername', '', true)); $msg = ''; if ($folder_name) { $sql = 'SELECT folder_name FROM ' . PRIVMSGS_FOLDER_TABLE . "\n\t\t\t\t\tWHERE folder_name = '" . $db->sql_escape($folder_name) . "'\n\t\t\t\t\t\tAND user_id = " . $user->data['user_id']; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if ($row) { trigger_error(sprintf($user->lang['FOLDER_NAME_EXIST'], $folder_name)); } $sql = 'SELECT COUNT(folder_id) as num_folder FROM ' . PRIVMSGS_FOLDER_TABLE . ' WHERE user_id = ' . $user->data['user_id']; $result = $db->sql_query($sql); $num_folder = (int) $db->sql_fetchfield('num_folder'); $db->sql_freeresult($result); if ($num_folder >= $config['pm_max_boxes']) { trigger_error('MAX_FOLDER_REACHED'); } $sql = 'INSERT INTO ' . PRIVMSGS_FOLDER_TABLE . ' ' . $db->sql_build_array('INSERT', array('user_id' => (int) $user->data['user_id'], 'folder_name' => $folder_name)); $db->sql_query($sql); $msg = $user->lang['FOLDER_ADDED']; } else { $msg = $user->lang['FOLDER_NAME_EMPTY']; } } else { $msg = $user->lang['FORM_INVALID']; } $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $redirect_url . '">', '</a>'); meta_refresh(3, $redirect_url); trigger_error($message); } // Rename folder if (isset($_POST['rename_folder'])) { if (check_form_key('ucp_pm_options')) { $new_folder_name = utf8_normalize_nfc(request_var('new_folder_name', '', true)); $rename_folder_id = request_var('rename_folder_id', 0); if (!$new_folder_name) { trigger_error('NO_NEW_FOLDER_NAME'); } // Select custom folder $sql = 'SELECT folder_name, pm_count FROM ' . PRIVMSGS_FOLDER_TABLE . "\n\t\t\t\tWHERE user_id = {$user->data['user_id']}\n\t\t\t\t\tAND folder_id = {$rename_folder_id}"; $result = $db->sql_query_limit($sql, 1); $folder_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$folder_row) { trigger_error('CANNOT_RENAME_FOLDER'); } $sql = 'UPDATE ' . PRIVMSGS_FOLDER_TABLE . "\n\t\t\t\tSET folder_name = '" . $db->sql_escape($new_folder_name) . "'\n\t\t\t\tWHERE folder_id = {$rename_folder_id}\n\t\t\t\t\tAND user_id = {$user->data['user_id']}"; $db->sql_query($sql); $msg = $user->lang['FOLDER_RENAMED']; } else { $msg = $user->lang['FORM_INVALID']; } $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $redirect_url . '">', '</a>'); meta_refresh(3, $redirect_url); trigger_error($message); } // Remove Folder if (isset($_POST['remove_folder'])) { $remove_folder_id = request_var('remove_folder_id', 0); // Default to "move all messages to inbox" $remove_action = request_var('remove_action', 1); $move_to = request_var('move_to', PRIVMSGS_INBOX); // Move to same folder? if ($remove_action == 1 && $remove_folder_id == $move_to) { trigger_error('CANNOT_MOVE_TO_SAME_FOLDER'); } // Select custom folder $sql = 'SELECT folder_name, pm_count FROM ' . PRIVMSGS_FOLDER_TABLE . "\n\t\t\tWHERE user_id = {$user->data['user_id']}\n\t\t\t\tAND folder_id = {$remove_folder_id}"; $result = $db->sql_query_limit($sql, 1); $folder_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$folder_row) { trigger_error('CANNOT_REMOVE_FOLDER'); } $s_hidden_fields = array('remove_folder_id' => $remove_folder_id, 'remove_action' => $remove_action, 'move_to' => $move_to, 'remove_folder' => 1); // Do we need to confirm? if (confirm_box(true)) { // Gather message ids $sql = 'SELECT msg_id FROM ' . PRIVMSGS_TO_TABLE . ' WHERE user_id = ' . $user->data['user_id'] . "\n\t\t\t\t\tAND folder_id = {$remove_folder_id}"; $result = $db->sql_query($sql); $msg_ids = array(); while ($row = $db->sql_fetchrow($result)) { $msg_ids[] = (int) $row['msg_id']; } $db->sql_freeresult($result); // First of all, copy all messages to another folder... or delete all messages switch ($remove_action) { // Move Messages case 1: $num_moved = move_pm($user->data['user_id'], $user->data['message_limit'], $msg_ids, $move_to, $remove_folder_id); // Something went wrong, only partially moved? if ($num_moved != $folder_row['pm_count']) { trigger_error($user->lang('MOVE_PM_ERROR', $user->lang('MESSAGES_COUNT', (int) $folder_row['pm_count']), $num_moved)); } break; // Remove Messages // Remove Messages case 2: delete_pm($user->data['user_id'], $msg_ids, $remove_folder_id); break; } // Remove folder $sql = 'DELETE FROM ' . PRIVMSGS_FOLDER_TABLE . "\n\t\t\t\tWHERE user_id = {$user->data['user_id']}\n\t\t\t\t\tAND folder_id = {$remove_folder_id}"; $db->sql_query($sql); // Check full folder option. If the removed folder has been specified as destination switch back to inbox if ($user->data['user_full_folder'] == $remove_folder_id) { $sql = 'UPDATE ' . USERS_TABLE . ' SET user_full_folder = ' . PRIVMSGS_INBOX . ' WHERE user_id = ' . $user->data['user_id']; $db->sql_query($sql); $user->data['user_full_folder'] = PRIVMSGS_INBOX; } // Now make sure the folder is not used for rules // We assign another folder id (the one the messages got moved to) or assign the INBOX (to not have to remove any rule) $sql = 'UPDATE ' . PRIVMSGS_RULES_TABLE . ' SET rule_folder_id = '; $sql .= $remove_action == 1 ? $move_to : PRIVMSGS_INBOX; $sql .= ' WHERE rule_folder_id = ' . $remove_folder_id; $db->sql_query($sql); $meta_info = append_sid("{$src_root_path}ucp.{$phpEx}", "i=pm&mode={$mode}"); $message = $user->lang['FOLDER_REMOVED']; meta_refresh(3, $meta_info); $message .= '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $meta_info . '">', '</a>'); trigger_error($message); } else { confirm_box(false, 'REMOVE_FOLDER', build_hidden_fields($s_hidden_fields)); } } // Add Rule if (isset($_POST['add_rule'])) { if (check_form_key('ucp_pm_options')) { $check_option = request_var('check_option', 0); $rule_option = request_var('rule_option', 0); $cond_option = request_var('cond_option', ''); $action_option = explode('|', request_var('action_option', '')); $rule_string = $cond_option != 'none' ? utf8_normalize_nfc(request_var('rule_string', '', true)) : ''; $rule_user_id = $cond_option != 'none' ? request_var('rule_user_id', 0) : 0; $rule_group_id = $cond_option != 'none' ? request_var('rule_group_id', 0) : 0; $action = (int) $action_option[0]; $folder_id = (int) $action_option[1]; if (!$action || !$check_option || !$rule_option || !$cond_option || $cond_option != 'none' && !$rule_string) { trigger_error('RULE_NOT_DEFINED'); } if ($cond_option == 'user' && !$rule_user_id || $cond_option == 'group' && !$rule_group_id) { trigger_error('RULE_NOT_DEFINED'); } $rule_ary = array('user_id' => $user->data['user_id'], 'rule_check' => $check_option, 'rule_connection' => $rule_option, 'rule_string' => $rule_string, 'rule_user_id' => $rule_user_id, 'rule_group_id' => $rule_group_id, 'rule_action' => $action, 'rule_folder_id' => $folder_id); $sql = 'SELECT rule_id FROM ' . PRIVMSGS_RULES_TABLE . ' WHERE ' . $db->sql_build_array('SELECT', $rule_ary); $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if ($row) { trigger_error('RULE_ALREADY_DEFINED'); } // Prevent users from flooding the rules table $sql = 'SELECT COUNT(rule_id) AS num_rules FROM ' . PRIVMSGS_RULES_TABLE . ' WHERE user_id = ' . (int) $user->data['user_id']; $result = $db->sql_query($sql); $num_rules = (int) $db->sql_fetchfield('num_rules'); $db->sql_freeresult($result); if ($num_rules >= 5000) { trigger_error('RULE_LIMIT_REACHED'); } $sql = 'INSERT INTO ' . PRIVMSGS_RULES_TABLE . ' ' . $db->sql_build_array('INSERT', $rule_ary); $db->sql_query($sql); // Set the user_message_rules bit $sql = 'UPDATE ' . USERS_TABLE . ' SET user_message_rules = 1 WHERE user_id = ' . $user->data['user_id']; $db->sql_query($sql); $msg = $user->lang['RULE_ADDED']; } else { $msg = $user->lang['FORM_INVALID']; } $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $redirect_url . '">', '</a>'); meta_refresh(3, $redirect_url); trigger_error($message); } // Remove Rule if (isset($_POST['delete_rule']) && !isset($_POST['cancel'])) { $delete_id = array_keys(request_var('delete_rule', array(0 => 0))); $delete_id = !empty($delete_id[0]) ? $delete_id[0] : 0; if (!$delete_id) { redirect(append_sid("{$src_root_path}ucp.{$phpEx}", 'i=pm&mode=' . $mode)); } // Do we need to confirm? if (confirm_box(true)) { $sql = 'DELETE FROM ' . PRIVMSGS_RULES_TABLE . ' WHERE user_id = ' . $user->data['user_id'] . "\n\t\t\t\t\tAND rule_id = {$delete_id}"; $db->sql_query($sql); $meta_info = append_sid("{$src_root_path}ucp.{$phpEx}", 'i=pm&mode=' . $mode); $message = $user->lang['RULE_DELETED']; // Reset user_message_rules if no more assigned $sql = 'SELECT rule_id FROM ' . PRIVMSGS_RULES_TABLE . ' WHERE user_id = ' . $user->data['user_id']; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); // Unset the user_message_rules bit if (!$row) { $sql = 'UPDATE ' . USERS_TABLE . ' SET user_message_rules = 0 WHERE user_id = ' . $user->data['user_id']; $db->sql_query($sql); } meta_refresh(3, $meta_info); $message .= '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $meta_info . '">', '</a>'); trigger_error($message); } else { confirm_box(false, 'DELETE_RULE', build_hidden_fields(array('delete_rule' => array($delete_id => 1)))); } } $folder = array(); $sql = 'SELECT COUNT(msg_id) as num_messages FROM ' . PRIVMSGS_TO_TABLE . ' WHERE user_id = ' . $user->data['user_id'] . ' AND folder_id = ' . PRIVMSGS_INBOX; $result = $db->sql_query($sql); $num_messages = (int) $db->sql_fetchfield('num_messages'); $db->sql_freeresult($result); $folder[PRIVMSGS_INBOX] = array('folder_name' => $user->lang['PM_INBOX'], 'message_status' => $user->lang('FOLDER_MESSAGE_STATUS', $user->lang('MESSAGES_COUNT', (int) $user->data['message_limit']), $num_messages)); $sql = 'SELECT folder_id, folder_name, pm_count FROM ' . PRIVMSGS_FOLDER_TABLE . ' WHERE user_id = ' . $user->data['user_id']; $result = $db->sql_query($sql); $num_user_folder = 0; while ($row = $db->sql_fetchrow($result)) { $num_user_folder++; $folder[$row['folder_id']] = array('folder_name' => $row['folder_name'], 'message_status' => $user->lang('FOLDER_MESSAGE_STATUS', $user->lang('MESSAGES_COUNT', (int) $user->data['message_limit']), (int) $row['pm_count'])); } $db->sql_freeresult($result); $s_full_folder_options = $s_to_folder_options = $s_folder_options = ''; if ($user->data['user_full_folder'] == FULL_FOLDER_NONE) { // -3 here to let the correct folder id be selected $to_folder_id = $config['full_folder_action'] - 3; } else { $to_folder_id = $user->data['user_full_folder']; } foreach ($folder as $folder_id => $folder_ary) { $s_full_folder_options .= '<option value="' . $folder_id . '"' . ($user->data['user_full_folder'] == $folder_id ? ' selected="selected"' : '') . '>' . $folder_ary['folder_name'] . ' (' . $folder_ary['message_status'] . ')</option>'; $s_to_folder_options .= '<option value="' . $folder_id . '"' . ($to_folder_id == $folder_id ? ' selected="selected"' : '') . '>' . $folder_ary['folder_name'] . ' (' . $folder_ary['message_status'] . ')</option>'; if ($folder_id != PRIVMSGS_INBOX) { $s_folder_options .= '<option value="' . $folder_id . '">' . $folder_ary['folder_name'] . ' (' . $folder_ary['message_status'] . ')</option>'; } } $s_delete_checked = $user->data['user_full_folder'] == FULL_FOLDER_DELETE ? ' checked="checked"' : ''; $s_hold_checked = $user->data['user_full_folder'] == FULL_FOLDER_HOLD ? ' checked="checked"' : ''; $s_move_checked = $user->data['user_full_folder'] >= 0 ? ' checked="checked"' : ''; if ($user->data['user_full_folder'] == FULL_FOLDER_NONE) { switch ($config['full_folder_action']) { case 1: $s_delete_checked = ' checked="checked"'; break; case 2: $s_hold_checked = ' checked="checked"'; break; } } $template->assign_vars(array('S_FULL_FOLDER_OPTIONS' => $s_full_folder_options, 'S_TO_FOLDER_OPTIONS' => $s_to_folder_options, 'S_FOLDER_OPTIONS' => $s_folder_options, 'S_DELETE_CHECKED' => $s_delete_checked, 'S_HOLD_CHECKED' => $s_hold_checked, 'S_MOVE_CHECKED' => $s_move_checked, 'S_MAX_FOLDER_REACHED' => $num_user_folder >= $config['pm_max_boxes'] ? true : false, 'S_MAX_FOLDER_ZERO' => $config['pm_max_boxes'] == 0 ? true : false, 'DEFAULT_ACTION' => $config['full_folder_action'] == 1 ? $user->lang['DELETE_OLDEST_MESSAGES'] : $user->lang['HOLD_NEW_MESSAGES'], 'U_FIND_USERNAME' => append_sid("{$src_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=ucp&field=rule_string&select_single=true'))); $rule_lang = $action_lang = $check_lang = array(); // Build all three language arrays preg_replace('#^((RULE|ACTION|CHECK)_([A-Z0-9_]+))$#e', "\${strtolower('\\2') . '_lang'}[constant('\\1')] = \$user->lang['PM_\\2']['\\3']", array_keys(get_defined_constants())); /* Rule Ordering: -> CHECK_* -> RULE_* [IN $global_privmsgs_rules:CHECK_*] -> [IF $rule_conditions[RULE_*] [|text|bool|user|group|own_group]] -> ACTION_* */ $check_option = request_var('check_option', 0); $rule_option = request_var('rule_option', 0); $cond_option = request_var('cond_option', ''); $action_option = request_var('action_option', ''); $back = isset($_REQUEST['back']) ? request_var('back', array('' => 0)) : array(); if (sizeof($back)) { if ($action_option) { $action_option = ''; } else { if ($cond_option) { $cond_option = ''; } else { if ($rule_option) { $rule_option = 0; } else { if ($check_option) { $check_option = 0; } } } } } if (isset($back['action']) && $cond_option == 'none') { $back['cond'] = true; } // Check if (!isset($global_privmsgs_rules[$check_option])) { $check_option = 0; } define_check_option($check_option && !isset($back['rule']) ? true : false, $check_option, $check_lang); if ($check_option && !isset($back['rule'])) { define_rule_option($rule_option && !isset($back['cond']) ? true : false, $rule_option, $rule_lang, $global_privmsgs_rules[$check_option]); } if ($rule_option && !isset($back['cond'])) { if (!isset($global_rule_conditions[$rule_option])) { $cond_option = 'none'; $template->assign_var('NONE_CONDITION', true); } else { define_cond_option($cond_option && !isset($back['action']) ? true : false, $cond_option, $rule_option, $global_rule_conditions); } } if ($cond_option && !isset($back['action'])) { define_action_option(false, $action_option, $action_lang, $folder); } show_defined_rules($user->data['user_id'], $check_lang, $rule_lang, $action_lang, $folder); }
function main($id, $mode) { global $user, $template, $phpbb_root_path, $auth, $phpEx, $db, $config; if (!$user->data['is_registered']) { trigger_error('NO_MESSAGE'); } // Is PM disabled? if (!$config['allow_privmsg']) { trigger_error('PM_DISABLED'); } $user->add_lang('posting'); $template->assign_var('S_PRIVMSGS', true); // Folder directly specified? $folder_specified = request_var('folder', ''); if (!in_array($folder_specified, array('inbox', 'outbox', 'sentbox'))) { $folder_specified = (int) $folder_specified; } else { $folder_specified = $folder_specified == 'inbox' ? PRIVMSGS_INBOX : ($folder_specified == 'outbox' ? PRIVMSGS_OUTBOX : PRIVMSGS_SENTBOX); } if (!$folder_specified) { $mode = !$mode ? request_var('mode', 'view') : $mode; } else { $mode = 'view'; } include $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx; switch ($mode) { // New private messages popup case 'popup': $l_new_message = ''; if ($user->data['is_registered']) { if ($user->data['user_new_privmsg']) { $l_new_message = $user->data['user_new_privmsg'] == 1 ? $user->lang['YOU_NEW_PM'] : $user->lang['YOU_NEW_PMS']; } else { $l_new_message = $user->lang['YOU_NO_NEW_PM']; } } $template->assign_vars(array('MESSAGE' => $l_new_message, 'S_NOT_LOGGED_IN' => $user->data['user_id'] == ANONYMOUS ? true : false, 'CLICK_TO_VIEW' => sprintf($user->lang['CLICK_VIEW_PRIVMSG'], '<a href="' . append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=pm&folder=inbox') . '" onclick="jump_to_inbox(this.href); return false;">', '</a>'), 'U_INBOX' => append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=pm&folder=inbox'), 'UA_INBOX' => append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=pm&folder=inbox', false))); $tpl_file = 'ucp_pm_popup'; break; // Compose message // Compose message case 'compose': $action = request_var('action', 'post'); get_folder($user->data['user_id']); if (!$auth->acl_get('u_sendpm')) { // trigger_error('NO_AUTH_SEND_MESSAGE'); $template->assign_vars(array('S_NO_AUTH_SEND_MESSAGE' => true, 'S_COMPOSE_PM_VIEW' => true)); $tpl_file = 'ucp_pm_viewfolder'; break; } include $phpbb_root_path . 'includes/ucp/ucp_pm_compose.' . $phpEx; compose_pm($id, $mode, $action); $tpl_file = 'posting_body'; break; case 'options': set_user_message_limit(); get_folder($user->data['user_id']); include $phpbb_root_path . 'includes/ucp/ucp_pm_options.' . $phpEx; message_options($id, $mode, $global_privmsgs_rules, $global_rule_conditions); $tpl_file = 'ucp_pm_options'; break; case 'drafts': get_folder($user->data['user_id']); $this->p_name = 'pm'; // Call another module... please do not try this at home... Hoochie Coochie Man include $phpbb_root_path . 'includes/ucp/ucp_main.' . $phpEx; $module = new ucp_main($this); $module->u_action = $this->u_action; $module->main($id, $mode); $this->tpl_name = $module->tpl_name; $this->page_title = 'UCP_PM_DRAFTS'; unset($module); return; break; case 'view': set_user_message_limit(); if ($folder_specified) { $folder_id = $folder_specified; $action = 'view_folder'; } else { $folder_id = request_var('f', PRIVMSGS_NO_BOX); $action = request_var('action', 'view_folder'); } $msg_id = request_var('p', 0); $view = request_var('view', ''); // View message if specified if ($msg_id) { $action = 'view_message'; } if (!$auth->acl_get('u_readpm')) { trigger_error('NO_AUTH_READ_MESSAGE'); } // Do not allow hold messages to be seen if ($folder_id == PRIVMSGS_HOLD_BOX) { trigger_error('NO_AUTH_READ_HOLD_MESSAGE'); } // First Handle Mark actions and moving messages $submit_mark = isset($_POST['submit_mark']) ? true : false; $move_pm = isset($_POST['move_pm']) ? true : false; $mark_option = request_var('mark_option', ''); $dest_folder = request_var('dest_folder', PRIVMSGS_NO_BOX); // Is moving PM triggered through mark options? if (!in_array($mark_option, array('mark_important', 'delete_marked')) && $submit_mark) { $move_pm = true; $dest_folder = (int) $mark_option; $submit_mark = false; } // Move PM if ($move_pm) { $move_msg_ids = isset($_POST['marked_msg_id']) ? request_var('marked_msg_id', array(0)) : array(); $cur_folder_id = request_var('cur_folder_id', PRIVMSGS_NO_BOX); if (move_pm($user->data['user_id'], $user->data['message_limit'], $move_msg_ids, $dest_folder, $cur_folder_id)) { // Return to folder view if single message moved if ($action == 'view_message') { $msg_id = 0; $folder_id = request_var('cur_folder_id', PRIVMSGS_NO_BOX); $action = 'view_folder'; } } } // Message Mark Options if ($submit_mark) { handle_mark_actions($user->data['user_id'], $mark_option); } // If new messages arrived, place them into the appropriate folder $num_not_moved = $num_removed = 0; $release = request_var('release', 0); if ($user->data['user_new_privmsg'] && $action == 'view_folder') { $return = place_pm_into_folder($global_privmsgs_rules, $release); $num_not_moved = $return['not_moved']; $num_removed = $return['removed']; } if (!$msg_id && $folder_id == PRIVMSGS_NO_BOX) { $folder_id = PRIVMSGS_INBOX; } else { if ($msg_id && $folder_id == PRIVMSGS_NO_BOX) { $sql = 'SELECT folder_id FROM ' . PRIVMSGS_TO_TABLE . "\n\t\t\t\t\t\tWHERE msg_id = {$msg_id}\n\t\t\t\t\t\t\tAND folder_id <> " . PRIVMSGS_NO_BOX . ' AND user_id = ' . $user->data['user_id']; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$row) { trigger_error('NO_MESSAGE'); } $folder_id = (int) $row['folder_id']; } } $message_row = array(); if ($action == 'view_message' && $msg_id) { // Get Message user want to see if ($view == 'next' || $view == 'previous') { $sql_condition = $view == 'next' ? '>' : '<'; $sql_ordering = $view == 'next' ? 'ASC' : 'DESC'; $sql = 'SELECT t.msg_id FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . PRIVMSGS_TABLE . " p2\n\t\t\t\t\t\t\tWHERE p2.msg_id = {$msg_id}\n\t\t\t\t\t\t\t\tAND t.folder_id = {$folder_id}\n\t\t\t\t\t\t\t\tAND t.user_id = " . $user->data['user_id'] . "\n\t\t\t\t\t\t\t\tAND t.msg_id = p.msg_id\n\t\t\t\t\t\t\t\tAND p.message_time {$sql_condition} p2.message_time\n\t\t\t\t\t\t\tORDER BY p.message_time {$sql_ordering}"; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$row) { $message = $view == 'next' ? 'NO_NEWER_PM' : 'NO_OLDER_PM'; trigger_error($message); } else { $msg_id = $row['msg_id']; } } $sql = 'SELECT t.*, p.*, u.* FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u WHERE t.user_id = ' . $user->data['user_id'] . "\n\t\t\t\t\t\t\tAND p.author_id = u.user_id\n\t\t\t\t\t\t\tAND t.folder_id = {$folder_id}\n\t\t\t\t\t\t\tAND t.msg_id = p.msg_id\n\t\t\t\t\t\t\tAND p.msg_id = {$msg_id}"; $result = $db->sql_query($sql); $message_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$message_row) { trigger_error('NO_MESSAGE'); } // Update unread status update_unread_status($message_row['pm_unread'], $message_row['msg_id'], $user->data['user_id'], $folder_id); } $folder = get_folder($user->data['user_id'], $folder_id); $s_folder_options = $s_to_folder_options = ''; foreach ($folder as $f_id => $folder_ary) { $option = '<option' . (!in_array($f_id, array(PRIVMSGS_INBOX, PRIVMSGS_OUTBOX, PRIVMSGS_SENTBOX)) ? ' class="sep"' : '') . ' value="' . $f_id . '"' . ($f_id == $folder_id ? ' selected="selected"' : '') . '>' . $folder_ary['folder_name'] . ($folder_ary['unread_messages'] ? ' [' . $folder_ary['unread_messages'] . '] ' : '') . '</option>'; $s_to_folder_options .= $f_id != PRIVMSGS_OUTBOX && $f_id != PRIVMSGS_SENTBOX ? $option : ''; $s_folder_options .= $option; } clean_sentbox($folder[PRIVMSGS_SENTBOX]['num_messages']); // Header for message view - folder and so on $folder_status = get_folder_status($folder_id, $folder); $template->assign_vars(array('CUR_FOLDER_ID' => $folder_id, 'CUR_FOLDER_NAME' => $folder_status['folder_name'], 'NUM_NOT_MOVED' => $num_not_moved, 'NUM_REMOVED' => $num_removed, 'RELEASE_MESSAGE_INFO' => sprintf($user->lang['RELEASE_MESSAGES'], '<a href="' . $this->u_action . '&folder=' . $folder_id . '&release=1">', '</a>'), 'NOT_MOVED_MESSAGES' => $num_not_moved == 1 ? $user->lang['NOT_MOVED_MESSAGE'] : sprintf($user->lang['NOT_MOVED_MESSAGES'], $num_not_moved), 'RULE_REMOVED_MESSAGES' => $num_removed == 1 ? $user->lang['RULE_REMOVED_MESSAGE'] : sprintf($user->lang['RULE_REMOVED_MESSAGES'], $num_removed), 'S_FOLDER_OPTIONS' => $s_folder_options, 'S_TO_FOLDER_OPTIONS' => $s_to_folder_options, 'S_FOLDER_ACTION' => $this->u_action . '&action=view_folder', 'S_PM_ACTION' => $this->u_action . '&action=' . $action, 'U_INBOX' => $this->u_action . '&folder=inbox', 'U_OUTBOX' => $this->u_action . '&folder=outbox', 'U_SENTBOX' => $this->u_action . '&folder=sentbox', 'U_CREATE_FOLDER' => $this->u_action . '&mode=options', 'U_CURRENT_FOLDER' => $this->u_action . '&folder=' . $folder_id, 'S_IN_INBOX' => $folder_id == PRIVMSGS_INBOX ? true : false, 'S_IN_OUTBOX' => $folder_id == PRIVMSGS_OUTBOX ? true : false, 'S_IN_SENTBOX' => $folder_id == PRIVMSGS_SENTBOX ? true : false, 'FOLDER_STATUS' => $folder_status['message'], 'FOLDER_MAX_MESSAGES' => $folder_status['max'], 'FOLDER_CUR_MESSAGES' => $folder_status['cur'], 'FOLDER_REMAINING_MESSAGES' => $folder_status['remaining'], 'FOLDER_PERCENT' => $folder_status['percent'])); if ($action == 'view_folder') { include $phpbb_root_path . 'includes/ucp/ucp_pm_viewfolder.' . $phpEx; view_folder($id, $mode, $folder_id, $folder); $tpl_file = 'ucp_pm_viewfolder'; } else { if ($action == 'view_message') { $template->assign_vars(array('S_VIEW_MESSAGE' => true, 'MSG_ID' => $msg_id)); if (!$msg_id) { trigger_error('NO_MESSAGE'); } include $phpbb_root_path . 'includes/ucp/ucp_pm_viewmessage.' . $phpEx; view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row); $tpl_file = $view == 'print' ? 'ucp_pm_viewmessage_print' : 'ucp_pm_viewmessage'; } } break; default: trigger_error('NO_ACTION_MODE', E_USER_ERROR); break; } $template->assign_vars(array('L_TITLE' => $user->lang['UCP_PM_' . strtoupper($mode)], 'S_UCP_ACTION' => $this->u_action . (isset($action) ? "&action={$action}" : ''))); // Set desired template $this->tpl_name = $tpl_file; $this->page_title = 'UCP_PM_' . strtoupper($mode); }
// First Handle Mark actions and moving messages $submit_mark = isset($_POST['submit_mark']); $move_pm = isset($_POST['move_pm']); $mark_option = get_variable('mark_option', 'REQUEST', ''); $dest_folder = get_variable('dest_folder', 'REQUEST', PRIVMSGS_NO_BOX); // Is moving PM triggered through mark options? if (!in_array($mark_option, array('mark_important', 'delete_marked')) && $submit_mark) { $move_pm = true; $dest_folder = (int) $mark_option; $submit_mark = false; } // Move PM if ($move_pm) { $msg_ids = isset($_POST['marked_msg_id']) ? array_unique(array_map('intval', $_POST['marked_msg_id'])) : array(); $cur_folder_id = get_variable('cur_folder_id', 'POST', PRIVMSGS_NO_BOX, 'int'); if (move_pm($_CLASS['core_user']->data['user_id'], $_CLASS['core_user']->data['user_message_limit'], $msg_ids, $dest_folder, $cur_folder_id)) { // Return to folder view if single message moved if ($action === 'view_message') { $msg_id = 0; $folder_id = $cur_folder_id; $action = 'view_folder'; } } } // Message Mark Options if ($submit_mark) { $mark_option = get_variable('mark_option', 'POST'); $msg_ids = isset($_POST['marked_msg_id']) ? array_unique(array_map('intval', $_POST['marked_msg_id'])) : array(); $cur_folder_id = get_variable('cur_folder_id', 'POST', PRIVMSGS_INBOX, 'int'); switch ($mark_option) { case 'mark_read':
function ucp_pm($id, $mode) { global $_CLASS, $site_file_root, $config; $action = ''; if ($_CLASS['core_user']->data['user_id'] == ANONYMOUS) { trigger_error('NO_MESSAGE'); } // Is PM disabled? if (!$config['allow_privmsg']) { trigger_error('PM_DISABLED'); } // This is loaded 2x with drafts $_CLASS['core_user']->add_lang('posting', 'Forums'); $_CLASS['core_template']->assign('S_PRIVMSGS', true); // Folder directly specified? $folder_specified = request_var('folder', ''); if (!in_array($folder_specified, array('inbox', 'outbox', 'sentbox'))) { $folder_specified = (int) $folder_specified; } else { $folder_specified = $folder_specified == 'inbox' ? PRIVMSGS_INBOX : ($folder_specified == 'outbox' ? PRIVMSGS_OUTBOX : PRIVMSGS_SENTBOX); } if (!$folder_specified) { $mode = !$mode ? request_var('mode', 'view_messages') : $mode; } else { $mode = 'view_messages'; } require $site_file_root . 'includes/forums/functions_privmsgs.php'; $tpl_file = 'ucp_pm_' . $mode . '.html'; switch ($mode) { // New private messages popup case 'popup': $indox_link = generate_link('Control_Panel&i=pm&folder=inbox'); if ($_CLASS['core_user']->data['user_id'] != ANONYMOUS) { if ($_CLASS['core_user']->data['user_new_privmsg']) { $l_new_message = $_CLASS['core_user']->data['user_new_privmsg'] == 1 ? $_CLASS['core_user']->lang['YOU_NEW_PM'] : $_CLASS['core_user']->lang['YOU_NEW_PMS']; } else { $l_new_message = $_CLASS['core_user']->lang['YOU_NO_NEW_PM']; } } $_CLASS['core_template']->assign(array('MESSAGE' => $l_new_message, 'U_JS_RETURN_INBOX' => $indox_link, 'S_NOT_LOGGED_IN' => $_CLASS['core_user']->data['user_id'] == ANONYMOUS ? true : false, 'CLICK_TO_VIEW' => sprintf($_CLASS['core_user']->lang['CLICK_VIEW_PRIVMSG'], '<a href="' . $indox_link . '" onclick="jump_to_inbox();return false;" target="_new">', '</a>'), 'U_INBOX' => $indox_link)); break; // Compose message // Compose message case 'compose': $action = request_var('action', 'post'); get_folder($_CLASS['core_user']->data['user_id'], $folder); if (!$_CLASS['auth']->acl_get('u_sendpm')) { trigger_error('NO_AUTH_SEND_MESSAGE'); } require $site_file_root . 'modules/Control_Panel/ucp/ucp_pm_compose.php'; compose_pm($id, $mode, $action); $tpl_file = 'ucp_posting_body.html'; break; case 'options': $sql = 'SELECT group_message_limit FROM ' . GROUPS_TABLE . ' WHERE group_id = ' . $_CLASS['core_user']->data['user_group']; $result = $_CLASS['core_db']->query($sql); list($message_limit) = $_CLASS['core_db']->fetch_row_num($result); $_CLASS['core_db']->free_result($result); (int) ($_CLASS['core_user']->data['message_limit'] = !$message_limit ? $config['pm_max_msgs'] : $message_limit); get_folder($_CLASS['core_user']->data['user_id'], $folder); require $site_file_root . 'modules/Control_Panel/ucp/ucp_pm_options.php'; message_options($id, $mode, $global_privmsgs_rules, $global_rule_conditions); break; case 'drafts': get_folder($_CLASS['core_user']->data['user_id'], $folder); require $site_file_root . 'modules/Control_Panel/ucp/ucp_main.php'; $module = new ucp_main($id, $mode); unset($module); exit; break; case 'unread': case 'view_messages': $sql = 'SELECT group_message_limit FROM ' . GROUPS_TABLE . ' WHERE group_id = ' . $_CLASS['core_user']->data['user_group']; $result = $_CLASS['core_db']->query($sql); list($message_limit) = $_CLASS['core_db']->fetch_row_num($result); $_CLASS['core_db']->free_result($result); $_CLASS['core_user']->data['message_limit'] = !$message_limit ? $config['pm_max_msgs'] : $message_limit; if ($folder_specified) { $folder_id = $folder_specified; $action = 'view_folder'; } else { $folder_id = request_var('f', PRIVMSGS_INBOX); $action = request_var('action', 'view_folder'); } $msg_id = request_var('p', 0); $view = request_var('view', ''); if ($msg_id && $action == 'view_folder') { $action = 'view_message'; } if (!$_CLASS['auth']->acl_get('u_readpm')) { trigger_error('NO_AUTH_READ_MESSAGE'); } // First Handle Mark actions and moving messages // Move PM if (isset($_REQUEST['move_pm'])) { $move_msg_ids = isset($_POST['marked_msg_id']) ? array_map('intval', $_POST['marked_msg_id']) : array(); $dest_folder = request_var('dest_folder', PRIVMSGS_NO_BOX); $cur_folder_id = request_var('cur_folder_id', PRIVMSGS_NO_BOX); if (move_pm($_CLASS['core_user']->data['user_id'], $_CLASS['core_user']->data['message_limit'], $move_msg_ids, $dest_folder, $cur_folder_id)) { // Return to folder view if single message moved if ($action == 'view_message') { $msg_id = 0; $folder_id = request_var('cur_folder_id', PRIVMSGS_NO_BOX); $action = 'view_folder'; } } } // Message Mark Options if (isset($_REQUEST['submit_mark'])) { handle_mark_actions($_CLASS['core_user']->data['user_id'], request_var('mark_option', '')); } // If new messages arrived, place them into the appropiate folder $num_not_moved = 0; if ($_CLASS['core_user']->data['user_new_privmsg'] && $action == 'view_folder') { place_pm_into_folder($global_privmsgs_rules, request_var('release', 0)); $num_not_moved = $_CLASS['core_user']->data['user_new_privmsg']; } if (!$msg_id && $folder_id == PRIVMSGS_NO_BOX && $mode == 'unread') { $folder_id = PRIVMSGS_INBOX; } else { if ($msg_id && $folder_id == PRIVMSGS_NO_BOX) { $sql = 'SELECT folder_id FROM ' . FORUMS_PRIVMSGS_TO_TABLE . "\n\t\t\t\t\t\tWHERE msg_id = {$msg_id}\n\t\t\t\t\t\t\tAND user_id = " . $_CLASS['core_user']->data['user_id']; $result = $_CLASS['core_db']->query_limit($sql, 1); if (!($row = $_CLASS['core_db']->fetch_row_assoc($result))) { trigger_error('NO_MESSAGE'); } $folder_id = (int) $row['folder_id']; } } $message_row = array(); if ($mode == 'view_messages' && $action == 'view_message' && $msg_id) { // Get Message user want to see if ($view == 'next' || $view == 'previous') { $sql_condition = $view == 'next' ? '>' : '<'; $sql_ordering = $view == 'next' ? 'ASC' : 'DESC'; $sql = 'SELECT t.msg_id FROM ' . FORUMS_PRIVMSGS_TO_TABLE . ' t, ' . FORUMS_PRIVMSGS_TABLE . ' p, ' . FORUMS_PRIVMSGS_TABLE . " p2\n\t\t\t\t\t\t\tWHERE p2.msg_id = {$msg_id}\n\t\t\t\t\t\t\t\tAND t.folder_id = {$folder_id}\n\t\t\t\t\t\t\t\tAND t.user_id = " . $_CLASS['core_user']->data['user_id'] . "\n\t\t\t\t\t\t\t\tAND t.msg_id = p.msg_id\n\t\t\t\t\t\t\t\tAND p.message_time {$sql_condition} p2.message_time\n\t\t\t\t\t\t\tORDER BY p.message_time {$sql_ordering}"; $result = $_CLASS['core_db']->query_limit($sql, 1); if (!($row = $_CLASS['core_db']->fetch_row_assoc($result))) { $message = $view == 'next' ? 'NO_NEWER_PM' : 'NO_OLDER_PM'; trigger_error($message); } else { $msg_id = $row['msg_id']; } } $sql = 'SELECT t.*, p.*, u.* FROM ' . FORUMS_PRIVMSGS_TO_TABLE . ' t, ' . FORUMS_PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u WHERE t.user_id = ' . $_CLASS['core_user']->data['user_id'] . "\n\t\t\t\t\t\t\tAND p.author_id = u.user_id\n\t\t\t\t\t\t\tAND t.folder_id = {$folder_id}\n\t\t\t\t\t\t\tAND t.msg_id = p.msg_id\n\t\t\t\t\t\t\tAND p.msg_id = {$msg_id}"; $result = $_CLASS['core_db']->query_limit($sql, 1); if (!($message_row = $_CLASS['core_db']->fetch_row_assoc($result))) { trigger_error('NO_MESSAGE'); } // Update unread status update_unread_status($message_row['unread'], $message_row['msg_id'], $_CLASS['core_user']->data['user_id'], $folder_id); } get_folder($_CLASS['core_user']->data['user_id'], $folder, $folder_id); $s_folder_options = $s_to_folder_options = ''; foreach ($folder as $f_id => $folder_ary) { $option = '<option' . (!in_array($f_id, array(PRIVMSGS_INBOX, PRIVMSGS_OUTBOX, PRIVMSGS_SENTBOX)) ? ' class="blue"' : '') . ' value="' . $f_id . '"' . ($f_id == $folder_id && $mode != 'unread' || $f_id === 'unread' && $mode == 'unread' ? ' selected="selected"' : '') . '>' . $folder_ary['folder_name'] . ($folder_ary['unread_messages'] ? ' [' . $folder_ary['unread_messages'] . '] ' : '') . '</option>'; $s_to_folder_options .= $f_id != PRIVMSGS_OUTBOX && $f_id != PRIVMSGS_SENTBOX ? $option : ''; $s_folder_options .= $option; } clean_sentbox($folder[PRIVMSGS_SENTBOX]['num_messages']); // Header for message view - folder and so on $folder_status = get_folder_status($folder_id, $folder); $url = 'Control_Panel&i=' . $id; $_CLASS['core_template']->assign(array('CUR_FOLDER_ID' => $folder_id, 'CUR_FOLDER_NAME' => $folder_status['folder_name'], 'NUM_NOT_MOVED' => $num_not_moved, 'RELEASE_MESSAGE_INFO' => sprintf($_CLASS['core_user']->lang['RELEASE_MESSAGES'], '<a href="' . generate_link($url . '&folder=' . $folder_id . '&release=1') . '">', '</a>'), 'NOT_MOVED_MESSAGES' => $num_not_moved == 1 ? $_CLASS['core_user']->lang['NOT_MOVED_MESSAGE'] : sprintf($_CLASS['core_user']->lang['NOT_MOVED_MESSAGES'], $num_not_moved), 'S_FOLDER_OPTIONS' => $s_folder_options, 'S_TO_FOLDER_OPTIONS' => $s_to_folder_options, 'S_FOLDER_ACTION' => generate_link($url . '&mode=view_messages&action=view_folder'), 'S_PM_ACTION' => generate_link("{$url}&mode={$mode}&action={$action}"), 'U_INBOX' => generate_link($url . '&folder=inbox'), 'U_OUTBOX' => generate_link($url . '&folder=outbox'), 'U_SENTBOX' => generate_link($url . '&folder=sentbox'), 'U_CREATE_FOLDER' => generate_link($url . '&mode=options'), 'S_IN_INBOX' => $folder_id == PRIVMSGS_INBOX ? true : false, 'S_IN_OUTBOX' => $folder_id == PRIVMSGS_OUTBOX ? true : false, 'S_IN_SENTBOX' => $folder_id == PRIVMSGS_SENTBOX ? true : false, 'FOLDER_STATUS' => $folder_status['message'], 'FOLDER_MAX_MESSAGES' => $folder_status['max'], 'FOLDER_CUR_MESSAGES' => $folder_status['cur'], 'FOLDER_REMAINING_MESSAGES' => $folder_status['remaining'], 'FOLDER_PERCENT' => $folder_status['percent'])); $_CLASS['core_template']->assign('S_VIEW_MESSAGE', false); if ($mode == 'unread' || $action == 'view_folder') { require $site_file_root . 'modules/Control_Panel/ucp/ucp_pm_viewfolder.php'; view_folder($id, $mode, $folder_id, $folder, $mode == 'unread' ? 'unread' : 'folder'); $tpl_file = 'ucp_pm_viewfolder.html'; } else { if ($action == 'view_message') { $_CLASS['core_template']->assign(array('S_VIEW_MESSAGE' => true, 'MSG_ID' => $msg_id)); if (!$msg_id) { trigger_error('NO_MESSAGE'); } require $site_file_root . 'modules/Control_Panel/ucp/ucp_pm_viewmessage.php'; view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row); $tpl_file = $view == 'print' ? 'ucp_pm_viewmessage_print.html' : 'ucp_pm_viewmessage.html'; } } break; default: trigger_error('NO_ACTION_MODE'); break; } $_CLASS['core_template']->assign(array('L_TITLE' => $_CLASS['core_user']->lang['UCP_PM_' . strtoupper($mode)], 'S_UCP_ACTION' => generate_link("Control_Panel&i={$id}&mode={$mode}" . (isset($action) ? "&action={$action}" : '')))); if (isset($view) && $view == 'print' || $mode == 'popup') { //page_header($page_title); $_CLASS['core_template']->display('modules/Control_Panel/' . $tpl_file); $_CLASS['core_display']->display_footer(); } else { $this->display($_CLASS['core_user']->lang['UCP_PM'], $tpl_file); } }
} if ($delete) { $pmmode = 'delete_pms'; $delete = false; } if ($savemails) { $pmmode = 'savemails'; } //--------------------------------- // // save marked // //--------------------------------- if ($pmmode == 'move_pms') { // move pm to save folder move_pm($mark_ids, $view_user_id, $folder_id, $to_folder); // return to box display if (!defined('IN_PCP')) { $return_path = append_sid("{$main_pgm}&folder={$to_folder}&sid=" . $userdata['session_id']); redirect($return_path); exit; } else { $folder_id = $to_folder; $folder_main = $folder_id; if (!empty($folders['main'][$folder_id])) { $folder_main = $folders['main'][$folder_id]; } $pmmode = ''; // rebuild the request switch ($folder_main) { case INBOX:
function message_options($id, $mode, $global_privmsgs_rules, $global_rule_conditions) { global $_CLASS, $config; $redirect_url = generate_link('Control_Panel&i=pm&mode=options'); $_CLASS['core_template']->assign_array(array('ERROR_MESSAGE' => false, 'S_RULE_DEFINED' => false, 'S_COND_DEFINED' => false, 'NONE_CONDITION' => false, 'S_ACTION_DEFINED' => false, 'NOTIFICATION_MESSAGE' => false, 'rule' => false)); // Change "full folder" setting - what to do if folder is full if (isset($_POST['fullfolder'])) { $full_action = request_var('full_action', 0); $set_folder_id = 0; switch ($full_action) { case 1: $set_folder_id = FULL_FOLDER_DELETE; break; case 2: $set_folder_id = request_var('full_move_to', PRIVMSGS_INBOX); break; case 3: $set_folder_id = FULL_FOLDER_HOLD; break; default: $full_action = 0; break; } if ($full_action) { $sql = 'UPDATE ' . USERS_TABLE . ' SET user_full_folder = ' . $set_folder_id . ' WHERE user_id = ' . $_CLASS['core_user']->data['user_id']; $_CLASS['core_db']->query($sql); $_CLASS['core_user']->data['user_full_folder'] = $set_folder_id; $message = $_CLASS['core_user']->lang['FULL_FOLDER_OPTION_CHANGED'] . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_UCP'], '<a href="' . $redirect_url . '">', '</a>'); $_CLASS['core_display']->meta_refresh(3, $redirect_url); trigger_error($message); } } // Add Folder if (isset($_POST['addfolder'])) { $folder_name = request_var('foldername', ''); if ($folder_name) { $sql = 'SELECT folder_name FROM ' . FORUMS_PRIVMSGS_FOLDER_TABLE . "\n\t\t\t\tWHERE folder_name = '" . $_CLASS['core_db']->escape($folder_name) . "'\n\t\t\t\t\tAND user_id = " . $_CLASS['core_user']->data['user_id']; $result = $_CLASS['core_db']->query_limit($sql, 1); $row = $_CLASS['core_db']->fetch_row_assoc($result); $_CLASS['core_db']->free_result($result); if ($row) { trigger_error(sprintf($_CLASS['core_user']->lang['FOLDER_NAME_EXIST'], $folder_name)); } $sql = 'SELECT COUNT(*) as num_folder FROM ' . FORUMS_PRIVMSGS_FOLDER_TABLE . ' WHERE user_id = ' . $_CLASS['core_user']->data['user_id']; $result = $_CLASS['core_db']->query($sql); list($count) = $_CLASS['core_db']->fetch_row_num($result); $_CLASS['core_db']->free_result($result); if ($count >= $config['pm_max_boxes']) { trigger_error('MAX_FOLDER_REACHED'); } $sql_array = array('user_id' => (int) $_CLASS['core_user']->data['user_id'], 'folder_name' => $folder_name, 'pm_count' => 0); $_CLASS['core_db']->query('INSERT INTO ' . FORUMS_PRIVMSGS_FOLDER_TABLE . ' ' . $_CLASS['core_db']->sql_build_array('INSERT', $sql_array)); $message = $_CLASS['core_user']->lang['FOLDER_ADDED'] . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_UCP'], '<a href="' . $redirect_url . '">', '</a>'); $_CLASS['core_display']->meta_refresh(3, $redirect_url); trigger_error($message); } } // Rename folder if (isset($_POST['rename_folder'])) { $new_folder_name = request_var('new_folder_name', ''); $rename_folder_id = request_var('rename_folder_id', 0); if (!$new_folder_name) { trigger_error('NO_NEW_FOLDER_NAME'); } // Select custom folder $sql = 'SELECT folder_name, pm_count FROM ' . FORUMS_PRIVMSGS_FOLDER_TABLE . ' WHERE user_id = ' . $_CLASS['core_user']->data['user_id'] . "\n\t\t\t\tAND folder_id = {$rename_folder_id}"; $result = $_CLASS['core_db']->query_limit($sql, 1); $folder_row = $_CLASS['core_db']->fetch_row_assoc($result); $_CLASS['core_db']->free_result($result); if (!$folder_row) { trigger_error('CANNOT_RENAME_FOLDER'); } $sql = 'SELECT folder_name FROM ' . FORUMS_PRIVMSGS_FOLDER_TABLE . "\n\t\t\tWHERE folder_name = '" . $_CLASS['core_db']->escape($new_folder_name) . "'\n\t\t\t\tAND user_id = " . $_CLASS['core_user']->data['user_id']; $result = $_CLASS['core_db']->query_limit($sql, 1); $row = $_CLASS['core_db']->fetch_row_assoc($result); $_CLASS['core_db']->free_result($result); if ($row) { trigger_error(sprintf($_CLASS['core_user']->lang['FOLDER_NAME_EXIST'], $new_folder_name)); } $sql = 'UPDATE ' . FORUMS_PRIVMSGS_FOLDER_TABLE . " \n\t\t\tSET folder_name = '" . $_CLASS['core_db']->escape($new_folder_name) . "'\n\t\t\tWHERE folder_id = {$rename_folder_id}\n\t\t\t\tAND user_id = " . $_CLASS['core_user']->data['user_id']; $_CLASS['core_db']->query($sql); $message = $_CLASS['core_user']->lang['FOLDER_RENAMED'] . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_UCP'], '<a href="' . $redirect_url . '">', '</a>'); $_CLASS['core_display']->meta_refresh(3, $redirect_url); trigger_error($message); } // Remove Folder if (isset($_POST['remove_folder'])) { $remove_folder_id = request_var('remove_folder_id', 0); // Default to "move all messages to inbox" $remove_action = request_var('remove_action', 1); $move_to = request_var('move_to', PRIVMSGS_INBOX); // Move to same folder? if ($remove_action == 1 && $remove_folder_id === $move_to) { trigger_error('CANNOT_MOVE_TO_SAME_FOLDER'); } // Select custom folder $sql = 'SELECT folder_name, pm_count FROM ' . FORUMS_PRIVMSGS_FOLDER_TABLE . ' WHERE user_id = ' . $_CLASS['core_user']->data['user_id'] . "\n\t\t\t\tAND folder_id = {$remove_folder_id}"; $result = $_CLASS['core_db']->query($sql); $folder_row = $_CLASS['core_db']->fetch_row_assoc($result); $_CLASS['core_db']->free_result($result); if (!$folder_row) { trigger_error('CANNOT_REMOVE_FOLDER'); } $hidden_fields = array('remove_folder_id' => $remove_folder_id, 'remove_folder' => 1, 'remove_action' => $remove_action, 'move_to' => $move_to); // Do we need to confirm? if (display_confirmation($_CLASS['core_user']->get_lang('REMOVE_FOLDER'), generate_hidden_fields($hidden_fields))) { // Gather message ids $sql = 'SELECT msg_id FROM ' . FORUMS_PRIVMSGS_TO_TABLE . ' WHERE user_id = ' . $_CLASS['core_user']->data['user_id'] . "\n\t\t\t\t\tAND folder_id = {$remove_folder_id}"; $result = $_CLASS['core_db']->query($sql); $msg_ids = array(); while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) { $msg_ids[] = (int) $row['msg_id']; } $_CLASS['core_db']->free_result($result); // First of all, copy all messages to another folder... or delete all messages switch ($remove_action) { // Move Messages case 1: $message_limit = $_CLASS['core_user']->data['user_message_limit'] ? $_CLASS['core_user']->data['user_message_limit'] : $config['pm_max_msgs']; $num_moved = move_pm($_CLASS['core_user']->data['user_id'], $message_limit, $msg_ids, $move_to, $remove_folder_id); // Something went wrong, only partially moved? if ($num_moved != $folder_row['pm_count']) { trigger_error(sprintf($_CLASS['core_user']->lang['MOVE_PM_ERROR'], $num_moved, $folder_row['pm_count'])); } break; // Remove Messages // Remove Messages case 2: delete_pm($_CLASS['core_user']->data['user_id'], $msg_ids, $remove_folder_id); break; } // Remove folder $sql = 'DELETE FROM ' . FORUMS_PRIVMSGS_FOLDER_TABLE . ' WHERE user_id = ' . $_CLASS['core_user']->data['user_id'] . "\n\t\t\t\t\tAND folder_id = {$remove_folder_id}"; $_CLASS['core_db']->query($sql); // Check full folder option. If the removed folder has been specified as destination switch back to inbox if ($_CLASS['core_user']->data['user_full_folder'] == $remove_folder_id) { $sql = 'UPDATE ' . USERS_TABLE . ' SET user_full_folder = ' . PRIVMSGS_INBOX . ' WHERE user_id = ' . $_CLASS['core_user']->data['user_id']; $_CLASS['core_db']->query($sql); $_CLASS['core_user']->data['user_full_folder'] = PRIVMSGS_INBOX; } $meta_info = generate_link('Control_Panel&i=pm&mode=' . $mode); $message = $_CLASS['core_user']->lang['FOLDER_REMOVED']; $_CLASS['core_display']->meta_refresh(3, $meta_info); $message .= '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_UCP'], '<a href="' . $meta_info . '">', '</a>'); trigger_error($message); } } // Add Rule if (isset($_POST['add_rule'])) { $check_option = request_var('check_option', 0); $rule_option = request_var('rule_option', 0); $cond_option = request_var('cond_option', ''); $action_option = explode('|', request_var('action_option', '')); $rule_string = $cond_option != 'none' ? request_var('rule_string', '') : ''; $rule_user_id = $cond_option != 'none' ? request_var('rule_user_id', 0) : 0; $rule_group_id = $cond_option != 'none' ? request_var('rule_group_id', 0) : 0; $action = (int) $action_option[0]; $folder_id = (int) $action_option[1]; if (!$action || !$check_option || !$rule_option || !$cond_option || $cond_option != 'none' && !$rule_string) { trigger_error('RULE_NOT_DEFINED'); } if ($cond_option == 'user' && !$rule_user_id || $cond_option == 'group' && !$rule_group_id) { trigger_error('RULE_NOT_DEFINED'); } $rule_ary = array('user_id' => $_CLASS['core_user']->data['user_id'], 'rule_check' => $check_option, 'rule_connection' => $rule_option, 'rule_string' => $rule_string, 'rule_user_id' => $rule_user_id, 'rule_group_id' => $rule_group_id, 'rule_action' => $action, 'rule_folder_id' => $folder_id); $sql = 'SELECT rule_id FROM ' . FORUMS_PRIVMSGS_RULES_TABLE . ' WHERE ' . $_CLASS['core_db']->sql_build_array('SELECT', $rule_ary); $result = $_CLASS['core_db']->query($sql, 1); $row = $_CLASS['core_db']->fetch_row_assoc($result); $_CLASS['core_db']->free_result($result); if ($row) { trigger_error('RULE_ALREADY_DEFINED'); } $sql = 'INSERT INTO ' . FORUMS_PRIVMSGS_RULES_TABLE . ' ' . $_CLASS['core_db']->sql_build_array('INSERT', $rule_ary); $_CLASS['core_db']->query($sql); $message = $_CLASS['core_user']->lang['RULE_ADDED'] . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_UCP'], '<a href="' . $redirect_url . '">', '</a>'); $_CLASS['core_display']->meta_refresh(3, $redirect_url); trigger_error($message); } // Remove Rule if (isset($_POST['delete_rule']) && !isset($_POST['cancel'])) { $delete_id = array_map('intval', array_keys($_POST['delete_rule'])); $delete_id = (int) $delete_id[0]; if (!$delete_id) { redirect(generate_link('Control_Panel&i=pm&mode=' . $mode)); } $s_hidden_fields = '<input type="hidden" name="delete_rule[' . $delete_id . ']" value="1" />'; // Do we need to confirm ? if (confirm_box(true)) { $sql = 'DELETE FROM ' . FORUMS_PRIVMSGS_RULES_TABLE . ' WHERE user_id = ' . $_CLASS['core_user']->data['user_id'] . "\n\t\t\t\t\tAND rule_id = {$delete_id}"; $_CLASS['core_db']->query($sql); $meta_info = generate_link("Control_Panel{$SID}&i=pm&mode={$mode}"); $message = $_CLASS['core_user']->lang['RULE_DELETED']; $_CLASS['core_display']->meta_refresh(3, $meta_info); $message .= '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_UCP'], '<a href="' . $meta_info . '">', '</a>'); trigger_error($message); } else { confirm_box(false, 'DELETE_RULE', $s_hidden_fields); } } $folder = array(); $message_limit = $_CLASS['core_user']->data['user_message_limit'] ? $config['pm_max_msgs'] : $_CLASS['core_user']->data['user_message_limit']; $sql = 'SELECT COUNT(*) as num_messages FROM ' . FORUMS_PRIVMSGS_TO_TABLE . ' WHERE user_id = ' . $_CLASS['core_user']->data['user_id'] . ' AND folder_id = ' . PRIVMSGS_INBOX; $result = $_CLASS['core_db']->query($sql); list($num_messages) = $_CLASS['core_db']->fetch_row_num($result); $_CLASS['core_db']->free_result($result); $folder[PRIVMSGS_INBOX] = array('folder_name' => $_CLASS['core_user']->get_lang('PM_INBOX'), 'message_status' => sprintf($_CLASS['core_user']->lang['FOLDER_MESSAGE_STATUS'], $num_messages, $message_limit)); $sql = 'SELECT folder_id, folder_name, pm_count FROM ' . FORUMS_PRIVMSGS_FOLDER_TABLE . ' WHERE user_id = ' . $_CLASS['core_user']->data['user_id']; $result = $_CLASS['core_db']->query($sql); $num_user_folder = 0; while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) { $num_user_folder++; $folder[$row['folder_id']] = array('folder_name' => $row['folder_name'], 'message_status' => sprintf($_CLASS['core_user']->lang['FOLDER_MESSAGE_STATUS'], $row['pm_count'], $message_limit)); } $_CLASS['core_db']->free_result($result); $s_full_folder_options = $s_to_folder_options = $s_folder_options = ''; // temp $_CLASS['core_user']->data['user_full_folder'] = FULL_FOLDER_NONE; if ($_CLASS['core_user']->data['user_full_folder'] == FULL_FOLDER_NONE) { // -3 here to let the correct folder id be selected $to_folder_id = $config['full_folder_action'] - 3; } else { $to_folder_id = $_CLASS['core_user']->data['user_full_folder']; } foreach ($folder as $folder_id => $folder_ary) { $s_full_folder_options .= '<option value="' . $folder_id . '"' . ($_CLASS['core_user']->data['user_full_folder'] == $folder_id ? ' selected="selected"' : '') . '>' . $folder_ary['folder_name'] . ' (' . $folder_ary['message_status'] . ')</option>'; //$s_to_folder_options .= '<option value="' . $folder_id . '"' . (($to_folder_id == $folder_id) ? ' selected="selected"' : '') . '>' . $folder_ary['folder_name'] . ' (' . $folder_ary['message_status'] . ')</option>'; $s_to_folder_options .= '<option value="' . $folder_id . '">' . $folder_ary['folder_name'] . ' (' . $folder_ary['message_status'] . ')</option>'; if ($folder_id != PRIVMSGS_INBOX) { $s_folder_options .= '<option value="' . $folder_id . '">' . $folder_ary['folder_name'] . ' (' . $folder_ary['message_status'] . ')</option>'; } } $s_delete_checked = $_CLASS['core_user']->data['user_full_folder'] == FULL_FOLDER_DELETE ? ' checked="checked"' : ''; $s_hold_checked = $_CLASS['core_user']->data['user_full_folder'] == FULL_FOLDER_HOLD ? ' checked="checked"' : ''; $s_move_checked = $_CLASS['core_user']->data['user_full_folder'] >= 0 ? ' checked="checked"' : ''; if ($_CLASS['core_user']->data['user_full_folder'] == FULL_FOLDER_NONE) { switch ($config['full_folder_action']) { case 1: $s_delete_checked = ' checked="checked"'; break; case 2: $s_hold_checked = ' checked="checked"'; break; } } $_CLASS['core_template']->assign_array(array('S_FULL_FOLDER_OPTIONS' => $s_full_folder_options, 'S_TO_FOLDER_OPTIONS' => $s_to_folder_options, 'S_FOLDER_OPTIONS' => $s_folder_options, 'S_DELETE_CHECKED' => $s_delete_checked, 'S_HOLD_CHECKED' => $s_hold_checked, 'S_MOVE_CHECKED' => $s_move_checked, 'S_MAX_FOLDER_REACHED' => $num_user_folder >= $config['pm_max_boxes'] ? true : false, 'DEFAULT_ACTION' => $config['full_folder_action'] == 1 ? $_CLASS['core_user']->lang['DELETE_OLDEST_MESSAGES'] : $_CLASS['core_user']->lang['HOLD_NEW_MESSAGES'], 'U_FIND_USERNAME' => generate_link('Members_List&mode=searchuser&form=ucp&field=rule_string'))); $rule_lang = $action_lang = $check_lang = array(); // Build all three language arrays preg_replace('#^((RULE|ACTION|CHECK)_([A-Z0-9_]+))$#e', "\${strtolower('\\2') . '_lang'}[constant('\\1')] = \$_CLASS['core_user']->lang['PM_\\2']['\\3']", array_keys(get_defined_constants())); /* Rule Ordering: -> CHECK_* -> RULE_* [IN $global_privmsgs_rules:CHECK_*] -> [IF $rule_conditions[RULE_*] [|text|bool|user|group|own_group]] -> ACTION_* */ $check_option = request_var('check_option', 0); $rule_option = request_var('rule_option', 0); $cond_option = request_var('cond_option', ''); $action_option = request_var('action_option', ''); $back = isset($_REQUEST['back']) ? request_var('back', '') : array(); if (!empty($back)) { if ($action_option) { $action_option = ''; } elseif ($cond_option) { $cond_option = ''; } elseif ($rule_option) { $rule_option = 0; } elseif ($check_option) { $check_option = 0; } } if (isset($back['action']) && $cond_option == 'none') { $back['cond'] = true; } // Check define_check_option($check_option && !isset($back['rule']) ? true : false, $check_option, $check_lang); if ($check_option && !isset($back['rule'])) { define_rule_option($rule_option && !isset($back['cond']) ? true : false, $rule_option, $rule_lang, $global_privmsgs_rules[$check_option]); } if ($rule_option && !isset($back['cond'])) { if (!isset($global_rule_conditions[$rule_option])) { $cond_option = 'none'; $_CLASS['core_template']->assign('NONE_CONDITION', true); } else { define_cond_option($cond_option && !isset($back['action']) ? true : false, $cond_option, $rule_option, $global_rule_conditions); } } if ($cond_option && !isset($back['action'])) { define_action_option(false, $action_option, $action_lang, $folder); } show_defined_rules($_CLASS['core_user']->data['user_id'], $check_lang, $rule_lang, $action_lang, $folder); }
} $recips = array(); while ($row = $db->sql_fetchrow($result)) { $recips[] = $row; } if (empty($recips)) { message_die(GENERAL_ERROR, _lang('No_post_id')); } //--------------------------------- // // move // //--------------------------------- if ($pmmode == 'move_pm') { // move pm to save folder move_pm($privmsg_recip_id, $view_user_id, $folder_id, $to_folder); // return to box display if (!defined('IN_PCP')) { $return_path = append_sid("{$main_pgm}&folder={$to_folder}"); redirect($return_path); exit; } else { $pmmode = 'view'; $folder_id = $to_folder; $folder_main = $folder_id; if (!empty($folders['main'][$folder_id])) { $folder_main = $folders['main'][$folder_id]; } } } //---------------------------------