campo-sirio/webcgi/formazione/check_module_user.pl
luca 3dbdc66142 This commit was generated by cvs2svn to compensate for changes in r8625,
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
1999-10-20 15:27:08 +00:00

77 lines
1.6 KiB
Perl
Executable File

#!/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;
}