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', (int) $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 $sql = 'SELECT COUNT(p.post_id) AS num_posts, u.user_id
187 FROM ' . USERS_TABLE
. ' u
188 LEFT JOIN ' . POSTS_TABLE
. ' p ON (u.user_id = p.poster_id AND p.post_postcount = 1)
190 $result = $db->sql_query($sql);
192 while ($row = $db->sql_fetchrow($result))
194 $db->sql_query('UPDATE ' . USERS_TABLE
. " SET user_posts = {$row['num_posts']} WHERE user_id = {$row['user_id']}");
196 $db->sql_freeresult($result);
198 add_log('admin', 'LOG_RESYNC_POSTCOUNTS');
203 if (!$auth->acl_get('a_board'))
205 trigger_error($user->lang
['NO_AUTH_OPERATION'] . adm_back_link($this->u_action
), E_USER_WARNING
);
208 set_config('board_startdate', time() - 1);
209 add_log('admin', 'LOG_RESET_DATE');
215 $db->sql_query('TRUNCATE TABLE ' . TOPICS_POSTED_TABLE
);
219 $db->sql_query('DELETE FROM ' . TOPICS_POSTED_TABLE
);
222 // This can get really nasty... therefore we only do the last six months
223 $get_from_time = time() - (6 * 4 * 7 * 24 * 60 * 60);
225 // Select forum ids, do not include categories
226 $sql = 'SELECT forum_id
227 FROM ' . FORUMS_TABLE
. '
228 WHERE forum_type <> ' . FORUM_CAT
;
229 $result = $db->sql_query($sql);
231 $forum_ids = array();
232 while ($row = $db->sql_fetchrow($result))
234 $forum_ids[] = $row['forum_id'];
236 $db->sql_freeresult($result);
238 // Any global announcements? ;)
241 // Now go through the forums and get us some topics...
242 foreach ($forum_ids as $forum_id)
244 $sql = 'SELECT p.poster_id, p.topic_id
245 FROM ' . POSTS_TABLE
. ' p, ' . TOPICS_TABLE
. ' t
246 WHERE t.forum_id = ' . $forum_id . '
247 AND t.topic_moved_id = 0
248 AND t.topic_last_post_time > ' . $get_from_time . '
249 AND t.topic_id = p.topic_id
250 AND p.poster_id <> ' . ANONYMOUS
. '
251 GROUP BY p.poster_id, p.topic_id';
252 $result = $db->sql_query($sql);
255 while ($row = $db->sql_fetchrow($result))
257 $posted[$row['poster_id']][] = $row['topic_id'];
259 $db->sql_freeresult($result);
262 foreach ($posted as $user_id => $topic_row)
264 foreach ($topic_row as $topic_id)
267 'user_id' => (int) $user_id,
268 'topic_id' => (int) $topic_id,
275 if (sizeof($sql_ary))
277 $db->sql_multi_insert(TOPICS_POSTED_TABLE
, $sql_ary);
281 add_log('admin', 'LOG_RESYNC_POST_MARKING');
285 if ((int) $user->data
['user_type'] !== USER_FOUNDER
)
287 trigger_error($user->lang
['NO_AUTH_OPERATION'] . adm_back_link($this->u_action
), E_USER_WARNING
);
294 $auth->acl_clear_prefetch();
297 add_log('admin', 'LOG_PURGE_CACHE');
303 // Get forum statistics
304 $total_posts = $config['num_posts'];
305 $total_topics = $config['num_topics'];
306 $total_users = $config['num_users'];
307 $total_files = $config['num_files'];
309 $start_date = $user->format_date($config['board_startdate']);
311 $boarddays = (time() - $config['board_startdate']) / 86400;
313 $posts_per_day = sprintf('%.2f', $total_posts / $boarddays);
314 $topics_per_day = sprintf('%.2f', $total_topics / $boarddays);
315 $users_per_day = sprintf('%.2f', $total_users / $boarddays);
316 $files_per_day = sprintf('%.2f', $total_files / $boarddays);
318 $upload_dir_size = get_formatted_filesize($config['upload_dir_size']);
320 $avatar_dir_size = 0;
322 if ($avatar_dir = @opendir
(PHPBB_ROOT_PATH
. $config['avatar_path']))
324 while (($file = readdir($avatar_dir)) !== false)
326 if ($file[0] != '.' && $file != 'CVS' && strpos($file, 'index.') === false)
328 $avatar_dir_size +
= filesize(PHPBB_ROOT_PATH
. $config['avatar_path'] . '/' . $file);
331 closedir($avatar_dir);
333 $avatar_dir_size = get_formatted_filesize($avatar_dir_size);
337 // Couldn't open Avatar dir.
338 $avatar_dir_size = $user->lang
['NOT_AVAILABLE'];
341 if ($posts_per_day > $total_posts)
343 $posts_per_day = $total_posts;
346 if ($topics_per_day > $total_topics)
348 $topics_per_day = $total_topics;
351 if ($users_per_day > $total_users)
353 $users_per_day = $total_users;
356 if ($files_per_day > $total_files)
358 $files_per_day = $total_files;
361 if ($config['allow_attachments'] ||
$config['allow_pm_attach'])
363 $sql = 'SELECT COUNT(attach_id) AS total_orphan
364 FROM ' . ATTACHMENTS_TABLE
. '
366 AND filetime < ' . (time() - 3*60*60);
367 $result = $db->sql_query($sql);
368 $total_orphan = (int) $db->sql_fetchfield('total_orphan');
369 $db->sql_freeresult($result);
373 $total_orphan = false;
376 $dbsize = get_database_size();
378 $template->assign_vars(array(
379 'TOTAL_POSTS' => $total_posts,
380 'POSTS_PER_DAY' => $posts_per_day,
381 'TOTAL_TOPICS' => $total_topics,
382 'TOPICS_PER_DAY' => $topics_per_day,
383 'TOTAL_USERS' => $total_users,
384 'USERS_PER_DAY' => $users_per_day,
385 'TOTAL_FILES' => $total_files,
386 'FILES_PER_DAY' => $files_per_day,
387 'START_DATE' => $start_date,
388 'AVATAR_DIR_SIZE' => $avatar_dir_size,
390 'UPLOAD_DIR_SIZE' => $upload_dir_size,
391 'TOTAL_ORPHAN' => $total_orphan,
392 'S_TOTAL_ORPHAN' => ($total_orphan === false) ?
false : true,
393 'GZIP_COMPRESSION' => ($config['gzip_compress']) ?
$user->lang
['ON'] : $user->lang
['OFF'],
394 'DATABASE_INFO' => $db->sql_server_info(),
395 'BOARD_VERSION' => $config['version'],
397 'U_ACTION' => $this->u_action
,
398 'U_ADMIN_LOG' => append_sid(PHPBB_ADMIN_PATH
. 'index.' . PHP_EXT
, 'i=logs&mode=admin'),
399 'U_INACTIVE_USERS' => append_sid(PHPBB_ADMIN_PATH
. 'index.' . PHP_EXT
, 'i=inactive&mode=list'),
401 'S_ACTION_OPTIONS' => ($auth->acl_get('a_board')) ?
true : false,
402 'S_FOUNDER' => ($user->data
['user_type'] == USER_FOUNDER
) ?
true : false,
409 if ($auth->acl_get('a_viewlogs'))
411 view_log('admin', $log_data, $log_count, 5);
413 foreach ($log_data as $row)
415 $template->assign_block_vars('log', array(
416 'USERNAME' => $row['username_full'],
418 'DATE' => $user->format_date($row['time']),
419 'ACTION' => $row['action'])
424 if ($auth->acl_get('a_user'))
429 view_inactive_users($inactive, $inactive_count, 10);
431 foreach ($inactive as $row)
433 $template->assign_block_vars('inactive', array(
434 'INACTIVE_DATE' => $user->format_date($row['user_inactive_time']),
435 'JOINED' => $user->format_date($row['user_regdate']),
436 'LAST_VISIT' => (!$row['user_lastvisit']) ?
' - ' : $user->format_date($row['user_lastvisit']),
437 'REASON' => $row['inactive_reason'],
438 'USER_ID' => $row['user_id'],
439 'USERNAME' => $row['username'],
440 'U_USER_ADMIN' => append_sid(PHPBB_ADMIN_PATH
. 'index.' . PHP_EXT
, "i=users&mode=overview&u={$row['user_id']}"))
444 $option_ary = array('activate' => 'ACTIVATE', 'delete' => 'DELETE');
445 if ($config['email_enable'])
447 $option_ary +
= array('remind' => 'REMIND');
450 $template->assign_vars(array(
451 'S_INACTIVE_USERS' => true,
452 'S_INACTIVE_OPTIONS' => build_select($option_ary))
456 // Warn if install is still present
457 if (file_exists(PHPBB_ROOT_PATH
. 'install'))
459 $template->assign_var('S_REMOVE_INSTALL', true);
462 if (file_exists(PHPBB_ROOT_PATH
. 'config.' . PHP_EXT
) && is_writeable(PHPBB_ROOT_PATH
. 'config.' . PHP_EXT
))
464 $template->assign_var('S_WRITEABLE_CONFIG', true);
467 $this->tpl_name
= 'acp_main';
468 $this->page_title
= 'ACP_MAIN';