Blame Extras/phpBB/3.0.4/includes/ucp/ucp_attachments.php

4c79b5
4c79b5
/**
4c79b5
*
4c79b5
* @package ucp
4c79b5
* @version $Id: ucp_attachments.php 8479 2008-03-29 00:22:48Z naderman $
4c79b5
* @copyright (c) 2005 phpBB Group
4c79b5
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
4c79b5
*
4c79b5
*/
4c79b5
4c79b5
/**
4c79b5
* @ignore
4c79b5
*/
4c79b5
if (!defined('IN_PHPBB'))
4c79b5
{
4c79b5
	exit;
4c79b5
}
4c79b5
4c79b5
/**
4c79b5
* ucp_attachments
4c79b5
* User attachments
4c79b5
* @package ucp
4c79b5
*/
4c79b5
class ucp_attachments
4c79b5
{
4c79b5
	var $u_action;
4c79b5
4c79b5
	function main($id, $mode)
4c79b5
	{
4c79b5
		global $template, $user, $db, $config, $phpEx, $phpbb_root_path;
4c79b5
4c79b5
		$start		= request_var('start', 0);
4c79b5
		$sort_key	= request_var('sk', 'a');
4c79b5
		$sort_dir	= request_var('sd', 'a');
4c79b5
4c79b5
		$delete		= (isset($_POST['delete'])) ? true : false;
4c79b5
		$confirm	= (isset($_POST['confirm'])) ? true : false;
4c79b5
		$delete_ids	= array_keys(request_var('attachment', array(0)));
4c79b5
4c79b5
		if ($delete && sizeof($delete_ids))
4c79b5
		{
4c79b5
			// Validate $delete_ids...
4c79b5
			$sql = 'SELECT attach_id
4c79b5
				FROM ' . ATTACHMENTS_TABLE . '
4c79b5
				WHERE poster_id = ' . $user->data['user_id'] . '
4c79b5
					AND is_orphan = 0
4c79b5
					AND ' . $db->sql_in_set('attach_id', $delete_ids);
4c79b5
			$result = $db->sql_query($sql);
4c79b5
4c79b5
			$delete_ids = array();
4c79b5
			while ($row = $db->sql_fetchrow($result))
4c79b5
			{
4c79b5
				$delete_ids[] = $row['attach_id'];
4c79b5
			}
4c79b5
			$db->sql_freeresult($result);
4c79b5
		}
4c79b5
4c79b5
		if ($delete && sizeof($delete_ids))
4c79b5
		{
4c79b5
			$s_hidden_fields = array(
4c79b5
				'delete'	=> 1
4c79b5
			);
4c79b5
4c79b5
			foreach ($delete_ids as $attachment_id)
4c79b5
			{
4c79b5
				$s_hidden_fields['attachment'][$attachment_id] = 1;
4c79b5
			}
4c79b5
4c79b5
			if (confirm_box(true))
4c79b5
			{
4c79b5
				if (!function_exists('delete_attachments'))
4c79b5
				{
4c79b5
					include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
4c79b5
				}
4c79b5
4c79b5
				delete_attachments('attach', $delete_ids);
4c79b5
4c79b5
				meta_refresh(3, $this->u_action);
4c79b5
				$message = ((sizeof($delete_ids) == 1) ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED']) . '

' . sprintf($user->lang['RETURN_UCP'], '', '');
4c79b5
				trigger_error($message);
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				confirm_box(false, (sizeof($delete_ids) == 1) ? 'DELETE_ATTACHMENT' : 'DELETE_ATTACHMENTS', build_hidden_fields($s_hidden_fields));
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		// Select box eventually
4c79b5
		$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']);
4c79b5
		$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');
4c79b5
4c79b5
		$sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
4c79b5
4c79b5
		$s_sort_key = '';
4c79b5
		foreach ($sort_key_text as $key => $value)
4c79b5
		{
4c79b5
			$selected = ($sort_key == $key) ? ' selected="selected"' : '';
4c79b5
			$s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
4c79b5
		}
4c79b5
4c79b5
		$s_sort_dir = '';
4c79b5
		foreach ($sort_dir_text as $key => $value)
4c79b5
		{
4c79b5
			$selected = ($sort_dir == $key) ? ' selected="selected"' : '';
4c79b5
			$s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
4c79b5
		}
4c79b5
4c79b5
		if (!isset($sort_key_sql[$sort_key]))
4c79b5
		{
4c79b5
			$sort_key = 'a';
4c79b5
		}
4c79b5
4c79b5
		$order_by = $sort_key_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
4c79b5
4c79b5
		$sql = 'SELECT COUNT(attach_id) as num_attachments
4c79b5
			FROM ' . ATTACHMENTS_TABLE . '
4c79b5
			WHERE poster_id = ' . $user->data['user_id'] . '
4c79b5
				AND is_orphan = 0';
4c79b5
		$result = $db->sql_query($sql);
4c79b5
		$num_attachments = $db->sql_fetchfield('num_attachments');
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		$sql = 'SELECT a.*, t.topic_title, p.message_subject as message_title
4c79b5
			FROM ' . ATTACHMENTS_TABLE . ' a
4c79b5
				LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id AND a.in_message = 0)
4c79b5
				LEFT JOIN ' . PRIVMSGS_TABLE . ' p ON (a.post_msg_id = p.msg_id AND a.in_message = 1)
4c79b5
			WHERE a.poster_id = ' . $user->data['user_id'] . "
4c79b5
				AND a.is_orphan = 0
4c79b5
			ORDER BY $order_by";
4c79b5
		$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
4c79b5
4c79b5
		$row_count = 0;
4c79b5
		if ($row = $db->sql_fetchrow($result))
4c79b5
		{
4c79b5
			$template->assign_var('S_ATTACHMENT_ROWS', true);
4c79b5
4c79b5
			do
4c79b5
			{
4c79b5
				if ($row['in_message'])
4c79b5
				{
4c79b5
					$view_topic = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&p={$row['post_msg_id']}");
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					$view_topic = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t={$row['topic_id']}&p={$row['post_msg_id']}") . "#p{$row['post_msg_id']}";
4c79b5
				}
4c79b5
4c79b5
				$template->assign_block_vars('attachrow', array(
4c79b5
					'ROW_NUMBER'		=> $row_count + ($start + 1),
4c79b5
					'FILENAME'			=> $row['real_filename'],
4c79b5
					'COMMENT'			=> bbcode_nl2br($row['attach_comment']),
4c79b5
					'EXTENSION'			=> $row['extension'],
4c79b5
					'SIZE'				=> get_formatted_filesize($row['filesize']),
4c79b5
					'DOWNLOAD_COUNT'	=> $row['download_count'],
4c79b5
					'POST_TIME'			=> $user->format_date($row['filetime']),
4c79b5
					'TOPIC_TITLE'		=> ($row['in_message']) ? $row['message_title'] : $row['topic_title'],
4c79b5
4c79b5
					'ATTACH_ID'			=> $row['attach_id'],
4c79b5
					'POST_ID'			=> $row['post_msg_id'],
4c79b5
					'TOPIC_ID'			=> $row['topic_id'],
4c79b5
4c79b5
					'S_IN_MESSAGE'		=> $row['in_message'],
4c79b5
4c79b5
					'U_VIEW_ATTACHMENT'	=> append_sid("{$phpbb_root_path}download/file.$phpEx", 'id=' . $row['attach_id']),
4c79b5
					'U_VIEW_TOPIC'		=> $view_topic)
4c79b5
				);
4c79b5
4c79b5
				$row_count++;
4c79b5
			}
4c79b5
			while ($row = $db->sql_fetchrow($result));
4c79b5
		}
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		$template->assign_vars(array(
4c79b5
			'PAGE_NUMBER'			=> on_page($num_attachments, $config['topics_per_page'], $start),
4c79b5
			'PAGINATION'			=> generate_pagination($this->u_action . "&sk=$sort_key&sd=$sort_dir", $num_attachments, $config['topics_per_page'], $start),
4c79b5
			'TOTAL_ATTACHMENTS'		=> $num_attachments,
4c79b5
4c79b5
			'L_TITLE'				=> $user->lang['UCP_ATTACHMENTS'],
4c79b5
4c79b5
			'U_SORT_FILENAME'		=> $this->u_action . "&sk=a&sd=" . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a'),
4c79b5
			'U_SORT_FILE_COMMENT'	=> $this->u_action . "&sk=b&sd=" . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'),
4c79b5
			'U_SORT_EXTENSION'		=> $this->u_action . "&sk=c&sd=" . (($sort_key == 'c' && $sort_dir == 'a') ? 'd' : 'a'),
4c79b5
			'U_SORT_FILESIZE'		=> $this->u_action . "&sk=d&sd=" . (($sort_key == 'd' && $sort_dir == 'a') ? 'd' : 'a'),
4c79b5
			'U_SORT_DOWNLOADS'		=> $this->u_action . "&sk=e&sd=" . (($sort_key == 'e' && $sort_dir == 'a') ? 'd' : 'a'),
4c79b5
			'U_SORT_POST_TIME'		=> $this->u_action . "&sk=f&sd=" . (($sort_key == 'f' && $sort_dir == 'a') ? 'd' : 'a'),
4c79b5
			'U_SORT_TOPIC_TITLE'	=> $this->u_action . "&sk=g&sd=" . (($sort_key == 'f' && $sort_dir == 'a') ? 'd' : 'a'),
4c79b5
4c79b5
			'S_DISPLAY_MARK_ALL'	=> ($num_attachments) ? true : false,
4c79b5
			'S_DISPLAY_PAGINATION'	=> ($num_attachments) ? true : false,
4c79b5
			'S_UCP_ACTION'			=> $this->u_action,
4c79b5
			'S_SORT_OPTIONS' 		=> $s_sort_key,
4c79b5
			'S_ORDER_SELECT'		=> $s_sort_dir)
4c79b5
		);
4c79b5
4c79b5
		$this->tpl_name = 'ucp_attachments';
4c79b5
		$this->page_title = 'UCP_ATTACHMENTS';
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
?>