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 |
for (int i=0; i<inst_res.size(); i++) |
45 |
{ |
46 |
int id = inst_res[i].getInt(2); |
47 |
st.clear(); |
48 |
|
49 |
st.setInt("v1", id); |
50 |
tntdb::Result res = st.select(); |
51 |
|
52 |
if (res.size() > 0) |
53 |
{ |
54 |
bool commerror = res[0].getBool(0); |
55 |
int temperature = res[0].getInt(1); |
56 |
bool flameDetector = res[0].getBool(2); |
57 |
bool conveyorError = res[0].getBool(3); |
58 |
bool powerFailure = res[0].getBool(4); |
59 |
|
60 |
if (commerror || temperature > 90 || flameDetector == false || conveyorError || powerFailure) |
61 |
{ |
62 |
out << "<a href='installationdetails?id=" << id << "'><b>" << inst_res[i].getString(0) << "</b> : " << inst_res[i].getString(1) << "<br></a>\n"; |
63 |
out << "<ul>"; |
64 |
|
65 |
if (temperature > 90) |
66 |
out << "<li>High temperature</li>\n"; |
67 |
|
68 |
if (commerror) |
69 |
out << "<li>Communication error</li>\n"; |
70 |
|
71 |
if (flameDetector == false) |
72 |
out << "<li>No flames</li>\n"; |
73 |
|
74 |
if (conveyorError) |
75 |
out << "<li>Conveyor error</li>\n"; |
76 |
|
77 |
if (powerFailure) |
78 |
out << "<li>Power failure</li>\n"; |
79 |
|
80 |
out << "</ul>\n"; |
81 |
|
82 |
|
83 |
} |
84 |
} |
85 |
} |
86 |
|
87 |
}> |
88 |
|
89 |
<&footer> |
90 |
</&footer> |