[ Index ]

PHP Cross Reference of phpBB-3.2.8-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->variable('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->variable('mode', 'view') : $mode;
  79          }
  80          else
  81          {
  82              $mode = 'view';
  83          }
  84  
  85          if (!function_exists('get_folder'))
  86          {
  87              include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
  88          }
  89  
  90          switch ($mode)
  91          {
  92              // Compose message
  93              case 'compose':
  94                  $action = $request->variable('action', 'post');
  95  
  96                  $user_folders = get_folder($user->data['user_id']);
  97  
  98                  if ($action != 'delete' && !$auth->acl_get('u_sendpm'))
  99                  {
 100                      // trigger_error('NO_AUTH_SEND_MESSAGE');
 101                      $template->assign_vars(array(
 102                          'S_NO_AUTH_SEND_MESSAGE'    => true,
 103                          'S_COMPOSE_PM_VIEW'            => true,
 104                      ));
 105  
 106                      $tpl_file = 'ucp_pm_viewfolder';
 107                      break;
 108                  }
 109  
 110                  if (!function_exists('compose_pm'))
 111                  {
 112                      include($phpbb_root_path . 'includes/ucp/ucp_pm_compose.' . $phpEx);
 113                  }
 114                  compose_pm($id, $mode, $action, $user_folders);
 115  
 116                  $tpl_file = 'posting_body';
 117              break;
 118  
 119              case 'options':
 120                  set_user_message_limit();
 121                  get_folder($user->data['user_id']);
 122  
 123                  if (!function_exists('message_options'))
 124                  {
 125                      include($phpbb_root_path . 'includes/ucp/ucp_pm_options.' . $phpEx);
 126                  }
 127                  message_options($id, $mode, $global_privmsgs_rules, $global_rule_conditions);
 128  
 129                  $tpl_file = 'ucp_pm_options';
 130              break;
 131  
 132              case 'drafts':
 133  
 134                  get_folder($user->data['user_id']);
 135                  $this->p_name = 'pm';
 136  
 137                  if (!class_exists('ucp_main'))
 138                  {
 139                      include($phpbb_root_path . 'includes/ucp/ucp_main.' . $phpEx);
 140                  }
 141  
 142                  $module = new ucp_main($this);
 143                  $module->u_action = $this->u_action;
 144                  $module->main($id, $mode);
 145  
 146                  $this->tpl_name = $module->tpl_name;
 147                  $this->page_title = 'UCP_PM_DRAFTS';
 148  
 149                  unset($module);
 150                  return;
 151  
 152              break;
 153  
 154              case 'view':
 155  
 156                  set_user_message_limit();
 157  
 158                  if ($folder_specified)
 159                  {
 160                      $folder_id = $folder_specified;
 161                      $action = 'view_folder';
 162                  }
 163                  else
 164                  {
 165                      $folder_id = $request->variable('f', PRIVMSGS_NO_BOX);
 166                      $action = $request->variable('action', 'view_folder');
 167                  }
 168  
 169                  $msg_id = $request->variable('p', 0);
 170                  $view    = $request->variable('view', '');
 171  
 172                  // View message if specified
 173                  if ($msg_id)
 174                  {
 175                      $action = 'view_message';
 176                  }
 177  
 178                  if (!$auth->acl_get('u_readpm'))
 179                  {
 180                      send_status_line(403, 'Forbidden');
 181                      trigger_error('NO_AUTH_READ_MESSAGE');
 182                  }
 183  
 184                  if ($view == 'print' && (!$config['print_pm'] || !$auth->acl_get('u_pm_printpm')))
 185                  {
 186                      send_status_line(403, 'Forbidden');
 187                      trigger_error('NO_AUTH_PRINT_MESSAGE');
 188                  }
 189  
 190                  // Do not allow hold messages to be seen
 191                  if ($folder_id == PRIVMSGS_HOLD_BOX)
 192                  {
 193                      trigger_error('NO_AUTH_READ_HOLD_MESSAGE');
 194                  }
 195  
 196                  // First Handle Mark actions and moving messages
 197                  $submit_mark    = (isset($_POST['submit_mark'])) ? true : false;
 198                  $move_pm        = (isset($_POST['move_pm'])) ? true : false;
 199                  $mark_option    = $request->variable('mark_option', '');
 200                  $dest_folder    = $request->variable('dest_folder', PRIVMSGS_NO_BOX);
 201  
 202                  // Is moving PM triggered through mark options?
 203                  if (!in_array($mark_option, array('mark_important', 'delete_marked')) && $submit_mark)
 204                  {
 205                      $move_pm = true;
 206                      $dest_folder = (int) $mark_option;
 207                      $submit_mark = false;
 208                  }
 209  
 210                  // Move PM
 211                  if ($move_pm)
 212                  {
 213                      $move_msg_ids    = (isset($_POST['marked_msg_id'])) ? $request->variable('marked_msg_id', array(0)) : array();
 214                      $cur_folder_id    = $request->variable('cur_folder_id', PRIVMSGS_NO_BOX);
 215  
 216                      if (move_pm($user->data['user_id'], $user->data['message_limit'], $move_msg_ids, $dest_folder, $cur_folder_id))
 217                      {
 218                          // Return to folder view if single message moved
 219                          if ($action == 'view_message')
 220                          {
 221                              $msg_id        = 0;
 222                              $folder_id    = $request->variable('cur_folder_id', PRIVMSGS_NO_BOX);
 223                              $action        = 'view_folder';
 224                          }
 225                      }
 226                  }
 227  
 228                  // Message Mark Options
 229                  if ($submit_mark)
 230                  {
 231                      handle_mark_actions($user->data['user_id'], $mark_option);
 232                  }
 233  
 234                  // If new messages arrived, place them into the appropriate folder
 235                  $num_not_moved = $num_removed = 0;
 236                  $release = $request->variable('release', 0);
 237  
 238                  if ($user->data['user_new_privmsg'] && ($action == 'view_folder' || $action == 'view_message'))
 239                  {
 240                      $return = place_pm_into_folder($global_privmsgs_rules, $release);
 241                      $num_not_moved = $return['not_moved'];
 242                      $num_removed = $return['removed'];
 243                  }
 244  
 245                  if (!$msg_id && $folder_id == PRIVMSGS_NO_BOX)
 246                  {
 247                      $folder_id = PRIVMSGS_INBOX;
 248                  }
 249                  else if ($msg_id && $folder_id == PRIVMSGS_NO_BOX)
 250                  {
 251                      $sql = 'SELECT folder_id
 252                          FROM ' . PRIVMSGS_TO_TABLE . "
 253                          WHERE msg_id = $msg_id
 254                              AND folder_id <> " . PRIVMSGS_NO_BOX . '
 255                              AND user_id = ' . $user->data['user_id'];
 256                      $result = $db->sql_query($sql);
 257                      $row = $db->sql_fetchrow($result);
 258                      $db->sql_freeresult($result);
 259  
 260                      if (!$row)
 261                      {
 262                          trigger_error('NO_MESSAGE');
 263                      }
 264                      $folder_id = (int) $row['folder_id'];
 265                  }
 266  
 267                  if ($request->variable('mark', '') == 'all' && check_link_hash($request->variable('token', ''), 'mark_all_pms_read'))
 268                  {
 269                      mark_folder_read($user->data['user_id'], $folder_id);
 270  
 271                      meta_refresh(3, $this->u_action);
 272                      $message = $user->lang['PM_MARK_ALL_READ_SUCCESS'];
 273  
 274                      if ($request->is_ajax())
 275                      {
 276                          $json_response = new \phpbb\json_response();
 277                          $json_response->send(array(
 278                              'MESSAGE_TITLE'    => $user->lang['INFORMATION'],
 279                              'MESSAGE_TEXT'    => $message,
 280                              'success'        => true,
 281                          ));
 282                      }
 283                      $message .= '<br /><br />' . $user->lang('RETURN_UCP', '<a href="' . $this->u_action . '">', '</a>');
 284  
 285                      trigger_error($message);
 286                  }
 287  
 288                  $message_row = array();
 289                  if ($action == 'view_message' && $msg_id)
 290                  {
 291                      // Get Message user want to see
 292                      if ($view == 'next' || $view == 'previous')
 293                      {
 294                          $sql_condition = ($view == 'next') ? '>' : '<';
 295                          $sql_ordering = ($view == 'next') ? 'ASC' : 'DESC';
 296  
 297                          $sql = 'SELECT t.msg_id
 298                              FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . PRIVMSGS_TABLE . " p2
 299                              WHERE p2.msg_id = $msg_id
 300                                  AND t.folder_id = $folder_id
 301                                  AND t.user_id = " . $user->data['user_id'] . "
 302                                  AND t.msg_id = p.msg_id
 303                                  AND p.message_time $sql_condition p2.message_time
 304                              ORDER BY p.message_time $sql_ordering";
 305                          $result = $db->sql_query_limit($sql, 1);
 306                          $row = $db->sql_fetchrow($result);
 307                          $db->sql_freeresult($result);
 308  
 309                          if (!$row)
 310                          {
 311                              $message = ($view == 'next') ? 'NO_NEWER_PM' : 'NO_OLDER_PM';
 312                              trigger_error($message);
 313                          }
 314                          else
 315                          {
 316                              $msg_id = $row['msg_id'];
 317                          }
 318                      }
 319  
 320                      $sql = 'SELECT t.*, p.*, u.*
 321                          FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u
 322                          WHERE t.user_id = ' . $user->data['user_id'] . "
 323                              AND p.author_id = u.user_id
 324                              AND t.folder_id = $folder_id
 325                              AND t.msg_id = p.msg_id
 326                              AND p.msg_id = $msg_id";
 327                      $result = $db->sql_query($sql);
 328                      $message_row = $db->sql_fetchrow($result);
 329                      $db->sql_freeresult($result);
 330  
 331                      if (!$message_row)
 332                      {
 333                          trigger_error('NO_MESSAGE');
 334                      }
 335  
 336                      // Update unread status
 337                      update_unread_status($message_row['pm_unread'], $message_row['msg_id'], $user->data['user_id'], $folder_id);
 338                  }
 339  
 340                  $folder = get_folder($user->data['user_id'], $folder_id);
 341  
 342                  $s_folder_options = $s_to_folder_options = '';
 343                  foreach ($folder as $f_id => $folder_ary)
 344                  {
 345                      $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>';
 346  
 347                      $s_to_folder_options .= ($f_id != PRIVMSGS_OUTBOX && $f_id != PRIVMSGS_SENTBOX) ? $option : '';
 348                      $s_folder_options .= $option;
 349                  }
 350                  clean_sentbox($folder[PRIVMSGS_SENTBOX]['num_messages']);
 351  
 352                  // Header for message view - folder and so on
 353                  $folder_status = get_folder_status($folder_id, $folder);
 354  
 355                  $template->assign_vars(array(
 356                      'CUR_FOLDER_ID'            => $folder_id,
 357                      'CUR_FOLDER_NAME'        => $folder_status['folder_name'],
 358                      'NUM_NOT_MOVED'            => $num_not_moved,
 359                      'NUM_REMOVED'            => $num_removed,
 360                      'RELEASE_MESSAGE_INFO'    => sprintf($user->lang['RELEASE_MESSAGES'], '<a href="' . $this->u_action . '&amp;folder=' . $folder_id . '&amp;release=1">', '</a>'),
 361                      'NOT_MOVED_MESSAGES'    => $user->lang('NOT_MOVED_MESSAGES', (int) $num_not_moved),
 362                      'RULE_REMOVED_MESSAGES'    => $user->lang('RULE_REMOVED_MESSAGES', (int) $num_removed),
 363  
 364                      'S_FOLDER_OPTIONS'        => $s_folder_options,
 365                      'S_TO_FOLDER_OPTIONS'    => $s_to_folder_options,
 366                      'S_FOLDER_ACTION'        => $this->u_action . '&amp;action=view_folder',
 367                      'S_PM_ACTION'            => $this->u_action . '&amp;action=' . $action,
 368  
 369                      'U_INBOX'                => $this->u_action . '&amp;folder=inbox',
 370                      'U_OUTBOX'                => $this->u_action . '&amp;folder=outbox',
 371                      'U_SENTBOX'                => $this->u_action . '&amp;folder=sentbox',
 372                      'U_CREATE_FOLDER'        => $this->u_action . '&amp;mode=options',
 373                      'U_CURRENT_FOLDER'        => $this->u_action . '&amp;folder=' . $folder_id,
 374                      'U_MARK_ALL'            => $this->u_action . '&amp;folder=' . $folder_id . '&amp;mark=all&amp;token=' . generate_link_hash('mark_all_pms_read'),
 375  
 376                      'S_IN_INBOX'            => ($folder_id == PRIVMSGS_INBOX) ? true : false,
 377                      'S_IN_OUTBOX'            => ($folder_id == PRIVMSGS_OUTBOX) ? true : false,
 378                      'S_IN_SENTBOX'            => ($folder_id == PRIVMSGS_SENTBOX) ? true : false,
 379  
 380                      'FOLDER_STATUS'                => $folder_status['message'],
 381                      'FOLDER_MAX_MESSAGES'        => $folder_status['max'],
 382                      'FOLDER_CUR_MESSAGES'        => $folder_status['cur'],
 383                      'FOLDER_REMAINING_MESSAGES'    => $folder_status['remaining'],
 384                      'FOLDER_PERCENT'            => $folder_status['percent'])
 385                  );
 386  
 387                  if ($action == 'view_folder')
 388                  {
 389                      if (!function_exists('view_folder'))
 390                      {
 391                          include($phpbb_root_path . 'includes/ucp/ucp_pm_viewfolder.' . $phpEx);
 392                      }
 393                      view_folder($id, $mode, $folder_id, $folder);
 394  
 395                      $tpl_file = 'ucp_pm_viewfolder';
 396                  }
 397                  else if ($action == 'view_message')
 398                  {
 399                      $template->assign_vars(array(
 400                          'S_VIEW_MESSAGE'        => true,
 401                          'L_RETURN_TO_FOLDER'    => $user->lang('RETURN_TO', $folder_status['folder_name']),
 402                          'MSG_ID'                => $msg_id,
 403                      ));
 404  
 405                      if (!$msg_id)
 406                      {
 407                          trigger_error('NO_MESSAGE');
 408                      }
 409  
 410                      if (!function_exists('view_message'))
 411                      {
 412                          include($phpbb_root_path . 'includes/ucp/ucp_pm_viewmessage.' . $phpEx);
 413                      }
 414                      view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row);
 415  
 416                      $tpl_file = ($view == 'print') ? 'ucp_pm_viewmessage_print' : 'ucp_pm_viewmessage';
 417                  }
 418  
 419              break;
 420  
 421              default:
 422                  trigger_error('NO_ACTION_MODE', E_USER_ERROR);
 423              break;
 424          }
 425  
 426          $template->assign_vars(array(
 427              'L_TITLE'            => $user->lang['UCP_PM_' . strtoupper($mode)],
 428              'S_UCP_ACTION'        => $this->u_action . ((isset($action)) ? "&amp;action=$action" : ''))
 429          );
 430  
 431          // Set desired template
 432          $this->tpl_name = $tpl_file;
 433          $this->page_title = 'UCP_PM_' . strtoupper($mode);
 434      }
 435  }


Generated: Sat Oct 26 11:28:42 2019 Cross-referenced by PHPXref 0.7.1