1 |
<%pre> |
2 |
#include <tntdb/connect.h> |
3 |
#include <tntdb/connection.h> |
4 |
#include <tntdb/result.h> |
5 |
#include <tntdb/row.h> |
6 |
|
7 |
|
8 |
std::string createInstallationSelector(tntdb::Connection& conn) |
9 |
{ |
10 |
std::stringstream out; |
11 |
tntdb::Result res = conn.select("SELECT c.name, i.id, i.description FROM customer c INNER JOIN installation i ON c.id = i.customerid ORDER BY name,description"); |
12 |
|
13 |
out << "<select name='installation'>\n"; |
14 |
|
15 |
for (unsigned int i=0; i<res.size(); ++i) |
16 |
{ |
17 |
out << " <option value='" << res[i].getInt(1) << "'>" << res[i].getString(0) << " :: " << res[i].getString(2) << "</option>\n"; |
18 |
} |
19 |
out << "</select>\n"; |
20 |
|
21 |
|
22 |
return out.str(); |
23 |
} |
24 |
|
25 |
|
26 |
</%pre> |
27 |
|
28 |
<%config> |
29 |
dburl; |
30 |
</%config> |
31 |
|
32 |
<%session scope="global"> |
33 |
std::string userName; |
34 |
</%session> |
35 |
|
36 |
<{ |
37 |
if (userName.size() == 0) |
38 |
{ |
39 |
reply.setHeader("Location", "index"); |
40 |
return HTTP_MOVED_TEMPORARILY; |
41 |
} |
42 |
}> |
43 |
|
44 |
|
45 |
<&header title="Send configuration"> |
46 |
</&header> |
47 |
|
48 |
<{ |
49 |
|
50 |
tntdb::Connection conn = tntdb::connect(dburl); |
51 |
|
52 |
std::ostream& out = reply.out(); |
53 |
|
54 |
|
55 |
if (qparam.param("command").size() > 0) |
56 |
{ |
57 |
std::string command = qparam.param("command"); |
58 |
std::string installation = (command == "2" ? qparam.param("installation") : "null"); |
59 |
std::stringstream sql; |
60 |
sql << "INSERT INTO command (created,commandid, installationid) "; |
61 |
sql << "VALUES (now(), " << command << ", " << installation << ")"; |
62 |
conn.execute( sql.str() ); |
63 |
} |
64 |
|
65 |
}> |
66 |
|
67 |
<h2>Send configuration</h2> |
68 |
|
69 |
<table border=1 align='center' cellspacing=0 cellpadding=5> |
70 |
<tr> |
71 |
<th colspan='2'> |
72 |
Send Commands |
73 |
</th> |
74 |
</tr> |
75 |
<tr> |
76 |
<td> |
77 |
<form method='post' action='adm_send_config'> |
78 |
<input type='hidden' name='command' value='1'> |
79 |
<input type='submit' value='Send configuration to all'> |
80 |
</form> |
81 |
</td> |
82 |
<td> |
83 |
<form method='post' action='adm_send_config'> |
84 |
<input type='hidden' name='command' value='2'> |
85 |
<$$ createInstallationSelector( conn ) $><br> |
86 |
<input type='submit' value='Send configuration to selected'> |
87 |
</form> |
88 |
</td> |
89 |
</tr> |
90 |
</table> |
91 |
|
92 |
|
93 |
<{ |
94 |
|
95 |
|
96 |
////////////////////////////////////////////////////////////////////////////////////// |
97 |
// Command Log |
98 |
|
99 |
/* commandid 1 -> Send to all |
100 |
* commandid 2 -> Send to one |
101 |
*/ |
102 |
std::string query; |
103 |
query += "SELECT name,description,date_trunc('second',created) AS created, date_trunc('second', executed) AS executed,commandid,installationid "; |
104 |
query += "FROM command "; |
105 |
query += "LEFT JOIN installation ON command.installationid = installation.id "; |
106 |
query += "LEFT JOIN customer ON installation.customerid = customer.id "; |
107 |
query += "ORDER BY created DESC "; |
108 |
|
109 |
tntdb::Result res = conn.select(query); |
110 |
|
111 |
out << "<p align='center'><b>Command history</b></p>\n"; |
112 |
out << "<table cellspacing='0' align='center' border='1'>"; |
113 |
out << "<tr><th> Created </th><th> Executed </th><th>Command</th></tr>\n"; |
114 |
|
115 |
for (unsigned int i=0; i<res.size(); ++i) |
116 |
{ |
117 |
out << "<tr><td> " << res[i].getString(2) << " </td>"; |
118 |
out << "<td> " << res[i].getString(3) << " </td>"; |
119 |
|
120 |
out << "<td> "; |
121 |
|
122 |
switch ( res[i].getInt(4) ) |
123 |
{ |
124 |
case 1: |
125 |
out << "Send configuration to All"; |
126 |
break; |
127 |
case 2: |
128 |
out << "Send configuration to <i>" << res[i].getString(0) << " :: " << res[i].getString(1) << "</i>"; |
129 |
break; |
130 |
default: |
131 |
out << "Unknown command"; |
132 |
break; |
133 |
} |
134 |
out << " </td>\n"; |
135 |
|
136 |
out << "</tr>\n"; |
137 |
} |
138 |
|
139 |
|
140 |
}> |
141 |
|
142 |
</table> |
143 |
|
144 |
<&footer> |
145 |
</&footer> |