-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA 02111-1307 USA
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-=over 2
-
-=item get_template_and_user
-
- my ($template, $borrowernumber, $cookie)
- = get_template_and_user(
- {
- template_name => "opac-main.tmpl",
- query => $query,
- type => "opac",
- authnotrequired => 1,
- flagsrequired => {borrow => 1, catalogue => '*', tools => 'import_patrons' },
- }
- );
-
- This call passes the C<query>, C<flagsrequired> and C<authnotrequired>
- to C<&checkauth> (in this module) to perform authentification.
- See C<&checkauth> for an explanation of these parameters.
-
- The C<template_name> is then used to find the correct template for
- the page. The authenticated users details are loaded onto the
- template in the HTML::Template LOOP variable C<USER_INFO>. Also the
- C<sessionID> is passed to the template. This can be used in templates
- if cookies are disabled. It needs to be put as and input to every
- authenticated page.
-
- More information on the C<gettemplate> sub can be found in the
- Output.pm module.
+=head2 get_template_and_user
+
+ my ($template, $borrowernumber, $cookie)
+ = get_template_and_user(
+ {
+ template_name => "opac-main.tmpl",
+ query => $query,
+ type => "opac",
+ authnotrequired => 1,
+ flagsrequired => {borrow => 1, catalogue => '*', tools => 'import_patrons' },
+ }
+ );
+
+This call passes the C<query>, C<flagsrequired> and C<authnotrequired>
+to C<&checkauth> (in this module) to perform authentification.
+See C<&checkauth> for an explanation of these parameters.
+
+The C<template_name> is then used to find the correct template for
+the page. The authenticated users details are loaded onto the
+template in the HTML::Template LOOP variable C<USER_INFO>. Also the
+C<sessionID> is passed to the template. This can be used in templates
+if cookies are disabled. It needs to be put as and input to every
+authenticated page.
+
+More information on the C<gettemplate> sub can be found in the
+Output.pm module.
- if (thaw($searchcookie)) {
- @recentSearches = @{thaw($searchcookie)};
- }
-
- if (@recentSearches > 0) {
- my $query = "INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, total, time) VALUES";
- my $icount = 1;
- foreach my $asearch (@recentSearches) {
- $query .= "(";
- $query .= $borrowernumber . ", ";
- $query .= '"' . $in->{'query'}->cookie("CGISESSID") . "\", ";
- $query .= '"' . $asearch->{'query_desc'} . "\", ";
- $query .= '"' . $asearch->{'query_cgi'} . "\", ";
- $query .= $asearch->{'total'} . ", ";
- $query .= 'FROM_UNIXTIME(' . $asearch->{'time'} . "))";
- if ($icount < @recentSearches) { $query .= ", ";}
- $icount++;
- }
-
- my $sth = $dbh->prepare($query);
- $sth->execute;
+ my @recentSearches = @{thaw($searchcookie) || []};
+ if (@recentSearches) {
+ my $sth = $dbh->prepare($SEARCH_HISTORY_INSERT_SQL);
+ $sth->execute( $borrowernumber,
+ $in->{'query'}->cookie("CGISESSID"),
+ $_->{'query_desc'},
+ $_->{'query_cgi'},
+ $_->{'total'},
+ $_->{'time'},
+ ) foreach @recentSearches;
- my $mylibraryfirst = C4::Context->preference("SearchMyLibraryFirst");
- my $opac_name;
- if($opac_limit_override && ($opac_search_limit =~ /branch:(\w+)/) ){
- $opac_name = C4::Branch::GetBranchName($1) # opac_search_limit is a branch, so we use it.
- } elsif($mylibraryfirst){
- $opac_name = C4::Branch::GetBranchName($mylibraryfirst);
+ my $opac_name = '';
+ if (($opac_search_limit =~ /branch:(\w+)/ && $opac_limit_override) || $in->{'query'}->param('limit') =~ /branch:(\w+)/){
+ $opac_name = $1; # opac_search_limit is a branch, so we use it.
+ } elsif (C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv && C4::Context->userenv->{'branch'}) {
+ $opac_name = C4::Context->userenv->{'branch'};
hidelostitems => C4::Context->preference("hidelostitems"),
mylibraryfirst => (C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv) ? C4::Context->userenv->{'branch'} : '',
opaclayoutstylesheet => "" . C4::Context->preference("opaclayoutstylesheet"),
hidelostitems => C4::Context->preference("hidelostitems"),
mylibraryfirst => (C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv) ? C4::Context->userenv->{'branch'} : '',
opaclayoutstylesheet => "" . C4::Context->preference("opaclayoutstylesheet"),
- OPACSerialIssueDisplayCount => C4::Context->preference("OPACSerialIssueDisplayCount"),
+ OPACSerialIssueDisplayCount => C4::Context->preference("OPACSerialIssueDisplayCount"),
+ OpacAddMastheadLibraryPulldown => C4::Context->preference("OpacAddMastheadLibraryPulldown"),
+ OPACXSLTDetailsDisplay => C4::Context->preference("OPACXSLTDetailsDisplay"),
+ OPACXSLTResultsDisplay => C4::Context->preference("OPACXSLTResultsDisplay"),
+ SyndeticsClientCode => C4::Context->preference("SyndeticsClientCode"),
+ SyndeticsEnabled => C4::Context->preference("SyndeticsEnabled"),
+ SyndeticsCoverImages => C4::Context->preference("SyndeticsCoverImages"),
+ SyndeticsTOC => C4::Context->preference("SyndeticsTOC"),
+ SyndeticsSummary => C4::Context->preference("SyndeticsSummary"),
+ SyndeticsEditions => C4::Context->preference("SyndeticsEditions"),
+ SyndeticsExcerpt => C4::Context->preference("SyndeticsExcerpt"),
+ SyndeticsReviews => C4::Context->preference("SyndeticsReviews"),
+ SyndeticsAuthorNotes => C4::Context->preference("SyndeticsAuthorNotes"),
+ SyndeticsAwards => C4::Context->preference("SyndeticsAwards"),
+ SyndeticsSeries => C4::Context->preference("SyndeticsSeries"),
+ SyndeticsCoverImageSize => C4::Context->preference("SyndeticsCoverImageSize"),
- if ( $userid = $query->param('userid') ) {
- my $password = $query->param('password');
- my ( $return, $cardnumber ) = checkpw( $dbh, $userid, $password );
- if ($return) {
- _session_log(sprintf "%20s from %16s logged in at %30s.\n", $userid,$ENV{'REMOTE_ADDR'},(strftime "%c",localtime));
- if ( $flags = haspermission($userid, $flagsrequired) ) {
- $loggedin = 1;
- }
- else {
- $info{'nopermission'} = 1;
- C4::Context->_unset_userenv($sessionID);
- }
+ $userid = $query->param('userid');
+ if ($cas || $userid) {
+ my $password = $query->param('password');
+ my ($return, $cardnumber);
+ if ($cas && $query->param('ticket')) {
+ my $retuserid;
+ ( $return, $cardnumber, $retuserid ) = checkpw( $dbh, $userid, $password, $query );
+ $userid = $retuserid;
+ $info{'invalidCasLogin'} = 1 unless ($return);
+ } else {
+ ( $return, $cardnumber ) = checkpw( $dbh, $userid, $password, $query );
+ }
+ if ($return) {
+ _session_log(sprintf "%20s from %16s logged in at %30s.\n", $userid,$ENV{'REMOTE_ADDR'},(strftime '%c', localtime));
+ if ( $flags = haspermission( $userid, $flagsrequired ) ) {
+ $loggedin = 1;
+ }
+ else {
+ $info{'nopermission'} = 1;
+ C4::Context->_unset_userenv($sessionID);
+ }
- my ($borrowernumber, $firstname, $surname, $userflags,
- $branchcode, $branchname, $branchprinter, $emailaddress);
-
- if ( $return == 1 ) {
- my $select = "
- 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
- ";
- my $sth = $dbh->prepare("$select where userid=?");
- $sth->execute($userid);
- unless ($sth->rows) {
- $debug and print STDERR "AUTH_1: no rows for userid='$userid'\n";
- $sth = $dbh->prepare("$select where cardnumber=?");
- $sth->execute($cardnumber);
- unless ($sth->rows) {
- $debug and print STDERR "AUTH_2a: no rows for cardnumber='$cardnumber'\n";
- $sth->execute($userid);
- unless ($sth->rows) {
- $debug and print STDERR "AUTH_2b: no rows for userid='$userid' AS cardnumber\n";
- }
- }
- }
- if ($sth->rows) {
- ($borrowernumber, $firstname, $surname, $userflags,
- $branchcode, $branchname, $branchprinter, $emailaddress) = $sth->fetchrow;
- $debug and print STDERR "AUTH_3 results: " .
- "$cardnumber,$borrowernumber,$userid,$firstname,$surname,$userflags,$branchcode,$emailaddress\n";
- } else {
- print STDERR "AUTH_3: no results for userid='$userid', cardnumber='$cardnumber'.\n";
- }
+ my ($borrowernumber, $firstname, $surname, $userflags,
+ $branchcode, $branchname, $branchprinter, $emailaddress);
+
+ if ( $return == 1 ) {
+ my $select = "
+ 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
+ ";
+ my $sth = $dbh->prepare("$select where userid=?");
+ $sth->execute($userid);
+ unless ($sth->rows) {
+ $debug and print STDERR "AUTH_1: no rows for userid='$userid'\n";
+ $sth = $dbh->prepare("$select where cardnumber=?");
+ $sth->execute($cardnumber);
+ unless ($sth->rows) {
+ $debug and print STDERR "AUTH_2a: no rows for cardnumber='$cardnumber'\n";
+ $sth->execute($userid);
+ unless ($sth->rows) {
+ $debug and print STDERR "AUTH_2b: no rows for userid='$userid' AS cardnumber\n";
+ }
+ }
+ }
+ if ($sth->rows) {
+ ($borrowernumber, $firstname, $surname, $userflags,
+ $branchcode, $branchname, $branchprinter, $emailaddress) = $sth->fetchrow;
+ $debug and print STDERR "AUTH_3 results: " .
+ "$cardnumber,$borrowernumber,$userid,$firstname,$surname,$userflags,$branchcode,$emailaddress\n";
+ } else {
+ print STDERR "AUTH_3: no results for userid='$userid', cardnumber='$cardnumber'.\n";
+ }
suggestion => C4::Context->preference("suggestion"),
virtualshelves => C4::Context->preference("virtualshelves"),
LibraryName => C4::Context->preference("LibraryName"),
opacuserlogin => C4::Context->preference("opacuserlogin"),
OpacNav => C4::Context->preference("OpacNav"),
opaccredits => C4::Context->preference("opaccredits"),
suggestion => C4::Context->preference("suggestion"),
virtualshelves => C4::Context->preference("virtualshelves"),
LibraryName => C4::Context->preference("LibraryName"),
opacuserlogin => C4::Context->preference("opacuserlogin"),
OpacNav => C4::Context->preference("OpacNav"),
opaccredits => C4::Context->preference("opaccredits"),
intranetcolorstylesheet =>
C4::Context->preference("intranetcolorstylesheet"),
intranetstylesheet => C4::Context->preference("intranetstylesheet"),
intranetbookbag => C4::Context->preference("intranetbookbag"),
IntranetNav => C4::Context->preference("IntranetNav"),
intranetuserjs => C4::Context->preference("intranetuserjs"),
intranetcolorstylesheet =>
C4::Context->preference("intranetcolorstylesheet"),
intranetstylesheet => C4::Context->preference("intranetstylesheet"),
intranetbookbag => C4::Context->preference("intranetbookbag"),
IntranetNav => C4::Context->preference("IntranetNav"),
intranetuserjs => C4::Context->preference("intranetuserjs"),
- my ( $return, $cardnumber ) = checkpw( $dbh, $userid, $password );
- if ($return and haspermission($userid, $flagsrequired)) {
+ my ($return, $cardnumber);
+ if ($cas && $query->param('ticket')) {
+ my $retuserid;
+ ( $return, $cardnumber, $retuserid ) = checkpw( $dbh, $userid, $password, $query );
+ $userid = $retuserid;
+ } else {
+ ( $return, $cardnumber ) = checkpw( $dbh, $userid, $password, $query );
+ }
+ if ($return and haspermission( $userid, $flagsrequired)) {
my ( $md5password, $cardnumber, $borrowernumber, $userid, $firstname,
$surname, $branchcode, $flags )
= $sth->fetchrow;
my ( $md5password, $cardnumber, $borrowernumber, $userid, $firstname,
$surname, $branchcode, $flags )
= $sth->fetchrow;