2 /***************************************************************************
5 * begin : Saturday, Feb 13, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: index.php,v 1.40.2.6 2004/07/11 16:46:15 acydburn Exp $
12 ***************************************************************************/
14 /***************************************************************************
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 ***************************************************************************/
23 define('IN_PHPBB', 1);
26 // Load default header
28 $no_page_header = TRUE;
29 $phpbb_root_path = "./../";
30 require($phpbb_root_path . 'extension.inc');
31 require('./pagestart.' . $phpEx);
36 function inarray($needle, $haystack)
38 for($i = 0; $i < sizeof($haystack); $i++ )
40 if( $haystack[$i] == $needle )
52 // Generate relevant output
54 if( isset($HTTP_GET_VARS['pane']) && $HTTP_GET_VARS['pane'] == 'left' )
59 while( $file = @readdir($dir) )
61 if( preg_match("/^admin_.*?\." . $phpEx . "$/", $file) )
71 include('./page_header_admin.'.$phpEx);
73 $template->set_filenames(array(
74 "body" => "admin/index_navigate.tpl")
77 $template->assign_vars(array(
78 "U_FORUM_INDEX" => append_sid("../index.$phpEx"),
79 "U_ADMIN_INDEX" => append_sid("index.$phpEx?pane=right"),
81 "L_FORUM_INDEX" => $lang['Main_index'],
82 "L_ADMIN_INDEX" => $lang['Admin_Index'],
83 "L_PREVIEW_FORUM" => $lang['Preview_forum'])
88 while( list($cat, $action_array) = each($module) )
90 $cat = ( !empty($lang[$cat]) ) ? $lang[$cat] : preg_replace("/_/", " ", $cat);
92 $template->assign_block_vars("catrow", array(
93 "ADMIN_CATEGORY" => $cat)
99 while( list($action, $file) = each($action_array) )
101 $row_color = ( !($row_count%2) ) ? $theme['td_color1'] : $theme['td_color2'];
102 $row_class = ( !($row_count%2) ) ? $theme['td_class1'] : $theme['td_class2'];
104 $action = ( !empty($lang[$action]) ) ? $lang[$action] : preg_replace("/_/", " ", $action);
106 $template->assign_block_vars("catrow.modulerow", array(
107 "ROW_COLOR" => "#" . $row_color,
108 "ROW_CLASS" => $row_class,
110 "ADMIN_MODULE" => $action,
111 "U_ADMIN_MODULE" => append_sid($file))
117 $template->pparse("body");
119 include('./page_footer_admin.'.$phpEx);
121 elseif( isset($HTTP_GET_VARS['pane']) && $HTTP_GET_VARS['pane'] == 'right' )
124 include('./page_header_admin.'.$phpEx);
126 $template->set_filenames(array(
127 "body" => "admin/index_body.tpl")
130 $template->assign_vars(array(
131 "L_WELCOME" => $lang['Welcome_phpBB'],
132 "L_ADMIN_INTRO" => $lang['Admin_intro'],
133 "L_FORUM_STATS" => $lang['Forum_stats'],
134 "L_WHO_IS_ONLINE" => $lang['Who_is_Online'],
135 "L_USERNAME" => $lang['Username'],
136 "L_LOCATION" => $lang['Location'],
137 "L_LAST_UPDATE" => $lang['Last_updated'],
138 "L_IP_ADDRESS" => $lang['IP_Address'],
139 "L_STATISTIC" => $lang['Statistic'],
140 "L_VALUE" => $lang['Value'],
141 "L_NUMBER_POSTS" => $lang['Number_posts'],
142 "L_POSTS_PER_DAY" => $lang['Posts_per_day'],
143 "L_NUMBER_TOPICS" => $lang['Number_topics'],
144 "L_TOPICS_PER_DAY" => $lang['Topics_per_day'],
145 "L_NUMBER_USERS" => $lang['Number_users'],
146 "L_USERS_PER_DAY" => $lang['Users_per_day'],
147 "L_BOARD_STARTED" => $lang['Board_started'],
148 "L_AVATAR_DIR_SIZE" => $lang['Avatar_dir_size'],
149 "L_DB_SIZE" => $lang['Database_size'],
150 "L_FORUM_LOCATION" => $lang['Forum_Location'],
151 "L_STARTED" => $lang['Login'],
152 "L_GZIP_COMPRESSION" => $lang['Gzip_compression'])
156 // Get forum statistics
158 $total_posts = get_db_stat('postcount');
159 $total_users = get_db_stat('usercount');
160 $total_topics = get_db_stat('topiccount');
162 $start_date = create_date($board_config['default_dateformat'], $board_config['board_startdate'], $board_config['board_timezone']);
164 $boarddays = ( time() - $board_config['board_startdate'] ) / 86400;
166 $posts_per_day = sprintf("%.2f", $total_posts / $boarddays);
167 $topics_per_day = sprintf("%.2f", $total_topics / $boarddays);
168 $users_per_day = sprintf("%.2f", $total_users / $boarddays);
170 $avatar_dir_size = 0;
172 if ($avatar_dir = @opendir($phpbb_root_path . $board_config['avatar_path']))
174 while( $file = @readdir($avatar_dir) )
176 if( $file != "." && $file != ".." )
178 $avatar_dir_size += @filesize($phpbb_root_path . $board_config['avatar_path'] . "/" . $file);
181 @closedir($avatar_dir);
184 // This bit of code translates the avatar directory size into human readable format
185 // Borrowed the code from the PHP.net annoted manual, origanally written by:
186 // Jesse (jesse@jess.on.ca)
188 if($avatar_dir_size >= 1048576)
190 $avatar_dir_size = round($avatar_dir_size / 1048576 * 100) / 100 . " MB";
192 else if($avatar_dir_size >= 1024)
194 $avatar_dir_size = round($avatar_dir_size / 1024 * 100) / 100 . " KB";
198 $avatar_dir_size = $avatar_dir_size . " Bytes";
204 // Couldn't open Avatar dir.
205 $avatar_dir_size = $lang['Not_available'];
208 if($posts_per_day > $total_posts)
210 $posts_per_day = $total_posts;
213 if($topics_per_day > $total_topics)
215 $topics_per_day = $total_topics;
218 if($users_per_day > $total_users)
220 $users_per_day = $total_users;
224 // DB size ... MySQL only
226 // This code is heavily influenced by a similar routine
227 // in phpMyAdmin 2.2.0
229 if( preg_match("/^mysql/", SQL_LAYER) )
231 $sql = "SELECT VERSION() AS mysql_version";
232 if($result = $db->sql_query($sql))
234 $row = $db->sql_fetchrow($result);
235 $version = $row['mysql_version'];
237 if( preg_match("/^(3\.23|4\.)/", $version) )
239 $db_name = ( preg_match("/^(3\.23\.[6-9])|(3\.23\.[1-9][1-9])|(4\.)/", $version) ) ? "`$dbname`" : $dbname;
241 $sql = "SHOW TABLE STATUS
243 if($result = $db->sql_query($sql))
245 $tabledata_ary = $db->sql_fetchrowset($result);
248 for($i = 0; $i < count($tabledata_ary); $i++)
250 if( $tabledata_ary[$i]['Type'] != "MRG_MyISAM" )
252 if( $table_prefix != "" )
254 if( strstr($tabledata_ary[$i]['Name'], $table_prefix) )
256 $dbsize += $tabledata_ary[$i]['Data_length'] + $tabledata_ary[$i]['Index_length'];
261 $dbsize += $tabledata_ary[$i]['Data_length'] + $tabledata_ary[$i]['Index_length'];
265 } // Else we couldn't get the table status.
269 $dbsize = $lang['Not_available'];
274 $dbsize = $lang['Not_available'];
277 else if( preg_match("/^mssql/", SQL_LAYER) )
279 $sql = "SELECT ((SUM(size) * 8.0) * 1024.0) as dbsize
281 if( $result = $db->sql_query($sql) )
283 $dbsize = ( $row = $db->sql_fetchrow($result) ) ? intval($row['dbsize']) : $lang['Not_available'];
287 $dbsize = $lang['Not_available'];
292 $dbsize = $lang['Not_available'];
295 if ( is_integer($dbsize) )
297 if( $dbsize >= 1048576 )
299 $dbsize = sprintf("%.2f MB", ( $dbsize / 1048576 ));
301 else if( $dbsize >= 1024 )
303 $dbsize = sprintf("%.2f KB", ( $dbsize / 1024 ));
307 $dbsize = sprintf("%.2f Bytes", $dbsize);
311 $template->assign_vars(array(
312 "NUMBER_OF_POSTS" => $total_posts,
313 "NUMBER_OF_TOPICS" => $total_topics,
314 "NUMBER_OF_USERS" => $total_users,
315 "START_DATE" => $start_date,
316 "POSTS_PER_DAY" => $posts_per_day,
317 "TOPICS_PER_DAY" => $topics_per_day,
318 "USERS_PER_DAY" => $users_per_day,
319 "AVATAR_DIR_SIZE" => $avatar_dir_size,
320 "DB_SIZE" => $dbsize,
321 "GZIP_COMPRESSION" => ( $board_config['gzip_compress'] ) ? $lang['ON'] : $lang['OFF'])
324 // End forum statistics
328 // Get users online information.
330 $sql = "SELECT u.user_id, u.username, u.user_session_time, u.user_session_page, s.session_logged_in, s.session_ip, s.session_start
331 FROM " . USERS_TABLE . " u, " . SESSIONS_TABLE . " s
332 WHERE s.session_logged_in = " . TRUE . "
333 AND u.user_id = s.session_user_id
334 AND u.user_id <> " . ANONYMOUS . "
335 AND s.session_time >= " . ( time() - 300 ) . "
336 ORDER BY u.user_session_time DESC";
337 if(!$result = $db->sql_query($sql))
339 message_die(GENERAL_ERROR, "Couldn't obtain regd user/online information.", "", __LINE__, __FILE__, $sql);
341 $onlinerow_reg = $db->sql_fetchrowset($result);
343 $sql = "SELECT session_page, session_logged_in, session_time, session_ip, session_start
344 FROM " . SESSIONS_TABLE . "
345 WHERE session_logged_in = 0
346 AND session_time >= " . ( time() - 300 ) . "
347 ORDER BY session_time DESC";
348 if(!$result = $db->sql_query($sql))
350 message_die(GENERAL_ERROR, "Couldn't obtain guest user/online information.", "", __LINE__, __FILE__, $sql);
352 $onlinerow_guest = $db->sql_fetchrowset($result);
354 $sql = "SELECT forum_name, forum_id
355 FROM " . FORUMS_TABLE;
356 if($forums_result = $db->sql_query($sql))
358 while($forumsrow = $db->sql_fetchrow($forums_result))
360 $forum_data[$forumsrow['forum_id']] = $forumsrow['forum_name'];
365 message_die(GENERAL_ERROR, "Couldn't obtain user/online forums information.", "", __LINE__, __FILE__, $sql);
368 $reg_userid_ary = array();
370 if( count($onlinerow_reg) )
372 $registered_users = 0;
374 for($i = 0; $i < count($onlinerow_reg); $i++)
376 if( !inarray($onlinerow_reg[$i]['user_id'], $reg_userid_ary) )
378 $reg_userid_ary[] = $onlinerow_reg[$i]['user_id'];
380 $username = $onlinerow_reg[$i]['username'];
382 if( $onlinerow_reg[$i]['user_allow_viewonline'] || $userdata['user_level'] == ADMIN )
393 if( $onlinerow_reg[$i]['user_session_page'] < 1 )
395 switch($onlinerow_reg[$i]['user_session_page'])
398 $location = $lang['Forum_index'];
399 $location_url = "index.$phpEx?pane=right";
402 $location = $lang['Posting_message'];
403 $location_url = "index.$phpEx?pane=right";
406 $location = $lang['Logging_on'];
407 $location_url = "index.$phpEx?pane=right";
410 $location = $lang['Searching_forums'];
411 $location_url = "index.$phpEx?pane=right";
414 $location = $lang['Viewing_profile'];
415 $location_url = "index.$phpEx?pane=right";
417 case PAGE_VIEWONLINE:
418 $location = $lang['Viewing_online'];
419 $location_url = "index.$phpEx?pane=right";
421 case PAGE_VIEWMEMBERS:
422 $location = $lang['Viewing_member_list'];
423 $location_url = "index.$phpEx?pane=right";
426 $location = $lang['Viewing_priv_msgs'];
427 $location_url = "index.$phpEx?pane=right";
430 $location = $lang['Viewing_FAQ'];
431 $location_url = "index.$phpEx?pane=right";
434 $location = $lang['Forum_index'];
435 $location_url = "index.$phpEx?pane=right";
440 $location_url = append_sid("admin_forums.$phpEx?mode=editforum&" . POST_FORUM_URL . "=" . $onlinerow_reg[$i]['user_session_page']);
441 $location = $forum_data[$onlinerow_reg[$i]['user_session_page']];
444 $row_color = ( $registered_users % 2 ) ? $theme['td_color1'] : $theme['td_color2'];
445 $row_class = ( $registered_users % 2 ) ? $theme['td_class1'] : $theme['td_class2'];
447 $reg_ip = decode_ip($onlinerow_reg[$i]['session_ip']);
449 $template->assign_block_vars("reg_user_row", array(
450 "ROW_COLOR" => "#" . $row_color,
451 "ROW_CLASS" => $row_class,
452 "USERNAME" => $username,
453 "STARTED" => create_date($board_config['default_dateformat'], $onlinerow_reg[$i]['session_start'], $board_config['board_timezone']),
454 "LASTUPDATE" => create_date($board_config['default_dateformat'], $onlinerow_reg[$i]['user_session_time'], $board_config['board_timezone']),
455 "FORUM_LOCATION" => $location,
456 "IP_ADDRESS" => $reg_ip,
458 "U_WHOIS_IP" => "http://network-tools.com/default.asp?host=$reg_ip",
459 "U_USER_PROFILE" => append_sid("admin_users.$phpEx?mode=edit&" . POST_USERS_URL . "=" . $onlinerow_reg[$i]['user_id']),
460 "U_FORUM_LOCATION" => append_sid($location_url))
468 $template->assign_vars(array(
469 "L_NO_REGISTERED_USERS_BROWSING" => $lang['No_users_browsing'])
476 if( count($onlinerow_guest) )
480 for($i = 0; $i < count($onlinerow_guest); $i++)
482 $guest_userip_ary[] = $onlinerow_guest[$i]['session_ip'];
485 if( $onlinerow_guest[$i]['session_page'] < 1 )
487 switch( $onlinerow_guest[$i]['session_page'] )
490 $location = $lang['Forum_index'];
491 $location_url = "index.$phpEx?pane=right";
494 $location = $lang['Posting_message'];
495 $location_url = "index.$phpEx?pane=right";
498 $location = $lang['Logging_on'];
499 $location_url = "index.$phpEx?pane=right";
502 $location = $lang['Searching_forums'];
503 $location_url = "index.$phpEx?pane=right";
506 $location = $lang['Viewing_profile'];
507 $location_url = "index.$phpEx?pane=right";
509 case PAGE_VIEWONLINE:
510 $location = $lang['Viewing_online'];
511 $location_url = "index.$phpEx?pane=right";
513 case PAGE_VIEWMEMBERS:
514 $location = $lang['Viewing_member_list'];
515 $location_url = "index.$phpEx?pane=right";
518 $location = $lang['Viewing_priv_msgs'];
519 $location_url = "index.$phpEx?pane=right";
522 $location = $lang['Viewing_FAQ'];
523 $location_url = "index.$phpEx?pane=right";
526 $location = $lang['Forum_index'];
527 $location_url = "index.$phpEx?pane=right";
532 $location_url = append_sid("admin_forums.$phpEx?mode=editforum&" . POST_FORUM_URL . "=" . $onlinerow_guest[$i]['session_page']);
533 $location = $forum_data[$onlinerow_guest[$i]['session_page']];
536 $row_color = ( $guest_users % 2 ) ? $theme['td_color1'] : $theme['td_color2'];
537 $row_class = ( $guest_users % 2 ) ? $theme['td_class1'] : $theme['td_class2'];
539 $guest_ip = decode_ip($onlinerow_guest[$i]['session_ip']);
541 $template->assign_block_vars("guest_user_row", array(
542 "ROW_COLOR" => "#" . $row_color,
543 "ROW_CLASS" => $row_class,
544 "USERNAME" => $lang['Guest'],
545 "STARTED" => create_date($board_config['default_dateformat'], $onlinerow_guest[$i]['session_start'], $board_config['board_timezone']),
546 "LASTUPDATE" => create_date($board_config['default_dateformat'], $onlinerow_guest[$i]['session_time'], $board_config['board_timezone']),
547 "FORUM_LOCATION" => $location,
548 "IP_ADDRESS" => $guest_ip,
550 "U_WHOIS_IP" => "http://network-tools.com/default.asp?host=$guest_ip",
551 "U_FORUM_LOCATION" => append_sid($location_url))
558 $template->assign_vars(array(
559 "L_NO_GUESTS_BROWSING" => $lang['No_users_browsing'])
563 $template->pparse("body");
565 include('./page_footer_admin.'.$phpEx);
573 $template->set_filenames(array(
574 "body" => "admin/index_frameset.tpl")
577 $template->assign_vars(array(
578 "S_FRAME_NAV" => append_sid("index.$phpEx?pane=left"),
579 "S_FRAME_MAIN" => append_sid("index.$phpEx?pane=right"))
582 header ("Expires: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
583 header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
585 $template->pparse("body");