X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FContext.pm;h=091febe0f87a8f0d5862f11dcd22d8ff77ff3243;hb=31fca3dfd248f020cbe44be9c196eedf3a03a079;hp=2d72ae8d518970ed4a470fd2101b5ce3a0765c3e;hpb=e54459b76321a55a0ace15f011649761a424657d;p=koha.git diff --git a/C4/Context.pm b/C4/Context.pm index 2d72ae8d51..091febe0f8 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -226,11 +226,14 @@ sub new # Load the desired config file. $self->{"config"} = &read_config_file($conf_fname); + warn "read_config_file($conf_fname) returned undef" if !defined($self->{"config"}); return undef if !defined($self->{"config"}); $self->{"dbh"} = undef; # Database handle $self->{"stopwords"} = undef; # stopwords list $self->{"marcfromkohafield"} = undef; # the hash with relations between koha table fields and MARC field/subfield + $self->{"userenv"} = undef; # User env + $self->{"activeuser"} = undef; # current active user bless $self, $class; return $self; @@ -596,6 +599,105 @@ sub _new_stopwords return $stopwordlist; } +=item userenv + + %userenv = C4::Context->userenv; + +Returns a hash with userenvironment variables. + +This hash is cached for future use: if you call +Cuserenv> twice, you will get the same hash without real DB access + +Returns Null if userenv is not set. +userenv is set in _new_userenv, called in Auth.pm + +=cut +#' + +=item userenv + + C4::Context->userenv; + +Builds a hash for user environment variables. + +This hash shall be cached for future use: if you call +Cuserenv> twice, you will get the same hash without real DB access + +set_userenv is called in Auth.pm + +=cut +#' +sub userenv +{ + my $var = $context->{"activeuser"}; + return $context->{"userenv"}->{$var} if (defined $context->{"userenv"}->{$var}); +} + +=item userenv + + C4::Context->set_userenv; + +Builds a hash for user environment variables. + +This hash shall be cached for future use: if you call +Cuserenv> twice, you will get the same hash without real DB access + +set_userenv is called in Auth.pm + +=cut +#' +sub set_userenv{ + my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $userflags)= @_; + my $var=$context->{"activeuser"}; + my $cell = { + "number" => $usernum, + "id" => $userid, + "cardnumber" => $usercnum, + "firstname" => $userfirstname, + "surname" => $usersurname, + "branch" => $userbranch, + "flags" => $userflags + }; + $context->{userenv}->{$var} = $cell; + return $cell; +} + +=item _new_userenv + + C4::Context->_new_userenv($session); + +Builds a hash for user environment variables. + +This hash shall be cached for future use: if you call +Cuserenv> twice, you will get the same hash without real DB access + +_new_userenv is called in Auth.pm + +=cut +#' +sub _new_userenv +{ + shift; + my ($sessionID)= @_; + $context->{"activeuser"}=$sessionID; +} + +=item _unset_userenv + + C4::Context->_unset_userenv; + +Destroys the hash for activeuser user environment variables. + +=cut +#' + +sub _unset_userenv +{ + my ($sessionID)= @_; +# undef $context->{$sessionID}; + undef $context->{"activeuser"} if ($context->{"activeuser"} eq $sessionID); +# $context->{"activeuser"}--; +} 1;