includes/ucp/ucp_attachments.php
author indvdum (gotoindvdum[at]gmail[dot]com)
Thu, 08 Mar 2012 01:33:19 +0400
changeset 11 0a7892c58331
parent 0 ceef6d64c21d
permissions -rw-r--r--
Style fix
indvdum@0
     1
<?php
indvdum@0
     2
/**
indvdum@0
     3
*
indvdum@0
     4
* @package ucp
indvdum@0
     5
* @version $Id$
indvdum@0
     6
* @copyright (c) 2005 phpBB Group
indvdum@0
     7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
indvdum@0
     8
*
indvdum@0
     9
*/
indvdum@0
    10
indvdum@0
    11
/**
indvdum@0
    12
* @ignore
indvdum@0
    13
*/
indvdum@0
    14
if (!defined('IN_PHPBB'))
indvdum@0
    15
{
indvdum@0
    16
	exit;
indvdum@0
    17
}
indvdum@0
    18
indvdum@0
    19
/**
indvdum@0
    20
* ucp_attachments
indvdum@0
    21
* User attachments
indvdum@0
    22
* @package ucp
indvdum@0
    23
*/
indvdum@0
    24
class ucp_attachments
indvdum@0
    25
{
indvdum@0
    26
	var $u_action;
indvdum@0
    27
indvdum@0
    28
	function main($id, $mode)
indvdum@0
    29
	{
indvdum@0
    30
		global $template, $user, $db, $config, $phpEx, $phpbb_root_path;
indvdum@0
    31
indvdum@0
    32
		$start		= request_var('start', 0);
indvdum@0
    33
		$sort_key	= request_var('sk', 'a');
indvdum@0
    34
		$sort_dir	= request_var('sd', 'a');
indvdum@0
    35
indvdum@0
    36
		$delete		= (isset($_POST['delete'])) ? true : false;
indvdum@0
    37
		$confirm	= (isset($_POST['confirm'])) ? true : false;
indvdum@0
    38
		$delete_ids	= array_keys(request_var('attachment', array(0)));
indvdum@0
    39
indvdum@0
    40
		if ($delete && sizeof($delete_ids))
indvdum@0
    41
		{
indvdum@0
    42
			// Validate $delete_ids...
indvdum@0
    43
			$sql = 'SELECT attach_id
indvdum@0
    44
				FROM ' . ATTACHMENTS_TABLE . '
indvdum@0
    45
				WHERE poster_id = ' . $user->data['user_id'] . '
indvdum@0
    46
					AND is_orphan = 0
indvdum@0
    47
					AND ' . $db->sql_in_set('attach_id', $delete_ids);
indvdum@0
    48
			$result = $db->sql_query($sql);
indvdum@0
    49
indvdum@0
    50
			$delete_ids = array();
indvdum@0
    51
			while ($row = $db->sql_fetchrow($result))
indvdum@0
    52
			{
indvdum@0
    53
				$delete_ids[] = $row['attach_id'];
indvdum@0
    54
			}
indvdum@0
    55
			$db->sql_freeresult($result);
indvdum@0
    56
		}
indvdum@0
    57
indvdum@0
    58
		if ($delete && sizeof($delete_ids))
indvdum@0
    59
		{
indvdum@0
    60
			$s_hidden_fields = array(
indvdum@0
    61
				'delete'	=> 1
indvdum@0
    62
			);
indvdum@0
    63
indvdum@0
    64
			foreach ($delete_ids as $attachment_id)
indvdum@0
    65
			{
indvdum@0
    66
				$s_hidden_fields['attachment'][$attachment_id] = 1;
indvdum@0
    67
			}
indvdum@0
    68
indvdum@0
    69
			if (confirm_box(true))
indvdum@0
    70
			{
indvdum@0
    71
				if (!function_exists('delete_attachments'))
indvdum@0
    72
				{
indvdum@0
    73
					include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
indvdum@0
    74
				}
indvdum@0
    75
indvdum@0
    76
				delete_attachments('attach', $delete_ids);
indvdum@0
    77
indvdum@0
    78
				meta_refresh(3, $this->u_action);
indvdum@0
    79
				$message = ((sizeof($delete_ids) == 1) ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED']) . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
indvdum@0
    80
				trigger_error($message);
indvdum@0
    81
			}
indvdum@0
    82
			else
indvdum@0
    83
			{
indvdum@0
    84
				confirm_box(false, (sizeof($delete_ids) == 1) ? 'DELETE_ATTACHMENT' : 'DELETE_ATTACHMENTS', build_hidden_fields($s_hidden_fields));
indvdum@0
    85
			}
indvdum@0
    86
		}
indvdum@0
    87
indvdum@0
    88
		// Select box eventually
indvdum@0
    89
		$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']);
indvdum@0
    90
		$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');
indvdum@0
    91
indvdum@0
    92
		$sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
indvdum@0
    93
indvdum@0
    94
		$s_sort_key = '';
indvdum@0
    95
		foreach ($sort_key_text as $key => $value)
indvdum@0
    96
		{
indvdum@0
    97
			$selected = ($sort_key == $key) ? ' selected="selected"' : '';
indvdum@0
    98
			$s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
indvdum@0
    99
		}
indvdum@0
   100
indvdum@0
   101
		$s_sort_dir = '';
indvdum@0
   102
		foreach ($sort_dir_text as $key => $value)
indvdum@0
   103
		{
indvdum@0
   104
			$selected = ($sort_dir == $key) ? ' selected="selected"' : '';
indvdum@0
   105
			$s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
indvdum@0
   106
		}
indvdum@0
   107
indvdum@0
   108
		if (!isset($sort_key_sql[$sort_key]))
indvdum@0
   109
		{
indvdum@0
   110
			$sort_key = 'a';
indvdum@0
   111
		}
indvdum@0
   112
indvdum@0
   113
		$order_by = $sort_key_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
indvdum@0
   114
indvdum@0
   115
		$sql = 'SELECT COUNT(attach_id) as num_attachments
indvdum@0
   116
			FROM ' . ATTACHMENTS_TABLE . '
indvdum@0
   117
			WHERE poster_id = ' . $user->data['user_id'] . '
indvdum@0
   118
				AND is_orphan = 0';
indvdum@0
   119
		$result = $db->sql_query($sql);
indvdum@0
   120
		$num_attachments = $db->sql_fetchfield('num_attachments');
indvdum@0
   121
		$db->sql_freeresult($result);
indvdum@0
   122
indvdum@0
   123
		$sql = 'SELECT a.*, t.topic_title, p.message_subject as message_title
indvdum@0
   124
			FROM ' . ATTACHMENTS_TABLE . ' a
indvdum@0
   125
				LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id AND a.in_message = 0)
indvdum@0
   126
				LEFT JOIN ' . PRIVMSGS_TABLE . ' p ON (a.post_msg_id = p.msg_id AND a.in_message = 1)
indvdum@0
   127
			WHERE a.poster_id = ' . $user->data['user_id'] . "
indvdum@0
   128
				AND a.is_orphan = 0
indvdum@0
   129
			ORDER BY $order_by";
indvdum@0
   130
		$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
indvdum@0
   131
indvdum@0
   132
		$row_count = 0;
indvdum@0
   133
		if ($row = $db->sql_fetchrow($result))
indvdum@0
   134
		{
indvdum@0
   135
			$template->assign_var('S_ATTACHMENT_ROWS', true);
indvdum@0
   136
indvdum@0
   137
			do
indvdum@0
   138
			{
indvdum@0
   139
				if ($row['in_message'])
indvdum@0
   140
				{
indvdum@0
   141
					$view_topic = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&amp;p={$row['post_msg_id']}");
indvdum@0
   142
				}
indvdum@0
   143
				else
indvdum@0
   144
				{
indvdum@0
   145
					$view_topic = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t={$row['topic_id']}&amp;p={$row['post_msg_id']}") . "#p{$row['post_msg_id']}";
indvdum@0
   146
				}
indvdum@0
   147
indvdum@0
   148
				$template->assign_block_vars('attachrow', array(
indvdum@0
   149
					'ROW_NUMBER'		=> $row_count + ($start + 1),
indvdum@0
   150
					'FILENAME'			=> $row['real_filename'],
indvdum@0
   151
					'COMMENT'			=> bbcode_nl2br($row['attach_comment']),
indvdum@0
   152
					'EXTENSION'			=> $row['extension'],
indvdum@0
   153
					'SIZE'				=> get_formatted_filesize($row['filesize']),
indvdum@0
   154
					'DOWNLOAD_COUNT'	=> $row['download_count'],
indvdum@0
   155
					'POST_TIME'			=> $user->format_date($row['filetime']),
indvdum@0
   156
					'TOPIC_TITLE'		=> ($row['in_message']) ? $row['message_title'] : $row['topic_title'],
indvdum@0
   157
indvdum@0
   158
					'ATTACH_ID'			=> $row['attach_id'],
indvdum@0
   159
					'POST_ID'			=> $row['post_msg_id'],
indvdum@0
   160
					'TOPIC_ID'			=> $row['topic_id'],
indvdum@0
   161
indvdum@0
   162
					'S_IN_MESSAGE'		=> $row['in_message'],
indvdum@0
   163
indvdum@0
   164
					'U_VIEW_ATTACHMENT'	=> append_sid("{$phpbb_root_path}download/file.$phpEx", 'id=' . $row['attach_id']),
indvdum@0
   165
					'U_VIEW_TOPIC'		=> $view_topic)
indvdum@0
   166
				);
indvdum@0
   167
indvdum@0
   168
				$row_count++;
indvdum@0
   169
			}
indvdum@0
   170
			while ($row = $db->sql_fetchrow($result));
indvdum@0
   171
		}
indvdum@0
   172
		$db->sql_freeresult($result);
indvdum@0
   173
indvdum@0
   174
		$template->assign_vars(array(
indvdum@0
   175
			'PAGE_NUMBER'			=> on_page($num_attachments, $config['topics_per_page'], $start),
indvdum@0
   176
			'PAGINATION'			=> generate_pagination($this->u_action . "&amp;sk=$sort_key&amp;sd=$sort_dir", $num_attachments, $config['topics_per_page'], $start),
indvdum@0
   177
			'TOTAL_ATTACHMENTS'		=> $num_attachments,
indvdum@0
   178
indvdum@0
   179
			'L_TITLE'				=> $user->lang['UCP_ATTACHMENTS'],
indvdum@0
   180
indvdum@0
   181
			'U_SORT_FILENAME'		=> $this->u_action . "&amp;sk=a&amp;sd=" . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a'),
indvdum@0
   182
			'U_SORT_FILE_COMMENT'	=> $this->u_action . "&amp;sk=b&amp;sd=" . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'),
indvdum@0
   183
			'U_SORT_EXTENSION'		=> $this->u_action . "&amp;sk=c&amp;sd=" . (($sort_key == 'c' && $sort_dir == 'a') ? 'd' : 'a'),
indvdum@0
   184
			'U_SORT_FILESIZE'		=> $this->u_action . "&amp;sk=d&amp;sd=" . (($sort_key == 'd' && $sort_dir == 'a') ? 'd' : 'a'),
indvdum@0
   185
			'U_SORT_DOWNLOADS'		=> $this->u_action . "&amp;sk=e&amp;sd=" . (($sort_key == 'e' && $sort_dir == 'a') ? 'd' : 'a'),
indvdum@0
   186
			'U_SORT_POST_TIME'		=> $this->u_action . "&amp;sk=f&amp;sd=" . (($sort_key == 'f' && $sort_dir == 'a') ? 'd' : 'a'),
indvdum@0
   187
			'U_SORT_TOPIC_TITLE'	=> $this->u_action . "&amp;sk=g&amp;sd=" . (($sort_key == 'g' && $sort_dir == 'a') ? 'd' : 'a'),
indvdum@0
   188
indvdum@0
   189
			'S_DISPLAY_MARK_ALL'	=> ($num_attachments) ? true : false,
indvdum@0
   190
			'S_DISPLAY_PAGINATION'	=> ($num_attachments) ? true : false,
indvdum@0
   191
			'S_UCP_ACTION'			=> $this->u_action,
indvdum@0
   192
			'S_SORT_OPTIONS' 		=> $s_sort_key,
indvdum@0
   193
			'S_ORDER_SELECT'		=> $s_sort_dir)
indvdum@0
   194
		);
indvdum@0
   195
indvdum@0
   196
		$this->tpl_name = 'ucp_attachments';
indvdum@0
   197
		$this->page_title = 'UCP_ATTACHMENTS';
indvdum@0
   198
	}
indvdum@0
   199
}
indvdum@0
   200
indvdum@0
   201
?>