From ab77322c089191bfc08de4e400b503869a50350d Mon Sep 17 00:00:00 2001
From: Joshua Ferraro
Date: Wed, 8 Aug 2007 08:37:04 -0500
Subject: [PATCH] adds the ability to set the branch at login,
Signed-off-by: Chris Cormack
---
C4/Auth.pm | 30 ++++++++++++++++++++---
C4/Branch.pm | 3 +--
koha-tmpl/intranet-tmpl/prog/en/auth.tmpl | 11 +++++++--
3 files changed, 36 insertions(+), 8 deletions(-)
diff --git a/C4/Auth.pm b/C4/Auth.pm
index b6ee706ddb..98e9c832b9 100644
--- a/C4/Auth.pm
+++ b/C4/Auth.pm
@@ -114,6 +114,7 @@ C4::Auth - Authenticates Koha users
sub get_template_and_user {
my $in = shift;
+ warn "GET Template";
my $template =
gettemplate( $in->{'template_name'}, $in->{'type'}, $in->{'query'} );
my ( $user, $cookie, $sessionID, $flags ) = checkauth(
@@ -216,8 +217,7 @@ sub get_template_and_user {
}
if ( $in->{'type'} eq "intranet" ) {
$template->param(
- intranetcolorstylesheet =>
- C4::Context->preference("intranetcolorstylesheet"),
+ intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
intranetstylesheet => C4::Context->preference("intranetstylesheet"),
IntranetNav => C4::Context->preference("IntranetNav"),
intranetuserjs => C4::Context->preference("intranetuserjs"),
@@ -383,7 +383,7 @@ sub checkauth {
# 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'} ) {
@@ -545,10 +545,14 @@ sub checkauth {
# 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
my $domain = $branches->{$br}->{'branchip'};
if ( $domain && $ip =~ /^$domain/ ) {
@@ -587,7 +591,17 @@ sub checkauth {
$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;
@@ -617,8 +631,16 @@ sub checkauth {
my $value = $query->param($name);
push @inputs, { name => $name, value => $value };
}
+ # get the branchloop, which we need for authetication
+ use C4::Branch;
+ my $branches = GetBranches();
+ my @branch_loop;
+ for my $branch_hash (keys %$branches) {
+ push @branch_loop, {branchcode => "$branch_hash", branchname => $branches->{$branch_hash}->{'branchname'}, };
+ }
my $template = gettemplate( $template_name, $type, $query );
+ $template->param(branchloop => \@branch_loop,);
$template->param(
INPUTS => \@inputs,
suggestion => C4::Context->preference("suggestion"),
diff --git a/C4/Branch.pm b/C4/Branch.pm
index 4a540be3f4..79d4d54a4b 100644
--- a/C4/Branch.pm
+++ b/C4/Branch.pm
@@ -91,8 +91,7 @@ foreach my $thisbranch (keys %$branches) {
=cut
sub GetBranches {
-
- my $onlymine=@_;
+ my ($onlymine)=@_;
# returns a reference to a hash of references to ALL branches...
my %branches;
my $dbh = C4::Context->dbh;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/auth.tmpl b/koha-tmpl/intranet-tmpl/prog/en/auth.tmpl
index b91d737dfe..69c6c4b511 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/auth.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/auth.tmpl
@@ -43,10 +43,17 @@