Added a couple of comments.
[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 # FIXME - As far as I can tell, this module is only used by the CDK
22 # stuff, which appears to be stillborn. In other words, this module
23 # isn't used.
24
25 use strict;
26 require Exporter;
27 use DBI;
28 use C4::Context;
29 use C4::Format;
30 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
31
32 # set the version for version checking
33 $VERSION = 0.01;
34
35 @ISA = qw(Exporter);
36 @EXPORT = qw(&Login &CheckAccess);
37
38 sub Login {
39   my ($env)=@_;
40   my $dbh = C4::Context->dbh;
41   my @branches;
42   my $query = "select * from branches order by branchname";
43   my $sth=$dbh->prepare($query);
44   $sth->execute;
45   while (my $branchrec=$sth->fetchrow_hashref) {
46     my $branchdet = 
47      fmtstr($env,$branchrec->{'branchcode'},"L2")." ".$branchrec->{'branchname'};
48     push @branches,$branchdet;
49   }
50   $sth->finish;
51   my $valid = "f";
52   &startint($env,"Logging In");
53   until ($valid eq "t") {
54     my ($reason,$username,$password,$branch) = logondialog ($env,"Logon to System",\@branches);
55     $username = uc $username;
56     $password = uc $password;
57     my $query = "select * from users where usercode = '$username' and password ='$password'";
58     $sth=$dbh->prepare($query);
59     $sth->execute;
60 #          debug_msg("",$query);
61     if (my $userrec = $sth->fetchrow_hashref) {
62     if ($userrec->{'usercode'} ne ''){
63       if ($branch ne "") {
64         $valid = "t";
65         my @dummy = split ' ', $branch;
66         $branch = $dummy[0];
67         $env->{'usercode'} = $username;
68         $env->{'branchcode'} = $branch;
69       }
70      
71     } else {
72       debug_msg("","not found");
73     }
74     }
75     $sth->finish;
76   }
77   &endint();
78 }
79   
80 sub CheckAccess {
81   my ($env)=@_;
82   }
83     
84 END { }       # module clean-up code here (global destructor)
85