Added support for showing patron flags in the issues module.
[koha.git] / C4 / Security.pm
1 package C4::Security; #asummes C4/Security
2
3 #requires DBI.pm to be installed
4 #uses DBD:Pg
5
6 use strict;
7 require Exporter;
8 use DBI;
9 use C4::Database;
10 use C4::Format;
11 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
12
13 # set the version for version checking
14 $VERSION = 0.01;
15
16 @ISA = qw(Exporter);
17 @EXPORT = qw(&Login &CheckAccess);
18 %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
19
20 # your exported package globals go here,
21 # as well as any optionally exported functions
22
23 @EXPORT_OK   = qw($Var1 %Hashit);
24
25
26 # non-exported package globals go here
27 use vars qw(@more $stuff);
28
29 # initalize package globals, first exported ones
30
31 my $Var1   = '';
32 my %Hashit = ();
33
34
35 # then the others (which are still accessible as $Some::Module::stuff)
36 my $stuff  = '';
37 my @more   = ();
38
39 # all file-scoped lexicals must be created before
40 # the functions below that use them.
41
42 # file-private lexicals go here
43 my $priv_var    = '';
44 my %secret_hash = ();
45
46 # here's a file-private function as a closure,
47 # callable as &$priv_func;  it cannot be prototyped.
48 my $priv_func = sub {
49 # stuff goes here.
50   };
51    
52 # make all your functions, whether exported or not;
53  
54 sub Login {
55   my ($env)=@_;
56   my $dbh=C4Connect;
57   my @branches;
58   my $query = "select * from branches order by branchname";
59   my $sth=$dbh->prepare($query);
60   $sth->execute;
61   while (my $branchrec=$sth->fetchrow_hashref) {
62     my $branchdet = 
63      fmtstr($env,$branchrec->{'branchcode'},"L2")." ".$branchrec->{'branchname'};
64     push @branches,$branchdet;
65   }
66   $sth->finish;
67   my $valid = "f";
68   &startint($env,"Logging In");
69   until ($valid eq "t") {
70     my ($reason,$username,$password,$branch) = logondialog ($env,"Logon to System",\@branches);
71     $username = uc $username;
72     $password = uc $password;
73     my $query = "select * from users where usercode = '$username' and password ='$password'";
74     $sth=$dbh->prepare($query);
75     $sth->execute;
76 #          debug_msg("",$query);
77     if (my $userrec = $sth->fetchrow_hashref) {
78     if ($userrec->{'usercode'} ne ''){
79       if ($branch ne "") {
80         $valid = "t";
81         my @dummy = split ' ', $branch;
82         $branch = $dummy[0];
83         $env->{'usercode'} = $username;
84         $env->{'branchcode'} = $branch;
85       }
86      
87     } else {
88       debug_msg("","not found");
89     }
90     }
91     $sth->finish;
92   }
93   $dbh->disconnect;
94   &endint();
95 }
96   
97 sub CheckAccess {
98   my ($env)=@_;
99   }
100     
101 END { }       # module clean-up code here (global destructor)
102