[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/includes/ucp/ -> ucp_attachments.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  * ucp_attachments
  24  * User attachments
  25  */
  26  class ucp_attachments
  27  {
  28      var $u_action;
  29  
  30  	function main($id, $mode)
  31      {
  32          global $template, $user, $db, $config, $phpEx, $phpbb_root_path, $phpbb_container, $request, $auth;
  33  
  34          $start        = $request->variable('start', 0);
  35          $sort_key    = $request->variable('sk', 'a');
  36          $sort_dir    = $request->variable('sd', 'a');
  37  
  38          $delete        = (isset($_POST['delete'])) ? true : false;
  39          $delete_ids    = array_keys($request->variable('attachment', array(0)));
  40  
  41          if ($delete && count($delete_ids))
  42          {
  43              // Validate $delete_ids...
  44              $sql = 'SELECT a.attach_id, p.post_edit_locked, t.topic_status, f.forum_id, f.forum_status
  45                  FROM ' . ATTACHMENTS_TABLE . ' a
  46                  LEFT JOIN ' . POSTS_TABLE . ' p
  47                      ON (a.post_msg_id = p.post_id AND a.in_message = 0)
  48                  LEFT JOIN ' . TOPICS_TABLE . ' t
  49                      ON (t.topic_id = p.topic_id AND a.in_message = 0)
  50                  LEFT JOIN ' . FORUMS_TABLE . ' f
  51                      ON (f.forum_id = t.forum_id AND a.in_message = 0)
  52                  WHERE a.poster_id = ' . $user->data['user_id'] . '
  53                      AND a.is_orphan = 0
  54                      AND ' . $db->sql_in_set('a.attach_id', $delete_ids);
  55              $result = $db->sql_query($sql);
  56  
  57              $delete_ids = array();
  58              while ($row = $db->sql_fetchrow($result))
  59              {
  60                  if (!$auth->acl_get('m_edit', $row['forum_id']) && ($row['forum_status'] == ITEM_LOCKED || $row['topic_status'] == ITEM_LOCKED || $row['post_edit_locked']))
  61                  {
  62                      continue;
  63                  }
  64  
  65                  $delete_ids[] = $row['attach_id'];
  66              }
  67              $db->sql_freeresult($result);
  68          }
  69  
  70          if ($delete && count($delete_ids))
  71          {
  72              $s_hidden_fields = array(
  73                  'delete'    => 1
  74              );
  75  
  76              foreach ($delete_ids as $attachment_id)
  77              {
  78                  $s_hidden_fields['attachment'][$attachment_id] = 1;
  79              }
  80  
  81              if (confirm_box(true))
  82              {
  83                  /** @var \phpbb\attachment\manager $attachment_manager */
  84                  $attachment_manager = $phpbb_container->get('attachment.manager');
  85                  $attachment_manager->delete('attach', $delete_ids);
  86                  unset($attachment_manager);
  87  
  88                  meta_refresh(3, $this->u_action);
  89                  $message = ((count($delete_ids) == 1) ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED']) . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
  90                  trigger_error($message);
  91              }
  92              else
  93              {
  94                  confirm_box(false, (count($delete_ids) == 1) ? 'DELETE_ATTACHMENT' : 'DELETE_ATTACHMENTS', build_hidden_fields($s_hidden_fields));
  95              }
  96          }
  97  
  98          // Select box eventually
  99          $sort_key_text = array('a' => $user->lang['SORT_FILENAME'], 'b' => $user->lang['SORT_COMMENT'], 'c' => $user->lang['SORT_EXTENSION'], 'd' => $user->lang['SORT_SIZE'], 'e' => $user->lang['SORT_DOWNLOADS'], 'f' => $user->lang['SORT_POST_TIME'], 'g' => $user->lang['SORT_TOPIC_TITLE']);
 100          $sort_key_sql = array('a' => 'a.real_filename', 'b' => 'a.attach_comment', 'c' => 'a.extension', 'd' => 'a.filesize', 'e' => 'a.download_count', 'f' => 'a.filetime', 'g' => 't.topic_title');
 101  
 102          $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
 103  
 104          $s_sort_key = '';
 105          foreach ($sort_key_text as $key => $value)
 106          {
 107              $selected = ($sort_key == $key) ? ' selected="selected"' : '';
 108              $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
 109          }
 110  
 111          $s_sort_dir = '';
 112          foreach ($sort_dir_text as $key => $value)
 113          {
 114              $selected = ($sort_dir == $key) ? ' selected="selected"' : '';
 115              $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
 116          }
 117  
 118          if (!isset($sort_key_sql[$sort_key]))
 119          {
 120              $sort_key = 'a';
 121          }
 122  
 123          $order_by = $sort_key_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
 124  
 125          $sql = 'SELECT COUNT(attach_id) as num_attachments
 126              FROM ' . ATTACHMENTS_TABLE . '
 127              WHERE poster_id = ' . $user->data['user_id'] . '
 128                  AND is_orphan = 0';
 129          $result = $db->sql_query($sql);
 130          $num_attachments = $db->sql_fetchfield('num_attachments');
 131          $db->sql_freeresult($result);
 132  
 133          // Ensure start is a valid value
 134          /* @var $pagination \phpbb\pagination */
 135          $pagination = $phpbb_container->get('pagination');
 136          $start = $pagination->validate_start($start, $config['topics_per_page'], $num_attachments);
 137  
 138          $sql = 'SELECT a.*, t.topic_title, pr.message_subject as message_title, p.post_edit_locked, t.topic_status, f.forum_id, f.forum_status
 139              FROM ' . ATTACHMENTS_TABLE . ' a
 140                  LEFT JOIN ' . POSTS_TABLE . ' p ON (a.post_msg_id = p.post_id AND a.in_message = 0)
 141                  LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id AND a.in_message = 0)
 142                  LEFT JOIN ' . FORUMS_TABLE . ' f ON (f.forum_id = t.forum_id AND a.in_message = 0)
 143                  LEFT JOIN ' . PRIVMSGS_TABLE . ' pr ON (a.post_msg_id = pr.msg_id AND a.in_message = 1)
 144              WHERE a.poster_id = ' . $user->data['user_id'] . "
 145                  AND a.is_orphan = 0
 146              ORDER BY $order_by";
 147          $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
 148  
 149          $row_count = 0;
 150          if ($row = $db->sql_fetchrow($result))
 151          {
 152              $template->assign_var('S_ATTACHMENT_ROWS', true);
 153  
 154              do
 155              {
 156                  if ($row['in_message'])
 157                  {
 158                      $view_topic = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&amp;p={$row['post_msg_id']}");
 159                  }
 160                  else
 161                  {
 162                      $view_topic = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t={$row['topic_id']}&amp;p={$row['post_msg_id']}") . "#p{$row['post_msg_id']}";
 163                  }
 164  
 165                  $template->assign_block_vars('attachrow', array(
 166                      'ROW_NUMBER'        => $row_count + ($start + 1),
 167                      'FILENAME'            => $row['real_filename'],
 168                      'COMMENT'            => bbcode_nl2br($row['attach_comment']),
 169                      'EXTENSION'            => $row['extension'],
 170                      'SIZE'                => get_formatted_filesize($row['filesize']),
 171                      'DOWNLOAD_COUNT'    => $row['download_count'],
 172                      'POST_TIME'            => $user->format_date($row['filetime']),
 173                      'TOPIC_TITLE'        => ($row['in_message']) ? $row['message_title'] : $row['topic_title'],
 174  
 175                      'ATTACH_ID'            => $row['attach_id'],
 176                      'POST_ID'            => $row['post_msg_id'],
 177                      'TOPIC_ID'            => $row['topic_id'],
 178  
 179                      'S_IN_MESSAGE'        => $row['in_message'],
 180                      'S_LOCKED'            => !$row['in_message'] && !$auth->acl_get('m_edit', $row['forum_id']) && ($row['forum_status'] == ITEM_LOCKED || $row['topic_status'] == ITEM_LOCKED || $row['post_edit_locked']),
 181  
 182                      'U_VIEW_ATTACHMENT'    => append_sid("{$phpbb_root_path}download/file.$phpEx", 'id=' . $row['attach_id']),
 183                      'U_VIEW_TOPIC'        => $view_topic)
 184                  );
 185  
 186                  $row_count++;
 187              }
 188              while ($row = $db->sql_fetchrow($result));
 189          }
 190          $db->sql_freeresult($result);
 191  
 192          $base_url = $this->u_action . "&amp;sk=$sort_key&amp;sd=$sort_dir";
 193          $pagination->generate_template_pagination($base_url, 'pagination', 'start', $num_attachments, $config['topics_per_page'], $start);
 194  
 195          $template->assign_vars(array(
 196              'TOTAL_ATTACHMENTS'        => $num_attachments,
 197              'NUM_ATTACHMENTS'        => $user->lang('NUM_ATTACHMENTS', $num_attachments),
 198  
 199              'L_TITLE'                => $user->lang['UCP_ATTACHMENTS'],
 200  
 201              'U_SORT_FILENAME'        => $this->u_action . "&amp;sk=a&amp;sd=" . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a'),
 202              'U_SORT_FILE_COMMENT'    => $this->u_action . "&amp;sk=b&amp;sd=" . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'),
 203              'U_SORT_EXTENSION'        => $this->u_action . "&amp;sk=c&amp;sd=" . (($sort_key == 'c' && $sort_dir == 'a') ? 'd' : 'a'),
 204              'U_SORT_FILESIZE'        => $this->u_action . "&amp;sk=d&amp;sd=" . (($sort_key == 'd' && $sort_dir == 'a') ? 'd' : 'a'),
 205              'U_SORT_DOWNLOADS'        => $this->u_action . "&amp;sk=e&amp;sd=" . (($sort_key == 'e' && $sort_dir == 'a') ? 'd' : 'a'),
 206              'U_SORT_POST_TIME'        => $this->u_action . "&amp;sk=f&amp;sd=" . (($sort_key == 'f' && $sort_dir == 'a') ? 'd' : 'a'),
 207              'U_SORT_TOPIC_TITLE'    => $this->u_action . "&amp;sk=g&amp;sd=" . (($sort_key == 'g' && $sort_dir == 'a') ? 'd' : 'a'),
 208  
 209              'S_DISPLAY_MARK_ALL'    => ($num_attachments) ? true : false,
 210              'S_DISPLAY_PAGINATION'    => ($num_attachments) ? true : false,
 211              'S_UCP_ACTION'            => $this->u_action,
 212              'S_SORT_OPTIONS'         => $s_sort_key,
 213              'S_ORDER_SELECT'        => $s_sort_dir)
 214          );
 215  
 216          $this->tpl_name = 'ucp_attachments';
 217          $this->page_title = 'UCP_ATTACHMENTS';
 218      }
 219  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1