admin_attach_cp.php
来自「这是php编的论坛的原代码」· PHP 代码 · 共 891 行 · 第 1/2 页
PHP
891 行
<?php
/***************************************************************************
* admin_attach_cp.php
* -------------------
* begin : Saturday, Feb 09, 2002
* copyright : (C) 2002 Meik Sievertsen
* email : acyd.burn@gmx.de
*
* $Id: admin_attach_cp.php,v 1.1.1.1 2003/02/11 22:27:30 wei.gao Exp $
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
define('IN_PHPBB', true);
if( !empty($setmodules) )
{
$filename = basename(__FILE__);
$module['Attachments']['Control_Panel'] = $filename;
return;
}
//
// Let's set the root dir for phpBB
//
$phpbb_root_path = './../';
require($phpbb_root_path . 'extension.inc');
require('pagestart.' . $phpEx);
//
// Init Variables
//
$start = ( isset($HTTP_GET_VARS['start']) ) ? $HTTP_GET_VARS['start'] : 0;
if(isset($HTTP_POST_VARS['order']))
{
$sort_order = ($HTTP_POST_VARS['order'] == 'ASC') ? 'ASC' : 'DESC';
}
else if(isset($HTTP_GET_VARS['order']))
{
$sort_order = ($HTTP_GET_VARS['order'] == 'ASC') ? 'ASC' : 'DESC';
}
else
{
$sort_order = '';
}
if(isset($HTTP_GET_VARS['mode']) || isset($HTTP_POST_VARS['mode']))
{
$mode = (isset($HTTP_POST_VARS['mode'])) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
}
else
{
$mode = '';
}
if( isset($HTTP_GET_VARS['view']) || isset($HTTP_POST_VARS['view']) )
{
$view = ( isset($HTTP_POST_VARS['view']) ) ? $HTTP_POST_VARS['view'] : $HTTP_GET_VARS['view'];
}
else
{
$view = '';
}
if(isset($HTTP_GET_VARS['uid']) || isset($HTTP_POST_VARS['u_id']))
{
$uid = (isset($HTTP_POST_VARS['u_id'])) ? $HTTP_POST_VARS['u_id'] : $HTTP_GET_VARS['uid'];
}
else
{
$uid = '';
}
$view = ( $HTTP_POST_VARS['search'] ) ? 'attachments' : $view;
//
// process modes based on view
//
if ($view == 'username')
{
$mode_types_text = array($lang['Sort_Username'], $lang['Sort_Attachments'], $lang['Sort_Size']);
$mode_types = array('username', 'attachments', 'filesize');
if (empty($mode))
{
$mode = 'attachments';
$sort_order = 'DESC';
}
}
else if ($view == 'attachments')
{
$mode_types_text = array($lang['Sort_Filename'], $lang['Sort_Comment'], $lang['Sort_Extension'], $lang['Sort_Size'], $lang['Sort_Downloads'], $lang['Sort_Posttime'], /*$lang['Sort_Posts']*/);
$mode_types = array('real_filename', 'comment', 'extension', 'filesize', 'downloads', 'post_time'/*, 'posts'*/);
if (empty($mode))
{
$mode = 'real_filename';
$sort_order = 'ASC';
}
}
else if ($view == 'search')
{
$mode_types_text = array($lang['Sort_Filename'], $lang['Sort_Comment'], $lang['Sort_Extension'], $lang['Sort_Size'], $lang['Sort_Downloads'], $lang['Sort_Posttime'], /*$lang['Sort_Posts']*/);
$mode_types = array('real_filename', 'comment', 'extension', 'filesize', 'downloads', 'post_time'/*, 'posts'*/);
$sort_order = 'DESC';
}
else
{
$view = 'stats';
$mode_types_text = array();
$sort_order = '';
}
//
// Pagination ?
//
$do_pagination = ( ($view != 'stats') && ($view != 'search') ) ? TRUE : FALSE;
//
// Set Order
//
$order_by = '';
if ($view == 'username')
{
switch($mode)
{
case 'username':
$order_by = 'ORDER BY u.username ' . $sort_order . ' LIMIT ' . $start . ', ' . $board_config['topics_per_page'];
break;
case 'attachments':
$order_by = 'ORDER BY total_attachments ' . $sort_order . ' LIMIT ' . $start . ', ' . $board_config['topics_per_page'];
break;
case 'filesize':
$order_by = 'ORDER BY total_size ' . $sort_order . ' LIMIT ' . $start . ', ' . $board_config['topics_per_page'];
break;
default:
$mode = 'attachments';
$sort_order = 'DESC';
$order_by = 'ORDER BY total_attachments ' . $sort_order . ' LIMIT ' . $start . ', ' . $board_config['topics_per_page'];
break;
}
}
else if ($view == 'attachments')
{
switch($mode)
{
case 'filename':
$order_by = 'ORDER BY a.real_filename ' . $sort_order . ' LIMIT ' . $start . ', ' . $board_config['topics_per_page'];
break;
case 'comment':
$order_by = 'ORDER BY a.comment ' . $sort_order . ' LIMIT ' . $start . ', ' . $board_config['topics_per_page'];
break;
case 'extension':
$order_by = 'ORDER BY a.extension ' . $sort_order . ' LIMIT ' . $start . ', ' . $board_config['topics_per_page'];
break;
case 'filesize':
$order_by = 'ORDER BY a.filesize ' . $sort_order . ' LIMIT ' . $start . ', ' . $board_config['topics_per_page'];
break;
case 'downloads':
$order_by = 'ORDER BY a.download_count ' . $sort_order . ' LIMIT ' . $start . ', ' . $board_config['topics_per_page'];
break;
case 'post_time':
$order_by = 'ORDER BY a.filetime ' . $sort_order . ' LIMIT ' . $start . ', ' . $board_config['topics_per_page'];
break;
default:
$mode = 'a.real_filename';
$sort_order = 'ASC';
$order_by = 'ORDER BY a.real_filename ' . $sort_order . ' LIMIT ' . $start . ', ' . $board_config['topics_per_page'];
break;
}
}
//
// Set select fields
//
$view_types_text = array($lang['View_Statistic'], $lang['View_Search'], $lang['View_Username'], $lang['View_Attachments']);
$view_types = array('stats', 'search', 'username', 'attachments');
$select_view = '<select name="view">';
for($i = 0; $i < count($view_types_text); $i++)
{
$selected = ($view == $view_types[$i]) ? ' selected="selected"' : '';
$select_view .= '<option value="' . $view_types[$i] . '"' . $selected . '>' . $view_types_text[$i] . '</option>';
}
$select_view .= '</select>';
if (count($mode_types_text) > 0)
{
$select_sort_mode = '<select name="mode">';
for($i = 0; $i < count($mode_types_text); $i++)
{
$selected = ($mode == $mode_types[$i]) ? ' selected="selected"' : '';
$select_sort_mode .= '<option value="' . $mode_types[$i] . '"' . $selected . '>' . $mode_types_text[$i] . '</option>';
}
$select_sort_mode .= '</select>';
}
if (!empty($sort_order))
{
$select_sort_order = '<select name="order">';
if($sort_order == 'ASC')
{
$select_sort_order .= '<option value="ASC" selected="selected">' . $lang['Sort_Ascending'] . '</option><option value="DESC">' . $lang['Sort_Descending'] . '</option>';
}
else
{
$select_sort_order .= '<option value="ASC">' . $lang['Sort_Ascending'] . '</option><option value="DESC" selected="selected">' . $lang['Sort_Descending'] . '</option>';
}
$select_sort_order .= '</select>';
}
$submit_change = ( isset($HTTP_POST_VARS['submit_change']) ) ? TRUE : FALSE;
$delete = ( isset($HTTP_POST_VARS['delete']) ) ? TRUE : FALSE;
$delete_id_list = ( isset($HTTP_POST_VARS['delete_id_list']) ) ? $HTTP_POST_VARS['delete_id_list'] : array();
$confirm = ( $HTTP_POST_VARS['confirm'] ) ? TRUE : FALSE;
if ( ($confirm) && (count($delete_id_list) > 0) )
{
$attachments = array();
delete_attachment(-1, $delete_id_list);
}
else if ( ($delete) && (count($delete_id_list)) > 0 )
{
//
// Not confirmed, show confirmation message
//
$hidden_fields = '<input type="hidden" name="view" value="' . $view . '" />';
$hidden_fields .= '<input type="hidden" name="mode" value="' . $mode . '" />';
$hidden_fields .= '<input type="hidden" name="order" value="' . $sort_order . '" />';
$hidden_fields .= '<input type="hidden" name="u_id" value="' . $uid . '" />';
$hidden_fields .= '<input type="hidden" name="start" value="' . $start . '" />';
for($i = 0; $i < count($delete_id_list); $i++)
{
$hidden_fields .= '<input type="hidden" name="delete_id_list[]" value="' . $delete_id_list[$i] . '" />';
}
$template->set_filenames(array(
'confirm' => 'confirm_body.tpl')
);
$template->assign_vars(array(
'MESSAGE_TITLE' => $lang['Confirm'],
'MESSAGE_TEXT' => $lang['Confirm_delete_attachments'],
'L_YES' => $lang['Yes'],
'L_NO' => $lang['No'],
'S_CONFIRM_ACTION' => append_sid('admin_attach_cp.' . $phpEx),
'S_HIDDEN_FIELDS' => $hidden_fields)
);
$template->pparse('confirm');
include('page_footer_admin.'.$phpEx);
exit;
}
//
// Assign Default Template Vars
//
$template->assign_vars(array(
'L_VIEW' => $lang['View'],
'L_SUBMIT' => $lang['Submit'],
'L_CONTROL_PANEL_TITLE' => $lang['Control_panel_title'],
'L_CONTROL_PANEL_EXPLAIN' => $lang['Control_panel_explain'],
'S_VIEW_SELECT' => $select_view,
'S_MODE_ACTION' => append_sid('admin_attach_cp.' . $phpEx))
);
if ($submit_change && $view == 'attachments')
{
$attach_change_list = ( isset($HTTP_POST_VARS['attach_id_list']) ) ? $HTTP_POST_VARS['attach_id_list'] : array();
$attach_comment_list = ( isset($HTTP_POST_VARS['attach_comment_list']) ) ? $HTTP_POST_VARS['attach_comment_list'] : array();
$attach_download_count_list = ( isset($HTTP_POST_VARS['attach_count_list']) ) ? $HTTP_POST_VARS['attach_count_list'] : array();
//
// Generate correct Change List
//
$attachments = array();
for ($i = 0; $i < count($attach_change_list); $i++)
{
$attachments['_' . $attach_change_list[$i]]['comment'] = stripslashes(htmlspecialchars($attach_comment_list[$i]));
$attachments['_' . $attach_change_list[$i]]['download_count'] = intval($attach_download_count_list[$i]);
}
$sql = "SELECT *
FROM " . ATTACHMENTS_DESC_TABLE . "
ORDER BY attach_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Couldn\'t get Attachment informations', '', __LINE__, __FILE__, $sql);
}
while ( $attachrow = $db->sql_fetchrow($result) )
{
if ( isset($attachments['_' . $attachrow['attach_id']]) )
{
if ( ($attachrow['comment'] != $attachments['_' . $attachrow['attach_id']]['comment']) || (intval($attachrow['download_count']) != intval($attachments['_' . $attachrow['attach_id']]['download_count'])) )
{
$sql = "UPDATE " . ATTACHMENTS_DESC_TABLE . "
SET comment = '" . $attachments['_' . $attachrow['attach_id']]['comment'] . "', download_count = " . intval($attachments['_' . $attachrow['attach_id']]['download_count']) . "
WHERE attach_id = " . $attachrow['attach_id'];
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Couldn\'t update Attachments Informations', '', __LINE__, __FILE__, $sql);
}
}
}
}
}
//
// Statistics
//
if ($view == 'stats')
{
$template->set_filenames(array(
'body' => 'admin/attach_cp_body.tpl')
);
$upload_dir_size = get_formatted_dirsize();
if (intval($attach_config['attachment_quota']) >= 1048576)
{
$attachment_quota = round(intval($attach_config['attachment_quota']) / 1048576 * 100) / 100 . ' ' . $lang['MB'];
}
else if (intval($attach_config['attachment_quota']) >= 1024)
{
$attachment_quota = round(intval($attach_config['attachment_quota']) / 1024 * 100) / 100 . ' ' . $lang['KB'];
}
else
{
$attachment_quota = intval($attach_config['attachment_quota']) . ' ' . $lang['Bytes'];
}
$sql = "SELECT count(*) AS total
FROM " . ATTACHMENTS_DESC_TABLE;
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error getting total attachments', '', __LINE__, __FILE__, $sql);
}
$total = $db->sql_fetchrow($result);
$number_of_attachments = $total['total'];
$sql = "SELECT post_id
FROM " . ATTACHMENTS_TABLE . "
WHERE post_id <> 0
GROUP BY post_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error getting total posts', '', __LINE__, __FILE__, $sql);
}
$number_of_posts = $db->sql_numrows($result);
$sql = "SELECT privmsgs_id
FROM " . ATTACHMENTS_TABLE . "
WHERE privmsgs_id <> 0
GROUP BY privmsgs_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error getting total private messages', '', __LINE__, __FILE__, $sql);
}
$number_of_pms = $db->sql_numrows($result);
$sql = "SELECT p.topic_id
FROM " . ATTACHMENTS_TABLE . " a, " . POSTS_TABLE . " p
WHERE a.post_id = p.post_id
GROUP BY p.topic_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error getting total topics', '', __LINE__, __FILE__, $sql);
}
$number_of_topics = $db->sql_numrows($result);
$sql = "SELECT user_id_1
FROM " . ATTACHMENTS_TABLE . "
WHERE (post_id <> 0)
GROUP BY user_id_1";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error getting total users', '', __LINE__, __FILE__, $sql);
}
$number_of_users = $db->sql_numrows($result);
$template->assign_vars(array(
'L_STATISTIC' => $lang['Statistic'],
'L_VALUE' => $lang['Value'],
'L_NUMBER_OF_ATTACHMENTS' => $lang['Number_of_attachments'],
'L_TOTAL_FILESIZE' => $lang['Total_filesize'],
'L_ATTACH_QUOTA' => $lang['Attach_quota'],
'L_NUMBER_OF_POSTS' => $lang['Number_posts_attach'],
'L_NUMBER_OF_PMS' => $lang['Number_pms_attach'],
'L_NUMBER_OF_TOPICS' => $lang['Number_topics_attach'],
'L_NUMBER_OF_USERS' => $lang['Number_users_attach'],
'TOTAL_FILESIZE' => $upload_dir_size,
'ATTACH_QUOTA' => $attachment_quota,
'NUMBER_OF_ATTACHMENTS' => $number_of_attachments,
'NUMBER_OF_POSTS' => $number_of_posts,
'NUMBER_OF_PMS' => $number_of_pms,
'NUMBER_OF_TOPICS' => $number_of_topics,
'NUMBER_OF_USERS' => $number_of_users)
);
}
//
// Search
//
if ($view == 'search')
{
//
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?