6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 if (!defined('IN_PHPBB'))
28 function main($id, $mode)
30 global $template, $user, $db, $config, $phpEx, $phpbb_root_path;
32 $start = request_var('start', 0);
33 $sort_key = request_var('sk', 'a');
34 $sort_dir = request_var('sd', 'a');
36 $delete = (isset($_POST['delete'])) ? true : false;
37 $confirm = (isset($_POST['confirm'])) ? true : false;
38 $delete_ids = array_keys(request_var('attachment', array(0)));
40 if ($delete && sizeof($delete_ids))
42 // Validate $delete_ids...
43 $sql = 'SELECT attach_id
44 FROM ' . ATTACHMENTS_TABLE . '
45 WHERE poster_id = ' . $user->data['user_id'] . '
47 AND ' . $db->sql_in_set('attach_id', $delete_ids);
48 $result = $db->sql_query($sql);
50 $delete_ids = array();
51 while ($row = $db->sql_fetchrow($result))
53 $delete_ids[] = $row['attach_id'];
55 $db->sql_freeresult($result);
58 if ($delete && sizeof($delete_ids))
60 $s_hidden_fields = array(
64 foreach ($delete_ids as $attachment_id)
66 $s_hidden_fields['attachment'][$attachment_id] = 1;
69 if (confirm_box(true))
71 if (!function_exists('delete_attachments'))
73 include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
76 delete_attachments('attach', $delete_ids);
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);
84 confirm_box(false, (sizeof($delete_ids) == 1) ? 'DELETE_ATTACHMENT' : 'DELETE_ATTACHMENTS', build_hidden_fields($s_hidden_fields));
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');
92 $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
95 foreach ($sort_key_text as $key => $value)
97 $selected = ($sort_key == $key) ? ' selected="selected"' : '';
98 $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
102 foreach ($sort_dir_text as $key => $value)
104 $selected = ($sort_dir == $key) ? ' selected="selected"' : '';
105 $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
108 if (!isset($sort_key_sql[$sort_key]))
113 $order_by = $sort_key_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
115 $sql = 'SELECT COUNT(attach_id) as num_attachments
116 FROM ' . ATTACHMENTS_TABLE . '
117 WHERE poster_id = ' . $user->data['user_id'] . '
119 $result = $db->sql_query($sql);
120 $num_attachments = $db->sql_fetchfield('num_attachments');
121 $db->sql_freeresult($result);
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'] . "
130 $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
133 if ($row = $db->sql_fetchrow($result))
135 $template->assign_var('S_ATTACHMENT_ROWS', true);
139 if ($row['in_message'])
141 $view_topic = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&p={$row['post_msg_id']}");
145 $view_topic = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t={$row['topic_id']}&p={$row['post_msg_id']}") . "#p{$row['post_msg_id']}";
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'],
158 'ATTACH_ID' => $row['attach_id'],
159 'POST_ID' => $row['post_msg_id'],
160 'TOPIC_ID' => $row['topic_id'],
162 'S_IN_MESSAGE' => $row['in_message'],
164 'U_VIEW_ATTACHMENT' => append_sid("{$phpbb_root_path}download/file.$phpEx", 'id=' . $row['attach_id']),
165 'U_VIEW_TOPIC' => $view_topic)
170 while ($row = $db->sql_fetchrow($result));
172 $db->sql_freeresult($result);
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,
179 'L_TITLE' => $user->lang['UCP_ATTACHMENTS'],
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'),
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)
196 $this->tpl_name = 'ucp_attachments';
197 $this->page_title = 'UCP_ATTACHMENTS';