#!/usr/bin/perl -T $dbname = 'corsi'; $dbhost = 'localhost'; use Pg; if (check_user("utente_fad", "Excel-base") eq 0) { print "Can't find it\n"; } else { print "Found it\n"; } print get_course("utente_fad"); sub get_course { my $retval; my $loginname=$_[0]; $retval = "no_course"; # Compose query string and connect $commandos = "SELECT * FROM UTENTI WHERE loginname='"; $commandos = "$commandos$loginname'"; $conn = Pg::connectdb("dbname=$dbname host=$dbhost"); if ($conn->status == PGRES_CONNECTION_OK) { $result = $conn->exec($commandos); # Did you find anyone? if ($result->ntuples > 0) { $retval = $result->getvalue(0,$result->fnumber("course")); } } $retval =~ tr/ //d; $retval; } sub check_user { my $commandos; my $modules; my $ret_val; my $loginname= $_[0]; my $modulename= $_[1]; $ret_val = 0; # Compose query string and connect $commandos = "SELECT * FROM UTENTI WHERE loginname='"; $commandos = "$commandos$loginname'"; $conn = Pg::connectdb("dbname=$dbname host=$dbhost"); if ($conn->status == PGRES_CONNECTION_OK) { $result = $conn->exec($commandos); # Did you find anyone? if ($result->ntuples > 0) { $modules = $result->getvalue(0,$result->fnumber("modules")); $commandos = "SELECT * FROM MODULI WHERE modulename='"; # Search for $module_name and fetch its number $commandos = "$commandos$modulename'"; $result = $conn->exec($commandos); if ($result->ntuples > 0) { $mod_num = $result->getvalue(0,$result->fnumber("modulenum")); # Now check if $mod_num is enabled for this $loginname $ret_val = 1 if (substr($modules, $mod_num-1,1) eq "X"); } } } $ret_val; }