Files correlati : Ricompilazione Demo : [ ] Commento : Modifiche di marco git-svn-id: svn://10.65.10.50/trunk@8858 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			142 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			142 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
// logout.cgi: applicazione per registrare l'uscita dall'area
 | 
						|
// dei corsi.
 | 
						|
 | 
						|
#include <libpq++.h>
 | 
						|
#include "applicat.h"
 | 
						|
 | 
						|
class Logout_Application : public Application
 | 
						|
{
 | 
						|
private:
 | 
						|
 | 
						|
  String     _dbname;
 | 
						|
  String     _utente;   // Utente corrente
 | 
						|
  PgEnv      _environment;
 | 
						|
  PgTransaction *_db;
 | 
						|
  
 | 
						|
protected:
 | 
						|
  virtual bool create();
 | 
						|
  virtual bool destroy();
 | 
						|
  virtual void main_func();
 | 
						|
  void logout();
 | 
						|
public:
 | 
						|
  Logout_Application() {_db = NULL;}
 | 
						|
  virtual ~Logout_Application() {};
 | 
						|
};
 | 
						|
 | 
						|
bool Logout_Application::create()
 | 
						|
{
 | 
						|
 | 
						|
  _dbname = POSTGRES_DB;
 | 
						|
  _environment.Port(POSTGRES_PORT);
 | 
						|
  _environment.Host(POSTGRES_HOST);
 | 
						|
  print_header("Uscita dall'area corsi");
 | 
						|
  _utente = getenv("REMOTE_USER");;
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool Logout_Application::destroy()
 | 
						|
{
 | 
						|
  print_footer();
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
void Logout_Application::logout()
 | 
						|
{
 | 
						|
  // 
 | 
						|
  String command;
 | 
						|
  // Compone la stringa di selezione utente: nome utente & logged altrimenti nisba logout!
 | 
						|
  command = "SELECT * FROM UTENTI WHERE loginname='";
 | 
						|
  command += _utente;
 | 
						|
  command += "' AND logged='t'";
 | 
						|
  _db->ExecCommandOk(command);
 | 
						|
  const int tuples = _db->Tuples();
 | 
						|
  if (tuples > 0) 
 | 
						|
  { // E' loggato oppure no...
 | 
						|
    // Cosa deve fare:
 | 
						|
    // Sistema le informazioni di logging dell'utente (anche sulla tabella ACCESSI)
 | 
						|
    String progressivo;
 | 
						|
    if (strncmp(_utente,"demo", 4)==0) 
 | 
						|
    {
 | 
						|
//Se l'utente è un utente dimostrativo cancella i dati relativi alle verifiche effettuate dalla tabella UTENTI
 | 
						|
      progressivo = _db->GetValue(0, "progaccesso");
 | 
						|
      command = "UPDATE UTENTI SET logged=0, logindate=null , verifiche= '' ";
 | 
						|
      command += " WHERE loginname='";
 | 
						|
      command += _utente;
 | 
						|
      command += "'";
 | 
						|
      _db->ExecCommandOk(command);
 | 
						|
    }
 | 
						|
    else
 | 
						|
    {
 | 
						|
     progressivo = _db->GetValue(0, "progaccesso");
 | 
						|
     command = "UPDATE UTENTI SET logged=0, logindate=null ";
 | 
						|
     command += " WHERE loginname='";
 | 
						|
     command += _utente;
 | 
						|
     command += "'";
 | 
						|
     _db->ExecCommandOk(command); // Aggiorna la tabella utenti
 | 
						|
    }
 | 
						|
    command = "UPDATE ACCESSI SET logoutdate=current_timestamp WHERE loginname='";
 | 
						|
    command += _utente;
 | 
						|
    command += "' AND progressivo=";
 | 
						|
    command += progressivo;
 | 
						|
    _db->ExecCommandOk(command); // Aggiorna la tabella accessi
 | 
						|
  }
 | 
						|
  // Se non trova l'utente indicato oppure non era loggato
 | 
						|
  // visualizza ugualmente un messaggio ingannatoreà
 | 
						|
  cout << "<H2>Uscita dall'area corsi</H2><BR><BR>" << endl;
 | 
						|
  cout << "<P>Uscita dall'area corsi effettuata con successo.</P><BR>";
 | 
						|
  cout << "<P>Le informazioni necessarie sono state registrate.</P><BR>";
 | 
						|
  cout << "<P><B>Grazie.</B></P><BR>";
 | 
						|
  
 | 
						|
  return;
 | 
						|
}
 | 
						|
 | 
						|
void Logout_Application::main_func()
 | 
						|
{ 
 | 
						|
  // Controllo utente: se il CGI viene chiamato senza indicazioni d'utente
 | 
						|
  // non mostra proprio nulla (null logout)
 | 
						|
  if (_utente.empty()) { 
 | 
						|
    cout << "<H2>Uscita dall'area corsi</H2><BR><BR>" << endl;
 | 
						|
    cout << "<P>Uscita dall'area corsi effettuata con successo.</P><BR>";
 | 
						|
    return;
 | 
						|
  }
 | 
						|
  // Se e' stato impostato l'utente, effettua la logout()
 | 
						|
  // Inizia la transazione
 | 
						|
  _db = new PgTransaction(_environment, _dbname);
 | 
						|
  if ( _db->ConnectionBad() )
 | 
						|
    print_database_error();
 | 
						|
  else
 | 
						|
    logout();
 | 
						|
  delete _db; // Termina la transazione
 | 
						|
  return;
 | 
						|
}
 | 
						|
 | 
						|
int main(int argc, char* argv[])
 | 
						|
{
 | 
						|
  Logout_Application* a = new Logout_Application();
 | 
						|
 
 | 
						|
  a->run(argc, argv);
 | 
						|
 | 
						|
  delete a;
 | 
						|
  
 | 
						|
  exit(0);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 |