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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 94 - (hide annotations) (download)
Thu Nov 29 08:04:13 2007 UTC (16 years, 6 months ago) by torben
File size: 3222 byte(s)
Replace HTTP Refresh: redirection  with Location:

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

  ViewVC Help
Powered by ViewVC 1.1.20