From dc8cfaa08168fdd332faded2f78679a2a1904fbe Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 14 Feb 2011 10:43:17 +0000 Subject: 'Ported' export functionality from macrotool. --- server/src/admin_connection.cc | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'server/src/admin_connection.cc') diff --git a/server/src/admin_connection.cc b/server/src/admin_connection.cc index e8c5b02..e470946 100644 --- a/server/src/admin_connection.cc +++ b/server/src/admin_connection.cc @@ -28,6 +28,7 @@ #include "admin_connection.h" #include "admin_rc.h" +#include "admin_export.h" #include "debug.h" @@ -55,7 +56,10 @@ static std::string admin_listactivesessions(Environment &env) std::vector act = env.sessions.activeSessions(); std::vector::iterator i = act.begin(); while(i != act.end()) { - str += "Session " + *i + "\n"; + Session *s = env.sessions.session(*i); + SessionAutolock lock(*s); + str += "Session " + *i + ": "+s->templ+" on "+s->patientid+" "+ + std::string(s->active()?"[active]":"[idle]")+"\n"; i++; } @@ -80,6 +84,8 @@ AdminConnection::~AdminConnection() {} bool AdminConnection::handle(const char *data, size_t size) { + status = 200; // OK + if(data == NULL && size == 0) { DEBUG(admin, "URI: %s\n", uri.c_str()); @@ -89,6 +95,7 @@ bool AdminConnection::handle(const char *data, size_t size) "/sessionunlock?id=[ID] unlock session with [ID] as its session id.\n" "/listactivesessions lists all active sessions on the server.\n" "/flushsessions flushes all active sessions to disc.\n" + "/export?template=[TEMPLATE] export template with name [TEMPLATE] to a\n csf file (comma seperated file, that can be opened in OOCalc or Excel).\n" + admin_rc("footer"); return true; } @@ -106,17 +113,31 @@ bool AdminConnection::handle(const char *data, size_t size) } if(uri == "/flushsessions") { - reply = admin_header(uri) + admin_flush(env) - + admin_rc("footer"); + reply = admin_header(uri) + admin_flush(env) + admin_rc("footer"); + return true; + } + + if(uri == "/export" && args.find("template") != args.end()) { + bool ok; + std::string res = admin_export(env, args["template"], &ok); + if(!ok) reply = admin_header(uri) + res + admin_rc("footer"); + else { + reply = res; + hdrs["Content-Type"] = "text/csv; charset=UTF-8"; + hdrs["Content-Disposition"] = "attachment; filename=\""+args["template"]+".csv\""; + } return true; } if(uri == "/favicon.ico") { + hdrs["Content-Type"] = "image/ico"; reply = admin_rc("favicon"); return true; } - reply = "'" + uri + "' not recognised as a valid command."; + reply = admin_header(uri) + + "'" + uri + "' not recognised as a valid command." + + admin_rc("footer"); return true; } @@ -125,11 +146,10 @@ bool AdminConnection::handle(const char *data, size_t size) void AdminConnection::getReply(Httpd::Reply &r) { - headers_t hdrs; - if(uri == "/favicon.ico") hdrs["Content-Type"] = "image/ico"; - else hdrs["Content-Type"] = "text/html; charset=UTF-8"; + if(hdrs.find("Content-Type") == hdrs.end()) + hdrs["Content-Type"] = "text/html; charset=UTF-8"; r.data = reply; r.headers = hdrs; - r.status = 200; // http 'OK' + r.status = status; // http 'OK' } -- cgit v1.2.3