Blame Identity/Webenv/phpBB/3.0.4/includes/ucp/ucp_attachments.php

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

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