// report.cgi: applicazione per avere qualche piccolo report/status // sui partecipanti ai corsi #include #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 << "

Troppi dati inviati



" << endl; cout << "

L'applicazione ha ricevuto troppi dati sul buffer d'ingresso.


" << 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 << "

Elenco utenti collegati



" << endl; } else if (_azione == "ACCESSI") { command = "SELECT * FROM ACCESSI WHERE loginname='"; command += _utente; command += "'"; cout << "

Elenco accessi effettuati per l'utente " << _utente << "



" << 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 << "

Elenco verifiche effettuate per l'utente " << _utente << "



" << 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 << "
" << endl; cout << ""; if (_azione == "LOGGATI") cout << "" << endl; else if (_azione == "ACCESSI") cout << "" << endl; else if (_azione == "VERIFICHE") cout << "" << endl; for (int i = 0; i < tuples; i++) { // Ciclo sulle tuple ritornate cout << ""; if (_azione == "LOGGATI") cout << "" << endl; else if (_azione == "ACCESSI") cout << "" << endl; else if (_azione == "VERIFICHE") cout << "" << endl; cout << "" << endl; } cout << "
Log-nameAccesso in data
Log-NameIngressoUscita
Log-nameModuloLiv. TestData verificaPunteggio
" << _db->GetValue(i,"loginname") << "" << _db->GetValue(i,"logindate") << "" << _db->GetValue(i,"loginname") << "" << _db->GetValue(i,"logindate") << "" << _db->GetValue(i,"logoutdate") << "" << _db->GetValue(i,"loginname") << "" << _db->GetValue(i,"modulo") << "" << _db->GetValue(i,"testnum") << "" << _db->GetValue(i,"data") << "" << _db->GetValue(i,"punteggio") << "
" << endl; if (_azione == "VERIFICHE" && !_modulo.empty() && !_testnum.empty()) { String user_answers, corso; trim(_corso); for (int i=0; iGetValue(i,"risposte"); _questionario.load(_correct_answers,user_answers); _questionario.dump_html(_corso, atoi(_modulo), _testnum[0]); } } } else cout << "

Nessun record presente per la query selezionata

" << endl; return; } void Report_Application::main_func() { if (_azione.empty() || (_azione != "LOGGATI" && _utente.empty())) { cout << "

Impossibile eseguire il report



" << endl; cout << "

E' necessario specificare il tipo di report e/o l'utente.


"; 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); }