2 # NOTE: This file uses 8-character tabs; do not change the tab size!
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA 02111-1307 USA
24 use Digest::MD5 qw(md5_base64);
30 use C4::Output; # to get the template
33 use C4::Branch; # GetBranches
36 # use Net::LDAP qw(:all);
38 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
40 # set the version for version checking
41 $VERSION = do { my @v = '$Revision$' =~ /\d+/g;
42 shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v );
47 C4::Auth - Authenticates Koha users
56 my ($template, $borrowernumber, $cookie)
57 = get_template_and_user({template_name => "opac-main.tmpl",
61 flagsrequired => {borrow => 1},
72 The main function of this module is to provide
73 authentification. However the get_template_and_user function has
74 been provided so that a users login information is passed along
75 automatically. This gets loaded into the template.
86 &get_template_and_user
89 =item get_template_and_user
91 my ($template, $borrowernumber, $cookie)
92 = get_template_and_user({template_name => "opac-main.tmpl",
96 flagsrequired => {borrow => 1},
99 This call passes the C<query>, C<flagsrequired> and C<authnotrequired>
100 to C<&checkauth> (in this module) to perform authentification.
101 See C<&checkauth> for an explanation of these parameters.
103 The C<template_name> is then used to find the correct template for
104 the page. The authenticated users details are loaded onto the
105 template in the HTML::Template LOOP variable C<USER_INFO>. Also the
106 C<sessionID> is passed to the template. This can be used in templates
107 if cookies are disabled. It needs to be put as and input to every
110 More information on the C<gettemplate> sub can be found in the
115 sub get_template_and_user {
118 gettemplate( $in->{'template_name'}, $in->{'type'}, $in->{'query'} );
119 my ( $user, $cookie, $sessionID, $flags ) = checkauth(
121 $in->{'authnotrequired'},
122 $in->{'flagsrequired'},
124 ) unless ($in->{'template_name'}=~/maintenance/);
127 my $insecure = C4::Context->preference('insecure');
128 if ($user or $insecure) {
129 $template->param( loggedinusername => $user );
130 $template->param( sessionID => $sessionID );
132 $borrowernumber = getborrowernumber($user);
133 my ( $borr, $alternativeflags ) =
134 GetMemberDetails( $borrowernumber );
137 $template->param( "USER_INFO" => \@bordat );
139 # We are going to use the $flags returned by checkauth
140 # to create the template's parameters that will indicate
141 # which menus the user can access.
142 if (( $flags && $flags->{superlibrarian}==1) or $insecure==1) {
143 $template->param( CAN_user_circulate => 1 );
144 $template->param( CAN_user_catalogue => 1 );
145 $template->param( CAN_user_parameters => 1 );
146 $template->param( CAN_user_borrowers => 1 );
147 $template->param( CAN_user_permission => 1 );
148 $template->param( CAN_user_reserveforothers => 1 );
149 $template->param( CAN_user_borrow => 1 );
150 $template->param( CAN_user_editcatalogue => 1 );
151 $template->param( CAN_user_updatecharge => 1 );
152 $template->param( CAN_user_acquisition => 1 );
153 $template->param( CAN_user_management => 1 );
154 $template->param( CAN_user_tools => 1 );
155 $template->param( CAN_user_editauthorities => 1 );
156 $template->param( CAN_user_serials => 1 );
157 $template->param( CAN_user_reports => 1 );
160 if ( $flags && $flags->{circulate} == 1 ) {
161 $template->param( CAN_user_circulate => 1 );
164 if ( $flags && $flags->{catalogue} == 1 ) {
165 $template->param( CAN_user_catalogue => 1 );
168 if ( $flags && $flags->{parameters} == 1 ) {
169 $template->param( CAN_user_parameters => 1 );
170 $template->param( CAN_user_management => 1 );
173 if ( $flags && $flags->{borrowers} == 1 ) {
174 $template->param( CAN_user_borrowers => 1 );
177 if ( $flags && $flags->{permissions} == 1 ) {
178 $template->param( CAN_user_permission => 1 );
181 if ( $flags && $flags->{reserveforothers} == 1 ) {
182 $template->param( CAN_user_reserveforothers => 1 );
185 if ( $flags && $flags->{borrow} == 1 ) {
186 $template->param( CAN_user_borrow => 1 );
189 if ( $flags && $flags->{editcatalogue} == 1 ) {
190 $template->param( CAN_user_editcatalogue => 1 );
193 if ( $flags && $flags->{updatecharges} == 1 ) {
194 $template->param( CAN_user_updatecharge => 1 );
197 if ( $flags && $flags->{acquisition} == 1 ) {
198 $template->param( CAN_user_acquisition => 1 );
201 if ( $flags && $flags->{tools} == 1 ) {
202 $template->param( CAN_user_tools => 1 );
205 if ( $flags && $flags->{editauthorities} == 1 ) {
206 $template->param( CAN_user_editauthorities => 1 );
209 if ( $flags && $flags->{serials} == 1 ) {
210 $template->param( CAN_user_serials => 1 );
213 if ( $flags && $flags->{reports} == 1 ) {
214 $template->param( CAN_user_reports => 1 );
217 if ( $in->{'type'} eq "intranet" ) {
219 intranetcolorstylesheet =>
220 C4::Context->preference("intranetcolorstylesheet"),
221 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
222 IntranetNav => C4::Context->preference("IntranetNav"),
223 intranetuserjs => C4::Context->preference("intranetuserjs"),
224 TemplateEncoding => C4::Context->preference("TemplateEncoding"),
225 AmazonContent => C4::Context->preference("AmazonContent"),
226 LibraryName => C4::Context->preference("LibraryName"),
227 LoginBranchcode => (C4::Context->userenv?C4::Context->userenv->{"branch"}:"insecure"),
228 LoginBranchname => (C4::Context->userenv?C4::Context->userenv->{"branchname"}:"insecure"),
229 AutoLocation => C4::Context->preference("AutoLocation"),
230 hide_marc => C4::Context->preference("hide_marc"),
231 patronimages => C4::Context->preference("patronimages"),
232 "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
233 advancedMARCEditor => C4::Context->preference("advancedMARCEditor"),
234 suggestion => C4::Context->preference("suggestion"),
235 virtualshelves => C4::Context->preference("virtualshelves"),
236 LibraryName => C4::Context->preference("LibraryName"),
237 KohaAdminEmailAddress => "" . C4::Context->preference("KohaAdminEmailAddress"),
241 warn "template type should be OPAC, here it is=[" . $in->{'type'} . "]"
242 unless ( $in->{'type'} eq 'opac' );
243 my $LibraryNameTitle = C4::Context->preference("LibraryName");
244 $LibraryNameTitle =~ s/<(?:\/?)(?:br|p)\s*(?:\/?)>/ /sgi;
245 $LibraryNameTitle =~ s/<(?:[^<>'"]|'(?:[^']*)'|"(?:[^"]*)")*>//sg;
247 KohaAdminEmailAddress => "" . C4::Context->preference("KohaAdminEmailAddress"),
248 suggestion => "" . C4::Context->preference("suggestion"),
249 virtualshelves => "" . C4::Context->preference("virtualshelves"),
250 OpacNav => "" . C4::Context->preference("OpacNav"),
251 opacheader => "" . C4::Context->preference("opacheader"),
252 opaccredits => "" . C4::Context->preference("opaccredits"),
253 opacsmallimage => "" . C4::Context->preference("opacsmallimage"),
254 opaclargeimage => "" . C4::Context->preference("opaclargeimage"),
255 opaclayoutstylesheet => "". C4::Context->preference("opaclayoutstylesheet"),
256 opaccolorstylesheet => "". C4::Context->preference("opaccolorstylesheet"),
257 opaclanguagesdisplay => "". C4::Context->preference("opaclanguagesdisplay"),
258 opacuserlogin => "" . C4::Context->preference("opacuserlogin"),
259 opacbookbag => "" . C4::Context->preference("opacbookbag"),
260 TemplateEncoding => "". C4::Context->preference("TemplateEncoding"),
261 AmazonContent => "" . C4::Context->preference("AmazonContent"),
262 LibraryName => "" . C4::Context->preference("LibraryName"),
263 LibraryNameTitle => "" . $LibraryNameTitle,
264 LoginBranchcode => (C4::Context->userenv?C4::Context->userenv->{"branch"}:"insecure"),
265 LoginBranchname => C4::Context->userenv?C4::Context->userenv->{"branchname"}:"",
266 OpacPasswordChange => C4::Context->preference("OpacPasswordChange"),
267 opacreadinghistory => C4::Context->preference("opacreadinghistory"),
268 opacuserjs => C4::Context->preference("opacuserjs"),
269 OpacCloud => C4::Context->preference("OpacCloud"),
270 OpacTopissue => C4::Context->preference("OpacTopissue"),
271 OpacAuthorities => C4::Context->preference("OpacAuthorities"),
272 OpacBrowser => C4::Context->preference("OpacBrowser"),
273 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
274 reviewson => C4::Context->preference("reviewson"),
275 hide_marc => C4::Context->preference("hide_marc"),
276 patronimages => C4::Context->preference("patronimages"),
277 "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
280 return ( $template, $borrowernumber, $cookie );
285 ($userid, $cookie, $sessionID) = &checkauth($query, $noauth, $flagsrequired, $type);
287 Verifies that the user is authorized to run this script. If
288 the user is authorized, a (userid, cookie, session-id, flags)
289 quadruple is returned. If the user is not authorized but does
290 not have the required privilege (see $flagsrequired below), it
291 displays an error page and exits. Otherwise, it displays the
292 login page and exits.
294 Note that C<&checkauth> will return if and only if the user
295 is authorized, so it should be called early on, before any
296 unfinished operations (e.g., if you've opened a file, then
297 C<&checkauth> won't close it for you).
299 C<$query> is the CGI object for the script calling C<&checkauth>.
301 The C<$noauth> argument is optional. If it is set, then no
302 authorization is required for the script.
304 C<&checkauth> fetches user and session information from C<$query> and
305 ensures that the user is authorized to run scripts that require
308 The C<$flagsrequired> argument specifies the required privileges
309 the user must have if the username and password are correct.
310 It should be specified as a reference-to-hash; keys in the hash
311 should be the "flags" for the user, as specified in the Members
312 intranet module. Any key specified must correspond to a "flag"
313 in the userflags table. E.g., { circulate => 1 } would specify
314 that the user must have the "circulate" privilege in order to
315 proceed. To make sure that access control is correct, the
316 C<$flagsrequired> parameter must be specified correctly.
318 The C<$type> argument specifies whether the template should be
319 retrieved from the opac or intranet directory tree. "opac" is
320 assumed if it is not specified; however, if C<$type> is specified,
321 "intranet" is assumed if it is not "opac".
323 If C<$query> does not have a valid session ID associated with it
324 (i.e., the user has not logged in) or if the session has expired,
325 C<&checkauth> presents the user with a login page (from the point of
326 view of the original script, C<&checkauth> does not return). Once the
327 user has authenticated, C<&checkauth> restarts the original script
328 (this time, C<&checkauth> returns).
330 The login page is provided using a HTML::Template, which is set in the
331 systempreferences table or at the top of this file. The variable C<$type>
332 selects which template to use, either the opac or the intranet
333 authentification template.
335 C<&checkauth> returns a user ID, a cookie, and a session ID. The
336 cookie should be sent back to the browser; it verifies that the user
344 # $authnotrequired will be set for scripts which will run without authentication
345 my $authnotrequired = shift;
346 my $flagsrequired = shift;
348 $type = 'opac' unless $type;
350 my $dbh = C4::Context->dbh;
351 # check that database and koha version are the same
352 unless (C4::Context->preference('Version')){
353 if ($type ne 'opac'){
354 warn "Install required, redirecting to Installer";
355 print $query->redirect("/cgi-bin/koha/installer/install.pl");
357 warn "OPAC Install required, redirecting to maintenance";
358 print $query->redirect("/cgi-bin/koha/maintenance.pl");
362 if (C4::Context->preference('Version') < C4::Context->config("kohaversion")){
363 if ($type ne 'opac'){
364 warn "Database update needed, redirecting to Installer. Database is ".C4::Context->preference('Version')." and Koha is : ".C4::Context->config("kohaversion");
365 print $query->redirect("/cgi-bin/koha/installer/install.pl?step=3");
367 warn "OPAC :Database update needed, redirecting to maintenance. Database is ".C4::Context->preference('Version')." and Koha is : ".C4::Context->config("kohaversion");
368 print $query->redirect("/cgi-bin/koha/maintenance.pl");
372 my $timeout = C4::Context->preference('timeout');
373 $timeout = 600 unless $timeout;
376 if ( $type eq 'opac' ) {
377 $template_name = "opac-auth.tmpl";
380 $template_name = "auth.tmpl";
386 my ( $userid, $cookie, $sessionID, $flags, $envcookie );
387 my $logout = $query->param('logout.x');
388 if ( $userid = $ENV{'REMOTE_USER'} ) {
390 # Using Basic Authentication, no cookies required
391 $cookie = $query->cookie(
392 -name => 'CGISESSID',
398 elsif ( $sessionID = $query->cookie("CGISESSID")) {
399 my $session = new CGI::Session("driver:MySQL", $sessionID, {Handle=>$dbh});
401 C4::Context->_new_userenv($sessionID);
403 C4::Context::set_userenv(
404 $session->param('number'), $session->param('id'),
405 $session->param('cardnumber'), $session->param('firstname'),
406 $session->param('surname'), $session->param('branch'),
407 $session->param('branchname'), $session->param('flags'),
408 $session->param('emailaddress'), $session->param('branchprinter')
411 my $ip=$session->param('ip');
412 $userid = $session->param('id');
413 my $lasttime = $session->param('lasttime');
416 # voluntary logout the user
418 C4::Context->_unset_userenv($sessionID);
421 open L, ">>/tmp/sessionlog";
422 my $time = localtime( time() );
423 printf L "%20s from %16s logged out at %30s (manually).\n", $userid,
429 if ( $lasttime < time() - $timeout ) {
432 $info{'timed_out'} = 1;
434 C4::Context->_unset_userenv($sessionID);
437 open L, ">>/tmp/sessionlog";
438 my $time = localtime( time() );
439 printf L "%20s from %16s logged out at %30s (inactivity).\n",
443 elsif ( $ip ne $ENV{'REMOTE_ADDR'} ) {
445 # Different ip than originally logged in from
446 $info{'oldip'} = $ip;
447 $info{'newip'} = $ENV{'REMOTE_ADDR'};
448 $info{'different_ip'} = 1;
450 C4::Context->_unset_userenv($sessionID);
453 open L, ">>/tmp/sessionlog";
454 my $time = localtime( time() );
456 "%20s from logged out at %30s (ip changed from %16s to %16s).\n",
457 $userid, $time, $ip, $info{'newip'};
461 $cookie = $query->cookie(CGISESSID => $session->id
463 $session->param('lasttime',time());
464 $flags = haspermission( $dbh, $userid, $flagsrequired );
469 $info{'nopermission'} = 1;
475 my $session = new CGI::Session("driver:MySQL", undef, {Handle=>$dbh});
476 my $sessionID = $session->id;
477 $userid = $query->param('userid');
478 C4::Context->_new_userenv($sessionID);
479 my $password = $query->param('password');
480 C4::Context->_new_userenv($sessionID);
481 my ( $return, $cardnumber ) = checkpw( $dbh, $userid, $password );
483 open L, ">>/tmp/sessionlog";
484 my $time = localtime( time() );
485 printf L "%20s from %16s logged in at %30s.\n", $userid,
486 $ENV{'REMOTE_ADDR'}, $time;
488 $cookie = $query->cookie(CGISESSID => $sessionID);
489 if ( $flags = haspermission( $dbh, $userid, $flagsrequired ) ) {
493 $info{'nopermission'} = 1;
494 C4::Context->_unset_userenv($sessionID);
496 if ( $return == 1 ) {
498 $borrowernumber, $firstname, $surname,
499 $userflags, $branchcode, $branchname,
500 $branchprinter, $emailaddress
504 "select borrowernumber, firstname, surname, flags, borrowers.branchcode, branches.branchname as branchname,branches.branchprinter as branchprinter, email from borrowers left join branches on borrowers.branchcode=branches.branchcode where userid=?"
506 $sth->execute($userid);
508 $borrowernumber, $firstname, $surname,
509 $userflags, $branchcode, $branchname,
510 $branchprinter, $emailaddress
515 # warn "$cardnumber,$borrowernumber,$userid,$firstname,$surname,$userflags,$branchcode,$emailaddress";
516 unless ( $sth->rows ) {
519 "select borrowernumber, firstname, surname, flags, borrowers.branchcode, branches.branchname as branchname, branches.branchprinter as branchprinter, email from borrowers left join branches on borrowers.branchcode=branches.branchcode where cardnumber=?"
521 $sth->execute($cardnumber);
523 $borrowernumber, $firstname, $surname,
524 $userflags, $branchcode, $branchname,
525 $branchprinter, $emailaddress
530 # warn "$cardnumber,$borrowernumber,$userid,$firstname,$surname,$userflags,$branchcode,$emailaddress";
531 unless ( $sth->rows ) {
532 $sth->execute($userid);
534 $borrowernumber, $firstname, $surname, $userflags,
535 $branchcode, $branchname, $branchprinter, $emailaddress
541 # warn "$cardnumber,$borrowernumber,$userid,$firstname,$surname,$userflags,$branchcode,$emailaddress";
544 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
546 # launch a sequence to check if we have a ip for the branch, if we have one we replace the branchcode of the userenv by the branch bound in the ip.
547 my $ip = $ENV{'REMOTE_ADDR'};
548 my $branches = GetBranches();
550 foreach my $br ( keys %$branches ) {
552 # now we work with the treatment of ip
553 my $domain = $branches->{$br}->{'branchip'};
554 if ( $domain && $ip =~ /^$domain/ ) {
555 $branchcode = $branches->{$br}->{'branchcode'};
557 # new op dev : add the branchprinter and branchname in the cookie
558 $branchprinter = $branches->{$br}->{'branchprinter'};
559 $branchname = $branches->{$br}->{'branchname'};
563 $session->param('number',$borrowernumber);
564 $session->param('id',$userid);
565 $session->param('cardnumber',$cardnumber);
566 $session->param('firstname',$firstname);
567 $session->param('surname',$surname);
568 $session->param('branch',$branchcode);
569 $session->param('branchname',$branchname);
570 $session->param('flags',$userflags);
571 $session->param('emailaddress',$emailaddress);
572 $session->param('ip',$session->remote_addr());
573 $session->param('lasttime',time());
575 elsif ( $return == 2 ) {
577 #We suppose the user is the superlibrarian
578 $session->param('number',0);
579 $session->param('id',C4::Context->config('user'));
580 $session->param('cardnumber',C4::Context->config('user'));
581 $session->param('firstname',C4::Context->config('user'));
582 $session->param('surname',C4::Context->config('user'),);
583 $session->param('branch','NO_LIBRARY_SET');
584 $session->param('branchname','NO_LIBRARY_SET');
585 $session->param('flags',1);
586 $session->param('emailaddress', C4::Context->preference('KohaAdminEmailAddress'));
587 $session->param('ip',$session->remote_addr());
588 $session->param('lasttime',time());
593 $info{'invalid_username_or_password'} = 1;
594 C4::Context->_unset_userenv($sessionID);
598 my $insecure = C4::Context->boolean_preference('insecure');
600 # finished authentification, now respond
601 if ( $loggedin || $authnotrequired || ( defined($insecure) && $insecure ) )
605 $cookie = $query->cookie( CGISESSID => ''
608 return ( $userid, $cookie, $sessionID, $flags );
612 # else we have a problem...
613 # get the inputs from the incoming query
615 foreach my $name ( param $query) {
616 (next) if ( $name eq 'userid' || $name eq 'password' );
617 my $value = $query->param($name);
618 push @inputs, { name => $name, value => $value };
621 my $template = gettemplate( $template_name, $type, $query );
624 suggestion => C4::Context->preference("suggestion"),
625 virtualshelves => C4::Context->preference("virtualshelves"),
626 opaclargeimage => C4::Context->preference("opaclargeimage"),
627 LibraryName => C4::Context->preference("LibraryName"),
628 OpacNav => C4::Context->preference("OpacNav"),
629 opaccredits => C4::Context->preference("opaccredits"),
630 opacreadinghistory => C4::Context->preference("opacreadinghistory"),
631 opacsmallimage => C4::Context->preference("opacsmallimage"),
632 opaclayoutstylesheet => C4::Context->preference("opaclayoutstylesheet"),
633 opaccolorstylesheet => C4::Context->preference("opaccolorstylesheet"),
634 opaclanguagesdisplay => C4::Context->preference("opaclanguagesdisplay"),
635 opacuserjs => C4::Context->preference("opacuserjs"),
637 intranetcolorstylesheet =>
638 C4::Context->preference("intranetcolorstylesheet"),
639 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
640 IntranetNav => C4::Context->preference("IntranetNav"),
641 intranetuserjs => C4::Context->preference("intranetuserjs"),
642 TemplateEncoding => C4::Context->preference("TemplateEncoding"),
645 $template->param( loginprompt => 1 ) unless $info{'nopermission'};
647 my $self_url = $query->url( -absolute => 1 );
650 LibraryName => => C4::Context->preference("LibraryName"),
652 $template->param( \%info );
653 # $cookie = $query->cookie(CGISESSID => $session->id
655 print $query->header(
665 my ( $dbh, $userid, $password ) = @_;
670 "select password,cardnumber,borrowernumber,userid,firstname,surname,branchcode,flags from borrowers where userid=?"
672 $sth->execute($userid);
674 my ( $md5password, $cardnumber, $borrowernumber, $userid, $firstname,
675 $surname, $branchcode, $flags )
677 if ( md5_base64($password) eq $md5password ) {
679 C4::Context->set_userenv( "$borrowernumber", $userid, $cardnumber,
680 $firstname, $surname, $branchcode, $flags );
681 return 1, $cardnumber;
686 "select password,cardnumber,borrowernumber,userid, firstname,surname,branchcode,flags from borrowers where cardnumber=?"
688 $sth->execute($userid);
690 my ( $md5password, $cardnumber, $borrowernumber, $userid, $firstname,
691 $surname, $branchcode, $flags )
693 if ( md5_base64($password) eq $md5password ) {
695 C4::Context->set_userenv( $borrowernumber, $userid, $cardnumber,
696 $firstname, $surname, $branchcode, $flags );
700 if ( $userid && $userid eq C4::Context->config('user')
701 && "$password" eq C4::Context->config('pass') )
704 # Koha superuser account
705 # C4::Context->set_userenv(0,0,C4::Context->config('user'),C4::Context->config('user'),C4::Context->config('user'),"",1);
708 if ( $userid && $userid eq 'demo'
709 && "$password" eq 'demo'
710 && C4::Context->config('demo') )
713 # DEMO => the demo user is allowed to do everything (if demo set to 1 in koha.conf
714 # some features won't be effective : modify systempref, modify MARC structure,
721 my $cardnumber = shift;
724 my $sth = $dbh->prepare("SELECT flags FROM borrowers WHERE cardnumber=?");
725 $sth->execute($cardnumber);
726 my ($flags) = $sth->fetchrow;
727 $flags = 0 unless $flags;
728 $sth = $dbh->prepare("SELECT bit, flag, defaulton FROM userflags");
731 while ( my ( $bit, $flag, $defaulton ) = $sth->fetchrow ) {
732 if ( ( $flags & ( 2**$bit ) ) || $defaulton ) {
733 $userflags->{$flag} = 1;
736 $userflags->{$flag} = 0;
743 my ( $dbh, $userid, $flagsrequired ) = @_;
744 my $sth = $dbh->prepare("SELECT cardnumber FROM borrowers WHERE userid=?");
745 $sth->execute($userid);
746 my ($cardnumber) = $sth->fetchrow;
747 ($cardnumber) || ( $cardnumber = $userid );
748 my $flags = getuserflags( $cardnumber, $dbh );
750 if ( $userid eq C4::Context->config('user') ) {
752 # Super User Account from /etc/koha.conf
753 $flags->{'superlibrarian'} = 1;
755 if ( $userid eq 'demo' && C4::Context->config('demo') ) {
757 # Demo user that can do "anything" (demo=1 in /etc/koha.conf)
758 $flags->{'superlibrarian'} = 1;
760 return $flags if $flags->{superlibrarian};
761 foreach ( keys %$flagsrequired ) {
762 return $flags if $flags->{$_};
767 sub getborrowernumber {
769 my $dbh = C4::Context->dbh;
770 for my $field ( 'userid', 'cardnumber' ) {
772 $dbh->prepare("select borrowernumber from borrowers where $field=?");
773 $sth->execute($userid);
775 my ($bnumber) = $sth->fetchrow;
782 END { } # module clean-up code here (global destructor)