5
* @version $Id: acp_main.php,v 1.52 2007/11/27 15:13:50 kellanved Exp $
6
* @copyright (c) 2005 phpBB Group
7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
14
if (!defined('IN_PHPBB'))
26
function main($id, $mode)
28
global $config, $db, $user, $auth, $template;
29
global $phpbb_root_path, $phpbb_admin_path, $phpEx;
31
// Show restore permissions notice
32
if ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm'))
34
$this->tpl_name = 'acp_main';
35
$this->page_title = 'ACP_MAIN';
37
$sql = 'SELECT user_id, username, user_colour
38
FROM ' . USERS_TABLE . '
39
WHERE user_id = ' . $user->data['user_perm_from'];
40
$result = $db->sql_query($sql);
41
$user_row = $db->sql_fetchrow($result);
42
$db->sql_freeresult($result);
44
$perm_from = '<strong' . (($user_row['user_colour']) ? ' style="color: #' . $user_row['user_colour'] . '">' : '>');
45
$perm_from .= ($user_row['user_id'] != ANONYMOUS) ? '<a href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u=' . $user_row['user_id']) . '">' : '';
46
$perm_from .= $user_row['username'];
47
$perm_from .= ($user_row['user_id'] != ANONYMOUS) ? '</a>' : '';
48
$perm_from .= '</strong>';
50
$template->assign_vars(array(
51
'S_RESTORE_PERMISSIONS' => true,
52
'U_RESTORE_PERMISSIONS' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=restore_perm'),
53
'PERM_FROM' => $perm_from,
54
'L_PERMISSIONS_TRANSFERRED_EXPLAIN' => sprintf($user->lang['PERMISSIONS_TRANSFERRED_EXPLAIN'], $perm_from, append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=restore_perm')),
60
$action = request_var('action', '');
64
if (!confirm_box(true))
70
$confirm_lang = 'RESET_ONLINE_CONFIRM';
74
$confirm_lang = 'RESYNC_STATS_CONFIRM';
78
$confirm_lang = 'RESYNC_POSTCOUNTS_CONFIRM';
82
$confirm_lang = 'RESET_DATE_CONFIRM';
86
$confirm_lang = 'RESYNC_POST_MARKING_CONFIRM';
90
$confirm_lang = 'PURGE_CACHE_CONFIRM';
95
$confirm_lang = 'CONFIRM_OPERATION';
100
confirm_box(false, $user->lang[$confirm_lang], build_hidden_fields(array(
112
if (!$auth->acl_get('a_board'))
114
trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
117
set_config('record_online_users', 1, true);
118
set_config('record_online_date', time(), true);
119
add_log('admin', 'LOG_RESET_ONLINE');
123
if (!$auth->acl_get('a_board'))
125
trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
128
$sql = 'SELECT COUNT(post_id) AS stat
129
FROM ' . POSTS_TABLE . '
130
WHERE post_approved = 1';
131
$result = $db->sql_query($sql);
132
set_config('num_posts', (int) $db->sql_fetchfield('stat'), true);
133
$db->sql_freeresult($result);
135
$sql = 'SELECT COUNT(topic_id) AS stat
136
FROM ' . TOPICS_TABLE . '
137
WHERE topic_approved = 1';
138
$result = $db->sql_query($sql);
139
set_config('num_topics', (int) $db->sql_fetchfield('stat'), true);
140
$db->sql_freeresult($result);
142
$sql = 'SELECT COUNT(user_id) AS stat
143
FROM ' . USERS_TABLE . '
144
WHERE user_type IN (' . USER_NORMAL . ',' . USER_FOUNDER . ')';
145
$result = $db->sql_query($sql);
146
set_config('num_users', (int) $db->sql_fetchfield('stat'), true);
147
$db->sql_freeresult($result);
149
$sql = 'SELECT COUNT(attach_id) as stat
150
FROM ' . ATTACHMENTS_TABLE . '
151
WHERE is_orphan = 0';
152
$result = $db->sql_query($sql);
153
set_config('num_files', (int) $db->sql_fetchfield('stat'), true);
154
$db->sql_freeresult($result);
156
$sql = 'SELECT SUM(filesize) as stat
157
FROM ' . ATTACHMENTS_TABLE . '
158
WHERE is_orphan = 0';
159
$result = $db->sql_query($sql);
160
set_config('upload_dir_size', (int) $db->sql_fetchfield('stat'), true);
161
$db->sql_freeresult($result);
163
if (!function_exists('update_last_username'))
165
include($phpbb_root_path . "includes/functions_user.$phpEx");
167
update_last_username();
169
add_log('admin', 'LOG_RESYNC_STATS');
173
if (!$auth->acl_get('a_board'))
175
trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
178
$sql = 'SELECT COUNT(p.post_id) AS num_posts, u.user_id
179
FROM ' . USERS_TABLE . ' u
180
LEFT JOIN ' . POSTS_TABLE . ' p ON (u.user_id = p.poster_id AND p.post_postcount = 1)
182
$result = $db->sql_query($sql);
184
while ($row = $db->sql_fetchrow($result))
186
$db->sql_query('UPDATE ' . USERS_TABLE . " SET user_posts = {$row['num_posts']} WHERE user_id = {$row['user_id']}");
188
$db->sql_freeresult($result);
190
add_log('admin', 'LOG_RESYNC_POSTCOUNTS');
195
if (!$auth->acl_get('a_board'))
197
trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
200
set_config('board_startdate', time() - 1);
201
add_log('admin', 'LOG_RESET_DATE');
205
switch ($db->sql_layer)
209
$db->sql_query('DELETE FROM ' . TOPICS_POSTED_TABLE);
213
$db->sql_query('TRUNCATE TABLE ' . TOPICS_POSTED_TABLE);
217
// This can get really nasty... therefore we only do the last six months
218
$get_from_time = time() - (6 * 4 * 7 * 24 * 60 * 60);
220
// Select forum ids, do not include categories
221
$sql = 'SELECT forum_id
222
FROM ' . FORUMS_TABLE . '
223
WHERE forum_type <> ' . FORUM_CAT;
224
$result = $db->sql_query($sql);
226
$forum_ids = array();
227
while ($row = $db->sql_fetchrow($result))
229
$forum_ids[] = $row['forum_id'];
231
$db->sql_freeresult($result);
233
// Any global announcements? ;)
236
// Now go through the forums and get us some topics...
237
foreach ($forum_ids as $forum_id)
239
$sql = 'SELECT p.poster_id, p.topic_id
240
FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
241
WHERE t.forum_id = ' . $forum_id . '
242
AND t.topic_moved_id = 0
243
AND t.topic_last_post_time > ' . $get_from_time . '
244
AND t.topic_id = p.topic_id
245
AND p.poster_id <> ' . ANONYMOUS . '
246
GROUP BY p.poster_id, p.topic_id';
247
$result = $db->sql_query($sql);
250
while ($row = $db->sql_fetchrow($result))
252
$posted[$row['poster_id']][] = $row['topic_id'];
254
$db->sql_freeresult($result);
257
foreach ($posted as $user_id => $topic_row)
259
foreach ($topic_row as $topic_id)
262
'user_id' => (int) $user_id,
263
'topic_id' => (int) $topic_id,
270
if (sizeof($sql_ary))
272
$db->sql_multi_insert(TOPICS_POSTED_TABLE, $sql_ary);
276
add_log('admin', 'LOG_RESYNC_POST_MARKING');
280
if ((int) $user->data['user_type'] !== USER_FOUNDER)
282
trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
289
$auth->acl_clear_prefetch();
292
add_log('admin', 'LOG_PURGE_CACHE');
298
// Get forum statistics
299
$total_posts = $config['num_posts'];
300
$total_topics = $config['num_topics'];
301
$total_users = $config['num_users'];
302
$total_files = $config['num_files'];
304
$start_date = $user->format_date($config['board_startdate']);
306
$boarddays = (time() - $config['board_startdate']) / 86400;
308
$posts_per_day = sprintf('%.2f', $total_posts / $boarddays);
309
$topics_per_day = sprintf('%.2f', $total_topics / $boarddays);
310
$users_per_day = sprintf('%.2f', $total_users / $boarddays);
311
$files_per_day = sprintf('%.2f', $total_files / $boarddays);
313
$upload_dir_size = ($config['upload_dir_size'] >= 1048576) ? sprintf('%.2f ' . $user->lang['MB'], ($config['upload_dir_size'] / 1048576)) : (($config['upload_dir_size'] >= 1024) ? sprintf('%.2f ' . $user->lang['KB'], ($config['upload_dir_size'] / 1024)) : sprintf('%.2f ' . $user->lang['BYTES'], $config['upload_dir_size']));
315
$avatar_dir_size = 0;
317
if ($avatar_dir = @opendir($phpbb_root_path . $config['avatar_path']))
319
while (($file = readdir($avatar_dir)) !== false)
321
if ($file[0] != '.' && $file != 'CVS' && strpos($file, 'index.') === false)
323
$avatar_dir_size += filesize($phpbb_root_path . $config['avatar_path'] . '/' . $file);
326
closedir($avatar_dir);
328
// This bit of code translates the avatar directory size into human readable format
329
// Borrowed the code from the PHP.net annoted manual, origanally written by:
330
// Jesse (jesse@jess.on.ca)
331
$avatar_dir_size = ($avatar_dir_size >= 1048576) ? sprintf('%.2f ' . $user->lang['MB'], ($avatar_dir_size / 1048576)) : (($avatar_dir_size >= 1024) ? sprintf('%.2f ' . $user->lang['KB'], ($avatar_dir_size / 1024)) : sprintf('%.2f ' . $user->lang['BYTES'], $avatar_dir_size));
335
// Couldn't open Avatar dir.
336
$avatar_dir_size = $user->lang['NOT_AVAILABLE'];
339
if ($posts_per_day > $total_posts)
341
$posts_per_day = $total_posts;
344
if ($topics_per_day > $total_topics)
346
$topics_per_day = $total_topics;
349
if ($users_per_day > $total_users)
351
$users_per_day = $total_users;
354
if ($files_per_day > $total_files)
356
$files_per_day = $total_files;
359
if ($config['allow_attachments'] || $config['allow_pm_attach'])
361
$sql = 'SELECT COUNT(attach_id) AS total_orphan
362
FROM ' . ATTACHMENTS_TABLE . '
364
AND filetime < ' . (time() - 3*60*60);
365
$result = $db->sql_query($sql);
366
$total_orphan = (int) $db->sql_fetchfield('total_orphan');
367
$db->sql_freeresult($result);
371
$total_orphan = false;
374
$dbsize = get_database_size();
376
$template->assign_vars(array(
377
'TOTAL_POSTS' => $total_posts,
378
'POSTS_PER_DAY' => $posts_per_day,
379
'TOTAL_TOPICS' => $total_topics,
380
'TOPICS_PER_DAY' => $topics_per_day,
381
'TOTAL_USERS' => $total_users,
382
'USERS_PER_DAY' => $users_per_day,
383
'TOTAL_FILES' => $total_files,
384
'FILES_PER_DAY' => $files_per_day,
385
'START_DATE' => $start_date,
386
'AVATAR_DIR_SIZE' => $avatar_dir_size,
388
'UPLOAD_DIR_SIZE' => $upload_dir_size,
389
'TOTAL_ORPHAN' => $total_orphan,
390
'S_TOTAL_ORPHAN' => ($total_orphan === false) ? false : true,
391
'GZIP_COMPRESSION' => ($config['gzip_compress']) ? $user->lang['ON'] : $user->lang['OFF'],
392
'DATABASE_INFO' => $db->sql_server_info(),
393
'BOARD_VERSION' => $config['version'],
395
'U_ACTION' => append_sid("{$phpbb_admin_path}index.$phpEx"),
396
'U_ADMIN_LOG' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=logs&mode=admin'),
397
'U_INACTIVE_USERS' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=inactive&mode=list'),
399
'S_ACTION_OPTIONS' => ($auth->acl_get('a_board')) ? true : false,
400
'S_FOUNDER' => ($user->data['user_type'] == USER_FOUNDER) ? true : false,
407
if ($auth->acl_get('a_viewlogs'))
409
view_log('admin', $log_data, $log_count, 5);
411
foreach ($log_data as $row)
413
$template->assign_block_vars('log', array(
414
'USERNAME' => $row['username_full'],
416
'DATE' => $user->format_date($row['time']),
417
'ACTION' => $row['action'])
422
if ($auth->acl_get('a_user'))
427
view_inactive_users($inactive, $inactive_count, 10);
429
foreach ($inactive as $row)
431
$template->assign_block_vars('inactive', array(
432
'INACTIVE_DATE' => $user->format_date($row['user_inactive_time']),
433
'JOINED' => $user->format_date($row['user_regdate']),
434
'LAST_VISIT' => (!$row['user_lastvisit']) ? ' - ' : $user->format_date($row['user_lastvisit']),
435
'REASON' => $row['inactive_reason'],
436
'USER_ID' => $row['user_id'],
437
'USERNAME' => $row['username'],
438
'U_USER_ADMIN' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&mode=overview&u={$row['user_id']}"))
442
$option_ary = array('activate' => 'ACTIVATE', 'delete' => 'DELETE');
443
if ($config['email_enable'])
445
$option_ary += array('remind' => 'REMIND');
448
$template->assign_vars(array(
449
'S_INACTIVE_USERS' => true,
450
'S_INACTIVE_OPTIONS' => build_select($option_ary))
454
// Warn if install is still present
455
if (file_exists($phpbb_root_path . 'install'))
457
$template->assign_var('S_REMOVE_INSTALL', true);
460
$this->tpl_name = 'acp_main';
461
$this->page_title = 'ACP_MAIN';
b'\\ No newline at end of file'