Added PODs.
[koha.git] / C4 / Security.pm
1 package C4::Security; #assumes C4/Security
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA  02111-1307 USA
20
21 use strict;
22 require Exporter;
23 use DBI;
24 use C4::Database;
25 use C4::Format;
26 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
27
28 # set the version for version checking
29 $VERSION = 0.01;
30
31 @ISA = qw(Exporter);
32 @EXPORT = qw(&Login &CheckAccess);
33
34 sub Login {
35   my ($env)=@_;
36   my $dbh=C4Connect;
37   my @branches;
38   my $query = "select * from branches order by branchname";
39   my $sth=$dbh->prepare($query);
40   $sth->execute;
41   while (my $branchrec=$sth->fetchrow_hashref) {
42     my $branchdet = 
43      fmtstr($env,$branchrec->{'branchcode'},"L2")." ".$branchrec->{'branchname'};
44     push @branches,$branchdet;
45   }
46   $sth->finish;
47   my $valid = "f";
48   &startint($env,"Logging In");
49   until ($valid eq "t") {
50     my ($reason,$username,$password,$branch) = logondialog ($env,"Logon to System",\@branches);
51     $username = uc $username;
52     $password = uc $password;
53     my $query = "select * from users where usercode = '$username' and password ='$password'";
54     $sth=$dbh->prepare($query);
55     $sth->execute;
56 #          debug_msg("",$query);
57     if (my $userrec = $sth->fetchrow_hashref) {
58     if ($userrec->{'usercode'} ne ''){
59       if ($branch ne "") {
60         $valid = "t";
61         my @dummy = split ' ', $branch;
62         $branch = $dummy[0];
63         $env->{'usercode'} = $username;
64         $env->{'branchcode'} = $branch;
65       }
66      
67     } else {
68       debug_msg("","not found");
69     }
70     }
71     $sth->finish;
72   }
73   $dbh->disconnect;
74   &endint();
75 }
76   
77 sub CheckAccess {
78   my ($env)=@_;
79   }
80     
81 END { }       # module clean-up code here (global destructor)
82