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 |
|
|
<form method="post" action="adm_installation_edit"> |
128 |
|
|
<table border="0"> |
129 |
|
|
<tr> |
130 |
|
|
<td>Description:</td> |
131 |
|
|
<td><input type="text" name="description" size="40" value="<$description$>"></td> |
132 |
|
|
</tr> |
133 |
|
|
<tr> |
134 |
|
|
<td>Address:</td> |
135 |
|
|
<td><textarea cols="30" rows="4" name="address"><$address$></textarea></td> |
136 |
|
|
</tr> |
137 |
|
|
<tr> |
138 |
|
|
<td>Furnace type:</td> |
139 |
|
|
<td><input type="text" name="furnacetype" size="40" value="<$furnacetype$>"></td> |
140 |
|
|
</tr> |
141 |
|
|
<tr> |
142 |
|
|
<td>Phone nr:</td> |
143 |
|
|
<td><input type="text" name="phonenr" size="40" value="<$phonenr$>"></td> |
144 |
|
|
</tr> |
145 |
|
|
<tr> |
146 |
|
|
<td>IMEI nr</td> |
147 |
torben |
104 |
<td><input type="text" name="imei" size="40" maxlength="16" value="<$imei$>"></td> |
148 |
torben |
101 |
</tr> |
149 |
|
|
<tr> |
150 |
|
|
<td>Update rate</td> |
151 |
|
|
<td><input type="text" name="updaterate" size="40" value="<$updaterate$>"></td> |
152 |
|
|
</tr> |
153 |
|
|
<tr> |
154 |
|
|
<td> </td> |
155 |
|
|
<td><input type="submit"><input type="reset"></td> |
156 |
|
|
</tr> |
157 |
|
|
</table> |
158 |
|
|
<input type="hidden" name="id" value="<$ id $>"> |
159 |
|
|
<input type="hidden" name="customerid" value="<$ customerid $>"> |
160 |
|
|
<input type="hidden" name="name" value="<$name$>"> |
161 |
|
|
<input type="hidden" name="submit" value="1"> |
162 |
|
|
</form> |
163 |
|
|
|
164 |
torben |
179 |
<{ |
165 |
|
|
if (id != -1) |
166 |
|
|
{ |
167 |
|
|
}> |
168 |
|
|
<br> |
169 |
|
|
<form method="post" action="adm_installation_delete" onsubmit="return confirm('Are you sure ?\\nThis will delete all loggings related to this installation','Delete installation');"> |
170 |
|
|
<input type="hidden" name="id" value="<$id$>"> |
171 |
|
|
<input type="hidden" name="customerid" value="<$customerid$>"> |
172 |
|
|
<input type="hidden" name="name" value="<$name$>"> |
173 |
|
|
<input type="submit" value="Delete this installation"> |
174 |
|
|
</form> |
175 |
|
|
|
176 |
torben |
101 |
|
177 |
|
|
<{ |
178 |
torben |
179 |
} //fi (id != -1) |
179 |
|
|
} //fi (showForm) |
180 |
torben |
101 |
}> |
181 |
|
|
|
182 |
|
|
<&footer> |
183 |
|
|
</&footer> |