'weathermap',
		'version'       => '0.97a',
		'longname'      => 'PHP Network Weathermap',
		'author'        => 'Howard Jones',
		'homepage'      => 'http://www.network-weathermap.com/',
		'webpage'      => 'http://www.network-weathermap.com/',
		'email' 	=> 'howie@thingy.com',
		'url'           => 'http://www.network-weathermap.com/versions.php'
	);
}
function disabled_plugin_weathermap_uninstall() {
	// doesn't really do anything. Here to remind me.
	
	// not sure what it should really do.
}
function disabled_plugin_weathermap_check_config() {
	// doesn't really do anything either because it's not implemented yet in PIA. Would be handy if it was.
	
	if(!function_exists("imagecreate")) return FALSE;
	if(!function_exists("preg_match")) return FALSE;
	if(!function_exists("imagecreatetruecolor")) return FALSE;
	if(!function_exists("imagecreatefrompng")) return FALSE;
	if(!function_exists("imagepng")) return FALSE;
	if(!function_exists("imageSaveAlpha")) return FALSE;
	if(!function_exists("imagealphablending")) return FALSE;
	
//	if(!function_exists("imagecopyresampled")) return FALSE;
	
	return TRUE;
}
function disabled_plugin_weathermap_install () {
	api_plugin_register_hook('weathermap', 'config_arrays',         'weathermap_config_arrays',        'setup.php');
	api_plugin_register_hook('weathermap', 'draw_navigation_text',  'weathermap_draw_navigation_text', 'setup.php');
	api_plugin_register_hook('weathermap', 'config_settings',       'weathermap_config_settings',      'setup.php');
	api_plugin_register_hook('weathermap', 'top_header_tabs',       'weathermap_show_tab',             'setup.php');
	api_plugin_register_hook('weathermap', 'top_graph_header_tabs', 'weathermap_show_tab',             'setup.php');
	api_plugin_register_hook('weathermap', 'poller_bottom', 'weathermap_poller_bottom',             'setup.php');
	api_plugin_register_hook('weathermap', 'poller_top', 'weathermap_poller_top',             'setup.php');
	api_plugin_register_hook('weathermap', 'poller_output', 'weathermap_poller_output',             'setup.php');
	
	api_plugin_register_hook('weathermap', 'top_graph_refresh', 'weathermap_top_graph_refresh',             'setup.php');
	api_plugin_register_hook('weathermap', 'page_title', 'weathermap_page_title',             'setup.php');
	api_plugin_register_hook('weathermap', 'page_head', 'weathermap_page_head',             'setup.php');
	weathermap_setup_table ();
}
function plugin_init_weathermap() {
	global $plugin_hooks;
	$plugin_hooks['top_header_tabs']['weathermap'] = 'weathermap_show_tab';
	$plugin_hooks['top_graph_header_tabs']['weathermap'] = 'weathermap_show_tab';
	$plugin_hooks['config_arrays']['weathermap'] = 'weathermap_config_arrays';
	$plugin_hooks['draw_navigation_text']['weathermap'] = 'weathermap_draw_navigation_text';
	$plugin_hooks['config_settings']['weathermap'] = 'weathermap_config_settings';
	
	$plugin_hooks['poller_bottom']['weathermap'] = 'weathermap_poller_bottom';
	$plugin_hooks['poller_top']['weathermap'] = 'weathermap_poller_top';
	$plugin_hooks['poller_output']['weathermap'] = 'weathermap_poller_output';
	
	$plugin_hooks['top_graph_refresh']['weathermap'] = 'weathermap_top_graph_refresh';
	$plugin_hooks['page_title']['weathermap'] = 'weathermap_page_title';
	$plugin_hooks['page_head']['weathermap'] = 'weathermap_page_head';
}
// figure out if this poller run is hitting the 'cron' entry for any maps.
function weathermap_poller_top()
{
	global $weathermap_poller_start_time;
	
	$n = time();
	
	// round to the nearest minute, since that's all we need for the crontab-style stuff
	$weathermap_poller_start_time = $n - ($n%60);
}
function weathermap_page_head()
{
	global $config;
	
	// Add in a Media RSS link on the thumbnail view
	// - format isn't quite right, so it's disabled for now.
	//	if(preg_match('/plugins\/weathermap\/weathermap\-cacti\-plugin\.php/',$_SERVER['REQUEST_URI'] ,$matches))
	//	{
	//		print '';
	//	}
	if(preg_match('/plugins\/weathermap\//',$_SERVER['REQUEST_URI'] ,$matches))
    {
		print '
">
  
          
   
 
";
	
		if(file_exists($htmlfile))
		{
			include($htmlfile);
		}
		print " ";
		html_graph_end_box();
	}
}
// calculate the name that cacti will use for this item in the tree views
function weathermap_tree_item_name($item_id)
{
        $description = db_fetch_cell("select titlecache from weathermap_maps where id=".intval($item_id));
	if($description == '')
	{
        	$configfile = db_fetch_cell("select configfile from weathermap_maps where id=".intval($item_id));
 		$description = "Map for config file: ".$configfile;
	}
	
	return $description;
}
// the edit form, for when you add or edit a map in a graph tree
function weathermap_tree_item_edit($tree_item)
{
	global $colors; 
	form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],0);
	print "Map ";
	form_dropdown("item_id", db_fetch_assoc("select id,CONCAT_WS('',titlecache,' (',configfile,')') as name from weathermap_maps where active='on' order by titlecache, configfile"), "name", "id", $tree_item['item_id'], "", "0");
	print " ";
	form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],1);
	print "Style ";
	print "Thumbnail Full Size  ";
}
function weathermap_show_tab () {
	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')];
	}
	$tabstyle = intval(read_config_option("superlinks_tabstyle"));
	$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))) {
		if($tabstyle>0)
		{
			$prefix="s_";
		}
		else
		{
			$prefix="";
		}
		print '", $path_rra, $required['data_source_path']);
		$dsname = $required['data_source_name'];
		$local_data_id = $required['local_data_id'];
		
		if(isset($knownfiles[$local_data_id]))
		{
			$file2 = $knownfiles[$local_data_id];			
			if($file2 != '') $file = $file2;
		}
				
	    if($logging >= POLLER_VERBOSITY_DEBUG) cacti_log("WM poller_output: Looking for $file ($local_data_id) (".$required['data_source_path'].")\n",true,"WEATHERMAP");
		
		if( isset($rrd_update_array[$file]) && is_array($rrd_update_array[$file]) && isset($rrd_update_array[$file]['times']) && is_array($rrd_update_array[$file]['times']) && isset( $rrd_update_array{$file}['times'][key($rrd_update_array[$file]['times'])]{$dsname} ) )
		{
			$value = $rrd_update_array{$file}['times'][key($rrd_update_array[$file]['times'])]{$dsname};
			$time = key($rrd_update_array[$file]['times']);
			if (read_config_option("log_verbosity") >= POLLER_VERBOSITY_MEDIUM) 
				cacti_log("WM poller_output: Got one! $file:$dsname -> $time $value\n",true,"WEATHERMAP");
			
			$period = $time - $required['last_time'];
			$lastval = $required['last_value'];
			
			// if the new value is a NaN, we'll give 0 instead, and pretend it didn't happen from the point
			// of view of the counter etc. That way, we don't get those enormous spikes. Still doesn't deal with
			// reboots very well, but it should improve it for drops.
			if($value == 'U')
			{
				$newvalue = 0;
				$newlastvalue = $lastval;
				$newtime = $required['last_time'];
			}
			else
			{
				$newlastvalue = $value;
				$newtime = $time;
				
				switch($required['data_source_type_id'])
				{
					case 1: //GAUGE
						$newvalue = $value;
						break;
					
					case 2: //COUNTER
						if ($value >= $lastval) {
							// Everything is normal
							$newvalue = $value - $lastval;
						} else {
							// Possible overflow, see if its 32bit or 64bit
							if ($lastval > 4294967295) {
								$newvalue = (18446744073709551615 - $lastval) + $value;
							} else {
								$newvalue = (4294967295 - $lastval) + $value;
							}
						}
						$newvalue = $newvalue / $period;
						break;
					
					case 3: //DERIVE
						$newvalue = ($value-$lastval) / $period;
						break;
					
					case 4: //ABSOLUTE
						$newvalue = $value / $period;
						break;
					
					default: // do something somewhat sensible in case something odd happens
						$newvalue = $value;
						warn("poller_output found an unknown data_source_type_id for $file:$dsname");
						break;
				}
			}
			db_execute("UPDATE weathermap_data SET last_time=$newtime, last_calc='$newvalue', last_value='$newlastvalue',sequence=sequence+1  where id = " . $required['id']);
	        	if($logging >= POLLER_VERBOSITY_DEBUG) cacti_log("WM poller_output: Final value is $newvalue (was $lastval, period was $period)\n",true,"WEATHERMAP");
		}
		else
		{
			if(1==0 && $logging >= POLLER_VERBOSITY_DEBUG)
			{
			#	cacti_log("WM poller_output: ENDING\n",true,"WEATHERMAP");
				cacti_log("WM poller_output: Didn't find it.\n",true,"WEATHERMAP");
				cacti_log("WM poller_output: DID find these:\n",true,"WEATHERMAP");
				
				foreach (array_keys($rrd_update_array) as $key)
				{
					$local_data_id = $rrd_update_array[$key]["local_data_id"];
					cacti_log("WM poller_output:    $key ($local_data_id)\n",true,"WEATHERMAP");
				}			
			}
		}
	}
	if($logging >= POLLER_VERBOSITY_DEBUG) cacti_log("WM poller_output: ENDING\n",true,"WEATHERMAP");
	
	return $rrd_update_array;
}
function weathermap_poller_bottom() {
	global $config;
	global $weathermap_debugging, $WEATHERMAP_VERSION;
	include_once($config["library_path"] . DIRECTORY_SEPARATOR."database.php");
	include_once(dirname(__FILE__).DIRECTORY_SEPARATOR."lib".DIRECTORY_SEPARATOR."poller-common.php");
	weathermap_setup_table();
	$renderperiod = read_config_option("weathermap_render_period");  
	$rendercounter = read_config_option("weathermap_render_counter");  
	$quietlogging = read_config_option("weathermap_quiet_logging");  
	if($renderperiod<0)
	{
		// manual updates only
		if($quietlogging==0) cacti_log("Weathermap $WEATHERMAP_VERSION - no updates ever",true,"WEATHERMAP");
		return;
	}
	else
	{
		// if we're due, run the render updates
		if( ( $renderperiod == 0) || ( ($rendercounter % $renderperiod) == 0) )
		{
			weathermap_run_maps(dirname(__FILE__) );
		}
		else
		{
			if($quietlogging==0) cacti_log("Weathermap $WEATHERMAP_VERSION - no update in this cycle ($rendercounter)",true,"WEATHERMAP");
		}
		# cacti_log("Weathermap counter is $rendercounter. period is $renderperiod.", true, "WEATHERMAP");
		// increment the counter
		$newcount = ($rendercounter+1)%1000;
		db_execute("replace into settings values('weathermap_render_counter',".$newcount.")");
	}
}
// vim:ts=4:sw=4:
?>
 'weathermap',
		'version'       => '0.92',
		'longname'      => 'PHP Network Weathermap',
		'author'        => 'Howard Jones',
		'homepage'      => 'http://wotsit.thingy.com/haj/cacti/php-weathermap/',
		'email' 	=> 'howie@thingy.com',
		'url'           => 'http://wotsit.thingy.com/haj/cacti/versions.php'
	);
}
function plugin_init_weathermap() {
	global $plugin_hooks;
	$plugin_hooks['top_header_tabs']['weathermap'] = 'weathermap_show_tab';
	$plugin_hooks['top_graph_header_tabs']['weathermap'] = 'weathermap_show_tab';
	$plugin_hooks['config_arrays']['weathermap'] = 'weathermap_config_arrays';
	$plugin_hooks['draw_navigation_text']['weathermap'] = 'weathermap_draw_navigation_text';
	$plugin_hooks['config_settings']['weathermap'] = 'weathermap_config_settings';
	$plugin_hooks['poller_bottom']['weathermap'] = 'weathermap_poller_bottom';
	$plugin_hooks['top_graph_refresh']['weathermap'] = 'weathermap_top_graph_refresh';
}
function weathermap_top_graph_refresh($refresh)
{
	if (basename($_SERVER["PHP_SELF"]) != "weathermap-cacti-plugin.php")
		return $refresh;
	// if we're cycling maps, then we want to handle reloads ourselves, thanks
	if($_REQUEST["action"] == 'viewmapcycle')
	{
		return(86400);
	}
	return ($refresh);
}
function weathermap_config_settings () {
	global $tabs, $settings;
	$tabs["misc"] = "Misc";
	$temp = array(
		"weathermap_header" => array(
			"friendly_name" => "Network Weathermap",
			"method" => "spacer",
		),
		"weathermap_pagestyle" => array(
			"friendly_name" => "Page style",
			"description" => "How to display multiple maps.",
			"method" => "drop_array",
			"array" => array(0 => "Thumbnail Overview", 1 => "Full Images")
		),
		"weathermap_thumbsize" => array(
			"friendly_name" => "Thumbnail Maximum Size",
			"description" => "The maximum width or height for thumbnails in thumbnail view, in pixels. Takes effect after the next poller run.",
			"method" => "textbox",
			"max_length" => 5,
		),
		"weathermap_cycle_refresh" => array(
			"friendly_name" => "Refresh Time",
			"description" => "How often to refresh the page in Cycle mode. Automatic makes all available maps fit into 5 minutes.",
			"method" => "drop_array",
			"array" => array(0 => "Automatic", 5 => "5 Seconds",
			15 => '15 Seconds',
			30 => '30 Seconds',
			60 => '1 Minute',
			120 => '2 Minutes',
			300 => '5 Minutes',
		)
	),
	"weathermap_output_format" => array(
		"friendly_name" => "Output Format",
		"description" => "What format do you prefer for the generated map images and thumbnails?",
		"method" => "drop_array",
		"array" => array('png' => "PNG (default)",
		'jpg' => "JPEG",
		'gif' => 'GIF'
	)
),
"weathermap_render_period" => array(
	"friendly_name" => "Map Rendering Interval",
	"description" => "How often do you want Weathermap to recalculate it's maps? You should not touch this unless you know what you are doing! It is mainly needed for people with non-standard polling setups.",
	"method" => "drop_array",
	"array" => array(-1 => "Never (manual updates)", 
		0 => "Every Poller Cycle (default)",
		2 => 'Every 2 Poller Cycles',
		3 => 'Every 3 Poller Cycles',
		4 => 'Every 4 Poller Cycles',
		5 => 'Every 5 Poller Cycles',
		10 => 'Every 10 Poller Cycles',
		12 => 'Every 12 Poller Cycles',
		24 => 'Every 24 Poller Cycles',
		36 => 'Every 36 Poller Cycles',
		48 => 'Every 48 Poller Cycles',
		72 => 'Every 72 Poller Cycles',
		288 => 'Every 288 Poller Cycles',
		),
	),
	"weathermap_quiet_logging" => array(
		"friendly_name" => "Quiet Logging",
		"description" => "By default, even in LOW level logging, Weathermap logs normal activity. This makes it REALLY log only errors in LOW mode.",
		"method" => "drop_array",
		"array" => array(0=>"Chatty (default)",1=>"Quiet")
		)
	);
	if (isset($settings["misc"]))
		$settings["misc"] = array_merge($settings["misc"], $temp);
	else
		$settings["misc"]=$temp;
}
function weathermap_setup_table () {
	global $config, $database_default;
	include_once($config["library_path"] . DIRECTORY_SEPARATOR . "database.php");
	$sql = "show tables from " . $database_default;
	$result = db_fetch_assoc($sql) or die (mysql_error());
	$tables = array();
	$sql = array();
	foreach($result as $index => $arr) {
		foreach ($arr as $t) {
			$tables[] = $t;
		}
	}
	$sql[] = "update weathermap_maps set sortorder=id where sortorder is null;";
	if (!in_array('weathermap_maps', $tables)) {
		$sql[] = "CREATE TABLE weathermap_maps (
			id int(11) NOT NULL auto_increment,
			sortorder int(11) NOT NULL default 0,
			active set('on','off') NOT NULL default 'on',
			configfile text NOT NULL,
			imagefile text NOT NULL,
			htmlfile text NOT NULL,
			titlecache text NOT NULL,
			PRIMARY KEY  (id)
		) TYPE=MyISAM;";
	}
	else
	{
		$colsql = "show columns from weathermap_maps from " . $database_default;
		$result = mysql_query($colsql) or die (mysql_error());
		$found = false;
		while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
			if ($row['Field'] == 'sortorder')
				$found = true;
		}
		if (!$found)
		{
			$sql[] = "alter table weathermap_maps add sortorder int(11) NOT NULL default 0 after id";
		}
	}
	if (!in_array('weathermap_auth', $tables)) {
		$sql[] = "CREATE TABLE weathermap_auth (
			userid mediumint(9) NOT NULL default '0',
			mapid int(11) NOT NULL default '0'
		) TYPE=MyISAM;";
	}
	// create the settings entries, if necessary
	$pagestyle = read_config_option("weathermap_pagestyle");
	if($pagestyle == '' or $pagestyle < 0 or $pagestyle >1)
	{
		$sql[] = "replace into settings values('weathermap_pagestyle',0)";
	}
	$cycledelay = read_config_option("weathermap_cycle_refresh");  
	if($cycledelay == '' or intval($cycledelay < 0) )
	{
		$sql[] = "replace into settings values('weathermap_cycle_refresh',0)";
	}
	$renderperiod = read_config_option("weathermap_render_period");  
	if($renderperiod == '' or intval($renderperiod < -1) )
	{
		$sql[] = "replace into settings values('weathermap_render_period',0)";
	}
	
	$quietlogging = read_config_option("weathermap_quiet_logging");  
	if($quietlogging == '' or intval($quietlogging < -1) )
	{
		$sql[] = "replace into settings values('weathermap_quiet_logging',0)";
	}
	$rendercounter = read_config_option("weathermap_render_counter");  
	if($rendercounter == '' or intval($rendercounter < 0) )
	{
		$sql[] = "replace into settings values('weathermap_render_counter',0)";
	}
	$outputformat = read_config_option("weathermap_output_format");  
	if($outputformat == '' )
	{
		$sql[] = "replace into settings values('weathermap_output_format','png')";
	}
	$tsize = read_config_option("weathermap_thumbsize");
	if($tsize == '' or $tsize < 1)
	{
		$sql[] = "replace into settings values('weathermap_thumbsize',250)";
	}
	// patch up the sortorder for any maps that don't have one.
	$sql[] = "update weathermap_maps set sortorder=id where sortorder is null or sortorder=0;";
	if (!empty($sql)) {
		for ($a = 0; $a < count($sql); $a++) {
			$result = db_execute($sql[$a]);
		}
	}
}
function weathermap_config_arrays () {
	global $user_auth_realms, $user_auth_realm_filenames, $menu;
	$user_auth_realms[42]='Configure Weathermap';
	$user_auth_realms[43]='View Weathermaps';
	$user_auth_realm_filenames['weathermap-cacti-plugin.php'] = 43;
	$user_auth_realm_filenames['weathermap-cacti-plugin-mgmt.php'] = 42;
	$menu["Management"]['plugins/weathermap/weathermap-cacti-plugin-mgmt.php'] = "Weathermaps";
}
function weathermap_show_tab () {
	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')];
	}
	if ((db_fetch_assoc("select user_auth_realm.realm_id from user_auth_realm where user_auth_realm.user_id='" . $_SESSION["sess_user_id"] . "' and user_auth_realm.realm_id='$realm_id2'")) || (empty($realm_id2))) {
		print '
         WebSVN
            - weathermap
            - Diff
               - Rev 85 and 13
            - /setup.php
       
      
	
	
	  
		weathermap Subversion Repositories:   
	
      [/ ] [setup.php ] - Diff between revs 13  and 85 
      
      
      
      
      Show entire file 
      
      Ignore whitespace 
       
      
      
      
Powered by WebSVN  2.2.1