<?php
/*
* topnbottom.php - three functions: the top, the bottom, and the status bar
* Monocle Radio
* Copyright (C) 2005 Kurt Gallagher (hide@address.com)
* http://proteankungfu.com/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* ==================================================
* ===============Page display functions=============
* ==================================================
*/
/*
* topofpage() - standard stuff at the top of a page
*/
function topofpage($title=false) {
global $page,$APP_ROOT,$cfg,$perms;
if($title) {
$title = $title.' - ';
}
//The playlist needs to auto-refresh
if($page=='playlist') {
$refresh = '<meta http-equiv="refresh" content="60;." />';
} else {
$refresh = '';
}
$status = display_connect_status();
if($_SESSION['user']) {
$ubox = "You are {$_SESSION['user']}. <a href=\"$APP_ROOT/logout/\">Logout</a>";
} else {
$ubox = "You are a guest. <a href=\"$APP_ROOT/login/\">Login</a>";
}
if($perms>0) $caption = 'Add Songs';
else $caption = 'Database';
echo <<<EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>{$title}Monocle Radio Control</title>
<link rel="stylesheet" type="text/css" media="all" href="style.css" />
$refresh
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
var checked = false;
function check(field) {
if(checked) {
for(i=0;i<field.length;i++)
field[i].checked = false;
checked = false;
} else {
for(i=0;i<field.length;i++)
field[i].checked = true;
checked = true;
}
}
</script>
</head>
<body>
<div id="container">
<div id="title">
Monocle Radio Control
</div>
<div class="status_bar">
$status
</div>
<div class="status_bar" style="text-align:center">
<a href="$APP_ROOT/playlist/" title="Playlist" accesskey="P">Playlist</a> ::
<a href="$APP_ROOT/database/" title="Browse Database" accesskey="D">$caption</a> ::
<a href="$APP_ROOT/search/" title="Search Database" accesskey="S">Search</a>\n
EOF;
if($cfg['mysql_enable']) {
if($perms == 2) {
echo <<<EOF
:: <a href="$APP_ROOT/users/">Manage Users</a>\n
EOF;
} elseif($perms == 1) {
echo <<<EOF
:: <a href="$APP_ROOT/users/edit/{$_SESSION['id']}/">Change password</a>\n
EOF;
}
echo <<<EOF
:: <a href="$APP_ROOT/track/">Track Users</a>\n
EOF;
}
echo <<<EOF
</div>
<div id="user_box">
$ubox
</div>
<div id="main">\n
EOF;
}
/*
* bottomofpage() - standard stuff at the bottom of a page
*/
function bottomofpage() {
global $page_start_time;
$page_end_time = microtime(true);
$total_time = $page_end_time - $page_start_time;
echo <<<EOF
</div><!--/main-->
<div id="footer">
<span>All content ©2005 Kurt Gallagher</span><br />
Page generated in $total_time seconds.
</div>
</div><!--/container-->
</body>
</html>
EOF;
}
/*
* string display_connect_status() - returns a string to be used in the connection status bar
*/
function display_connect_status() {
global $mpd,$perms,$APP_ROOT,$cfg;
if($mpd->connected) {
$string .= "<span class=\"green\">Connected</span> on {$mpd->host}:{$mpd->port} ";
} else {
$string .= "<span class=\"red\">Not Connected</span>";
}
if($cfg['using_icecast']) {
$string .= ' | ';
if($mpd->state==MPD_STATE_PLAYING || $mpd->state==MPD_STATE_PAUSED) {
$string .= "The stream is currently <span class=\"green\">LIVE</span>. ";
$string .= "<a href=\"http://{$cfg['icecast_host']}:{$cfg['icecast_port']}/{$cfg['icecast_mount']}.m3u\" title=\"Listen to the Stream\">Listen</a>";
} else {
$string .= "The stream is currently <span class=\"red\">INACTIVE</span> at this time.";
}
}
if($perms > 0) {
$string .= " | Database: ";
if($mpd->updating_db) {
$string .= "Updating...";
} else {
$string .= 'Idle. <a href="'.$APP_ROOT.'/control/updatedb/database" title="Refresh Database">Update</a>';
}
}
return $string;
}
?>