+=head2 IsSuperLibrarian
+
+ C4::Context->IsSuperLibrarian();
+
+=cut
+
+sub IsSuperLibrarian {
+ my $userenv = C4::Context->userenv;
+
+ unless ( $userenv and exists $userenv->{flags} ) {
+ # If we reach this without a user environment,
+ # assume that we're running from a command-line script,
+ # and act as a superlibrarian.
+ carp("C4::Context->userenv not defined!");
+ return 1;
+ }
+
+ return ($userenv->{flags}//0) % 2;
+}
+
+=head2 interface
+
+Sets the current interface for later retrieval in any Perl module
+
+ C4::Context->interface('opac');
+ C4::Context->interface('intranet');
+ my $interface = C4::Context->interface;
+
+=cut
+
+sub interface {
+ my ($class, $interface) = @_;
+
+ if (defined $interface) {
+ $interface = lc $interface;
+ if ($interface eq 'opac' || $interface eq 'intranet' || $interface eq 'sip' || $interface eq 'commandline') {
+ $context->{interface} = $interface;
+ } else {
+ warn "invalid interface : '$interface'";
+ }
+ }
+
+ 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};
+}
+
+=head3 temporary_directory
+
+Returns root directory for temporary storage
+
+=cut
+
+sub temporary_directory {
+ my ( $class ) = @_;
+ return C4::Context->config('tmp_path') || File::Spec->tmpdir;
+}
+