home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 April / PCWorld_2005-04_cd.bin / akce / web / phpnuke / PHP-Nuke-7.5.exe / html / includes / page_header.php < prev    next >
PHP Script  |  2004-07-13  |  20KB  |  499 lines

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