[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/includes/ucp/ -> ucp_pm_viewfolder.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  * View message folder
  24  * Called from ucp_pm with mode == 'view' && action == 'view_folder'
  25  */
  26  function view_folder($id, $mode, $folder_id, $folder)
  27  {
  28      global $user, $template, $auth, $db, $cache;
  29      global $phpbb_root_path, $config, $phpEx;
  30  
  31      $submit_export = (isset($_POST['submit_export'])) ? true : false;
  32  
  33      $folder_info = get_pm_from($folder_id, $folder, $user->data['user_id']);
  34  
  35      if (!$submit_export)
  36      {
  37          $user->add_lang('viewforum');
  38  
  39          // Grab icons
  40          $icons = $cache->obtain_icons();
  41  
  42          $color_rows = array('marked', 'replied');
  43  
  44          // only show the friend/foe color rows if the module is enabled
  45          $zebra_enabled = false;
  46  
  47          $_module = new p_master();
  48          $_module->list_modules('ucp');
  49          $_module->set_active('zebra');
  50  
  51          $zebra_enabled = ($_module->active_module === false) ? false : true;
  52  
  53          unset($_module);
  54  
  55          if ($zebra_enabled)
  56          {
  57              $color_rows = array_merge($color_rows, array('friend', 'foe'));
  58          }
  59  
  60          foreach ($color_rows as $var)
  61          {
  62              $template->assign_block_vars('pm_colour_info', array(
  63                  'IMG'    => $user->img("pm_{$var}", ''),
  64                  'CLASS'    => "pm_{$var}_colour",
  65                  'LANG'    => $user->lang[strtoupper($var) . '_MESSAGE'])
  66              );
  67          }
  68  
  69          $mark_options = array('mark_important', 'delete_marked');
  70  
  71          // Minimise edits
  72          if (!$auth->acl_get('u_pm_delete') && $key = array_search('delete_marked', $mark_options))
  73          {
  74              unset($mark_options[$key]);
  75          }
  76  
  77          $s_mark_options = '';
  78          foreach ($mark_options as $mark_option)
  79          {
  80              $s_mark_options .= '<option value="' . $mark_option . '">' . $user->lang[strtoupper($mark_option)] . '</option>';
  81          }
  82  
  83          // We do the folder moving options here too, for template authors to use...
  84          $s_folder_move_options = '';
  85          if ($folder_id != PRIVMSGS_NO_BOX && $folder_id != PRIVMSGS_OUTBOX)
  86          {
  87              foreach ($folder as $f_id => $folder_ary)
  88              {
  89                  if ($f_id == PRIVMSGS_OUTBOX || $f_id == PRIVMSGS_SENTBOX || $f_id == $folder_id)
  90                  {
  91                      continue;
  92                  }
  93  
  94                  $s_folder_move_options .= '<option' . (($f_id != PRIVMSGS_INBOX) ? ' class="sep"' : '') . ' value="' . $f_id . '">';
  95                  $s_folder_move_options .= sprintf($user->lang['MOVE_MARKED_TO_FOLDER'], $folder_ary['folder_name']);
  96                  $s_folder_move_options .= (($folder_ary['unread_messages']) ? ' [' . $folder_ary['unread_messages'] . '] ' : '') . '</option>';
  97              }
  98          }
  99          $friend = $foe = array();
 100  
 101          // Get friends and foes
 102          $sql = 'SELECT *
 103              FROM ' . ZEBRA_TABLE . '
 104              WHERE user_id = ' . $user->data['user_id'];
 105          $result = $db->sql_query($sql);
 106  
 107          while ($row = $db->sql_fetchrow($result))
 108          {
 109              $friend[$row['zebra_id']] = $row['friend'];
 110              $foe[$row['zebra_id']] = $row['foe'];
 111          }
 112          $db->sql_freeresult($result);
 113  
 114          $template->assign_vars(array(
 115              'S_MARK_OPTIONS'        => $s_mark_options,
 116              'S_MOVE_MARKED_OPTIONS'    => $s_folder_move_options)
 117          );
 118  
 119          // Okay, lets dump out the page ...
 120          if (sizeof($folder_info['pm_list']))
 121          {
 122              $address_list = array();
 123  
 124              // Build Recipient List if in outbox/sentbox - max two additional queries
 125              if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX)
 126              {
 127                  $address_list = get_recipient_strings($folder_info['rowset']);
 128              }
 129  
 130              foreach ($folder_info['pm_list'] as $message_id)
 131              {
 132                  $row = &$folder_info['rowset'][$message_id];
 133  
 134                  $folder_img = ($row['pm_unread']) ? 'pm_unread' : 'pm_read';
 135                  $folder_alt = ($row['pm_unread']) ? 'NEW_MESSAGES' : 'NO_NEW_MESSAGES';
 136  
 137                  // Generate all URIs ...
 138                  $view_message_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=view&amp;f=$folder_id&amp;p=$message_id");
 139                  $remove_message_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=compose&amp;action=delete&amp;p=$message_id");
 140  
 141                  $row_indicator = '';
 142                  foreach ($color_rows as $var)
 143                  {
 144                      if (($var != 'friend' && $var != 'foe' && $row['pm_' . $var])
 145                          ||
 146                          (($var == 'friend' || $var == 'foe') && isset(${$var}[$row['author_id']]) && ${$var}[$row['author_id']]))
 147                      {
 148                          $row_indicator = $var;
 149                          break;
 150                      }
 151                  }
 152  
 153                  // Send vars to template
 154                  $template->assign_block_vars('messagerow', array(
 155                      'PM_CLASS'            => ($row_indicator) ? 'pm_' . $row_indicator . '_colour' : '',
 156  
 157                      'MESSAGE_AUTHOR_FULL'        => get_username_string('full', $row['author_id'], $row['username'], $row['user_colour'], $row['username']),
 158                      'MESSAGE_AUTHOR_COLOUR'        => get_username_string('colour', $row['author_id'], $row['username'], $row['user_colour'], $row['username']),
 159                      'MESSAGE_AUTHOR'            => get_username_string('username', $row['author_id'], $row['username'], $row['user_colour'], $row['username']),
 160                      'U_MESSAGE_AUTHOR'            => get_username_string('profile', $row['author_id'], $row['username'], $row['user_colour'], $row['username']),
 161  
 162                      'FOLDER_ID'            => $folder_id,
 163                      'MESSAGE_ID'        => $message_id,
 164                      'SENT_TIME'            => $user->format_date($row['message_time']),
 165                      'SUBJECT'            => censor_text($row['message_subject']),
 166                      'FOLDER'            => (isset($folder[$row['folder_id']])) ? $folder[$row['folder_id']]['folder_name'] : '',
 167                      'U_FOLDER'            => (isset($folder[$row['folder_id']])) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'folder=' . $row['folder_id']) : '',
 168                      'PM_ICON_IMG'        => (!empty($icons[$row['icon_id']])) ? '<img src="' . $config['icons_path'] . '/' . $icons[$row['icon_id']]['img'] . '" width="' . $icons[$row['icon_id']]['width'] . '" height="' . $icons[$row['icon_id']]['height'] . '" alt="" title="" />' : '',
 169                      'PM_ICON_URL'        => (!empty($icons[$row['icon_id']])) ? $config['icons_path'] . '/' . $icons[$row['icon_id']]['img'] : '',
 170                      'FOLDER_IMG'        => $user->img($folder_img, $folder_alt),
 171                      'FOLDER_IMG_STYLE'    => $folder_img,
 172                      'PM_IMG'            => ($row_indicator) ? $user->img('pm_' . $row_indicator, '') : '',
 173                      'ATTACH_ICON_IMG'    => ($auth->acl_get('u_pm_download') && $row['message_attachment'] && $config['allow_pm_attach']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
 174  
 175                      'S_PM_UNREAD'        => ($row['pm_unread']) ? true : false,
 176                      'S_PM_DELETED'        => ($row['pm_deleted']) ? true : false,
 177                      'S_PM_REPORTED'        => (isset($row['report_id'])) ? true : false,
 178                      'S_AUTHOR_DELETED'    => ($row['author_id'] == ANONYMOUS) ? true : false,
 179  
 180                      'U_VIEW_PM'            => ($row['pm_deleted']) ? '' : $view_message_url,
 181                      'U_REMOVE_PM'        => ($row['pm_deleted']) ? $remove_message_url : '',
 182                      'U_MCP_REPORT'        => (isset($row['report_id'])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=pm_reports&amp;mode=pm_report_details&amp;r=' . $row['report_id']) : '',
 183                      'RECIPIENTS'        => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? implode($user->lang['COMMA_SEPARATOR'], $address_list[$message_id]) : '')
 184                  );
 185              }
 186              unset($folder_info['rowset']);
 187  
 188              $template->assign_vars(array(
 189                  'S_SHOW_RECIPIENTS'        => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? true : false,
 190                  'S_SHOW_COLOUR_LEGEND'    => true,
 191  
 192                  'REPORTED_IMG'            => $user->img('icon_topic_reported', 'PM_REPORTED'),
 193                  'S_PM_ICONS'            => ($config['enable_pm_icons']) ? true : false)
 194              );
 195          }
 196      }
 197      else
 198      {
 199          $export_type = request_var('export_option', '');
 200          $enclosure = request_var('enclosure', '');
 201          $delimiter = request_var('delimiter', '');
 202  
 203          if ($export_type == 'CSV' && ($delimiter === '' || $enclosure === ''))
 204          {
 205              $template->assign_var('PROMPT', true);
 206          }
 207          else
 208          {
 209              // Build Recipient List if in outbox/sentbox
 210  
 211              $address_temp = $address = $data = array();
 212  
 213              if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX)
 214              {
 215                  foreach ($folder_info['rowset'] as $message_id => $row)
 216                  {
 217                      $address_temp[$message_id] = rebuild_header(array('to' => $row['to_address'], 'bcc' => $row['bcc_address']));
 218                      $address[$message_id] = array();
 219                  }
 220              }
 221  
 222              foreach ($folder_info['pm_list'] as $message_id)
 223              {
 224                  $row = &$folder_info['rowset'][$message_id];
 225  
 226                  include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
 227  
 228                  $sql = 'SELECT p.message_text, p.bbcode_uid
 229                      FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u
 230                      WHERE t.user_id = ' . $user->data['user_id'] . "
 231                          AND p.author_id = u.user_id
 232                          AND t.folder_id = $folder_id
 233                          AND t.msg_id = p.msg_id
 234                          AND p.msg_id = $message_id";
 235                  $result = $db->sql_query_limit($sql, 1);
 236                  $message_row = $db->sql_fetchrow($result);
 237                  $db->sql_freeresult($result);
 238  
 239                  $_types = array('u', 'g');
 240                  foreach ($_types as $ug_type)
 241                  {
 242                      if (isset($address_temp[$message_id][$ug_type]) && sizeof($address_temp[$message_id][$ug_type]))
 243                      {
 244                          if (!isset($address[$message_id][$ug_type]))
 245                          {
 246                              $address[$message_id][$ug_type] = array();
 247                          }
 248                          if ($ug_type == 'u')
 249                          {
 250                              $sql = 'SELECT user_id as id, username as name
 251                                  FROM ' . USERS_TABLE . '
 252                                  WHERE ';
 253                          }
 254                          else
 255                          {
 256                              $sql = 'SELECT group_id as id, group_name as name
 257                                  FROM ' . GROUPS_TABLE . '
 258                                  WHERE ';
 259                          }
 260                          $sql .= $db->sql_in_set(($ug_type == 'u') ? 'user_id' : 'group_id', array_map('intval', array_keys($address_temp[$message_id][$ug_type])));
 261  
 262                          $result = $db->sql_query($sql);
 263  
 264                          while ($info_row = $db->sql_fetchrow($result))
 265                          {
 266                              $address[$message_id][$ug_type][$address_temp[$message_id][$ug_type][$info_row['id']]][] = $info_row['name'];
 267                              unset($address_temp[$message_id][$ug_type][$info_row['id']]);
 268                          }
 269                          $db->sql_freeresult($result);
 270                      }
 271                  }
 272  
 273                  // There is the chance that all recipients of the message got deleted. To avoid creating
 274                  // exports without recipients, we add a bogus "undisclosed recipient".
 275                  if (!(isset($address[$message_id]['g']) && sizeof($address[$message_id]['g'])) &&
 276                      !(isset($address[$message_id]['u']) && sizeof($address[$message_id]['u'])))
 277                  {
 278                      $address[$message_id]['u'] = array();
 279                      $address[$message_id]['u']['to'] = array();
 280                      $address[$message_id]['u']['to'][] = $user->lang['UNDISCLOSED_RECIPIENT'];
 281                  }
 282  
 283                  decode_message($message_row['message_text'], $message_row['bbcode_uid']);
 284  
 285                  $data[] = array(
 286                      'subject'    => censor_text($row['message_subject']),
 287                      'sender'    => $row['username'],
 288                      // ISO 8601 date. For PHP4 we are able to hardcode the timezone because $user->format_date() does not set it.
 289                      'date'        => $user->format_date($row['message_time'], 'c', true),
 290                      'to'        => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? $address[$message_id] : '',
 291                      'message'    => $message_row['message_text']
 292                  );
 293              }
 294  
 295              switch ($export_type)
 296              {
 297                  case 'CSV':
 298                  case 'CSV_EXCEL':
 299                      $mimetype = 'text/csv';
 300                      $filetype = 'csv';
 301  
 302                      if ($export_type == 'CSV_EXCEL')
 303                      {
 304                          $enclosure = '"';
 305                          $delimiter = ',';
 306                          $newline = "\r\n";
 307                      }
 308                      else
 309                      {
 310                          $newline = "\n";
 311                      }
 312  
 313                      $string = '';
 314                      foreach ($data as $value)
 315                      {
 316                          $recipients = $value['to'];
 317                          $value['to'] = $value['bcc'] = '';
 318  
 319                          if (is_array($recipients))
 320                          {
 321                              foreach ($recipients as $values)
 322                              {
 323                                  $value['bcc'] .= (isset($values['bcc']) && is_array($values['bcc'])) ? ',' . implode(',', $values['bcc']) : '';
 324                                  $value['to'] .= (isset($values['to']) && is_array($values['to'])) ? ',' . implode(',', $values['to']) : '';
 325                              }
 326  
 327                              // Remove the commas which will appear before the first entry.
 328                              $value['to'] = substr($value['to'], 1);
 329                              $value['bcc'] = substr($value['bcc'], 1);
 330                          }
 331  
 332                          foreach ($value as $tag => $text)
 333                          {
 334                              $cell = str_replace($enclosure, $enclosure . $enclosure, $text);
 335  
 336                              if (strpos($cell, $enclosure) !== false || strpos($cell, $delimiter) !== false || strpos($cell, $newline) !== false)
 337                              {
 338                                  $string .= $enclosure . $text . $enclosure . $delimiter;
 339                              }
 340                              else
 341                              {
 342                                  $string .= $cell . $delimiter;
 343                              }
 344                          }
 345                          $string = substr($string, 0, -1) . $newline;
 346                      }
 347                  break;
 348  
 349                  case 'XML':
 350                      $mimetype = 'application/xml';
 351                      $filetype = 'xml';
 352                      $string = '<?xml version="1.0"?>' . "\n";
 353                      $string .= "<phpbb>\n";
 354  
 355                      foreach ($data as $value)
 356                      {
 357                          $string .= "\t<privmsg>\n";
 358  
 359                          if (is_array($value['to']))
 360                          {
 361                              foreach ($value['to'] as $key => $values)
 362                              {
 363                                  foreach ($values as $type => $types)
 364                                  {
 365                                      foreach ($types as $name)
 366                                      {
 367                                          $string .= "\t\t<recipient type=\"$type\" status=\"$key\">$name</recipient>\n";
 368                                      }
 369                                  }
 370                              }
 371                          }
 372  
 373                          unset($value['to']);
 374  
 375                          foreach ($value as $tag => $text)
 376                          {
 377                              $string .= "\t\t<$tag>$text</$tag>\n";
 378                          }
 379  
 380                          $string .= "\t</privmsg>\n";
 381                      }
 382                      $string .= '</phpbb>';
 383                  break;
 384              }
 385  
 386              header('Cache-Control: private, no-cache');
 387              header("Content-Type: $mimetype; name=\"data.$filetype\"");
 388              header("Content-disposition: attachment; filename=data.$filetype");
 389              echo $string;
 390              exit;
 391          }
 392      }
 393  }
 394  
 395  /**
 396  * Get Messages from folder/user
 397  */
 398  function get_pm_from($folder_id, $folder, $user_id)
 399  {
 400      global $user, $db, $template, $config, $auth, $phpbb_container, $phpbb_root_path, $phpEx, $phpbb_dispatcher;
 401  
 402      $start = request_var('start', 0);
 403  
 404      // Additional vars later, pm ordering is mostly different from post ordering. :/
 405      $sort_days    = request_var('st', 0);
 406      $sort_key    = request_var('sk', 't');
 407      $sort_dir    = request_var('sd', 'd');
 408  
 409      $pagination = $phpbb_container->get('pagination');
 410  
 411      // PM ordering options
 412      $limit_days = array(0 => $user->lang['ALL_MESSAGES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
 413  
 414      // No sort by Author for sentbox/outbox (already only author available)
 415      // Also, sort by msg_id for the time - private messages are not as prone to errors as posts are.
 416      if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX)
 417      {
 418          $sort_by_text = array('t' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
 419          $sort_by_sql = array('t' => 'p.message_time', 's' => array('p.message_subject', 'p.message_time'));
 420      }
 421      else
 422      {
 423          $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
 424          $sort_by_sql = array('a' => array('u.username_clean', 'p.message_time'), 't' => 'p.message_time', 's' => array('p.message_subject', 'p.message_time'));
 425      }
 426  
 427      $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
 428      gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
 429  
 430      $folder_sql = 't.folder_id = ' . (int) $folder_id;
 431  
 432      // Limit pms to certain time frame, obtain correct pm count
 433      if ($sort_days)
 434      {
 435          $min_post_time = time() - ($sort_days * 86400);
 436  
 437          if (isset($_POST['sort']))
 438          {
 439              $start = 0;
 440          }
 441  
 442          $sql = 'SELECT COUNT(t.msg_id) AS pm_count
 443              FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . " p
 444              WHERE $folder_sql
 445                  AND t.user_id = $user_id
 446                  AND t.msg_id = p.msg_id
 447                  AND p.message_time >= $min_post_time";
 448          $result = $db->sql_query_limit($sql, 1);
 449          $pm_count = (int) $db->sql_fetchfield('pm_count');
 450          $db->sql_freeresult($result);
 451  
 452          $sql_limit_time = "AND p.message_time >= $min_post_time";
 453      }
 454      else
 455      {
 456          $pm_count = (!empty($folder[$folder_id]['num_messages'])) ? $folder[$folder_id]['num_messages'] : 0;
 457          $sql_limit_time = '';
 458      }
 459  
 460      $base_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&amp;mode=view&amp;action=view_folder&amp;f=$folder_id&amp;$u_sort_param");
 461      $start = $pagination->validate_start($start, $config['topics_per_page'], $pm_count);
 462      $pagination->generate_template_pagination($base_url, 'pagination', 'start', $pm_count, $config['topics_per_page'], $start);
 463  
 464      $template_vars = array(
 465          'TOTAL_MESSAGES'    => $user->lang('VIEW_PM_MESSAGES', (int) $pm_count),
 466  
 467          'POST_IMG'        => (!$auth->acl_get('u_sendpm')) ? $user->img('button_topic_locked', 'POST_PM_LOCKED') : $user->img('button_pm_new', 'POST_NEW_PM'),
 468  
 469          'S_NO_AUTH_SEND_MESSAGE'    => !$auth->acl_get('u_sendpm'),
 470  
 471          'S_SELECT_SORT_DIR'        => $s_sort_dir,
 472          'S_SELECT_SORT_KEY'        => $s_sort_key,
 473          'S_SELECT_SORT_DAYS'    => $s_limit_days,
 474          'S_TOPIC_ICONS'            => ($config['enable_pm_icons']) ? true : false,
 475  
 476          'U_POST_NEW_TOPIC'    => ($auth->acl_get('u_sendpm')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=compose') : '',
 477          'S_PM_ACTION'        => append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&amp;mode=view&amp;action=view_folder&amp;f=$folder_id" . (($start !== 0) ? "&amp;start=$start" : '')),
 478      );
 479  
 480      /**
 481      * Modify template variables before they are assigned
 482      *
 483      * @event core.ucp_pm_view_folder_get_pm_from_template
 484      * @var    int        folder_id        Folder ID
 485      * @var    array    folder            Folder data
 486      * @var    int        user_id            User ID
 487      * @var    string    base_url        Pagination base URL
 488      * @var    int        start            Pagination start
 489      * @var    int        pm_count        Count of PMs
 490      * @var    array    template_vars    Template variables to be assigned
 491      * @since 3.1.11-RC1
 492      */
 493      $vars = array(
 494          'folder_id',
 495          'folder',
 496          'user_id',
 497          'base_url',
 498          'start',
 499          'pm_count',
 500          'template_vars',
 501      );
 502      extract($phpbb_dispatcher->trigger_event('core.ucp_pm_view_folder_get_pm_from_template', compact($vars)));
 503  
 504      $template->assign_vars($template_vars);
 505  
 506      // Grab all pm data
 507      $rowset = $pm_list = array();
 508  
 509      // If the user is trying to reach late pages, start searching from the end
 510      $store_reverse = false;
 511      $sql_limit = $config['topics_per_page'];
 512      if ($start > $pm_count / 2)
 513      {
 514          $store_reverse = true;
 515  
 516          // Select the sort order
 517          $direction = ($sort_dir == 'd') ? 'ASC' : 'DESC';
 518          $sql_limit = $pagination->reverse_limit($start, $sql_limit, $pm_count);
 519          $sql_start = $pagination->reverse_start($start, $sql_limit, $pm_count);
 520      }
 521      else
 522      {
 523          // Select the sort order
 524          $direction = ($sort_dir == 'd') ? 'DESC' : 'ASC';
 525          $sql_start = $start;
 526      }
 527  
 528      // Sql sort order
 529      if (is_array($sort_by_sql[$sort_key]))
 530      {
 531          $sql_sort_order = implode(' ' . $direction . ', ', $sort_by_sql[$sort_key]) . ' ' . $direction;
 532      }
 533      else
 534      {
 535          $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . $direction;
 536      }
 537  
 538      $sql_ary = array(
 539          'SELECT'    => 't.*, p.root_level, p.message_time, p.message_subject, p.icon_id, p.to_address, p.message_attachment, p.bcc_address, u.username, u.username_clean, u.user_colour, p.message_reported',
 540          'FROM'        => array(
 541              PRIVMSGS_TO_TABLE    => 't',
 542              PRIVMSGS_TABLE        => 'p',
 543              USERS_TABLE            => 'u',
 544          ),
 545          'WHERE'        => "t.user_id = $user_id
 546              AND p.author_id = u.user_id
 547              AND $folder_sql
 548              AND t.msg_id = p.msg_id
 549              $sql_limit_time",
 550          'ORDER_BY'    => $sql_sort_order,
 551      );
 552  
 553      /**
 554      * Modify SQL before it is executed
 555      *
 556      * @event core.ucp_pm_view_folder_get_pm_from_sql
 557      * @var    array    sql_ary        SQL array
 558      * @var    int        sql_limit    SQL limit
 559      * @var    int        sql_start    SQL start
 560      * @since 3.1.11-RC1
 561      */
 562      $vars = array(
 563          'sql_ary',
 564          'sql_limit',
 565          'sql_start',
 566      );
 567      extract($phpbb_dispatcher->trigger_event('core.ucp_pm_view_folder_get_pm_from_sql', compact($vars)));
 568  
 569      $result = $db->sql_query_limit($db->sql_build_query('SELECT', $sql_ary), $sql_limit, $sql_start);
 570  
 571      $pm_reported = array();
 572      while ($row = $db->sql_fetchrow($result))
 573      {
 574          $rowset[$row['msg_id']] = $row;
 575          $pm_list[] = $row['msg_id'];
 576          if ($row['message_reported'])
 577          {
 578              $pm_reported[] = $row['msg_id'];
 579          }
 580      }
 581      $db->sql_freeresult($result);
 582  
 583      // Fetch the report_ids, if there are any reported pms.
 584      if (!empty($pm_reported) && $auth->acl_getf_global('m_report'))
 585      {
 586          $sql = 'SELECT pm_id, report_id
 587              FROM ' . REPORTS_TABLE . '
 588              WHERE report_closed = 0
 589                  AND ' . $db->sql_in_set('pm_id', $pm_reported);
 590          $result = $db->sql_query($sql);
 591  
 592          while ($row = $db->sql_fetchrow($result))
 593          {
 594              $rowset[$row['pm_id']]['report_id'] = $row['report_id'];
 595          }
 596          $db->sql_freeresult($result);
 597      }
 598  
 599      $pm_list = ($store_reverse) ? array_reverse($pm_list) : $pm_list;
 600  
 601      return array(
 602          'pm_count'    => $pm_count,
 603          'pm_list'    => $pm_list,
 604          'rowset'    => $rowset
 605      );
 606  }


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