1 |
<%pre> |
2 |
#include <tntdb/connect.h> |
3 |
#include <tntdb/connection.h> |
4 |
#include <tntdb/result.h> |
5 |
#include <tntdb/row.h> |
6 |
|
7 |
</%pre> |
8 |
|
9 |
<%config> |
10 |
dburl; |
11 |
</%config> |
12 |
|
13 |
<&header title="Critical systems"> |
14 |
</&header> |
15 |
<h2>Critical systems</h2> |
16 |
|
17 |
<{ |
18 |
|
19 |
reply.setHeader("Refresh", "120"); |
20 |
|
21 |
tntdb::Connection conn = tntdb::connectCached(dburl); |
22 |
|
23 |
|
24 |
std::string query1; |
25 |
query1 += "SELECT c.name, i.description, i.id, i.commerror "; |
26 |
query1 += "FROM installation i INNER JOIN customer c "; |
27 |
query1 += "ON i.customerid = c.id"; |
28 |
|
29 |
|
30 |
tntdb::Result inst_res = conn.select(query1); |
31 |
|
32 |
|
33 |
std::string query2; |
34 |
query2 += "SELECT temperature,flamedetector,conveyorerror,powerfailure "; |
35 |
query2 += "FROM logtable "; |
36 |
query2 += "WHERE installationnr = :v1 "; |
37 |
query2 += "ORDER BY messagenr DESC,logtime DESC "; |
38 |
query2 += "LIMIT 1"; |
39 |
|
40 |
|
41 |
tntdb::Statement st = conn.prepare(query2); |
42 |
|
43 |
std::ostream& out = reply.out(); |
44 |
|
45 |
bool hasCritical = false; |
46 |
|
47 |
for (unsigned i=0; i<inst_res.size(); i++) |
48 |
{ |
49 |
int id = inst_res[i].getInt(2); |
50 |
st.clear(); |
51 |
|
52 |
st.setInt("v1", id); |
53 |
tntdb::Result res = st.select(); |
54 |
|
55 |
bool commerror = inst_res[i].getBool(3); |
56 |
int temperature = 50; |
57 |
bool flameDetector = true; |
58 |
bool conveyorError = false; |
59 |
bool powerFailure = false; |
60 |
|
61 |
if (res.size() > 0) |
62 |
{ |
63 |
temperature = res[0].getInt(0); |
64 |
flameDetector = res[0].getBool(1); |
65 |
conveyorError = res[0].getBool(2); |
66 |
powerFailure = res[0].getBool(3); |
67 |
} |
68 |
|
69 |
if (commerror || temperature > 90 || flameDetector == false || conveyorError || powerFailure) |
70 |
{ |
71 |
out << "<a href='installationdetails?id=" << id << "'><b>" << inst_res[i].getString(0) << "</b> : " << inst_res[i].getString(1) << "<br></a>\n"; |
72 |
out << "<ul>"; |
73 |
|
74 |
if (temperature > 90) |
75 |
out << "<li>High temperature</li>\n"; |
76 |
|
77 |
if (commerror) |
78 |
out << "<li>Communication error</li>\n"; |
79 |
|
80 |
if (flameDetector == false) |
81 |
out << "<li>No flames</li>\n"; |
82 |
|
83 |
if (conveyorError) |
84 |
out << "<li>Conveyor error</li>\n"; |
85 |
|
86 |
if (powerFailure) |
87 |
out << "<li>Power failure</li>\n"; |
88 |
|
89 |
out << "</ul>\n"; |
90 |
|
91 |
hasCritical = true; |
92 |
} |
93 |
} |
94 |
|
95 |
if (hasCritical == false) |
96 |
{ |
97 |
out << "<i>No critical installations found</i>\n"; |
98 |
} |
99 |
|
100 |
}> |
101 |
|
102 |
<&footer> |
103 |
</&footer> |