2 /***************************************************************************
5 * begin : Saturday, Feb 13, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: page_header.php,v 1.106.2.25 2005/10/30 15:17:14 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 if ( !defined('IN_PHPBB') )
25 die("Hacking attempt");
28 define('HEADER_INC', TRUE);
33 $do_gzip_compress = FALSE;
34 if ( $board_config['gzip_compress'] )
36 $phpver = phpversion();
38 $useragent = (isset($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) ? $HTTP_SERVER_VARS['HTTP_USER_AGENT'] : getenv('HTTP_USER_AGENT');
40 if ( $phpver >= '4.0.4pl1' && ( strstr($useragent,'compatible') || strstr($useragent,'Gecko') ) )
42 if ( extension_loaded('zlib') )
44 ob_start('ob_gzhandler');
47 else if ( $phpver > '4.0' )
49 if ( strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip') )
51 if ( extension_loaded('zlib') )
53 $do_gzip_compress = TRUE;
57 header('Content-Encoding: gzip');
64 // Parse and show the overall header.
66 $template->set_filenames(array(
67 'overall_header' => ( empty($gen_simple_header) ) ? 'overall_header.tpl' : 'simple_header.tpl')
71 // Generate logged in/logged out status
73 if ( $userdata['session_logged_in'] )
75 $u_login_logout = 'login.'.$phpEx.'?logout=true&sid=' . $userdata['session_id'];
76 $l_login_logout = $lang['Logout'] . ' [ ' . $userdata['username'] . ' ]';
80 $u_login_logout = 'login.'.$phpEx;
81 $l_login_logout = $lang['Login'];
84 $s_last_visit = ( $userdata['session_logged_in'] ) ? create_date($board_config['default_dateformat'], $userdata['user_lastvisit'], $board_config['board_timezone']) : '';
87 // Get basic (usernames + totals) online
90 $logged_visible_online = 0;
91 $logged_hidden_online = 0;
93 $online_userlist = '';
96 if (defined('SHOW_ONLINE'))
99 $user_forum_sql = ( !empty($forum_id) ) ? "AND s.session_page = " . intval($forum_id) : '';
100 $sql = "SELECT u.username, u.user_id, u.user_allow_viewonline, u.user_level, s.session_logged_in, s.session_ip
101 FROM ".USERS_TABLE." u, ".SESSIONS_TABLE." s
102 WHERE u.user_id = s.session_user_id
103 AND s.session_time >= ".( time() - 300 ) . "
105 ORDER BY u.username ASC, s.session_ip ASC";
106 if( !($result = $db->sql_query($sql)) )
108 message_die(GENERAL_ERROR, 'Could not obtain user/online information', '', __LINE__, __FILE__, $sql);
111 $userlist_ary = array();
112 $userlist_visible = array();
115 $prev_user_ip = $prev_session_ip = '';
117 while( $row = $db->sql_fetchrow($result) )
119 // User is logged in and therefor not a guest
120 if ( $row['session_logged_in'] )
122 // Skip multiple sessions for one user
123 if ( $row['user_id'] != $prev_user_id )
126 if ( $row['user_level'] == ADMIN )
128 $row['username'] = '<b>' . $row['username'] . '</b>';
129 $style_color = 'style="color:#' . $theme['fontcolor3'] . '"';
131 else if ( $row['user_level'] == MOD )
133 $row['username'] = '<b>' . $row['username'] . '</b>';
134 $style_color = 'style="color:#' . $theme['fontcolor2'] . '"';
137 if ( $row['user_allow_viewonline'] )
139 $user_online_link = '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $row['user_id']) . '"' . $style_color .'>' . $row['username'] . '</a>';
140 $logged_visible_online++;
144 $user_online_link = '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $row['user_id']) . '"' . $style_color .'><i>' . $row['username'] . '</i></a>';
145 $logged_hidden_online++;
148 if ( $row['user_allow_viewonline'] || $userdata['user_level'] == ADMIN )
150 $online_userlist .= ( $online_userlist != '' ) ? ', ' . $user_online_link : $user_online_link;
154 $prev_user_id = $row['user_id'];
158 // Skip multiple sessions for one user
159 if ( $row['session_ip'] != $prev_session_ip )
165 $prev_session_ip = $row['session_ip'];
167 $db->sql_freeresult($result);
169 if ( empty($online_userlist) )
171 $online_userlist = $lang['None'];
173 $online_userlist = ( ( isset($forum_id) ) ? $lang['Browsing_forum'] : $lang['Registered_users'] ) . ' ' . $online_userlist;
175 $total_online_users = $logged_visible_online + $logged_hidden_online + $guests_online;
177 if ( $total_online_users > $board_config['record_online_users'])
179 $board_config['record_online_users'] = $total_online_users;
180 $board_config['record_online_date'] = time();
182 $sql = "UPDATE " . CONFIG_TABLE . "
183 SET config_value = '$total_online_users'
184 WHERE config_name = 'record_online_users'";
185 if ( !$db->sql_query($sql) )
187 message_die(GENERAL_ERROR, 'Could not update online user record (nr of users)', '', __LINE__, __FILE__, $sql);
190 $sql = "UPDATE " . CONFIG_TABLE . "
191 SET config_value = '" . $board_config['record_online_date'] . "'
192 WHERE config_name = 'record_online_date'";
193 if ( !$db->sql_query($sql) )
195 message_die(GENERAL_ERROR, 'Could not update online user record (date)', '', __LINE__, __FILE__, $sql);
199 if ( $total_online_users == 0 )
201 $l_t_user_s = $lang['Online_users_zero_total'];
203 else if ( $total_online_users == 1 )
205 $l_t_user_s = $lang['Online_user_total'];
209 $l_t_user_s = $lang['Online_users_total'];
212 if ( $logged_visible_online == 0 )
214 $l_r_user_s = $lang['Reg_users_zero_total'];
216 else if ( $logged_visible_online == 1 )
218 $l_r_user_s = $lang['Reg_user_total'];
222 $l_r_user_s = $lang['Reg_users_total'];
225 if ( $logged_hidden_online == 0 )
227 $l_h_user_s = $lang['Hidden_users_zero_total'];
229 else if ( $logged_hidden_online == 1 )
231 $l_h_user_s = $lang['Hidden_user_total'];
235 $l_h_user_s = $lang['Hidden_users_total'];
238 if ( $guests_online == 0 )
240 $l_g_user_s = $lang['Guest_users_zero_total'];
242 else if ( $guests_online == 1 )
244 $l_g_user_s = $lang['Guest_user_total'];
248 $l_g_user_s = $lang['Guest_users_total'];
251 $l_online_users = sprintf($l_t_user_s, $total_online_users);
252 $l_online_users .= sprintf($l_r_user_s, $logged_visible_online);
253 $l_online_users .= sprintf($l_h_user_s, $logged_hidden_online);
254 $l_online_users .= sprintf($l_g_user_s, $guests_online);
258 // Obtain number of new private messages
259 // if user is logged in
261 if ( ($userdata['session_logged_in']) && (empty($gen_simple_header)) )
263 if ( $userdata['user_new_privmsg'] )
265 $l_message_new = ( $userdata['user_new_privmsg'] == 1 ) ? $lang['New_pm'] : $lang['New_pms'];
266 $l_privmsgs_text = sprintf($l_message_new, $userdata['user_new_privmsg']);
268 if ( $userdata['user_last_privmsg'] > $userdata['user_lastvisit'] )
270 $sql = "UPDATE " . USERS_TABLE . "
271 SET user_last_privmsg = " . $userdata['user_lastvisit'] . "
272 WHERE user_id = " . $userdata['user_id'];
273 if ( !$db->sql_query($sql) )
275 message_die(GENERAL_ERROR, 'Could not update private message new/read time for user', '', __LINE__, __FILE__, $sql);
279 $icon_pm = $images['pm_new_msg'];
284 $icon_pm = $images['pm_new_msg'];
289 $l_privmsgs_text = $lang['No_new_pm'];
292 $icon_pm = $images['pm_no_new_msg'];
295 if ( $userdata['user_unread_privmsg'] )
297 $l_message_unread = ( $userdata['user_unread_privmsg'] == 1 ) ? $lang['Unread_pm'] : $lang['Unread_pms'];
298 $l_privmsgs_text_unread = sprintf($l_message_unread, $userdata['user_unread_privmsg']);
302 $l_privmsgs_text_unread = $lang['No_unread_pm'];
307 $icon_pm = $images['pm_no_new_msg'];
308 $l_privmsgs_text = $lang['Login_check_pm'];
309 $l_privmsgs_text_unread = '';
314 // Generate HTML required for Mozilla Navigation bar
316 if (!isset($nav_links))
318 $nav_links = array();
321 $nav_links_html = '';
322 $nav_link_proto = '<link rel="%s" href="%s" title="%s" />' . "\n";
323 while( list($nav_item, $nav_array) = @each($nav_links) )
325 if ( !empty($nav_array['url']) )
327 $nav_links_html .= sprintf($nav_link_proto, $nav_item, append_sid($nav_array['url']), $nav_array['title']);
331 // We have a nested array, used for items like <link rel='chapter'> that can occur more than once.
332 while( list(,$nested_array) = each($nav_array) )
334 $nav_links_html .= sprintf($nav_link_proto, $nav_item, $nested_array['url'], $nested_array['title']);
339 // Format Timezone. We are unable to use array_pop here, because of PHP3 compatibility
340 $l_timezone = explode('.', $board_config['board_timezone']);
341 $l_timezone = (count($l_timezone) > 1 && $l_timezone[count($l_timezone)-1] != 0) ? $lang[sprintf('%.1f', $board_config['board_timezone'])] : $lang[number_format($board_config['board_timezone'])];
343 // The following assigns all _common_ variables that may be used at any point
346 $template->assign_vars(array(
347 'SITENAME' => $board_config['sitename'],
348 'SITE_DESCRIPTION' => $board_config['site_desc'],
349 'PAGE_TITLE' => $page_title,
350 'LAST_VISIT_DATE' => sprintf($lang['You_last_visit'], $s_last_visit),
351 'CURRENT_TIME' => sprintf($lang['Current_time'], create_date($board_config['default_dateformat'], time(), $board_config['board_timezone'])),
352 'TOTAL_USERS_ONLINE' => $l_online_users,
353 'LOGGED_IN_USER_LIST' => $online_userlist,
354 'RECORD_USERS' => sprintf($lang['Record_online_users'], $board_config['record_online_users'], create_date($board_config['default_dateformat'], $board_config['record_online_date'], $board_config['board_timezone'])),
355 'PRIVATE_MESSAGE_INFO' => $l_privmsgs_text,
356 'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread,
357 'PRIVATE_MESSAGE_NEW_FLAG' => $s_privmsg_new,
359 'PRIVMSG_IMG' => $icon_pm,
361 'L_USERNAME' => $lang['Username'],
362 'L_PASSWORD' => $lang['Password'],
363 'L_LOGIN_LOGOUT' => $l_login_logout,
364 'L_LOGIN' => $lang['Login'],
365 'L_LOG_ME_IN' => $lang['Log_me_in'],
366 'L_AUTO_LOGIN' => $lang['Log_me_in'],
367 'L_INDEX' => sprintf($lang['Forum_Index'], $board_config['sitename']),
368 'L_REGISTER' => $lang['Register'],
369 'L_PROFILE' => $lang['Profile'],
370 'L_SEARCH' => $lang['Search'],
371 'L_PRIVATEMSGS' => $lang['Private_Messages'],
372 'L_WHO_IS_ONLINE' => $lang['Who_is_Online'],
373 'L_MEMBERLIST' => $lang['Memberlist'],
374 'L_FAQ' => $lang['FAQ'],
375 'L_USERGROUPS' => $lang['Usergroups'],
376 'L_SEARCH_NEW' => $lang['Search_new'],
377 'L_SEARCH_UNANSWERED' => $lang['Search_unanswered'],
378 'L_SEARCH_SELF' => $lang['Search_your_posts'],
379 'L_WHOSONLINE_ADMIN' => sprintf($lang['Admin_online_color'], '<span style="color:#' . $theme['fontcolor3'] . '">', '</span>'),
380 'L_WHOSONLINE_MOD' => sprintf($lang['Mod_online_color'], '<span style="color:#' . $theme['fontcolor2'] . '">', '</span>'),
382 'U_SEARCH_UNANSWERED' => append_sid('search.'.$phpEx.'?search_id=unanswered'),
383 'U_SEARCH_SELF' => append_sid('search.'.$phpEx.'?search_id=egosearch'),
384 'U_SEARCH_NEW' => append_sid('search.'.$phpEx.'?search_id=newposts'),
385 'U_INDEX' => append_sid('index.'.$phpEx),
386 'U_REGISTER' => append_sid('profile.'.$phpEx.'?mode=register'),
387 'U_PROFILE' => append_sid('profile.'.$phpEx.'?mode=editprofile'),
388 'U_PRIVATEMSGS' => append_sid('privmsg.'.$phpEx.'?folder=inbox'),
389 'U_PRIVATEMSGS_POPUP' => append_sid('privmsg.'.$phpEx.'?mode=newpm'),
390 'U_SEARCH' => append_sid('search.'.$phpEx),
391 'U_MEMBERLIST' => append_sid('memberlist.'.$phpEx),
392 'U_MODCP' => append_sid('modcp.'.$phpEx),
393 'U_FAQ' => append_sid('faq.'.$phpEx),
394 'U_VIEWONLINE' => append_sid('viewonline.'.$phpEx),
395 'U_LOGIN_LOGOUT' => append_sid($u_login_logout),
396 'U_GROUP_CP' => append_sid('groupcp.'.$phpEx),
398 'S_CONTENT_DIRECTION' => $lang['DIRECTION'],
399 'S_CONTENT_ENCODING' => $lang['ENCODING'],
400 'S_CONTENT_DIR_LEFT' => $lang['LEFT'],
401 'S_CONTENT_DIR_RIGHT' => $lang['RIGHT'],
402 'S_TIMEZONE' => sprintf($lang['All_times'], $l_timezone),
403 'S_LOGIN_ACTION' => append_sid('login.'.$phpEx),
405 'T_HEAD_STYLESHEET' => $theme['head_stylesheet'],
406 'T_BODY_BACKGROUND' => $theme['body_background'],
407 'T_BODY_BGCOLOR' => '#'.$theme['body_bgcolor'],
408 'T_BODY_TEXT' => '#'.$theme['body_text'],
409 'T_BODY_LINK' => '#'.$theme['body_link'],
410 'T_BODY_VLINK' => '#'.$theme['body_vlink'],
411 'T_BODY_ALINK' => '#'.$theme['body_alink'],
412 'T_BODY_HLINK' => '#'.$theme['body_hlink'],
413 'T_TR_COLOR1' => '#'.$theme['tr_color1'],
414 'T_TR_COLOR2' => '#'.$theme['tr_color2'],
415 'T_TR_COLOR3' => '#'.$theme['tr_color3'],
416 'T_TR_CLASS1' => $theme['tr_class1'],
417 'T_TR_CLASS2' => $theme['tr_class2'],
418 'T_TR_CLASS3' => $theme['tr_class3'],
419 'T_TH_COLOR1' => '#'.$theme['th_color1'],
420 'T_TH_COLOR2' => '#'.$theme['th_color2'],
421 'T_TH_COLOR3' => '#'.$theme['th_color3'],
422 'T_TH_CLASS1' => $theme['th_class1'],
423 'T_TH_CLASS2' => $theme['th_class2'],
424 'T_TH_CLASS3' => $theme['th_class3'],
425 'T_TD_COLOR1' => '#'.$theme['td_color1'],
426 'T_TD_COLOR2' => '#'.$theme['td_color2'],
427 'T_TD_COLOR3' => '#'.$theme['td_color3'],
428 'T_TD_CLASS1' => $theme['td_class1'],
429 'T_TD_CLASS2' => $theme['td_class2'],
430 'T_TD_CLASS3' => $theme['td_class3'],
431 'T_FONTFACE1' => $theme['fontface1'],
432 'T_FONTFACE2' => $theme['fontface2'],
433 'T_FONTFACE3' => $theme['fontface3'],
434 'T_FONTSIZE1' => $theme['fontsize1'],
435 'T_FONTSIZE2' => $theme['fontsize2'],
436 'T_FONTSIZE3' => $theme['fontsize3'],
437 'T_FONTCOLOR1' => '#'.$theme['fontcolor1'],
438 'T_FONTCOLOR2' => '#'.$theme['fontcolor2'],
439 'T_FONTCOLOR3' => '#'.$theme['fontcolor3'],
440 'T_SPAN_CLASS1' => $theme['span_class1'],
441 'T_SPAN_CLASS2' => $theme['span_class2'],
442 'T_SPAN_CLASS3' => $theme['span_class3'],
444 'NAV_LINKS' => $nav_links_html)
450 if ( !$userdata['session_logged_in'] )
452 $template->assign_block_vars('switch_user_logged_out', array());
456 if (!isset($board_config['allow_autologin']) || $board_config['allow_autologin'] )
458 $template->assign_block_vars('switch_allow_autologin', array());
459 $template->assign_block_vars('switch_user_logged_out.switch_allow_autologin', array());
464 $template->assign_block_vars('switch_user_logged_in', array());
466 if ( !empty($userdata['user_popup_pm']) )
468 $template->assign_block_vars('switch_enable_pm_popup', array());
472 // Add no-cache control for cookies if they are set
473 //$c_no_cache = (isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) || isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_data'])) ? 'no-cache="set-cookie", ' : '';
475 // Work around for "current" Apache 2 + PHP module which seems to not
476 // cope with private cache control setting
477 if (!empty($HTTP_SERVER_VARS['SERVER_SOFTWARE']) && strstr($HTTP_SERVER_VARS['SERVER_SOFTWARE'], 'Apache/2'))
479 header ('Cache-Control: no-cache, pre-check=0, post-check=0');
483 header ('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
485 header ('Expires: 0');
486 header ('Pragma: no-cache');
488 $template->pparse('overall_header');