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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 104 by torben, Thu Nov 29 17:06:38 2007 UTC revision 195 by torben, Sat Dec 8 16:47:03 2007 UTC
# Line 3  Line 3 
3  #include <tntdb/connection.h>  #include <tntdb/connection.h>
4  #include <tntdb/result.h>  #include <tntdb/result.h>
5  #include <tntdb/row.h>  #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>  </%pre>
27    
28  <%config>  <%config>
# Line 11  dburl; Line 31  dburl;
31    
32  <%session scope="global">  <%session scope="global">
33  std::string userName;  std::string userName;
 bool isAdmin;  
34  </%session>  </%session>
35    
36  <{  <{
# Line 28  if (userName.size() == 0) Line 47  if (userName.size() == 0)
47    
48  <{  <{
49    
50  tntdb::Connection conn = tntdb::connect(dburl);  tntdb::Connection conn = tntdb::connectCached(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>&nbsp;Created&nbsp;</th><th>&nbsp;Executed&nbsp;</th><th>Command</th></tr>\n";
114    
115    for (unsigned int i=0; i<res.size(); ++i)
116    {
117            out << "<tr><td>&nbsp;" << res[i].getString(2) << "&nbsp;</td>";
118            out << "<td>&nbsp;" << res[i].getString(3) << "&nbsp;</td>";
119    
120            out << "<td>&nbsp;";
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 << "&nbsp;</td>\n";
135    
136            out << "</tr>\n";
137    }
138    
139    
140  }>  }>
141    
142    </table>
143    
144  <&footer>  <&footer>
145  </&footer>  </&footer>

Legend:
Removed from v.104  
changed lines
  Added in v.195

  ViewVC Help
Powered by ViewVC 1.1.20