Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ucp_pm_viewfolder.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 18.59 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  /**
 015  * @ignore
 016  */
 017  if (!defined('IN_PHPBB'))
 018  {
 019      exit;
 020  }
 021   
 022  /**
 023  * View message folder
 024  * Called from ucp_pm with mode == 'view' && action == 'view_folder'
 025  */
 026  function view_folder($id, $mode, $folder_id, $folder)
 027  {
 028      global $user, $template, $auth, $db, $cache;
 029      global $phpbb_root_path, $config, $phpEx;
 030   
 031      $submit_export = (isset($_POST['submit_export'])) ? true : false;
 032   
 033      $folder_info = get_pm_from($folder_id, $folder, $user->data['user_id']);
 034   
 035      if (!$submit_export)
 036      {
 037          $user->add_lang('viewforum');
 038   
 039          // Grab icons
 040          $icons = $cache->obtain_icons();
 041   
 042          $color_rows = array('marked', 'replied');
 043   
 044          // only show the friend/foe color rows if the module is enabled
 045          $zebra_enabled = false;
 046   
 047          $_module = new p_master();
 048          $_module->list_modules('ucp');
 049          $_module->set_active('zebra');
 050   
 051          $zebra_enabled = ($_module->active_module === false) ? false : true;
 052   
 053          unset($_module);
 054   
 055          if ($zebra_enabled)
 056          {
 057              $color_rows = array_merge($color_rows, array('friend', 'foe'));
 058          }
 059   
 060          foreach ($color_rows as $var)
 061          {
 062              $template->assign_block_vars('pm_colour_info', array(
 063                  'IMG'    => $user->img("pm_{$var}", ''),
 064                  'CLASS'    => "pm_{$var}_colour",
 065                  'LANG'    => $user->lang[strtoupper($var) . '_MESSAGE'])
 066              );
 067          }
 068   
 069          $mark_options = array('mark_important', 'delete_marked');
 070   
 071          // Minimise edits
 072          if (!$auth->acl_get('u_pm_delete') && $key = array_search('delete_marked', $mark_options))
 073          {
 074              unset($mark_options[$key]);
 075          }
 076   
 077          $s_mark_options = '';
 078          foreach ($mark_options as $mark_option)
 079          {
 080              $s_mark_options .= '<option value="' . $mark_option . '">' . $user->lang[strtoupper($mark_option)] . '</option>';
 081          }
 082   
 083          // We do the folder moving options here too, for template authors to use...
 084          $s_folder_move_options = '';
 085          if ($folder_id != PRIVMSGS_NO_BOX && $folder_id != PRIVMSGS_OUTBOX)
 086          {
 087              foreach ($folder as $f_id => $folder_ary)
 088              {
 089                  if ($f_id == PRIVMSGS_OUTBOX || $f_id == PRIVMSGS_SENTBOX || $f_id == $folder_id)
 090                  {
 091                      continue;
 092                  }
 093   
 094                  $s_folder_move_options .= '<option' . (($f_id != PRIVMSGS_INBOX) ? ' class="sep"' : '') . ' value="' . $f_id . '">';
 095                  $s_folder_move_options .= sprintf($user->lang['MOVE_MARKED_TO_FOLDER'], $folder_ary['folder_name']);
 096                  $s_folder_move_options .= (($folder_ary['unread_messages']) ? ' [' . $folder_ary['unread_messages'] . '] ' : '') . '</option>';
 097              }
 098          }
 099          $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;
 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->assign_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      // Grab all pm data
 481      $rowset = $pm_list = array();
 482   
 483      // If the user is trying to reach late pages, start searching from the end
 484      $store_reverse = false;
 485      $sql_limit = $config['topics_per_page'];
 486      if ($start > $pm_count / 2)
 487      {
 488          $store_reverse = true;
 489   
 490          // Select the sort order
 491          $direction = ($sort_dir == 'd') ? 'ASC' : 'DESC';
 492          $sql_limit = $pagination->reverse_limit($start, $sql_limit, $pm_count);
 493          $sql_start = $pagination->reverse_start($start, $sql_limit, $pm_count);
 494      }
 495      else
 496      {
 497          // Select the sort order
 498          $direction = ($sort_dir == 'd') ? 'DESC' : 'ASC';
 499          $sql_start = $start;
 500      }
 501   
 502      // Sql sort order
 503      if (is_array($sort_by_sql[$sort_key]))
 504      {
 505          $sql_sort_order = implode(' ' . $direction . ', ', $sort_by_sql[$sort_key]) . ' ' . $direction;
 506      }
 507      else
 508      {
 509          $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . $direction;
 510      }
 511   
 512      $sql = '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
 513          FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . " u
 514          WHERE t.user_id = $user_id
 515              AND p.author_id = u.user_id
 516              AND $folder_sql
 517              AND t.msg_id = p.msg_id
 518              $sql_limit_time
 519          ORDER BY $sql_sort_order";
 520      $result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
 521   
 522      $pm_reported = array();
 523      while ($row = $db->sql_fetchrow($result))
 524      {
 525          $rowset[$row['msg_id']] = $row;
 526          $pm_list[] = $row['msg_id'];
 527          if ($row['message_reported'])
 528          {
 529              $pm_reported[] = $row['msg_id'];
 530          }
 531      }
 532      $db->sql_freeresult($result);
 533   
 534      // Fetch the report_ids, if there are any reported pms.
 535      if (!empty($pm_reported) && $auth->acl_getf_global('m_report'))
 536      {
 537          $sql = 'SELECT pm_id, report_id
 538              FROM ' . REPORTS_TABLE . '
 539              WHERE report_closed = 0
 540                  AND ' . $db->sql_in_set('pm_id', $pm_reported);
 541          $result = $db->sql_query($sql);
 542   
 543          while ($row = $db->sql_fetchrow($result))
 544          {
 545              $rowset[$row['pm_id']]['report_id'] = $row['report_id'];
 546          }
 547          $db->sql_freeresult($result);
 548      }
 549   
 550      $pm_list = ($store_reverse) ? array_reverse($pm_list) : $pm_list;
 551   
 552      return array(
 553          'pm_count'    => $pm_count,
 554          'pm_list'    => $pm_list,
 555          'rowset'    => $rowset
 556      );
 557  }
 558