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 |
|
|
bool isAdmin; |
19 |
|
|
</%session> |
20 |
|
|
|
21 |
|
|
<%args> |
22 |
|
|
int id; |
23 |
|
|
</%args> |
24 |
|
|
|
25 |
|
|
<&header title="Customer Administration"> |
26 |
|
|
</&header> |
27 |
torben |
90 |
|
28 |
|
|
|
29 |
|
|
|
30 |
torben |
83 |
<{ |
31 |
|
|
|
32 |
|
|
if (userName.size() == 0) |
33 |
torben |
92 |
{ |
34 |
torben |
83 |
reply.setHeader("Refresh", "0; url=login"); |
35 |
torben |
92 |
return HTTP_OK; |
36 |
|
|
} |
37 |
torben |
83 |
|
38 |
torben |
90 |
if (id == -1) |
39 |
|
|
reply.out() << "<h2>New Customer</h2>\n"; |
40 |
|
|
else |
41 |
|
|
reply.out() << "<h2>Modify customer</h2>\n"; |
42 |
|
|
|
43 |
|
|
reply.out() << "<a href='adm_customer_list'>"; |
44 |
|
|
reply.sout() << "<< back to customer list"; |
45 |
|
|
reply.out() << "</a><br>"; |
46 |
|
|
|
47 |
torben |
83 |
tntdb::Connection conn = tntdb::connect(dburl); |
48 |
|
|
|
49 |
torben |
90 |
|
50 |
|
|
std::string submit = qparam.param("submit"); |
51 |
|
|
if (submit == "1") |
52 |
|
|
{ |
53 |
|
|
std::string form_name = qparam.param("name"); |
54 |
|
|
std::string form_address = qparam.param("address"); |
55 |
|
|
std::string form_phone = qparam.param("phone"); |
56 |
|
|
std::string form_contact = qparam.param("contact"); |
57 |
|
|
|
58 |
|
|
|
59 |
|
|
if (id == -1) |
60 |
|
|
{ |
61 |
|
|
tntdb::Statement st = conn.prepare("INSERT INTO customer (name,address,phonenr,contactperson) values (:v1, :v2, :v3, :v4)"); |
62 |
|
|
st.setString("v1", form_name).setString("v2", form_address).setString("v3", form_phone).setString("v4", form_contact); |
63 |
|
|
st.execute(); |
64 |
|
|
|
65 |
|
|
//tntdb::Value v = conn.selectValue("SELECT lastval()"); //get the auto-generated id |
66 |
|
|
//id = v.getInt(); |
67 |
|
|
reply.setHeader("Refresh", "0; url=adm_customer_list"); |
68 |
|
|
return HTTP_OK; |
69 |
|
|
} |
70 |
|
|
else |
71 |
|
|
{ |
72 |
|
|
tntdb::Statement st = conn.prepare("UPDATE customer SET name=:v1, address=:v2, phonenr=:v3, contactperson=:v4 WHERE id=:v5"); |
73 |
|
|
st.setString("v1", form_name).setString("v2", form_address).setString("v3", form_phone).setString("v4", form_contact).setInt("v5", id); |
74 |
|
|
st.execute(); |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
|
80 |
|
|
std::string name; |
81 |
|
|
std::string address; |
82 |
|
|
std::string phone; |
83 |
|
|
std::string contact; |
84 |
|
|
|
85 |
|
|
bool showForm = true; |
86 |
|
|
|
87 |
|
|
if (id != -1) |
88 |
|
|
{ |
89 |
|
|
std::stringstream query; |
90 |
|
|
query << "SELECT name,address, phonenr,contactperson FROM customer WHERE id = " << id; |
91 |
|
|
tntdb::Result res = conn.select(query.str()); |
92 |
|
|
|
93 |
|
|
if (res.size() > 0) |
94 |
|
|
{ |
95 |
|
|
name = res[0].getString(0); |
96 |
|
|
address = res[0].getString(1); |
97 |
|
|
phone = res[0].getString(2); |
98 |
|
|
contact = res[0].getString(3); |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
else |
102 |
|
|
{ |
103 |
|
|
reply.out() << "<p><i>Invalid customer ID !</i></p>\n"; |
104 |
|
|
showForm = false; |
105 |
|
|
} |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
if (showForm) |
109 |
|
|
{ |
110 |
torben |
83 |
}> |
111 |
|
|
|
112 |
torben |
90 |
<form method="post" action="adm_customer_edit"> |
113 |
|
|
<table border="0"> |
114 |
|
|
<tr> |
115 |
|
|
<td>Name: </td> |
116 |
|
|
<td><input type="text" name="name" size="40" value="<$ name $>"></td> |
117 |
|
|
</tr> |
118 |
|
|
<tr> |
119 |
|
|
<td valign="top">Address: </td> |
120 |
|
|
<td><textarea name="address" cols=30 rows=4><$ address $></textarea></td> |
121 |
|
|
</tr> |
122 |
|
|
<tr> |
123 |
|
|
<td>Phone:</td> |
124 |
|
|
<td><input type="text" name="phone" value="<$ phone $>"></td> |
125 |
|
|
</tr> |
126 |
|
|
<tr> |
127 |
|
|
<td>Contact:</td> |
128 |
|
|
<td><input type="text" name="contact" value="<$ contact $>"></td> |
129 |
|
|
</tr> |
130 |
|
|
<tr> |
131 |
|
|
<td> </td> |
132 |
|
|
<td><input type="submit"><input type="reset"></td> |
133 |
|
|
</tr> |
134 |
|
|
</table> |
135 |
|
|
<input type="hidden" name="id" value="<$ id $>"> |
136 |
|
|
<input type="hidden" name="submit" value="1"> |
137 |
|
|
</form> |
138 |
|
|
|
139 |
|
|
<br> |
140 |
|
|
<form method="post" action="adm_customer_delete"> |
141 |
|
|
<input type="hidden" name="id" value="<$ id $>"> |
142 |
|
|
<input type="submit" value="Delete"> |
143 |
|
|
</form> |
144 |
|
|
|
145 |
|
|
<{ |
146 |
|
|
} |
147 |
|
|
|
148 |
|
|
|
149 |
|
|
}> |
150 |
|
|
|
151 |
torben |
83 |
<&footer> |
152 |
|
|
</&footer> |