= 0) {
$imageformat = strtolower(read_config_option("weathermap_output_format"));
$userid = (isset($_SESSION["sess_user_id"])
? intval($_SESSION["sess_user_id"]) : 1);
$map =
db_fetch_assoc(
"select weathermap_maps.* from weathermap_auth,weathermap_maps where weathermap_maps.id=weathermap_auth.mapid and active='on' and (userid="
. $userid . " or userid=0) and weathermap_maps.id=" . $id);
if (sizeof($map)) {
$imagefile =
dirname(__FILE__) . '/output/' . '/' . $map[0]['filehash'] . "."
. $imageformat;
if ($action == 'viewthumb')
$imagefile =
dirname(__FILE__) . '/output/' . $map[0]['filehash'] . ".thumb."
. $imageformat;
$orig_cwd = getcwd();
chdir(dirname(__FILE__));
header('Content-type: image/png');
// readfile_chunked($imagefile);
readfile($imagefile);
dir($orig_cwd);
} else {
// no permission to view this map
}
}
break;
case 'viewmapcycle':
include_once($config["base_path"] . "/include/top_graph_header.php");
print
"
\n";
print
" \n";
weathermap_fullview(true);
weathermap_versionbox();
include_once($config["base_path"] . "/include/bottom_footer.php");
break;
case 'viewmap':
include_once($config["base_path"] . "/include/top_graph_header.php");
print
"\n";
print
" \n";
$id = -1;
if (isset($_REQUEST['id'])
&& (!is_numeric($_REQUEST['id']) || strlen($_REQUEST['id']) == 20)) {
$id = weathermap_translate_id($_REQUEST['id']);
}
if (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) {
$id = intval($_REQUEST['id']);
}
if ($id >= 0) {
weathermap_singleview($id);
}
weathermap_versionbox();
include_once($config["base_path"] . "/include/bottom_footer.php");
break;
default:
include_once($config["base_path"] . "/include/top_graph_header.php");
print
"\n";
print
" \n";
$group_id = -1;
if (isset($_REQUEST['group_id']) && (is_numeric($_REQUEST['group_id']))) {
$group_id = intval($_REQUEST['group_id']);
$_SESSION['wm_last_group'] = $group_id;
} else {
if (isset($_SESSION['wm_last_group'])) {
$group_id = intval($_SESSION['wm_last_group']);
}
}
$tabs = weathermap_get_valid_tabs();
$tab_ids = array_keys($tabs);
if (($group_id == -1) && (sizeof($tab_ids) > 0)) {
$group_id = $tab_ids[0];
}
if (read_config_option("weathermap_pagestyle") == 0) {
weathermap_thumbview($group_id);
}
if (read_config_option("weathermap_pagestyle") == 1) {
weathermap_fullview(false, false, $group_id);
}
if (read_config_option("weathermap_pagestyle") == 2) {
weathermap_fullview(false, true, $group_id);
}
weathermap_versionbox();
include_once($config["base_path"] . "/include/bottom_footer.php");
break;
}
function weathermap_cycleview() { }
function weathermap_singleview($mapid)
{
global $colors;
$is_wm_admin = false;
$outdir = dirname(__FILE__) . '/output/';
$confdir = dirname(__FILE__) . '/configs/';
$userid = (isset($_SESSION["sess_user_id"]) ? intval($_SESSION["sess_user_id"]) : 1);
$map =
db_fetch_assoc(
"select weathermap_maps.* from weathermap_auth,weathermap_maps where weathermap_maps.id=weathermap_auth.mapid and active='on' and (userid="
. $userid . " or userid=0) and weathermap_maps.id=" . $mapid);
if (sizeof($map)) {
# print do_hook_function ('weathermap_page_top', array($map[0]['id'], $map[0]['titlecache']) );
print do_hook_function('weathermap_page_top', '');
$htmlfile = $outdir . $map[0]['filehash'] . ".html";
$maptitle = $map[0]['titlecache'];
if ($maptitle == '')
$maptitle = "Map for config file: " . $map[0]['configfile'];
weathermap_mapselector($mapid);
html_graph_start_box(1, true);
?>
">|
|
";
if (file_exists($htmlfile)) {
include($htmlfile);
} else {
print
" This map hasn't been created yet.";
global $config, $user_auth_realms, $user_auth_realm_filenames;
$realm_id2 = 0;
if (isset($user_auth_realm_filenames[basename(
'weathermap-cacti-plugin.php')])) {
$realm_id2 = $user_auth_realm_filenames[basename(
'weathermap-cacti-plugin.php')];
}
$userid = (isset($_SESSION["sess_user_id"])
? intval($_SESSION["sess_user_id"]) : 1);
if ((db_fetch_assoc("select user_auth_realm.realm_id from user_auth_realm where user_auth_realm.us
er_id='" . $userid . "' and user_auth_realm.realm_id='$realm_id2'"))
|| (empty($realm_id2))) {
print
" (If this message stays here for more than one poller cycle, then check your cacti.log file for errors!)";
}
print " ";
}
print " | ";
html_graph_end_box();
}
}
function weathermap_show_manage_tab()
{
global $config, $user_auth_realms, $user_auth_realm_filenames;
$realm_id2 = 0;
if (isset($user_auth_realm_filenames['weathermap-cacti-plugin-mgmt.php'])) {
$realm_id2 = $user_auth_realm_filenames['weathermap-cacti-plugin-mgmt.php'];
}
$userid = (isset($_SESSION["sess_user_id"]) ? intval($_SESSION["sess_user_id"]) : 1);
if ((db_fetch_assoc(
"select user_auth_realm.realm_id from user_auth_realm where user_auth_realm.user_id='"
. $userid . "' and user_auth_realm.realm_id='$realm_id2'"))
|| (empty($realm_id2))) {
print 'Manage Maps';
}
}
function weathermap_thumbview($limit_to_group = -1)
{
global $colors;
$userid = (isset($_SESSION["sess_user_id"]) ? intval($_SESSION["sess_user_id"]) : 1);
$maplist_SQL =
"select distinct weathermap_maps.* from weathermap_auth,weathermap_maps where weathermap_maps.id=weathermap_auth.mapid and active='on' and ";
if ($limit_to_group > 0)
$maplist_SQL .= " weathermap_maps.group_id=" . $limit_to_group . " and ";
$maplist_SQL .= " (userid=" . $userid . " or userid=0) order by sortorder, id";
$maplist = db_fetch_assoc($maplist_SQL);
// if there's only one map, ignore the thumbnail setting and show it fullsize
if (sizeof($maplist) == 1) {
$pagetitle = "Network Weathermap";
weathermap_fullview(false, false, $limit_to_group);
} else {
$pagetitle = "Network Weathermaps";
html_graph_start_box(2, true);
?>
">
|
|
| Click on thumbnails for a full view (or you can
automatically cycle between full-size
maps) |
0) {
$outdir = dirname(__FILE__) . '/output/';
$confdir = dirname(__FILE__) . '/configs/';
$imageformat = strtolower(read_config_option("weathermap_output_format"));
html_graph_start_box(1, false);
print "";
foreach ($maplist as $map) {
$i++;
$imgsize = "";
# $thumbfile = $outdir."weathermap_thumb_".$map['id'].".".$imageformat;
# $thumburl = "output/weathermap_thumb_".$map['id'].".".$imageformat."?time=".time();
$thumbfile = $outdir . $map['filehash'] . ".thumb." . $imageformat;
$thumburl =
"?action=viewthumb&id=" . $map['filehash'] . "&time=" . time();
if ($map['thumb_width'] > 0) {
$imgsize = ' WIDTH="' . $map['thumb_width'] . '" HEIGHT="'
. $map['thumb_height'] . '" ';
}
$maptitle = $map['titlecache'];
if ($maptitle == '')
$maptitle = "Map for config file: " . $map['configfile'];
print
'';
if (file_exists($thumbfile)) {
print
' '
. $maptitle
. ' ![' . $maptitle
. ' ' . $maptitle
. ']() ';
} else {
print "(thumbnail for map not created yet)";
}
print ' ';
}
print " |
";
html_graph_end_box();
} else {
print
"You Have No Maps
\n";
}
}
}
function weathermap_fullview($cycle = false, $firstonly = false, $limit_to_group = -1)
{
global $colors;
$_SESSION['custom'] = false;
$userid = (isset($_SESSION["sess_user_id"]) ? intval($_SESSION["sess_user_id"]) : 1);
# $query = "select distinct weathermap_maps.* from weathermap_auth,weathermap_maps where weathermap_maps.id=weathermap_auth.mapid and active='on' and (userid=".$userid." or userid=0) order by sortorder, id";
$maplist_SQL =
"select distinct weathermap_maps.* from weathermap_auth,weathermap_maps where weathermap_maps.id=weathermap_auth.mapid and active='on' and ";
if ($limit_to_group > 0) {
$maplist_SQL .= " weathermap_maps.group_id=" . $limit_to_group . " and ";
}
$maplist_SQL .= " (userid=" . $userid . " or userid=0) order by sortorder, id";
if ($firstonly) {
$maplist_SQL .= " LIMIT 1";
}
$maplist = db_fetch_assoc($maplist_SQL);
html_graph_start_box(2, true);
if (sizeof($maplist) == 1) {
$pagetitle = "Network Weathermap";
} else {
$pagetitle = "Network Weathermaps";
}
?>
">
|
|
0) {
$outdir = dirname(__FILE__) . '/output/';
$confdir = dirname(__FILE__) . '/configs/';
foreach ($maplist as $map) {
$i++;
$htmlfile = $outdir . $map['filehash'] . ".html";
$maptitle = $map['titlecache'];
if ($maptitle == '')
$maptitle = "Map for config file: " . $map['configfile'];
print '';
html_graph_start_box(1, true);
print '
';
?>
|
|
|
This map hasn't been created yet.";
}
print ' |
';
html_graph_end_box();
print '
';
}
if ($cycle) {
$refreshtime = read_config_option("weathermap_cycle_refresh");
// OK, so the Cycle plugin does all this with a tag at the bottom of the body
// that overrides the one at the top (that Cacti puts there). Unfortunately, that
// isn't valid HTML! So here's a Javascript driven way to do it
// It has the advantage that the image switching is cleaner, too.
// We also do a nice thing of taking the poller-period (5 mins), and the
// available maps, and making sure each one gets equal time in the 5 minute period.
?>
You Have No Maps\n";
}
}
function weathermap_translate_id($idname)
{
$SQL = "select id from weathermap_maps where configfile='"
. mysql_real_escape_string($idname) . "' or filehash='"
. mysql_real_escape_string($idname) . "'";
$map = db_fetch_assoc($SQL);
return ($map[0]['id']);
}
function weathermap_versionbox()
{
global $WEATHERMAP_VERSION, $colors;
global $config, $user_auth_realms, $user_auth_realm_filenames;
$pagefoot =
"Powered by PHP Weathermap version $WEATHERMAP_VERSION";
$realm_id2 = 0;
if (isset($user_auth_realm_filenames['weathermap-cacti-plugin-mgmt.php'])) {
$realm_id2 = $user_auth_realm_filenames['weathermap-cacti-plugin-mgmt.php'];
}
$userid = (isset($_SESSION["sess_user_id"]) ? intval($_SESSION["sess_user_id"]) : 1);
if ((db_fetch_assoc(
"select user_auth_realm.realm_id from user_auth_realm where user_auth_realm.user_id='"
. $userid . "' and user_auth_realm.realm_id='$realm_id2'"))
|| (empty($realm_id2))) {
$pagefoot
.= " --- Weathermap Management";
$pagefoot .= " | Local Documentation";
$pagefoot .= " | Editor";
}
html_graph_start_box(1, true);
?>
">
|
|
';
html_start_box(
"Local Documentation -- Weathermap Website -- Weathermap Editor -- This is version $WEATHERMAP_VERSION",
"78%", $colors["header"], "2", "center", "");
html_end_box();
}
function weathermap_mapselector($current_id = 0)
{
global $colors;
$show_selector = intval(read_config_option("weathermap_map_selector"));
if ($show_selector == 0)
return false;
$userid = (isset($_SESSION["sess_user_id"]) ? intval($_SESSION["sess_user_id"]) : 1);
$maps =
db_fetch_assoc(
"select distinct weathermap_maps.*,weathermap_groups.name, weathermap_groups.sortorder as gsort from weathermap_groups,weathermap_auth,weathermap_maps where weathermap_maps.group_id=weathermap_groups.id and weathermap_maps.id=weathermap_auth.mapid and active='on' and (userid="
. $userid . " or userid=0) order by gsort, sortorder");
if (sizeof($maps) > 1) {
/* include graph view filter selector */
html_graph_start_box(3, true);
?>
" class = "noprint">
1) {
/* draw the categories tabs on the top of the page */
print
"\n";
if (sizeof($tabs) > 0) {
$show_all = intval(read_config_option("weathermap_all_tab"));
if ($show_all == 1) {
$tabs['-2'] = "All Maps";
}
foreach (array_keys($tabs) as $tab_short_name) {
print "|
| \n
| \n";
}
}
print " | \n
\n";
return (true);
} else {
return (false);
}
}
// vim:ts=4:sw=4:
?>