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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 183 - (hide annotations) (download)
Fri Dec 7 05:32:31 2007 UTC (16 years, 5 months ago) by torben
File size: 6183 byte(s)
Limit IMEI field to 15 characters

1 torben 101 <%pre>
2     #include <tntdb/connect.h>
3     #include <tntdb/connection.h>
4     #include <tntdb/result.h>
5     #include <tntdb/row.h>
6    
7     #include <sstream>
8    
9     #include "common.h"
10     </%pre>
11    
12     <%config>
13     dburl;
14     </%config>
15    
16     <%session scope="global">
17     std::string userName;
18     </%session>
19    
20     <%args>
21     int id;
22     int customerid;
23     std::string name;
24     </%args>
25    
26     <{
27     if (userName.size() == 0)
28     {
29     reply.setHeader("Location", "index");
30     return HTTP_MOVED_TEMPORARILY;
31     }
32     }>
33    
34    
35     <&header title="Installation Administration">
36     </&header>
37    
38    
39     <{
40    
41     if (id == -1)
42     reply.out() << "<h2>New installation</h2>\n";
43     else
44     reply.out() << "<h2>Modify installation</h2>\n";
45    
46     reply.out() << "<a href='adm_installation_list?customerid=" << customerid<< "&name=" << name << "'>";
47     reply.sout() << "<< back to installation list";
48 torben 171 reply.out() << "</a><br><br>";
49 torben 101
50     tntdb::Connection conn = tntdb::connect(dburl);
51    
52    
53     std::string submit = qparam.param("submit");
54     if (submit == "1")
55     {
56     std::string form_description = trim(qparam.param("description"));
57     std::string form_address = trim(qparam.param("address"));
58     std::string form_furnacetype = trim(qparam.param("furnacetype"));
59     std::string form_phonenr = trim(qparam.param("phonenr"));
60     std::string form_imei = trim(qparam.param("imei"));
61     int form_updaterate = atoi(trim(qparam.param("updaterate")).c_str());
62    
63     if (id == -1)
64     {
65     tntdb::Statement st = conn.prepare(
66     "INSERT INTO installation (customerid,description,address,furnacetype, installationphonenr,imei,updaterate ) values (:v1,:v2,:v3,:v4,:v5,:v6,:v7)");
67     st.setInt("v1", customerid).setString("v2", form_description).setString("v3", form_address).setString("v4", form_furnacetype);
68     st.setString("v5", form_phonenr).setString("v6",form_imei).setInt("v7", form_updaterate);
69     st.execute();
70    
71     std::stringstream url;
72     url << "adm_installation_list?customerid=" << customerid << "&name=" << name;
73    
74     reply.setHeader("Location", url.str());
75     return HTTP_MOVED_TEMPORARILY;
76     }
77     else
78     {
79     tntdb::Statement st = conn.prepare(
80     "UPDATE installation SET description=:v1, address=:v2, furnacetype=:v3, installationphonenr=:v4, imei=:v5, updaterate=:v6 WHERE id=:v7");
81     st.setString("v1", form_description).setString("v2", form_address).setString("v3", form_furnacetype).setString("v4", form_phonenr);
82     st.setString("v5", form_imei); st.setInt("v6", form_updaterate).setInt("v7", id);
83     st.execute();
84    
85     reply.out() << "<i>Installation updated</i><br>\n";
86     }
87    
88     }
89    
90    
91     std::string description;
92     std::string address;
93     std::string furnacetype;
94     std::string phonenr;
95     std::string imei;
96     std::string updaterate;
97    
98     bool showForm = true;
99    
100     if (id != -1)
101     {
102     std::stringstream query;
103     query << "SELECT description,address, furnacetype,installationphonenr,imei,updaterate FROM installation WHERE id = " << id;
104     tntdb::Result res = conn.select(query.str());
105    
106     if (res.size() > 0)
107     {
108     description = res[0].getString(0);
109     address = res[0].getString(1);
110     furnacetype = res[0].getString(2);
111     phonenr = res[0].getString(3);
112     imei = res[0].getString(4);
113     updaterate = res[0].getString(5);
114     }
115    
116     else
117     {
118     reply.out() << "<p><i>Invalid installation ID !</i></p>\n";
119     showForm = false;
120     }
121     }
122    
123     if (showForm)
124     {
125     }>
126    
127 torben 181
128     <script type="text/javascript" language="JavaScript" src="/md5.js"></script>
129     <script type="text/javascript" language="JavaScript" src="/trim.js"></script>
130     <script type="text/javascript">
131    
132     function validateInstallationForm()
133     {
134     var form = document.installationform;
135     form.description.value = trim(form.description.value);
136     form.phonenr.value = trim(form.phonenr.value);
137     form.imei.value = trim(form.imei.value);
138     form.updaterate.value = trim(form.updaterate.value);
139    
140     if (form.description.value.length < 3)
141     {
142     alert("Description must be at least 3 characters.");
143     return false;
144     }
145    
146     if (isNaN(form.phonenr.value))
147     {
148     alert("Phonenr may only contain digits");
149     return false;
150     }
151    
152     if (form.phonenr.value.length < 8)
153     {
154     if (!confirm("Phonenr seems rather short, are you sure this is correct"))
155     {
156     return false;
157     }
158     }
159    
160     if (isNaN(form.imei.value))
161     {
162     alert("IMEI may only contain digits");
163     return false;
164     }
165    
166     if (form.imei.value.length != 15)
167     {
168     alert("IMEI must be exactly 15 digits");
169     return false;
170     }
171    
172     if (isNaN(form.updaterate.value))
173     {
174     alert("Update rate may only contain digits");
175     return false;
176     }
177    
178     var updaterate = parseInt(form.updaterate.value);
179    
180     if (form.updaterate.value == "" || updaterate <5 || updaterate > 250)
181     {
182     alert("Update rate must be between 5 and 250\\n(Both inclusive)");
183     return false;
184     }
185    
186    
187     return true;
188     }
189    
190     </script>
191    
192     <form method="post" action="adm_installation_edit" name="installationform" onsubmit="return validateInstallationForm();">
193 torben 101 <table border="0">
194     <tr>
195     <td>Description:</td>
196     <td><input type="text" name="description" size="40" value="<$description$>"></td>
197     </tr>
198     <tr>
199     <td>Address:</td>
200     <td><textarea cols="30" rows="4" name="address"><$address$></textarea></td>
201     </tr>
202     <tr>
203     <td>Furnace type:</td>
204     <td><input type="text" name="furnacetype" size="40" value="<$furnacetype$>"></td>
205     </tr>
206     <tr>
207     <td>Phone nr:</td>
208     <td><input type="text" name="phonenr" size="40" value="<$phonenr$>"></td>
209     </tr>
210     <tr>
211     <td>IMEI nr</td>
212 torben 183 <td><input type="text" name="imei" size="40" maxlength="15" value="<$imei$>"></td>
213 torben 101 </tr>
214     <tr>
215 torben 181 <td>Update rate*</td>
216 torben 101 <td><input type="text" name="updaterate" size="40" value="<$updaterate$>"></td>
217     </tr>
218     <tr>
219     <td>&nbsp;</td>
220     <td><input type="submit"><input type="reset"></td>
221     </tr>
222     </table>
223     <input type="hidden" name="id" value="<$ id $>">
224     <input type="hidden" name="customerid" value="<$ customerid $>">
225     <input type="hidden" name="name" value="<$name$>">
226     <input type="hidden" name="submit" value="1">
227     </form>
228    
229 torben 181 <p>*: Update rate is in minutes.</p>
230    
231 torben 179 <{
232     if (id != -1)
233     {
234     }>
235     <br>
236     <form method="post" action="adm_installation_delete" onsubmit="return confirm('Are you sure ?\\nThis will delete all loggings related to this installation','Delete installation');">
237     <input type="hidden" name="id" value="<$id$>">
238     <input type="hidden" name="customerid" value="<$customerid$>">
239     <input type="hidden" name="name" value="<$name$>">
240     <input type="submit" value="Delete this installation">
241     </form>
242    
243 torben 101
244     <{
245 torben 179 } //fi (id != -1)
246     } //fi (showForm)
247 torben 101 }>
248    
249     <&footer>
250     </&footer>

  ViewVC Help
Powered by ViewVC 1.1.20