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

Legend:
Removed from v.89  
changed lines
  Added in v.90

  ViewVC Help
Powered by ViewVC 1.1.20