Bug Fixing for independantBranches support.
[koha.git] / C4 / Context.pm
index 2d72ae8..091febe 100644 (file)
@@ -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
+C<C4::Context-E<gt>userenv> 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
+C<C4::Context-E<gt>userenv> 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
+C<C4::Context-E<gt>userenv> 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
+C<C4::Context-E<gt>userenv> 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;