From f12fc20e1d5863fe239d03090fb618776251eefc Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Thu, 6 Sep 2007 20:47:30 -0500 Subject: [PATCH] Fix to get selectbranchandprinter working fine with the Session Signed-off-by: Chris Cormack --- C4/Auth.pm | 1 + C4/Context.pm | 3 ++- circ/circulation.pl | 33 ++++++++++++++++++++++++++++++--- circ/selectbranchprinter.pl | 31 +++++++++++++++++-------------- 4 files changed, 50 insertions(+), 18 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index a8f0c8797c..c59360ec33 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -562,6 +562,7 @@ sub checkauth { $session->param('emailaddress',$emailaddress); $session->param('ip',$session->remote_addr()); $session->param('lasttime',time()); + $session->param('branchprinter',$branchprinter); } elsif ( $return == 2 ) { #We suppose the user is the superlibrarian diff --git a/C4/Context.pm b/C4/Context.pm index 6451828ebf..7661a5723e 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -803,7 +803,7 @@ set_userenv is called in Auth.pm #' sub set_userenv{ - my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress)= @_; + my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter)= @_; my $var=$context->{"activeuser"}; my $cell = { "number" => $usernum, @@ -816,6 +816,7 @@ sub set_userenv{ "branchname" => $branchname, "flags" => $userflags, "emailaddress" => $emailaddress, + "branchprinter" => $branchprinter }; $context->{userenv}->{$var} = $cell; return $cell; diff --git a/circ/circulation.pl b/circ/circulation.pl index 6d4f60bdf5..15c041c8a2 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -34,6 +34,8 @@ use C4::Circulation; use C4::Members; use C4::Biblio; use C4::Reserves; +use C4::Context; +use CGI::Session; use Date::Calc qw( Today @@ -49,6 +51,31 @@ use Date::Calc qw( # my $query = new CGI; +# new op dev the branch and the printer are now defined by the userenv +# but first we have to check if someone has tried to change them + +my $branch = $query->param('branch'); +if ($branch){ + # update our session so the userenv is updated + my $dbh=C4::Context->dbh; + my $sessionID = $query->cookie("CGISESSID") ; + my $session = new CGI::Session("driver:MySQL", $sessionID, {Handle=>$dbh}); + $session->param('branch',$branch); + my $branchname = GetBranchName($branch); + $session->param('branchname',$branchname); +} + +my $printer = $query->param('printer'); +if ($printer){ + # update our session so the userenv is updated + my $dbh=C4::Context->dbh; + my $sessionID = $query->cookie("CGISESSID") ; + my $session = new CGI::Session("driver:MySQL", $sessionID, {Handle=>$dbh}); + $session->param('branchprinter',$printer); + +} + + my ( $template, $loggedinuser, $cookie ) = get_template_and_user ( { template_name => 'circ/circulation.tmpl', @@ -61,17 +88,17 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user ( my $branches = GetBranches(); my $printers = GetPrinters(); -my $printer = GetPrinter($query, $printers); + my $findborrower = $query->param('findborrower'); $findborrower =~ s|,| |g; #$findborrower =~ s|'| |g; my $borrowernumber = $query->param('borrowernumber'); -# new op dev the branch and the printer are now defined by the userenv -my $branch = C4::Context->userenv->{'branch'}; +$branch = C4::Context->userenv->{'branch'}; $printer = C4::Context->userenv->{'branchprinter'}; + # If Autolocated is not activated, we show the Circulation Parameters to chage settings of librarian if (C4::Context->preference("AutoLocation") ne 1) { diff --git a/circ/selectbranchprinter.pl b/circ/selectbranchprinter.pl index f01860b304..637f1338e6 100755 --- a/circ/selectbranchprinter.pl +++ b/circ/selectbranchprinter.pl @@ -19,6 +19,8 @@ use strict; use CGI qw/:standard/; + +use C4::Context; use C4::Circulation; use C4::Output; use C4::Auth; @@ -39,14 +41,25 @@ my $printers = GetPrinters(); my $branch = $query->param('branch'); my $printer = $query->param('printer'); -my %cookie = $query->cookie('userenv'); -($branch) || ( $branch = $cookie{'branch'} ); -($printer) || ( $printer = $cookie{'printer'} ); +# set header with cookie.... + +my ( $template, $borrowernumber, $cookie ) = get_template_and_user( + { + template_name => "circ/selectbranchprinter.tmpl", + query => $query, + type => "intranet", + authnotrequired => 0, + flagsrequired => { circulate => 1 }, + } +); + +($branch) || ( $branch = C4::Context->userenv->{'branch'} ); +($printer) || ( $printer = C4::Context->userenv->{'branchprinter'} ); ( $branches->{$branch} ) || ( $branch = ( keys %$branches )[0] ); ( $printers->{$printer} ) || ( $printer = ( keys %$printers )[0] ); -# is you force a selection.... +# if you force a selection.... my $oldbranch = $branch; my $oldprinter = $printer; @@ -92,17 +105,7 @@ if ( $branchcount == 1 ) { ################################################################################ # Start writing page.... -# set header with cookie.... -my ( $template, $borrowernumber, $cookie ) = get_template_and_user( - { - template_name => "circ/selectbranchprinter.tmpl", - query => $query, - type => "intranet", - authnotrequired => 0, - flagsrequired => { circulate => 1 }, - } -); $template->param( oneprinter => $oneprinter, onebranch => $onebranch, -- 2.39.5