/[H9]/trunk/tntnet/dynamic/critical.ecpp
ViewVC logotype

Annotation of /trunk/tntnet/dynamic/critical.ecpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 122 - (hide annotations) (download)
Sun Dec 2 16:56:14 2007 UTC (16 years, 6 months ago) by torben
File size: 2410 byte(s)
* Finished critical list
* Moved <ul> style from customerlist to stylesheet
* Added image alt-tags to installationdetails
* Safer login via prepeared statements



1 torben 71 <%pre>
2     #include <tntdb/connect.h>
3     #include <tntdb/connection.h>
4     #include <tntdb/result.h>
5     #include <tntdb/row.h>
6 torben 104
7 torben 122 //#include <vector>
8     #include <sstream>
9 torben 104
10 torben 122 /*
11 torben 104 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 torben 122 };*/
19 torben 104
20 torben 71 </%pre>
21    
22 torben 68 <%config>
23     dburl;
24     </%config>
25    
26     <&header title="Critical systems">
27     </&header>
28 torben 104 <h2>Critical systems</h2>
29    
30 torben 71 <{
31 torben 68
32    
33 torben 122 //std::vector<CriticalInstallation> criticals;
34 torben 104
35     tntdb::Connection conn = tntdb::connect(dburl);
36    
37 torben 122 /*
38 torben 104 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 torben 122 }*/
43 torben 104
44 torben 111
45 torben 122 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 torben 111
50 torben 122
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 torben 71 }>
112    
113 torben 68 <&footer>
114     </&footer>

  ViewVC Help
Powered by ViewVC 1.1.20