1 | <?php |
---|
2 | |
---|
3 | /* |
---|
4 | ########### SVN repository information ################### |
---|
5 | # $Date: 2011-08-21 13:24:14 +0000 (Sun, 21 Aug 2011) $ |
---|
6 | # $Author: jemian $ |
---|
7 | # $Revision: 619 $ |
---|
8 | # $HeadURL$ |
---|
9 | # $Id: index.php 619 2011-08-21 13:24:14Z jemian $ |
---|
10 | ########### SVN repository information ################### |
---|
11 | */ |
---|
12 | |
---|
13 | //**************************************************** |
---|
14 | |
---|
15 | $propertiesFile = 'properties.xml'; |
---|
16 | $pvListFile = 'pvlist.xml'; |
---|
17 | $defaultGallerySpan = 'week'; |
---|
18 | |
---|
19 | include('makeTagHTML.php'); |
---|
20 | |
---|
21 | |
---|
22 | /** Returns subversion revision number */ |
---|
23 | function getSvnIdStr() { |
---|
24 | $svn_id = '$Id: index.php 619 2011-08-21 13:24:14Z jemian $'; |
---|
25 | $scid = trim($svn_id, "$"); |
---|
26 | return $scid; |
---|
27 | } |
---|
28 | |
---|
29 | //**************************************************** |
---|
30 | |
---|
31 | function directoryBrowsing($rootDir) { |
---|
32 | foreach(scanDir($rootDir) as $key => $content) { |
---|
33 | $path = $rootDir.'/'.$content; |
---|
34 | if(is_file($path) && is_readable($path)) { |
---|
35 | print($path . "\n"); |
---|
36 | } |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | //**************************************************** |
---|
41 | |
---|
42 | function readPropertiesXML($xmlFile) { |
---|
43 | $doc = new DOMDocument; |
---|
44 | $doc->load($xmlFile); |
---|
45 | $propsXML = new DOMXPath($doc); |
---|
46 | $items = array('title', 'rrdtool', 'rrdupdate', 'rrd_file_start_time', |
---|
47 | 'www_plot_dir', 'rrd_logs_base_dir'); |
---|
48 | $props = array(); |
---|
49 | foreach($items as $key) { |
---|
50 | $props[$key] = $propsXML->query('/properties/'.$key)->item(0)->textContent; |
---|
51 | } |
---|
52 | $items = array( |
---|
53 | 'spans' => 'span', |
---|
54 | 'subdirs' => 'subdir', |
---|
55 | ); |
---|
56 | foreach($items as $parent => $child) { |
---|
57 | $props[$parent] = array(); |
---|
58 | $query = '//' . $parent . '/' . $child; |
---|
59 | foreach ($propsXML->query($query) as $entry) { |
---|
60 | $value = $entry->textContent; |
---|
61 | $name = $propsXML->query('./@name', $entry)->item(0)->textContent; |
---|
62 | $props[$parent][$name] = $value; |
---|
63 | } |
---|
64 | } |
---|
65 | return($props); |
---|
66 | } |
---|
67 | |
---|
68 | //**************************************************** |
---|
69 | |
---|
70 | function readPvlistXML($xmlFile) { |
---|
71 | $doc = new DOMDocument; |
---|
72 | $doc->load($xmlFile); |
---|
73 | $pvXML = new DOMXPath($doc); |
---|
74 | |
---|
75 | $items = array('units', 'min', 'max', 'scale'); |
---|
76 | $pvList = array(); |
---|
77 | foreach($pvXML->query('//PV_LIST/EPICS_PV') as $entry) { |
---|
78 | $pv = $pvXML->query('./@pv', $entry)->item(0)->textContent; |
---|
79 | $arr = array(); |
---|
80 | $arr['pv'] = $pv; |
---|
81 | $arr['desc'] = trim($entry->textContent); |
---|
82 | foreach($items as $item) { |
---|
83 | $value = $pvXML->query('./@'.$item, $entry)->item(0)->textContent; |
---|
84 | $arr[$item] = $value; |
---|
85 | } |
---|
86 | $arr['fileRoot'] = str_replace (':', '-', $pv); |
---|
87 | $pvList[] = $arr; |
---|
88 | } |
---|
89 | return($pvList); |
---|
90 | } |
---|
91 | |
---|
92 | //**************************************************** |
---|
93 | |
---|
94 | function showGallery($span) { |
---|
95 | global $propertiesFile, $pvListFile, $_SERVER; |
---|
96 | // show all available plots at the selected span |
---|
97 | // This can be very friendly for the PDA screen size |
---|
98 | // BUT, it loads all the PNG charts for the chosen $span |
---|
99 | //----------- |
---|
100 | // load the properties and EPICS PV list from XML configuration files |
---|
101 | $props = readPropertiesXML($propertiesFile); |
---|
102 | $pvList = readPvlistXML($pvListFile); |
---|
103 | //----------- |
---|
104 | sort($pvList); |
---|
105 | foreach($pvList as $arr) { |
---|
106 | $pngFile = sprintf('%s/%s-%s.png', |
---|
107 | $props['subdirs']['fs_plot_dir'], |
---|
108 | $arr['fileRoot'], |
---|
109 | $span); |
---|
110 | $htmlFile = sprintf('%s/%s.html', |
---|
111 | $props['subdirs']['html_dir'], |
---|
112 | $arr['fileRoot']); |
---|
113 | $cgiFile = sprintf('%s/%s.cgi', |
---|
114 | $props['subdirs']['cgi_dir'], |
---|
115 | $arr['fileRoot']); |
---|
116 | if (file_exists($pngFile)) { |
---|
117 | $tag = makeTagHTML( |
---|
118 | sprintf('img src="%s" width="%d" height="%d"', $pngFile, 200, 80) |
---|
119 | ); |
---|
120 | if (file_exists($htmlFile)) { |
---|
121 | // link to an HTML page if available, it shows more plots |
---|
122 | $href = $htmlFile; |
---|
123 | } else { |
---|
124 | // otherwise, just show the PNG full-size |
---|
125 | $href = $pngFile; |
---|
126 | } |
---|
127 | $a = makeTagHTML(sprintf('a href="%s"', $href), $tag); |
---|
128 | $body .= $a; |
---|
129 | } |
---|
130 | } |
---|
131 | $title = $props['title'] . " for the last " . $span; |
---|
132 | |
---|
133 | // make HTML head |
---|
134 | $head = "<!-- created by ./index.php -->\n"; |
---|
135 | $head .= makeTagHTML('title', $title, 0); |
---|
136 | $head .= makeTagHTML('meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"'); |
---|
137 | $head .= makeTagHTML('meta name="GENERATOR" content="Pete Jemian, text editor"'); |
---|
138 | $head .= makeTagHTML('meta http-equiv="Pragma" content="no-cache"'); |
---|
139 | |
---|
140 | // append an ending to the body |
---|
141 | $body .= makeTagHTML('hr', ''); |
---|
142 | $body .= makeTagHTML('a href="documentation.html"', 'README'); |
---|
143 | |
---|
144 | // assemble full HTML |
---|
145 | $parts = makeTagHTML('head', $head); |
---|
146 | $parts .= makeTagHTML('body', makeTagHTML('h1', $title, 0) . $body); |
---|
147 | |
---|
148 | // assemble everything |
---|
149 | $html = makeTagHTML('html', $parts); |
---|
150 | print($html); |
---|
151 | } |
---|
152 | |
---|
153 | //**************************************************** |
---|
154 | |
---|
155 | function showFullList($span) { |
---|
156 | global $propertiesFile, $pvListFile, $_SERVER; |
---|
157 | // show all data logs |
---|
158 | // show all available plots at the selected span |
---|
159 | //----------- |
---|
160 | // load the properties and EPICS PV list from XML configuration files |
---|
161 | $props = readPropertiesXML($propertiesFile); |
---|
162 | $pvList = readPvlistXML($pvListFile); |
---|
163 | //----------- |
---|
164 | sort($pvList); |
---|
165 | $row = makeTagHTML('th', 'PV'); |
---|
166 | $row .= makeTagHTML('th', 'description'); |
---|
167 | $row .= makeTagHTML('th', 'plot for last '.$span); |
---|
168 | $table = makeTagHTML('tr', $row); |
---|
169 | $i = 0; |
---|
170 | foreach($pvList as $arr) { |
---|
171 | $i = $i + 1; // for coloring each table row |
---|
172 | |
---|
173 | $pngFile = sprintf('%s/%s-%s.png', |
---|
174 | $props['subdirs']['fs_plot_dir'], |
---|
175 | $arr['fileRoot'], |
---|
176 | $span); |
---|
177 | $htmlFile = sprintf('%s/%s.html', |
---|
178 | $props['subdirs']['html_dir'], |
---|
179 | $arr['fileRoot']); |
---|
180 | $cgiFile = sprintf('%s/%s.cgi', |
---|
181 | $props['subdirs']['cgi_dir'], |
---|
182 | $arr['fileRoot']); |
---|
183 | |
---|
184 | // @TODO: make a new PNG file with default $span |
---|
185 | |
---|
186 | if (file_exists($pngFile)) { |
---|
187 | $tag = makeTagHTML( |
---|
188 | sprintf('img src="%s" width="%d" height="%d"', $pngFile, 100, 40) |
---|
189 | ); |
---|
190 | |
---|
191 | // PV name |
---|
192 | if (file_exists($cgiFile)) { |
---|
193 | // link to a RRDCGI page if available, it shows more plots |
---|
194 | $a = makeTagHTML(sprintf('a href="%s"', $cgiFile), $arr['pv']); |
---|
195 | } else { |
---|
196 | // otherwise, just show nothing |
---|
197 | $a = $arr['pv']; |
---|
198 | } |
---|
199 | $row = makeTagHTML('td', $a); |
---|
200 | |
---|
201 | // description |
---|
202 | $row .= makeTagHTML('td', $arr['desc']); |
---|
203 | |
---|
204 | // representative plot (recent history) |
---|
205 | if (file_exists($cgiFile)) { |
---|
206 | // link to a RRDCGI page if available, it shows more plots |
---|
207 | $href = $cgiFile; |
---|
208 | } else { |
---|
209 | // otherwise, just show the PNG full-size |
---|
210 | $href = $pngFile; |
---|
211 | } |
---|
212 | $a = makeTagHTML(sprintf('a href="%s"', $href), $tag); |
---|
213 | $row .= makeTagHTML('td', $a); |
---|
214 | |
---|
215 | // table row group |
---|
216 | if ( ($i % 2) == 0 ) { |
---|
217 | $table .= makeTagHTML('tr bgcolor="Azure"', $row); |
---|
218 | } else { |
---|
219 | $table .= makeTagHTML('tr', $row); |
---|
220 | } |
---|
221 | } |
---|
222 | } |
---|
223 | $body = makeTagHTML('table border="2"', $table); |
---|
224 | $title = $props['title'] . " For the last " . $span; |
---|
225 | |
---|
226 | // make HTML head |
---|
227 | $head = "<!-- created by ./index.php -->\n"; |
---|
228 | $head .= makeTagHTML('title', $title, 0); |
---|
229 | $head .= makeTagHTML('meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"'); |
---|
230 | $head .= makeTagHTML('meta name="GENERATOR" content="Pete Jemian, text editor"'); |
---|
231 | $head .= makeTagHTML('meta http-equiv="Pragma" content="no-cache"'); |
---|
232 | |
---|
233 | // put a title on the body |
---|
234 | $body = makeTagHTML('h1', $title, 0) |
---|
235 | . makeTagHTML( |
---|
236 | 'small', |
---|
237 | makeTagHTML('a href="documentation.html"', 'documentation') |
---|
238 | . ', ' |
---|
239 | . 'subversion ' . getSvnIdStr(), |
---|
240 | 0) |
---|
241 | . $body; |
---|
242 | |
---|
243 | |
---|
244 | // assemble full HTML |
---|
245 | $parts = makeTagHTML('head', $head); |
---|
246 | $parts .= makeTagHTML('body', $body); |
---|
247 | |
---|
248 | // assemble everything |
---|
249 | $html = makeTagHTML('html', $parts); |
---|
250 | print($html); |
---|
251 | } |
---|
252 | |
---|
253 | //**************************************************** |
---|
254 | |
---|
255 | function main() { |
---|
256 | global $propertiesFile, $pvListFile; |
---|
257 | print("<pre>\n"); |
---|
258 | print("--------------------------------------\n"); |
---|
259 | directoryBrowsing('.'); |
---|
260 | print("--------------------------------------\n"); |
---|
261 | $props = readPropertiesXML($propertiesFile); |
---|
262 | print_r($props); |
---|
263 | print("--------------------------------------\n"); |
---|
264 | $pvList = readPvlistXML($pvListFile); |
---|
265 | print_r($pvList); |
---|
266 | print("--------------------------------------\n"); |
---|
267 | print("</pre>\n"); |
---|
268 | } |
---|
269 | |
---|
270 | //**************************************************** |
---|
271 | |
---|
272 | // main(); |
---|
273 | // construct other display methods, including form/response |
---|
274 | // for now, this works but is bandwidth-intensive |
---|
275 | //showGallery($defaultGallerySpan); |
---|
276 | // |
---|
277 | // alternative view showing a table of PV | description with links |
---|
278 | showFullList($defaultGallerySpan); |
---|
279 | //phpInfo(); |
---|
280 | |
---|
281 | ?> |
---|