1 rizwank 1.1 <?php
2 /***************************************************************************
3 * page_header.php
4 * -------------------
5 * begin : Saturday, Feb 13, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
8 *
9 * $Id: page_header.php,v 1.106.2.11 2002/12/19 17:17:39 psotfx Exp $
10 *
11 *
12 ***************************************************************************/
13
14 /***************************************************************************
15 *
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.
20 *
21 ***************************************************************************/
22 rizwank 1.1
23 if ( !defined('IN_PHPBB') )
24 {
25 die("Hacking attempt");
26 }
27
28 define('HEADER_INC', TRUE);
29
30 //
31 // gzip_compression
32 //
33 $do_gzip_compress = FALSE;
34 if ( $board_config['gzip_compress'] )
35 {
36 $phpver = phpversion();
37
38 $useragent = (isset($_SERVER["HTTP_USER_AGENT"]) ) ? $_SERVER["HTTP_USER_AGENT"] : $HTTP_USER_AGENT;
39
40 if ( $phpver >= '4.0.4pl1' && ( strstr($useragent,'compatible') || strstr($useragent,'Gecko') ) )
41 {
42 if ( extension_loaded('zlib') )
43 rizwank 1.1 {
44 ob_start('ob_gzhandler');
45 }
46 }
47 else if ( $phpver > '4.0' )
48 {
49 if ( strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip') )
50 {
51 if ( extension_loaded('zlib') )
52 {
53 $do_gzip_compress = TRUE;
54 ob_start();
55 ob_implicit_flush(0);
56
57 header('Content-Encoding: gzip');
58 }
59 }
60 }
61 }
62
63 //
64 rizwank 1.1 // Parse and show the overall header.
65 //
66 $template->set_filenames(array(
67 'overall_header' => ( empty($gen_simple_header) ) ? 'overall_header.tpl' : 'simple_header.tpl')
68 );
69
70 //
71 // Generate logged in/logged out status
72 //
73 if ( $userdata['session_logged_in'] )
74 {
75 $u_login_logout = 'login.'.$phpEx.'?logout=true&sid=' . $userdata['session_id'];
76 $l_login_logout = $lang['Logout'] . ' [ ' . $userdata['username'] . ' ]';
77 }
78 else
79 {
80 $u_login_logout = 'login.'.$phpEx;
81 $l_login_logout = $lang['Login'];
82 }
83
84 $s_last_visit = ( $userdata['session_logged_in'] ) ? create_date($board_config['default_dateformat'], $userdata['user_lastvisit'], $board_config['board_timezone']) : '';
85 rizwank 1.1
86 //
87 // Get basic (usernames + totals) online
88 // situation
89 //
90 $logged_visible_online = 0;
91 $logged_hidden_online = 0;
92 $guests_online = 0;
93 $online_userlist = '';
94
95 if (defined('SHOW_ONLINE'))
96 {
97
98 $user_forum_sql = ( !empty($forum_id) ) ? "AND s.session_page = " . intval($forum_id) : '';
99 $sql = "SELECT u.username, u.user_id, u.user_allow_viewonline, u.user_level, s.session_logged_in, s.session_ip
100 FROM ".USERS_TABLE." u, ".SESSIONS_TABLE." s
101 WHERE u.user_id = s.session_user_id
102 AND s.session_time >= ".( time() - 300 ) . "
103 $user_forum_sql
104 ORDER BY u.username ASC, s.session_ip ASC";
105 if( !($result = $db->sql_query($sql)) )
106 rizwank 1.1 {
107 message_die(GENERAL_ERROR, 'Could not obtain user/online information', '', __LINE__, __FILE__, $sql);
108 }
109
110 $userlist_ary = array();
111 $userlist_visible = array();
112
113 $prev_user_id = 0;
114 $prev_user_ip = '';
115
116 while( $row = $db->sql_fetchrow($result) )
117 {
118 // User is logged in and therefor not a guest
119 if ( $row['session_logged_in'] )
120 {
121 // Skip multiple sessions for one user
122 if ( $row['user_id'] != $prev_user_id )
123 {
124 $style_color = '';
125 if ( $row['user_level'] == ADMIN )
126 {
127 rizwank 1.1 $row['username'] = '<b>' . $row['username'] . '</b>';
128 $style_color = 'style="color:#' . $theme['fontcolor3'] . '"';
129 }
130 else if ( $row['user_level'] == MOD )
131 {
132 $row['username'] = '<b>' . $row['username'] . '</b>';
133 $style_color = 'style="color:#' . $theme['fontcolor2'] . '"';
134 }
135
136 if ( $row['user_allow_viewonline'] )
137 {
138 $user_online_link = '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $row['user_id']) . '"' . $style_color .'>' . $row['username'] . '</a>';
139 $logged_visible_online++;
140 }
141 else
142 {
143 $user_online_link = '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $row['user_id']) . '"' . $style_color .'><i>' . $row['username'] . '</i></a>';
144 $logged_hidden_online++;
145 }
146
147 if ( $row['user_allow_viewonline'] || $userdata['user_level'] == ADMIN )
148 rizwank 1.1 {
149 $online_userlist .= ( $online_userlist != '' ) ? ', ' . $user_online_link : $user_online_link;
150 }
151 }
152
153 $prev_user_id = $row['user_id'];
154 }
155 else
156 {
157 // Skip multiple sessions for one user
158 if ( $row['session_ip'] != $prev_session_ip )
159 {
160 $guests_online++;
161 }
162 }
163
164 $prev_session_ip = $row['session_ip'];
165 }
166 $db->sql_freeresult($result);
167
168 if ( empty($online_userlist) )
169 rizwank 1.1 {
170 $online_userlist = $lang['None'];
171 }
172 $online_userlist = ( ( isset($forum_id) ) ? $lang['Browsing_forum'] : $lang['Registered_users'] ) . ' ' . $online_userlist;
173
174 $total_online_users = $logged_visible_online + $logged_hidden_online + $guests_online;
175
176 if ( $total_online_users > $board_config['record_online_users'])
177 {
178 $board_config['record_online_users'] = $total_online_users;
179 $board_config['record_online_date'] = time();
180
181 $sql = "UPDATE " . CONFIG_TABLE . "
182 SET config_value = '$total_online_users'
183 WHERE config_name = 'record_online_users'";
184 if ( !$db->sql_query($sql) )
185 {
186 message_die(GENERAL_ERROR, 'Could not update online user record (nr of users)', '', __LINE__, __FILE__, $sql);
187 }
188
189 $sql = "UPDATE " . CONFIG_TABLE . "
190 rizwank 1.1 SET config_value = '" . $board_config['record_online_date'] . "'
191 WHERE config_name = 'record_online_date'";
192 if ( !$db->sql_query($sql) )
193 {
194 message_die(GENERAL_ERROR, 'Could not update online user record (date)', '', __LINE__, __FILE__, $sql);
195 }
196 }
197
198 if ( $total_online_users == 0 )
199 {
200 $l_t_user_s = $lang['Online_users_zero_total'];
201 }
202 else if ( $total_online_users == 1 )
203 {
204 $l_t_user_s = $lang['Online_user_total'];
205 }
206 else
207 {
208 $l_t_user_s = $lang['Online_users_total'];
209 }
210
211 rizwank 1.1 if ( $logged_visible_online == 0 )
212 {
213 $l_r_user_s = $lang['Reg_users_zero_total'];
214 }
215 else if ( $logged_visible_online == 1 )
216 {
217 $l_r_user_s = $lang['Reg_user_total'];
218 }
219 else
220 {
221 $l_r_user_s = $lang['Reg_users_total'];
222 }
223
224 if ( $logged_hidden_online == 0 )
225 {
226 $l_h_user_s = $lang['Hidden_users_zero_total'];
227 }
228 else if ( $logged_hidden_online == 1 )
229 {
230 $l_h_user_s = $lang['Hidden_user_total'];
231 }
232 rizwank 1.1 else
233 {
234 $l_h_user_s = $lang['Hidden_users_total'];
235 }
236
237 if ( $guests_online == 0 )
238 {
239 $l_g_user_s = $lang['Guest_users_zero_total'];
240 }
241 else if ( $guests_online == 1 )
242 {
243 $l_g_user_s = $lang['Guest_user_total'];
244 }
245 else
246 {
247 $l_g_user_s = $lang['Guest_users_total'];
248 }
249
250 $l_online_users = sprintf($l_t_user_s, $total_online_users);
251 $l_online_users .= sprintf($l_r_user_s, $logged_visible_online);
252 $l_online_users .= sprintf($l_h_user_s, $logged_hidden_online);
253 rizwank 1.1 $l_online_users .= sprintf($l_g_user_s, $guests_online);
254 }
255
256 //
257 // Obtain number of new private messages
258 // if user is logged in
259 //
260 if ( $userdata['session_logged_in'] )
261 {
262 if ( $userdata['user_new_privmsg'] )
263 {
264 $l_message_new = ( $userdata['user_new_privmsg'] == 1 ) ? $lang['New_pm'] : $lang['New_pms'];
265 $l_privmsgs_text = sprintf($l_message_new, $userdata['user_new_privmsg']);
266
267 if ( $userdata['user_last_privmsg'] > $userdata['user_lastvisit'] )
268 {
269 $sql = "UPDATE " . USERS_TABLE . "
270 SET user_last_privmsg = " . $userdata['user_lastvisit'] . "
271 WHERE user_id = " . $userdata['user_id'];
272 if ( !$db->sql_query($sql) )
273 {
274 rizwank 1.1 message_die(GENERAL_ERROR, 'Could not update private message new/read time for user', '', __LINE__, __FILE__, $sql);
275 }
276
277 $s_privmsg_new = 1;
278 $icon_pm = $images['pm_new_msg'];
279 }
280 else
281 {
282 $s_privmsg_new = 0;
283 $icon_pm = $images['pm_new_msg'];
284 }
285 }
286 else
287 {
288 $l_privmsgs_text = $lang['No_new_pm'];
289
290 $s_privmsg_new = 0;
291 $icon_pm = $images['pm_no_new_msg'];
292 }
293
294 if ( $userdata['user_unread_privmsg'] )
295 rizwank 1.1 {
296 $l_message_unread = ( $userdata['user_unread_privmsg'] == 1 ) ? $lang['Unread_pm'] : $lang['Unread_pms'];
297 $l_privmsgs_text_unread = sprintf($l_message_unread, $userdata['user_unread_privmsg']);
298 }
299 else
300 {
301 $l_privmsgs_text_unread = $lang['No_unread_pm'];
302 }
303 }
304 else
305 {
306 $icon_pm = $images['pm_no_new_msg'];
307 $l_privmsgs_text = $lang['Login_check_pm'];
308 $l_privmsgs_text_unread = '';
309 $s_privmsg_new = 0;
310 }
311
312 //
313 // Generate HTML required for Mozilla Navigation bar
314 //
315 $nav_links_html = '';
316 rizwank 1.1 $nav_link_proto = '<link rel="%s" href="%s" title="%s" />' . "\n";
317 while( list($nav_item, $nav_array) = @each($nav_links) )
318 {
319 if ( !empty($nav_array['url']) )
320 {
321 $nav_links_html .= sprintf($nav_link_proto, $nav_item, append_sid($nav_array['url']), $nav_array['title']);
322 }
323 else
324 {
325 // We have a nested array, used for items like <link rel='chapter'> that can occur more than once.
326 while( list(,$nested_array) = each($nav_array) )
327 {
328 $nav_links_html .= sprintf($nav_link_proto, $nav_item, $nested_array['url'], $nested_array['title']);
329 }
330 }
331 }
332
333 //
334 // The following assigns all _common_ variables that may be used at any point
335 // in a template.
336 //
337 rizwank 1.1 $template->assign_vars(array(
338 'SITENAME' => $board_config['sitename'],
339 'SITE_DESCRIPTION' => $board_config['site_desc'],
340 'PAGE_TITLE' => $page_title,
341 'LAST_VISIT_DATE' => sprintf($lang['You_last_visit'], $s_last_visit),
342 'CURRENT_TIME' => sprintf($lang['Current_time'], create_date($board_config['default_dateformat'], time(), $board_config['board_timezone'])),
343 'TOTAL_USERS_ONLINE' => $l_online_users,
344 'LOGGED_IN_USER_LIST' => $online_userlist,
345 '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'])),
346 'PRIVATE_MESSAGE_INFO' => $l_privmsgs_text,
347 'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread,
348 'PRIVATE_MESSAGE_NEW_FLAG' => $s_privmsg_new,
349
350 'PRIVMSG_IMG' => $icon_pm,
351
352 'L_USERNAME' => $lang['Username'],
353 'L_PASSWORD' => $lang['Password'],
354 'L_LOGIN_LOGOUT' => $l_login_logout,
355 'L_LOGIN' => $lang['Login'],
356 'L_LOG_ME_IN' => $lang['Log_me_in'],
357 'L_AUTO_LOGIN' => $lang['Log_me_in'],
358 rizwank 1.1 'L_INDEX' => sprintf($lang['Forum_Index'], $board_config['sitename']),
359 'L_REGISTER' => $lang['Register'],
360 'L_PROFILE' => $lang['Profile'],
361 'L_SEARCH' => $lang['Search'],
362 'L_PRIVATEMSGS' => $lang['Private_Messages'],
363 'L_WHO_IS_ONLINE' => $lang['Who_is_Online'],
364 'L_MEMBERLIST' => $lang['Memberlist'],
365 'L_FAQ' => $lang['FAQ'],
366 'L_USERGROUPS' => $lang['Usergroups'],
367 'L_SEARCH_NEW' => $lang['Search_new'],
368 'L_SEARCH_UNANSWERED' => $lang['Search_unanswered'],
369 'L_SEARCH_SELF' => $lang['Search_your_posts'],
370 'L_WHOSONLINE_ADMIN' => sprintf($lang['Admin_online_color'], '<span style="color:#' . $theme['fontcolor3'] . '">', '</span>'),
371 'L_WHOSONLINE_MOD' => sprintf($lang['Mod_online_color'], '<span style="color:#' . $theme['fontcolor2'] . '">', '</span>'),
372
373 'U_SEARCH_UNANSWERED' => append_sid('search.'.$phpEx.'?search_id=unanswered'),
374 'U_SEARCH_SELF' => append_sid('search.'.$phpEx.'?search_id=egosearch'),
375 'U_SEARCH_NEW' => append_sid('search.'.$phpEx.'?search_id=newposts'),
376 'U_INDEX' => append_sid('index.'.$phpEx),
377 'U_REGISTER' => append_sid('profile.'.$phpEx.'?mode=register'),
378 'U_PROFILE' => append_sid('profile.'.$phpEx.'?mode=editprofile'),
379 rizwank 1.1 'U_PRIVATEMSGS' => append_sid('privmsg.'.$phpEx.'?folder=inbox'),
380 'U_PRIVATEMSGS_POPUP' => append_sid('privmsg.'.$phpEx.'?mode=newpm'),
381 'U_SEARCH' => append_sid('search.'.$phpEx),
382 'U_MEMBERLIST' => append_sid('memberlist.'.$phpEx),
383 'U_MODCP' => append_sid('modcp.'.$phpEx),
384 'U_FAQ' => append_sid('faq.'.$phpEx),
385 'U_VIEWONLINE' => append_sid('viewonline.'.$phpEx),
386 'U_LOGIN_LOGOUT' => append_sid($u_login_logout),
387 'U_MEMBERSLIST' => append_sid('memberlist.'.$phpEx),
388 'U_GROUP_CP' => append_sid('groupcp.'.$phpEx),
389
390 'S_CONTENT_DIRECTION' => $lang['DIRECTION'],
391 'S_CONTENT_ENCODING' => $lang['ENCODING'],
392 'S_CONTENT_DIR_LEFT' => $lang['LEFT'],
393 'S_CONTENT_DIR_RIGHT' => $lang['RIGHT'],
394 'S_TIMEZONE' => sprintf($lang['All_times'], $lang[number_format($board_config['board_timezone'])]),
395 'S_LOGIN_ACTION' => append_sid('login.'.$phpEx),
396
397 'T_HEAD_STYLESHEET' => $theme['head_stylesheet'],
398 'T_BODY_BACKGROUND' => $theme['body_background'],
399 'T_BODY_BGCOLOR' => '#'.$theme['body_bgcolor'],
400 rizwank 1.1 'T_BODY_TEXT' => '#'.$theme['body_text'],
401 'T_BODY_LINK' => '#'.$theme['body_link'],
402 'T_BODY_VLINK' => '#'.$theme['body_vlink'],
403 'T_BODY_ALINK' => '#'.$theme['body_alink'],
404 'T_BODY_HLINK' => '#'.$theme['body_hlink'],
405 'T_TR_COLOR1' => '#'.$theme['tr_color1'],
406 'T_TR_COLOR2' => '#'.$theme['tr_color2'],
407 'T_TR_COLOR3' => '#'.$theme['tr_color3'],
408 'T_TR_CLASS1' => $theme['tr_class1'],
409 'T_TR_CLASS2' => $theme['tr_class2'],
410 'T_TR_CLASS3' => $theme['tr_class3'],
411 'T_TH_COLOR1' => '#'.$theme['th_color1'],
412 'T_TH_COLOR2' => '#'.$theme['th_color2'],
413 'T_TH_COLOR3' => '#'.$theme['th_color3'],
414 'T_TH_CLASS1' => $theme['th_class1'],
415 'T_TH_CLASS2' => $theme['th_class2'],
416 'T_TH_CLASS3' => $theme['th_class3'],
417 'T_TD_COLOR1' => '#'.$theme['td_color1'],
418 'T_TD_COLOR2' => '#'.$theme['td_color2'],
419 'T_TD_COLOR3' => '#'.$theme['td_color3'],
420 'T_TD_CLASS1' => $theme['td_class1'],
421 rizwank 1.1 'T_TD_CLASS2' => $theme['td_class2'],
422 'T_TD_CLASS3' => $theme['td_class3'],
423 'T_FONTFACE1' => $theme['fontface1'],
424 'T_FONTFACE2' => $theme['fontface2'],
425 'T_FONTFACE3' => $theme['fontface3'],
426 'T_FONTSIZE1' => $theme['fontsize1'],
427 'T_FONTSIZE2' => $theme['fontsize2'],
428 'T_FONTSIZE3' => $theme['fontsize3'],
429 'T_FONTCOLOR1' => '#'.$theme['fontcolor1'],
430 'T_FONTCOLOR2' => '#'.$theme['fontcolor2'],
431 'T_FONTCOLOR3' => '#'.$theme['fontcolor3'],
432 'T_SPAN_CLASS1' => $theme['span_class1'],
433 'T_SPAN_CLASS2' => $theme['span_class2'],
434 'T_SPAN_CLASS3' => $theme['span_class3'],
435
436 'NAV_LINKS' => $nav_links_html)
437 );
438
439 //
440 // Login box?
441 //
442 rizwank 1.1 if ( !$userdata['session_logged_in'] )
443 {
444 $template->assign_block_vars('switch_user_logged_out', array());
445 }
446 else
447 {
448 $template->assign_block_vars('switch_user_logged_in', array());
449
450 if ( !empty($userdata['user_popup_pm']) )
451 {
452 $template->assign_block_vars('switch_enable_pm_popup', array());
453 }
454 }
455
456 // Work around for "current" Apache 2 + PHP module which seems to not
457 // cope with private cache control setting
458 if (!empty($HTTP_SERVER_VARS['SERVER_SOFTWARE']) && strstr($HTTP_SERVER_VARS['SERVER_SOFTWARE'], 'Apache/2'))
459 {
460 header ('Cache-Control: no-cache, pre-check=0, post-check=0, max-age=0');
461 }
462 else
463 rizwank 1.1 {
464 header ('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
465 }
466 header ('Expires: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
467 header ('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
468
469 $template->pparse('overall_header');
470
471 ?>
|