View | Details | Raw Unified | Return to bug 10278
Collapse All | Expand All

(-)a/C4/Auth.pm (-1 / +1 lines)
Lines 758-764 sub checkauth { Link Here
758
                $session->param('surname'),      $session->param('branch'),
758
                $session->param('surname'),      $session->param('branch'),
759
                $session->param('branchname'),   $session->param('flags'),
759
                $session->param('branchname'),   $session->param('flags'),
760
                $session->param('emailaddress'), $session->param('branchprinter'),
760
                $session->param('emailaddress'), $session->param('branchprinter'),
761
                $session->param('persona'),      $session->param('shibboleth')
761
                $session->param('persona'),      $session->param('shibboleth'), $type
762
            );
762
            );
763
            C4::Context::set_shelves_userenv( 'bar', $session->param('barshelves') );
763
            C4::Context::set_shelves_userenv( 'bar', $session->param('barshelves') );
764
            C4::Context::set_shelves_userenv( 'pub', $session->param('pubshelves') );
764
            C4::Context::set_shelves_userenv( 'pub', $session->param('pubshelves') );
(-)a/C4/Branch.pm (-15 / +65 lines)
Lines 42-47 BEGIN { Link Here
42
		&GetCategoryTypes
42
		&GetCategoryTypes
43
		&GetBranchCategories
43
		&GetBranchCategories
44
		&GetBranchesInCategory
44
		&GetBranchesInCategory
45
        &GetCategoriesForBranch
45
		&ModBranchCategoryInfo
46
		&ModBranchCategoryInfo
46
        &GetIndependentGroupModificationRights
47
        &GetIndependentGroupModificationRights
47
		&DelBranch
48
		&DelBranch
Lines 108-113 Create a branch selector with the following code. Link Here
108
109
109
sub GetBranches {
110
sub GetBranches {
110
    my ($onlymine) = @_;
111
    my ($onlymine) = @_;
112
    $onlymine ||= onlymine();
111
113
112
    # returns a reference to a hash of references to ALL branches...
114
    # returns a reference to a hash of references to ALL branches...
113
    my %branches;
115
    my %branches;
Lines 429-434 sub GetBranchesInCategory { Link Here
429
	return( \@branches );
431
	return( \@branches );
430
}
432
}
431
433
434
=head2 GetCategoriesForBranch
435
436
    my @categories = GetCategoriesForBranch({
437
        branchcode   => $branchcode,
438
        categorytype => 'independent_group'
439
    });
440
441
    Called in a list context, returns an array of branch category codes
442
    that branch is part of.
443
444
    Called in a scalar context, returns an array ref.
445
446
=cut
447
448
sub GetCategoriesForBranch {
449
    my ( $params ) = @_;
450
    my $branchcode = $params->{branchcode};
451
    my $categorytype = $params->{categorytype} || '%';
452
453
    carp("Missing branchcode parameter!") unless ( $branchcode );
454
455
    my $sql = q{
456
        SELECT categorycode FROM branchrelations
457
        JOIN branchcategories USING ( categorycode )
458
        WHERE branchcode   = ?
459
          AND categorytype = ?
460
    };
461
462
    my $categories = C4::Context->dbh->selectcol_arrayref( $sql, {}, ( $branchcode, $categorytype ) );
463
464
    return wantarray() ? $categories : @$categories;
465
}
466
432
=head2 GetIndependentGroupModificationRights
467
=head2 GetIndependentGroupModificationRights
433
468
434
    GetIndependentGroupModificationRights(
469
    GetIndependentGroupModificationRights(
Lines 463-491 sub GetBranchesInCategory { Link Here
463
sub GetIndependentGroupModificationRights {
498
sub GetIndependentGroupModificationRights {
464
    my ($params) = @_;
499
    my ($params) = @_;
465
500
466
    my $this_branch  = $params->{branch};
501
    my $this_branch  = $params->{branch}    ||= q{};
467
    my $other_branch = $params->{for};
502
    my $other_branch = $params->{for}       ||= q{};
468
503
504
    $this_branch ||= $ENV{BRANCHCODE};
469
    $this_branch ||= C4::Context->userenv->{branch};
505
    $this_branch ||= C4::Context->userenv->{branch};
470
506
471
    carp("No branch found!") unless ($this_branch);
507
    unless ($this_branch) {
508
        carp("No branch found!");
509
        return;
510
    }
472
511
473
    return 1 if ( $this_branch eq $other_branch );
512
    return 1 if ( $this_branch eq $other_branch );
474
513
475
    my $sql = q{
514
    my $allow_all = 0;
476
        SELECT DISTINCT(branchcode)
515
    $allow_all = 1 if C4::Context->IsSuperLibrarian();
477
        FROM branchrelations
516
    $allow_all = 1 if C4::Context->userenv->{type} eq 'opac' && !$ENV{BRANCHCODE};
478
        JOIN branchcategories USING ( categorycode )
479
        WHERE categorycode IN (
480
            SELECT categorycode
481
            FROM branchrelations
482
            WHERE branchcode = ?
483
        )
484
        AND branchcategories.categorytype = 'independent_group'
485
    };
486
517
518
    my $sql;
487
    my @params;
519
    my @params;
488
    push( @params, $this_branch );
520
521
    if ( $allow_all ) {
522
        $sql = q{
523
            SELECT branchcode FROM branches WHERE 1
524
        }
525
    } else {
526
        $sql = q{
527
            SELECT DISTINCT(branchcode)
528
            FROM branchrelations
529
            JOIN branchcategories USING ( categorycode )
530
            WHERE categorycode IN (
531
                SELECT categorycode
532
                FROM branchrelations
533
                WHERE branchcode = ?
534
            )
535
            AND branchcategories.categorytype = 'independent_group'
536
        };
537
        push( @params, $this_branch );
538
    }
489
539
490
    if ($other_branch) {
540
    if ($other_branch) {
491
        $sql .= q{ AND branchcode = ? };
541
        $sql .= q{ AND branchcode = ? };
(-)a/C4/Context.pm (-1 / +2 lines)
Lines 1100-1106 set_userenv is called in Auth.pm Link Here
1100
#'
1100
#'
1101
sub set_userenv {
1101
sub set_userenv {
1102
    shift @_;
1102
    shift @_;
1103
    my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter, $persona, $shibboleth)=
1103
    my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter, $persona, $shibboleth, $type)=
1104
    map { Encode::is_utf8( $_ ) ? $_ : Encode::decode('UTF-8', $_) } # CGI::Session doesn't handle utf-8, so we decode it here
1104
    map { Encode::is_utf8( $_ ) ? $_ : Encode::decode('UTF-8', $_) } # CGI::Session doesn't handle utf-8, so we decode it here
1105
    @_;
1105
    @_;
1106
    my $var=$context->{"activeuser"} || '';
1106
    my $var=$context->{"activeuser"} || '';
Lines 1118-1123 sub set_userenv { Link Here
1118
        "branchprinter"    => $branchprinter,
1118
        "branchprinter"    => $branchprinter,
1119
        "persona"    => $persona,
1119
        "persona"    => $persona,
1120
        "shibboleth" => $shibboleth,
1120
        "shibboleth" => $shibboleth,
1121
        "type"       => $type,
1121
    };
1122
    };
1122
    $context->{userenv}->{$var} = $cell;
1123
    $context->{userenv}->{$var} = $cell;
1123
    return $cell;
1124
    return $cell;
(-)a/C4/Items.pm (-1 / +9 lines)
Lines 1281-1286 If this is set, it is set to C<One Order>. Link Here
1281
1281
1282
sub GetItemsInfo {
1282
sub GetItemsInfo {
1283
    my ( $biblionumber ) = @_;
1283
    my ( $biblionumber ) = @_;
1284
1285
    my $IndependentBranchesRecordsAndItems =
1286
      C4::Context->preference('IndependentBranchesRecordsAndItems')
1287
      && !C4::Context->IsSuperLibrarian();
1288
1284
    my $dbh   = C4::Context->dbh;
1289
    my $dbh   = C4::Context->dbh;
1285
    # note biblioitems.* must be avoided to prevent large marc and marcxml fields from killing performance.
1290
    # note biblioitems.* must be avoided to prevent large marc and marcxml fields from killing performance.
1286
    my $query = "
1291
    my $query = "
Lines 1326-1332 sub GetItemsInfo { Link Here
1326
     LEFT JOIN serial USING (serialid)
1331
     LEFT JOIN serial USING (serialid)
1327
     LEFT JOIN itemtypes   ON   itemtypes.itemtype         = "
1332
     LEFT JOIN itemtypes   ON   itemtypes.itemtype         = "
1328
     . (C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype');
1333
     . (C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype');
1329
    $query .= " WHERE items.biblionumber = ? ORDER BY home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ;
1334
    $query .= " WHERE items.biblionumber = ? ";
1335
    $query .= " AND items.homebranch IN ( " . GetIndependentGroupModificationRights({ stringify => 1}) . " ) " if ( $IndependentBranchesRecordsAndItems );
1336
    $query .= " ORDER BY home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ;
1337
1330
    my $sth = $dbh->prepare($query);
1338
    my $sth = $dbh->prepare($query);
1331
    $sth->execute($biblionumber);
1339
    $sth->execute($biblionumber);
1332
    my $i = 0;
1340
    my $i = 0;
(-)a/C4/Search.pm (+71 lines)
Lines 36-41 use URI::Escape; Link Here
36
use Business::ISBN;
36
use Business::ISBN;
37
use MARC::Record;
37
use MARC::Record;
38
use MARC::Field;
38
use MARC::Field;
39
use List::MoreUtils qw(none);
39
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG);
40
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG);
40
41
41
# set the version for version checking
42
# set the version for version checking
Lines 303-308 sub SimpleSearch { Link Here
303
        $zoom_query->destroy();
304
        $zoom_query->destroy();
304
    }
305
    }
305
306
307
    if ( C4::Context->preference('IndependentBranchesRecordsAndItems') ) {
308
        my @new_results;
309
        my $dbh = C4::Context->dbh();
310
        foreach my $result ( @{$results} ) {
311
            my $marc_record = MARC::Record->new_from_usmarc($result);
312
            my $koha_record = TransformMarcToKoha( $dbh, $marc_record );
313
            my $is_allowed = $koha_record->{branchcode} ? GetIndependentGroupModificationRights( { for => $koha_record->{branchcode} } ) : 1;
314
315
            push( @new_results, $result ) if ( $is_allowed );
316
        }
317
        $results = \@new_results;
318
        $total_hits = scalar( @new_results );
319
    }
320
306
    return ( undef, $results, $total_hits );
321
    return ( undef, $results, $total_hits );
307
}
322
}
308
323
Lines 1741-1746 sub buildQuery { Link Here
1741
        $limit .= "($availability_limit)";
1756
        $limit .= "($availability_limit)";
1742
    }
1757
    }
1743
1758
1759
    if ( C4::Context->preference('IndependentBranchesRecordsAndItems') ) {
1760
        my $search_context = C4::Context->userenv->{type};
1761
        my $IndependentBranchesRecordsAndItems;
1762
        if ( $search_context eq 'opac' ) {
1763
            # For the OPAC, if IndependentBranchesRecordsAndItems is enabled,
1764
            # and BRANCHCODE has been set in the httpd conf,
1765
            # we need to filter the items
1766
            $IndependentBranchesRecordsAndItems = $ENV{BRANCHCODE};
1767
        }
1768
        else {
1769
            # For the intranet, if IndependentBranchesRecordsAndItems is enabled,
1770
            # and the user is not a superlibrarian,
1771
            # we need to filter the items
1772
            $IndependentBranchesRecordsAndItems = !C4::Context->IsSuperLibrarian();
1773
        }
1774
        my @allowed_branches = $IndependentBranchesRecordsAndItems ? GetIndependentGroupModificationRights() : ();
1775
1776
        if ( @allowed_branches ) {
1777
            $limit .= " and " if ( $query || $limit );
1778
            $limit .= "(" . join( " or ", map { "branch:$_" } @allowed_branches ) . ")";
1779
        }
1780
    }
1781
1744
    # Normalize the query and limit strings
1782
    # Normalize the query and limit strings
1745
    # This is flawed , means we can't search anything with : in it
1783
    # This is flawed , means we can't search anything with : in it
1746
    # if user wants to do ccl or cql, start the query with that
1784
    # if user wants to do ccl or cql, start the query with that
Lines 2052-2065 sub searchResults { Link Here
2052
        my $maxitems = $maxitems_pref ? $maxitems_pref - 1 : 1;
2090
        my $maxitems = $maxitems_pref ? $maxitems_pref - 1 : 1;
2053
        my @hiddenitems; # hidden itemnumbers based on OpacHiddenItems syspref
2091
        my @hiddenitems; # hidden itemnumbers based on OpacHiddenItems syspref
2054
2092
2093
        my $IndependentBranchesRecordsAndItems;
2094
        if ( $search_context eq 'opac' ) {
2095
            # For the OPAC, if IndependentBranchesRecordsAndItems is enabled,
2096
            # and BRANCHCODE has been set in the httpd conf,
2097
            # we need to filter the items
2098
            $IndependentBranchesRecordsAndItems =
2099
              C4::Context->preference('IndependentBranchesRecordsAndItems')
2100
              && $ENV{BRANCHCODE};
2101
        }
2102
        else {
2103
            # For the intranet, if IndependentBranchesRecordsAndItems is enabled,
2104
            # and the user is not a superlibrarian,
2105
            # we need to filter the items
2106
            $IndependentBranchesRecordsAndItems =
2107
              C4::Context->preference('IndependentBranchesRecordsAndItems')
2108
              && !C4::Context->IsSuperLibrarian();
2109
        }
2110
        my @allowed_branches = $IndependentBranchesRecordsAndItems ? GetIndependentGroupModificationRights() : undef;
2111
2055
        # loop through every item
2112
        # loop through every item
2113
        my $index = -1;
2056
        foreach my $field (@fields) {
2114
        foreach my $field (@fields) {
2115
            $index++;
2057
            my $item;
2116
            my $item;
2058
2117
2059
            # populate the items hash
2118
            # populate the items hash
2060
            foreach my $code ( keys %subfieldstosearch ) {
2119
            foreach my $code ( keys %subfieldstosearch ) {
2061
                $item->{$code} = $field->subfield( $subfieldstosearch{$code} );
2120
                $item->{$code} = $field->subfield( $subfieldstosearch{$code} );
2062
            }
2121
            }
2122
2123
            # if IndependentBranchesRecordsAndItems is enabled, and this record
2124
            # isn't allowed to be viewed, remove it from the items list and go
2125
            # right to the next item.
2126
            if ( $IndependentBranchesRecordsAndItems ) {
2127
                if ( none { $_ eq $item->{homebranch} } @allowed_branches ) {
2128
                    splice(@fields, $index, 1);
2129
                    $items_count--;
2130
                    next;
2131
                }
2132
            }
2133
2063
            $item->{description} = $itemtypes{ $item->{itype} }{description};
2134
            $item->{description} = $itemtypes{ $item->{itype} }{description};
2064
2135
2065
	        # OPAC hidden items
2136
	        # OPAC hidden items
(-)a/C4/Serials.pm (+4 lines)
Lines 765-770 sub SearchSubscriptions { Link Here
765
        push @where_strs, "subscription.closed = ?";
765
        push @where_strs, "subscription.closed = ?";
766
        push @where_args, "$args->{closed}";
766
        push @where_args, "$args->{closed}";
767
    }
767
    }
768
    if( C4::Context->preference('IndependentBranchesRecordsAndItems') && !C4::Context->IsSuperlibrarian() ) {
769
        my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
770
        push @where_strs, "subscription.branchcode IN ( $branches )";
771
    }
768
    if(@where_strs){
772
    if(@where_strs){
769
        $query .= " WHERE " . join(" AND ", @where_strs);
773
        $query .= " WHERE " . join(" AND ", @where_strs);
770
    }
774
    }
(-)a/catalogue/search.pl (-14 / +6 lines)
Lines 135-140 Not yet completed... Link Here
135
use strict;            # always use
135
use strict;            # always use
136
#use warnings; FIXME - Bug 2505
136
#use warnings; FIXME - Bug 2505
137
137
138
use List::MoreUtils qw(any);
139
138
## STEP 1. Load things that are used in both search page and
140
## STEP 1. Load things that are used in both search page and
139
# results page and decide which template to load, operations 
141
# results page and decide which template to load, operations 
140
# to perform, etc.
142
# to perform, etc.
Lines 233-252 my $branches = GetBranches(); Link Here
233
# Populate branch_loop with all branches sorted by their name.  If
235
# Populate branch_loop with all branches sorted by their name.  If
234
# IndependentBranches is activated, set the default branch to the borrower
236
# IndependentBranches is activated, set the default branch to the borrower
235
# branch, except for superlibrarian who need to search all libraries.
237
# branch, except for superlibrarian who need to search all libraries.
236
my $user = C4::Context->userenv;
238
$template->param(
237
my @branch_loop = map {
239
    branchloop       => GetBranchesLoop(),
238
     {
240
    searchdomainloop => GetBranchCategories( undef, 'searchdomain' ),
239
        value      => $_,
241
);
240
        branchname => $branches->{$_}->{branchname},
241
        selected   => $user->{branch} eq $_ && C4::Branch::onlymine(),
242
     }
243
} sort {
244
    $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname}
245
} keys %$branches;
246
247
my $categories = GetBranchCategories('searchdomain');
248
249
$template->param(branchloop => \@branch_loop, searchdomainloop => $categories);
250
242
251
# load the Type stuff
243
# load the Type stuff
252
my $itemtypes = GetItemTypes;
244
my $itemtypes = GetItemTypes;
(-)a/cataloguing/addbooks.pl (-1 / +2 lines)
Lines 95-105 if ($query) { Link Here
95
    # SimpleSearch() give the results per page we want, so 0 offet here
95
    # SimpleSearch() give the results per page we want, so 0 offet here
96
    my $total = @{$marcresults};
96
    my $total = @{$marcresults};
97
    my @newresults = searchResults( 'intranet', $query, $total, $results_per_page, 0, 0, $marcresults );
97
    my @newresults = searchResults( 'intranet', $query, $total, $results_per_page, 0, 0, $marcresults );
98
    my $q = $input->param('q');
98
    $template->param(
99
    $template->param(
99
        total          => $total_hits,
100
        total          => $total_hits,
100
        query          => $query,
101
        query          => $query,
101
        resultsloop    => \@newresults,
102
        resultsloop    => \@newresults,
102
        pagination_bar => pagination_bar( "/cgi-bin/koha/cataloguing/addbooks.pl?q=$query&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
103
        pagination_bar => pagination_bar( "/cgi-bin/koha/cataloguing/addbooks.pl?q=$q&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
103
    );
104
    );
104
}
105
}
105
106
(-)a/cataloguing/additem.pl (-21 / +22 lines)
Lines 708-713 if ( C4::Context->preference('EasyAnalyticalRecords') ) { Link Here
708
    }
708
    }
709
}
709
}
710
710
711
my $IndependentBranches = !C4::Context->IsSuperLibrarian()
712
  && C4::Context->preference('IndependentBranches');
713
my $IndependentBranchesRecordsAndItems = $IndependentBranches
714
  && C4::Context->preference('IndependentBranchesRecordsAndItems');
711
715
712
foreach my $field (@fields) {
716
foreach my $field (@fields) {
713
    next if ( $field->tag() < 10 );
717
    next if ( $field->tag() < 10 );
Lines 731-745 foreach my $field (@fields) { Link Here
731
						|| $subfieldvalue;
735
						|| $subfieldvalue;
732
        }
736
        }
733
737
734
        if (   $field->tag eq $branchtagfield
738
        if (   $IndependentBranches
735
            && $subfieldcode eq $branchtagsubfield
739
            && $field->tag   eq $branchtagfield
736
            && C4::Context->preference("IndependentBranches") )
740
            && $subfieldcode eq $branchtagsubfield )
737
        {
741
        {
738
            #verifying rights
742
            #verifying rights
739
            my $userenv = C4::Context->userenv();
740
            unless (
743
            unless (
741
                C4::Context->IsSuperLibrarian()
744
                GetIndependentGroupModificationRights(
742
                || GetIndependentGroupModificationRights(
743
                    { for => $subfieldvalue }
745
                    { for => $subfieldvalue }
744
                )
746
                )
745
              )
747
              )
Lines 747-770 foreach my $field (@fields) { Link Here
747
                $this_row{'nomod'} = 1;
749
                $this_row{'nomod'} = 1;
748
            }
750
            }
749
        }
751
        }
750
        $this_row{itemnumber} = $subfieldvalue if ($field->tag() eq $itemtagfield && $subfieldcode eq $itemtagsubfield);
751
752
752
	if ( C4::Context->preference('EasyAnalyticalRecords') ) {
753
        $this_row{itemnumber} = $subfieldvalue if ($field->tag() eq $itemtagfield && $subfieldcode eq $itemtagsubfield);
753
	    foreach my $hostitemnumber (@hostitemnumbers){
754
		if ($this_row{itemnumber} eq $hostitemnumber){
755
			$this_row{hostitemflag} = 1;
756
			$this_row{hostbiblionumber}= GetBiblionumberFromItemnumber($hostitemnumber);
757
			last;
758
		}
759
	    }
760
754
761
#	    my $countanalytics=GetAnalyticsCount($this_row{itemnumber});
755
        if ( C4::Context->preference('EasyAnalyticalRecords') ) {
762
#           if ($countanalytics > 0){
756
            foreach my $hostitemnumber (@hostitemnumbers) {
763
#                $this_row{countanalytics} = $countanalytics;
757
                if ( $this_row{itemnumber} eq $hostitemnumber ) {
764
#           }
758
                    $this_row{hostitemflag} = 1;
765
	}
759
                    $this_row{hostbiblionumber} =
760
                      GetBiblionumberFromItemnumber($hostitemnumber);
761
                    last;
762
                }
763
            }
764
        }
766
765
767
    }
766
    }
767
768
    next if ( $this_row{'nomod'} && $IndependentBranchesRecordsAndItems );
769
768
    if (%this_row) {
770
    if (%this_row) {
769
        push(@big_array, \%this_row);
771
        push(@big_array, \%this_row);
770
    }
772
    }
771
- 

Return to bug 10278