[ Index ]

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


Generated: Tue Apr 7 19:42:26 2020 Cross-referenced by PHPXref 0.7.1