Location: PHPKode > projects > Weathermap5rrd > weathermap5rrd-1.3.11/currentvalues.php
<?php
/*
 * weathermap5rrd - currentvalues.php
 * Copyright (C) 2008 Zdenek Styblik
 * 
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * Authors:
 * Zdenek Styblik ~ 2007-2008
 * Alexandre Fontelle ~ 2005-2006
 *
 */
if (isset($_GET['config']) && !empty($_GET['config']))
{
	$cfgfile = urldecode($_GET['config']);
} 
else
{
	$cfgfile = NULL;
	exit("Incorrect call to currentvalues.php. Cfg file not set.");
} /* not isset($_GET['config']) */
if (isset($_GET['link']) && !empty($_GET['link']))
{
	$linkname = urldecode($_GET['link']);
}
else
{
	exit("Incorrect call to currentvalues.php. Link variable is not defined");
} /* not isset($_GET['link'] */
if (!file_exists('lib/configfile.php') | !is_readable('lib/configfile.php'))
{
	exit("Unable to read 'config.php'. File doesn't exist or check permissions");
}
require_once('config.php');
if (!file_exists('lib/configfile.php') | !is_readable('lib/configfile.php'))
{
	exit("Unable to read 'lib/configfile.php'. File doesn't exist or check 
		permissions");
}
require_once 'lib/configfile.php';
$configfile = new config_file($cfgfile);
if ($configfile->readConfig() == false) 
	exit("Config file not found. Make sure weathermap5rrd has access to it.");
$config = $configfile->getConfig();
if (isset($config->links) && is_object($config->links))
{
	if (isset($config->links->{$linkname}))
 	{
		$link = $config->links->{$linkname};
		if (!isset($link->target))
	 	{
			exit("Link target file is missing.");
		} /* !isset($link->target) */
		if (!isset($link->targetin))
			$link->targetin = $link->target;
		if (!isset($link->targetout))
			$link->targetout = $link->target;
		if (!isset($link->inpos))
			$link->inpos = 1;
		if (!isset($link->unit))
			$link->unit = "bytes";
		if (!isset($link->outpos))
			$link->outpos = 2;
		$rrdstep = $configfile->getRRDStep();
		require_once 'lib/rrd.php';
		$rrd = new rrdtools();
		require_once 'lib/graphic.php';
		$graphic = new graphic();
		if (($in = $rrd->rrdtool_get_last_value($link->targetin, $link->inpos, $rrdstep)) == false)
			exit("Error in RRD #1;");
		$indisplay = $graphic->toDisplay($in);
		if (($out = $rrd->rrdtool_get_last_value($link->targetout, $link->outpos, $rrdstep)) == false)
			exit("Error in RRD #2;");
		$outdisplay = $graphic->toDisplay($out);
		echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
		echo '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">';
		echo "\n\t<head>";
		echo "\n\t\t<title>current values</title>";
		echo "\n\t</head>";
		echo "\n\t<body>\n";
		echo "\t\t\t<p>Input : {$indisplay}";
		echo "\n\t\t<br />";
		echo "\n\t\t<br />";
		echo "\n\t\tOutput : {$outdisplay}</p>";
		echo "\n\t</body>";
		echo "\n</html>";
	}
	else
 	{
		exit("Link '{$linkname}' doesn't exist.");
	} /* not $config->links->{$linkname} */
}
else
{
	exit("No links were defined.");
} /* not $config->links */
?>
Return current item: Weathermap5rrd