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

(-)a/C4/Auth.pm (-1 / +1 lines)
Lines 648-654 sub checkauth { Link Here
648
                $session->param('surname'),      $session->param('branch'),
648
                $session->param('surname'),      $session->param('branch'),
649
                $session->param('branchname'),   $session->param('flags'),
649
                $session->param('branchname'),   $session->param('flags'),
650
                $session->param('emailaddress'), $session->param('branchprinter'),
650
                $session->param('emailaddress'), $session->param('branchprinter'),
651
                $session->param('persona')
651
                $session->param('persona'),      $type
652
            );
652
            );
653
            C4::Context::set_shelves_userenv('bar',$session->param('barshelves'));
653
            C4::Context::set_shelves_userenv('bar',$session->param('barshelves'));
654
            C4::Context::set_shelves_userenv('pub',$session->param('pubshelves'));
654
            C4::Context::set_shelves_userenv('pub',$session->param('pubshelves'));
(-)a/C4/Branch.pm (-17 / +66 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 109-114 Create a branch selector with the following code. Link Here
109
110
110
sub GetBranches {
111
sub GetBranches {
111
    my ($onlymine)=@_;
112
    my ($onlymine)=@_;
113
    $onlymine ||= onlymine();
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;
114
    my $dbh = C4::Context->dbh;
116
    my $dbh = C4::Context->dbh;
Lines 431-436 sub GetBranchesInCategory { Link Here
431
	return( \@branches );
433
	return( \@branches );
432
}
434
}
433
435
436
=head2 GetCategoriesForBranch
437
438
    my @categories = GetCategoriesForBranch({
439
        branchcode   => $branchcode,
440
        categorytype => 'independent_group'
441
    });
442
443
    Called in a list context, returns an array of branch category codes
444
    that branch is part of.
445
446
    Called in a scalar context, returns an array ref.
447
448
=cut
449
450
sub GetCategoriesForBranch {
451
    my ( $params ) = @_;
452
    my $branchcode = $params->{branchcode};
453
    my $categorytype = $params->{categorytype} || '%';
454
455
    carp("Missing branchcode parameter!") unless ( $branchcode );
456
457
    my $sql = q{
458
        SELECT categorycode FROM branchrelations
459
        JOIN branchcategories USING ( categorycode )
460
        WHERE branchcode   = ?
461
          AND categorytype = ?
462
    };
463
464
    my $categories = C4::Context->dbh->selectcol_arrayref( $sql, {}, ( $branchcode, $categorytype ) );
465
466
    return wantarray() ? $categories : @$categories;
467
}
468
434
=head2 GetIndependentGroupModificationRights
469
=head2 GetIndependentGroupModificationRights
435
470
436
    GetIndependentGroupModificationRights(
471
    GetIndependentGroupModificationRights(
Lines 460-466 sub GetBranchesInCategory { Link Here
460
    is useful for "branchcode IN $branchcodes" clauses
495
    is useful for "branchcode IN $branchcodes" clauses
461
    in SQL queries.
496
    in SQL queries.
462
497
463
    $this_branch and $other_branch are equal for efficiency.
498
    Returns 1 if $this_branch and $other_branch are equal for efficiency.
464
499
465
    So you can write:
500
    So you can write:
466
    my @branches = GetIndependentGroupModificationRights();
501
    my @branches = GetIndependentGroupModificationRights();
Lines 472-501 sub GetBranchesInCategory { Link Here
472
sub GetIndependentGroupModificationRights {
507
sub GetIndependentGroupModificationRights {
473
    my ($params) = @_;
508
    my ($params) = @_;
474
509
475
    my $this_branch  = $params->{branch};
510
    my $this_branch  = $params->{branch}    ||= q{};
476
    my $other_branch = $params->{for};
511
    my $other_branch = $params->{for}       ||= q{};
477
    my $stringify    = $params->{stringify};
512
    my $stringify    = $params->{stringify} ||= q{};
478
513
514
    $this_branch ||= $ENV{BRANCHCODE};
479
    $this_branch ||= C4::Context->userenv->{branch};
515
    $this_branch ||= C4::Context->userenv->{branch};
480
516
481
    carp("No branch found!") unless ($this_branch);
517
    unless ($this_branch) {
518
        carp("No branch found!");
519
        return;
520
    }
482
521
483
    return 1 if ( $this_branch eq $other_branch );
522
    return 1 if ( $this_branch eq $other_branch );
484
523
485
    my $sql = q{
524
    my $allow_all = 0;
486
        SELECT DISTINCT(branchcode)
525
    $allow_all = 1 if C4::Context->IsSuperLibrarian();
487
        FROM branchrelations
526
    $allow_all = 1 if C4::Context->userenv->{type} eq 'opac' && !$ENV{BRANCHCODE};
488
        JOIN branchcategories USING ( categorycode )
489
        WHERE categorycode IN (
490
            SELECT categorycode
491
            FROM branchrelations
492
            WHERE branchcode = ?
493
        )
494
        AND branchcategories.categorytype = 'independent_group'
495
    };
496
527
528
    my $sql;
497
    my @params;
529
    my @params;
498
    push( @params, $this_branch );
530
    if ( $allow_all ) {
531
        $sql = q{
532
            SELECT branchcode FROM branches WHERE 1
533
        }
534
    } else {
535
        $sql = q{
536
            SELECT DISTINCT(branchcode)
537
            FROM branchrelations
538
            JOIN branchcategories USING ( categorycode )
539
            WHERE categorycode IN (
540
                SELECT categorycode
541
                FROM branchrelations
542
                WHERE branchcode = ?
543
            )
544
            AND branchcategories.categorytype = 'independent_group'
545
        };
546
        push( @params, $this_branch );
547
    }
499
548
500
    if ($other_branch) {
549
    if ($other_branch) {
501
        $sql .= q{ AND branchcode = ? };
550
        $sql .= q{ AND branchcode = ? };
(-)a/C4/Context.pm (-14 / +22 lines)
Lines 1105-1127 set_userenv is called in Auth.pm Link Here
1105
1105
1106
#'
1106
#'
1107
sub set_userenv {
1107
sub set_userenv {
1108
    my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter, $persona)= @_;
1108
    my (
1109
    my $var=$context->{"activeuser"} || '';
1109
        $usernum,      $userid,        $usercnum,   $userfirstname,
1110
        $usersurname,  $userbranch,    $branchname, $userflags,
1111
        $emailaddress, $branchprinter, $persona,    $type
1112
    ) = @_;
1113
1114
    my $var = $context->{"activeuser"} || '';
1115
1110
    my $cell = {
1116
    my $cell = {
1111
        "number"     => $usernum,
1117
        "number"        => $usernum,
1112
        "id"         => $userid,
1118
        "id"            => $userid,
1113
        "cardnumber" => $usercnum,
1119
        "cardnumber"    => $usercnum,
1114
        "firstname"  => $userfirstname,
1120
        "firstname"     => $userfirstname,
1115
        "surname"    => $usersurname,
1121
        "surname"       => $usersurname,
1116
        #possibly a law problem
1122
        "branch"        => $userbranch,
1117
        "branch"     => $userbranch,
1123
        "branchname"    => $branchname,
1118
        "branchname" => $branchname,
1124
        "flags"         => $userflags,
1119
        "flags"      => $userflags,
1125
        "emailaddress"  => $emailaddress,
1120
        "emailaddress"     => $emailaddress,
1126
        "branchprinter" => $branchprinter,
1121
        "branchprinter"    => $branchprinter,
1127
        "persona"       => $persona,
1122
        "persona"    => $persona,
1128
        "type"          => $type,
1123
    };
1129
    };
1130
1124
    $context->{userenv}->{$var} = $cell;
1131
    $context->{userenv}->{$var} = $cell;
1132
1125
    return $cell;
1133
    return $cell;
1126
}
1134
}
1127
1135
(-)a/C4/Items.pm (-1 / +9 lines)
Lines 1206-1211 If this is set, it is set to C<One Order>. Link Here
1206
1206
1207
sub GetItemsInfo {
1207
sub GetItemsInfo {
1208
    my ( $biblionumber ) = @_;
1208
    my ( $biblionumber ) = @_;
1209
1210
    my $IndependentBranchesRecordsAndItems =
1211
      C4::Context->preference('IndependentBranchesRecordsAndItems')
1212
      && !C4::Context->IsSuperLibrarian();
1213
1209
    my $dbh   = C4::Context->dbh;
1214
    my $dbh   = C4::Context->dbh;
1210
    # note biblioitems.* must be avoided to prevent large marc and marcxml fields from killing performance.
1215
    # note biblioitems.* must be avoided to prevent large marc and marcxml fields from killing performance.
1211
    my $query = "
1216
    my $query = "
Lines 1235-1241 sub GetItemsInfo { Link Here
1235
     LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
1240
     LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
1236
     LEFT JOIN itemtypes   ON   itemtypes.itemtype         = "
1241
     LEFT JOIN itemtypes   ON   itemtypes.itemtype         = "
1237
     . (C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype');
1242
     . (C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype');
1238
    $query .= " WHERE items.biblionumber = ? ORDER BY home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ;
1243
    $query .= " WHERE items.biblionumber = ? ";
1244
    $query .= " AND items.homebranch IN ( " . GetIndependentGroupModificationRights({ stringify => 1}) . " ) " if ( $IndependentBranchesRecordsAndItems );
1245
    $query .= " ORDER BY home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ;
1246
1239
    my $sth = $dbh->prepare($query);
1247
    my $sth = $dbh->prepare($query);
1240
    $sth->execute($biblionumber);
1248
    $sth->execute($biblionumber);
1241
    my $i = 0;
1249
    my $i = 0;
(-)a/C4/Koha.pm (-37 / +37 lines)
Lines 36-78 BEGIN { Link Here
36
    $VERSION = 3.07.00.049;
36
    $VERSION = 3.07.00.049;
37
	require Exporter;
37
	require Exporter;
38
	@ISA    = qw(Exporter);
38
	@ISA    = qw(Exporter);
39
	@EXPORT = qw(
39
    @EXPORT = qw(
40
		&slashifyDate
40
      &slashifyDate
41
		&subfield_is_koha_internal_p
41
      &subfield_is_koha_internal_p
42
		&GetPrinters &GetPrinter
42
      &GetPrinters &GetPrinter
43
		&GetItemTypes &getitemtypeinfo
43
      &GetItemTypes &getitemtypeinfo
44
		&GetCcodes
44
      &GetCcodes
45
		&GetSupportName &GetSupportList
45
      &GetSupportName &GetSupportList
46
		&get_itemtypeinfos_of
46
      &get_itemtypeinfos_of
47
		&getframeworks &getframeworkinfo
47
      &getframeworks &getframeworkinfo
48
		&getauthtypes &getauthtype
48
      &getauthtypes &getauthtype
49
		&getallthemes
49
      &getallthemes
50
		&getFacets
50
      &getFacets
51
		&displayServers
51
      &displayServers
52
		&getnbpages
52
      &getnbpages
53
		&get_infos_of
53
      &get_infos_of
54
		&get_notforloan_label_of
54
      &get_notforloan_label_of
55
		&getitemtypeimagedir
55
      &getitemtypeimagedir
56
		&getitemtypeimagesrc
56
      &getitemtypeimagesrc
57
		&getitemtypeimagelocation
57
      &getitemtypeimagelocation
58
		&GetAuthorisedValues
58
      &GetAuthorisedValues
59
		&GetAuthorisedValueCategories
59
      &GetAuthorisedValueCategories
60
                &IsAuthorisedValueCategory
60
      &IsAuthorisedValueCategory
61
		&GetKohaAuthorisedValues
61
      &GetKohaAuthorisedValues
62
		&GetKohaAuthorisedValuesFromField
62
      &GetKohaAuthorisedValuesFromField
63
    &GetKohaAuthorisedValueLib
63
      &GetKohaAuthorisedValueLib
64
    &GetAuthorisedValueByCode
64
      &GetAuthorisedValueByCode
65
    &GetKohaImageurlFromAuthorisedValues
65
      &GetKohaImageurlFromAuthorisedValues
66
		&GetAuthValCode
66
      &GetAuthValCode
67
        &AddAuthorisedValue
67
      &AddAuthorisedValue
68
		&GetNormalizedUPC
68
      &GetNormalizedUPC
69
		&GetNormalizedISBN
69
      &GetNormalizedISBN
70
		&GetNormalizedEAN
70
      &GetNormalizedEAN
71
		&GetNormalizedOCLCNumber
71
      &GetNormalizedOCLCNumber
72
        &xml_escape
72
      &xml_escape
73
73
74
		$DEBUG
74
      $DEBUG
75
	);
75
    );
76
	$DEBUG = 0;
76
	$DEBUG = 0;
77
@EXPORT_OK = qw( GetDailyQuote );
77
@EXPORT_OK = qw( GetDailyQuote );
78
}
78
}
(-)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 utf8;
40
use utf8;
40
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG);
41
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG);
41
42
Lines 301-306 sub SimpleSearch { Link Here
301
        $zoom_query->destroy();
302
        $zoom_query->destroy();
302
    }
303
    }
303
304
305
    if ( C4::Context->preference('IndependentBranchesRecordsAndItems') ) {
306
        my @new_results;
307
        my $dbh = C4::Context->dbh();
308
        foreach my $result ( @{$results} ) {
309
            my $marc_record = MARC::Record->new_from_usmarc($result);
310
            my $koha_record = TransformMarcToKoha( $dbh, $marc_record );           
311
            my $is_allowed = $koha_record->{branchcode} ? GetIndependentGroupModificationRights( { for => $koha_record->{branchcode} } ) : 1;
312
313
            push( @new_results, $result ) if ( $is_allowed );
314
        }
315
        $results = \@new_results;
316
        $total_hits = scalar( @new_results );
317
    }
318
304
    return ( undef, $results, $total_hits );
319
    return ( undef, $results, $total_hits );
305
}
320
}
306
321
Lines 1574-1579 sub buildQuery { Link Here
1574
        $limit .= "($availability_limit)";
1589
        $limit .= "($availability_limit)";
1575
    }
1590
    }
1576
1591
1592
    if ( C4::Context->preference('IndependentBranchesRecordsAndItems') ) {
1593
        my $search_context = C4::Context->userenv->{type};
1594
        my $IndependentBranchesRecordsAndItems;
1595
        if ( $search_context eq 'opac' ) {
1596
            # For the OPAC, if IndependentBranchesRecordsAndItems is enabled,
1597
            # and BRANCHCODE has been set in the httpd conf,
1598
            # we need to filter the items
1599
            $IndependentBranchesRecordsAndItems = $ENV{BRANCHCODE};
1600
        }
1601
        else {
1602
            # For the intranet, if IndependentBranchesRecordsAndItems is enabled,
1603
            # and the user is not a superlibrarian,
1604
            # we need to filter the items
1605
            $IndependentBranchesRecordsAndItems = !C4::Context->IsSuperLibrarian();
1606
        }
1607
        my @allowed_branches = $IndependentBranchesRecordsAndItems ? GetIndependentGroupModificationRights() : ();
1608
	
1609
        if ( @allowed_branches ) {
1610
            $limit .= " and " if ( $query || $limit );
1611
            $limit .= "(" . join( " or ", map { "branch:$_" } @allowed_branches ) . ")";
1612
        }
1613
    }
1614
1577
    # Normalize the query and limit strings
1615
    # Normalize the query and limit strings
1578
    # This is flawed , means we can't search anything with : in it
1616
    # This is flawed , means we can't search anything with : in it
1579
    # if user wants to do ccl or cql, start the query with that
1617
    # if user wants to do ccl or cql, start the query with that
Lines 1828-1841 sub searchResults { Link Here
1828
        my $maxitems = $maxitems_pref ? $maxitems_pref - 1 : 1;
1866
        my $maxitems = $maxitems_pref ? $maxitems_pref - 1 : 1;
1829
        my @hiddenitems; # hidden itemnumbers based on OpacHiddenItems syspref
1867
        my @hiddenitems; # hidden itemnumbers based on OpacHiddenItems syspref
1830
1868
1869
        my $IndependentBranchesRecordsAndItems;
1870
        if ( $search_context eq 'opac' ) {
1871
            # For the OPAC, if IndependentBranchesRecordsAndItems is enabled,
1872
            # and BRANCHCODE has been set in the httpd conf,
1873
            # we need to filter the items
1874
            $IndependentBranchesRecordsAndItems =
1875
              C4::Context->preference('IndependentBranchesRecordsAndItems')
1876
              && $ENV{BRANCHCODE};
1877
        }
1878
        else {
1879
            # For the intranet, if IndependentBranchesRecordsAndItems is enabled,
1880
            # and the user is not a superlibrarian,
1881
            # we need to filter the items
1882
            $IndependentBranchesRecordsAndItems =
1883
              C4::Context->preference('IndependentBranchesRecordsAndItems')
1884
              && !C4::Context->IsSuperLibrarian();
1885
        }
1886
        my @allowed_branches = $IndependentBranchesRecordsAndItems ? GetIndependentGroupModificationRights() : undef;
1887
1831
        # loop through every item
1888
        # loop through every item
1889
        my $index = -1;
1832
        foreach my $field (@fields) {
1890
        foreach my $field (@fields) {
1891
            $index++;
1833
            my $item;
1892
            my $item;
1834
1893
1835
            # populate the items hash
1894
            # populate the items hash
1836
            foreach my $code ( keys %subfieldstosearch ) {
1895
            foreach my $code ( keys %subfieldstosearch ) {
1837
                $item->{$code} = $field->subfield( $subfieldstosearch{$code} );
1896
                $item->{$code} = $field->subfield( $subfieldstosearch{$code} );
1838
            }
1897
            }
1898
1899
            # if IndependentBranchesRecordsAndItems is enabled, and this record
1900
            # isn't allowed to be viewed, remove it from the items list and go
1901
            # right to the next item.
1902
            if ( $IndependentBranchesRecordsAndItems ) {
1903
                if ( none { $_ eq $item->{homebranch} } @allowed_branches ) {
1904
                    splice(@fields, $index, 1);
1905
                    $items_count--;
1906
                    next;
1907
                }
1908
            }
1909
1839
            $item->{description} = $itemtypes{ $item->{itype} }{description};
1910
            $item->{description} = $itemtypes{ $item->{itype} }{description};
1840
1911
1841
	        # OPAC hidden items
1912
	        # OPAC hidden items
(-)a/C4/Serials.pm (+4 lines)
Lines 738-743 sub SearchSubscriptions { Link Here
738
        push @where_strs, "subscription.closed = ?";
738
        push @where_strs, "subscription.closed = ?";
739
        push @where_args, "$args->{closed}";
739
        push @where_args, "$args->{closed}";
740
    }
740
    }
741
    if( C4::Context->preference('IndependentBranchesRecordsAndItems') && !C4::Context->IsSuperlibrarian() ) {
742
        my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
743
        push @where_strs, "subscription.branchcode IN ( $branches )";
744
    }
741
    if(@where_strs){
745
    if(@where_strs){
742
        $query .= " WHERE " . join(" AND ", @where_strs);
746
        $query .= " WHERE " . join(" AND ", @where_strs);
743
    }
747
    }
(-)a/catalogue/search.pl (-17 / +12 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 152-157 use URI::Escape; Link Here
152
use POSIX qw(ceil floor);
154
use POSIX qw(ceil floor);
153
use String::Random;
155
use String::Random;
154
use C4::Branch; # GetBranches
156
use C4::Branch; # GetBranches
157
use URI::Escape;
155
158
156
my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
159
my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
157
# create a new CGI object
160
# create a new CGI object
Lines 181-189 else { Link Here
181
    flagsrequired   => { catalogue => 1 },
184
    flagsrequired   => { catalogue => 1 },
182
    }
185
    }
183
);
186
);
187
184
if (C4::Context->preference("marcflavour") eq "UNIMARC" ) {
188
if (C4::Context->preference("marcflavour") eq "UNIMARC" ) {
185
    $template->param('UNIMARC' => 1);
189
    $template->param('UNIMARC' => 1);
186
}
190
}
191
187
if (C4::Context->preference("IntranetNumbersPreferPhrase")) {
192
if (C4::Context->preference("IntranetNumbersPreferPhrase")) {
188
    $template->param('numbersphr' => 1);
193
    $template->param('numbersphr' => 1);
189
}
194
}
Lines 228-247 my $branches = GetBranches(); Link Here
228
# Populate branch_loop with all branches sorted by their name.  If
233
# Populate branch_loop with all branches sorted by their name.  If
229
# IndependentBranches is activated, set the default branch to the borrower
234
# IndependentBranches is activated, set the default branch to the borrower
230
# branch, except for superlibrarian who need to search all libraries.
235
# branch, except for superlibrarian who need to search all libraries.
231
my $user = C4::Context->userenv;
236
$template->param(
232
my @branch_loop = map {
237
    branchloop       => GetBranchesLoop(),
233
     {
238
    searchdomainloop => GetBranchCategories( undef, 'searchdomain' ),
234
        value      => $_,
239
);
235
        branchname => $branches->{$_}->{branchname},
236
        selected   => $user->{branch} eq $_ && C4::Branch::onlymine(),
237
     }
238
} sort {
239
    $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname}
240
} keys %$branches;
241
242
my $categories = GetBranchCategories('searchdomain');
243
244
$template->param(branchloop => \@branch_loop, searchdomainloop => $categories);
245
240
246
# load the Type stuff
241
# load the Type stuff
247
my $itemtypes = GetItemTypes;
242
my $itemtypes = GetItemTypes;
Lines 407-418 if ($indexes[0] && (!$indexes[1] || $params->{'scan'})) { Link Here
407
}
402
}
408
403
409
# an operand can be a single term, a phrase, or a complete ccl query
404
# an operand can be a single term, a phrase, or a complete ccl query
410
my @operands = map uri_unescape($_), $cgi->param('q');
405
my @operands = map { uri_unescape( $_ ) } $cgi->param('q');
411
406
412
# limits are use to limit to results to a pre-defined category such as branch or language
407
# limits are use to limit to results to a pre-defined category such as branch or language
413
my @limits = map uri_unescape($_), $cgi->param('limit');
408
my @limits = map { uri_unescape($_) } $cgi->param('limit');
414
409
415
if($params->{'multibranchlimit'}) {
410
if( $params->{'multibranchlimit'} ) {
416
    my $multibranch = '('.join( " or ", map { "branch: $_ " } @{ GetBranchesInCategory( $params->{'multibranchlimit'} ) } ).')';
411
    my $multibranch = '('.join( " or ", map { "branch: $_ " } @{ GetBranchesInCategory( $params->{'multibranchlimit'} ) } ).')';
417
    push @limits, $multibranch if ($multibranch ne  '()');
412
    push @limits, $multibranch if ($multibranch ne  '()');
418
}
413
}
(-)a/cataloguing/addbooks.pl (-1 / +2 lines)
Lines 98-108 if ($query) { Link Here
98
    foreach my $line (@newresults) {
98
    foreach my $line (@newresults) {
99
        if ( not exists $line->{'size'} ) { $line->{'size'} = "" }
99
        if ( not exists $line->{'size'} ) { $line->{'size'} = "" }
100
    }
100
    }
101
    my $q = $input->param('q');
101
    $template->param(
102
    $template->param(
102
        total          => $total_hits,
103
        total          => $total_hits,
103
        query          => $query,
104
        query          => $query,
104
        resultsloop    => \@newresults,
105
        resultsloop    => \@newresults,
105
        pagination_bar => pagination_bar( "/cgi-bin/koha/cataloguing/addbooks.pl?q=$query&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
106
        pagination_bar => pagination_bar( "/cgi-bin/koha/cataloguing/addbooks.pl?q=$q&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
106
    );
107
    );
107
}
108
}
108
109
(-)a/cataloguing/additem.pl (-20 / +23 lines)
Lines 667-672 if ( C4::Context->preference('EasyAnalyticalRecords') ) { Link Here
667
    }
667
    }
668
}
668
}
669
669
670
my $IndependentBranches = !C4::Context->IsSuperLibrarian()
671
  && C4::Context->preference('IndependentBranches');
672
my $IndependentBranchesRecordsAndItems = $IndependentBranches
673
  && C4::Context->preference('IndependentBranchesRecordsAndItems');
670
674
671
foreach my $field (@fields) {
675
foreach my $field (@fields) {
672
    next if ( $field->tag() < 10 );
676
    next if ( $field->tag() < 10 );
Lines 690-704 foreach my $field (@fields) { Link Here
690
						|| $subfieldvalue;
694
						|| $subfieldvalue;
691
        }
695
        }
692
696
693
        if (   $field->tag eq $branchtagfield
697
        if (   $IndependentBranches
694
            && $subfieldcode eq $branchtagsubfield
698
            && $field->tag   eq $branchtagfield
695
            && C4::Context->preference("IndependentBranches") )
699
            && $subfieldcode eq $branchtagsubfield )
696
        {
700
        {
701
697
            #verifying rights
702
            #verifying rights
698
            my $userenv = C4::Context->userenv();
699
            unless (
703
            unless (
700
                $userenv->{'flags'} % 2 == 1
704
                GetIndependentGroupModificationRights(
701
                || GetIndependentGroupModificationRights(
702
                    { for => $subfieldvalue }
705
                    { for => $subfieldvalue }
703
                )
706
                )
704
              )
707
              )
Lines 706-729 foreach my $field (@fields) { Link Here
706
                $this_row{'nomod'} = 1;
709
                $this_row{'nomod'} = 1;
707
            }
710
            }
708
        }
711
        }
709
        $this_row{itemnumber} = $subfieldvalue if ($field->tag() eq $itemtagfield && $subfieldcode eq $itemtagsubfield);
710
712
711
	if ( C4::Context->preference('EasyAnalyticalRecords') ) {
713
        $this_row{itemnumber} = $subfieldvalue if ($field->tag() eq $itemtagfield && $subfieldcode eq $itemtagsubfield);
712
	    foreach my $hostitemnumber (@hostitemnumbers){
713
		if ($this_row{itemnumber} eq $hostitemnumber){
714
			$this_row{hostitemflag} = 1;
715
			$this_row{hostbiblionumber}= GetBiblionumberFromItemnumber($hostitemnumber);
716
			last;
717
		}
718
	    }
719
714
720
#	    my $countanalytics=GetAnalyticsCount($this_row{itemnumber});
715
        if ( C4::Context->preference('EasyAnalyticalRecords') ) {
721
#           if ($countanalytics > 0){
716
            foreach my $hostitemnumber (@hostitemnumbers) {
722
#                $this_row{countanalytics} = $countanalytics;
717
                if ( $this_row{itemnumber} eq $hostitemnumber ) {
723
#           }
718
                    $this_row{hostitemflag} = 1;
724
	}
719
                    $this_row{hostbiblionumber} =
720
                      GetBiblionumberFromItemnumber($hostitemnumber);
721
                    last;
722
                }
723
            }
724
        }
725
725
726
    }
726
    }
727
728
    next if ( $this_row{'nomod'} && $IndependentBranchesRecordsAndItems );
729
727
    if (%this_row) {
730
    if (%this_row) {
728
        push(@big_array, \%this_row);
731
        push(@big_array, \%this_row);
729
    }
732
    }
(-)a/installer/data/mysql/updatedatabase.pl (-12 / +33 lines)
Lines 6941-6958 if ( CheckVersion($DBversion) ) { Link Here
6941
    SetVersion ($DBversion);
6941
    SetVersion ($DBversion);
6942
}
6942
}
6943
6943
6944
$DBversion = "3.11.00.XXX";
6945
if ( CheckVersion($DBversion) ) {
6946
    $dbh->do(q{
6947
        ALTER TABLE branchcategories
6948
        CHANGE categorytype categorytype
6949
          ENUM( 'searchdomain', 'independent_group' )
6950
            NULL DEFAULT NULL
6951
    });
6952
    print "Upgrade to $DBversion done (Remove branch property groups, add independent groups)\n";
6953
    SetVersion ($DBversion);
6954
}
6955
6956
$DBversion = '3.13.00.003';
6944
$DBversion = '3.13.00.003';
6957
if ( CheckVersion($DBversion) ) {
6945
if ( CheckVersion($DBversion) ) {
6958
    $dbh->do("ALTER TABLE serial DROP itemnumber");
6946
    $dbh->do("ALTER TABLE serial DROP itemnumber");
Lines 7079-7084 if ( CheckVersion($DBversion) ) { Link Here
7079
    SetVersion($DBversion);
7067
    SetVersion($DBversion);
7080
}
7068
}
7081
7069
7070
$DBversion = "3.11.00.XXX";
7071
if ( CheckVersion($DBversion) ) {
7072
    $dbh->do(q{
7073
        ALTER TABLE branchcategories
7074
        CHANGE categorytype categorytype
7075
          ENUM( 'searchdomain', 'independent_group' )
7076
            NULL DEFAULT NULL
7077
    });
7078
    print "Upgrade to $DBversion done (Remove branch property groups, add independent groups)\n";
7079
    SetVersion ($DBversion);
7080
}
7081
7082
$DBversion = "3.13.00.XXX";
7083
if ( CheckVersion($DBversion) ) {
7084
    $dbh->do("
7085
        INSERT INTO systempreferences (
7086
            variable,
7087
            value,
7088
            options,
7089
            explanation,
7090
            type
7091
        ) VALUES (
7092
            'IndependentBranchesRecordsAndItems',
7093
            '0',
7094
            '',
7095
            'If on, the staff interface search will hide all records that do not contain an item owned by the logged in branch, and hide the items themselves.',
7096
            'YesNo'
7097
        )
7098
    ");
7099
    print "Upgrade to $DBversion done (Bug 10278 - Add ability to hide items and records from search results for Independent Branches)\n";
7100
    SetVersion ($DBversion);
7101
}
7102
7082
=head1 FUNCTIONS
7103
=head1 FUNCTIONS
7083
7104
7084
=head2 TableExists($table)
7105
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-search.inc (-28 / +36 lines)
Lines 1-33 Link Here
1
<div class="gradient">
1
<div class="gradient">
2
<h1 id="logo"><a href="/cgi-bin/koha/mainpage.pl">[% LibraryName %]</a></h1><!-- Begin Catalogue Resident Search Box -->
2
    <h1 id="logo"><a href="/cgi-bin/koha/mainpage.pl">[% LibraryName %]</a></h1><!-- Begin Catalogue Resident Search Box -->
3
<div id="header_search">
3
    <div id="header_search">
4
4
5
[% INCLUDE 'patron-search-box.inc' %]
5
        [% INCLUDE 'patron-search-box.inc' %]
6
6
7
[% IF ( CAN_user_circulate ) %]
7
        [% IF ( CAN_user_circulate ) %]
8
<div id="checkin_search" class="residentsearch">
8
            <div id="checkin_search" class="residentsearch">
9
    <p class="tip">Scan a barcode to check in:</p>
9
                <p class="tip">Scan a barcode to check in:</p>
10
    <form method="post" action="/cgi-bin/koha/circ/returns.pl" autocomplete="off">
10
                <form method="post" action="/cgi-bin/koha/circ/returns.pl" autocomplete="off">
11
        <input name="barcode" id="ret_barcode" size="40" />
11
                    <input name="barcode" id="ret_barcode" size="40" />
12
        <input value="Submit" class="submit" type="submit" />
12
                    <input value="Submit" class="submit" type="submit" />
13
    </form>
13
                </form>
14
</div>
14
            </div>
15
	[% END %]
15
        [% END %]
16
	[% IF ( CAN_user_catalogue ) %]
16
17
	<div id="catalog_search" class="residentsearch">
17
        [% IF ( CAN_user_catalogue ) %]
18
	<p class="tip">Enter search keywords:</p>
18
            <div id="catalog_search" class="residentsearch">
19
		<form action="/cgi-bin/koha/catalogue/search.pl"  method="get" id="cat-search-block">
19
            <p class="tip">Enter search keywords:</p>
20
			 <input type="text" name="q" id="search-form" size="40" value="" title="Enter the terms you wish to search for." class="form-text" />
20
                <form action="/cgi-bin/koha/catalogue/search.pl"  method="get" id="cat-search-block">
21
				<input type="submit" class="submit" value="Submit" />
21
                    <input type="text" name="q" id="search-form" size="40" value="" title="Enter the terms you wish to search for." class="form-text" />
22
		</form>
22
                    <input type="submit" class="submit" value="Submit" />
23
	</div>
23
                </form>
24
	[% END %]
24
            </div>
25
	
25
        [% END %]
26
			<ul>
26
27
            [% IF ( CAN_user_circulate ) %]<li><a href="#circ_search">Check out</a></li>[% END %]
27
28
    [% IF ( CAN_user_circulate ) %]<li><a href="#checkin_search">Check in</a></li>[% END %]
28
        <ul>
29
            [% IF ( CAN_user_catalogue ) %]<li class="ui-tabs-selected"><a href="#catalog_search">Search the catalog</a></li>[% END %]
29
            [% IF ( CAN_user_circulate ) %]
30
			</ul>	
30
                <li><a href="#circ_search">Check out</a></li>
31
</div><!-- /header_search -->
31
            [% END %]
32
            [% IF ( CAN_user_circulate ) %]
33
                <li><a href="#checkin_search">Check in</a></li>
34
            [% END %]
35
            [% IF ( CAN_user_catalogue ) %]
36
                <li class="ui-tabs-selected"><a href="#catalog_search">Search the catalog</a></li>
37
            [% END %]
38
        </ul>
39
    </div><!-- /header_search -->
32
</div><!-- /gradient -->
40
</div><!-- /gradient -->
33
<!-- End Catalogue Resident Search Box -->
41
<!-- End Catalogue Resident Search Box -->
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref (+7 lines)
Lines 70-75 Administration: Link Here
70
                  yes: Prevent
70
                  yes: Prevent
71
                  no: "Don't prevent"
71
                  no: "Don't prevent"
72
            - staff (but not superlibrarians) from modifying objects (holds, items, patrons, etc.) belonging to other libraries.
72
            - staff (but not superlibrarians) from modifying objects (holds, items, patrons, etc.) belonging to other libraries.
73
        -
74
            - pref: IndependentBranchesRecordsAndItems
75
              default: 0
76
              choices:
77
                  yes: Prevent
78
                  no: "Don't prevent"
79
            - staff from seeing items owned by other libraries, and records without any items the library.
73
    CAS Authentication:
80
    CAS Authentication:
74
        -
81
        -
75
            - pref: casAuthentication
82
            - pref: casAuthentication
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt (-26 / +33 lines)
Lines 1-3 Link Here
1
[% USE Koha %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Catalog &rsaquo; Advanced search</title>
3
<title>Koha &rsaquo; Catalog &rsaquo; Advanced search</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'doc-head-close.inc' %]
Lines 229-262 Link Here
229
[% END %]
230
[% END %]
230
231
231
<!-- AVAILABILITY LIMITS -->
232
<!-- AVAILABILITY LIMITS -->
232
    <fieldset id="availability"><legend>Location and availability</legend>
233
<fieldset id="availability"><legend>Location and availability</legend>
233
<fieldset id="currently-avail">
234
    <fieldset id="currently-avail">
234
        <p><label for="available-items">Only items currently available</label> <input type="checkbox" id="available-items" name="limit" value="available" /></p>
235
            <p><label for="available-items">Only items currently available</label> <input type="checkbox" id="available-items" name="limit" value="available" /></p>
235
</fieldset>
236
    </fieldset>
236
237
237
<fieldset id="select-libs">
238
    <fieldset id="select-libs">
238
        <p><label for="branchloop">Individual libraries:</label><select name="limit" id="branchloop" onchange='if(this.value != ""){document.getElementById("categoryloop").disabled=true;} else {document.getElementById("categoryloop").disabled=false;}'>
239
            <p>
239
        <option value="">All libraries</option>
240
                <label for="branchloop">Individual libraries:</label>
240
        [% FOREACH branchloo IN branchloop %]
241
                <select name="limit" id="branchloop" onchange='if(this.value != ""){document.getElementById("categoryloop").disabled=true;} else {document.getElementById("categoryloop").disabled=false;}'>
241
        [% IF ( branchloo.selected ) %]
242
                    <option value="">All libraries</option>
242
        <option value="branch:[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
243
                    [% FOREACH branchloo IN branchloop %]
243
        [% ELSE %]
244
                        [% IF ( branchloo.selected ) %]
244
        <option value="branch:[% branchloo.value %]">[% branchloo.branchname %]</option>
245
                            <option value="branch:[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
245
        [% END %]
246
                        [% ELSE %]
246
        [% END %]
247
                            <option value="branch:[% branchloo.value %]">[% branchloo.branchname %]</option>
247
        </select></p>
248
                        [% END %]
248
    <!-- <input type="hidden" name="limit" value="branch: MAIN" /> -->
249
                    [% END %]
249
        [% IF ( searchdomainloop ) %]
250
                </select>
250
    <p>OR</p> <!-- should addjs to grey out group pulldown if a library is selected. -->
251
            </p>
251
        <p><label for="categoryloop">Groups of libraries: </label><select name="multibranchlimit" id="categoryloop">
252
252
        <option value=""> -- none -- </option>
253
            [% IF searchdomainloop && !Koha.Preference('IndependentBranchesRecordsAndItems') %]
253
        [% FOREACH searchdomainloo IN searchdomainloop %]
254
                <p>OR</p> <!-- should addjs to grey out group pulldown if a library is selected. -->
254
        <option value="[% searchdomainloo.categorycode %]">[% searchdomainloo.categoryname %]</option>
255
                <p>
255
        [% END %]
256
                    <label for="categoryloop">Groups of libraries: </label>
256
        </select></p>
257
                    <select name="multibranchlimit" id="categoryloop">
257
    [% END %]
258
                        <option value=""> -- none -- </option>
258
</fieldset>
259
                        [% FOREACH searchdomainloo IN searchdomainloop %]
260
                            <option value="[% searchdomainloo.categorycode %]">[% searchdomainloo.categoryname %]</option>
261
                        [% END %]
262
                    </select>
263
                </p>
264
            [% END %]
259
    </fieldset>
265
    </fieldset>
266
</fieldset>
260
<!-- /AVAILABILITY LIMITS -->
267
<!-- /AVAILABILITY LIMITS -->
261
268
262
<!-- RANK LIMITS -->
269
<!-- RANK LIMITS -->
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt (+2 lines)
Lines 23-29 Link Here
23
    function GetZ3950Terms(){
23
    function GetZ3950Terms(){
24
        var strQuery="&frameworkcode=";
24
        var strQuery="&frameworkcode=";
25
        [% FOREACH z3950_search_param IN z3950_search_params %]
25
        [% FOREACH z3950_search_param IN z3950_search_params %]
26
/*
26
            strQuery += "&" + "[% z3950_search_param.name %]" + "=" + "[% z3950_search_param.encvalue %]";
27
            strQuery += "&" + "[% z3950_search_param.name %]" + "=" + "[% z3950_search_param.encvalue %]";
28
*/
27
        [% END %]
29
        [% END %]
28
        return strQuery;
30
        return strQuery;
29
    }
31
    }
(-)a/opac/opac-search.pl (-1 / +6 lines)
Lines 410-415 if($params->{'multibranchlimit'}) { Link Here
410
    push @limits, $multibranch if ($multibranch ne  '()');
410
    push @limits, $multibranch if ($multibranch ne  '()');
411
}
411
}
412
412
413
if ( C4::Context->preference('IndependentBranchesRecordsAndItems') ) {
414
    my @branches = GetIndependentGroupModificationRights();
415
    my $allowed = '(' . join( " or ", map { "branch: $_ " } @branches ) . ')';
416
    push( @limits, $allowed ) if ( $allowed ne '()' );
417
}
418
413
my $available;
419
my $available;
414
foreach my $limit(@limits) {
420
foreach my $limit(@limits) {
415
    if ($limit =~/available/) {
421
    if ($limit =~/available/) {
416
- 

Return to bug 10278