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;
30 // Show restore permissions notice
31 if ($user->data
['user_perm_from'] && $auth->acl_get('a_switchperm'))
33 $this->tpl_name
= 'acp_main';
34 $this->page_title
= 'ACP_MAIN';
36 $sql = 'SELECT user_id, username, user_colour
37 FROM ' . USERS_TABLE
. '
38 WHERE user_id = ' . $user->data
['user_perm_from'];
39 $result = $db->sql_query($sql);
40 $user_row = $db->sql_fetchrow($result);
41 $db->sql_freeresult($result);
43 $perm_from = '<strong' . (($user_row['user_colour']) ?
' style="color: #' . $user_row['user_colour'] . '">' : '>');
44 $perm_from .= ($user_row['user_id'] != ANONYMOUS
) ?
'<a href="' . append_sid('memberlist', 'mode=viewprofile&u=' . $user_row['user_id']) . '">' : '';
45 $perm_from .= $user_row['username'];
46 $perm_from .= ($user_row['user_id'] != ANONYMOUS
) ?
'</a>' : '';
47 $perm_from .= '</strong>';
49 $template->assign_vars(array(
50 'S_RESTORE_PERMISSIONS' => true,
51 'U_RESTORE_PERMISSIONS' => append_sid('ucp', 'mode=restore_perm'),
52 'PERM_FROM' => $perm_from,
53 'L_PERMISSIONS_TRANSFERRED_EXPLAIN' => sprintf($user->lang
['PERMISSIONS_TRANSFERRED_EXPLAIN'], $perm_from, append_sid('ucp', 'mode=restore_perm')),
59 $action = request_var('action', '');
63 if ($action === 'admlogout')
66 $redirect_url = append_sid(PHPBB_ROOT_PATH
. 'index.' . PHP_EXT
);
67 meta_refresh(3, $redirect_url);
68 trigger_error($user->lang
['ADM_LOGGED_OUT'] . '<br /><br />' . sprintf($user->lang
['RETURN_INDEX'], '<a href="' . $redirect_url . '">', '</a>'));
71 if (!confirm_box(true))
77 $confirm_lang = 'RESET_ONLINE_CONFIRM';
81 $confirm_lang = 'RESYNC_STATS_CONFIRM';
85 $confirm_lang = 'RESYNC_POSTCOUNTS_CONFIRM';
89 $confirm_lang = 'RESET_DATE_CONFIRM';
93 $confirm_lang = 'RESYNC_POST_MARKING_CONFIRM';
97 $confirm_lang = 'PURGE_CACHE_CONFIRM';
102 $confirm_lang = 'CONFIRM_OPERATION';
107 confirm_box(false, $user->lang
[$confirm_lang], build_hidden_fields(array(
120 if (!$auth->acl_get('a_board'))
122 trigger_error($user->lang
['NO_AUTH_OPERATION'] . adm_back_link($this->u_action
), E_USER_WARNING
);
125 set_config('record_online_users', 1, true);
126 set_config('record_online_date', time(), true);
127 add_log('admin', 'LOG_RESET_ONLINE');
131 if (!$auth->acl_get('a_board'))
133 trigger_error($user->lang
['NO_AUTH_OPERATION'] . adm_back_link($this->u_action
), E_USER_WARNING
);
136 $sql = 'SELECT COUNT(post_id) AS stat
137 FROM ' . POSTS_TABLE
. '
138 WHERE post_approved = 1';
139 $result = $db->sql_query($sql);
140 set_config('num_posts', (int) $db->sql_fetchfield('stat'), true);
141 $db->sql_freeresult($result);
143 $sql = 'SELECT COUNT(topic_id) AS stat
144 FROM ' . TOPICS_TABLE
. '
145 WHERE topic_approved = 1';
146 $result = $db->sql_query($sql);
147 set_config('num_topics', (int) $db->sql_fetchfield('stat'), true);
148 $db->sql_freeresult($result);
150 $sql = 'SELECT COUNT(user_id) AS stat
151 FROM ' . USERS_TABLE
. '
152 WHERE user_type IN (' . USER_NORMAL
. ',' . USER_FOUNDER
. ')';
153 $result = $db->sql_query($sql);
154 set_config('num_users', (int) $db->sql_fetchfield('stat'), true);
155 $db->sql_freeresult($result);
157 $sql = 'SELECT COUNT(attach_id) as stat
158 FROM ' . ATTACHMENTS_TABLE
. '
159 WHERE is_orphan = 0';
160 $result = $db->sql_query($sql);
161 set_config('num_files', (int) $db->sql_fetchfield('stat'), true);
162 $db->sql_freeresult($result);
164 $sql = 'SELECT SUM(filesize) as stat
165 FROM ' . ATTACHMENTS_TABLE
. '
166 WHERE is_orphan = 0';
167 $result = $db->sql_query($sql);
168 set_config('upload_dir_size', (float) $db->sql_fetchfield('stat'), true);
169 $db->sql_freeresult($result);
171 if (!function_exists('update_last_username'))
173 include(PHPBB_ROOT_PATH
. 'includes/functions_user.' . PHP_EXT
);
175 update_last_username();
177 add_log('admin', 'LOG_RESYNC_STATS');
181 if (!$auth->acl_get('a_board'))
183 trigger_error($user->lang
['NO_AUTH_OPERATION'] . adm_back_link($this->u_action
), E_USER_WARNING
);
186 // Resync post counts
188 $step = ($config['num_posts']) ?
(max((int) ($config['num_posts'] / 5), 20000)) : 20000;
190 $db->sql_query('UPDATE ' . USERS_TABLE
. ' SET user_posts = 0');
194 $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
195 FROM ' . POSTS_TABLE
. '
196 WHERE post_id BETWEEN ' . ($start +
1) . ' AND ' . ($start +
$step) . '
197 AND post_postcount = 1 AND post_approved = 1
199 $result = $db->sql_query($sql);
201 if ($row = $db->sql_fetchrow($result))
205 $sql = 'UPDATE ' . USERS_TABLE
. " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}";
206 $db->sql_query($sql);
208 while ($row = $db->sql_fetchrow($result));
216 $db->sql_freeresult($result);
220 add_log('admin', 'LOG_RESYNC_POSTCOUNTS');
225 if (!$auth->acl_get('a_board'))
227 trigger_error($user->lang
['NO_AUTH_OPERATION'] . adm_back_link($this->u_action
), E_USER_WARNING
);
230 set_config('board_startdate', time() - 1);
231 add_log('admin', 'LOG_RESET_DATE');
237 $db->sql_query('TRUNCATE TABLE ' . TOPICS_POSTED_TABLE
);
241 $db->sql_query('DELETE FROM ' . TOPICS_POSTED_TABLE
);
244 // This can get really nasty... therefore we only do the last six months
245 $get_from_time = time() - (6 * 4 * 7 * 24 * 60 * 60);
247 // Select forum ids, do not include categories
248 $sql = 'SELECT forum_id
249 FROM ' . FORUMS_TABLE
. '
250 WHERE forum_type <> ' . FORUM_CAT
;
251 $result = $db->sql_query($sql);
253 $forum_ids = array();
254 while ($row = $db->sql_fetchrow($result))
256 $forum_ids[] = $row['forum_id'];
258 $db->sql_freeresult($result);
260 // Any global announcements? ;)
263 // Now go through the forums and get us some topics...
264 foreach ($forum_ids as $forum_id)
266 $sql = 'SELECT p.poster_id, p.topic_id
267 FROM ' . POSTS_TABLE
. ' p, ' . TOPICS_TABLE
. ' t
268 WHERE t.forum_id = ' . $forum_id . '
269 AND t.topic_moved_id = 0
270 AND t.topic_last_post_time > ' . $get_from_time . '
271 AND t.topic_id = p.topic_id
272 AND p.poster_id <> ' . ANONYMOUS
. '
273 GROUP BY p.poster_id, p.topic_id';
274 $result = $db->sql_query($sql);
277 while ($row = $db->sql_fetchrow($result))
279 $posted[$row['poster_id']][] = $row['topic_id'];
281 $db->sql_freeresult($result);
284 foreach ($posted as $user_id => $topic_row)
286 foreach ($topic_row as $topic_id)
289 'user_id' => (int) $user_id,
290 'topic_id' => (int) $topic_id,
297 if (sizeof($sql_ary))
299 $db->sql_multi_insert(TOPICS_POSTED_TABLE
, $sql_ary);
303 add_log('admin', 'LOG_RESYNC_POST_MARKING');
307 if ((int) $user->data
['user_type'] !== USER_FOUNDER
)
309 trigger_error($user->lang
['NO_AUTH_OPERATION'] . adm_back_link($this->u_action
), E_USER_WARNING
);
316 $auth->acl_clear_prefetch();
319 add_log('admin', 'LOG_PURGE_CACHE');
325 // Get forum statistics
326 $total_posts = $config['num_posts'];
327 $total_topics = $config['num_topics'];
328 $total_users = $config['num_users'];
329 $total_files = $config['num_files'];
331 $start_date = $user->format_date($config['board_startdate']);
333 $boarddays = (time() - $config['board_startdate']) / 86400;
335 $posts_per_day = sprintf('%.2f', $total_posts / $boarddays);
336 $topics_per_day = sprintf('%.2f', $total_topics / $boarddays);
337 $users_per_day = sprintf('%.2f', $total_users / $boarddays);
338 $files_per_day = sprintf('%.2f', $total_files / $boarddays);
340 $upload_dir_size = get_formatted_filesize($config['upload_dir_size']);
342 $avatar_dir_size = 0;
344 if ($avatar_dir = @opendir
(PHPBB_ROOT_PATH
. $config['avatar_path']))
346 while (($file = readdir($avatar_dir)) !== false)
348 if ($file[0] != '.' && $file != 'CVS' && strpos($file, 'index.') === false)
350 $avatar_dir_size +
= filesize(PHPBB_ROOT_PATH
. $config['avatar_path'] . '/' . $file);
353 closedir($avatar_dir);
355 $avatar_dir_size = get_formatted_filesize($avatar_dir_size);
359 // Couldn't open Avatar dir.
360 $avatar_dir_size = $user->lang
['NOT_AVAILABLE'];
363 if ($posts_per_day > $total_posts)
365 $posts_per_day = $total_posts;
368 if ($topics_per_day > $total_topics)
370 $topics_per_day = $total_topics;
373 if ($users_per_day > $total_users)
375 $users_per_day = $total_users;
378 if ($files_per_day > $total_files)
380 $files_per_day = $total_files;
383 if ($config['allow_attachments'] ||
$config['allow_pm_attach'])
385 $sql = 'SELECT COUNT(attach_id) AS total_orphan
386 FROM ' . ATTACHMENTS_TABLE
. '
388 AND filetime < ' . (time() - 3*60*60);
389 $result = $db->sql_query($sql);
390 $total_orphan = (int) $db->sql_fetchfield('total_orphan');
391 $db->sql_freeresult($result);
395 $total_orphan = false;
398 $dbsize = get_database_size();
400 $template->assign_vars(array(
401 'TOTAL_POSTS' => $total_posts,
402 'POSTS_PER_DAY' => $posts_per_day,
403 'TOTAL_TOPICS' => $total_topics,
404 'TOPICS_PER_DAY' => $topics_per_day,
405 'TOTAL_USERS' => $total_users,
406 'USERS_PER_DAY' => $users_per_day,
407 'TOTAL_FILES' => $total_files,
408 'FILES_PER_DAY' => $files_per_day,
409 'START_DATE' => $start_date,
410 'AVATAR_DIR_SIZE' => $avatar_dir_size,
412 'UPLOAD_DIR_SIZE' => $upload_dir_size,
413 'TOTAL_ORPHAN' => $total_orphan,
414 'S_TOTAL_ORPHAN' => ($total_orphan === false) ?
false : true,
415 'GZIP_COMPRESSION' => ($config['gzip_compress']) ?
$user->lang
['ON'] : $user->lang
['OFF'],
416 'DATABASE_INFO' => $db->sql_server_info(),
417 'BOARD_VERSION' => $config['version'],
419 'U_ACTION' => $this->u_action
,
420 'U_ADMIN_LOG' => append_sid(PHPBB_ADMIN_PATH
. 'index.' . PHP_EXT
, 'i=logs&mode=admin'),
421 'U_INACTIVE_USERS' => append_sid(PHPBB_ADMIN_PATH
. 'index.' . PHP_EXT
, 'i=inactive&mode=list'),
423 'S_ACTION_OPTIONS' => ($auth->acl_get('a_board')) ?
true : false,
424 'S_FOUNDER' => ($user->data
['user_type'] == USER_FOUNDER
) ?
true : false,
431 if ($auth->acl_get('a_viewlogs'))
433 view_log('admin', $log_data, $log_count, 5);
435 foreach ($log_data as $row)
437 $template->assign_block_vars('log', array(
438 'USERNAME' => $row['username_full'],
440 'DATE' => $user->format_date($row['time']),
441 'ACTION' => $row['action'])
446 if ($auth->acl_get('a_user'))
451 view_inactive_users($inactive, $inactive_count, 10);
453 foreach ($inactive as $row)
455 $template->assign_block_vars('inactive', array(
456 'INACTIVE_DATE' => $user->format_date($row['user_inactive_time']),
457 'JOINED' => $user->format_date($row['user_regdate']),
458 'LAST_VISIT' => (!$row['user_lastvisit']) ?
' - ' : $user->format_date($row['user_lastvisit']),
459 'REASON' => $row['inactive_reason'],
460 'USER_ID' => $row['user_id'],
461 'USERNAME' => $row['username'],
462 'U_USER_ADMIN' => append_sid(PHPBB_ADMIN_PATH
. 'index.' . PHP_EXT
, "i=users&mode=overview&u={$row['user_id']}"))
466 $option_ary = array('activate' => 'ACTIVATE', 'delete' => 'DELETE');
467 if ($config['email_enable'])
469 $option_ary +
= array('remind' => 'REMIND');
472 $template->assign_vars(array(
473 'S_INACTIVE_USERS' => true,
474 'S_INACTIVE_OPTIONS' => build_select($option_ary))
478 // Warn if install is still present
479 if (file_exists(PHPBB_ROOT_PATH
. 'install'))
481 $template->assign_var('S_REMOVE_INSTALL', true);
484 if (!defined('PHPBB_DISABLE_CONFIG_CHECK') && file_exists(PHPBB_ROOT_PATH
. 'config.' . PHP_EXT
) && is_writable(PHPBB_ROOT_PATH
. 'config.' . PHP_EXT
))
486 // World-Writable? (000x)
487 $template->assign_var('S_WRITABLE_CONFIG', (bool) (@fileperms
(PHPBB_ROOT_PATH
. 'config.' . PHP_EXT
) & 0x0002));
490 $this->tpl_name
= 'acp_main';
491 $this->page_title
= 'ACP_MAIN';