diff --git a/tc/tc0900.cpp b/tc/tc0900.cpp index b8b834d67..d5c92d7ed 100755 --- a/tc/tc0900.cpp +++ b/tc/tc0900.cpp @@ -6,7 +6,10 @@ #include #include #include +#include #include +#include +#include #include #include #include @@ -675,8 +678,110 @@ void TConvert_archives::convert_table(const char * tablename, TArray & fieldlist } +static void build_xml_filename(TFilename& name, bool remote) +{ + const long n = dongle().number(); + name.format("tc_%05ld", n); + if (n == 0) // Le chiavi di sviluppo sono tutte 0, uso il nome della stazione + { + char host[80]; + xvt_sys_get_host_name(host, sizeof(host)); + name << host; + name.replace(' ', '_'); + if (remote) + { + TString str; + time_t t; time(&t); str = ctime(&t); + + str.rtrim(1); + name << '_' << str; + name.replace(' ', '_'); + name.replace(':', '_'); + } + } + name.ext("xml"); +} + +static TXmlItem& find_or_create_child(TXmlItem& root, const char* tag, bool reset = false) +{ + TXmlItem* pitem = root.FindFirstChild(tag); + if (pitem == NULL) + pitem = &root.AddChild(tag); + else + { + if (reset) + { + pitem->Destroy(); + pitem->SetTag(tag); + } + } + return *pitem; +} + +static TXmlItem& set_attr(TXmlItem& root, const char* name, const char* value) +{ + TXmlItem& c = root.AddChild("attr"); + c.SetAttr("Name", name); + + TString str = value; str.trim(); + c.SetAttr("Value", str); + return c; +} + +static bool save_campo_xml() +{ + TFilename filename; build_xml_filename(filename, false); + + TXmlItem root; + + root.SetTag("Campo"); + + TXmlItem& system = find_or_create_child(root, "system"); + + TFilename str; + xvt_sys_get_host_name(str.get_buffer(), str.size()); + set_attr(system, "Host", str); + xvt_sys_get_user_name(str.get_buffer(), str.size()); + set_attr(system, "User", str); + time_t t; time(&t); str = ctime(&t); + set_attr(system, "Time", str); + xvt_sys_get_version(str.get_buffer(), NULL, str.size()); + set_attr(system, "O.S.", str); + + TXmlItem& study = find_or_create_child(root, "study", true); + TXmlItem& firm = study.AddChild("firm"); + + set_attr(study, "DataPath", firm2dir(-1)); + set_attr(firm, "Code", format("%ld", prefix().firm().codice())); + set_attr(firm, "RagSoc", prefix().firm().ragione_sociale()); + + root.Save(filename); + return filename.exist(); +} + +static bool send_firm_xml() +{ + TWait_cursor waiter; + bool ok = save_campo_xml(); + if (ok && (xvt_net_get_status() & 0x4) != 0) + { + TSocketClient aga; + CONNID id = aga.QueryConnection("21", "www.aga.it"); + if (id > 0) + { + TFilename local, remote; + build_xml_filename(local, false); + build_xml_filename(remote, true); + ok = aga.FtpSendFile(id, remote, local, "attivazioni", "viagra"); + aga.RemoveConnection(id); + } + } + return ok; +} + void TConvert_archives::convert(bool comtables) { + send_firm_xml(); TArray field_infos; TConfig d(CONFIG_DITTA, "ca"); const bool usepdcc = d.get_bool("UsePdcc"); @@ -984,8 +1089,10 @@ void TConvert_archives::convert(bool comtables) void TConvert_archives::main_loop() { + Tdninst d; + _m = new TConvert_mask; - if (_m->run() == K_ENTER) + if (_m->run() == K_ENTER && d.can_I_run()) convert(_m->get_bool(F_CONVCOM)); delete _m; }