rocksolid-light/Rocksolid_Light/common/header.php

199 lines
6.1 KiB
PHP
Raw Normal View History

2020-11-29 01:55:31 +01:00
<?php
if (basename(getcwd()) == 'mods') {
$rootdir = "../../";
2020-11-29 01:55:31 +01:00
} else {
$rootdir = "../";
2020-11-29 01:55:31 +01:00
}
include($rootdir . 'common/config.inc.php');
global $OVERRIDES;
2020-11-29 01:55:31 +01:00
$CONFIG = include $config_file;
$menulist = get_section_menu_array();
$linklist = file($config_dir . "links.conf", FILE_IGNORE_NEW_LINES);
2020-11-29 01:55:31 +01:00
echo '<meta charset="utf-8">';
// Set tzo if possible
?>
<script>
if (navigator.cookieEnabled)
document.cookie = "tzo=" + (-new Date().getTimezoneOffset()) + "; path=/";
var tzid = new Intl.DateTimeFormat().resolvedOptions().timeZone;
document.cookie = "tzid=" + tzid + "; path=/";
</script>
<?php
if (isset($_COOKIE['mail_name']) && isset($_COOKIE['pkey'])) {
$user = strtolower($_COOKIE['mail_name']);
if (! isset($_SESSION['theme']) && file_exists($config_dir . '/userconfig/' . $user . '.config')) {
$user_config = unserialize(file_get_contents($config_dir . '/userconfig/' . $user . '.config'));
$_SESSION['theme'] = $user_config['theme'];
}
2022-01-26 03:55:40 +01:00
} else {
unset($user);
2022-01-26 03:55:40 +01:00
}
// Get theme
$default_theme = "Default Theme";
if (isset($_SESSION['theme'])) {
$do_theme = preg_replace("/ /", "%20", $_SESSION['theme']);
2020-11-29 01:55:31 +01:00
} else {
$do_theme = preg_replace("/ /", "%20", $default_theme);
2020-11-29 01:55:31 +01:00
}
echo '<link rel="stylesheet" type="text/css" href="' . $rootdir . '/common/themes/' . $do_theme . '/style.css">';
2024-11-03 14:50:39 +01:00
echo '<link rel="icon" type="image/x-icon" href="/common/images/favicon.ico">';
if ((isset($_SESSION['theme'])) && file_exists($rootdir . '/common/themes/' . $do_theme . '/images/rocksolidlight.png')) {
$header_image = $rootdir . '/common/themes/' . $do_theme . '/images/rocksolidlight.png';
2020-11-29 01:55:31 +01:00
} else {
$header_image = $rootdir . 'common/images/rocksolidlight.png';
2020-11-29 01:55:31 +01:00
}
echo '</head><body>';
echo '<table class="np_header_table_top">';
echo '<tr class="np_header_bar_top">';
echo '<td class="np_td_header_bar_logo_image"><a href="' . $CONFIG['default_content'] . '">';
echo '<img src="' . $header_image . '" alt="Rocksolid Light"';
echo ' class="responsive_image"></a></td>';
echo '<td class="header_page_title_top">';
echo $CONFIG['rslight_title'];
echo '</td>';
echo '<td class="header_links_text">';
if (isset($user) && $user && check_unread_mail() == true) {
$unread = true;
} else {
$unread = false;
}
foreach ($linklist as $link) {
if ($link[0] == '#') {
continue;
}
$linkitem = explode(':', $link, 2);
if ($linkitem[1] == '0') {
continue;
}
if ($unread && (strpos($linkitem[1], 'spoolnews/mail.php') !== false)) {
echo '<strong>';
echo '<a class="np_header_links" href="' . trim($linkitem[1]) . '">' . trim(strtoupper($linkitem[0])) . '</a>&nbsp;&nbsp;';
echo '</strong>';
} else {
echo '<a class="np_header_links" href="' . trim($linkitem[1]) . '">' . trim($linkitem[0]) . '</a>&nbsp;&nbsp;';
}
}
echo '<a class="np_header_links" href="../spoolnews/user.php">';
if (isset($user)) {
echo '(' . $_COOKIE['mail_name'] . ')';
} else {
echo 'login';
}
echo '</a>';
2024-02-26 14:02:08 +01:00
echo '</td></tr>';
echo '</table>';
2020-11-29 01:55:31 +01:00
include($config_dir . '/fortunes.conf');
2020-11-29 01:55:31 +01:00
// If $config_dir/motd.txt is not blank, show it
if (file_exists($config_dir . '/motd.txt')) {
$motd = file_get_contents($config_dir . '/motd.txt');
2020-11-29 01:55:31 +01:00
}
// If specific <section>-motd.txt exists, use it
if (file_exists($config_dir . '/' . $config_name . '-motd.txt')) {
$motd = file_get_contents($config_dir . '/' . $config_name . '-motd.txt');
}
echo '<table class="np_header_button_bar"><tr>';
foreach ($menulist as $menu) {
$menuitem = explode(':', $menu);
if ($menuitem[1] == '0') {
continue;
2020-11-29 01:55:31 +01:00
}
if (! isset($frame['menu'])) {
2023-05-15 04:41:08 +02:00
$frame['menu'] = null;
}
2020-11-29 01:55:31 +01:00
echo '<td>';
echo '<form target="' . $frame['menu'] . '" action="' . $rootdir . $menuitem[0] . '">';
echo '<button class="np_header_button_link" type="submit">' . $menuitem[0] . '</button>';
2020-11-29 01:55:31 +01:00
echo '</form>';
echo '</td>';
}
echo '</tr></table>';
2024-02-26 14:02:08 +01:00
$config_name = basename(getcwd());
if (!isset($OVERRIDES['disable_msgid_search']) || $OVERRIDES['disable_msgid_search'] == false) {
if ($config_name != "common" && $config_name != 'spoolnews') {
echo '<form name="form1" method="get" action="article-flat.php">';
echo '<table class="header_message_id_search">';
echo '<tr>';
echo '<td class="header_message_id_search_prompt">Message-ID: ';
echo '<input name="id" type="text" id="id" size="40" maxlength="120">&nbsp;';
2024-10-28 16:34:09 +01:00
echo '<input type="submit" name="Submit" value="Lookup">';
echo '</td></tr></table>';
echo '</form>';
}
2024-02-26 14:02:08 +01:00
}
// Soup...Uh, Message of the Day
if ($unread) {
$motd = '*** You have unread mail. <a href="../spoolnews/mail.php">Click Here</a> ***';
echo '<div class="np_display_motd_new_mail">';;
} else {
echo '<div class="np_display_motd">';
2020-11-29 01:55:31 +01:00
}
echo $motd;
echo '</div>';
function check_unread_mail()
{
global $CONFIG, $spooldir;
if (isset($_COOKIE['mail_name'])) {
$name = strtolower($_COOKIE['mail_name']);
$database = $spooldir . '/mail.db3';
if (is_file($database)) {
$dbh = head_mail_db_open($database);
$query = $dbh->prepare('SELECT * FROM messages where rcpt_to=:rcpt_to');
$query->execute([
'rcpt_to' => $name
]);
$newmail = false;
while (($row = $query->fetch()) !== false) {
if (($row['rcpt_viewed'] != 'true') && ($row['to_hide'] != 'true')) {
$newmail = true;
}
}
$dbh = null;
return $newmail;
} else {
return false;
}
}
}
function head_mail_db_open($database, $table = 'messages')
{
try {
$dbh = new PDO('sqlite:' . $database);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
exit();
}
$dbh->exec("CREATE TABLE IF NOT EXISTS messages(
id INTEGER PRIMARY KEY,
msgid TEXT UNIQUE,
mail_from TEXT,
mail_viewed TEXT,
rcpt_to TEXT,
rcpt_viewed TEXT,
rcpt_target TEXT,
date TEXT,
subject TEXT,
message TEXT,
from_hide TEXT,
to_hide TEXT)");
return ($dbh);
}