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