use strict;
use warnings;
use Digest::MD5 qw(md5_base64);
-use JSON qw/encode_json decode_json/;
+use JSON qw/encode_json/;
use URI::Escape;
use CGI::Session;
require Exporter;
use C4::Context;
use C4::Templates; # to get the template
+use C4::Languages;
use C4::Branch; # GetBranches
+use C4::Search::History;
use C4::VirtualShelves;
use Koha::AuthUtils qw(hash_password);
use POSIX qw/strftime/;
@EXPORT = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions);
@EXPORT_OK = qw(&check_api_auth &get_session &check_cookie_auth &checkpw &checkpw_internal &checkpw_hash
&get_all_subpermissions &get_user_subpermissions
- ParseSearchHistorySession SetSearchHistorySession
);
%EXPORT_TAGS = ( EditPermissions => [qw(get_all_subpermissions get_user_subpermissions)] );
$ldap = C4::Context->config('useldapserver') || 0;
template_name => "opac-main.tmpl",
query => $query,
type => "opac",
- authnotrequired => 1,
+ authnotrequired => 0,
flagsrequired => {borrow => 1, catalogue => '*', tools => 'import_patrons' },
}
);
template_name => "opac-main.tmpl",
query => $query,
type => "opac",
- authnotrequired => 1,
+ authnotrequired => 0,
flagsrequired => {borrow => 1, catalogue => '*', tools => 'import_patrons' },
}
);
=cut
-my $SEARCH_HISTORY_INSERT_SQL =<<EOQ;
-INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, total, time )
-VALUES ( ?, ?, ?, ?, ?, FROM_UNIXTIME(?))
-EOQ
-
sub get_template_and_user {
my $in = shift;
my ( $user, $cookie, $sessionID, $flags );
+ C4::Context->interface($in->{type});
+
+ $in->{'authnotrequired'} ||= 0;
my $template = C4::Templates::gettemplate(
$in->{'template_name'},
$in->{'type'},
# If at least one search has already been performed
if ($sth->fetchrow_array > 0) {
- # We show the link in opac
- $template->param(ShowOpacRecentSearchLink => 1);
+ # We show the link in opac
+ $template->param( EnableOpacSearchHistory => 1 );
}
# And if there are searches performed when the user was not logged in,
# we add them to the logged-in search history
- my @recentSearches = ParseSearchHistorySession($in->{'query'});
+ my @recentSearches = C4::Search::History::get_from_session({ cgi => $in->{'query'} });
if (@recentSearches) {
- my $sth = $dbh->prepare($SEARCH_HISTORY_INSERT_SQL);
+ my $dbh = C4::Context->dbh;
+ my $query = q{
+ INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, type, total, time )
+ VALUES (?, ?, ?, ?, ?, ?, ?)
+ };
+
+ my $sth = $dbh->prepare($query);
$sth->execute( $borrowernumber,
- $in->{'query'}->cookie("CGISESSID"),
- $_->{'query_desc'},
- $_->{'query_cgi'},
- $_->{'total'},
- $_->{'time'},
+ $in->{query}->cookie("CGISESSID"),
+ $_->{query_desc},
+ $_->{query_cgi},
+ $_->{type} || 'biblio',
+ $_->{total},
+ $_->{time},
) foreach @recentSearches;
# clear out the search history from the session now that
# we've saved it to the database
- SetSearchHistorySession($in->{'query'}, []);
+ C4::Search::History::set_to_session({ cgi => $in->{'query'}, search_history => [] });
}
+ } elsif ( $in->{type} eq 'intranet' and C4::Context->preference('EnableSearchHistory') ) {
+ $template->param( EnableSearchHistory => 1 );
}
}
else { # if this is an anonymous session, setup to display public lists...
# Anonymous opac search history
# If opac search history is enabled and at least one search has already been performed
if (C4::Context->preference('EnableOpacSearchHistory')) {
- my @recentSearches = ParseSearchHistorySession($in->{'query'});
+ my @recentSearches = C4::Search::History::get_from_session({ cgi => $in->{'query'} });
if (@recentSearches) {
- $template->param(ShowOpacRecentSearchLink => 1);
+ $template->param(EnableOpacSearchHistory => 1);
}
}
}
# these template parameters are set the same regardless of $in->{'type'}
+
+ # Set the using_https variable for templates
+ # FIXME Under Plack the CGI->https method always returns 'OFF'
+ my $https = $in->{query}->https();
+ my $using_https = (defined $https and $https ne 'OFF') ? 1 : 0;
+
$template->param(
"BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
EnhancedMessagingPreferences => C4::Context->preference('EnhancedMessagingPreferences'),
singleBranchMode => C4::Context->preference("singleBranchMode"),
XSLTDetailsDisplay => C4::Context->preference("XSLTDetailsDisplay"),
XSLTResultsDisplay => C4::Context->preference("XSLTResultsDisplay"),
- using_https => $in->{'query'}->https() ? 1 : 0,
+ using_https => $using_https,
noItemTypeImages => C4::Context->preference("noItemTypeImages"),
marcflavour => C4::Context->preference("marcflavour"),
persona => C4::Context->preference("persona"),
my $opac_search_limit = $ENV{'OPAC_SEARCH_LIMIT'};
my $opac_limit_override = $ENV{'OPAC_LIMIT_OVERRIDE'};
my $opac_name = '';
- if (($opac_search_limit && $opac_search_limit =~ /branch:(\w+)/ && $opac_limit_override) || ($in->{'query'}->param('limit') && $in->{'query'}->param('limit') =~ /branch:(\w+)/)){
+ if (
+ ($opac_limit_override && $opac_search_limit && $opac_search_limit =~ /branch:(\w+)/) ||
+ ($in->{'query'}->param('limit') && $in->{'query'}->param('limit') =~ /branch:(\w+)/) ||
+ ($in->{'query'}->param('multibranchlimit') && $in->{'query'}->param('multibranchlimit') =~ /multibranchlimit-(\w+)/)
+ ) {
$opac_name = $1; # opac_search_limit is a branch, so we use it.
} elsif ( $in->{'query'}->param('multibranchlimit') ) {
$opac_name = $in->{'query'}->param('multibranchlimit');
# Check if we were asked using parameters to force a specific language
if ( defined $in->{'query'}->param('language') ) {
- # Extract the language, let C4::Templates::getlanguage choose
+ # Extract the language, let C4::Languages::getlanguage choose
# what to do
- my $language = C4::Templates::getlanguage($in->{'query'},$in->{'type'});
+ my $language = C4::Languages::getlanguage($in->{'query'});
my $languagecookie = C4::Templates::getlanguagecookie($in->{'query'},$language);
if ( ref $cookie eq 'ARRAY' ) {
push @{ $cookie }, $languagecookie;
PatronSelfRegistrationDefaultCategory => C4::Context->preference("PatronSelfRegistrationDefaultCategory"),
persona => C4::Context->preference("Persona"),
opac_css_override => $ENV{'OPAC_CSS_OVERRIDE'},
- NoLoginInstructions => C4::Context->preference("NoLoginInstructions"),
);
$template->param( OpacPublic => C4::Context->preference("OpacPublic"));
$debug and print STDERR "## checkpw - checking CAS\n";
# In case of a CAS authentication, we use the ticket instead of the password
my $ticket = $query->param('ticket');
+ $query->delete('ticket'); # remove ticket to come back to original URL
my ($retval,$retcard,$retuserid) = checkpw_cas($dbh, $ticket, $query); # EXTERNAL AUTH
($retval) and return ($retval,$retcard,$retuserid);
return 0;
sub checkpw_internal {
my ( $dbh, $userid, $password ) = @_;
+ if ( $userid && $userid eq C4::Context->config('user') ) {
+ if ( $password && $password eq C4::Context->config('pass') ) {
+ # Koha superuser account
+# C4::Context->set_userenv(0,0,C4::Context->config('user'),C4::Context->config('user'),C4::Context->config('user'),"",1);
+ return 2;
+ }
+ else {
+ return 0;
+ }
+ }
+
my $sth =
$dbh->prepare(
"select password,cardnumber,borrowernumber,userid,firstname,surname,branchcode,flags from borrowers where userid=?"
return 1, $cardnumber, $userid;
}
}
- if ( $userid && $userid eq C4::Context->config('user')
- && "$password" eq C4::Context->config('pass') )
- {
-
-# Koha superuser account
-# 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'
&& "$password" eq 'demo'
&& C4::Context->config('demo') )
return 0;
}
-sub ParseSearchHistorySession {
- my $cgi = shift;
- my $sessionID = $cgi->cookie('CGISESSID');
- return () unless $sessionID;
- my $session = get_session($sessionID);
- return () unless $session and $session->param('search_history');
- my $obj = eval { decode_json(uri_unescape($session->param('search_history'))) };
- return () unless defined $obj;
- return () unless ref $obj eq 'ARRAY';
- return @{ $obj };
-}
-
-sub SetSearchHistorySession {
- my ($cgi, $search_history) = @_;
- my $sessionID = $cgi->cookie('CGISESSID');
- return () unless $sessionID;
- my $session = get_session($sessionID);
- return () unless $session;
- $session->param('search_history', uri_escape(encode_json($search_history)));
-}
-
END { } # module clean-up code here (global destructor)
1;
__END__