/[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 93 by torben, Thu Nov 29 07:34:54 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 20  int id; Line 24  int id;
24    
25  <&header title="Customer Administration">  <&header title="Customer Administration">
26  </&header>  </&header>
27    
28    
29    
30  <{  <{
31    
32  if (userName.size() == 0)  if (userName.size() == 0)
33    {
34      reply.setHeader("Refresh", "0; url=login");      reply.setHeader("Refresh", "0; url=login");
35            return HTTP_OK;
36    }
37    
38    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  tntdb::Connection conn = tntdb::connect(dburl);  tntdb::Connection conn = tntdb::connect(dburl);
48    
49    
50    std::string submit = qparam.param("submit");
51    if (submit == "1")
52    {
53            std::string form_name = trim(qparam.param("name"));
54            std::string form_address = trim(qparam.param("address"));
55            std::string form_phone = trim(qparam.param("phone"));
56            std::string form_contact = trim(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    }>
111    
112    <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>&nbsp;</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  <&footer>  <&footer>

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

  ViewVC Help
Powered by ViewVC 1.1.20