add warning to ACP index if config file is writeable
[phpbb.git] / phpBB / includes / acp / acp_main.php
blobe5d7fc77c0c71eb06f89d86d72947e5bd285bbb5
1 <?php
2 /**
4 * @package acp
5 * @version $Id$
6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 */
11 /**
12 * @ignore
14 if (!defined('IN_PHPBB'))
16 exit;
19 /**
20 * @package acp
22 class acp_main
24 var $u_action;
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&amp;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')),
54 ));
56 return;
59 $action = request_var('action', '');
61 if ($action)
63 if ($action === 'admlogout')
65 $user->unset_admin();
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))
73 switch ($action)
75 case 'online':
76 $confirm = true;
77 $confirm_lang = 'RESET_ONLINE_CONFIRM';
78 break;
79 case 'stats':
80 $confirm = true;
81 $confirm_lang = 'RESYNC_STATS_CONFIRM';
82 break;
83 case 'user':
84 $confirm = true;
85 $confirm_lang = 'RESYNC_POSTCOUNTS_CONFIRM';
86 break;
87 case 'date':
88 $confirm = true;
89 $confirm_lang = 'RESET_DATE_CONFIRM';
90 break;
91 case 'db_track':
92 $confirm = true;
93 $confirm_lang = 'RESYNC_POST_MARKING_CONFIRM';
94 break;
95 case 'purge_cache':
96 $confirm = true;
97 $confirm_lang = 'PURGE_CACHE_CONFIRM';
98 break;
100 default:
101 $confirm = true;
102 $confirm_lang = 'CONFIRM_OPERATION';
105 if ($confirm)
107 confirm_box(false, $user->lang[$confirm_lang], build_hidden_fields(array(
108 'i' => $id,
109 'mode' => $mode,
110 'action' => $action,
111 )));
114 else
116 switch ($action)
119 case 'online':
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');
128 break;
130 case 'stats':
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');
178 break;
180 case 'user':
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)
189 GROUP BY u.user_id';
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');
200 break;
202 case 'date':
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');
210 break;
212 case 'db_track':
213 if ($db->truncate)
215 $db->sql_query('TRUNCATE TABLE ' . TOPICS_POSTED_TABLE);
217 else
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? ;)
239 $forum_ids[] = 0;
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);
254 $posted = array();
255 while ($row = $db->sql_fetchrow($result))
257 $posted[$row['poster_id']][] = $row['topic_id'];
259 $db->sql_freeresult($result);
261 $sql_ary = array();
262 foreach ($posted as $user_id => $topic_row)
264 foreach ($topic_row as $topic_id)
266 $sql_ary[] = array(
267 'user_id' => (int) $user_id,
268 'topic_id' => (int) $topic_id,
269 'topic_posted' => 1,
273 unset($posted);
275 if (sizeof($sql_ary))
277 $db->sql_multi_insert(TOPICS_POSTED_TABLE, $sql_ary);
281 add_log('admin', 'LOG_RESYNC_POST_MARKING');
282 break;
284 case 'purge_cache':
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);
290 global $cache;
291 $cache->purge();
293 // Clear permissions
294 $auth->acl_clear_prefetch();
295 cache_moderators();
297 add_log('admin', 'LOG_PURGE_CACHE');
298 break;
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);
335 else
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 . '
365 WHERE is_orphan = 1
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);
371 else
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,
389 'DBSIZE' => $dbsize,
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&amp;mode=admin'),
399 'U_INACTIVE_USERS' => append_sid(PHPBB_ADMIN_PATH . 'index.' . PHP_EXT, 'i=inactive&amp;mode=list'),
401 'S_ACTION_OPTIONS' => ($auth->acl_get('a_board')) ? true : false,
402 'S_FOUNDER' => ($user->data['user_type'] == USER_FOUNDER) ? true : false,
406 $log_data = array();
407 $log_count = 0;
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'],
417 'IP' => $row['ip'],
418 'DATE' => $user->format_date($row['time']),
419 'ACTION' => $row['action'])
424 if ($auth->acl_get('a_user'))
426 $inactive = array();
427 $inactive_count = 0;
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&amp;mode=overview&amp;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';