4 |
#include <tntdb/result.h> |
#include <tntdb/result.h> |
5 |
#include <tntdb/row.h> |
#include <tntdb/row.h> |
6 |
|
|
|
//#include <vector> |
|
|
#include <sstream> |
|
|
|
|
|
/* |
|
|
class CriticalInstallation |
|
|
{ |
|
|
public: |
|
|
CriticalInstallation() {} |
|
|
CriticalInstallation(int i, std::string m) : id(i), message(m) {} |
|
|
int id; |
|
|
std::string message; |
|
|
};*/ |
|
|
|
|
7 |
</%pre> |
</%pre> |
8 |
|
|
9 |
<%config> |
<%config> |
16 |
|
|
17 |
<{ |
<{ |
18 |
|
|
19 |
|
reply.setHeader("Refresh", "120"); |
20 |
|
|
21 |
//std::vector<CriticalInstallation> criticals; |
tntdb::Connection conn = tntdb::connectCached(dburl); |
|
|
|
|
tntdb::Connection conn = tntdb::connect(dburl); |
|
|
|
|
|
/* |
|
|
tntdb::Result res = conn.select("SELECT id FROM installation WHERE commerror = true"); |
|
|
for (int i=0; i<res.size(); ++i) |
|
|
{ |
|
|
criticals.push_back(CriticalInstallation(res[i].getInt(0), std::string("Communication Error"))); |
|
|
}*/ |
|
22 |
|
|
23 |
|
|
24 |
std::string query1; |
std::string query1; |
25 |
query1 += "SELECT c.name, i.description, i.id "; |
query1 += "SELECT c.name, i.description, i.id, i.commerror "; |
26 |
query1 += "FROM installation i INNER JOIN customer c "; |
query1 += "FROM installation i INNER JOIN customer c "; |
27 |
query1 += "ON i.customerid = c.id"; |
query1 += "ON i.customerid = c.id"; |
28 |
|
|
30 |
tntdb::Result inst_res = conn.select(query1); |
tntdb::Result inst_res = conn.select(query1); |
31 |
|
|
32 |
|
|
|
|
|
33 |
std::string query2; |
std::string query2; |
34 |
query2 += "SELECT commerror,temperature,flamedetector,conveyorerror,powerfailure "; |
query2 += "SELECT temperature,flamedetector,conveyorerror,powerfailure "; |
35 |
query2 += "FROM logtable "; |
query2 += "FROM logtable "; |
|
query2 += "INNER JOIN installation "; |
|
|
query2 += "ON logtable.installationnr = installation.id "; |
|
36 |
query2 += "WHERE installationnr = :v1 "; |
query2 += "WHERE installationnr = :v1 "; |
37 |
query2 += "ORDER BY messagenr DESC "; |
query2 += "ORDER BY messagenr DESC,logtime DESC "; |
38 |
query2 += "LIMIT 1"; |
query2 += "LIMIT 1"; |
39 |
|
|
40 |
|
|
41 |
tntdb::Statement st = conn.prepare(query2); |
tntdb::Statement st = conn.prepare(query2); |
42 |
|
|
43 |
std::ostream& out = reply.out(); |
std::ostream& out = reply.out(); |
44 |
|
|
45 |
for (int i=0; i<inst_res.size(); i++) |
bool hasCritical = false; |
46 |
|
|
47 |
|
for (unsigned i=0; i<inst_res.size(); i++) |
48 |
{ |
{ |
49 |
int id = inst_res[i].getInt(2); |
int id = inst_res[i].getInt(2); |
50 |
st.clear(); |
st.clear(); |
52 |
st.setInt("v1", id); |
st.setInt("v1", id); |
53 |
tntdb::Result res = st.select(); |
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) |
if (res.size() > 0) |
62 |
{ |
{ |
63 |
bool commerror = res[0].getBool(0); |
temperature = res[0].getInt(0); |
64 |
int temperature = res[0].getInt(1); |
flameDetector = res[0].getBool(1); |
65 |
bool flameDetector = res[0].getBool(2); |
conveyorError = res[0].getBool(2); |
66 |
bool conveyorError = res[0].getBool(3); |
powerFailure = res[0].getBool(3); |
67 |
bool powerFailure = res[0].getBool(4); |
} |
68 |
|
|
69 |
if (commerror || temperature > 90 || flameDetector == false || conveyorError || powerFailure) |
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"; |
out << "<a href='installationdetails?id=" << id << "'><b>" << inst_res[i].getString(0) << "</b> : " << inst_res[i].getString(1) << "<br></a>\n"; |
72 |
out << "<ul>"; |
out << "<ul>"; |
73 |
|
|
74 |
if (temperature > 90) |
if (temperature > 90) |
75 |
out << "<li>High temperature</li>\n"; |
out << "<li>High temperature</li>\n"; |
76 |
|
|
77 |
if (commerror) |
if (commerror) |
78 |
out << "<li>Communication error</li>\n"; |
out << "<li>Communication error</li>\n"; |
79 |
|
|
80 |
if (flameDetector == false) |
if (flameDetector == false) |
81 |
out << "<li>No flames</li>\n"; |
out << "<li>No flames</li>\n"; |
82 |
|
|
83 |
if (conveyorError) |
if (conveyorError) |
84 |
out << "<li>Conveyor error</li>\n"; |
out << "<li>Conveyor error</li>\n"; |
85 |
|
|
86 |
if (powerFailure) |
if (powerFailure) |
87 |
out << "<li>Power failure</li>\n"; |
out << "<li>Power failure</li>\n"; |
88 |
|
|
89 |
out << "</ul>\n"; |
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> |
<&footer> |