git-svn-id: svn://10.65.10.50/branches/R_10_00@22977 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			252 lines
		
	
	
		
			6.6 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			252 lines
		
	
	
		
			6.6 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <applicat.h>
 | |
| #include <config.h>
 | |
| #include <dongle.h>
 | |
| #include <isam.h>
 | |
| #include <modaut.h>
 | |
| #include <prefix.h>
 | |
| #include <netsock.h>
 | |
| #include <recset.h>
 | |
| #include <utility.h>
 | |
| #include <xml.h>
 | |
| 
 | |
| #include "ba1103.h"
 | |
| 
 | |
| #include <doc.h>
 | |
| #include <mov.h>
 | |
| #include <nditte.h>
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TFirm_isamfile
 | |
| // Prossimamente nelle migliori librerie:
 | |
| // praticamente un TLocalisamfile di un ditta qualsiasi,
 | |
| // normalmente diversa dalla corrente.
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TFirm_isamfile : public TIsamtempfile
 | |
| {
 | |
| protected:
 | |
|   static const TString& build_file_name(int logicnum, long firm);
 | |
| 
 | |
| public:
 | |
|   TFirm_isamfile(int logicnum, long firm = -1);
 | |
| };
 | |
| 
 | |
| const TString& TFirm_isamfile::build_file_name(int logicnum, long codditta)
 | |
| {
 | |
|   // Se codditta < 0 allora usa la ditta corrente;
 | |
|   // Se codditta = 0 allora usa i dati comuni
 | |
|   if (codditta < 0) 
 | |
|     codditta = main_app().get_firm();
 | |
|   TFilename path = firm2dir(codditta);
 | |
|   path.add(logic2table(logicnum));
 | |
|   path.lower(); path.ext("dbf");
 | |
|   if (!path.exist() && codditta > 0)
 | |
|   {
 | |
|     NFCHECK(path, "Impossibile aprire ", (const char*)path);
 | |
|     path = firm2dir(0L);
 | |
|     path.add(logic2table(logicnum));
 | |
|     path.lower(); path.ext("dbf");
 | |
|   }
 | |
|   path.insert("%");
 | |
|   return get_tmp_string() = path;
 | |
| }
 | |
| 
 | |
| TFirm_isamfile::TFirm_isamfile(int lf, long codditta) 
 | |
|               : TIsamtempfile(lf, build_file_name(lf, codditta), false, false)
 | |
| { }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // Utilities
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| // Costruisce il nome del file xml locale o remoto
 | |
| static void build_xml_filename(TFilename& name, bool remote)
 | |
| {
 | |
|   const long n = dongle().number();
 | |
|   name.format("%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)
 | |
|     {
 | |
|       const TDate oggi(TODAY);
 | |
|       name << '_' << oggi.date2ansi();
 | |
|     }
 | |
|   }
 | |
|   name.ext("xml");
 | |
| }
 | |
| 
 | |
| // Cerca un tag figlio e se non lo trova lo crea.  Opzionalmente lo svuota anche.
 | |
| 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 const TString& get_last(long codditta, int lf, const char* field)
 | |
| {
 | |
|   if (prefix_valid())
 | |
|   {
 | |
|     TFirm_isamfile file(lf, codditta);
 | |
|     if (file.last() == NOERR)
 | |
|       return file.get(field);
 | |
|   }
 | |
|   return EMPTY_STRING;
 | |
| }
 | |
| 
 | |
| static int is_active_firm(long codditta)
 | |
| {
 | |
|   if (main_app().get_firm() == codditta)
 | |
|     return 2;
 | |
| 
 | |
|   if (!prefix_valid()) // Non posso scartare nulla a priori
 | |
|     return codditta > 0;
 | |
| 
 | |
|   if (prefix().exist(codditta))
 | |
|   {
 | |
|     int anno = 0;
 | |
|     if (dongle().active(CGAUT))
 | |
|     {
 | |
|       const TDate datareg = get_last(codditta, LF_MOV, MOV_DATAREG);
 | |
|       anno = datareg.year();
 | |
|     }
 | |
| 
 | |
|     if (anno == 0 && dongle().active(VEAUT))
 | |
|       anno = atoi(get_last(codditta, LF_DOC, DOC_ANNO));
 | |
| 
 | |
|     if (anno > 0)
 | |
|     {
 | |
|       const TDate oggi(TODAY);
 | |
|       const int annoscorso = oggi.year()-1;
 | |
|       const int annoprossimo = annoscorso+2;
 | |
|       if (anno >= annoscorso && anno <= annoprossimo)
 | |
|         return 1;
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   return 0;
 | |
| }
 | |
| 
 | |
| static TXmlItem& set_attr(TXmlItem& root, const char* name, const char* value)
 | |
| {
 | |
|   TXmlItem& c = find_or_create_child(root, "attr");
 | |
|   c.SetAttr("Name", name);
 | |
| 
 | |
|   TString str = value; str.trim();
 | |
|   c.SetAttr("Value", str);
 | |
|   return c;
 | |
| }
 | |
| 
 | |
| // Salva o aggiorna il file xml coi dati di installazione
 | |
| bool save_campo_xml()
 | |
| {
 | |
|   TFilename filename; build_xml_filename(filename, false);
 | |
|   
 | |
|   TXmlItem root;
 | |
|   if (!root.Load(filename))
 | |
|     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);
 | |
|   TArray ditte; TPrefix::firms(ditte);
 | |
|   FOR_EACH_ARRAY_ITEM(ditte, i, obj)
 | |
|   {
 | |
|     TAssoc_array& ass = *(TAssoc_array*)obj;
 | |
|     const TString* cod = (TString*)ass.objptr(NDT_CODDITTA);
 | |
|     const int flag = cod ? is_active_firm(atol(*cod)) : 0;
 | |
|     if (flag != 0)
 | |
|     {
 | |
|       TXmlItem& firm = study.AddChild("firm");
 | |
|       FOR_EACH_ASSOC_STRING(ass, h, k, s)
 | |
|       {
 | |
|         if (strlen(s) >= 4) // Scarto codici e flag inutili
 | |
|           firm.SetAttr(k, s);
 | |
|       }
 | |
|       firm.SetAttr("Current", flag == 2);
 | |
|     }
 | |
|   }
 | |
|   
 | |
|   set_attr(study, "DataPath", firm2dir(-1));
 | |
|   set_attr(study, "ExePath", main_app().argv(0)); 
 | |
| 
 | |
|   const TDongle& d = dongle();
 | |
|   TXmlItem& chiavetta = find_or_create_child(root, "dongle", true);
 | |
|   chiavetta.SetAttr("OEM", get_oem_info("OEM"));
 | |
|   chiavetta.SetAttr("Number", d.number());
 | |
|   chiavetta.SetAttr("Users",  d.max_users());
 | |
|   chiavetta.SetAttr("Year",   d.year_assist());
 | |
|   chiavetta.SetAttr("Update", d.last_update().string());
 | |
|   switch (d.hardware())
 | |
|   {
 | |
|   case _dongle_hardlock: chiavetta.SetAttr("Model", "Hardlock"); break;
 | |
|   case _dongle_eutron  : chiavetta.SetAttr("Model", "Eutron"); break;
 | |
|   case _dongle_network : chiavetta.SetAttr("Model", "Network server"); 
 | |
|     chiavetta.SetAttr("Server", d.server_name()); 
 | |
|     break;
 | |
|   default: chiavetta.SetAttr("Model", "Unknown"); break;    
 | |
|   }
 | |
| 
 | |
|   TConfig ini("install.ini", "Main");
 | |
|   for (word m = 1; m < ENDAUT; m++) if (d.active(m))
 | |
|   {
 | |
|     const TString4 name = d.module_code2name(m);
 | |
|     const TString& version = ini.get("Versione", name);
 | |
|     if (version.full())
 | |
|     {
 | |
|       TXmlItem& module = chiavetta.AddChild("module");
 | |
|       module.SetAttr("Code",    name);
 | |
|       module.SetAttr("Version", version);
 | |
|       module.SetAttr("Patch",   ini.get("Patch"));
 | |
|       module.SetAttr("Date",    ini.get("Data"));
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   root.Save(filename);
 | |
|   return filename.exist();
 | |
| }
 | |
| 
 | |
| // Aggiorna il file xml coi dati di installazione e lo spedisce qua
 | |
| bool send_campo_xml()
 | |
| { 
 | |
|   TWait_cursor waiter;
 | |
|   bool ok = save_campo_xml();
 | |
|   if (ok && (xvt_net_get_status() & 0x4) != 0)
 | |
|   {
 | |
|     TSocketClient sirio;
 | |
|     CONNID id = sirio.QueryConnection("21", "93.146.247.172");
 | |
|     if (id > 0)
 | |
|     {
 | |
|       TFilename local, remote; 
 | |
|       build_xml_filename(local, false);
 | |
|       build_xml_filename(remote, true);
 | |
|       ok = sirio.FtpSendFile(id, remote, local, "attivazioni", "viagra");
 | |
|       sirio.RemoveConnection(id);
 | |
|     }
 | |
|   }
 | |
|   return ok;
 | |
| }
 |