my $userenv = C4::Context->userenv;
if ( C4::Context->preference("IndependentBranches") ) {
- if ( ( $userenv ) and ( $userenv->{flags} != 1 ) ) {
+ unless ( C4::Context->IsSuperLibrarian() ) {
$query .= q{
AND (
borrowers.branchcode = ?
my @query_params = ( $supplierid, $code, $datereceived );
if ( C4::Context->preference("IndependentBranches") ) {
- my $userenv = C4::Context->userenv;
- if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
+ unless ( C4::Context->IsSuperLibrarian() ) {
$strsth .= " and (borrowers.branchcode = ?
or borrowers.branchcode = '')";
- push @query_params, $userenv->{branch};
+ push @query_params, C4::Context->userenv->{branch};
}
}
$strsth .= " ORDER BY aqbasket.basketno";
$from .= ' AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) <= CAST(now() AS date)';
}
if (C4::Context->preference("IndependentBranches")
- && C4::Context->userenv
- && C4::Context->userenv->{flags} != 1 ) {
+ && !C4::Context->IsSuperLibrarian() ) {
$from .= ' AND borrowers.branchcode LIKE ? ';
push @query_params, C4::Context->userenv->{branch};
}
}
if ( C4::Context->preference("IndependentBranches") ) {
- my $userenv = C4::Context->userenv;
- if ( $userenv && ($userenv->{flags} || 0) != 1 ) {
+ unless ( C4::Context->IsSuperLibrarian() ) {
$query .= " AND (borrowers.branchcode = ? OR borrowers.branchcode ='' ) ";
- push @query_params, $userenv->{branch};
+ push @query_params, C4::Context->userenv->{branch};
}
}
$query .= " ORDER BY id";
}
sub onlymine {
- return
- C4::Context->preference('IndependentBranches') &&
- C4::Context->userenv &&
- C4::Context->userenv->{flags} %2 != 1 &&
- C4::Context->userenv->{branch} ;
+ return
+ C4::Context->preference('IndependentBranches')
+ && C4::Context->userenv
+ && !C4::Context->IsSuperLibrarian()
+ && C4::Context->userenv->{branch};
}
# always returns a string for OK comparison via "eq" or "ne"
}
if ( C4::Context->preference("IndependentBranches") ) {
my $userenv = C4::Context->userenv;
- if ( ($userenv) && ( $userenv->{flags} % 2 != 1 ) ) {
+ unless ( C4::Context->IsSuperLibrarian() ) {
if ( $item->{C4::Context->preference("HomeOrHoldingBranch")} ne $userenv->{branch} ){
$issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
$issuingimpossible{'itemhomebranch'} = $item->{C4::Context->preference("HomeOrHoldingBranch")};
use POSIX ();
use DateTime::TimeZone;
use Module::Load::Conditional qw(can_load);
+use Carp;
=head1 NAME
}
+=head2 IsSuperLibrarian
+
+ C4::Context->IsSuperlibrarian();
+
+=cut
+
+sub IsSuperLibrarian {
+ my $userenv = C4::Context->userenv
+ || carp("C4::Context->userenv not defined!");
+
+ return $userenv->{flags} % 2 == 1;
+}
1;
__END__
$datedue = $idata->{'date_due'};
if (C4::Context->preference("IndependentBranches")){
my $userenv = C4::Context->userenv;
- if ( ($userenv) && ( $userenv->{flags} % 2 != 1 ) ) {
+ unless ( C4::Context->IsSuperLibrarian() ) {
$data->{'NOTSAMEBRANCH'} = 1 if ($idata->{'bcode'} ne $userenv->{branch});
}
}
if ($onloan){
$error = "book_on_loan"
}
- elsif ( !( C4::Context->userenv->{flags} & 1 )
+ elsif ( !C4::Context->IsSuperLibrarian()
and C4::Context->preference("IndependentBranches")
and ( C4::Context->userenv->{branch} ne $item->{'homebranch'} ) )
{
#---- branch
if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
if ( ( C4::Context->preference("IndependentBranches") )
- && ( C4::Context->userenv && C4::Context->userenv->{flags} % 2 != 1 ) ) {
+ && !C4::Context->IsSuperLibrarian() ) {
my $sth = $dbh->prepare( "SELECT branchcode,branchname FROM branches WHERE branchcode = ? ORDER BY branchname" );
$sth->execute( C4::Context->userenv->{branch} );
push @authorised_values, ""
if ( C4::Context->preference("IndependentBranches") ) { # && !$showallbranches){
if ( my $userenv = C4::Context->userenv ) {
my $branch = $userenv->{'branch'};
- if ( ($userenv->{flags} % 2 !=1) && $branch ){
+ if ( !C4::Context->IsSuperLibrarian() && $branch ){
if (my $fr = ref $filter) {
if ( $fr eq "HASH" ) {
$filter->{branchcode} = $branch;
my $filterbranch = $params->{'branchcode'} ||
((C4::Context->preference('IndependentBranches')
&& C4::Context->userenv
- && C4::Context->userenv->{flags} % 2 !=1
+ && !C4::Context->IsSuperLibrarian()
&& C4::Context->userenv->{branch})
? C4::Context->userenv->{branch}
: "");
my $filterbranch = shift ||
((C4::Context->preference('IndependentBranches')
&& C4::Context->userenv
- && C4::Context->userenv->{flags} % 2 !=1
+ && !C4::Context->IsSuperLibrarian()
&& C4::Context->userenv->{branch})
? C4::Context->userenv->{branch}
: "");
my $filterbranch = shift ||
((C4::Context->preference('IndependentBranches')
&& C4::Context->userenv
- && C4::Context->userenv->{flags} % 2 !=1
+ && !C4::Context->IsSuperLibrarian()
&& C4::Context->userenv->{branch})
? C4::Context->userenv->{branch}
: "");
$userid ||= C4::Context->userenv->{'id'};
my $independent_branches = C4::Context->preference('IndependentBranches');
return 1 unless $independent_branches;
- if( $flags % 2 == 1 # superlibrarian
+ if( C4::Context->IsSuperLibrarian()
or C4::Auth::haspermission( $userid, {serials => 'superserials'}),
or C4::Auth::haspermission( $userid, {serials => 'edit_subscription'}),
or not defined $subscription->{branchcode}
if ( C4::Context->preference('IndependentBranches') ) {
my $userenv = C4::Context->userenv;
if ($userenv) {
- if ( ( $userenv->{flags} % 2 ) != 1 && !$suggestion->{branchcode} )
+ if ( !C4::Context->IsSuperLibrarian() && !$suggestion->{branchcode} )
{
push @sql_params, $$userenv{branch};
push @query, q{
if ( C4::Context->preference("IndependentBranches") || $branchcode ) {
my $userenv = C4::Context->userenv;
if ($userenv) {
- unless ( $userenv->{flags} % 2 == 1 ) {
+ unless ( C4::Context->IsSuperLibrarian() ) {
push @sql_params, $userenv->{branch};
$query .= q{ AND (U1.branchcode = ? OR U1.branchcode ='') };
}
$query .= q{ AND (U1.branchcode = ? OR U1.branchcode ='') };
}
}
-
+
my $sth = $dbh->prepare($query);
$sth->execute(@sql_params);
my $results;
my $sth;
my $userenv = C4::Context->userenv;
if ( C4::Context->preference("IndependentBranches")
- && $userenv->{flags} % 2 != 1 )
+ && !C4::Context->IsSuperLibrarian() )
{
my $query = q{
SELECT count(*)
Modify the suggestion according to the hash passed by ref.
The hash HAS to contain suggestionid
-Data not defined is not updated unless it is a note or sort1
+Data not defined is not updated unless it is a note or sort1
Send a mail to notify the user that did the suggestion.
-Note that there is no function to modify a suggestion.
+Note that there is no function to modify a suggestion.
=cut
=head2 DelSuggestionsOlderThan
&DelSuggestionsOlderThan($days)
-
+
Delete all suggestions older than TODAY-$days , that have be accepted or rejected.
-
+
=cut
sub DelSuggestionsOlderThan {
$template->param( delete_confirm => 1 );
if ( C4::Context->preference("IndependentBranches") ) {
my $userenv = C4::Context->userenv;
- unless ( $userenv->{flags} == 1 ) {
+ unless ( C4::Context->IsSuperLibrarian() ) {
my $validtest = ( $basket->{creationdate} eq '' )
|| ( $userenv->{branch} eq $basket->{branch} )
|| ( $userenv->{branch} eq '' )
# get librarian branch...
if ( C4::Context->preference("IndependentBranches") ) {
my $userenv = C4::Context->userenv;
- unless ( $userenv->{flags} == 1 ) {
+ unless ( C4::Context->IsSuperLibrarian() ) {
my $validtest = ( $basket->{creationdate} eq '' )
|| ( $userenv->{branch} eq $basket->{branch} )
|| ( $userenv->{branch} eq '' )
}
# build branches list
-my $onlymine=C4::Context->preference('IndependentBranches') &&
- C4::Context->userenv &&
- C4::Context->userenv->{flags}!=1 &&
- C4::Context->userenv->{branch};
+my $onlymine =
+ C4::Context->preference('IndependentBranches')
+ && C4::Context->userenv
+ && !C4::Context->IsSuperLibrarian()
+ && C4::Context->userenv->{branch};
my $branches = GetBranches($onlymine);
my @branchloop;
foreach my $thisbranch ( sort {$branches->{$a}->{'branchname'} cmp $branches->{$b}->{'branchname'}} keys %$branches ) {
#---- branch
if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
#Use GetBranches($onlymine)
- my $onlymine=C4::Context->preference('IndependentBranches') &&
- C4::Context->userenv &&
- C4::Context->userenv->{flags} % 2 == 0 &&
- C4::Context->userenv->{branch};
+ my $onlymine =
+ C4::Context->preference('IndependentBranches')
+ && C4::Context->userenv
+ && !C4::Context->IsSuperLibrarian()
+ && C4::Context->userenv->{branch};
my $branches = GetBranches($onlymine);
my @branchloop;
foreach my $thisbranch ( sort keys %$branches ) {
my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
-my $onlymine = C4::Context->preference('IndependentBranches') &&
- C4::Context->userenv &&
- C4::Context->userenv->{flags}!=1 &&
- C4::Context->userenv->{branch};
+my $onlymine =
+ C4::Context->preference('IndependentBranches')
+ && C4::Context->userenv
+ && !C4::Context->IsSuperLibrarian()
+ && C4::Context->userenv->{branch};
my $branch = $input->param('branch') || C4::Context->userenv->{branch};
my $branches = GetBranchesLoop($branch,$onlymine); # build once ahead of time, instead of multiple times later.
itemtypename => $description,
};
}
-my $onlymine=C4::Context->preference('IndependentBranches') &&
- C4::Context->userenv &&
- C4::Context->userenv->{flags} % 2 !=1 &&
- C4::Context->userenv->{branch};
+my $onlymine =
+ C4::Context->preference('IndependentBranches')
+ && C4::Context->userenv
+ && !C4::Context->IsSuperLibrarian()
+ && C4::Context->userenv->{branch};
$branchfilter = C4::Context->userenv->{'branch'} if ($onlymine && !$branchfilter);
OR firstname LIKE ?
OR cardnumber LIKE ? )
);
-if (C4::Context->preference("IndependentBranches")){
- if ( C4::Context->userenv
- && (C4::Context->userenv->{flags} % 2) !=1
- && C4::Context->userenv->{'branch'}
- ){
- $sql .= " AND borrowers.branchcode =" . $dbh->quote(C4::Context->userenv->{'branch'});
- }
+if ( C4::Context->preference("IndependentBranches")
+ && C4::Context->userenv
+ && !C4::Context->IsSuperLibrarian()
+ && C4::Context->userenv->{'branch'} )
+{
+ $sql .= " AND borrowers.branchcode ="
+ . $dbh->quote( C4::Context->userenv->{'branch'} );
}
$sql .= q( ORDER BY surname, firstname LIMIT 10);
if (C4::Context->preference("IndependentBranches")) {
my $userenv = C4::Context->userenv;
- if (($userenv->{flags} % 2 != 1) && $bor->{'branchcode'}){
+ if ( !C4::Context->IsSuperLibrarian() && $bor->{'branchcode'}){
unless ($userenv->{branch} eq $bor->{'branchcode'}){
print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_OTHERLIBRARY");
exit;
}
if (C4::Context->preference("IndependentBranches")) {
- if ($userenv && $userenv->{flags} % 2 != 1){
+ unless ( C4::Context->IsSuperLibrarian() ){
$debug and print STDERR " $newdata{'branchcode'} : ".$userenv->{flags}.":".$userenv->{branch};
unless (!$newdata{'branchcode'} || $userenv->{branch} eq $newdata{'branchcode'}){
push @errors, "ERROR_branch";
}
if (C4::Context->preference("IndependentBranches")) {
my $userenv = C4::Context->userenv;
- if ($userenv->{flags} % 2 != 1 && $data{'branchcode'}){
+ if ( !C4::Context->IsSuperLibrarian() && $data{'branchcode'} ) {
unless ($userenv->{branch} eq $data{'branchcode'}){
print $input->redirect("/cgi-bin/koha/members/members-home.pl");
exit;
my $samebranch;
if ( C4::Context->preference("IndependentBranches") ) {
my $userenv = C4::Context->userenv;
- unless ( $userenv->{flags} % 2 == 1 ) {
+ if ( C4::Context->IsSuperLibrarian() ) {
+ $samebranch = 1;
+ }
+ else {
$samebranch = ( $data->{'branchcode'} eq $userenv->{branch} );
}
- $samebranch = 1 if ( $userenv->{flags} % 2 == 1 );
-}else{
+}
+else {
$samebranch = 1;
}
my $branchdetail = GetBranchDetail( $data->{'branchcode'});
my $candeleteuser;
my $userenv = C4::Context->userenv;
-if($userenv->{flags} % 2 == 1){
+if ( C4::Context->IsSuperLibrarian() ) {
$candeleteuser = 1;
-}elsif ( C4::Context->preference("IndependentBranches") ) {
+}
+elsif ( C4::Context->preference("IndependentBranches") ) {
$candeleteuser = ( $data->{'branchcode'} eq $userenv->{branch} );
-}else{
- if( C4::Auth::getuserflags( $userenv->{flags},$userenv->{number})->{borrowers} ) {
+}
+else {
+ if ( C4::Auth::getuserflags( $userenv->{flags}, $userenv->{number} )->{borrowers} ) {
$candeleteuser = 1;
- }else{
+ }
+ else {
$candeleteuser = 0;
}
}
if (! C4::Context->preference("canreservefromotherbranches")){
# cant reserve items so need to check if item homebranch and userenv branch match if not we cant reserve
my $userenv = C4::Context->userenv;
- if ( ($userenv) && ( $userenv->{flags} % 2 != 1 ) ) {
+ unless ( C4::Context->IsSuperLibrarian ) {
$item->{cantreserve} = 1 if ( $item->{homebranch} ne $userenv->{branch} );
}
}
my ($count,$results);
-if (C4::Context->preference("IndependentBranches")){
- if (C4::Context->userenv && C4::Context->userenv->{flags} % 2 !=1 && C4::Context->userenv->{'branch'}){
- $$patron{branchcode}=C4::Context->userenv->{'branch'};
- }
+if ( C4::Context->preference("IndependentBranches") ) {
+ if ( C4::Context->userenv
+ && !C4::Context->IsSuperLibrarian()
+ && C4::Context->userenv->{'branch'} )
+ {
+ $$patron{branchcode} = C4::Context->userenv->{'branch'};
+ }
}
$$patron{firstname}.="\%" if ($$patron{firstname});
$$patron{surname}.="\%" if ($$patron{surname});
}
}
-my $userenv = C4::Context->userenv;
my $onlymine =
C4::Context->preference('IndependentBranches')
- && $userenv
- && $userenv->{flags} % 2 != 1
+ && C4::Context->userenv
+ && !C4::Context->IsSuperLibrarian
&& (
- not C4::Auth::haspermission( $userenv->{id}, { serials => 'superserials' } )
+ not C4::Auth::haspermission( C4::Context->userenv->{id}, { serials => 'superserials' } )
)
- && $userenv->{branch};
-
+ && C4::Context->userenv->{branch};
my $branches = GetBranches($onlymine);
my $branchloop;
for my $thisbranch (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %{$branches}) {
#branch display management
my $branchfilter = ($displayby ne "branchcode") ? $input->param('branchcode') : '';
-my $onlymine=C4::Context->preference('IndependentBranches') &&
- C4::Context->userenv &&
- C4::Context->userenv->{flags}!=1 &&
- C4::Context->userenv->{branch};
+my $onlymine =
+ C4::Context->preference('IndependentBranches')
+ && C4::Context->userenv
+ && !C4::Context->IsSuperLibrarian()
+ && C4::Context->userenv->{branch};
my $branches = GetBranches($onlymine);
my @branchloop;
my $limit_ind_branch =
( C4::Context->preference('IndependentBranches')
&& C4::Context->userenv
- && !( C4::Context->userenv->{flags} & 1 )
+ && !C4::Context->IsSuperLibrarian()
&& C4::Context->userenv->{branch} ) ? 1 : 0;
my $branch = $query->param("branch") || '';
if ( C4::Context->preference("IndependentBranches")
&& C4::Context->userenv
- && !( C4::Context->userenv->{flags} & 1 ) )
+ && !C4::Context->IsSuperLibrarian() )
{
$branch = C4::Context->userenv->{'branch'};
}
my $branch= $input->param('branch') || C4::Context->userenv->{'branch'};
# Set all the branches.
-my $onlymine=(C4::Context->preference('IndependentBranches') &&
- C4::Context->userenv &&
- C4::Context->userenv->{flags} % 2 !=1 &&
- C4::Context->userenv->{branch}?1:0);
+my $onlymine =
+ ( C4::Context->preference('IndependentBranches')
+ && C4::Context->userenv
+ && !C4::Context->IsSuperLibrarian()
+ && C4::Context->userenv->{branch} ? 1 : 0 );
if ( $onlymine ) {
$branch = C4::Context->userenv->{'branch'};
}