1 | 1 | simandl | <?php |
2 | | | |
3 | | | $guest_account = true; |
4 | | | |
5 | | | chdir('../../'); |
6 | | | include_once("./include/auth.php"); |
7 | 85 | simandl | // include_once("./include/config.php"); |
8 | 1 | simandl | |
9 | | | // include the weathermap class so that we can get the version |
10 | | | include_once(dirname(__FILE__)."/Weathermap.class.php"); |
11 | | | |
12 | | | $action = ""; |
13 | | | if (isset($_POST['action'])) { |
14 | | | $action = $_POST['action']; |
15 | | | } else if (isset($_GET['action'])) { |
16 | | | $action = $_GET['action']; |
17 | | | } |
18 | | | |
19 | | | switch($action) |
20 | | | { |
21 | 85 | simandl | case 'viewthumb': // FALL THROUGH |
22 | | | case 'viewimage': |
23 | | | $id = -1; |
24 | | | |
25 | | | if( isset($_REQUEST['id']) && (!is_numeric($_REQUEST['id']) || strlen($_REQUEST['id'])==20) ) |
26 | | | { |
27 | | | $id = weathermap_translate_id($_REQUEST['id']); |
28 | | | } |
29 | | | |
30 | | | if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) ) |
31 | | | { |
32 | | | $id = intval($_REQUEST['id']); |
33 | | | } |
34 | | | |
35 | | | if($id >=0) |
36 | | | { |
37 | | | $imageformat = strtolower(read_config_option("weathermap_output_format")); |
38 | | | |
39 | | | $userid = (isset($_SESSION["sess_user_id"]) ? intval($_SESSION["sess_user_id"]) : 1); |
40 | | | $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); |
41 | | | |
42 | | | if(sizeof($map)) |
43 | | | { |
44 | | | $imagefile = dirname(__FILE__).'/output/'.'/'.$map[0]['filehash'].".".$imageformat; |
45 | | | if($action == 'viewthumb') $imagefile = dirname(__FILE__).'/output/'.$map[0]['filehash'].".thumb.".$imageformat; |
46 | | | |
47 | | | $orig_cwd = getcwd(); |
48 | | | chdir(dirname(__FILE__)); |
49 | | | |
50 | | | header('Content-type: image/png'); |
51 | | | |
52 | | | // readfile_chunked($imagefile); |
53 | | | readfile($imagefile); |
54 | | | |
55 | | | dir($orig_cwd); |
56 | | | } |
57 | | | else |
58 | | | { |
59 | | | // no permission to view this map |
60 | | | } |
61 | | | |
62 | | | } |
63 | | | |
64 | | | break; |
65 | | | |
66 | | | case 'liveviewimage': |
67 | | | $id = -1; |
68 | | | |
69 | | | if( isset($_REQUEST['id']) && (!is_numeric($_REQUEST['id']) || strlen($_REQUEST['id'])==20) ) |
70 | | | { |
71 | | | $id = weathermap_translate_id($_REQUEST['id']); |
72 | | | } |
73 | | | |
74 | | | if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) ) |
75 | | | { |
76 | | | $id = intval($_REQUEST['id']); |
77 | | | } |
78 | | | |
79 | | | if($id >=0) |
80 | | | { |
81 | | | $userid = (isset($_SESSION["sess_user_id"]) ? intval($_SESSION["sess_user_id"]) : 1); |
82 | | | $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); |
83 | | | |
84 | | | if(sizeof($map)) |
85 | | | { |
86 | | | |
87 | | | $mapfile = dirname(__FILE__).'/configs/'.'/'.$map[0]['configfile']; |
88 | | | $orig_cwd = getcwd(); |
89 | | | chdir(dirname(__FILE__)); |
90 | | | |
91 | | | header('Content-type: image/png'); |
92 | | | |
93 | | | $map = new WeatherMap; |
94 | | | $map->context = ''; |
95 | | | // $map->context = "cacti"; |
96 | | | $map->rrdtool = read_config_option("path_rrdtool"); |
97 | | | $map->ReadConfig($mapfile); |
98 | | | $map->ReadData(); |
99 | | | $map->DrawMap('','',250,TRUE,FALSE); |
100 | | | dir($orig_cwd); |
101 | | | } |
102 | | | |
103 | | | } |
104 | | | |
105 | | | break; |
106 | | | case 'liveview': |
107 | | | include_once($config["base_path"]."/include/top_graph_header.php"); |
108 | | | print "<div id=\"overDiv\" style=\"position:absolute; visibility:hidden; z-index:1000;\"></div>\n"; |
109 | | | print "<script type=\"text/javascript\" src=\"overlib.js\"><!-- overLIB (c) Erik Bosrup --></script> \n"; |
110 | | | |
111 | | | $id = -1; |
112 | | | |
113 | | | if( isset($_REQUEST['id']) && (!is_numeric($_REQUEST['id']) || strlen($_REQUEST['id'])==20) ) |
114 | | | { |
115 | | | $id = weathermap_translate_id($_REQUEST['id']); |
116 | | | } |
117 | | | |
118 | | | if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) ) |
119 | | | { |
120 | | | $id = intval($_REQUEST['id']); |
121 | | | } |
122 | | | |
123 | | | if($id >=0) |
124 | | | { |
125 | | | $userid = (isset($_SESSION["sess_user_id"]) ? intval($_SESSION["sess_user_id"]) : 1); |
126 | | | $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); |
127 | | | |
128 | | | if(sizeof($map)) |
129 | | | { |
130 | | | $maptitle = $map[0]['titlecache']; |
131 | | | |
132 | | | html_graph_start_box(1,true); |
133 | | | ?> |
134 | | | <tr bgcolor="<?php print $colors["panel"];?>"><td><table width="100%" cellpadding="0" cellspacing="0"><tr><td class="textHeader" nowrap><?php print $maptitle; ?></td></tr></table></td></tr> |
135 | | | <?php |
136 | | | print "<tr><td>"; |
137 | | | |
138 | | | # print "Generating map $id here now from ".$map[0]['configfile']; |
139 | | | |
140 | | | $confdir = dirname(__FILE__).'/configs/'; |
141 | | | // everything else in this file is inside this else |
142 | | | $mapname = $map[0]['configfile']; |
143 | | | $mapfile = $confdir.'/'.$mapname; |
144 | | | |
145 | | | $orig_cwd = getcwd(); |
146 | | | chdir(dirname(__FILE__)); |
147 | | | |
148 | | | $map = new WeatherMap; |
149 | | | // $map->context = "cacti"; |
150 | | | $map->rrdtool = read_config_option("path_rrdtool"); |
151 | | | print "<pre>"; |
152 | | | $map->ReadConfig($mapfile); |
153 | | | $map->ReadData(); |
154 | | | $map->DrawMap('null'); |
155 | | | $map->PreloadMapHTML(); |
156 | | | print "</pre>"; |
157 | | | print ""; |
158 | | | print "<img src='?action=liveviewimage&id=$id' />\n"; |
159 | | | print $map->imap->subHTML("LEGEND:"); |
160 | | | print $map->imap->subHTML("TIMESTAMP"); |
161 | | | print $map->imap->subHTML("NODE:"); |
162 | | | print $map->imap->subHTML("LINK:"); |
163 | | | chdir($orig_cwd); |
164 | | | |
165 | | | print "</td></tr>"; |
166 | | | html_graph_end_box(); |
167 | | | } |
168 | | | else |
169 | | | { |
170 | | | print "Map unavailable."; |
171 | | | } |
172 | | | } |
173 | | | else |
174 | | | { |
175 | | | print "No ID, or unknown map name."; |
176 | | | } |
177 | | | |
178 | | | |
179 | | | weathermap_versionbox(); |
180 | | | include_once($config["base_path"]."/include/bottom_footer.php"); |
181 | | | break; |
182 | | | |
183 | | | case 'mrss': |
184 | | | header('Content-type: application/rss+xml'); |
185 | | | print '<?xml version="1.0" encoding="utf-8" standalone="yes"?>'."\n"; |
186 | | | print '<rss xmlns:media="http://search.yahoo.com/mrss" version="2.0"><channel><title>My Network Weathermaps</title>'; |
187 | | | $userid = (isset($_SESSION["sess_user_id"]) ? intval($_SESSION["sess_user_id"]) : 1); |
188 | | | $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=".$userid." or userid=0) order by sortorder, id"); |
189 | | | foreach ($maplist as $map) { |
190 | | | $thumburl = "weathermap-cacti-plugin.php?action=viewthumb&id=".$map['filehash']."&time=".time(); |
191 | | | $bigurl = "weathermap-cacti-plugin.php?action=viewimage&id=".$map['filehash']."&time=".time(); |
192 | | | $linkurl = 'weathermap-cacti-plugin.php?action=viewmap&id='.$map['filehash']; |
193 | | | $maptitle = $map['titlecache']; |
194 | | | $guid = $map['filehash']; |
195 | | | if($maptitle == '') $maptitle= "Map for config file: ".$map['configfile']; |
196 | | | |
197 | | | printf('<item><title>%s</title><description>Network Weathermap named "%s"</description><link>%s</link><media:thumbnail url="%s"/><media:content url="%s"/><guid isPermaLink="false">%s%s</guid></item>', |
198 | | | $maptitle, $maptitle, $linkurl,$thumburl,$bigurl,$config['url_path'],$guid); |
199 | | | print "\n"; |
200 | | | } |
201 | | | |
202 | | | print '</channel></rss>'; |
203 | | | break; |
204 | | | |
205 | 1 | simandl | case 'viewmapcycle': |
206 | | | include_once($config["base_path"]."/include/top_graph_header.php"); |
207 | | | print "<div id=\"overDiv\" style=\"position:absolute; visibility:hidden; z-index:1000;\"></div>\n"; |
208 | | | print "<script type=\"text/javascript\" src=\"overlib.js\"><!-- overLIB (c) Erik Bosrup --></script> \n"; |
209 | | | weathermap_fullview(TRUE); |
210 | | | weathermap_versionbox(); |
211 | | | |
212 | | | include_once($config["base_path"]."/include/bottom_footer.php"); |
213 | | | break; |
214 | | | |
215 | | | case 'viewmap': |
216 | | | include_once($config["base_path"]."/include/top_graph_header.php"); |
217 | | | print "<div id=\"overDiv\" style=\"position:absolute; visibility:hidden; z-index:1000;\"></div>\n"; |
218 | | | print "<script type=\"text/javascript\" src=\"overlib.js\"><!-- overLIB (c) Erik Bosrup --></script> \n"; |
219 | | | |
220 | 85 | simandl | $id = -1; |
221 | | | |
222 | | | if( isset($_REQUEST['id']) && (!is_numeric($_REQUEST['id']) || strlen($_REQUEST['id'])==20) ) |
223 | | | { |
224 | | | $id = weathermap_translate_id($_REQUEST['id']); |
225 | | | } |
226 | | | |
227 | 1 | simandl | if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) ) |
228 | | | { |
229 | 85 | simandl | $id = intval($_REQUEST['id']); |
230 | 1 | simandl | } |
231 | 85 | simandl | |
232 | | | if($id>=0) |
233 | | | { |
234 | | | weathermap_singleview($id); |
235 | | | } |
236 | | | |
237 | 1 | simandl | weathermap_versionbox(); |
238 | | | |
239 | | | include_once($config["base_path"]."/include/bottom_footer.php"); |
240 | | | break; |
241 | | | default: |
242 | | | include_once($config["base_path"]."/include/top_graph_header.php"); |
243 | | | print "<div id=\"overDiv\" style=\"position:absolute; visibility:hidden; z-index:1000;\"></div>\n"; |
244 | | | print "<script type=\"text/javascript\" src=\"overlib.js\"><!-- overLIB (c) Erik Bosrup --></script> \n"; |
245 | | | |
246 | 85 | simandl | $group_id = -1; |
247 | | | if( isset($_REQUEST['group_id']) && (is_numeric($_REQUEST['group_id']) ) ) |
248 | | | { |
249 | | | $group_id = intval($_REQUEST['group_id']); |
250 | | | $_SESSION['wm_last_group'] = $group_id; |
251 | | | } |
252 | | | else |
253 | | | { |
254 | | | if(isset($_SESSION['wm_last_group'])) |
255 | | | { |
256 | | | $group_id = intval($_SESSION['wm_last_group']); |
257 | | | } |
258 | | | } |
259 | | | |
260 | | | $tabs = weathermap_get_valid_tabs(); |
261 | | | $tab_ids = array_keys($tabs); |
262 | | | if( ($group_id == -1) && (sizeof($tab_ids)>0)) |
263 | | | { |
264 | | | $group_id = $tab_ids[0]; |
265 | | | } |
266 | | | |
267 | 1 | simandl | if(read_config_option("weathermap_pagestyle") == 0) |
268 | | | { |
269 | 85 | simandl | weathermap_thumbview($group_id); |
270 | 1 | simandl | } |
271 | | | if(read_config_option("weathermap_pagestyle") == 1) |
272 | | | { |
273 | 85 | simandl | weathermap_fullview(FALSE,FALSE,$group_id); |
274 | 1 | simandl | } |
275 | 85 | simandl | if(read_config_option("weathermap_pagestyle") == 2) |
276 | | | { |
277 | | | weathermap_fullview(FALSE, TRUE, $group_id); |
278 | | | } |
279 | 1 | simandl | |
280 | | | weathermap_versionbox(); |
281 | | | include_once($config["base_path"]."/include/bottom_footer.php"); |
282 | | | break; |
283 | | | } |
284 | | | |
285 | | | |
286 | | | function weathermap_cycleview() |
287 | | | { |
288 | | | |
289 | | | } |
290 | | | |
291 | | | function weathermap_singleview($mapid) |
292 | | | { |
293 | | | global $colors; |
294 | | | |
295 | 85 | simandl | $is_wm_admin = false; |
296 | | | |
297 | 1 | simandl | $outdir = dirname(__FILE__).'/output/'; |
298 | | | $confdir = dirname(__FILE__).'/configs/'; |
299 | | | |
300 | 85 | simandl | $userid = (isset($_SESSION["sess_user_id"]) ? intval($_SESSION["sess_user_id"]) : 1); |
301 | | | $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); |
302 | 1 | simandl | |
303 | 85 | simandl | |
304 | 1 | simandl | if(sizeof($map)) |
305 | | | { |
306 | 85 | simandl | # print do_hook_function ('weathermap_page_top', array($map[0]['id'], $map[0]['titlecache']) ); |
307 | | | print do_hook_function ('weathermap_page_top', '' ); |
308 | | | |
309 | | | $htmlfile = $outdir.$map[0]['filehash'].".html"; |
310 | 1 | simandl | $maptitle = $map[0]['titlecache']; |
311 | | | if($maptitle == '') $maptitle= "Map for config file: ".$map[0]['configfile']; |
312 | | | |
313 | 85 | simandl | weathermap_mapselector($mapid); |
314 | | | |
315 | 1 | simandl | html_graph_start_box(1,true); |
316 | | | ?> |
317 | 85 | simandl | <tr bgcolor="<?php print $colors["panel"];?>"><td><table width="100%" cellpadding="0" cellspacing="0"><tr><td class="textHeader" nowrap><?php print $maptitle; |
318 | | | |
319 | | | if($is_wm_admin) |
320 | | | { |
321 | | | |
322 | | | print "<span style='font-size: 80%'>"; |
323 | | | print "[ <a href='weathermap-cacti-plugin-mgmt.php?action=map_settings&id=".$mapid."'>Map Settings</a> |"; |
324 | | | print "<a href='weathermap-cacti-plugin-mgmt.php?action=perms_edit&id=".$mapid."'>Map Permissions</a> |"; |
325 | | | print "<a href=''>Edit Map</a> ]"; |
326 | | | print "</span>"; |
327 | | | } |
328 | | | |
329 | | | |
330 | | | ?></td></tr></table></td></tr> |
331 | 1 | simandl | <?php |
332 | | | print "<tr><td>"; |
333 | | | |
334 | | | if(file_exists($htmlfile)) |
335 | | | { |
336 | | | include($htmlfile); |
337 | | | } |
338 | | | else |
339 | | | { |
340 | | | print "<div align=\"center\" style=\"padding:20px\"><em>This map hasn't been created yet."; |
341 | | | |
342 | | | global $config, $user_auth_realms, $user_auth_realm_filenames; |
343 | | | $realm_id2 = 0; |
344 | | | |
345 | | | if (isset($user_auth_realm_filenames[basename('weathermap-cacti-plugin.php')])) { |
346 | | | $realm_id2 = $user_auth_realm_filenames[basename('weathermap-cacti-plugin.php')]; |
347 | | | } |
348 | 85 | simandl | |
349 | | | $userid = (isset($_SESSION["sess_user_id"]) ? intval($_SESSION["sess_user_id"]) : 1); |
350 | 1 | simandl | if ((db_fetch_assoc("select user_auth_realm.realm_id from user_auth_realm where user_auth_realm.us |
351 | 85 | simandl | er_id='" . $userid . "' and user_auth_realm.realm_id='$realm_id2'")) || (empty($realm_id2))) { |
352 | 1 | simandl | |
353 | | | print " (If this message stays here for more than one poller cycle, then check your cacti.log file for errors!)"; |
354 | | | |
355 | | | } |
356 | | | print "</em></div>"; |
357 | | | } |
358 | | | print "</td></tr>"; |
359 | | | html_graph_end_box(); |
360 | | | |
361 | | | } |
362 | | | } |
363 | | | |
364 | | | function weathermap_show_manage_tab() |
365 | | | { |
366 | | | global $config, $user_auth_realms, $user_auth_realm_filenames; |
367 | | | $realm_id2 = 0; |
368 | | | |
369 | | | if (isset($user_auth_realm_filenames['weathermap-cacti-plugin-mgmt.php'])) { |
370 | | | $realm_id2 = $user_auth_realm_filenames['weathermap-cacti-plugin-mgmt.php']; |
371 | | | } |
372 | 85 | simandl | $userid = (isset($_SESSION["sess_user_id"]) ? intval($_SESSION["sess_user_id"]) : 1); |
373 | | | 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))) { |
374 | 1 | simandl | |
375 | | | print '<a href="' . $config['url_path'] . 'plugins/weathermap/weathermap-cacti-plugin-mgmt.php">Manage Maps</a>'; |
376 | | | } |
377 | | | } |
378 | | | |
379 | 85 | simandl | function weathermap_thumbview($limit_to_group = -1) |
380 | 1 | simandl | { |
381 | | | global $colors; |
382 | | | |
383 | 85 | simandl | $userid = (isset($_SESSION["sess_user_id"]) ? intval($_SESSION["sess_user_id"]) : 1); |
384 | | | $maplist_SQL = "select distinct weathermap_maps.* from weathermap_auth,weathermap_maps where weathermap_maps.id=weathermap_auth.mapid and active='on' and "; |
385 | | | if($limit_to_group >0) $maplist_SQL .= " weathermap_maps.group_id=".$limit_to_group." and "; |
386 | | | $maplist_SQL .= " (userid=".$userid." or userid=0) order by sortorder, id"; |
387 | | | |
388 | | | $maplist = db_fetch_assoc( $maplist_SQL ); |
389 | | | |
390 | | | // if there's only one map, ignore the thumbnail setting and show it fullsize |
391 | 1 | simandl | if(sizeof($maplist) == 1) |
392 | | | { |
393 | | | $pagetitle = "Network Weathermap"; |
394 | 85 | simandl | weathermap_fullview(FALSE,FALSE, $limit_to_group); |
395 | 1 | simandl | } |
396 | | | else |
397 | | | { |
398 | | | $pagetitle = "Network Weathermaps"; |
399 | | | |
400 | | | html_graph_start_box(2,true); |
401 | | | ?> |
402 | | | <tr bgcolor="<?php print $colors["panel"];?>"> |
403 | | | <td> |
404 | | | <table width="100%" cellpadding="0" cellspacing="0"> |
405 | | | <tr> |
406 | | | <td class="textHeader" nowrap> <?php print $pagetitle; ?></td> |
407 | | | <td align="right"> <a href="?action=viewmapcycle">automatically cycle</a> between full-size maps) </td> |
408 | | | </tr> |
409 | | | </table> |
410 | | | </td> |
411 | | | </tr> |
412 | | | <tr> |
413 | | | <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> |
414 | | | </tr> |
415 | | | <?php |
416 | | | html_graph_end_box(); |
417 | 85 | simandl | $showlivelinks = intval(read_config_option("weathermap_live_view")); |
418 | 1 | simandl | |
419 | 85 | simandl | weathermap_tabs($limit_to_group); |
420 | 1 | simandl | $i = 0; |
421 | | | if (sizeof($maplist) > 0) |
422 | | | { |
423 | | | |
424 | | | $outdir = dirname(__FILE__).'/output/'; |
425 | | | $confdir = dirname(__FILE__).'/configs/'; |
426 | | | |
427 | | | $imageformat = strtolower(read_config_option("weathermap_output_format")); |
428 | | | |
429 | 85 | simandl | html_graph_start_box(1,false); |
430 | | | print "<tr><td class='wm_gallery'>"; |
431 | 1 | simandl | foreach ($maplist as $map) { |
432 | | | $i++; |
433 | | | |
434 | 85 | simandl | $imgsize = ""; |
435 | | | # $thumbfile = $outdir."weathermap_thumb_".$map['id'].".".$imageformat; |
436 | | | # $thumburl = "output/weathermap_thumb_".$map['id'].".".$imageformat."?time=".time(); |
437 | | | $thumbfile = $outdir.$map['filehash'].".thumb.".$imageformat; |
438 | | | $thumburl = "?action=viewthumb&id=".$map['filehash']."&time=".time(); |
439 | | | if($map['thumb_width'] > 0) { $imgsize = ' WIDTH="'.$map['thumb_width'].'" HEIGHT="'.$map['thumb_height'].'" '; } |
440 | 1 | simandl | $maptitle = $map['titlecache']; |
441 | | | if($maptitle == '') $maptitle= "Map for config file: ".$map['configfile']; |
442 | | | |
443 | | | print '<div class="wm_thumbcontainer" style="margin: 2px; border: 1px solid #bbbbbb; padding: 2px; float:left;">'; |
444 | | | if(file_exists($thumbfile)) |
445 | | | { |
446 | 85 | simandl | 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['filehash'].'"><img class="wm_thumb" '.$imgsize.'src="'.$thumburl.'" alt="'.$maptitle.'" border="0" hspace="5" vspace="5" title="'.$maptitle.'"/></a>'; |
447 | 1 | simandl | } |
448 | | | else |
449 | | | { |
450 | 85 | simandl | print "(thumbnail for map not created yet)"; |
451 | 1 | simandl | } |
452 | 85 | simandl | if($showlivelinks==1) |
453 | | | { |
454 | | | print "<a href='?action=liveview&id=".$map['filehash']."'>(live)</a>"; |
455 | | | } |
456 | 1 | simandl | print '</div> '; |
457 | | | } |
458 | | | print "</td></tr>"; |
459 | | | html_graph_end_box(); |
460 | 85 | simandl | |
461 | 1 | simandl | } |
462 | | | else |
463 | | | { |
464 | | | print "<div align=\"center\" style=\"padding:20px\"><em>You Have No Maps</em></div>\n"; |
465 | | | } |
466 | | | } |
467 | | | } |
468 | | | |
469 | 85 | simandl | function weathermap_fullview($cycle=FALSE, $firstonly=FALSE, $limit_to_group = -1) |
470 | 1 | simandl | { |
471 | | | global $colors; |
472 | | | |
473 | | | $_SESSION['custom']=false; |
474 | | | |
475 | 85 | simandl | $userid = (isset($_SESSION["sess_user_id"]) ? intval($_SESSION["sess_user_id"]) : 1); |
476 | | | # $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"; |
477 | | | $maplist_SQL = "select distinct weathermap_maps.* from weathermap_auth,weathermap_maps where weathermap_maps.id=weathermap_auth.mapid and active='on' and "; |
478 | | | if($limit_to_group >0) $maplist_SQL .= " weathermap_maps.group_id=".$limit_to_group." and "; |
479 | | | $maplist_SQL .= " (userid=".$userid." or userid=0) order by sortorder, id"; |
480 | | | |
481 | | | if($firstonly) { $maplist_SQL .= " LIMIT 1"; } |
482 | | | |
483 | | | $maplist = db_fetch_assoc( $maplist_SQL ); |
484 | 1 | simandl | html_graph_start_box(2,true); |
485 | | | |
486 | | | if(sizeof($maplist) == 1) |
487 | | | { |
488 | | | $pagetitle = "Network Weathermap"; |
489 | | | } |
490 | | | else |
491 | | | { |
492 | | | $pagetitle = "Network Weathermaps"; |
493 | | | } |
494 | | | |
495 | | | ?> |
496 | | | <tr bgcolor="<?php print $colors["panel"];?>"> |
497 | | | <td> |
498 | | | <table width="100%" cellpadding="0" cellspacing="0"> |
499 | | | <tr> |
500 | | | <td class="textHeader" nowrap> <?php print $pagetitle; ?> </td> |
501 | | | <td align="right"> |
502 | | | <?php if(! $cycle) { ?> |
503 | | | <a href="?action=viewmapcycle">automatically cycle</a> between full-size maps) |
504 | | | <?php } else { ?> |
505 | | | Cycling all available maps. <a href="?action=">Stop.</a> |
506 | | | <?php }?> |
507 | | | </td> |
508 | | | </tr> |
509 | | | </table> |
510 | | | </td> |
511 | | | </tr> |
512 | | | <?php |
513 | | | html_graph_end_box(); |
514 | | | |
515 | 85 | simandl | weathermap_tabs($limit_to_group); |
516 | | | |
517 | 1 | simandl | $i = 0; |
518 | | | if (sizeof($maplist) > 0) |
519 | | | { |
520 | | | |
521 | | | $outdir = dirname(__FILE__).'/output/'; |
522 | | | $confdir = dirname(__FILE__).'/configs/'; |
523 | | | foreach ($maplist as $map) |
524 | | | { |
525 | | | $i++; |
526 | 85 | simandl | $htmlfile = $outdir.$map['filehash'].".html"; |
527 | 1 | simandl | $maptitle = $map['titlecache']; |
528 | | | if($maptitle == '') $maptitle= "Map for config file: ".$map['configfile']; |
529 | 85 | simandl | |
530 | | | print '<div class="weathermapholder" id="mapholder_'.$map['filehash'].'">'; |
531 | 1 | simandl | html_graph_start_box(1,true); |
532 | 85 | simandl | print '<tr bgcolor="#' . $colors["header_panel"] . '">'; |
533 | 1 | simandl | ?> |
534 | | | <td colspan="3"> |
535 | | | <table width="100%" cellspacing="0" cellpadding="3" border="0"> |
536 | | | <tr> |
537 | 85 | simandl | <td align="left" class="textHeaderDark"> |
538 | | | <a name="map_<?php echo $map['filehash']; ?>"></a> |
539 | | | <?php print htmlspecialchars($maptitle); ?> |
540 | | | </td> |
541 | 1 | simandl | </tr> |
542 | | | </table> |
543 | | | </td> |
544 | | | </tr> |
545 | 85 | simandl | <tr> |
546 | | | <td> |
547 | 1 | simandl | <?php |
548 | | | |
549 | | | if(file_exists($htmlfile)) |
550 | | | { |
551 | | | include($htmlfile); |
552 | | | } |
553 | | | else |
554 | | | { |
555 | | | print "<div align=\"center\" style=\"padding:20px\"><em>This map hasn't been created yet.</em></div>"; |
556 | | | } |
557 | | | |
558 | | | print '</td></tr>'; |
559 | | | html_graph_end_box(); |
560 | | | print '</div>'; |
561 | | | } |
562 | | | |
563 | | | |
564 | | | if($cycle) |
565 | | | { |
566 | | | $refreshtime = read_config_option("weathermap_cycle_refresh"); |
567 | | | // OK, so the Cycle plugin does all this with a <META> tag at the bottom of the body |
568 | | | // that overrides the one at the top (that Cacti puts there). Unfortunately, that |
569 | | | // isn't valid HTML! So here's a Javascript driven way to do it |
570 | | | |
571 | | | // It has the advantage that the image switching is cleaner, too. |
572 | | | // We also do a nice thing of taking the poller-period (5 mins), and the |
573 | | | // available maps, and making sure each one gets equal time in the 5 minute period. |
574 | | | ?> |
575 | | | <script type="text/javascript"> |
576 | | | |
577 | | | function addEvent(obj, evType, fn) |
578 | | | { |
579 | | | if (obj.addEventListener) |
580 | | | { |
581 | | | obj.addEventListener(evType, fn, false); |
582 | | | return true; |
583 | | | } |
584 | | | |
585 | | | else if (obj.attachEvent) |
586 | | | { |
587 | | | var r = obj.attachEvent("on" + evType, fn); |
588 | | | return r; |
589 | | | } |
590 | | | |
591 | | | else |
592 | | | { |
593 | | | return false; |
594 | | | } |
595 | | | } |
596 | | | |
597 | | | wm_maps = new Array; |
598 | | | wm_current = 0; |
599 | | | |
600 | | | function wm_tick() |
601 | | | { |
602 | | | document.getElementById(wm_maps[wm_current]).style.display='none'; |
603 | | | wm_current++; |
604 | | | if(wm_current >= wm_maps.length) wm_current = 0; |
605 | | | document.getElementById(wm_maps[wm_current]).style.display='block'; |
606 | | | |
607 | | | } |
608 | | | |
609 | | | function wm_reload() |
610 | | | { |
611 | | | window.location.reload(); |
612 | | | } |
613 | | | |
614 | | | function wm_initJS() |
615 | | | { |
616 | | | var i,j; |
617 | | | var possible_maps = document.getElementsByTagName('div'); |
618 | | | |
619 | | | j = 0; |
620 | | | |
621 | | | for (i = 0; i < possible_maps.length; ++i) |
622 | | | { |
623 | | | if (possible_maps[i].className == 'weathermapholder') |
624 | | | { |
625 | | | wm_maps[j] = possible_maps[i].id; |
626 | | | j++; |
627 | | | } |
628 | | | } |
629 | | | // stop here if there were no maps |
630 | | | if(j>0) |
631 | | | { |
632 | | | wm_current = 0; |
633 | | | // hide all but the first one |
634 | | | if(j>1) |
635 | | | { |
636 | | | for(i=1;i<j;i++) |
637 | | | { |
638 | | | document.getElementById(wm_maps[i]).style.display='none'; |
639 | | | } |
640 | | | } |
641 | | | // figure out how long the refresh is, so that we get |
642 | | | // through all the maps in exactly 5 minutes |
643 | | | |
644 | | | var period = <?php echo $refreshtime ?> * 1000; |
645 | | | |
646 | | | if(period == 0) |
647 | | | { |
648 | | | var period = 300000/j; |
649 | | | } |
650 | | | |
651 | | | // our map-switching clock |
652 | | | setInterval(wm_tick, period); |
653 | | | // when to reload the whole page (with new map data) |
654 | | | setTimeout( wm_reload ,300000); |
655 | | | } |
656 | | | } |
657 | | | |
658 | | | |
659 | | | addEvent(window, 'load', wm_initJS); |
660 | | | |
661 | | | </script> |
662 | | | <?php |
663 | | | } |
664 | | | } |
665 | | | else |
666 | | | { |
667 | | | print "<div align=\"center\" style=\"padding:20px\"><em>You Have No Maps</em></div>\n"; |
668 | | | } |
669 | | | |
670 | | | |
671 | | | } |
672 | | | |
673 | 85 | simandl | function weathermap_translate_id($idname) |
674 | | | { |
675 | | | $SQL = "select id from weathermap_maps where configfile='".mysql_real_escape_string($idname)."' or filehash='".mysql_real_escape_string($idname)."'"; |
676 | | | $map = db_fetch_assoc($SQL); |
677 | | | |
678 | | | return($map[0]['id']); |
679 | | | } |
680 | | | |
681 | 1 | simandl | function weathermap_versionbox() |
682 | | | { |
683 | | | global $WEATHERMAP_VERSION, $colors; |
684 | 85 | simandl | global $config, $user_auth_realms, $user_auth_realm_filenames; |
685 | | | |
686 | 1 | simandl | $pagefoot = "Powered by <a href=\"http://www.network-weathermap.com/?v=$WEATHERMAP_VERSION\">PHP Weathermap version $WEATHERMAP_VERSION</a>"; |
687 | 85 | simandl | |
688 | | | $realm_id2 = 0; |
689 | 1 | simandl | |
690 | 85 | simandl | if (isset($user_auth_realm_filenames['weathermap-cacti-plugin-mgmt.php'])) { |
691 | | | $realm_id2 = $user_auth_realm_filenames['weathermap-cacti-plugin-mgmt.php']; |
692 | | | } |
693 | | | $userid = (isset($_SESSION["sess_user_id"]) ? intval($_SESSION["sess_user_id"]) : 1); |
694 | | | 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))) |
695 | | | { |
696 | | | $pagefoot .= " --- <a href='weathermap-cacti-plugin-mgmt.php' title='Go to the map management page'>Weathermap Management</a>"; |
697 | | | $pagefoot .= " | <a target=\"_blank\" href=\"docs/\">Local Documentation</a>"; |
698 | | | $pagefoot .= " | <a target=\"_blank\" href=\"editor.php\">Editor</a>"; |
699 | | | } |
700 | | | |
701 | | | |
702 | 1 | simandl | html_graph_start_box(1,true); |
703 | | | |
704 | | | ?> |
705 | | | <tr bgcolor="<?php print $colors["panel"];?>"> |
706 | 85 | simandl | <td> |
707 | | | <table width="100%" cellpadding="0" cellspacing="0"> |
708 | | | <tr> |
709 | | | <td class="textHeader" nowrap> <?php print $pagefoot; ?> </td> |
710 | | | </tr> |
711 | | | </table> |
712 | | | </td> |
713 | 1 | simandl | </tr> |
714 | | | <?php |
715 | | | html_graph_end_box(); |
716 | | | } |
717 | 85 | simandl | |
718 | | | |
719 | | | function readfile_chunked($filename) { |
720 | | | $chunksize = 1*(1024*1024); // how many bytes per chunk |
721 | | | $buffer = ''; |
722 | | | $cnt =0; |
723 | | | |
724 | | | $handle = fopen($filename, 'rb'); |
725 | | | if ($handle === false) return false; |
726 | | | |
727 | | | while (!feof($handle)) { |
728 | | | $buffer = fread($handle, $chunksize); |
729 | | | echo $buffer; |
730 | | | } |
731 | | | $status = fclose($handle); |
732 | | | return $status; |
733 | | | } |
734 | | | |
735 | | | function weathermap_footer_links() |
736 | | | { |
737 | | | global $colors; |
738 | | | global $WEATHERMAP_VERSION; |
739 | | | print '<br />'; |
740 | | | html_start_box("<center><a target=\"_blank\" class=\"linkOverDark\" href=\"docs/\">Local Documentation</a> -- <a target=\"_blank\" class=\"linkOverDark\" href=\"http://www.network-weathermap.com/\">Weathermap Website</a> -- <a target=\"_target\" class=\"linkOverDark\" href=\"weathermap-cacti-plugin-editor.php?plug=1\">Weathermap Editor</a> -- This is version $WEATHERMAP_VERSION</center>", "78%", $colors["header"], "2", "center", ""); |
741 | | | html_end_box(); |
742 | | | } |
743 | | | |
744 | | | function weathermap_mapselector($current_id = 0) |
745 | | | { |
746 | | | global $colors; |
747 | | | |
748 | | | $show_selector = intval(read_config_option("weathermap_map_selector")); |
749 | | | |
750 | | | if($show_selector == 0) return false; |
751 | | | |
752 | | | $userid = (isset($_SESSION["sess_user_id"]) ? intval($_SESSION["sess_user_id"]) : 1); |
753 | | | $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"); |
754 | | | |
755 | | | if(sizeof($maps)>1) |
756 | | | { |
757 | | | |
758 | | | /* include graph view filter selector */ |
759 | | | html_graph_start_box(3, TRUE); |
760 | | | ?> |
761 | | | <tr bgcolor="<?php print $colors["panel"];?>" class="noprint"> |
762 | | | <form name="weathermap_select" method="post" action=""> |
763 | | | <input name="action" value="viewmap" type="hidden"> |
764 | | | <td class="noprint"> |
765 | | | <table width="100%" cellpadding="0" cellspacing="0"> |
766 | | | <tr class="noprint"> |
767 | | | <td nowrap style='white-space: nowrap;' width="40"> |
768 | | | <strong>Jump To Map:</strong> |
769 | | | </td> |
770 | | | <td> |
771 | | | <select name="id"> |
772 | | | <?php |
773 | | | |
774 | | | $ngroups = 0; |
775 | | | $lastgroup = "------lasdjflkjsdlfkjlksdjflksjdflkjsldjlkjsd"; |
776 | | | foreach ($maps as $map) |
777 | | | { |
778 | | | if($current_id == $map['id']) $nullhash = $map['filehash']; |
779 | | | if($map['name'] != $lastgroup) |
780 | | | { |
781 | | | $ngroups++; |
782 | | | $lastgroup = $map['name']; |
783 | | | } |
784 | | | } |
785 | | | |
786 | | | |
787 | | | $lastgroup = "------lasdjflkjsdlfkjlksdjflksjdflkjsldjlkjsd"; |
788 | | | foreach ($maps as $map) |
789 | | | { |
790 | | | if($ngroups>1 && $map['name'] != $lastgroup) |
791 | | | { |
792 | | | print "<option style='font-weight: bold; font-style: italic' value='$nullhash'>".htmlspecialchars($map['name'])."</option>"; |
793 | | | $lastgroup = $map['name']; |
794 | | | } |
795 | | | print '<option '; |
796 | | | if($current_id == $map['id']) print " SELECTED "; |
797 | | | print 'value="'.$map['filehash'].'">'; |
798 | | | // if we're showing group headings, then indent the map names |
799 | | | if($ngroups>1) { print " - "; } |
800 | | | print htmlspecialchars($map['titlecache']).'</option>'; |
801 | | | } |
802 | | | ?> |
803 | | | </select> |
804 | | | <input type="image" src="../../images/button_go.gif" alt="Go" border="0" align="absmiddle"> |
805 | | | </td> |
806 | | | </tr> |
807 | | | </table> |
808 | | | </td> |
809 | | | </form> |
810 | | | </tr> |
811 | | | <?php |
812 | | | |
813 | | | html_graph_end_box(FALSE); |
814 | | | } |
815 | | | } |
816 | | | |
817 | | | function weathermap_get_valid_tabs() |
818 | | | { |
819 | | | $tabs = array(); |
820 | | | $userid = (isset($_SESSION["sess_user_id"]) ? intval($_SESSION["sess_user_id"]) : 1); |
821 | | | $maps = db_fetch_assoc("select weathermap_maps.*, weathermap_groups.name as group_name from weathermap_auth,weathermap_maps, weathermap_groups where weathermap_groups.id=weathermap_maps.group_id and weathermap_maps.id=weathermap_auth.mapid and active='on' and (userid=".$userid." or userid=0) order by weathermap_groups.sortorder"); |
822 | | | |
823 | | | |
824 | | | foreach ($maps as $map) |
825 | | | { |
826 | | | $tabs[$map['group_id']] = $map['group_name']; |
827 | | | } |
828 | | | |
829 | | | return($tabs); |
830 | | | } |
831 | | | |
832 | | | function weathermap_tabs($current_tab) |
833 | | | { |
834 | | | global $colors; |
835 | | | |
836 | | | // $current_tab=2; |
837 | | | |
838 | | | $tabs = weathermap_get_valid_tabs(); |
839 | | | |
840 | | | # print "Limiting to $current_tab\n"; |
841 | | | |
842 | | | if(sizeof($tabs) > 1) |
843 | | | { |
844 | | | /* draw the categories tabs on the top of the page */ |
845 | | | print "<p></p><table class='tabs' width='100%' cellspacing='0' cellpadding='3' align='center'><tr>\n"; |
846 | | | |
847 | | | if (sizeof($tabs) > 0) { |
848 | | | $show_all = intval(read_config_option("weathermap_all_tab")); |
849 | | | if($show_all == 1) |
850 | | | { |
851 | | | $tabs['-2'] = "All Maps"; |
852 | | | } |
853 | | | |
854 | | | foreach (array_keys($tabs) as $tab_short_name) { |
855 | | | print "<td " . (($tab_short_name == $current_tab) ? "bgcolor='silver'" : "bgcolor='#DFDFDF'") . " nowrap='nowrap' width='" . (strlen($tabs[$tab_short_name]) * 9) . "' align='center' class='tab'> |
856 | | | <span class='textHeader'><a href='weathermap-cacti-plugin.php?group_id=$tab_short_name'>$tabs[$tab_short_name]</a></span> |
857 | | | </td>\n |
858 | | | <td width='1'></td>\n"; |
859 | | | } |
860 | | | |
861 | | | } |
862 | | | |
863 | | | print "<td></td>\n</tr></table>\n"; |
864 | | | |
865 | | | return(true); |
866 | | | } |
867 | | | else |
868 | | | { |
869 | | | return(false); |
870 | | | } |
871 | | | |
872 | | | } |
873 | | | |
874 | 1 | simandl | // vim:ts=4:sw=4: |
875 | | | ?> |