jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [weathermap-cacti-plugin.php] - Blame information for rev 56

 

Line No. Rev Author Line
11simandl<?php
2 
3$guest_account = true;
4 
5chdir('../../');
6include_once("./include/auth.php");
7include_once("./include/config.php");
8 
9// include the weathermap class so that we can get the version
10include_once(dirname(__FILE__)."/Weathermap.class.php");
11 
12$action = "";
13if (isset($_POST['action'])) {
14 $action = $_POST['action'];
15} else if (isset($_GET['action'])) {
16 $action = $_GET['action'];
17}
18 
19switch($action)
20{
21case 'viewmapcycle':
22 include_once($config["base_path"]."/include/top_graph_header.php");
23 print "<div id=\"overDiv\" style=\"position:absolute; visibility:hidden; z-index:1000;\"></div>\n";
24 print "<script type=\"text/javascript\" src=\"overlib.js\"><!-- overLIB (c) Erik Bosrup --></script> \n";
25 weathermap_fullview(TRUE);
26 weathermap_versionbox();
27 
28 include_once($config["base_path"]."/include/bottom_footer.php");
29 break;
30 
31case 'viewmap':
32 include_once($config["base_path"]."/include/top_graph_header.php");
33 print "<div id=\"overDiv\" style=\"position:absolute; visibility:hidden; z-index:1000;\"></div>\n";
34 print "<script type=\"text/javascript\" src=\"overlib.js\"><!-- overLIB (c) Erik Bosrup --></script> \n";
35 
36 if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) )
37 {
38 weathermap_singleview($_REQUEST['id']);
39 }
40 weathermap_versionbox();
41 
42 include_once($config["base_path"]."/include/bottom_footer.php");
43 break;
44default:
45 include_once($config["base_path"]."/include/top_graph_header.php");
46 print "<div id=\"overDiv\" style=\"position:absolute; visibility:hidden; z-index:1000;\"></div>\n";
47 print "<script type=\"text/javascript\" src=\"overlib.js\"><!-- overLIB (c) Erik Bosrup --></script> \n";
48 
49 if(read_config_option("weathermap_pagestyle") == 0)
50 {
51 weathermap_thumbview();
52 }
53 if(read_config_option("weathermap_pagestyle") == 1)
54 {
55 weathermap_fullview();
56 }
57 
58 weathermap_versionbox();
59 include_once($config["base_path"]."/include/bottom_footer.php");
60 break;
61}
62 
63 
64function weathermap_cycleview()
65{
66 
67}
68 
69function weathermap_singleview($mapid)
70{
71 global $colors;
72 
73 $outdir = dirname(__FILE__).'/output/';
74 $confdir = dirname(__FILE__).'/configs/';
75 
76// $map = db_fetch_assoc("select * from weathermap_maps where id=".$mapid);
77 $map = db_fetch_assoc("select weathermap_maps.* from weathermap_auth,weathermap_maps where weathermap_maps.id=weathermap_auth.mapid and active='on' and (userid=".$_SESSION["sess_user_id"]." or userid=0) and weathermap_maps.id=".$mapid);
78 
79 if(sizeof($map))
80 {
81 $htmlfile = $outdir."weathermap_".$map[0]['id'].".html";
82 $maptitle = $map[0]['titlecache'];
83 if($maptitle == '') $maptitle= "Map for config file: ".$map[0]['configfile'];
84 
85 html_graph_start_box(1,true);
86?>
87<tr bgcolor="<?php print $colors["panel"];?>">
88 <td>
89 <table width="100%" cellpadding="0" cellspacing="0">
90 <tr>
91 <td class="textHeader" nowrap><?php print $maptitle; ?></td>
92 </tr>
93 </table>
94 </td>
95</tr>
96<?php
97// print "<tr><td><h2>".$maptitle."</h2></td></tr>";
98 print "<tr><td>";
99 
100 if(file_exists($htmlfile))
101 {
102 include($htmlfile);
103 }
104 else
105 {
106 print "<div align=\"center\" style=\"padding:20px\"><em>This map hasn't been created yet.";
107 
108 global $config, $user_auth_realms, $user_auth_realm_filenames;
109 $realm_id2 = 0;
110 
111 if (isset($user_auth_realm_filenames[basename('weathermap-cacti-plugin.php')])) {
112 $realm_id2 = $user_auth_realm_filenames[basename('weathermap-cacti-plugin.php')];
113 }
114 
115 if ((db_fetch_assoc("select user_auth_realm.realm_id from user_auth_realm where user_auth_realm.us
116 er_id='" . $_SESSION["sess_user_id"] . "' and user_auth_realm.realm_id='$realm_id2'")) || (empty($realm_id2))) {
117 
118 print " (If this message stays here for more than one poller cycle, then check your cacti.log file for errors!)";
119 
120 }
121 print "</em></div>";
122 }
123 print "</td></tr>";
124 html_graph_end_box();
125 
126 }
127}
128 
129function weathermap_show_manage_tab()
130{
131 global $config, $user_auth_realms, $user_auth_realm_filenames;
132 $realm_id2 = 0;
133 
134 if (isset($user_auth_realm_filenames['weathermap-cacti-plugin-mgmt.php'])) {
135 $realm_id2 = $user_auth_realm_filenames['weathermap-cacti-plugin-mgmt.php'];
136 }
137 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))) {
138 
139 print '<a href="' . $config['url_path'] . 'plugins/weathermap/weathermap-cacti-plugin-mgmt.php">Manage Maps</a>';
140 }
141}
142 
143function weathermap_thumbview()
144{
145 global $colors;
146 
147 $maplist = db_fetch_assoc( "select distinct weathermap_maps.* from weathermap_auth,weathermap_maps where weathermap_maps.id=weathermap_auth.mapid and active='on' and (userid=".$_SESSION["sess_user_id"]." or userid=0) order by sortorder, id");
148 
149 
150 if(sizeof($maplist) == 1)
151 {
152 $pagetitle = "Network Weathermap";
153 weathermap_fullview();
154 }
155 else
156 {
157 $pagetitle = "Network Weathermaps";
158 
159 html_graph_start_box(2,true);
160?>
161<tr bgcolor="<?php print $colors["panel"];?>">
162 <td>
163 <table width="100%" cellpadding="0" cellspacing="0">
164 <tr>
165 <td class="textHeader" nowrap> <?php print $pagetitle; ?></td>
166 <td align="right"> <a href="?action=viewmapcycle">automatically cycle</a> between full-size maps) </td>
167 </tr>
168 </table>
169 </td>
170</tr>
171<tr>
172<td><i>Click on thumbnails for a full view (or you can <a href="?action=viewmapcycle">automatically cycle</a> between full-size maps)</i></td>
173</tr>
174<?php
175 html_graph_end_box();
176 
177 $i = 0;
178 if (sizeof($maplist) > 0)
179 {
180 
181 $outdir = dirname(__FILE__).'/output/';
182 $confdir = dirname(__FILE__).'/configs/';
183 
184 $imageformat = strtolower(read_config_option("weathermap_output_format"));
185 
186 html_graph_start_box(1,true);
187 print "<tr><td>";
188 foreach ($maplist as $map) {
189 $i++;
190 
191 $thumbfile = $outdir."weathermap_thumb_".$map['id'].".".$imageformat;
192 $thumburl = "output/weathermap_thumb_".$map['id'].".".$imageformat;
193 $maptitle = $map['titlecache'];
194 if($maptitle == '') $maptitle= "Map for config file: ".$map['configfile'];
195 
196 print '<div class="wm_thumbcontainer" style="margin: 2px; border: 1px solid #bbbbbb; padding: 2px; float:left;">';
197 if(file_exists($thumbfile))
198 {
199 print '<div class="wm_thumbtitle" style="font-size: 1.2em; font-weight: bold; text-align: center">'.$maptitle.'</div><a href="weathermap-cacti-plugin.php?action=viewmap&id='.$map['id'].'"><img class="wm_thumb" src="'.$thumburl.'" alt="'.$maptitle.'" border="0" hspace="5" vspace="5" title="'.$maptitle.'"/></a>';
200 }
201 else
202 {
203 print "(thumbnail for map ".$map['id']." not created yet)";
204 }
205 print '</div> ';
206 }
207 print "</td></tr>";
208 html_graph_end_box();
209 
210 }
211 else
212 {
213 print "<div align=\"center\" style=\"padding:20px\"><em>You Have No Maps</em></div>\n";
214 }
215 }
216}
217 
218function weathermap_fullview($cycle=FALSE)
219{
220 global $colors;
221 
222 $_SESSION['custom']=false;
223 
224 $maplist = db_fetch_assoc( "select distinct weathermap_maps.* from weathermap_auth,weathermap_maps where weathermap_maps.id=weathermap_auth.mapid and active='on' and (userid=".$_SESSION["sess_user_id"]." or userid=0) order by sortorder, id");
225 html_graph_start_box(2,true);
226 
227 if(sizeof($maplist) == 1)
228 {
229 $pagetitle = "Network Weathermap";
230 }
231 else
232 {
233 $pagetitle = "Network Weathermaps";
234 }
235 
236?>
237<tr bgcolor="<?php print $colors["panel"];?>">
238 <td>
239 <table width="100%" cellpadding="0" cellspacing="0">
240 <tr>
241 <td class="textHeader" nowrap> <?php print $pagetitle; ?> </td>
242 <td align="right">
243 <?php if(! $cycle) { ?>
244 <a href="?action=viewmapcycle">automatically cycle</a> between full-size maps)
245 <?php } else { ?>
246 Cycling all available maps. <a href="?action=">Stop.</a>
247 <?php }?>
248 </td>
249 </tr>
250 </table>
251 </td>
252</tr>
253<?php
254 html_graph_end_box();
255 
256 $i = 0;
257 if (sizeof($maplist) > 0)
258 {
259 
260 $outdir = dirname(__FILE__).'/output/';
261 $confdir = dirname(__FILE__).'/configs/';
262 foreach ($maplist as $map)
263 {
264 $i++;
265 $htmlfile = $outdir."weathermap_".$map['id'].".html";
266 $maptitle = $map['titlecache'];
267 if($maptitle == '') $maptitle= "Map for config file: ".$map['configfile'];
268 
269 print '<div class="weathermapholder" id="mapholder_'.$map['id'].'">';
270 html_graph_start_box(1,true);
271?>
272 <tr bgcolor="#<?php print $colors["header_panel"];?>">
273 <td colspan="3">
274 <table width="100%" cellspacing="0" cellpadding="3" border="0">
275 <tr>
276 <td align="left" class="textHeaderDark"><a name="map_<?php echo $map['id']; ?>"></a>
277 <?php print htmlspecialchars($maptitle); ?>
278 </td>
279 </tr>
280 </table>
281 </td>
282 </tr>
283 <tr>
284 <td>
285<?php
286 
287 if(file_exists($htmlfile))
288 {
289 include($htmlfile);
290 }
291 else
292 {
293 print "<div align=\"center\" style=\"padding:20px\"><em>This map hasn't been created yet.</em></div>";
294 }
295 
296 print '</td></tr>';
297 html_graph_end_box();
298 print '</div>';
299 }
300 
301 
302 if($cycle)
303 {
304 $refreshtime = read_config_option("weathermap_cycle_refresh");
305 // OK, so the Cycle plugin does all this with a <META> tag at the bottom of the body
306 // that overrides the one at the top (that Cacti puts there). Unfortunately, that
307 // isn't valid HTML! So here's a Javascript driven way to do it
308 
309 // It has the advantage that the image switching is cleaner, too.
310 // We also do a nice thing of taking the poller-period (5 mins), and the
311 // available maps, and making sure each one gets equal time in the 5 minute period.
312?>
313 <script type="text/javascript">
314 
315 function addEvent(obj, evType, fn)
316 {
317 if (obj.addEventListener)
318 {
319 obj.addEventListener(evType, fn, false);
320 return true;
321 }
322 
323 else if (obj.attachEvent)
324 {
325 var r = obj.attachEvent("on" + evType, fn);
326 return r;
327 }
328 
329 else
330 {
331 return false;
332 }
333 }
334 
335 wm_maps = new Array;
336 wm_current = 0;
337 
338 function wm_tick()
339 {
340 document.getElementById(wm_maps[wm_current]).style.display='none';
341 wm_current++;
342 if(wm_current >= wm_maps.length) wm_current = 0;
343 document.getElementById(wm_maps[wm_current]).style.display='block';
344 
345 }
346 
347 function wm_reload()
348 {
349 window.location.reload();
350 }
351 
352 function wm_initJS()
353 {
354 var i,j;
355 var possible_maps = document.getElementsByTagName('div');
356 
357 j = 0;
358 
359 for (i = 0; i < possible_maps.length; ++i)
360 {
361 if (possible_maps[i].className == 'weathermapholder')
362 {
363 wm_maps[j] = possible_maps[i].id;
364 j++;
365 }
366 }
367 // stop here if there were no maps
368 if(j>0)
369 {
370 wm_current = 0;
371 // hide all but the first one
372 if(j>1)
373 {
374 for(i=1;i<j;i++)
375 {
376 document.getElementById(wm_maps[i]).style.display='none';
377 }
378 }
379 // figure out how long the refresh is, so that we get
380 // through all the maps in exactly 5 minutes
381 
382 var period = <?php echo $refreshtime ?> * 1000;
383 
384 if(period == 0)
385 {
386 var period = 300000/j;
387 }
388 
389 // our map-switching clock
390 setInterval(wm_tick, period);
391 // when to reload the whole page (with new map data)
392 setTimeout( wm_reload ,300000);
393 }
394 }
395 
396 
397 addEvent(window, 'load', wm_initJS);
398 
399 </script>
400<?php
401 }
402 }
403 else
404 {
405 print "<div align=\"center\" style=\"padding:20px\"><em>You Have No Maps</em></div>\n";
406 }
407 
408 
409}
410 
411function weathermap_versionbox()
412{
413 global $WEATHERMAP_VERSION, $colors;
414 ;
415 $pagefoot = "Powered by <a href=\"http://www.network-weathermap.com/?v=$WEATHERMAP_VERSION\">PHP Weathermap version $WEATHERMAP_VERSION</a>";
416 
417 html_graph_start_box(1,true);
418 
419?>
420<tr bgcolor="<?php print $colors["panel"];?>">
421 <td>
422 <table width="100%" cellpadding="0" cellspacing="0">
423 <tr>
424 <td class="textHeader" nowrap> <?php print $pagefoot; ?> </td>
425 </tr>
426 </table>
427 </td>
428</tr>
429<?php
430 html_graph_end_box();
431}
432// vim:ts=4:sw=4:
433?>

Powered by WebSVN 2.2.1