jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [cacti-pick.php] - Blame information for rev 98

 

Line No. Rev Author Line
11simandl<?php
2 
313simandl// ******************************************
4// sensible defaults
5$mapdir='configs';
6$cacti_base = '../../';
7$cacti_url = '/';
8$ignore_cacti=FALSE;
9 
1085simandl$config['base_url'] = $cacti_url;
11 
1213simandl@include_once('editor-config.php');
13 
1485simandl// check if the goalposts have moved
15if( is_dir($cacti_base) && file_exists($cacti_base."/include/global.php") )
1613simandl{
17 // include the cacti-config, so we know about the database
1885simandl include_once($cacti_base."/include/global.php");
19 // $config['base_url'] = $cacti_url;
20 $config['base_url'] = (isset($config['url_path'])? $config['url_path'] : $cacti_url);
21 $cacti_found = TRUE;
22 // print "global";
23}
24elseif( is_dir($cacti_base) && file_exists($cacti_base."/include/config.php") )
25{
26 // include the cacti-config, so we know about the database
2713simandl include_once($cacti_base."/include/config.php");
28 
2985simandl // $config['base_url'] = $cacti_url;
30 $config['base_url'] = (isset($config['url_path'])? $config['url_path'] : $cacti_url);
31 $cacti_found = TRUE;
32 // print "config";
3313simandl}
34else
35{
36 $cacti_found = FALSE;
37}
38 
3985simandl// print $config['base_url'];
40 
4113simandl// ******************************************
42 
431simandlfunction js_escape($str)
44{
45 $str = str_replace('\\', '\\\\', $str);
46 $str = str_replace("'", "\\\'", $str);
47 
48 $str = "'".$str."'";
49 
50 return($str);
51}
52 
5313simandlif(isset($_REQUEST['command']) && $_REQUEST["command"]=='link_step2')
541simandl{
55 $dataid = intval($_REQUEST['dataid']);
56 
57 $SQL_graphid = "select graph_templates_item.local_graph_id, title_cache FROM graph_templates_item,graph_templates_graph,data_template_rrd where graph_templates_graph.local_graph_id = graph_templates_item.local_graph_id and task_item_id=data_template_rrd.id and local_data_id=$dataid LIMIT 1;";
58 
59 $link = mysql_connect($database_hostname,$database_username,$database_password)
60 or die('Could not connect: ' . mysql_error());
61 mysql_selectdb($database_default,$link) or die('Could not select database: '.mysql_error());
62 
63 $result = mysql_query($SQL_graphid) or die('Query failed: ' . mysql_error());
64 $line = mysql_fetch_array($result, MYSQL_ASSOC);
65 $graphid = $line['local_graph_id'];
66 
67?>
68<html>
69<head>
70 <script type="text/javascript">
71 function update_source_step2(graphid)
72 {
73 var graph_url, hover_url;
74 
75 var base_url = '<?php echo isset($config['base_url'])?$config['base_url']:''; ?>';
76 
77 if (typeof window.opener == "object") {
78 
79 graph_url = base_url + 'graph_image.php?local_graph_id=' + graphid + '&rra_id=0&graph_nolegend=true&graph_height=100&graph_width=300';
80 info_url = base_url + 'graph.php?rra_id=all&local_graph_id=' + graphid;
81 
82 opener.document.forms["frmMain"].link_infourl.value = info_url;
83 opener.document.forms["frmMain"].link_hover.value = graph_url;
84 }
85 self.close();
86 }
87 
88 window.onload = update_source_step2(<?php echo $graphid ?>);
89 
90 </script>
91</head>
92<body>
93This window should disappear in a moment.
94</body>
95</html>
96<?php
9713simandl // end of link step 2
981simandl}
9913simandl 
100if(isset($_REQUEST['command']) && $_REQUEST["command"]=='link_step1')
1011simandl{
102?>
103<html>
104<head>
10585simandl <script type="text/javascript" src="editor-resources/jquery-latest.min.js"></script>
1061simandl <script type="text/javascript">
107 
10885simandl function filterlist(previous)
109 {
110 var filterstring = $('input#filterstring').val();
111 
112 if(filterstring=='')
113 {
114 $('ul#dslist > li').show();
115 return;
116 }
117 
118 if(filterstring!=previous)
119 {
120 $('ul#dslist > li').hide();
121 $("ul#dslist > li:contains('" + filterstring + "')").show();
122 }
123 }
124 
125 $(document).ready( function() {
126 $('span.filter').keyup(function() {
127 var previous = $('input#filterstring').val();
128 setTimeout(function () {filterlist(previous)}, 500);
129 }).show();
130 });
131 
1321simandl function update_source_step1(dataid,datasource)
133 {
134 var newlocation;
135 var fullpath;
136 
13785simandl var rra_path = <?php echo js_escape($config['rra_path']); ?>;
1381simandl 
139 if (typeof window.opener == "object") {
14085simandl fullpath = datasource.replace(/<path_rra>/, rra_path);
141 if(document.forms['mini'].aggregate.checked)
142 {
143 opener.document.forms["frmMain"].link_target.value = opener.document.forms["frmMain"].link_target.value + " " + fullpath;
144 }
145 else
146 {
147 opener.document.forms["frmMain"].link_target.value = fullpath;
148 }
1491simandl }
150 if(document.forms['mini'].overlib.checked)
151 {
15213simandl newlocation = 'cacti-pick.php?command=link_step2&dataid=' + dataid;
1531simandl self.location = newlocation;
154 }
155 else
156 {
157 self.close();
158 }
159 }
16085simandl 
161 function applyDSFilterChange(objForm) {
162 strURL = '?host_id=' + objForm.host_id.value;
163 strURL = strURL + '&command=link_step1';
164 if( objForm.overlib.checked)
165 {
166 strURL = strURL + "&overlib=1";
167 }
168 else
169 {
170 strURL = strURL + "&overlib=0";
171 }
172 // document.frmMain.link_bandwidth_out_cb.checked
173 if( objForm.aggregate.checked)
174 {
175 strURL = strURL + "&aggregate=1";
176 }
177 else
178 {
179 strURL = strURL + "&aggregate=0";
180 }
181 document.location = strURL;
182 }
183 
1841simandl </script>
185<style type="text/css">
186body { font-family: sans-serif; font-size: 10pt; }
187ul { list-style: none; margin: 0; padding: 0; }
188ul { border: 1px solid black; }
189ul li.row0 { background: #ddd;}
190ul li.row1 { background: #ccc;}
191ul li { border-bottom: 1px solid #aaa; border-top: 1px solid #eee; padding: 2px;}
192ul li a { text-decoration: none; color: black; }
193</style>
194<title>Pick a data source</title>
195</head>
196<body>
197<?php
198 
19985simandl $SQL_picklist = "select data_local.host_id, data_template_data.local_data_id, data_template_data.name_cache, data_template_data.active, data_template_data.data_source_path from data_local,data_template_data,data_input,data_template where data_local.id=data_template_data.local_data_id and data_input.id=data_template_data.data_input_id and data_local.data_template_id=data_template.id ";
2001simandl 
20185simandl $host_id = -1;
202 
203 $overlib = true;
204 $aggregate = false;
205 
206 if(isset($_REQUEST['aggregate'])) $aggregate = ( $_REQUEST['aggregate']==0 ? false : true);
207 if(isset($_REQUEST['overlib'])) $overlib= ( $_REQUEST['overlib']==0 ? false : true);
208 
209 
210 if(isset($_REQUEST['host_id']))
211 {
212 $host_id = intval($_REQUEST['host_id']);
213 if($host_id>=0) $SQL_picklist .= " and data_local.host_id=$host_id ";
214 }
215 
216 $SQL_picklist .= " order by name_cache;";
217 
218 $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname");
219?>
2201simandl 
221<h3>Pick a data source:</h3>
222 
223<form name="mini">
22485simandl<?php
225if(sizeof($hosts) > 0) {
226 print 'Host: <select name="host_id" onChange="applyDSFilterChange(document.mini)">';
227 
228 print '<option '.($host_id==-1 ? 'SELECTED' : '' ).' value="-1">Any</option>';
229 print '<option '.($host_id==0 ? 'SELECTED' : '' ).' value="0">None</option>';
230 foreach ($hosts as $host)
231 {
232 print '<option ';
233 if($host_id==$host['id']) print " SELECTED ";
234 print 'value="'.$host['id'].'">'.$host['name'].'</option>';
235 }
236 print '</select><br />';
237}
238 
239 print '<span class="filter" style="display: none;">Filter: <input id="filterstring" name="filterstring" size="20"> (case-sensitive)<br /></span>';
240 print '<input id="overlib" name="overlib" type="checkbox" value="yes" '.($overlib ? 'CHECKED' : '' ).'> <label for="overlib">Also set OVERLIBGRAPH and INFOURL.</label><br />';
241 print '<input id="aggregate" name="aggregate" type="checkbox" value="yes" '.($aggregate ? 'CHECKED' : '' ).'> <label for="aggregate">Append TARGET to existing one (Aggregate)</label>';
242 
243 print '</form><div class="listcontainer"><ul id="dslist">';
244 
2451simandl $queryrows = db_fetch_assoc($SQL_picklist);
246 
247 // print $SQL_picklist;
248 
249 $i=0;
25085simandl if( is_array($queryrows) && sizeof($queryrows) > 0 )
2511simandl {
252 foreach ($queryrows as $line) {
253 //while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
254 echo "<li class=\"row".($i%2)."\">";
255 $key = $line['local_data_id']."','".$line['data_source_path'];
256 echo "<a href=\"#\" onclick=\"update_source_step1('$key')\">". $line['name_cache'] . "</a>";
257 echo "</li>\n";
25885simandl 
2591simandl $i++;
260 }
261 }
262 else
263 {
26485simandl print "<li>No results...</li>";
2651simandl }
266 
267 // Free resultset
268 //mysql_free_result($result);
269 
270 // Closing connection
271 //mysql_close($link);
272 
273?>
274</ul>
27585simandl</div>
2761simandl</body>
277</html>
278<?php
27913simandl} // end of link step 1
280 
281if(isset($_REQUEST['command']) && $_REQUEST["command"]=='node_step1')
282{
28385simandl $host_id = -1;
284 $SQL_picklist = "SELECT graph_templates_graph.id, graph_local.host_id, graph_templates_graph.local_graph_id, graph_templates_graph.height, graph_templates_graph.width, graph_templates_graph.title_cache, graph_templates.name, graph_local.host_id FROM (graph_local,graph_templates_graph) LEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id) WHERE graph_local.id=graph_templates_graph.local_graph_id ";
285 
286 $overlib = true;
287 $aggregate = false;
288 
289 if(isset($_REQUEST['aggregate'])) $aggregate = ( $_REQUEST['aggregate']==0 ? false : true);
290 if(isset($_REQUEST['overlib'])) $overlib= ( $_REQUEST['overlib']==0 ? false : true);
291 
292 
293 if(isset($_REQUEST['host_id']))
294 {
295 $host_id = intval($_REQUEST['host_id']);
296 if($host_id>=0) $SQL_picklist .= " and graph_local.host_id=$host_id ";
297 }
298 $SQL_picklist .= " order by title_cache";
299 
300 $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname");
301 
30213simandl?>
303<html>
304<head>
30585simandl<script type="text/javascript" src="editor-resources/jquery-latest.min.js"></script>
306<script type="text/javascript">
307 
308 function filterlist(previous)
309 {
310 var filterstring = $('input#filterstring').val();
311 
312 if(filterstring=='')
313 {
314 $('ul#dslist > li').show();
315 return;
316 }
317 
318 if(filterstring!=previous)
319 {
320 $('ul#dslist > li').hide();
321 $('ul#dslist > li').contains(filterstring).show();
322 }
323 }
324 
325 $(document).ready( function() {
326 $('span.filter').keyup(function() {
327 var previous = $('input#filterstring').val();
328 setTimeout(function () {filterlist(previous)}, 500);
329 }).show();
330 });
331 
332 function applyDSFilterChange(objForm) {
333 strURL = '?host_id=' + objForm.host_id.value;
334 strURL = strURL + '&command=node_step1';
335 if( objForm.overlib.checked)
336 {
337 strURL = strURL + "&overlib=1";
338 }
339 else
340 {
341 strURL = strURL + "&overlib=0";
342 }
343 
344 //if( objForm.aggregate.checked)
345 //{
346 // strURL = strURL + "&aggregate=1";
347 //}
348 //else
349 //{
350 // strURL = strURL + "&aggregate=0";
351 //}
352 document.location = strURL;
353 }
354 
355 </script>
35613simandl <script type="text/javascript">
357 
358 function update_source_step1(graphid)
359 {
360 var graph_url, hover_url;
361 
362 var base_url = '<?php echo isset($config['base_url'])?$config['base_url']:''; ?>';
363 
364 if (typeof window.opener == "object") {
365 
36685simandl graph_url = base_url + 'graph_image.php?rra_id=0&graph_nolegend=true&graph_height=100&graph_width=300&local_graph_id=' + graphid;
36713simandl info_url = base_url + 'graph.php?rra_id=all&local_graph_id=' + graphid;
368 
36985simandl // only set the overlib URL unless the box is checked
370 if( document.forms['mini'].overlib.checked)
371 {
372 opener.document.forms["frmMain"].node_infourl.value = info_url;
373 }
37413simandl opener.document.forms["frmMain"].node_hover.value = graph_url;
375 }
376 self.close();
377 }
378 </script>
379<style type="text/css">
380body { font-family: sans-serif; font-size: 10pt; }
381ul { list-style: none; margin: 0; padding: 0; }
382ul { border: 1px solid black; }
383ul li.row0 { background: #ddd;}
384ul li.row1 { background: #ccc;}
385ul li { border-bottom: 1px solid #aaa; border-top: 1px solid #eee; padding: 2px;}
386ul li a { text-decoration: none; color: black; }
387</style>
38885simandl<title>Pick a graph</title>
38913simandl</head>
390<body>
391 
392<?php
393 
39485simandl# print "Cacti is ".$config["cacti_version"];
39513simandl 
396# $SQL_picklist = "select data_template_data.local_data_id, data_template_data.name_cache, data_template_data.active, data_template_data.data_source_path from data_local,data_template_data,data_input,data_template left join data_input on data_input.id=data_template_data.data_input_id left join data_template on data_local.data_template_id=data_template.id where data_local.id=data_template_data.local_data_id order by name_cache;";
397# $SQL_picklist = "select data_template_data.local_data_id, data_template_data.name_cache, data_template_data.active, data_template_data.data_source_path from data_local,data_template_data,data_input,data_template where data_local.id=data_template_data.local_data_id and data_input.id=data_template_data.data_input_id and data_local.data_template_id=data_template.id order by name_cache;";
39885simandl 
399 
400 
40113simandl #$link = mysql_connect($database_hostname,$database_username,$database_password)
402 # or die('Could not connect: ' . mysql_error());
403 # mysql_selectdb($database_default,$link) or die('Could not select database: '.mysql_error());
404 
405 #$result = mysql_query($SQL_picklist) or die('Query failed: ' . mysql_error());
406?>
40785simandl 
40813simandl<h3>Pick a graph:</h3>
409 
41085simandl<form name="mini">
411<?php
412if(sizeof($hosts) > 0) {
413 print 'Host: <select name="host_id" onChange="applyDSFilterChange(document.mini)">';
414 
415 print '<option '.($host_id==-1 ? 'SELECTED' : '' ).' value="-1">Any</option>';
416 print '<option '.($host_id==0 ? 'SELECTED' : '' ).' value="0">None</option>';
417 foreach ($hosts as $host)
418 {
419 print '<option ';
420 if($host_id==$host['id']) print " SELECTED ";
421 print 'value="'.$host['id'].'">'.$host['name'].'</option>';
422 }
423 print '</select><br />';
424}
425 
426 print '<span class="filter" style="display: none;">Filter: <input id="filterstring" name="filterstring" size="20"> (case-sensitive)<br /></span>';
427 print '<input id="overlib" name="overlib" type="checkbox" value="yes" '.($overlib ? 'CHECKED' : '' ).'> <label for="overlib">Set both OVERLIBGRAPH and INFOURL.</label><br />';
428 // print '<input id="aggregate" name="aggregate" type="checkbox" value="yes" '.($aggregate ? 'CHECKED' : '' ).'> <label for="aggregate">Append TARGET to existing one (Aggregate)</label>';
429 
430 print '</form><div class="listcontainer"><ul id="dslist">';
431 
43213simandl $queryrows = db_fetch_assoc($SQL_picklist);
433 
434 // print $SQL_picklist;
435 
436 $i=0;
43785simandl if( is_array($queryrows) && sizeof($queryrows) > 0)
43813simandl {
439 foreach ($queryrows as $line) {
440 //while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
441 echo "<li class=\"row".($i%2)."\">";
442 $key = $line['local_graph_id'];
443 echo "<a href=\"#\" onclick=\"update_source_step1('$key')\">". $line['title_cache'] . "</a>";
444 echo "</li>\n";
445 $i++;
446 }
447 }
448 else
449 {
450 print "No results...";
451 }
452 
453 // Free resultset
454 //mysql_free_result($result);
455 
456 // Closing connection
457 //mysql_close($link);
458?>
459</ul>
460</body>
461</html>
462<?php
463} // end of node step 1
464 
4651simandl// vim:ts=4:sw=4:
466?>

Powered by WebSVN 2.2.1