package C4::Context;
+
# Copyright 2002 Katipo Communications
#
# This file is part of Koha.
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
-use strict;
-use warnings;
-use vars qw($AUTOLOAD $context @context_stack $servers);
+use Modern::Perl;
+
+use vars qw($AUTOLOAD $context @context_stack);
BEGIN {
if ($ENV{'HTTP_USER_AGENT'}) {
require CGI::Carp;
my $conf_cache = Koha::Caches->get_instance('config');
my $config_from_cache;
if ( $conf_cache->cache ) {
- $config_from_cache = $conf_cache->get_from_cache('koha_conf');
+ $self = $conf_cache->get_from_cache('koha_conf');
}
- unless ( %$self ) {
+ unless ( $self and %$self ) {
$self = Koha::Config->read_from_file($conf_fname);
- }
-
- if ( $config_from_cache ) {
- $self = $config_from_cache;
- } elsif ( $conf_cache->memcached_cache ) {
- # FIXME it may be better to use the memcached servers from the config file
- # to cache it
- $conf_cache->set_in_cache('koha_conf', $self)
+ if ( $conf_cache->memcached_cache ) {
+ # FIXME it may be better to use the memcached servers from the config file
+ # to cache it
+ $conf_cache->set_in_cache('koha_conf', $self)
+ }
}
unless ( exists $self->{config} or defined $self->{config} ) {
warn "The config file ($conf_fname) has not been parsed correctly";
my $self = shift;
my $var = shift; # The system preference to return
- $var = lc $var;
-
return $ENV{"OVERRIDE_SYSPREF_$var"}
if defined $ENV{"OVERRIDE_SYSPREF_$var"};
- my $cached_var = $use_syspref_cache
- ? $syspref_cache->get_from_cache("syspref_$var")
- : undef;
- return $cached_var if defined $cached_var;
+ $var = lc $var;
+
+ if ($use_syspref_cache) {
+ $syspref_cache = Koha::Caches->get_instance('syspref') unless $syspref_cache;
+ my $cached_var = $syspref_cache->get_from_cache("syspref_$var");
+ return $cached_var if defined $cached_var;
+ }
my $syspref;
eval { $syspref = Koha::Config::SysPrefs->find( lc $var ) };
C4::Context->set_userenv($usernum, $userid, $usercnum,
$userfirstname, $usersurname,
$userbranch, $branchname, $userflags,
- $emailaddress, $branchprinter, $persona);
+ $emailaddress, $branchprinter, $shibboleth);
Establish a hash of user environment variables.
#'
sub set_userenv {
shift @_;
- my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter, $persona, $shibboleth)=
+ my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter, $shibboleth)=
map { Encode::is_utf8( $_ ) ? $_ : Encode::decode('UTF-8', $_) } # CGI::Session doesn't handle utf-8, so we decode it here
@_;
my $var=$context->{"activeuser"} || '';
"flags" => $userflags,
"emailaddress" => $emailaddress,
"branchprinter" => $branchprinter,
- "persona" => $persona,
"shibboleth" => $shibboleth,
};
$context->{userenv}->{$var} = $cell;
return $context->{interface} // 'opac';
}
+# always returns a string for OK comparison via "eq" or "ne"
+sub mybranch {
+ C4::Context->userenv or return '';
+ return C4::Context->userenv->{branch} || '';
+}
+
+=head2 only_my_library
+
+ my $test = C4::Context->only_my_library;
+
+ Returns true if you enabled IndependentBranches and the current user
+ does not have superlibrarian permissions.
+
+=cut
+
+sub only_my_library {
+ return
+ C4::Context->preference('IndependentBranches')
+ && C4::Context->userenv
+ && !C4::Context->IsSuperLibrarian()
+ && C4::Context->userenv->{branch};
+}
+
1;
+
__END__
=head1 ENVIRONMENT