forked from iinnovations/cupidweblib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatalogs.html
executable file
·456 lines (416 loc) · 14.7 KB
/
datalogs.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
<?php require_once('auth/user.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><!-- InstanceBegin template="/Templates/main.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- Get me some jquery-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="/js/iijslib.js" type="text/javascript"></script>
<!--Record auth level-->
<script type="text/javascript">
var sessiondata = {}
sessiondata.username = "<?php if (!empty($_SESSION['user']['name'])) { echo $_SESSION['user']['name'];} ?>";
sessiondata.sessionid = "<?php if (!empty($_SESSION['user']['sessionid'])) {echo $_SESSION['user']['sessionid'];} ?>";
sessiondata.appip = "<?php if (!empty($_SESSION['user']['appip'])) {echo $_SESSION['user']['appip'];} ?>";
sessiondata.realip = "<?php if (!empty($_SESSION['user']['realip'])) {echo $_SESSION['user']['realip'];} ?>";
sessiondata.authlevel = "<?php if (!empty($_SESSION['user']['authlevel'])) {echo $_SESSION['user']['authlevel'];} ?>";
// <!--Log access-->
logUserAuths(sessiondata)
</script>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Datalogs</title>
<!-- InstanceEndEditable -->
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<style media="all" type="text/css">
@import "css/all.css";
</style>
<!-- InstanceBeginEditable name="head" -->
<?php $user->require_login(); ?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script>
var logdata=[];
var sensorlognames=[];
var logmetadata=[];
var logdata=[];
var tablenames=[];
var controldatabase='/var/www/data/controldata.db'
var logdatabase='/var/www/data/logdata.db'
var queryresult=[];
var choices=[];
var dumpfilename='/var/www/data/datadump.csv'
var refresh=2000;
function addInput(object,choices,classname){
var newDiv=document.createElement('div');
var selectHTML = "";
selectHTML="<select>";
for(i=0; i<choices.length; i=i+1){
selectHTML+= "<option value='"+choices[i]+"'>"+choices[i]+"</option>";
}
selectHTML += "</select>";
newDiv.innerHTML= selectHTML;
newDiv.className=classname;
//document.getElementById(divName).appendChild(newDiv);
object.appendChild(newDiv);
}
function UpdateInput(inputid,choices){
document.getElementById(inputid).options.length=0;
for(var i=0; i<choices.length; i++) {
document.getElementById(inputid).options[i]=new Option(choices[i], choices[i], true, false);
}
}
function autoCreateTable(tableID,contenttable){
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
propcount=Object.keys(contenttable[0]).length
// delete all except header row
for(var i = table.rows.length-1; i >= 0; i--)
{
table.deleteRow(i);
}
// create header
var header=table.createTHead()
var row = header.insertRow()
j=0
for (var property in contenttable[0])
{
var newth = row.appendChild(document.createElement("th"))
newth.innerHTML=property
if (j==0)
{
newth.className="first"
}
if (j==propcount)
{
newth.className="last"
}
j++
}
// content table is 2D table
console.log(contenttable)
for(var i=0; i<contenttable.length; i++)
{
var row=table.insertRow(table.rows.length)
var j=0
for (var property in contenttable[i]) // item is object in object array
{
//alert(property + ' = ' + contenttable[i][property])
var newcell = row.insertCell(j)
newcell.innerHTML = contenttable[i][property];
newcell.className = property;
j++;
}
}
}
function addRow(tableID,contentarray) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
// content array is complicated. need to comment better
// see function that calls add row for format.
for(var i=0; i<contentarray.length; i++) {
//alert(table.name);
var newcell = row.insertCell(i);
// determine if input or indicator
var element1 = document.createElement("input")
label=contentarray[i][1];
element1.className=label;
//alert(label)
//alert(newcell.childNodes);
// Act depending on type of cell
var textvalue='empty'
switch(contentarray[i][2]) {
case "text":
element1.type="text";
newcell.appendChild(element1);
element1.value = contentarray[i][0];
break;
case "checkbox":
element1.type="checkbox";
newcell.appendChild(element1);
if (contentarray[i][0]==1) {
element1.checked=true;
element1.value=true;
}
else if (contentarray[i][0]==0 ){
element1.checked=false;
element1.value=false;
}
break;
case "select-one":
addInput(newcell,contentarray[i][3],label)
break;
case "value":
newcell.innerHTML = contentarray[i][0];
break;
case "boolean":
if (contentarray[i][0]==1) {
textvalue="T";
}
else if (contentarray[i][0]==0 ){
textvalue="F"
}
else {
textvalue="Error"
}
newcell.innerHTML = textvalue;
break;
case "onoff":
if (contentarray[i][0]==1) {
textvalue="On";
}
else if (contentarray[i][0]==0 ){
textvalue="Off"
}
else {
textvalue="Error"
}
newcell.innerHTML = textvalue;
break;
} // end switch
//alert('type= ' + contentarray[i][2] + '. value in= ' + contentarray[i][0] + '. value out= ' + textvalue)
} // end for
}
function RenderLogData (logdata) {
var table = document.getElementById('logdatatable')
//console.log(sensorinfo);
for(var i = table.rows.length - 1; i > 0; i--)
{
table.deleteRow(i);
}
alert(logdata)
for (var i=0;i<logdata.length;i++)
{
addRow('logdatatable',[[logdata[i].ROM,"ROM","value"],[logdata[i].value,"value","value"],[logdata[i].time,"polltime","value"]]);
}
}
function RenderLogsAvailable (data) {
var table = document.getElementById('logsavailabletable')
//console.log(sensorinfo);
for(var i = table.rows.length - 1; i > 0; i--)
{
table.deleteRow(i);
}
//alert(data.length)
for (var j=0;j<data.length;j++)
{
addRow('logsavailabletable',[[data[j][0],"logname","value"],[data[j][1],"logpoints","value"],[data[j][2],"lastlogtime","value"]]);
}
}
function dumplog() {
// Prepare tablename
// If we need to send multiple tables, we can send 'tablelist' rather than tablename
logtablename=$('#selectlog').val()
$.ajax({
url: "/wsgiactions",
type: "post",
datatype:"json",
data: {'dump':'empty','database':logdatabase,'tablename':logtablename,'outputfile':dumpfilename},
success: function(response){
alert("Data successfully dumped to " + dumpfilename + ". Retrieve by clicking the \'d/l dump\' button")
// Execute our callback function
}
});
}
function GetAndRenderLogData(logname) {
// set a callback function to render the data on success, then go get it
var callback = RenderLogData;
wsgiCallbackTableData(controldatabase,logname,callback);
}
function GetAndRenderLogsAvailable() {
// set a callback function to render the data on success, then go get it
$.ajax({
url: "/wsgisqlitequery",
type: "post",
datatype:"json",
data: {'database':logdatabase,'query':'select name from sqlite_master where type = \'table\''},
success: function(response){
//alert("I worked");
tablenames=response
UpdateInput("selectlog",tablenames)
// * Run queries on each of the tables to get some metadata
// Construct the query
queryarray=[];
for (var i=0;i<tablenames.length;i++)
{
//query.push('\'select ROM from ' + tablenames[i] + ' order by time limit 1\'')
queryarray.push("select count(*) from \'" + tablenames[i] + "\'")
queryarray.push("select time from \'" + tablenames[i] + "\' order by time limit 1")
}
//console.log('* query *')
//console.log(query)
$.ajax({
url: "/wsgisqlitequery",
type: "post",
datatype:"json",
data: {'database':logdatabase,'queryarray':queryarray},
success: function(response){
//alert("I worked");
data=response;
for (var i=0;i<tablenames.length;i++){
logmetadata[i]=[tablenames[i][0],data[2*i][0][0],data[2*i+1][0][0]];
}
RenderLogsAvailable(logmetadata);
}
});
}
});
}
function wsgiCallbackTableData (database,table,callback) {
// Get the data
$.ajax({
url: "/wsgisqlitequery",
type: "post",
datatype:"json",
data: {'database':database,'table':table},
success: function(response){
//alert("I worked");
// Execute our callback function
callback(response);
}
});
}
$(document).ready(function(){
$.ajaxSetup({
// Disable caching of AJAX responses
cache: false
});
// Update which logs are available
$('#updatelogsavailablebutton').click(function(){
//alert('I am going to update now');
GetAndRenderLogsAvailable()
});
$('#dumpdatabutton').click(function(){
//alert('I am going to update now');
dumplog()
});
// This is where we update the log table
$('#updatelogdatabutton').click(function(){
logtablename=document.getElementById("selectlog").value
//alert(logtablename)
var callback=autoCreateTable
$.ajax({
url: "/wsgisqlitequery",
type: "post",
datatype:"json",
data: {'database':logdatabase,'table':logtablename},
success: function(response){
//alert("I worked");
// Execute our callback function
autoCreateTable("logdatatable",response);
}
});
});
});
// Stuff to run when page loads
GetAndRenderLogsAvailable()
</script>
<!-- InstanceEndEditable -->
</head>
<body>
<div id="main">
<!-- InstanceBeginEditable name="NavBar" -->
<div id="header"> <a href="http://www.interfaceinnovations.org" class="logo"><img src="/images/cmstemplate/logo.png"alt="" /></a>
<ul id="top-navigation">
<li><span><span><a href="index.html">Home</a></span></span></li>
<li><span><span><a href="controlpanel.html">Panel</a></span></span></li>
<li><span><span><a href="smallpanel.html">SmPanel</a></span></span></li>
<li><span><span><a href="inputs.html">Sensors</a></span></span></li>
<li class="active"><span><span>Datalogs</span></span></li>
<li><span><span><a href="settings.html">Settings</a></span></span></li>
<li><span><span><a href="admin.html">Admin</a></span></span></li>
<li><span><span><a href="help.html">Help</a></span></span></li>
</ul>
<div id="login"><?php
if($user->logged_in()):
?>
<p>You are logged in as <?php echo $_SESSION['user']['name']; ?>. <a href="auth/logout">Log out</a></p>
<?php
endif;
if(!$user->logged_in()):
?>
<p>You are not logged in. <a href="auth/login">Log in</a>
<?php
endif;
?>
</p></div><!-- login -->
</div><!-- header -->
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="MainBody" -->
<div id="middle">
<div id="full-column">
<div class="top-bar">
<h1>Datalogs</h1>
<div class="breadcrumbs">We just broke this by restructuring our databases. Hang on ...</div>
</div> <!-- End top bar -->
<br />
<div class="fullcontent">
<table width="100%">
<tr>
<td align="left">
<h2>Logs Available</h2>
</td>
<td align="right">
<button id="updatelogsavailablebutton" />Update Available Logs</button>
</td>
</tr>
</table>
</div>
<div class="table fulltable"> <img src="images/cmstemplate/bg-th-left.gif" width="8" height="7" alt="" class="left" /> <img src="images/cmstemplate/bg-th-right.gif" width="7" height="7" alt="" class="right" />
<table class="listing fulllisting" cellpadding="0" cellspacing="0" id="logsavailabletable">
<tr>
<th class="first">Name</th>
<th>Logpoints</th>
<th class="last">Last Control Time</th>
</tr>
<tr>
<td>value</td>
<td>value</td>
<td>value</td>
</tr>
</table>
</div> <!-- full table -->
<div class="fullcontent">
<table width="100%">
<tr>
<td width="150px">
<h2>Log Data</h2>
</td>
<td>Select Log
<select className="selectlog" id="selectlog" name="selectlog"><option value="None">None</option></select>
</td>
<td align="right"><button id="dumpdatabutton" >Dump Data</button></td>
<td align="left"><button id="downloaddumpbutton" onclick="window.location='data/datadump.csv';">Download Data</button></td>
<td align="right">
<!--<input id="updatelogdatabutton" class="plainbutton" type="submit" value="Update Log Data"></input>-->
<button id="updatelogdatabutton" >Update Log Data</button>
</td>
</tr>
</table>
</div>
<div class="table fulltable"> <img src="images/cmstemplate/bg-th-left.gif" width="8" height="7" alt="" class="left" /> <img src="images/cmstemplate/bg-th-right.gif" width="7" height="7" alt="" class="right" />
<table class="listing fulllisting" cellpadding="0" cellspacing="0" id="logdatatable">
<tr>
<th class="first">Name</th>
<th>ControlROM</th>
<th>Enabled</th>
<th>Recipe</th>
<th>Positive Output</th>
<th class="last">Negative Output</th>
</tr>
<tr>
<td>value</td>
<td>value</td>
<td>value</td>
<td>value</td>
<td>value</td>
<td>value</td>
</tr>
</table>
</div> <!-- full table -->
</div>
</div>
<!-- InstanceEndEditable -->
<div id="footer"></div>
</div>
</body>
<!-- InstanceEnd --></html>