PageRenderTime 50ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/phpBB3/includes/ucp/ucp_pm.php

https://gitlab.com/perioner/mfhs
PHP | 424 lines | 301 code | 74 blank | 49 comment | 64 complexity | cd7f2ca101901aed4176e01a99a8e0aa MD5 | raw file
  1. <?php
  2. /**
  3. * @package ucp
  4. * @version $Id: ucp_pm.php 8479 2008-03-29 00:22:48Z naderman $
  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. get_folder($user->data['user_id']);
  103. if (!$auth->acl_get('u_sendpm'))
  104. {
  105. trigger_error('NO_AUTH_SEND_MESSAGE');
  106. }
  107. include($phpbb_root_path . 'includes/ucp/ucp_pm_compose.' . $phpEx);
  108. compose_pm($id, $mode, $action);
  109. $tpl_file = 'posting_body';
  110. break;
  111. case 'options':
  112. $sql = 'SELECT group_message_limit
  113. FROM ' . GROUPS_TABLE . '
  114. WHERE group_id = ' . $user->data['group_id'];
  115. $result = $db->sql_query($sql, 3600);
  116. $message_limit = (int) $db->sql_fetchfield('group_message_limit');
  117. $db->sql_freeresult($result);
  118. $user->data['message_limit'] = (!$message_limit) ? $config['pm_max_msgs'] : $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. $sql = 'SELECT group_message_limit
  139. FROM ' . GROUPS_TABLE . '
  140. WHERE group_id = ' . $user->data['group_id'];
  141. $result = $db->sql_query($sql, 3600);
  142. $message_limit = (int) $db->sql_fetchfield('group_message_limit');
  143. $db->sql_freeresult($result);
  144. $user->data['message_limit'] = (!$message_limit) ? $config['pm_max_msgs'] : $message_limit;
  145. if ($folder_specified)
  146. {
  147. $folder_id = $folder_specified;
  148. $action = 'view_folder';
  149. }
  150. else
  151. {
  152. $folder_id = request_var('f', PRIVMSGS_NO_BOX);
  153. $action = request_var('action', 'view_folder');
  154. }
  155. $msg_id = request_var('p', 0);
  156. $view = request_var('view', '');
  157. // View message if specified
  158. if ($msg_id)
  159. {
  160. $action = 'view_message';
  161. }
  162. if (!$auth->acl_get('u_readpm'))
  163. {
  164. trigger_error('NO_AUTH_READ_MESSAGE');
  165. }
  166. // Do not allow hold messages to be seen
  167. if ($folder_id == PRIVMSGS_HOLD_BOX)
  168. {
  169. trigger_error('NO_AUTH_READ_HOLD_MESSAGE');
  170. }
  171. // First Handle Mark actions and moving messages
  172. $submit_mark = (isset($_POST['submit_mark'])) ? true : false;
  173. $move_pm = (isset($_POST['move_pm'])) ? true : false;
  174. $mark_option = request_var('mark_option', '');
  175. $dest_folder = request_var('dest_folder', PRIVMSGS_NO_BOX);
  176. // Is moving PM triggered through mark options?
  177. if (!in_array($mark_option, array('mark_important', 'delete_marked')) && $submit_mark)
  178. {
  179. $move_pm = true;
  180. $dest_folder = (int) $mark_option;
  181. $submit_mark = false;
  182. }
  183. // Move PM
  184. if ($move_pm)
  185. {
  186. $move_msg_ids = (isset($_POST['marked_msg_id'])) ? request_var('marked_msg_id', array(0)) : array();
  187. $cur_folder_id = request_var('cur_folder_id', PRIVMSGS_NO_BOX);
  188. if (move_pm($user->data['user_id'], $user->data['message_limit'], $move_msg_ids, $dest_folder, $cur_folder_id))
  189. {
  190. // Return to folder view if single message moved
  191. if ($action == 'view_message')
  192. {
  193. $msg_id = 0;
  194. $folder_id = request_var('cur_folder_id', PRIVMSGS_NO_BOX);
  195. $action = 'view_folder';
  196. }
  197. }
  198. }
  199. // Message Mark Options
  200. if ($submit_mark)
  201. {
  202. handle_mark_actions($user->data['user_id'], $mark_option);
  203. }
  204. // If new messages arrived, place them into the appropriate folder
  205. $num_not_moved = $num_removed = 0;
  206. $release = request_var('release', 0);
  207. if ($user->data['user_new_privmsg'] && $action == 'view_folder')
  208. {
  209. $return = place_pm_into_folder($global_privmsgs_rules, $release);
  210. $num_not_moved = $return['not_moved'];
  211. $num_removed = $return['removed'];
  212. }
  213. if (!$msg_id && $folder_id == PRIVMSGS_NO_BOX)
  214. {
  215. $folder_id = PRIVMSGS_INBOX;
  216. }
  217. else if ($msg_id && $folder_id == PRIVMSGS_NO_BOX)
  218. {
  219. $sql = 'SELECT folder_id
  220. FROM ' . PRIVMSGS_TO_TABLE . "
  221. WHERE msg_id = $msg_id
  222. AND folder_id <> " . PRIVMSGS_NO_BOX . '
  223. AND user_id = ' . $user->data['user_id'];
  224. $result = $db->sql_query($sql);
  225. $row = $db->sql_fetchrow($result);
  226. $db->sql_freeresult($result);
  227. if (!$row)
  228. {
  229. trigger_error('NO_MESSAGE');
  230. }
  231. $folder_id = (int) $row['folder_id'];
  232. }
  233. $message_row = array();
  234. if ($action == 'view_message' && $msg_id)
  235. {
  236. // Get Message user want to see
  237. if ($view == 'next' || $view == 'previous')
  238. {
  239. $sql_condition = ($view == 'next') ? '>' : '<';
  240. $sql_ordering = ($view == 'next') ? 'ASC' : 'DESC';
  241. $sql = 'SELECT t.msg_id
  242. FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . PRIVMSGS_TABLE . " p2
  243. WHERE p2.msg_id = $msg_id
  244. AND t.folder_id = $folder_id
  245. AND t.user_id = " . $user->data['user_id'] . "
  246. AND t.msg_id = p.msg_id
  247. AND p.message_time $sql_condition p2.message_time
  248. ORDER BY p.message_time $sql_ordering";
  249. $result = $db->sql_query_limit($sql, 1);
  250. $row = $db->sql_fetchrow($result);
  251. $db->sql_freeresult($result);
  252. if (!$row)
  253. {
  254. $message = ($view == 'next') ? 'NO_NEWER_PM' : 'NO_OLDER_PM';
  255. trigger_error($message);
  256. }
  257. else
  258. {
  259. $msg_id = $row['msg_id'];
  260. }
  261. }
  262. $sql = 'SELECT t.*, p.*, u.*
  263. FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u
  264. WHERE t.user_id = ' . $user->data['user_id'] . "
  265. AND p.author_id = u.user_id
  266. AND t.folder_id = $folder_id
  267. AND t.msg_id = p.msg_id
  268. AND p.msg_id = $msg_id";
  269. $result = $db->sql_query($sql);
  270. $message_row = $db->sql_fetchrow($result);
  271. $db->sql_freeresult($result);
  272. if (!$message_row)
  273. {
  274. trigger_error('NO_MESSAGE');
  275. }
  276. // Update unread status
  277. update_unread_status($message_row['pm_unread'], $message_row['msg_id'], $user->data['user_id'], $folder_id);
  278. }
  279. $folder = get_folder($user->data['user_id'], $folder_id);
  280. $s_folder_options = $s_to_folder_options = '';
  281. foreach ($folder as $f_id => $folder_ary)
  282. {
  283. $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>';
  284. $s_to_folder_options .= ($f_id != PRIVMSGS_OUTBOX && $f_id != PRIVMSGS_SENTBOX) ? $option : '';
  285. $s_folder_options .= $option;
  286. }
  287. clean_sentbox($folder[PRIVMSGS_SENTBOX]['num_messages']);
  288. // Header for message view - folder and so on
  289. $folder_status = get_folder_status($folder_id, $folder);
  290. $template->assign_vars(array(
  291. 'CUR_FOLDER_ID' => $folder_id,
  292. 'CUR_FOLDER_NAME' => $folder_status['folder_name'],
  293. 'NUM_NOT_MOVED' => $num_not_moved,
  294. 'NUM_REMOVED' => $num_removed,
  295. 'RELEASE_MESSAGE_INFO' => sprintf($user->lang['RELEASE_MESSAGES'], '<a href="' . $this->u_action . '&amp;folder=' . $folder_id . '&amp;release=1">', '</a>'),
  296. 'NOT_MOVED_MESSAGES' => ($num_not_moved == 1) ? $user->lang['NOT_MOVED_MESSAGE'] : sprintf($user->lang['NOT_MOVED_MESSAGES'], $num_not_moved),
  297. 'RULE_REMOVED_MESSAGES' => ($num_removed == 1) ? $user->lang['RULE_REMOVED_MESSAGE'] : sprintf($user->lang['RULE_REMOVED_MESSAGES'], $num_removed),
  298. 'S_FOLDER_OPTIONS' => $s_folder_options,
  299. 'S_TO_FOLDER_OPTIONS' => $s_to_folder_options,
  300. 'S_FOLDER_ACTION' => $this->u_action . '&amp;action=view_folder',
  301. 'S_PM_ACTION' => $this->u_action . '&amp;action=' . $action,
  302. 'U_INBOX' => $this->u_action . '&amp;folder=inbox',
  303. 'U_OUTBOX' => $this->u_action . '&amp;folder=outbox',
  304. 'U_SENTBOX' => $this->u_action . '&amp;folder=sentbox',
  305. 'U_CREATE_FOLDER' => $this->u_action . '&amp;mode=options',
  306. 'U_CURRENT_FOLDER' => $this->u_action . '&amp;folder=' . $folder_id,
  307. 'S_IN_INBOX' => ($folder_id == PRIVMSGS_INBOX) ? true : false,
  308. 'S_IN_OUTBOX' => ($folder_id == PRIVMSGS_OUTBOX) ? true : false,
  309. 'S_IN_SENTBOX' => ($folder_id == PRIVMSGS_SENTBOX) ? true : false,
  310. 'FOLDER_STATUS' => $folder_status['message'],
  311. 'FOLDER_MAX_MESSAGES' => $folder_status['max'],
  312. 'FOLDER_CUR_MESSAGES' => $folder_status['cur'],
  313. 'FOLDER_REMAINING_MESSAGES' => $folder_status['remaining'],
  314. 'FOLDER_PERCENT' => $folder_status['percent'])
  315. );
  316. if ($action == 'view_folder')
  317. {
  318. include($phpbb_root_path . 'includes/ucp/ucp_pm_viewfolder.' . $phpEx);
  319. view_folder($id, $mode, $folder_id, $folder);
  320. $tpl_file = 'ucp_pm_viewfolder';
  321. }
  322. else if ($action == 'view_message')
  323. {
  324. $template->assign_vars(array(
  325. 'S_VIEW_MESSAGE' => true,
  326. 'MSG_ID' => $msg_id)
  327. );
  328. if (!$msg_id)
  329. {
  330. trigger_error('NO_MESSAGE');
  331. }
  332. include($phpbb_root_path . 'includes/ucp/ucp_pm_viewmessage.' . $phpEx);
  333. view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row);
  334. $tpl_file = ($view == 'print') ? 'ucp_pm_viewmessage_print' : 'ucp_pm_viewmessage';
  335. }
  336. break;
  337. default:
  338. trigger_error('NO_ACTION_MODE', E_USER_ERROR);
  339. break;
  340. }
  341. $template->assign_vars(array(
  342. 'L_TITLE' => $user->lang['UCP_PM_' . strtoupper($mode)],
  343. 'S_UCP_ACTION' => $this->u_action . ((isset($action)) ? "&amp;action=$action" : ''))
  344. );
  345. // Set desired template
  346. $this->tpl_name = $tpl_file;
  347. $this->page_title = 'UCP_PM_' . strtoupper($mode);
  348. }
  349. }
  350. ?>