#!/usr/bin/perl
# Copyright 2001-2006 Leslie Richardson
# This file is part of Open Admin for Schools.
# Open Admin for Schools is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
my %lex = ('Userid' => 'Userid',
'Password' => 'Password',
'Duration' => 'Duration',
'Login' => 'Login',
'Staff Login' => 'Staff Login',
'min' => 'min',
'No Userid Found' => 'No Userid Found',
'Incorrect Password' => 'Incorrect Password',
'Logged In' => 'Logged In',
'User' => 'User',
);
use DBI;
use CGI;
use CGI::Session;
my $q = CGI->new;
my %arr = $q->Vars;
require "../etc/admin.conf" or die "Cannot open admin.conf!";
my $dsn = "DBI:$dbtype:dbname=$dbase";
my $dbh = DBI->connect($dsn,$user,$password);
my $login_result;
if ($arr{flag}) {
$login_result = doLogin();
} else {
print $q->header;
}
# Print Page Heading
#print "$doctype\n
". $lex{'Staff Login'}. "
#
#
#
printHTMLHeader();
print "
". $lex{'Staff Login'}. "
\n";
if ($login_result) {
print "$login_result\n";
}
print "
\n";
#----------
sub doLogin {
#----------
delete $arr{flag};
my $session = new CGI::Session("driver:mysql;serializer:FreezeThaw",
undef,{Handle => $dbh}) or die CGI::Session->errstr;
# Set Session Values;
# Check password/userid against database (-1 no user, -2 wrong password;
my $error = checkPassword($arr{userid}, $arr{password});
if ($error == -1){
print $q->header;
return $lex{'No Userid Found'};
}
if ($error == -2){
print $q->header;
return $lex{'Incorrect Password'};
}
$cookietime = checkCookieTime($arr{duration});
# Set values for userid and logged_in in session
$session->param('logged_in','1');
$session->expire('logged_in',$cookietime);
$session->param('userid',$arr{userid});
# Now print page header...
print $session->header;
printHTMLHeader();
print "
". $lex{'Staff Login'}. "
\n";
my $sth = $dbh->prepare("select firstname, lastname from staff
where userid = ?");
$sth->execute($arr{userid});
if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; }
my ($firstname, $lastname) = $sth->fetchrow;
print "$firstname $lastname ". $lex{'Logged In'}. " \n";
print "\n";
print "