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.99.2.6 2005/10/30 15:17:13 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', true);
24 $phpbb_root_path = './';
25 include($phpbb_root_path . 'extension.inc');
26 include($phpbb_root_path . 'common.'.$phpEx);
29 // Start session management
31 $userdata = session_pagestart($user_ip, PAGE_INDEX);
32 init_userprefs($userdata);
34 // End session management
37 $viewcat = ( !empty($HTTP_GET_VARS[POST_CAT_URL]) ) ? $HTTP_GET_VARS[POST_CAT_URL] : -1;
39 if( isset($HTTP_GET_VARS['mark']) || isset($HTTP_POST_VARS['mark']) )
41 $mark_read = ( isset($HTTP_POST_VARS['mark']) ) ? $HTTP_POST_VARS['mark'] : $HTTP_GET_VARS['mark'];
49 // Handle marking posts
51 if( $mark_read == 'forums' )
53 if( $userdata['session_logged_in'] )
55 setcookie($board_config['cookie_name'] . '_f_all', time(), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
58 $template->assign_vars(array(
59 "META" => '<meta http-equiv="refresh" content="3;url=' .append_sid("index.$phpEx") . '">')
62 $message = $lang['Forums_marked_read'] . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a> ');
64 message_die(GENERAL_MESSAGE, $message);
67 // End handle marking posts
70 $tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . "_t"]) : array();
71 $tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . "_f"]) : array();
74 // If you don't use these stats on your index you may want to consider
77 $total_posts = get_db_stat('postcount');
78 $total_users = get_db_stat('usercount');
79 $newest_userdata = get_db_stat('newestuser');
80 $newest_user = $newest_userdata['username'];
81 $newest_uid = $newest_userdata['user_id'];
83 if( $total_posts == 0 )
85 $l_total_post_s = $lang['Posted_articles_zero_total'];
87 else if( $total_posts == 1 )
89 $l_total_post_s = $lang['Posted_article_total'];
93 $l_total_post_s = $lang['Posted_articles_total'];
96 if( $total_users == 0 )
98 $l_total_user_s = $lang['Registered_users_zero_total'];
100 else if( $total_users == 1 )
102 $l_total_user_s = $lang['Registered_user_total'];
106 $l_total_user_s = $lang['Registered_users_total'];
113 $sql = "SELECT c.cat_id, c.cat_title, c.cat_order
114 FROM " . CATEGORIES_TABLE . " c
115 ORDER BY c.cat_order";
116 if( !($result = $db->sql_query($sql)) )
118 message_die(GENERAL_ERROR, 'Could not query categories list', '', __LINE__, __FILE__, $sql);
121 $category_rows = array();
122 while( $category_rows[] = $db->sql_fetchrow($result) );
123 $db->sql_freeresult($result);
125 if( ( $total_categories = count($category_rows) ) )
128 // Define appropriate SQL
133 $sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id
134 FROM " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p, " . USERS_TABLE . " u
135 WHERE p.post_id = f.forum_last_post_id
136 AND u.user_id = p.poster_id
138 SELECT f.*, NULL, NULL, NULL, NULL
139 FROM " . FORUMS_TABLE . " f
142 FROM " . POSTS_TABLE . " p
143 WHERE p.post_id = f.forum_last_post_id
146 ORDER BY cat_id, forum_order";
150 $sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id
151 FROM " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p, " . USERS_TABLE . " u
152 WHERE p.post_id = f.forum_last_post_id(+)
153 AND u.user_id = p.poster_id(+)
154 ORDER BY f.cat_id, f.forum_order";
158 $sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id
159 FROM (( " . FORUMS_TABLE . " f
160 LEFT JOIN " . POSTS_TABLE . " p ON p.post_id = f.forum_last_post_id )
161 LEFT JOIN " . USERS_TABLE . " u ON u.user_id = p.poster_id )
162 ORDER BY f.cat_id, f.forum_order";
165 if ( !($result = $db->sql_query($sql)) )
167 message_die(GENERAL_ERROR, 'Could not query forums information', '', __LINE__, __FILE__, $sql);
170 $forum_data = array();
171 while( $row = $db->sql_fetchrow($result) )
173 $forum_data[] = $row;
175 $db->sql_freeresult($result);
177 if ( !($total_forums = count($forum_data)) )
179 message_die(GENERAL_MESSAGE, $lang['No_forums']);
183 // Obtain a list of topic ids which contain
184 // posts made since user last visited
186 if ($userdata['session_logged_in'])
189 if ($userdata['user_lastvisit'] < (time() - 5184000))
191 $userdata['user_lastvisit'] = time() - 5184000;
194 $sql = "SELECT t.forum_id, t.topic_id, p.post_time
195 FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
196 WHERE p.post_id = t.topic_last_post_id
197 AND p.post_time > " . $userdata['user_lastvisit'] . "
198 AND t.topic_moved_id = 0";
199 if ( !($result = $db->sql_query($sql)) )
201 message_die(GENERAL_ERROR, 'Could not query new topic information', '', __LINE__, __FILE__, $sql);
204 $new_topic_data = array();
205 while( $topic_data = $db->sql_fetchrow($result) )
207 $new_topic_data[$topic_data['forum_id']][$topic_data['topic_id']] = $topic_data['post_time'];
209 $db->sql_freeresult($result);
213 // Obtain list of moderators of each forum
214 // First users, then groups ... broken into two queries
216 $sql = "SELECT aa.forum_id, u.user_id, u.username
217 FROM " . AUTH_ACCESS_TABLE . " aa, " . USER_GROUP_TABLE . " ug, " . GROUPS_TABLE . " g, " . USERS_TABLE . " u
218 WHERE aa.auth_mod = " . TRUE . "
219 AND g.group_single_user = 1
220 AND ug.group_id = aa.group_id
221 AND g.group_id = aa.group_id
222 AND u.user_id = ug.user_id
223 GROUP BY u.user_id, u.username, aa.forum_id
224 ORDER BY aa.forum_id, u.user_id";
225 if ( !($result = $db->sql_query($sql)) )
227 message_die(GENERAL_ERROR, 'Could not query forum moderator information', '', __LINE__, __FILE__, $sql);
230 $forum_moderators = array();
231 while( $row = $db->sql_fetchrow($result) )
233 $forum_moderators[$row['forum_id']][] = '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $row['user_id']) . '">' . $row['username'] . '</a>';
235 $db->sql_freeresult($result);
237 $sql = "SELECT aa.forum_id, g.group_id, g.group_name
238 FROM " . AUTH_ACCESS_TABLE . " aa, " . USER_GROUP_TABLE . " ug, " . GROUPS_TABLE . " g
239 WHERE aa.auth_mod = " . TRUE . "
240 AND g.group_single_user = 0
241 AND g.group_type <> " . GROUP_HIDDEN . "
242 AND ug.group_id = aa.group_id
243 AND g.group_id = aa.group_id
244 GROUP BY g.group_id, g.group_name, aa.forum_id
245 ORDER BY aa.forum_id, g.group_id";
246 if ( !($result = $db->sql_query($sql)) )
248 message_die(GENERAL_ERROR, 'Could not query forum moderator information', '', __LINE__, __FILE__, $sql);
251 while( $row = $db->sql_fetchrow($result) )
253 $forum_moderators[$row['forum_id']][] = '<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=" . $row['group_id']) . '">' . $row['group_name'] . '</a>';
255 $db->sql_freeresult($result);
258 // Find which forums are visible for this user
260 $is_auth_ary = array();
261 $is_auth_ary = auth(AUTH_VIEW, AUTH_LIST_ALL, $userdata, $forum_data);
264 // Start output of page
266 define('SHOW_ONLINE', true);
267 $page_title = $lang['Index'];
268 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
270 $template->set_filenames(array(
271 'body' => 'index_body.tpl')
274 $template->assign_vars(array(
275 'TOTAL_POSTS' => sprintf($l_total_post_s, $total_posts),
276 'TOTAL_USERS' => sprintf($l_total_user_s, $total_users),
277 'NEWEST_USER' => sprintf($lang['Newest_user'], '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=$newest_uid") . '">', $newest_user, '</a>'),
279 'FORUM_IMG' => $images['forum'],
280 'FORUM_NEW_IMG' => $images['forum_new'],
281 'FORUM_LOCKED_IMG' => $images['forum_locked'],
283 'L_FORUM' => $lang['Forum'],
284 'L_TOPICS' => $lang['Topics'],
285 'L_REPLIES' => $lang['Replies'],
286 'L_VIEWS' => $lang['Views'],
287 'L_POSTS' => $lang['Posts'],
288 'L_LASTPOST' => $lang['Last_Post'],
289 'L_NO_NEW_POSTS' => $lang['No_new_posts'],
290 'L_NEW_POSTS' => $lang['New_posts'],
291 'L_NO_NEW_POSTS_LOCKED' => $lang['No_new_posts_locked'],
292 'L_NEW_POSTS_LOCKED' => $lang['New_posts_locked'],
293 'L_ONLINE_EXPLAIN' => $lang['Online_explain'],
295 'L_MODERATOR' => $lang['Moderators'],
296 'L_FORUM_LOCKED' => $lang['Forum_is_locked'],
297 'L_MARK_FORUMS_READ' => $lang['Mark_all_forums'],
299 'U_MARK_READ' => append_sid("index.$phpEx?mark=forums"))
303 // Okay, let's build the index
305 for($i = 0; $i < $total_categories; $i++)
307 $cat_id = $category_rows[$i]['cat_id'];
310 // Should we display this category/forum set?
312 $display_forums = false;
313 for($j = 0; $j < $total_forums; $j++)
315 if ( $is_auth_ary[$forum_data[$j]['forum_id']]['auth_view'] && $forum_data[$j]['cat_id'] == $cat_id )
317 $display_forums = true;
322 // Yes, we should, so first dump out the category
323 // title, then, if appropriate the forum list
325 if ( $display_forums )
327 $template->assign_block_vars('catrow', array(
329 'CAT_DESC' => $category_rows[$i]['cat_title'],
330 'U_VIEWCAT' => append_sid("index.$phpEx?" . POST_CAT_URL . "=$cat_id"))
333 if ( $viewcat == $cat_id || $viewcat == -1 )
335 for($j = 0; $j < $total_forums; $j++)
337 if ( $forum_data[$j]['cat_id'] == $cat_id )
339 $forum_id = $forum_data[$j]['forum_id'];
341 if ( $is_auth_ary[$forum_id]['auth_view'] )
343 if ( $forum_data[$j]['forum_status'] == FORUM_LOCKED )
345 $folder_image = $images['forum_locked'];
346 $folder_alt = $lang['Forum_locked'];
350 $unread_topics = false;
351 if ( $userdata['session_logged_in'] )
353 if ( !empty($new_topic_data[$forum_id]) )
355 $forum_last_post_time = 0;
357 while( list($check_topic_id, $check_post_time) = @each($new_topic_data[$forum_id]) )
359 if ( empty($tracking_topics[$check_topic_id]) )
361 $unread_topics = true;
362 $forum_last_post_time = max($check_post_time, $forum_last_post_time);
367 if ( $tracking_topics[$check_topic_id] < $check_post_time )
369 $unread_topics = true;
370 $forum_last_post_time = max($check_post_time, $forum_last_post_time);
375 if ( !empty($tracking_forums[$forum_id]) )
377 if ( $tracking_forums[$forum_id] > $forum_last_post_time )
379 $unread_topics = false;
383 if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) )
385 if ( $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all'] > $forum_last_post_time )
387 $unread_topics = false;
394 $folder_image = ( $unread_topics ) ? $images['forum_new'] : $images['forum'];
395 $folder_alt = ( $unread_topics ) ? $lang['New_posts'] : $lang['No_new_posts'];
398 $posts = $forum_data[$j]['forum_posts'];
399 $topics = $forum_data[$j]['forum_topics'];
401 if ( $forum_data[$j]['forum_last_post_id'] )
403 $last_post_time = create_date($board_config['default_dateformat'], $forum_data[$j]['post_time'], $board_config['board_timezone']);
405 $last_post = $last_post_time . '<br />';
407 $last_post .= ( $forum_data[$j]['user_id'] == ANONYMOUS ) ? ( ($forum_data[$j]['post_username'] != '' ) ? $forum_data[$j]['post_username'] . ' ' : $lang['Guest'] . ' ' ) : '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . '=' . $forum_data[$j]['user_id']) . '">' . $forum_data[$j]['username'] . '</a> ';
409 $last_post .= '<a href="' . append_sid("viewtopic.$phpEx?" . POST_POST_URL . '=' . $forum_data[$j]['forum_last_post_id']) . '#' . $forum_data[$j]['forum_last_post_id'] . '"><img src="' . $images['icon_latest_reply'] . '" border="0" alt="' . $lang['View_latest_post'] . '" title="' . $lang['View_latest_post'] . '" /></a>';
413 $last_post = $lang['No_Posts'];
416 if ( count($forum_moderators[$forum_id]) > 0 )
418 $l_moderators = ( count($forum_moderators[$forum_id]) == 1 ) ? $lang['Moderator'] : $lang['Moderators'];
419 $moderator_list = implode(', ', $forum_moderators[$forum_id]);
423 $l_moderators = ' ';
424 $moderator_list = ' ';
427 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
428 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
430 $template->assign_block_vars('catrow.forumrow', array(
431 'ROW_COLOR' => '#' . $row_color,
432 'ROW_CLASS' => $row_class,
433 'FORUM_FOLDER_IMG' => $folder_image,
434 'FORUM_NAME' => $forum_data[$j]['forum_name'],
435 'FORUM_DESC' => $forum_data[$j]['forum_desc'],
436 'POSTS' => $forum_data[$j]['forum_posts'],
437 'TOPICS' => $forum_data[$j]['forum_topics'],
438 'LAST_POST' => $last_post,
439 'MODERATORS' => $moderator_list,
441 'L_MODERATOR' => $l_moderators,
442 'L_FORUM_FOLDER_ALT' => $folder_alt,
444 'U_VIEWFORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"))
451 } // for ... categories
453 }// if ... total_categories
456 message_die(GENERAL_MESSAGE, $lang['No_forums']);
462 $template->pparse('body');
464 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);