1 | 1 | simandl | <?php |
2 | | | include_once('editor-config.php'); |
3 | | | |
4 | | | function js_escape($str) |
5 | | | { |
6 | | | $str = str_replace('\\', '\\\\', $str); |
7 | | | $str = str_replace("'", "\\\'", $str); |
8 | | | |
9 | | | $str = "'".$str."'"; |
10 | | | |
11 | | | return($str); |
12 | | | } |
13 | | | |
14 | | | if(isset($_REQUEST['command']) && $_REQUEST["command"]=='step2') |
15 | | | { |
16 | | | $dataid = intval($_REQUEST['dataid']); |
17 | | | |
18 | | | $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;"; |
19 | | | |
20 | | | $link = mysql_connect($database_hostname,$database_username,$database_password) |
21 | | | or die('Could not connect: ' . mysql_error()); |
22 | | | mysql_selectdb($database_default,$link) or die('Could not select database: '.mysql_error()); |
23 | | | |
24 | | | $result = mysql_query($SQL_graphid) or die('Query failed: ' . mysql_error()); |
25 | | | $line = mysql_fetch_array($result, MYSQL_ASSOC); |
26 | | | $graphid = $line['local_graph_id']; |
27 | | | |
28 | | | ?> |
29 | | | <html> |
30 | | | <head> |
31 | | | |
32 | | | <script type="text/javascript"> |
33 | | | function update_source_step2(graphid) |
34 | | | { |
35 | | | var graph_url, hover_url; |
36 | | | |
37 | | | var base_url = '<?php echo isset($config['base_url'])?$config['base_url']:''; ?>'; |
38 | | | |
39 | | | if (typeof window.opener == "object") { |
40 | | | |
41 | | | graph_url = base_url + 'graph_image.php?local_graph_id=' + graphid + '&rra_id=0&graph_nolegend=true&graph_height=100&graph_width=300'; |
42 | | | info_url = base_url + 'graph.php?rra_id=all&local_graph_id=' + graphid; |
43 | | | |
44 | | | opener.document.forms["frmMain"].link_infourl.value = info_url; |
45 | | | opener.document.forms["frmMain"].link_hover.value = graph_url; |
46 | | | } |
47 | | | self.close(); |
48 | | | } |
49 | | | |
50 | | | window.onload = update_source_step2(<?php echo $graphid ?>); |
51 | | | |
52 | | | </script> |
53 | | | </head> |
54 | | | <body> |
55 | | | This window should disappear in a moment. |
56 | | | </body> |
57 | | | </html> |
58 | | | <?php |
59 | | | } |
60 | | | else |
61 | | | { |
62 | | | ?> |
63 | | | <html> |
64 | | | <head> |
65 | | | |
66 | | | <script type="text/javascript"> |
67 | | | |
68 | | | function update_source_step1(dataid,datasource) |
69 | | | { |
70 | | | var newlocation; |
71 | | | var fullpath; |
72 | | | |
73 | | | var rra_path = <?php echo js_escape($config['base_path']); ?>; |
74 | | | |
75 | | | if (typeof window.opener == "object") { |
76 | | | fullpath = datasource.replace(/<path_rra>/, rra_path + '/rra'); |
77 | | | |
78 | | | opener.document.forms["frmMain"].link_target.value = fullpath; |
79 | | | } |
80 | | | if(document.forms['mini'].overlib.checked) |
81 | | | { |
82 | | | newlocation = 'cacti-pick.php?command=step2&dataid=' + dataid; |
83 | | | self.location = newlocation; |
84 | | | } |
85 | | | else |
86 | | | { |
87 | | | self.close(); |
88 | | | } |
89 | | | } |
90 | | | </script> |
91 | | | <style type="text/css"> |
92 | | | body { font-family: sans-serif; font-size: 10pt; } |
93 | | | ul { list-style: none; margin: 0; padding: 0; } |
94 | | | ul { border: 1px solid black; } |
95 | | | ul li.row0 { background: #ddd;} |
96 | | | ul li.row1 { background: #ccc;} |
97 | | | ul li { border-bottom: 1px solid #aaa; border-top: 1px solid #eee; padding: 2px;} |
98 | | | ul li a { text-decoration: none; color: black; } |
99 | | | </style> |
100 | | | <title>Pick a data source</title> |
101 | | | </head> |
102 | | | <body> |
103 | | | |
104 | | | <?php |
105 | | | |
106 | | | // print "Cacti is ".$config["cacti_version"] = "0.8.6g"; |
107 | | | |
108 | | | $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;"; |
109 | | | $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;"; |
110 | | | //$link = mysql_connect($database_hostname,$database_username,$database_password) |
111 | | | // or die('Could not connect: ' . mysql_error()); |
112 | | | // mysql_selectdb($database_default,$link) or die('Could not select database: '.mysql_error()); |
113 | | | |
114 | | | //$result = mysql_query($SQL_picklist) or die('Query failed: ' . mysql_error()); |
115 | | | ?> |
116 | | | <h3>Pick a data source:</h3> |
117 | | | |
118 | | | <form name="mini"> |
119 | | | <input name="overlib" type="checkbox" value="yes" checked> Also set OVERLIBGRAPH and INFOURL. |
120 | | | </form> |
121 | | | <ul> |
122 | | | <?php |
123 | | | $queryrows = db_fetch_assoc($SQL_picklist); |
124 | | | |
125 | | | // print $SQL_picklist; |
126 | | | |
127 | | | $i=0; |
128 | | | if( is_array($queryrows) ) |
129 | | | { |
130 | | | foreach ($queryrows as $line) { |
131 | | | //while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { |
132 | | | echo "<li class=\"row".($i%2)."\">"; |
133 | | | $key = $line['local_data_id']."','".$line['data_source_path']; |
134 | | | echo "<a href=\"#\" onclick=\"update_source_step1('$key')\">". $line['name_cache'] . "</a>"; |
135 | | | echo "</li>\n"; |
136 | | | $i++; |
137 | | | } |
138 | | | } |
139 | | | else |
140 | | | { |
141 | | | print "No results..."; |
142 | | | } |
143 | | | |
144 | | | // Free resultset |
145 | | | //mysql_free_result($result); |
146 | | | |
147 | | | // Closing connection |
148 | | | //mysql_close($link); |
149 | | | |
150 | | | ?> |
151 | | | </ul> |
152 | | | </body> |
153 | | | </html> |
154 | | | <?php |
155 | | | } // end of step 1 |
156 | | | // vim:ts=4:sw=4: |
157 | | | ?> |