includes/ucp/ucp_attachments.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/includes/ucp/ucp_attachments.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,201 @@
     1.4 +<?php
     1.5 +/**
     1.6 +*
     1.7 +* @package ucp
     1.8 +* @version $Id$
     1.9 +* @copyright (c) 2005 phpBB Group
    1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    1.11 +*
    1.12 +*/
    1.13 +
    1.14 +/**
    1.15 +* @ignore
    1.16 +*/
    1.17 +if (!defined('IN_PHPBB'))
    1.18 +{
    1.19 +	exit;
    1.20 +}
    1.21 +
    1.22 +/**
    1.23 +* ucp_attachments
    1.24 +* User attachments
    1.25 +* @package ucp
    1.26 +*/
    1.27 +class ucp_attachments
    1.28 +{
    1.29 +	var $u_action;
    1.30 +
    1.31 +	function main($id, $mode)
    1.32 +	{
    1.33 +		global $template, $user, $db, $config, $phpEx, $phpbb_root_path;
    1.34 +
    1.35 +		$start		= request_var('start', 0);
    1.36 +		$sort_key	= request_var('sk', 'a');
    1.37 +		$sort_dir	= request_var('sd', 'a');
    1.38 +
    1.39 +		$delete		= (isset($_POST['delete'])) ? true : false;
    1.40 +		$confirm	= (isset($_POST['confirm'])) ? true : false;
    1.41 +		$delete_ids	= array_keys(request_var('attachment', array(0)));
    1.42 +
    1.43 +		if ($delete && sizeof($delete_ids))
    1.44 +		{
    1.45 +			// Validate $delete_ids...
    1.46 +			$sql = 'SELECT attach_id
    1.47 +				FROM ' . ATTACHMENTS_TABLE . '
    1.48 +				WHERE poster_id = ' . $user->data['user_id'] . '
    1.49 +					AND is_orphan = 0
    1.50 +					AND ' . $db->sql_in_set('attach_id', $delete_ids);
    1.51 +			$result = $db->sql_query($sql);
    1.52 +
    1.53 +			$delete_ids = array();
    1.54 +			while ($row = $db->sql_fetchrow($result))
    1.55 +			{
    1.56 +				$delete_ids[] = $row['attach_id'];
    1.57 +			}
    1.58 +			$db->sql_freeresult($result);
    1.59 +		}
    1.60 +
    1.61 +		if ($delete && sizeof($delete_ids))
    1.62 +		{
    1.63 +			$s_hidden_fields = array(
    1.64 +				'delete'	=> 1
    1.65 +			);
    1.66 +
    1.67 +			foreach ($delete_ids as $attachment_id)
    1.68 +			{
    1.69 +				$s_hidden_fields['attachment'][$attachment_id] = 1;
    1.70 +			}
    1.71 +
    1.72 +			if (confirm_box(true))
    1.73 +			{
    1.74 +				if (!function_exists('delete_attachments'))
    1.75 +				{
    1.76 +					include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
    1.77 +				}
    1.78 +
    1.79 +				delete_attachments('attach', $delete_ids);
    1.80 +
    1.81 +				meta_refresh(3, $this->u_action);
    1.82 +				$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>');
    1.83 +				trigger_error($message);
    1.84 +			}
    1.85 +			else
    1.86 +			{
    1.87 +				confirm_box(false, (sizeof($delete_ids) == 1) ? 'DELETE_ATTACHMENT' : 'DELETE_ATTACHMENTS', build_hidden_fields($s_hidden_fields));
    1.88 +			}
    1.89 +		}
    1.90 +
    1.91 +		// Select box eventually
    1.92 +		$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']);
    1.93 +		$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');
    1.94 +
    1.95 +		$sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
    1.96 +
    1.97 +		$s_sort_key = '';
    1.98 +		foreach ($sort_key_text as $key => $value)
    1.99 +		{
   1.100 +			$selected = ($sort_key == $key) ? ' selected="selected"' : '';
   1.101 +			$s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
   1.102 +		}
   1.103 +
   1.104 +		$s_sort_dir = '';
   1.105 +		foreach ($sort_dir_text as $key => $value)
   1.106 +		{
   1.107 +			$selected = ($sort_dir == $key) ? ' selected="selected"' : '';
   1.108 +			$s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
   1.109 +		}
   1.110 +
   1.111 +		if (!isset($sort_key_sql[$sort_key]))
   1.112 +		{
   1.113 +			$sort_key = 'a';
   1.114 +		}
   1.115 +
   1.116 +		$order_by = $sort_key_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
   1.117 +
   1.118 +		$sql = 'SELECT COUNT(attach_id) as num_attachments
   1.119 +			FROM ' . ATTACHMENTS_TABLE . '
   1.120 +			WHERE poster_id = ' . $user->data['user_id'] . '
   1.121 +				AND is_orphan = 0';
   1.122 +		$result = $db->sql_query($sql);
   1.123 +		$num_attachments = $db->sql_fetchfield('num_attachments');
   1.124 +		$db->sql_freeresult($result);
   1.125 +
   1.126 +		$sql = 'SELECT a.*, t.topic_title, p.message_subject as message_title
   1.127 +			FROM ' . ATTACHMENTS_TABLE . ' a
   1.128 +				LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id AND a.in_message = 0)
   1.129 +				LEFT JOIN ' . PRIVMSGS_TABLE . ' p ON (a.post_msg_id = p.msg_id AND a.in_message = 1)
   1.130 +			WHERE a.poster_id = ' . $user->data['user_id'] . "
   1.131 +				AND a.is_orphan = 0
   1.132 +			ORDER BY $order_by";
   1.133 +		$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
   1.134 +
   1.135 +		$row_count = 0;
   1.136 +		if ($row = $db->sql_fetchrow($result))
   1.137 +		{
   1.138 +			$template->assign_var('S_ATTACHMENT_ROWS', true);
   1.139 +
   1.140 +			do
   1.141 +			{
   1.142 +				if ($row['in_message'])
   1.143 +				{
   1.144 +					$view_topic = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&amp;p={$row['post_msg_id']}");
   1.145 +				}
   1.146 +				else
   1.147 +				{
   1.148 +					$view_topic = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t={$row['topic_id']}&amp;p={$row['post_msg_id']}") . "#p{$row['post_msg_id']}";
   1.149 +				}
   1.150 +
   1.151 +				$template->assign_block_vars('attachrow', array(
   1.152 +					'ROW_NUMBER'		=> $row_count + ($start + 1),
   1.153 +					'FILENAME'			=> $row['real_filename'],
   1.154 +					'COMMENT'			=> bbcode_nl2br($row['attach_comment']),
   1.155 +					'EXTENSION'			=> $row['extension'],
   1.156 +					'SIZE'				=> get_formatted_filesize($row['filesize']),
   1.157 +					'DOWNLOAD_COUNT'	=> $row['download_count'],
   1.158 +					'POST_TIME'			=> $user->format_date($row['filetime']),
   1.159 +					'TOPIC_TITLE'		=> ($row['in_message']) ? $row['message_title'] : $row['topic_title'],
   1.160 +
   1.161 +					'ATTACH_ID'			=> $row['attach_id'],
   1.162 +					'POST_ID'			=> $row['post_msg_id'],
   1.163 +					'TOPIC_ID'			=> $row['topic_id'],
   1.164 +
   1.165 +					'S_IN_MESSAGE'		=> $row['in_message'],
   1.166 +
   1.167 +					'U_VIEW_ATTACHMENT'	=> append_sid("{$phpbb_root_path}download/file.$phpEx", 'id=' . $row['attach_id']),
   1.168 +					'U_VIEW_TOPIC'		=> $view_topic)
   1.169 +				);
   1.170 +
   1.171 +				$row_count++;
   1.172 +			}
   1.173 +			while ($row = $db->sql_fetchrow($result));
   1.174 +		}
   1.175 +		$db->sql_freeresult($result);
   1.176 +
   1.177 +		$template->assign_vars(array(
   1.178 +			'PAGE_NUMBER'			=> on_page($num_attachments, $config['topics_per_page'], $start),
   1.179 +			'PAGINATION'			=> generate_pagination($this->u_action . "&amp;sk=$sort_key&amp;sd=$sort_dir", $num_attachments, $config['topics_per_page'], $start),
   1.180 +			'TOTAL_ATTACHMENTS'		=> $num_attachments,
   1.181 +
   1.182 +			'L_TITLE'				=> $user->lang['UCP_ATTACHMENTS'],
   1.183 +
   1.184 +			'U_SORT_FILENAME'		=> $this->u_action . "&amp;sk=a&amp;sd=" . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a'),
   1.185 +			'U_SORT_FILE_COMMENT'	=> $this->u_action . "&amp;sk=b&amp;sd=" . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'),
   1.186 +			'U_SORT_EXTENSION'		=> $this->u_action . "&amp;sk=c&amp;sd=" . (($sort_key == 'c' && $sort_dir == 'a') ? 'd' : 'a'),
   1.187 +			'U_SORT_FILESIZE'		=> $this->u_action . "&amp;sk=d&amp;sd=" . (($sort_key == 'd' && $sort_dir == 'a') ? 'd' : 'a'),
   1.188 +			'U_SORT_DOWNLOADS'		=> $this->u_action . "&amp;sk=e&amp;sd=" . (($sort_key == 'e' && $sort_dir == 'a') ? 'd' : 'a'),
   1.189 +			'U_SORT_POST_TIME'		=> $this->u_action . "&amp;sk=f&amp;sd=" . (($sort_key == 'f' && $sort_dir == 'a') ? 'd' : 'a'),
   1.190 +			'U_SORT_TOPIC_TITLE'	=> $this->u_action . "&amp;sk=g&amp;sd=" . (($sort_key == 'g' && $sort_dir == 'a') ? 'd' : 'a'),
   1.191 +
   1.192 +			'S_DISPLAY_MARK_ALL'	=> ($num_attachments) ? true : false,
   1.193 +			'S_DISPLAY_PAGINATION'	=> ($num_attachments) ? true : false,
   1.194 +			'S_UCP_ACTION'			=> $this->u_action,
   1.195 +			'S_SORT_OPTIONS' 		=> $s_sort_key,
   1.196 +			'S_ORDER_SELECT'		=> $s_sort_dir)
   1.197 +		);
   1.198 +
   1.199 +		$this->tpl_name = 'ucp_attachments';
   1.200 +		$this->page_title = 'UCP_ATTACHMENTS';
   1.201 +	}
   1.202 +}
   1.203 +
   1.204 +?>
   1.205 \ No newline at end of file