which included commits to RCS files with non-trunk default branches. git-svn-id: svn://10.65.10.50/trunk@8626 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			220 lines
		
	
	
		
			5.7 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			220 lines
		
	
	
		
			5.7 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| // report.cgi: applicazione per avere qualche piccolo report/status
 | |
| // sui partecipanti ai corsi
 | |
| 
 | |
| #include <libpq++.h>
 | |
| #include "applicat.h"
 | |
| #include "questionnaire.h"
 | |
| 
 | |
| class Report_Application : public Application
 | |
| {
 | |
| private:
 | |
| 
 | |
|   String     _dbname;
 | |
|   String     _utente;
 | |
|   String     _azione; //ACCESSI, VERIFICHE, LOGGATI
 | |
|   String     _modulo; // Numero del modulo
 | |
|   String     _testnum; // Livello di test
 | |
|   String     _correct_answers;
 | |
|   String     _corso;
 | |
|   Questionnaire _questionario;
 | |
|   PgEnv      _environment;
 | |
|   PgDatabase *_db;
 | |
|   
 | |
| protected:
 | |
|   virtual bool create();
 | |
|   virtual bool destroy();
 | |
|   virtual void main_func();
 | |
|   void report();
 | |
| public:
 | |
|   Report_Application() {_db = NULL;}
 | |
|   virtual ~Report_Application() {};
 | |
| };
 | |
| 
 | |
| bool Report_Application::create()
 | |
| {
 | |
|   _modulo  = "";
 | |
|   _testnum = "";
 | |
|   _corso = "";
 | |
|   _dbname = POSTGRES_DB;
 | |
|   _environment.Port(POSTGRES_PORT);
 | |
|   _environment.Host(POSTGRES_HOST);
 | |
|   print_header("Report per utenti");
 | |
|   char *t1, *t2;
 | |
|   char *ccc = getenv("CONTENT_LENGTH");
 | |
|   int cl = ccc != NULL ? atoi(ccc) : 0;
 | |
|   if (cl < 512)
 | |
|     for (int x = 0; cl && (!feof(stdin)); x++) {
 | |
|       t1 = fmakeword(stdin, '&', &cl);
 | |
|       t2 = makeword(t1, '=');
 | |
|       unescape_url(t1);
 | |
|       unescape_url(t2);
 | |
|       if (!strcmp(t2,"AZIONE"))
 | |
| 	_azione = t1;
 | |
|       if (!strcmp(t2,"UTENTE"))
 | |
| 	_utente = t1;
 | |
|       if (!strcmp(t2,"MODULO"))
 | |
| 	_modulo = t1;
 | |
|       if (!strcmp(t2,"TESTNUM"))
 | |
| 	_testnum = t1;
 | |
|     }
 | |
|   else {
 | |
|     cout << "<H2>Troppi dati inviati</H2><BR><BR>" << endl;
 | |
|     cout << "<P>L'applicazione ha ricevuto troppi dati sul buffer d'ingresso.</P><BR>" << endl;
 | |
|     return FALSE;
 | |
|   } 
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool Report_Application::destroy()
 | |
| {
 | |
|   print_footer();
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| void Report_Application::report()
 | |
| {
 | |
|   // The Last One... Query di selezione per ogni azione diversa
 | |
|   String command, command1;
 | |
|   if (_azione == "LOGGATI") {
 | |
|     command = "SELECT * FROM UTENTI WHERE logged='t'";
 | |
|     cout << "<H2>Elenco utenti collegati</H2><BR><BR>" << endl;
 | |
|   }
 | |
|   else
 | |
|     if (_azione == "ACCESSI") {
 | |
|       command = "SELECT * FROM ACCESSI WHERE loginname='";
 | |
|       command += _utente;
 | |
|       command += "'";
 | |
|       cout << "<H2>Elenco accessi effettuati per l'utente " << _utente << "</H2><BR><BR>" << endl;
 | |
|     }
 | |
|     else
 | |
|       if (_azione == "VERIFICHE") {
 | |
| 	command = "SELECT * FROM VERIFICHE WHERE loginname='";
 | |
| 	command += _utente;
 | |
| 	command += "'";
 | |
| 	if (!_modulo.empty() && !_testnum.empty()){
 | |
| 	  command += " AND MODULO=";
 | |
| 	  command += _modulo;
 | |
| 	  command += " AND TESTNUM='";
 | |
| 	  command += _testnum;
 | |
| 	  command += "'";
 | |
| 
 | |
| 	  // Selezione per reperire il correttore
 | |
| 	  command1 = "SELECT * FROM CORRETTORI WHERE MODULO=";
 | |
| 	  command1 += _modulo;
 | |
| 	  command1 += " AND TESTNUM='";
 | |
| 	  command1 += _testnum;
 | |
| 	  command1 += "'";
 | |
| 	  _db->ExecCommandOk(command1);
 | |
| 	  if (_db->Tuples() > 0)
 | |
| 	    _correct_answers = _db->GetValue(0,"risposte");
 | |
| 
 | |
| 	  // Selezione per reperire a quale corso appartiene l'utente
 | |
| 	  command1 = "SELECT * FROM UTENTI WHERE loginname='";
 | |
| 	  command1 += _utente;
 | |
| 	  command1 += "'";
 | |
| 	  _db->ExecCommandOk(command1);
 | |
| 	  if (_db->Tuples() > 0)
 | |
| 	    _corso = _db->GetValue(0,"course");
 | |
|         }
 | |
| 	
 | |
| 	cout << "<H2>Elenco verifiche effettuate per l'utente " << _utente << "</H2><BR><BR>" << endl;
 | |
|       }
 | |
|       else
 | |
| 	command = "SELECT * FROM UTENTI WHERE loginname='_'"; // Comando per ritornare 0 Tuple
 | |
| 
 | |
|   _db->ExecCommandOk(command);
 | |
|   const int tuples = _db->Tuples();
 | |
| 
 | |
|   if (tuples > 0) {
 | |
|     // Intestazione tabella
 | |
|     cout << "<CENTER><TABLE BORDER>" << endl;
 | |
|     cout << "<TR>";
 | |
|     if (_azione == "LOGGATI")
 | |
|       cout << "<TH>Log-name</TH><TH>Accesso in data</TH></TR>" << endl;
 | |
|       else
 | |
| 	if (_azione == "ACCESSI")
 | |
| 	  cout << "<TH>Log-Name</TH><TH>Ingresso</TH><TH>Uscita</TH></TR>" << endl;
 | |
| 	  else
 | |
| 	    if (_azione == "VERIFICHE")
 | |
| 	      cout << "<TH>Log-name</TH><TH>Modulo</TH><TH>Liv. Test</TH><TH>Data verifica</TH><TH>Punteggio</TH></TR>" << endl;
 | |
|     for (int i = 0; i < tuples; i++) { // Ciclo sulle tuple ritornate
 | |
|       cout << "<TR>";
 | |
|       if (_azione == "LOGGATI")
 | |
| 	cout << "<TD>" << _db->GetValue(i,"loginname") << "</TD><TD>" << _db->GetValue(i,"logindate") << "</TD>" << endl;
 | |
| 	else
 | |
| 	  if (_azione == "ACCESSI")
 | |
| 	    cout << "<TD>" << _db->GetValue(i,"loginname") << "</TD><TD>" << _db->GetValue(i,"logindate") << "</TD><TD>" << _db->GetValue(i,"logoutdate") << "</TD>" << endl;
 | |
| 	    else
 | |
| 	      if (_azione == "VERIFICHE")
 | |
| 		cout << "<TD>" << _db->GetValue(i,"loginname") 
 | |
| 		     << "</TD><TD>" << _db->GetValue(i,"modulo") << "</TD><TD>" 
 | |
| 		     << _db->GetValue(i,"testnum") << "</TD><TD>" 
 | |
| 		     << _db->GetValue(i,"data") << "</TD><TD>" 
 | |
| 		     << _db->GetValue(i,"punteggio") << "</TD>" << endl;
 | |
|       cout << "</TR>" << endl;
 | |
|     }
 | |
|       
 | |
|     cout << "</TABLE></CENTER>" << endl;
 | |
| 
 | |
|     if (_azione == "VERIFICHE" && !_modulo.empty() && !_testnum.empty()) {  
 | |
|       String user_answers, corso;
 | |
|       
 | |
|       trim(_corso);
 | |
|       for (int i=0; i<tuples; i++) { 
 | |
| 	user_answers = _db->GetValue(i,"risposte");
 | |
| 	_questionario.load(_correct_answers,user_answers);
 | |
| 	_questionario.dump_html(_corso, atoi(_modulo), _testnum[0]);
 | |
|       }
 | |
|     }     
 | |
|   }
 | |
|   else
 | |
|     cout << "<p>Nessun record presente per la query selezionata</p>" << endl;
 | |
|   return;
 | |
| }
 | |
| 
 | |
| void Report_Application::main_func()
 | |
| { 
 | |
|   if (_azione.empty() || (_azione != "LOGGATI" && _utente.empty())) { 
 | |
|     cout << "<H2>Impossibile eseguire il report</H2><BR><BR>" << endl;
 | |
|     cout << "<P>E' necessario specificare il tipo di report e/o l'utente.</P><BR>";
 | |
|     return;
 | |
|   }
 | |
|   _db = new PgDatabase(_environment, _dbname);
 | |
|   if ( _db->ConnectionBad() )
 | |
|     print_database_error();
 | |
|   else
 | |
|     report();
 | |
|   delete _db;
 | |
|   return;
 | |
| }
 | |
| 
 | |
| int main(int argc, char* argv[])
 | |
| {
 | |
|   Report_Application* a = new Report_Application();
 | |
|  
 | |
|   a->run(argc, argv);
 | |
| 
 | |
|   delete a;
 | |
|   
 | |
|   exit(0);
 | |
| }
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 |