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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 83 by torben, Wed Nov 28 17:03:27 2007 UTC revision 101 by torben, Thu Nov 29 13:59:21 2007 UTC
# Line 3  Line 3 
3  #include <tntdb/connection.h>  #include <tntdb/connection.h>
4  #include <tntdb/result.h>  #include <tntdb/result.h>
5  #include <tntdb/row.h>  #include <tntdb/row.h>
6    
7    #include <sstream>
8    
9    #include "common.h"
10  </%pre>  </%pre>
11    
12  <%config>  <%config>
# Line 18  bool isAdmin; Line 22  bool isAdmin;
22  int id;  int id;
23  </%args>  </%args>
24    
25    <{
26    if (userName.size() == 0)
27    {
28            reply.setHeader("Location", "index");
29            return HTTP_MOVED_TEMPORARILY;
30    }
31    }>
32    
33    
34  <&header title="Customer Administration">  <&header title="Customer Administration">
35  </&header>  </&header>
36    
37    
38  <{  <{
39    
40  if (userName.size() == 0)  if (id == -1)
41      reply.setHeader("Refresh", "0; url=login");          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  tntdb::Connection conn = tntdb::connect(dburl);  tntdb::Connection conn = tntdb::connect(dburl);
50    
51    
52    std::string submit = qparam.param("submit");
53    if (submit == "1")
54    {
55            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    
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    
70                    reply.setHeader("Location", "adm_customer_list");
71                    return HTTP_MOVED_TEMPORARILY;
72            }
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                    reply.out() << "<i>Customer updated</i><br>\n";
80            }
81    
82    }
83    
84    
85    std::string name;
86    std::string address;
87    std::string phone;
88    std::string contact;
89    
90    bool showForm = true;
91    
92    if (id != -1)
93    {
94            std::stringstream query;
95            query << "SELECT name,address, phonenr,contactperson FROM customer WHERE id = " << id;
96            tntdb::Result res = conn.select(query.str());
97    
98            if (res.size() > 0)
99            {
100                    name = res[0].getString(0);
101                    address = res[0].getString(1);
102                    phone = res[0].getString(2);
103                    contact = res[0].getString(3);
104            }
105    
106            else
107            {
108                    reply.out() << "<p><i>Invalid customer ID !</i></p>\n";
109                    showForm = false;
110            }
111    }
112    
113    if (showForm)
114    {
115    }>
116    
117    <form method="post" action="adm_customer_edit">
118    <table border="0">
119    <tr>
120      <td>Name: </td>
121      <td><input type="text" name="name" size="40" value="<$ name $>"></td>
122    </tr>
123    <tr>
124      <td valign="top">Address: </td>
125      <td><textarea name="address" cols=30 rows=4><$ address $></textarea></td>
126    </tr>
127    <tr>
128      <td>Phone:</td>
129      <td><input type="text" name="phone" value="<$ phone $>"></td>
130    </tr>
131    <tr>
132      <td>Contact:</td>  
133      <td><input type="text" name="contact" value="<$ contact $>"></td>
134    </tr>
135    <tr>
136      <td>&nbsp;</td>
137      <td><input type="submit"><input type="reset"></td>
138    </tr>
139    </table>
140    <input type="hidden" name="id" value="<$ id $>">
141    <input type="hidden" name="submit" value="1">
142    </form>
143    
144    <br>
145    <form method="post" action="adm_customer_delete">
146    <input type="hidden" name="id" value="<$ id $>">
147    <input type="submit" value="Delete">
148    </form>
149    
150    <{
151    }
152    
153    
154  }>  }>
155    
156  <&footer>  <&footer>

Legend:
Removed from v.83  
changed lines
  Added in v.101

  ViewVC Help
Powered by ViewVC 1.1.20