<?php
#
# Copyright (C) 2008 Red Hat, Inc.
# Author: Andreas Thienemann <athienem@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as published by
# the Free Software Foundation; version 2 only
#
# 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 Library General Public License for more details.
#
# You should have received a copy of the GNU Library 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.
# Copyright 2004, 2005 Red Hat, Inc.
#
# AUTHOR: Andreas Thienemann <athienem@redhat.com>
#

// HTML Header
function html_header($title = '', $calendar = False, $refresh = False) {

	$js = '';
	$refresh = '';

	if ($calendar == True) {
		$js .= '<script language="JavaScript" src="js/cal/calendar.js"></script>';
	}

	if ($refresh !== False) {
		$refresh = '<meta http-equiv="refresh" content="300" />';
	}


	$head = '<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
          "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
  <link rel="stylesheet" href="styles.css" type="text/css" /> 
  '.$refresh.'
  <title>'.$title.'</title>
  '.$js.'
  <meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" />
</head>
<body>
';

	return $head;
}

// HTML Footer
function html_footer() {
        global $prog_name, $prog_url, $prog_vers, $date_fmt_str;
	$foot = '<p><i>This page was generated by <a href="'.$prog_url.'">'.$prog_name.'</a> version '.$prog_vers.' at '.strftime($date_fmt_str).'</i></p>
</body>
</html>
';
	return $foot;
}

// The Top-Bar
function page_header($title = '') {
	$head = '<table class="head" width="100%">
   <tr class="whiteonblack">
    <td class="whiteonblack" width="33%" id="left"> <a href="'.$_SERVER['SCRIPT_NAME'].'"><img src="img/net-icon.png" width="48" height="48" alt="Back Home" border="0"></a></td>
    <td class="whiteonblack" width="33%" id="middle">'.$title.'</td>
    <td class="whiteonblack" width="33%" id="right">&nbsp;</td>
   </tr>

   <tr class="brownondarkbrown">
    <td align="left" class="brownondarkbrown">
     &nbsp;
    </td>
    <td align="center">
     Bugs? Errors? <a class="logintext" href="mailto:andreas@bawue.net">andreas@bawue.net</a>. This is beta&trade; after all.
    </td>
    <td align="right" class="brownondarkbrown">
     &nbsp;
    </td>

   </tr>
  </table>
';

	return $head;
}

function chartstyle_header() {

	global $chart_styles;

	if (@$_REQUEST['nslookup'] == 'on') {
		$nslookup = 'checked="checked"';
	} else {
		$nslookup = False;
	}
	if (@$_REQUEST['rolling'] == 'on') {
		$rolling = 'checked="checked"';
	} else {
		$rolling = False;
	}

	$output = '<div style="margin: 30px auto 30px auto; width: 850px; text-align: left;"><form action='.$_SERVER['SCRIPT_NAME'].'>
	<table>
	 <tr>
	  <td>Start Date: <input type="text" name="startdate" value="'.$_REQUEST['startdate'].'" size="10" /></td>
	  <td>Start Time: <input type="text" name="starttime" value="'.$_REQUEST['starttime'].'" size="5" /></td>
	  <td>End Date: <input type="text" name="enddate" value="'.$_REQUEST['enddate'].'" size="10" /></td>
	  <td>End Time: <input type="text" name="endtime" value="'.$_REQUEST['endtime'].'" size="5" /></td>
	  <td>Chart Style: <select name="style" size=1>';

                foreach ($chart_styles as $style=>$file) {
			if (@$_REQUEST['style'] == $style) {
	                        $output .= '<option selected="selected">'.$style.'</option>'."\n";
			} else {
	                        $output .= '<option>'.$style.'</option>'."\n";
			}
                }

	$output .= ' </select><td>Nslookup: <input type="checkbox" name="nslookup" '.$nslookup.'/><td>
	   </select><td>Rolling chart: <input type="checkbox" name="rolling" '.$rolling.'/><td>
	  <td><input type="hidden" name="probe" value="'.$_REQUEST['probe'].'" /><input type="hidden" name="action" value="chart" /><input type="submit" value="Chart!" /></td>
	 </tr>
	</table>
	</form></div>';

// <tr><td><input type="hidden" name="probe" value="'.$_REQUEST['probe'].'" /><select name="timeframe"><option $

	return $output;
}
