<%pre> #include #include #include #include #include #include "common.h" <%config> dburl; <%session scope="global"> std::string userName; <%args> int id; int customerid; std::string name; <{ if (userName.size() == 0) { reply.setHeader("Location", "index"); return HTTP_MOVED_TEMPORARILY; } }> <&header title="Installation Administration"> <{ if (id == -1) reply.out() << "

New installation

\n"; else reply.out() << "

Modify installation

\n"; reply.out() << ""; reply.sout() << "<< back to installation list"; reply.out() << "

"; tntdb::Connection conn = tntdb::connectCached(dburl); std::string submit = qparam.param("submit"); if (submit == "1") { std::string form_description = trim(qparam.param("description")); std::string form_address = trim(qparam.param("address")); std::string form_furnacetype = trim(qparam.param("furnacetype")); std::string form_phonenr = trim(qparam.param("phonenr")); std::string form_imei = trim(qparam.param("imei")); int form_updaterate = atoi(trim(qparam.param("updaterate")).c_str()); if (id == -1) { tntdb::Statement st = conn.prepare( "INSERT INTO installation (customerid,description,address,furnacetype, installationphonenr,imei,updaterate ) values (:v1,:v2,:v3,:v4,:v5,:v6,:v7)"); st.setInt("v1", customerid).setString("v2", form_description).setString("v3", form_address).setString("v4", form_furnacetype); st.setString("v5", form_phonenr).setString("v6",form_imei).setInt("v7", form_updaterate); st.execute(); std::stringstream url; url << "adm_installation_list?customerid=" << customerid << "&name=" << name; reply.setHeader("Location", url.str()); return HTTP_MOVED_TEMPORARILY; } else { tntdb::Statement st = conn.prepare( "UPDATE installation SET description=:v1, address=:v2, furnacetype=:v3, installationphonenr=:v4, imei=:v5, updaterate=:v6 WHERE id=:v7"); st.setString("v1", form_description).setString("v2", form_address).setString("v3", form_furnacetype).setString("v4", form_phonenr); st.setString("v5", form_imei); st.setInt("v6", form_updaterate).setInt("v7", id); st.execute(); reply.out() << "Installation updated
\n"; } } std::string description; std::string address; std::string furnacetype; std::string phonenr; std::string imei; std::string updaterate; bool showForm = true; if (id != -1) { std::stringstream query; query << "SELECT description,address, furnacetype,installationphonenr,imei,updaterate FROM installation WHERE id = " << id; tntdb::Result res = conn.select(query.str()); if (res.size() > 0) { description = res[0].getString(0); address = res[0].getString(1); furnacetype = res[0].getString(2); phonenr = res[0].getString(3); imei = res[0].getString(4); updaterate = res[0].getString(5); } else { reply.out() << "

Invalid installation ID !

\n"; showForm = false; } } if (showForm) { }>
Description:
Address:
Furnace type:
Phone nr:
IMEI nr
Update rate*
 

*: Update rate is in minutes.

<{ if (id != -1) { }>
<{ } //fi (id != -1) } //fi (showForm) }> <&footer>