1 |
torben |
83 |
<%pre> |
2 |
|
|
#include <tntdb/connect.h> |
3 |
|
|
#include <tntdb/connection.h> |
4 |
|
|
#include <tntdb/result.h> |
5 |
|
|
#include <tntdb/row.h> |
6 |
torben |
90 |
|
7 |
|
|
#include <sstream> |
8 |
|
|
|
9 |
|
|
#include "common.h" |
10 |
torben |
83 |
</%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 |
|
|
</%args> |
23 |
|
|
|
24 |
torben |
94 |
<{ |
25 |
|
|
if (userName.size() == 0) |
26 |
|
|
{ |
27 |
|
|
reply.setHeader("Location", "index"); |
28 |
|
|
return HTTP_MOVED_TEMPORARILY; |
29 |
|
|
} |
30 |
|
|
}> |
31 |
|
|
|
32 |
|
|
|
33 |
torben |
83 |
<&header title="Customer Administration"> |
34 |
|
|
</&header> |
35 |
torben |
90 |
|
36 |
|
|
|
37 |
torben |
83 |
<{ |
38 |
|
|
|
39 |
torben |
90 |
if (id == -1) |
40 |
|
|
reply.out() << "<h2>New Customer</h2>\n"; |
41 |
|
|
else |
42 |
|
|
reply.out() << "<h2>Modify customer</h2>\n"; |
43 |
|
|
|
44 |
|
|
reply.out() << "<a href='adm_customer_list'>"; |
45 |
|
|
reply.sout() << "<< back to customer list"; |
46 |
torben |
171 |
reply.out() << "</a><br><br>"; |
47 |
torben |
90 |
|
48 |
torben |
195 |
tntdb::Connection conn = tntdb::connectCached(dburl); |
49 |
torben |
83 |
|
50 |
torben |
90 |
|
51 |
|
|
std::string submit = qparam.param("submit"); |
52 |
|
|
if (submit == "1") |
53 |
|
|
{ |
54 |
torben |
93 |
std::string form_name = trim(qparam.param("name")); |
55 |
|
|
std::string form_address = trim(qparam.param("address")); |
56 |
|
|
std::string form_phone = trim(qparam.param("phone")); |
57 |
|
|
std::string form_contact = trim(qparam.param("contact")); |
58 |
torben |
90 |
|
59 |
|
|
|
60 |
|
|
if (id == -1) |
61 |
|
|
{ |
62 |
|
|
tntdb::Statement st = conn.prepare("INSERT INTO customer (name,address,phonenr,contactperson) values (:v1, :v2, :v3, :v4)"); |
63 |
|
|
st.setString("v1", form_name).setString("v2", form_address).setString("v3", form_phone).setString("v4", form_contact); |
64 |
|
|
st.execute(); |
65 |
|
|
|
66 |
|
|
//tntdb::Value v = conn.selectValue("SELECT lastval()"); //get the auto-generated id |
67 |
|
|
//id = v.getInt(); |
68 |
torben |
94 |
|
69 |
|
|
reply.setHeader("Location", "adm_customer_list"); |
70 |
|
|
return HTTP_MOVED_TEMPORARILY; |
71 |
torben |
90 |
} |
72 |
|
|
else |
73 |
|
|
{ |
74 |
|
|
tntdb::Statement st = conn.prepare("UPDATE customer SET name=:v1, address=:v2, phonenr=:v3, contactperson=:v4 WHERE id=:v5"); |
75 |
|
|
st.setString("v1", form_name).setString("v2", form_address).setString("v3", form_phone).setString("v4", form_contact).setInt("v5", id); |
76 |
|
|
st.execute(); |
77 |
torben |
101 |
|
78 |
|
|
reply.out() << "<i>Customer updated</i><br>\n"; |
79 |
torben |
90 |
} |
80 |
|
|
|
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
|
84 |
|
|
std::string name; |
85 |
|
|
std::string address; |
86 |
|
|
std::string phone; |
87 |
|
|
std::string contact; |
88 |
|
|
|
89 |
|
|
bool showForm = true; |
90 |
|
|
|
91 |
|
|
if (id != -1) |
92 |
|
|
{ |
93 |
|
|
std::stringstream query; |
94 |
|
|
query << "SELECT name,address, phonenr,contactperson FROM customer WHERE id = " << id; |
95 |
|
|
tntdb::Result res = conn.select(query.str()); |
96 |
|
|
|
97 |
|
|
if (res.size() > 0) |
98 |
|
|
{ |
99 |
|
|
name = res[0].getString(0); |
100 |
|
|
address = res[0].getString(1); |
101 |
|
|
phone = res[0].getString(2); |
102 |
|
|
contact = res[0].getString(3); |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
else |
106 |
|
|
{ |
107 |
|
|
reply.out() << "<p><i>Invalid customer ID !</i></p>\n"; |
108 |
|
|
showForm = false; |
109 |
|
|
} |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
if (showForm) |
113 |
|
|
{ |
114 |
torben |
83 |
}> |
115 |
|
|
|
116 |
torben |
181 |
<script type="text/javascript" language="JavaScript" src="/md5.js"></script> |
117 |
|
|
<script type="text/javascript" language="JavaScript" src="/trim.js"></script> |
118 |
|
|
<script type="text/javascript"> |
119 |
|
|
|
120 |
|
|
function validateCustomerForm() |
121 |
|
|
{ |
122 |
|
|
var form = document.customerform; |
123 |
|
|
form.name.value = trim(form.name.value); |
124 |
|
|
|
125 |
|
|
if (form.name.value.length < 3) |
126 |
|
|
{ |
127 |
|
|
alert("Name must at least be 3 characters"); |
128 |
|
|
return false; |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
return true; |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
</script> |
135 |
|
|
|
136 |
|
|
<form method="post" action="adm_customer_edit" name="customerform" onsubmit="return validateCustomerForm();"> |
137 |
torben |
90 |
<table border="0"> |
138 |
|
|
<tr> |
139 |
|
|
<td>Name: </td> |
140 |
|
|
<td><input type="text" name="name" size="40" value="<$ name $>"></td> |
141 |
|
|
</tr> |
142 |
|
|
<tr> |
143 |
|
|
<td valign="top">Address: </td> |
144 |
|
|
<td><textarea name="address" cols=30 rows=4><$ address $></textarea></td> |
145 |
|
|
</tr> |
146 |
|
|
<tr> |
147 |
|
|
<td>Phone:</td> |
148 |
|
|
<td><input type="text" name="phone" value="<$ phone $>"></td> |
149 |
|
|
</tr> |
150 |
|
|
<tr> |
151 |
|
|
<td>Contact:</td> |
152 |
|
|
<td><input type="text" name="contact" value="<$ contact $>"></td> |
153 |
|
|
</tr> |
154 |
|
|
<tr> |
155 |
|
|
<td> </td> |
156 |
|
|
<td><input type="submit"><input type="reset"></td> |
157 |
|
|
</tr> |
158 |
|
|
</table> |
159 |
|
|
<input type="hidden" name="id" value="<$ id $>"> |
160 |
|
|
<input type="hidden" name="submit" value="1"> |
161 |
|
|
</form> |
162 |
|
|
|
163 |
torben |
179 |
<{ |
164 |
|
|
if (id != -1) |
165 |
|
|
{ |
166 |
|
|
}> |
167 |
torben |
90 |
<br> |
168 |
torben |
190 |
<br> |
169 |
torben |
179 |
<form method="post" action="adm_customer_delete" onsubmit="return confirm('Are you sure?\\nThis will delete all related installations and logdata','Delete customer');"> |
170 |
torben |
90 |
<input type="hidden" name="id" value="<$ id $>"> |
171 |
torben |
171 |
<input type="submit" value="Delete this customer"> |
172 |
torben |
90 |
</form> |
173 |
|
|
|
174 |
|
|
<{ |
175 |
torben |
179 |
} //fi (id != -1) |
176 |
|
|
} //fi (showForm) |
177 |
torben |
90 |
}> |
178 |
|
|
|
179 |
torben |
83 |
<&footer> |
180 |
|
|
</&footer> |