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

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

  ViewVC Help
Powered by ViewVC 1.1.20