[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/includes/ucp/ -> ucp_pm.php (source)

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


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1