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

Contents of /trunk/tntnet/dynamic/adm_send_config.ecpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 124 - (show annotations) (download)
Sun Dec 2 19:32:52 2007 UTC (16 years, 5 months ago) by torben
File size: 3244 byte(s)
Finished send configuration

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

  ViewVC Help
Powered by ViewVC 1.1.20