/[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 94 by torben, Thu Nov 29 08:04:13 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    
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    }>
114    
115    <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  <&footer>  <&footer>

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

  ViewVC Help
Powered by ViewVC 1.1.20