[ Index ]

PHP Cross Reference of phpBB 3.0 Beta 3

title

Body

[close]

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

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


Generated: Wed Nov 22 00:35:05 2006 Cross-referenced by PHPXref 0.6