use C4::Koha;
use C4::Branch; # GetBranches
+# use utf8;
# use Net::LDAP;
# use Net::LDAP qw(:all);
{
template_name => "opac-main.tmpl",
query => $query,
- type => "opac",
- authnotrequired => 1,
- flagsrequired => {borrow => 1},
- }
+ type => "opac",
+ authnotrequired => 1,
+ flagsrequired => {borrow => 1},
+ }
);
print $query->header(
{
template_name => "opac-main.tmpl",
query => $query,
- type => "opac",
- authnotrequired => 1,
- flagsrequired => {borrow => 1},
- }
+ type => "opac",
+ authnotrequired => 1,
+ flagsrequired => {borrow => 1},
+ }
);
This call passes the C<query>, C<flagsrequired> and C<authnotrequired>
my $borrowernumber;
my $insecure = C4::Context->preference('insecure');
if ($user or $insecure) {
+
+ # load the template variables for stylesheets and JavaScript
+ $template->param( css_libs => $in->{'css_libs'} );
+ $template->param( css_module => $in->{'css_module'} );
+ $template->param( css_page => $in->{'css_page'} );
+ $template->param( css_widgets => $in->{'css_widgets'} );
+
+ $template->param( js_libs => $in->{'js_libs'} );
+ $template->param( js_module => $in->{'js_module'} );
+ $template->param( js_page => $in->{'js_page'} );
+ $template->param( js_widgets => $in->{'js_widgets'} );
+
+ # user info
$template->param( loggedinusername => $user );
$template->param( sessionID => $sessionID );
$template->param( CAN_user_updatecharge => 1 );
$template->param( CAN_user_acquisition => 1 );
$template->param( CAN_user_management => 1 );
- $template->param( CAN_user_tools => 1 );
+ $template->param( CAN_user_tools => 1 );
$template->param( CAN_user_editauthorities => 1 );
$template->param( CAN_user_serials => 1 );
$template->param( CAN_user_reports => 1 );
if ( $flags && $flags->{tools} == 1 ) {
$template->param( CAN_user_tools => 1 );
}
-
+
if ( $flags && $flags->{editauthorities} == 1 ) {
$template->param( CAN_user_editauthorities => 1 );
}
-
+
if ( $flags && $flags->{serials} == 1 ) {
$template->param( CAN_user_serials => 1 );
}
if ( $in->{'type'} eq "intranet" ) {
$template->param(
intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
- intranetstylesheet => C4::Context->preference("intranetstylesheet"),
- IntranetNav => C4::Context->preference("IntranetNav"),
- intranetuserjs => C4::Context->preference("intranetuserjs"),
- TemplateEncoding => C4::Context->preference("TemplateEncoding"),
- AmazonContent => C4::Context->preference("AmazonContent"),
- LibraryName => C4::Context->preference("LibraryName"),
- LoginBranchcode => (C4::Context->userenv?C4::Context->userenv->{"branch"}:"insecure"),
- LoginBranchname => (C4::Context->userenv?C4::Context->userenv->{"branchname"}:"insecure"),
- LoginBranchnameShort => substr((C4::Context->userenv?C4::Context->userenv->{"branchname"}:"insecure"),0,10),
- AutoLocation => C4::Context->preference("AutoLocation"),
- hide_marc => C4::Context->preference("hide_marc"),
- patronimages => C4::Context->preference("patronimages"),
+ intranetstylesheet => C4::Context->preference("intranetstylesheet"),
+ IntranetNav => C4::Context->preference("IntranetNav"),
+ intranetuserjs => C4::Context->preference("intranetuserjs"),
+ TemplateEncoding => C4::Context->preference("TemplateEncoding"),
+ AmazonContent => C4::Context->preference("AmazonContent"),
+ LibraryName => C4::Context->preference("LibraryName"),
+ LoginBranchcode => (C4::Context->userenv?C4::Context->userenv->{"branch"}:"insecure"),
+ LoginBranchname => (C4::Context->userenv?C4::Context->userenv->{"branchname"}:"insecure"),
+ LoginFirstname => (C4::Context->userenv?C4::Context->userenv->{"firstname"}:"Bel"),
+ LoginSurname => C4::Context->userenv?C4::Context->userenv->{"surname"}:"Inconnu",
+ AutoLocation => C4::Context->preference("AutoLocation"),
+ hide_marc => C4::Context->preference("hide_marc"),
+ patronimages => C4::Context->preference("patronimages"),
"BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
advancedMARCEditor => C4::Context->preference("advancedMARCEditor"),
suggestion => C4::Context->preference("suggestion"),
virtualshelves => C4::Context->preference("virtualshelves"),
LibraryName => C4::Context->preference("LibraryName"),
KohaAdminEmailAddress => "" . C4::Context->preference("KohaAdminEmailAddress"),
+ IntranetmainUserblock => C4::Context->preference("IntranetmainUserblock"),
);
}
else {
- warn "template type should be OPAC, here it is=[" . $in->{'type'} . "]"
- unless ( $in->{'type'} eq 'opac' );
+ warn "template type should be OPAC, here it is=[" . $in->{'type'} . "]" unless ( $in->{'type'} eq 'opac' );
my $LibraryNameTitle = C4::Context->preference("LibraryName");
$LibraryNameTitle =~ s/<(?:\/?)(?:br|p)\s*(?:\/?)>/ /sgi;
$LibraryNameTitle =~ s/<(?:[^<>'"]|'(?:[^']*)'|"(?:[^"]*)")*>//sg;
- $template->param(
+ $template->param(
KohaAdminEmailAddress => "" . C4::Context->preference("KohaAdminEmailAddress"),
suggestion => "" . C4::Context->preference("suggestion"),
virtualshelves => "" . C4::Context->preference("virtualshelves"),
LibraryNameTitle => "" . $LibraryNameTitle,
LoginBranchcode => (C4::Context->userenv?C4::Context->userenv->{"branch"}:"insecure"),
LoginBranchname => C4::Context->userenv?C4::Context->userenv->{"branchname"}:"",
+ LoginFirstname => (C4::Context->userenv?C4::Context->userenv->{"firstname"}:"Bel"),
+ LoginSurname => C4::Context->userenv?C4::Context->userenv->{"surname"}:"Inconnu",
OpacPasswordChange => C4::Context->preference("OpacPasswordChange"),
opacreadinghistory => C4::Context->preference("opacreadinghistory"),
opacuserjs => C4::Context->preference("opacuserjs"),
sub checkauth {
my $query = shift;
-
-# $authnotrequired will be set for scripts which will run without authentication
+ # warn "Checking Auth";
+ # $authnotrequired will be set for scripts which will run without authentication
my $authnotrequired = shift;
my $flagsrequired = shift;
my $type = shift;
$type = 'opac' unless $type;
my $dbh = C4::Context->dbh;
- # check that database and koha version are the same
- unless (C4::Context->preference('Version')){
- if ($type ne 'opac'){
+ my $timeout = C4::Context->preference('timeout');
+ $timeout = 600 unless $timeout;
+
+
+ # If Version syspref is unavailable, it means Koha is beeing installed,
+ # and so we must redirect to OPAC maintenance page or to the WebInstaller
+ unless (C4::Context->preference('Version')) {
+ if ($type ne 'opac') {
warn "Install required, redirecting to Installer";
print $query->redirect("/cgi-bin/koha/installer/install.pl");
- } else {
+ }
+ else {
warn "OPAC Install required, redirecting to maintenance";
print $query->redirect("/cgi-bin/koha/maintenance.pl");
- }
- exit;
- }
- if (C4::Context->preference('Version') < C4::Context->config("kohaversion")){
- if ($type ne 'opac'){
- warn "Database update needed, redirecting to Installer. Database is ".C4::Context->preference('Version')." and Koha is : ".C4::Context->config("kohaversion");
- print $query->redirect("/cgi-bin/koha/installer/install.pl?step=3");
- } else {
- warn "OPAC :Database update needed, redirecting to maintenance. Database is ".C4::Context->preference('Version')." and Koha is : ".C4::Context->config("kohaversion");
- print $query->redirect("/cgi-bin/koha/maintenance.pl");
- }
+ }
exit;
}
- my $timeout = C4::Context->preference('timeout');
- $timeout = 600 unless $timeout;
- my $template_name;
- if ( $type eq 'opac' ) {
- $template_name = "opac-auth.tmpl";
- }
- else {
- $template_name = "auth.tmpl";
- }
# state variables
my $loggedin = 0;
my %info;
- my ( $userid, $cookie, $sessionID, $flags, $envcookie );
+ my ( $userid, $cookie, $sessionID, $flags );
my $logout = $query->param('logout.x');
if ( $userid = $ENV{'REMOTE_USER'} ) {
-
# Using Basic Authentication, no cookies required
$cookie = $query->cookie(
-name => 'CGISESSID',
$loggedin = 1;
}
elsif ( $sessionID = $query->cookie("CGISESSID")) {
- my $session = new CGI::Session("driver:MySQL", $sessionID, {Handle=>$dbh});
-
+ my $storage_method = C4::Context->preference('SessionStorage');
+ my $session;
+ if ($storage_method eq 'mysql'){
+ $session = new CGI::Session("driver:MySQL", $sessionID, {Handle=>$dbh});
+ }
+ else {
+ # catch all defaults to tmp should work on all systems
+ $session = new CGI::Session("driver:File", $sessionID, {Directory=>'/tmp'});
+ }
C4::Context->_new_userenv($sessionID);
- if ($session){
- C4::Context::set_userenv(
+ if ($session){
+ C4::Context::set_userenv(
$session->param('number'), $session->param('id'),
$session->param('cardnumber'), $session->param('firstname'),
$session->param('surname'), $session->param('branch'),
$session->param('branchname'), $session->param('flags'),
$session->param('emailaddress'), $session->param('branchprinter')
);
+# warn "".$session->param('cardnumber').", ".$session->param('firstname').",
+# ".$session->param('surname').", ".$session->param('branch');
}
- my $ip=$session->param('ip');
- $userid = $session->param('id');
- my $lasttime = $session->param('lasttime');
+ my $ip;
+ my $lasttime;
+ if ($session) {
+ $ip = $session->param('ip');
+ $lasttime = $session->param('lasttime');
+ $userid = $session->param('id');
+ }
+
+
if ($logout) {
# voluntary logout the user
- $session->delete;
+
+ $session->flush;
+ $session->delete();
C4::Context->_unset_userenv($sessionID);
$sessionID = undef;
$userid = undef;
close L;
}
if ($userid) {
- warn "here $userid";
if ( $lasttime < time() - $timeout ) {
-
# timed logout
$info{'timed_out'} = 1;
- $session->delete();
+ $session->delete();
C4::Context->_unset_userenv($sessionID);
$userid = undef;
$sessionID = undef;
close L;
}
elsif ( $ip ne $ENV{'REMOTE_ADDR'} ) {
-
# Different ip than originally logged in from
$info{'oldip'} = $ip;
$info{'newip'} = $ENV{'REMOTE_ADDR'};
$info{'different_ip'} = 1;
- $session->delete();
+ $session->delete();
C4::Context->_unset_userenv($sessionID);
$sessionID = undef;
$userid = undef;
close L;
}
else {
- $cookie = $query->cookie(CGISESSID => $session->id
- );
- $session->param('lasttime',time());
+ $cookie = $query->cookie( CGISESSID => $session->id );
+ $session->param('lasttime',time());
$flags = haspermission( $dbh, $userid, $flagsrequired );
if ($flags) {
$loggedin = 1;
}
}
unless ($userid) {
- my $session = new CGI::Session("driver:MySQL", undef, {Handle=>$dbh});
- my $sessionID = $session->id;
+ my $storage_method = C4::Context->preference('SessionStorage');
+ my $session;
+ if ($storage_method eq 'mysql'){
+ $session = new CGI::Session("driver:MySQL", $sessionID, {Handle=>$dbh});
+ }
+ else {
+ # catch all defaults to tmp should work on all systems
+ $session = new CGI::Session("driver:File", $sessionID, {Directory=>'/tmp'});
+ }
+
+ my $sessionID;
+ if ($session) {
+ $sessionID = $session->id;
+ }
$userid = $query->param('userid');
C4::Context->_new_userenv($sessionID);
my $password = $query->param('password');
= $sth->fetchrow
if ( $sth->rows );
-# warn "$cardnumber,$borrowernumber,$userid,$firstname,$surname,$userflags,$branchcode,$emailaddress";
+# warn "$cardnumber,$borrowernumber,$userid,$firstname,$surname,$userflags,$branchcode,$emailaddress";
unless ( $sth->rows ) {
my $sth =
$dbh->prepare(
= $sth->fetchrow
if ( $sth->rows );
-# warn "$cardnumber,$borrowernumber,$userid,$firstname,$surname,$userflags,$branchcode,$emailaddress";
+# warn "$cardnumber,$borrowernumber,$userid,$firstname,$surname,$userflags,$branchcode,$emailaddress";
unless ( $sth->rows ) {
$sth->execute($userid);
(
= $sth->fetchrow
if ( $sth->rows );
}
-
-# warn "$cardnumber,$borrowernumber,$userid,$firstname,$surname,$userflags,$branchcode,$emailaddress";
}
-# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
-# new op dev :
# 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.
my $ip = $ENV{'REMOTE_ADDR'};
+ # if they specify at login, use that
+ if ($query->param('branch')) {
+ $branchcode = $query->param('branch');
+ $branchname = GetBranchName($branchcode);
+ }
my $branches = GetBranches();
my @branchesloop;
foreach my $br ( keys %$branches ) {
-
- # now we work with the treatment of ip
+ # now we work with the treatment of ip
my $domain = $branches->{$br}->{'branchip'};
if ( $domain && $ip =~ /^$domain/ ) {
$branchcode = $branches->{$br}->{'branchcode'};
$branchname = $branches->{$br}->{'branchname'};
}
}
-
- $session->param('number',$borrowernumber);
- $session->param('id',$userid);
- $session->param('cardnumber',$cardnumber);
- $session->param('firstname',$firstname);
- $session->param('surname',$surname);
- $session->param('branch',$branchcode);
- $session->param('branchname',$branchname);
- $session->param('flags',$userflags);
- $session->param('emailaddress',$emailaddress);
+ $session->param('number',$borrowernumber);
+ $session->param('id',$userid);
+ $session->param('cardnumber',$cardnumber);
+ $session->param('firstname',$firstname);
+ $session->param('surname',$surname);
+ $session->param('branch',$branchcode);
+ $session->param('branchname',$branchname);
+ $session->param('flags',$userflags);
+ $session->param('emailaddress',$emailaddress);
$session->param('ip',$session->remote_addr());
- $session->param('lasttime',time());
+ $session->param('lasttime',time());
+# warn "".$session->param('cardnumber').", ".$session->param('firstname').",
+# ".$session->param('surname').", ".$session->param('branch');
}
elsif ( $return == 2 ) {
-
#We suppose the user is the superlibrarian
- $session->param('number',0);
- $session->param('id',C4::Context->config('user'));
- $session->param('cardnumber',C4::Context->config('user'));
- $session->param('firstname',C4::Context->config('user'));
- $session->param('surname',C4::Context->config('user'),);
- $session->param('branch','NO_LIBRARY_SET');
- $session->param('branchname','NO_LIBRARY_SET');
- $session->param('flags',1);
- $session->param('emailaddress', C4::Context->preference('KohaAdminEmailAddress'));
- $session->param('ip',$session->remote_addr());
- $session->param('lasttime',time());
- }
+ $session->param('number',0);
+ $session->param('id',C4::Context->config('user'));
+ $session->param('cardnumber',C4::Context->config('user'));
+ $session->param('firstname',C4::Context->config('user'));
+ $session->param('surname',C4::Context->config('user'));
+ $session->param('branch','NO_LIBRARY_SET');
+ $session->param('branchname','NO_LIBRARY_SET');
+ $session->param('flags',1);
+ $session->param('emailaddress', C4::Context->preference('KohaAdminEmailAddress'));
+ $session->param('ip',$session->remote_addr());
+ $session->param('lasttime',time());
+ }
+ if ($session){
+ C4::Context::set_userenv(
+ $session->param('number'), $session->param('id'),
+ $session->param('cardnumber'), $session->param('firstname'),
+ $session->param('surname'), $session->param('branch'),
+ $session->param('branchname'), $session->param('flags'),
+ $session->param('emailaddress'), $session->param('branchprinter')
+ );
+ }
}
+
else {
if ($userid) {
$info{'invalid_username_or_password'} = 1;
$cookie = $query->cookie( CGISESSID => ''
);
}
- return ( $userid, $cookie, $sessionID, $flags );
+ return ( $userid, $cookie, $sessionID, $flags );
}
- # else we have a problem...
+#
+#
+# AUTH rejected, show the login/password template, after checking the DB.
+#
+#
+
# get the inputs from the incoming query
my @inputs = ();
foreach my $name ( param $query) {
my $value = $query->param($name);
push @inputs, { name => $name, value => $value };
}
+ # get the branchloop, which we need for authentication
+ my $branches = GetBranches();
+ my @branch_loop;
+ for my $branch_hash (keys %$branches) {
+ push @branch_loop, {branchcode => "$branch_hash", branchname => $branches->{$branch_hash}->{'branchname'}, };
+ }
+ # check that database and koha version are the same
+ # there is no DB version, it's a fresh install,
+ # go to web installer
+ # there is a DB version, compare it to the code version
+ my $kohaversion=C4::Context::KOHAVERSION;
+ # remove the 3 last . to have a Perl number
+ $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
+# warn "kohaversion : $kohaversion";
+ if (C4::Context->preference('Version') < $kohaversion){
+ if ($type ne 'opac'){
+ warn "Database update needed, redirecting to Installer. Database is ".C4::Context->preference('Version')." and Koha is : ".C4::Context->config("kohaversion");
+ print $query->redirect("/cgi-bin/koha/installer/install.pl?step=3");
+ } else {
+ warn "OPAC :Database update needed, redirecting to maintenance. Database is ".C4::Context->preference('Version')." and Koha is : ".C4::Context->config("kohaversion");
+ print $query->redirect("/cgi-bin/koha/maintenance.pl");
+ }
+ exit;
+ }
+ my $template_name;
+ if ( $type eq 'opac' ) {
+ $template_name = "opac-auth.tmpl";
+ }
+ else {
+ $template_name = "auth.tmpl";
+ }
my $template = gettemplate( $template_name, $type, $query );
+ $template->param(branchloop => \@branch_loop,);
$template->param(
+ login => 1,
INPUTS => \@inputs,
suggestion => C4::Context->preference("suggestion"),
virtualshelves => C4::Context->preference("virtualshelves"),
# $cookie = $query->cookie(CGISESSID => $session->id
# );
print $query->header(
- -type => 'utf-8',
+ -type => 'text/html',
+ -charset => 'utf-8',
-cookie => $cookie
),
$template->output;
{
# Koha superuser account
-# C4::Context->set_userenv(0,0,C4::Context->config('user'),C4::Context->config('user'),C4::Context->config('user'),"",1);
+# C4::Context->set_userenv(0,0,C4::Context->config('user'),C4::Context->config('user'),C4::Context->config('user'),"",1);
return 2;
}
if ( $userid && $userid eq 'demo'