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