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

Contents of /trunk/tntnet/dynamic/adm_customer_edit.ecpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 126 - (show annotations) (download)
Sun Dec 2 20:26:43 2007 UTC (16 years, 5 months ago) by torben
File size: 3259 byte(s)
Silenced compiler warnings

1 <%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 </%args>
23
24 <{
25 if (userName.size() == 0)
26 {
27 reply.setHeader("Location", "index");
28 return HTTP_MOVED_TEMPORARILY;
29 }
30 }>
31
32
33 <&header title="Customer Administration">
34 </&header>
35
36
37 <{
38
39 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 reply.out() << "</a><br>";
47
48 tntdb::Connection conn = tntdb::connect(dburl);
49
50
51 std::string submit = qparam.param("submit");
52 if (submit == "1")
53 {
54 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
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
69 reply.setHeader("Location", "adm_customer_list");
70 return HTTP_MOVED_TEMPORARILY;
71 }
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
78 reply.out() << "<i>Customer updated</i><br>\n";
79 }
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 }>
115
116 <form method="post" action="adm_customer_edit">
117 <table border="0">
118 <tr>
119 <td>Name: </td>
120 <td><input type="text" name="name" size="40" value="<$ name $>"></td>
121 </tr>
122 <tr>
123 <td valign="top">Address: </td>
124 <td><textarea name="address" cols=30 rows=4><$ address $></textarea></td>
125 </tr>
126 <tr>
127 <td>Phone:</td>
128 <td><input type="text" name="phone" value="<$ phone $>"></td>
129 </tr>
130 <tr>
131 <td>Contact:</td>
132 <td><input type="text" name="contact" value="<$ contact $>"></td>
133 </tr>
134 <tr>
135 <td>&nbsp;</td>
136 <td><input type="submit"><input type="reset"></td>
137 </tr>
138 </table>
139 <input type="hidden" name="id" value="<$ id $>">
140 <input type="hidden" name="submit" value="1">
141 </form>
142
143 <br>
144 <form method="post" action="adm_customer_delete">
145 <input type="hidden" name="id" value="<$ id $>">
146 <input type="submit" value="Delete">
147 </form>
148
149 <{
150 }
151
152
153 }>
154
155 <&footer>
156 </&footer>

  ViewVC Help
Powered by ViewVC 1.1.20