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