source: trunk/forum/includes/acp/acp_main.php

Last change on this file was 702, checked in by george, 15 years ago
  • Upraveno: Aktualizace fóra.
File size: 18.4 KB
Line 
1<?php
2/**
3*
4* @package acp
5* @version $Id$
6* @copyright (c) 2005 phpBB Group
7* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8*
9*/
10
11/**
12* @ignore
13*/
14if (!defined('IN_PHPBB'))
15{
16 exit;
17}
18
19/**
20* @package acp
21*/
22class acp_main
23{
24 var $u_action;
25
26 function main($id, $mode)
27 {
28 global $config, $db, $user, $auth, $template;
29 global $phpbb_root_path, $phpbb_admin_path, $phpEx;
30
31 // Show restore permissions notice
32 if ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm'))
33 {
34 $this->tpl_name = 'acp_main';
35 $this->page_title = 'ACP_MAIN';
36
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);
43
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&amp;u=' . $user_row['user_id']) . '">' : '';
46 $perm_from .= $user_row['username'];
47 $perm_from .= ($user_row['user_id'] != ANONYMOUS) ? '</a>' : '';
48 $perm_from .= '</strong>';
49
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')),
55 ));
56
57 return;
58 }
59
60 $action = request_var('action', '');
61
62 if ($action)
63 {
64 if ($action === 'admlogout')
65 {
66 $user->unset_admin();
67 $redirect_url = append_sid("{$phpbb_root_path}index.$phpEx");
68 meta_refresh(3, $redirect_url);
69 trigger_error($user->lang['ADM_LOGGED_OUT'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect_url . '">', '</a>'));
70 }
71
72 if (!confirm_box(true))
73 {
74 switch ($action)
75 {
76 case 'online':
77 $confirm = true;
78 $confirm_lang = 'RESET_ONLINE_CONFIRM';
79 break;
80 case 'stats':
81 $confirm = true;
82 $confirm_lang = 'RESYNC_STATS_CONFIRM';
83 break;
84 case 'user':
85 $confirm = true;
86 $confirm_lang = 'RESYNC_POSTCOUNTS_CONFIRM';
87 break;
88 case 'date':
89 $confirm = true;
90 $confirm_lang = 'RESET_DATE_CONFIRM';
91 break;
92 case 'db_track':
93 $confirm = true;
94 $confirm_lang = 'RESYNC_POST_MARKING_CONFIRM';
95 break;
96 case 'purge_cache':
97 $confirm = true;
98 $confirm_lang = 'PURGE_CACHE_CONFIRM';
99 break;
100 case 'purge_sessions':
101 $confirm = true;
102 $confirm_lang = 'PURGE_SESSIONS_CONFIRM';
103 break;
104
105 default:
106 $confirm = true;
107 $confirm_lang = 'CONFIRM_OPERATION';
108 }
109
110 if ($confirm)
111 {
112 confirm_box(false, $user->lang[$confirm_lang], build_hidden_fields(array(
113 'i' => $id,
114 'mode' => $mode,
115 'action' => $action,
116 )));
117 }
118 }
119 else
120 {
121 switch ($action)
122 {
123
124 case 'online':
125 if (!$auth->acl_get('a_board'))
126 {
127 trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
128 }
129
130 set_config('record_online_users', 1, true);
131 set_config('record_online_date', time(), true);
132 add_log('admin', 'LOG_RESET_ONLINE');
133 break;
134
135 case 'stats':
136 if (!$auth->acl_get('a_board'))
137 {
138 trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
139 }
140
141 $sql = 'SELECT COUNT(post_id) AS stat
142 FROM ' . POSTS_TABLE . '
143 WHERE post_approved = 1';
144 $result = $db->sql_query($sql);
145 set_config('num_posts', (int) $db->sql_fetchfield('stat'), true);
146 $db->sql_freeresult($result);
147
148 $sql = 'SELECT COUNT(topic_id) AS stat
149 FROM ' . TOPICS_TABLE . '
150 WHERE topic_approved = 1';
151 $result = $db->sql_query($sql);
152 set_config('num_topics', (int) $db->sql_fetchfield('stat'), true);
153 $db->sql_freeresult($result);
154
155 $sql = 'SELECT COUNT(user_id) AS stat
156 FROM ' . USERS_TABLE . '
157 WHERE user_type IN (' . USER_NORMAL . ',' . USER_FOUNDER . ')';
158 $result = $db->sql_query($sql);
159 set_config('num_users', (int) $db->sql_fetchfield('stat'), true);
160 $db->sql_freeresult($result);
161
162 $sql = 'SELECT COUNT(attach_id) as stat
163 FROM ' . ATTACHMENTS_TABLE . '
164 WHERE is_orphan = 0';
165 $result = $db->sql_query($sql);
166 set_config('num_files', (int) $db->sql_fetchfield('stat'), true);
167 $db->sql_freeresult($result);
168
169 $sql = 'SELECT SUM(filesize) as stat
170 FROM ' . ATTACHMENTS_TABLE . '
171 WHERE is_orphan = 0';
172 $result = $db->sql_query($sql);
173 set_config('upload_dir_size', (float) $db->sql_fetchfield('stat'), true);
174 $db->sql_freeresult($result);
175
176 if (!function_exists('update_last_username'))
177 {
178 include($phpbb_root_path . "includes/functions_user.$phpEx");
179 }
180 update_last_username();
181
182 add_log('admin', 'LOG_RESYNC_STATS');
183 break;
184
185 case 'user':
186 if (!$auth->acl_get('a_board'))
187 {
188 trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
189 }
190
191 // Resync post counts
192 $start = $max_post_id = 0;
193
194 // Find the maximum post ID, we can only stop the cycle when we've reached it
195 $sql = 'SELECT MAX(forum_last_post_id) as max_post_id
196 FROM ' . FORUMS_TABLE;
197 $result = $db->sql_query($sql);
198 $max_post_id = (int) $db->sql_fetchfield('max_post_id');
199 $db->sql_freeresult($result);
200
201 // No maximum post id? :o
202 if (!$max_post_id)
203 {
204 $sql = 'SELECT MAX(post_id)
205 FROM ' . POSTS_TABLE;
206 $result = $db->sql_query($sql);
207 $max_post_id = (int) $db->sql_fetchfield('max_post_id');
208 $db->sql_freeresult($result);
209 }
210
211 // Still no maximum post id? Then we are finished
212 if (!$max_post_id)
213 {
214 add_log('admin', 'LOG_RESYNC_POSTCOUNTS');
215 break;
216 }
217
218 $step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000;
219 $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_posts = 0');
220
221 while ($start < $max_post_id)
222 {
223 $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
224 FROM ' . POSTS_TABLE . '
225 WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . '
226 AND post_postcount = 1 AND post_approved = 1
227 GROUP BY poster_id';
228 $result = $db->sql_query($sql);
229
230 if ($row = $db->sql_fetchrow($result))
231 {
232 do
233 {
234 $sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}";
235 $db->sql_query($sql);
236 }
237 while ($row = $db->sql_fetchrow($result));
238 }
239 $db->sql_freeresult($result);
240
241 $start += $step;
242 }
243
244 add_log('admin', 'LOG_RESYNC_POSTCOUNTS');
245
246 break;
247
248 case 'date':
249 if (!$auth->acl_get('a_board'))
250 {
251 trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
252 }
253
254 set_config('board_startdate', time() - 1);
255 add_log('admin', 'LOG_RESET_DATE');
256 break;
257
258 case 'db_track':
259 switch ($db->sql_layer)
260 {
261 case 'sqlite':
262 case 'firebird':
263 $db->sql_query('DELETE FROM ' . TOPICS_POSTED_TABLE);
264 break;
265
266 default:
267 $db->sql_query('TRUNCATE TABLE ' . TOPICS_POSTED_TABLE);
268 break;
269 }
270
271 // This can get really nasty... therefore we only do the last six months
272 $get_from_time = time() - (6 * 4 * 7 * 24 * 60 * 60);
273
274 // Select forum ids, do not include categories
275 $sql = 'SELECT forum_id
276 FROM ' . FORUMS_TABLE . '
277 WHERE forum_type <> ' . FORUM_CAT;
278 $result = $db->sql_query($sql);
279
280 $forum_ids = array();
281 while ($row = $db->sql_fetchrow($result))
282 {
283 $forum_ids[] = $row['forum_id'];
284 }
285 $db->sql_freeresult($result);
286
287 // Any global announcements? ;)
288 $forum_ids[] = 0;
289
290 // Now go through the forums and get us some topics...
291 foreach ($forum_ids as $forum_id)
292 {
293 $sql = 'SELECT p.poster_id, p.topic_id
294 FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
295 WHERE t.forum_id = ' . $forum_id . '
296 AND t.topic_moved_id = 0
297 AND t.topic_last_post_time > ' . $get_from_time . '
298 AND t.topic_id = p.topic_id
299 AND p.poster_id <> ' . ANONYMOUS . '
300 GROUP BY p.poster_id, p.topic_id';
301 $result = $db->sql_query($sql);
302
303 $posted = array();
304 while ($row = $db->sql_fetchrow($result))
305 {
306 $posted[$row['poster_id']][] = $row['topic_id'];
307 }
308 $db->sql_freeresult($result);
309
310 $sql_ary = array();
311 foreach ($posted as $user_id => $topic_row)
312 {
313 foreach ($topic_row as $topic_id)
314 {
315 $sql_ary[] = array(
316 'user_id' => (int) $user_id,
317 'topic_id' => (int) $topic_id,
318 'topic_posted' => 1,
319 );
320 }
321 }
322 unset($posted);
323
324 if (sizeof($sql_ary))
325 {
326 $db->sql_multi_insert(TOPICS_POSTED_TABLE, $sql_ary);
327 }
328 }
329
330 add_log('admin', 'LOG_RESYNC_POST_MARKING');
331 break;
332
333 case 'purge_cache':
334 if ((int) $user->data['user_type'] !== USER_FOUNDER)
335 {
336 trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
337 }
338
339 global $cache;
340 $cache->purge();
341
342 // Clear permissions
343 $auth->acl_clear_prefetch();
344 cache_moderators();
345
346 add_log('admin', 'LOG_PURGE_CACHE');
347 break;
348
349 case 'purge_sessions':
350 if ((int) $user->data['user_type'] !== USER_FOUNDER)
351 {
352 trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
353 }
354
355 $tables = array(CONFIRM_TABLE, SESSIONS_TABLE);
356
357 foreach ($tables as $table)
358 {
359 switch ($db->sql_layer)
360 {
361 case 'sqlite':
362 case 'firebird':
363 $db->sql_query("DELETE FROM $table");
364 break;
365
366 default:
367 $db->sql_query("TRUNCATE TABLE $table");
368 break;
369 }
370 }
371
372 // let's restore the admin session
373 $reinsert_ary = array(
374 'session_id' => (string) $user->session_id,
375 'session_page' => (string) substr($user->page['page'], 0, 199),
376 'session_forum_id' => $user->page['forum'],
377 'session_user_id' => (int) $user->data['user_id'],
378 'session_start' => (int) $user->data['session_start'],
379 'session_last_visit' => (int) $user->data['session_last_visit'],
380 'session_time' => (int) $user->time_now,
381 'session_browser' => (string) trim(substr($user->browser, 0, 149)),
382 'session_forwarded_for' => (string) $user->forwarded_for,
383 'session_ip' => (string) $user->ip,
384 'session_autologin' => (int) $user->data['session_autologin'],
385 'session_admin' => 1,
386 'session_viewonline' => (int) $user->data['session_viewonline'],
387 );
388
389 $sql = 'INSERT INTO ' . SESSIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $reinsert_ary);
390 $db->sql_query($sql);
391
392 add_log('admin', 'LOG_PURGE_SESSIONS');
393 break;
394 }
395 }
396 }
397
398 // Version check
399 $user->add_lang('install');
400
401 if ($auth->acl_get('a_server') && version_compare(PHP_VERSION, '5.2.0', '<'))
402 {
403 $template->assign_vars(array(
404 'S_PHP_VERSION_OLD' => true,
405 'L_PHP_VERSION_OLD' => sprintf($user->lang['PHP_VERSION_OLD'], '<a href="http://www.phpbb.com/community/viewtopic.php?f=14&amp;t=1958605">', '</a>'),
406 ));
407 }
408
409 $latest_version_info = false;
410 if (($latest_version_info = obtain_latest_version_info(request_var('versioncheck_force', false))) === false)
411 {
412 $template->assign_var('S_VERSIONCHECK_FAIL', true);
413 }
414 else
415 {
416 $latest_version_info = explode("\n", $latest_version_info);
417
418 $latest_version = str_replace('rc', 'RC', strtolower(trim($latest_version_info[0])));
419 $current_version = str_replace('rc', 'RC', strtolower($config['version']));
420
421 $template->assign_vars(array(
422 'S_VERSION_UP_TO_DATE' => version_compare($current_version, $latest_version, '<') ? false : true,
423 ));
424 }
425
426 // Get forum statistics
427 $total_posts = $config['num_posts'];
428 $total_topics = $config['num_topics'];
429 $total_users = $config['num_users'];
430 $total_files = $config['num_files'];
431
432 $start_date = $user->format_date($config['board_startdate']);
433
434 $boarddays = (time() - $config['board_startdate']) / 86400;
435
436 $posts_per_day = sprintf('%.2f', $total_posts / $boarddays);
437 $topics_per_day = sprintf('%.2f', $total_topics / $boarddays);
438 $users_per_day = sprintf('%.2f', $total_users / $boarddays);
439 $files_per_day = sprintf('%.2f', $total_files / $boarddays);
440
441 $upload_dir_size = get_formatted_filesize($config['upload_dir_size']);
442
443 $avatar_dir_size = 0;
444
445 if ($avatar_dir = @opendir($phpbb_root_path . $config['avatar_path']))
446 {
447 while (($file = readdir($avatar_dir)) !== false)
448 {
449 if ($file[0] != '.' && $file != 'CVS' && strpos($file, 'index.') === false)
450 {
451 $avatar_dir_size += filesize($phpbb_root_path . $config['avatar_path'] . '/' . $file);
452 }
453 }
454 closedir($avatar_dir);
455
456 $avatar_dir_size = get_formatted_filesize($avatar_dir_size);
457 }
458 else
459 {
460 // Couldn't open Avatar dir.
461 $avatar_dir_size = $user->lang['NOT_AVAILABLE'];
462 }
463
464 if ($posts_per_day > $total_posts)
465 {
466 $posts_per_day = $total_posts;
467 }
468
469 if ($topics_per_day > $total_topics)
470 {
471 $topics_per_day = $total_topics;
472 }
473
474 if ($users_per_day > $total_users)
475 {
476 $users_per_day = $total_users;
477 }
478
479 if ($files_per_day > $total_files)
480 {
481 $files_per_day = $total_files;
482 }
483
484 if ($config['allow_attachments'] || $config['allow_pm_attach'])
485 {
486 $sql = 'SELECT COUNT(attach_id) AS total_orphan
487 FROM ' . ATTACHMENTS_TABLE . '
488 WHERE is_orphan = 1
489 AND filetime < ' . (time() - 3*60*60);
490 $result = $db->sql_query($sql);
491 $total_orphan = (int) $db->sql_fetchfield('total_orphan');
492 $db->sql_freeresult($result);
493 }
494 else
495 {
496 $total_orphan = false;
497 }
498
499 $dbsize = get_database_size();
500
501 $template->assign_vars(array(
502 'TOTAL_POSTS' => $total_posts,
503 'POSTS_PER_DAY' => $posts_per_day,
504 'TOTAL_TOPICS' => $total_topics,
505 'TOPICS_PER_DAY' => $topics_per_day,
506 'TOTAL_USERS' => $total_users,
507 'USERS_PER_DAY' => $users_per_day,
508 'TOTAL_FILES' => $total_files,
509 'FILES_PER_DAY' => $files_per_day,
510 'START_DATE' => $start_date,
511 'AVATAR_DIR_SIZE' => $avatar_dir_size,
512 'DBSIZE' => $dbsize,
513 'UPLOAD_DIR_SIZE' => $upload_dir_size,
514 'TOTAL_ORPHAN' => $total_orphan,
515 'S_TOTAL_ORPHAN' => ($total_orphan === false) ? false : true,
516 'GZIP_COMPRESSION' => ($config['gzip_compress'] && @extension_loaded('zlib')) ? $user->lang['ON'] : $user->lang['OFF'],
517 'DATABASE_INFO' => $db->sql_server_info(),
518 'BOARD_VERSION' => $config['version'],
519
520 'U_ACTION' => $this->u_action,
521 'U_ADMIN_LOG' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=logs&amp;mode=admin'),
522 'U_INACTIVE_USERS' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=inactive&amp;mode=list'),
523 'U_VERSIONCHECK' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=update&amp;mode=version_check'),
524 'U_VERSIONCHECK_FORCE' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=1&amp;versioncheck_force=1'),
525
526 'S_ACTION_OPTIONS' => ($auth->acl_get('a_board')) ? true : false,
527 'S_FOUNDER' => ($user->data['user_type'] == USER_FOUNDER) ? true : false,
528 )
529 );
530
531 $log_data = array();
532 $log_count = 0;
533
534 if ($auth->acl_get('a_viewlogs'))
535 {
536 view_log('admin', $log_data, $log_count, 5);
537
538 foreach ($log_data as $row)
539 {
540 $template->assign_block_vars('log', array(
541 'USERNAME' => $row['username_full'],
542 'IP' => $row['ip'],
543 'DATE' => $user->format_date($row['time']),
544 'ACTION' => $row['action'])
545 );
546 }
547 }
548
549 if ($auth->acl_get('a_user'))
550 {
551 $user->add_lang('memberlist');
552
553 $inactive = array();
554 $inactive_count = 0;
555
556 view_inactive_users($inactive, $inactive_count, 10);
557
558 foreach ($inactive as $row)
559 {
560 $template->assign_block_vars('inactive', array(
561 'INACTIVE_DATE' => $user->format_date($row['user_inactive_time']),
562 'REMINDED_DATE' => $user->format_date($row['user_reminded_time']),
563 'JOINED' => $user->format_date($row['user_regdate']),
564 'LAST_VISIT' => (!$row['user_lastvisit']) ? ' - ' : $user->format_date($row['user_lastvisit']),
565
566 'REASON' => $row['inactive_reason'],
567 'USER_ID' => $row['user_id'],
568 'POSTS' => ($row['user_posts']) ? $row['user_posts'] : 0,
569 'REMINDED' => $row['user_reminded'],
570
571 'REMINDED_EXPLAIN' => $user->lang('USER_LAST_REMINDED', (int) $row['user_reminded'], $user->format_date($row['user_reminded_time'])),
572
573 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], false, append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&amp;mode=overview')),
574 'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
575 'USER_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
576
577 'U_USER_ADMIN' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&amp;mode=overview&amp;u={$row['user_id']}"),
578 'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id={$row['user_id']}&amp;sr=posts") : '',
579 ));
580 }
581
582 $option_ary = array('activate' => 'ACTIVATE', 'delete' => 'DELETE');
583 if ($config['email_enable'])
584 {
585 $option_ary += array('remind' => 'REMIND');
586 }
587
588 $template->assign_vars(array(
589 'S_INACTIVE_USERS' => true,
590 'S_INACTIVE_OPTIONS' => build_select($option_ary))
591 );
592 }
593
594 // Warn if install is still present
595 if (file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install'))
596 {
597 $template->assign_var('S_REMOVE_INSTALL', true);
598 }
599
600 if (!defined('PHPBB_DISABLE_CONFIG_CHECK') && file_exists($phpbb_root_path . 'config.' . $phpEx) && phpbb_is_writable($phpbb_root_path . 'config.' . $phpEx))
601 {
602 // World-Writable? (000x)
603 $template->assign_var('S_WRITABLE_CONFIG', (bool) (@fileperms($phpbb_root_path . 'config.' . $phpEx) & 0x0002));
604 }
605
606 // Fill dbms version if not yet filled
607 if (empty($config['dbms_version']))
608 {
609 set_config('dbms_version', $db->sql_server_info(true));
610 }
611
612 $this->tpl_name = 'acp_main';
613 $this->page_title = 'ACP_MAIN';
614 }
615}
616
617?>
Note: See TracBrowser for help on using the repository browser.