PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/phpBB/includes/ucp/ucp_pm.php

https://github.com/naderman/phpbb-orchestra
PHP | 416 lines | 294 code | 72 blank | 50 comment | 64 complexity | 2162d0d1705e0959c098aa45d1ceb29e MD5 | raw file
  1. <?php
  2. /**
  3. * @package ucp
  4. * @version $Id$
  5. * @copyright (c) 2005 phpBB Group
  6. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  7. *
  8. */
  9. /**
  10. * @ignore
  11. */
  12. if (!defined('IN_PHPBB'))
  13. {
  14. exit;
  15. }
  16. /**
  17. * Private Message Class
  18. *
  19. * $_REQUEST['folder'] display folder with the id used
  20. * $_REQUEST['folder'] inbox|outbox|sentbox display folder with the associated name
  21. *
  22. * Display Messages (default to inbox) - mode=view
  23. * Display single message - mode=view&p=[msg_id] or &p=[msg_id] (short linkage)
  24. *
  25. * if the folder id with (&f=[folder_id]) is used when displaying messages, one query will be saved. If it is not used, phpBB needs to grab
  26. * the folder id first in order to display the input boxes and folder names and such things. ;) phpBB always checks this against the database to make
  27. * sure the user is able to view the message.
  28. *
  29. * Composing Messages (mode=compose):
  30. * To specific user (u=[user_id])
  31. * To specific group (g=[group_id])
  32. * Quoting a post (action=quotepost&p=[post_id])
  33. * Quoting a PM (action=quote&p=[msg_id])
  34. * Forwarding a PM (action=forward&p=[msg_id])
  35. *
  36. * @package ucp
  37. */
  38. class ucp_pm
  39. {
  40. var $u_action;
  41. function main($id, $mode)
  42. {
  43. global $user, $template, $phpbb_root_path, $auth, $phpEx, $db, $config;
  44. if (!$user->data['is_registered'])
  45. {
  46. trigger_error('NO_MESSAGE');
  47. }
  48. // Is PM disabled?
  49. if (!$config['allow_privmsg'])
  50. {
  51. trigger_error('PM_DISABLED');
  52. }
  53. $user->add_lang('posting');
  54. $template->assign_var('S_PRIVMSGS', true);
  55. // Folder directly specified?
  56. $folder_specified = request_var('folder', '');
  57. if (!in_array($folder_specified, array('inbox', 'outbox', 'sentbox')))
  58. {
  59. $folder_specified = (int) $folder_specified;
  60. }
  61. else
  62. {
  63. $folder_specified = ($folder_specified == 'inbox') ? PRIVMSGS_INBOX : (($folder_specified == 'outbox') ? PRIVMSGS_OUTBOX : PRIVMSGS_SENTBOX);
  64. }
  65. if (!$folder_specified)
  66. {
  67. $mode = (!$mode) ? request_var('mode', 'view') : $mode;
  68. }
  69. else
  70. {
  71. $mode = 'view';
  72. }
  73. include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
  74. switch ($mode)
  75. {
  76. // New private messages popup
  77. case 'popup':
  78. $l_new_message = '';
  79. if ($user->data['is_registered'])
  80. {
  81. if ($user->data['user_new_privmsg'])
  82. {
  83. $l_new_message = ($user->data['user_new_privmsg'] == 1) ? $user->lang['YOU_NEW_PM'] : $user->lang['YOU_NEW_PMS'];
  84. }
  85. else
  86. {
  87. $l_new_message = $user->lang['YOU_NO_NEW_PM'];
  88. }
  89. }
  90. $template->assign_vars(array(
  91. 'MESSAGE' => $l_new_message,
  92. 'S_NOT_LOGGED_IN' => ($user->data['user_id'] == ANONYMOUS) ? true : false,
  93. 'CLICK_TO_VIEW' => sprintf($user->lang['CLICK_VIEW_PRIVMSG'], '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;folder=inbox') . '" onclick="jump_to_inbox(this.href); return false;">', '</a>'),
  94. 'U_INBOX' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;folder=inbox'),
  95. 'UA_INBOX' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=inbox', false))
  96. );
  97. $tpl_file = 'ucp_pm_popup';
  98. break;
  99. // Compose message
  100. case 'compose':
  101. $action = request_var('action', 'post');
  102. $user_folders = get_folder($user->data['user_id']);
  103. if (!$auth->acl_get('u_sendpm'))
  104. {
  105. // trigger_error('NO_AUTH_SEND_MESSAGE');
  106. $template->assign_vars(array(
  107. 'S_NO_AUTH_SEND_MESSAGE' => true,
  108. 'S_COMPOSE_PM_VIEW' => true,
  109. ));
  110. $tpl_file = 'ucp_pm_viewfolder';
  111. break;
  112. }
  113. include($phpbb_root_path . 'includes/ucp/ucp_pm_compose.' . $phpEx);
  114. compose_pm($id, $mode, $action, $user_folders);
  115. $tpl_file = 'posting_body';
  116. break;
  117. case 'options':
  118. set_user_message_limit();
  119. get_folder($user->data['user_id']);
  120. include($phpbb_root_path . 'includes/ucp/ucp_pm_options.' . $phpEx);
  121. message_options($id, $mode, $global_privmsgs_rules, $global_rule_conditions);
  122. $tpl_file = 'ucp_pm_options';
  123. break;
  124. case 'drafts':
  125. get_folder($user->data['user_id']);
  126. $this->p_name = 'pm';
  127. // Call another module... please do not try this at home... Hoochie Coochie Man
  128. include($phpbb_root_path . 'includes/ucp/ucp_main.' . $phpEx);
  129. $module = new ucp_main($this);
  130. $module->u_action = $this->u_action;
  131. $module->main($id, $mode);
  132. $this->tpl_name = $module->tpl_name;
  133. $this->page_title = 'UCP_PM_DRAFTS';
  134. unset($module);
  135. return;
  136. break;
  137. case 'view':
  138. set_user_message_limit();
  139. if ($folder_specified)
  140. {
  141. $folder_id = $folder_specified;
  142. $action = 'view_folder';
  143. }
  144. else
  145. {
  146. $folder_id = request_var('f', PRIVMSGS_NO_BOX);
  147. $action = request_var('action', 'view_folder');
  148. }
  149. $msg_id = request_var('p', 0);
  150. $view = request_var('view', '');
  151. // View message if specified
  152. if ($msg_id)
  153. {
  154. $action = 'view_message';
  155. }
  156. if (!$auth->acl_get('u_readpm'))
  157. {
  158. trigger_error('NO_AUTH_READ_MESSAGE');
  159. }
  160. // Do not allow hold messages to be seen
  161. if ($folder_id == PRIVMSGS_HOLD_BOX)
  162. {
  163. trigger_error('NO_AUTH_READ_HOLD_MESSAGE');
  164. }
  165. // First Handle Mark actions and moving messages
  166. $submit_mark = (isset($_POST['submit_mark'])) ? true : false;
  167. $move_pm = (isset($_POST['move_pm'])) ? true : false;
  168. $mark_option = request_var('mark_option', '');
  169. $dest_folder = request_var('dest_folder', PRIVMSGS_NO_BOX);
  170. // Is moving PM triggered through mark options?
  171. if (!in_array($mark_option, array('mark_important', 'delete_marked')) && $submit_mark)
  172. {
  173. $move_pm = true;
  174. $dest_folder = (int) $mark_option;
  175. $submit_mark = false;
  176. }
  177. // Move PM
  178. if ($move_pm)
  179. {
  180. $move_msg_ids = (isset($_POST['marked_msg_id'])) ? request_var('marked_msg_id', array(0)) : array();
  181. $cur_folder_id = request_var('cur_folder_id', PRIVMSGS_NO_BOX);
  182. if (move_pm($user->data['user_id'], $user->data['message_limit'], $move_msg_ids, $dest_folder, $cur_folder_id))
  183. {
  184. // Return to folder view if single message moved
  185. if ($action == 'view_message')
  186. {
  187. $msg_id = 0;
  188. $folder_id = request_var('cur_folder_id', PRIVMSGS_NO_BOX);
  189. $action = 'view_folder';
  190. }
  191. }
  192. }
  193. // Message Mark Options
  194. if ($submit_mark)
  195. {
  196. handle_mark_actions($user->data['user_id'], $mark_option);
  197. }
  198. // If new messages arrived, place them into the appropriate folder
  199. $num_not_moved = $num_removed = 0;
  200. $release = request_var('release', 0);
  201. if ($user->data['user_new_privmsg'] && $action == 'view_folder')
  202. {
  203. $return = place_pm_into_folder($global_privmsgs_rules, $release);
  204. $num_not_moved = $return['not_moved'];
  205. $num_removed = $return['removed'];
  206. }
  207. if (!$msg_id && $folder_id == PRIVMSGS_NO_BOX)
  208. {
  209. $folder_id = PRIVMSGS_INBOX;
  210. }
  211. else if ($msg_id && $folder_id == PRIVMSGS_NO_BOX)
  212. {
  213. $sql = 'SELECT folder_id
  214. FROM ' . PRIVMSGS_TO_TABLE . "
  215. WHERE msg_id = $msg_id
  216. AND folder_id <> " . PRIVMSGS_NO_BOX . '
  217. AND user_id = ' . $user->data['user_id'];
  218. $result = $db->sql_query($sql);
  219. $row = $db->sql_fetchrow($result);
  220. $db->sql_freeresult($result);
  221. if (!$row)
  222. {
  223. trigger_error('NO_MESSAGE');
  224. }
  225. $folder_id = (int) $row['folder_id'];
  226. }
  227. $message_row = array();
  228. if ($action == 'view_message' && $msg_id)
  229. {
  230. // Get Message user want to see
  231. if ($view == 'next' || $view == 'previous')
  232. {
  233. $sql_condition = ($view == 'next') ? '>' : '<';
  234. $sql_ordering = ($view == 'next') ? 'ASC' : 'DESC';
  235. $sql = 'SELECT t.msg_id
  236. FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . PRIVMSGS_TABLE . " p2
  237. WHERE p2.msg_id = $msg_id
  238. AND t.folder_id = $folder_id
  239. AND t.user_id = " . $user->data['user_id'] . "
  240. AND t.msg_id = p.msg_id
  241. AND p.message_time $sql_condition p2.message_time
  242. ORDER BY p.message_time $sql_ordering";
  243. $result = $db->sql_query_limit($sql, 1);
  244. $row = $db->sql_fetchrow($result);
  245. $db->sql_freeresult($result);
  246. if (!$row)
  247. {
  248. $message = ($view == 'next') ? 'NO_NEWER_PM' : 'NO_OLDER_PM';
  249. trigger_error($message);
  250. }
  251. else
  252. {
  253. $msg_id = $row['msg_id'];
  254. }
  255. }
  256. $sql = 'SELECT t.*, p.*, u.*
  257. FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u
  258. WHERE t.user_id = ' . $user->data['user_id'] . "
  259. AND p.author_id = u.user_id
  260. AND t.folder_id = $folder_id
  261. AND t.msg_id = p.msg_id
  262. AND p.msg_id = $msg_id";
  263. $result = $db->sql_query($sql);
  264. $message_row = $db->sql_fetchrow($result);
  265. $db->sql_freeresult($result);
  266. if (!$message_row)
  267. {
  268. trigger_error('NO_MESSAGE');
  269. }
  270. // Update unread status
  271. update_unread_status($message_row['pm_unread'], $message_row['msg_id'], $user->data['user_id'], $folder_id);
  272. }
  273. $folder = get_folder($user->data['user_id'], $folder_id);
  274. $s_folder_options = $s_to_folder_options = '';
  275. foreach ($folder as $f_id => $folder_ary)
  276. {
  277. $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>';
  278. $s_to_folder_options .= ($f_id != PRIVMSGS_OUTBOX && $f_id != PRIVMSGS_SENTBOX) ? $option : '';
  279. $s_folder_options .= $option;
  280. }
  281. clean_sentbox($folder[PRIVMSGS_SENTBOX]['num_messages']);
  282. // Header for message view - folder and so on
  283. $folder_status = get_folder_status($folder_id, $folder);
  284. $template->assign_vars(array(
  285. 'CUR_FOLDER_ID' => $folder_id,
  286. 'CUR_FOLDER_NAME' => $folder_status['folder_name'],
  287. 'NUM_NOT_MOVED' => $num_not_moved,
  288. 'NUM_REMOVED' => $num_removed,
  289. 'RELEASE_MESSAGE_INFO' => sprintf($user->lang['RELEASE_MESSAGES'], '<a href="' . $this->u_action . '&amp;folder=' . $folder_id . '&amp;release=1">', '</a>'),
  290. 'NOT_MOVED_MESSAGES' => ($num_not_moved == 1) ? $user->lang['NOT_MOVED_MESSAGE'] : sprintf($user->lang['NOT_MOVED_MESSAGES'], $num_not_moved),
  291. 'RULE_REMOVED_MESSAGES' => ($num_removed == 1) ? $user->lang['RULE_REMOVED_MESSAGE'] : sprintf($user->lang['RULE_REMOVED_MESSAGES'], $num_removed),
  292. 'S_FOLDER_OPTIONS' => $s_folder_options,
  293. 'S_TO_FOLDER_OPTIONS' => $s_to_folder_options,
  294. 'S_FOLDER_ACTION' => $this->u_action . '&amp;action=view_folder',
  295. 'S_PM_ACTION' => $this->u_action . '&amp;action=' . $action,
  296. 'U_INBOX' => $this->u_action . '&amp;folder=inbox',
  297. 'U_OUTBOX' => $this->u_action . '&amp;folder=outbox',
  298. 'U_SENTBOX' => $this->u_action . '&amp;folder=sentbox',
  299. 'U_CREATE_FOLDER' => $this->u_action . '&amp;mode=options',
  300. 'U_CURRENT_FOLDER' => $this->u_action . '&amp;folder=' . $folder_id,
  301. 'S_IN_INBOX' => ($folder_id == PRIVMSGS_INBOX) ? true : false,
  302. 'S_IN_OUTBOX' => ($folder_id == PRIVMSGS_OUTBOX) ? true : false,
  303. 'S_IN_SENTBOX' => ($folder_id == PRIVMSGS_SENTBOX) ? true : false,
  304. 'FOLDER_STATUS' => $folder_status['message'],
  305. 'FOLDER_MAX_MESSAGES' => $folder_status['max'],
  306. 'FOLDER_CUR_MESSAGES' => $folder_status['cur'],
  307. 'FOLDER_REMAINING_MESSAGES' => $folder_status['remaining'],
  308. 'FOLDER_PERCENT' => $folder_status['percent'])
  309. );
  310. if ($action == 'view_folder')
  311. {
  312. include($phpbb_root_path . 'includes/ucp/ucp_pm_viewfolder.' . $phpEx);
  313. view_folder($id, $mode, $folder_id, $folder);
  314. $tpl_file = 'ucp_pm_viewfolder';
  315. }
  316. else if ($action == 'view_message')
  317. {
  318. $template->assign_vars(array(
  319. 'S_VIEW_MESSAGE' => true,
  320. 'MSG_ID' => $msg_id)
  321. );
  322. if (!$msg_id)
  323. {
  324. trigger_error('NO_MESSAGE');
  325. }
  326. include($phpbb_root_path . 'includes/ucp/ucp_pm_viewmessage.' . $phpEx);
  327. view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row);
  328. $tpl_file = ($view == 'print') ? 'ucp_pm_viewmessage_print' : 'ucp_pm_viewmessage';
  329. }
  330. break;
  331. default:
  332. trigger_error('NO_ACTION_MODE', E_USER_ERROR);
  333. break;
  334. }
  335. $template->assign_vars(array(
  336. 'L_TITLE' => $user->lang['UCP_PM_' . strtoupper($mode)],
  337. 'S_UCP_ACTION' => $this->u_action . ((isset($action)) ? "&amp;action=$action" : ''))
  338. );
  339. // Set desired template
  340. $this->tpl_name = $tpl_file;
  341. $this->page_title = 'UCP_PM_' . strtoupper($mode);
  342. }
  343. }
  344. ?>