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

(-)a/C4/Acquisition.pm (-11 / +12 lines)
Lines 31-36 use C4::Debug; Link Here
31
use C4::SQLHelper qw(InsertInTable UpdateInTable);
31
use C4::SQLHelper qw(InsertInTable UpdateInTable);
32
use C4::Bookseller qw(GetBookSellerFromId);
32
use C4::Bookseller qw(GetBookSellerFromId);
33
use C4::Templates qw(gettemplate);
33
use C4::Templates qw(gettemplate);
34
use C4::Branch qw(GetIndependentGroupModificationRights);
34
35
35
use Time::localtime;
36
use Time::localtime;
36
use HTML::Entities;
37
use HTML::Entities;
Lines 1964-1972 sub GetParcel { Link Here
1964
    my @query_params = ( $supplierid, $code, $datereceived );
1965
    my @query_params = ( $supplierid, $code, $datereceived );
1965
    if ( C4::Context->preference("IndependentBranches") ) {
1966
    if ( C4::Context->preference("IndependentBranches") ) {
1966
        unless ( C4::Context->IsSuperLibrarian() ) {
1967
        unless ( C4::Context->IsSuperLibrarian() ) {
1967
            $strsth .= " and (borrowers.branchcode = ?
1968
            my $branches =
1968
                        or borrowers.branchcode  = '')";
1969
              GetIndependentGroupModificationRights( { stringify => 1 } );
1969
            push @query_params, C4::Context->userenv->{branch};
1970
            $strsth .= " AND ( borrowers.branchcode IN ( $branches ) OR borrowers.branchcode  = '')";
1970
        }
1971
        }
1971
    }
1972
    }
1972
    $strsth .= " ORDER BY aqbasket.basketno";
1973
    $strsth .= " ORDER BY aqbasket.basketno";
Lines 2181-2188 sub GetLateOrders { Link Here
2181
    }
2182
    }
2182
    if (C4::Context->preference("IndependentBranches")
2183
    if (C4::Context->preference("IndependentBranches")
2183
            && !C4::Context->IsSuperLibrarian() ) {
2184
            && !C4::Context->IsSuperLibrarian() ) {
2184
        $from .= ' AND borrowers.branchcode LIKE ? ';
2185
        my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
2185
        push @query_params, C4::Context->userenv->{branch};
2186
        $from .= qq{ AND borrowers.branchcode IN ( $branches ) };
2186
    }
2187
    }
2187
    $from .= " AND orderstatus <> 'cancelled' ";
2188
    $from .= " AND orderstatus <> 'cancelled' ";
2188
    my $query = "$select $from $having\nORDER BY latesince, basketno, borrowers.branchcode, supplier";
2189
    my $query = "$select $from $having\nORDER BY latesince, basketno, borrowers.branchcode, supplier";
Lines 2403-2414 sub GetHistory { Link Here
2403
        $query .= ") ";
2404
        $query .= ") ";
2404
    }
2405
    }
2405
2406
2406
2407
    if ( C4::Context->preference("IndependentBranches")
2407
    if ( C4::Context->preference("IndependentBranches") ) {
2408
        && !C4::Context->IsSuperLibrarian() )
2408
        unless ( C4::Context->IsSuperLibrarian() ) {
2409
    {
2409
            $query .= " AND (borrowers.branchcode = ? OR borrowers.branchcode ='' ) ";
2410
        my $branches =
2410
            push @query_params, C4::Context->userenv->{branch};
2411
          GetIndependentGroupModificationRights( { stringify => 1 } );
2411
        }
2412
        $query .= qq{ AND ( borrowers.branchcode = ? OR borrowers.branchcode IN ( $branches ) ) };
2412
    }
2413
    }
2413
    $query .= " ORDER BY id";
2414
    $query .= " ORDER BY id";
2414
    my $sth = $dbh->prepare($query);
2415
    my $sth = $dbh->prepare($query);
(-)a/C4/Branch.pm (-5 / +103 lines)
Lines 19-24 package C4::Branch; Link Here
19
use strict;
19
use strict;
20
#use warnings; FIXME - Bug 2505
20
#use warnings; FIXME - Bug 2505
21
require Exporter;
21
require Exporter;
22
use Carp;
22
use C4::Context;
23
use C4::Context;
23
24
24
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
25
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Lines 42-47 BEGIN { Link Here
42
		&GetBranchCategories
43
		&GetBranchCategories
43
		&GetBranchesInCategory
44
		&GetBranchesInCategory
44
		&ModBranchCategoryInfo
45
		&ModBranchCategoryInfo
46
        &GetIndependentGroupModificationRights
45
		&DelBranch
47
		&DelBranch
46
		&DelBranchCategory
48
		&DelBranchCategory
47
	        &CheckCategoryUnique
49
	        &CheckCategoryUnique
Lines 113-121 sub GetBranches { Link Here
113
    my $sth;
115
    my $sth;
114
    my $query = "SELECT * FROM branches";
116
    my $query = "SELECT * FROM branches";
115
    my @bind_parameters;
117
    my @bind_parameters;
116
    if ( $onlymine && C4::Context->userenv && C4::Context->userenv->{branch} ) {
118
    if ($onlymine && C4::Context->userenv && C4::Context->userenv->{branch}){
117
        $query .= ' WHERE branchcode = ? ';
119
      my $branches = GetIndependentGroupModificationRights({ stringify => 1 });
118
        push @bind_parameters, C4::Context->userenv->{branch};
120
      $query .= qq{ WHERE branchcode IN ( $branches ) };
119
    }
121
    }
120
    $query .= " ORDER BY branchname";
122
    $query .= " ORDER BY branchname";
121
    $sth = $dbh->prepare($query);
123
    $sth = $dbh->prepare($query);
Lines 294-300 C<$results> is an hashref Link Here
294
296
295
sub GetBranchCategory {
297
sub GetBranchCategory {
296
    my ($catcode) = @_;
298
    my ($catcode) = @_;
297
    return unless $catcode;
299
    unless ( $catcode ) {
300
        carp("No category code passed in!");
301
        return;
302
    }
298
303
299
    my $dbh = C4::Context->dbh;
304
    my $dbh = C4::Context->dbh;
300
    my $sth;
305
    my $sth;
Lines 364-370 the categories were already here, and minimally used. Link Here
364
369
365
	#TODO  manage category types.  rename possibly to 'agency domains' ? as borrowergroups are called categories.
370
	#TODO  manage category types.  rename possibly to 'agency domains' ? as borrowergroups are called categories.
366
sub GetCategoryTypes {
371
sub GetCategoryTypes {
367
	return ( 'searchdomain','properties');
372
 return ( 'searchdomain','independent_groups');
368
}
373
}
369
374
370
=head2 GetBranch
375
=head2 GetBranch
Lines 419-424 sub GetBranchesInCategory { Link Here
419
	return( \@branches );
424
	return( \@branches );
420
}
425
}
421
426
427
=head2 GetIndependentGroupModificationRights
428
429
    GetIndependentGroupModificationRights(
430
                                           {
431
                                               branch => $this_branch,
432
                                               for => $other_branch,
433
                                               stringify => 1,
434
                                           }
435
                                          );
436
437
    Returns a list of branches this branch shares a common
438
    independent group with.
439
440
    If 'branch' is not provided, it will be looked up via
441
    C4::Context->userenv->{branch}.
442
443
    If 'for' is provided, the lookup is limited to that branch.
444
445
    If called in a list context, returns a list of
446
    branchcodes ( including $this_branch ).
447
448
    If called in a scalar context, it returns
449
    a count of matching branchcodes. Returns 1 if
450
451
    If stringify param is passed, the return value will
452
    be a string of the comma delimited branchcodes. This
453
    is useful for "branchcode IN $branchcodes" clauses
454
    in SQL queries.
455
456
    $this_branch and $other_branch are equal for efficiency.
457
458
    So you can write:
459
    my @branches = GetIndependentGroupModificationRights();
460
    or something like:
461
    if ( GetIndependentGroupModificationRights( { for => $other_branch } ) ) { do_stuff(); }
462
463
=cut
464
465
sub GetIndependentGroupModificationRights {
466
    my ($params) = @_;
467
468
    my $this_branch  = $params->{branch};
469
    my $other_branch = $params->{for};
470
    my $stringify    = $params->{stringify};
471
472
    $this_branch ||= C4::Context->userenv->{branch};
473
474
    carp("No branch found!") unless ($this_branch);
475
476
    return 1 if ( $this_branch eq $other_branch );
477
478
    my $sql = q{
479
        SELECT DISTINCT(branchcode)
480
        FROM branchrelations
481
        JOIN branchcategories USING ( categorycode )
482
        WHERE categorycode IN (
483
            SELECT categorycode
484
            FROM branchrelations
485
            WHERE branchcode = ?
486
        )
487
        AND branchcategories.categorytype = 'independent_group'
488
    };
489
490
    my @params;
491
    push( @params, $this_branch );
492
493
    if ($other_branch) {
494
        $sql .= q{ AND branchcode = ? };
495
        push( @params, $other_branch );
496
    }
497
498
    my $dbh = C4::Context->dbh;
499
    my @branchcodes = @{ $dbh->selectcol_arrayref( $sql, {}, @params ) };
500
501
    if ( $stringify ) {
502
        if ( @branchcodes ) {
503
            return join( ',', map { qq{'$_'} } @branchcodes );
504
        } else {
505
            return qq{'$this_branch'};
506
        }
507
    }
508
509
    if ( wantarray() ) {
510
        if ( @branchcodes ) {
511
            return @branchcodes;
512
        } else {
513
            return $this_branch;
514
        }
515
    } else {
516
        return scalar(@branchcodes);
517
    }
518
}
519
422
=head2 GetBranchInfo
520
=head2 GetBranchInfo
423
521
424
$results = GetBranchInfo($branchcode);
522
$results = GetBranchInfo($branchcode);
(-)a/C4/Circulation.pm (-5 / +16 lines)
Lines 896-909 sub CanBookBeIssued { Link Here
896
        $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
896
        $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
897
    }
897
    }
898
    if ( C4::Context->preference("IndependentBranches") ) {
898
    if ( C4::Context->preference("IndependentBranches") ) {
899
        my $userenv = C4::Context->userenv;
900
        unless ( C4::Context->IsSuperLibrarian() ) {
899
        unless ( C4::Context->IsSuperLibrarian() ) {
901
            if ( $item->{C4::Context->preference("HomeOrHoldingBranch")} ne $userenv->{branch} ){
900
            unless (
901
                GetIndependentGroupModificationRights(
902
                    {
903
                        for => $item->{ C4::Context->preference(
904
                                "HomeOrHoldingBranch") }
905
                    }
906
                )
907
              )
908
            {
902
                $issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
909
                $issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
903
                $issuingimpossible{'itemhomebranch'} = $item->{C4::Context->preference("HomeOrHoldingBranch")};
910
                $issuingimpossible{'itemhomebranch'} =
911
                  $item->{ C4::Context->preference("HomeOrHoldingBranch") };
904
            }
912
            }
905
            $needsconfirmation{BORRNOTSAMEBRANCH} = GetBranchName( $borrower->{'branchcode'} )
913
906
              if ( $borrower->{'branchcode'} ne $userenv->{branch} );
914
            $needsconfirmation{BORRNOTSAMEBRANCH} =
915
              GetBranchName( $borrower->{'branchcode'} )
916
              if (
917
                $borrower->{'branchcode'} ne C4::Context->userenv->{branch} );
907
        }
918
        }
908
    }
919
    }
909
920
(-)a/C4/Items.pm (-18 / +30 lines)
Lines 35-40 use DateTime::Format::MySQL; Link Here
35
use Data::Dumper; # used as part of logging item record changes, not just for
35
use Data::Dumper; # used as part of logging item record changes, not just for
36
                  # debugging; so please don't remove this
36
                  # debugging; so please don't remove this
37
use Koha::DateUtils qw/dt_from_string/;
37
use Koha::DateUtils qw/dt_from_string/;
38
use C4::Branch qw/GetIndependentGroupModificationRights/;
38
39
39
use vars qw($VERSION @ISA @EXPORT);
40
use vars qw($VERSION @ISA @EXPORT);
40
41
Lines 1295-1312 sub GetItemsInfo { Link Here
1295
        my $datedue = '';
1296
        my $datedue = '';
1296
        $isth->execute( $data->{'itemnumber'} );
1297
        $isth->execute( $data->{'itemnumber'} );
1297
        if ( my $idata = $isth->fetchrow_hashref ) {
1298
        if ( my $idata = $isth->fetchrow_hashref ) {
1298
            $data->{borrowernumber} = $idata->{borrowernumber};
1299
            $data->{borrowernumber}  = $idata->{borrowernumber};
1299
            $data->{cardnumber}     = $idata->{cardnumber};
1300
            $data->{cardnumber}      = $idata->{cardnumber};
1300
            $data->{surname}     = $idata->{surname};
1301
            $data->{surname}         = $idata->{surname};
1301
            $data->{firstname}     = $idata->{firstname};
1302
            $data->{firstname}       = $idata->{firstname};
1302
            $data->{lastreneweddate} = $idata->{lastreneweddate};
1303
            $data->{lastreneweddate} = $idata->{lastreneweddate};
1303
            $datedue                = $idata->{'date_due'};
1304
            $datedue                 = $idata->{'date_due'};
1304
        if (C4::Context->preference("IndependentBranches")){
1305
1305
        my $userenv = C4::Context->userenv;
1306
            if ( C4::Context->preference("IndependentBranches") && C4::Context->userenv ) {
1306
        unless ( C4::Context->IsSuperLibrarian() ) {
1307
                unless (
1307
            $data->{'NOTSAMEBRANCH'} = 1 if ($idata->{'bcode'} ne $userenv->{branch});
1308
                    C4::Context->IsSuperLibrarian()
1308
        }
1309
                    || GetIndependentGroupModificationRights( { for => $idata->{'bcode'} } )
1309
        }
1310
                  )
1311
                {
1312
                    $data->{'NOTSAMEBRANCH'} = 1 if ($idata->{'bcode'} ne C4::Context->userenv->{branch});
1313
                }
1314
            }
1310
        }
1315
        }
1311
		if ( $data->{'serial'}) {	
1316
		if ( $data->{'serial'}) {	
1312
			$ssth->execute($data->{'itemnumber'}) ;
1317
			$ssth->execute($data->{'itemnumber'}) ;
Lines 2262-2273 sub DelItemCheck { Link Here
2262
2267
2263
    my $item = GetItem($itemnumber);
2268
    my $item = GetItem($itemnumber);
2264
2269
2265
    if ($onloan){
2270
    if ($onloan) {
2266
        $error = "book_on_loan" 
2271
        $error = "book_on_loan";
2267
    }
2272
    }
2268
    elsif ( !C4::Context->IsSuperLibrarian()
2273
    elsif (
2269
        and C4::Context->preference("IndependentBranches")
2274
           !C4::Context->IsSuperLibrarian()
2270
        and ( C4::Context->userenv->{branch} ne $item->{'homebranch'} ) )
2275
        && C4::Context->preference("IndependentBranches")
2276
        && !GetIndependentGroupModificationRights(
2277
            {
2278
                for => $item->{ C4::Context->preference("HomeOrHoldingBranch") }
2279
            }
2280
        )
2281
      )
2271
    {
2282
    {
2272
        $error = "not_same_branch";
2283
        $error = "not_same_branch";
2273
    }
2284
    }
Lines 2749-2756 sub PrepareItemrecordDisplay { Link Here
2749
                    if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
2760
                    if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
2750
                        if (   ( C4::Context->preference("IndependentBranches") )
2761
                        if (   ( C4::Context->preference("IndependentBranches") )
2751
                            && !C4::Context->IsSuperLibrarian() ) {
2762
                            && !C4::Context->IsSuperLibrarian() ) {
2752
                            my $sth = $dbh->prepare( "SELECT branchcode,branchname FROM branches WHERE branchcode = ? ORDER BY branchname" );
2763
                            my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
2753
                            $sth->execute( C4::Context->userenv->{branch} );
2764
                            my $sth = $dbh->prepare( "SELECT branchcode,branchname FROM branches WHERE branchcode IN ( $branches ) ORDER BY branchname" );
2765
                            $sth->execute();
2754
                            push @authorised_values, ""
2766
                            push @authorised_values, ""
2755
                              unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2767
                              unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2756
                            while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
2768
                            while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
(-)a/C4/Letters.pm (+1 lines)
Lines 126-131 sub getletter { Link Here
126
    my ( $module, $code, $branchcode, $message_transport_type ) = @_;
126
    my ( $module, $code, $branchcode, $message_transport_type ) = @_;
127
    $message_transport_type ||= 'email';
127
    $message_transport_type ||= 'email';
128
128
129
    $branchcode ||= q{};
129
130
130
    if ( C4::Context->preference('IndependentBranches')
131
    if ( C4::Context->preference('IndependentBranches')
131
            and $branchcode
132
            and $branchcode
(-)a/C4/Members.pm (-49 / +69 lines)
Lines 25-30 use strict; Link Here
25
use C4::Context;
25
use C4::Context;
26
use C4::Dates qw(format_date_in_iso format_date);
26
use C4::Dates qw(format_date_in_iso format_date);
27
use String::Random qw( random_string );
27
use String::Random qw( random_string );
28
use Clone qw(clone);
28
use Date::Calc qw/Today Add_Delta_YM check_date Date_to_Days/;
29
use Date::Calc qw/Today Add_Delta_YM check_date Date_to_Days/;
29
use C4::Log; # logaction
30
use C4::Log; # logaction
30
use C4::Overdues;
31
use C4::Overdues;
Lines 41-47 use Koha::DateUtils; Link Here
41
use Koha::Borrower::Debarments qw(IsDebarred);
42
use Koha::Borrower::Debarments qw(IsDebarred);
42
use Text::Unaccent qw( unac_string );
43
use Text::Unaccent qw( unac_string );
43
use Koha::AuthUtils qw(hash_password);
44
use Koha::AuthUtils qw(hash_password);
44
45
use C4::Branch qw( GetIndependentGroupModificationRights );
45
our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,$debug);
46
our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,$debug);
46
47
47
BEGIN {
48
BEGIN {
Lines 255-279 sub Search { Link Here
255
    # $showallbranches was not used at the time SearchMember() was mainstreamed into Search().
256
    # $showallbranches was not used at the time SearchMember() was mainstreamed into Search().
256
    # Mentioning for the reference
257
    # Mentioning for the reference
257
258
258
    if ( C4::Context->preference("IndependentBranches") ) { # && !$showallbranches){
259
    if ( C4::Context->preference("IndependentBranches") ) {
259
        if ( my $userenv = C4::Context->userenv ) {
260
        unless ( C4::Context->IsSuperLibrarian() ) {
260
            my $branch =  $userenv->{'branch'};
261
            $filter = clone($filter);    # Modify a copy only
261
            if ( !C4::Context->IsSuperLibrarian() && $branch ){
262
            my @branches = GetIndependentGroupModificationRights();
262
                if (my $fr = ref $filter) {
263
            if ( my $fr = ref $filter ) {
263
                    if ( $fr eq "HASH" ) {
264
                if ( $fr eq "HASH" ) {
264
                        $filter->{branchcode} = $branch;
265
                    $filter->{branchcode} = \@branches;
265
                    }
266
                    else {
267
                        foreach (@$filter) {
268
                            $_ = { '' => $_ } unless ref $_;
269
                            $_->{branchcode} = $branch;
270
                        }
271
                    }
272
                }
266
                }
273
                else {
267
                else {
274
                    $filter = { '' => $filter, branchcode => $branch };
268
                    foreach (@$filter) {
269
                        $_ = { '' => $_ } unless ref $_;
270
                        $_->{branchcode} = \@branches;
271
                    }
275
                }
272
                }
276
            }      
273
            }
274
            else {
275
                $filter = { '' => $filter, branchcode => \@branches };
276
            }
277
        }
277
        }
278
    }
278
    }
279
279
Lines 1344-1349 sub checkuniquemember { Link Here
1344
            ($dateofbirth) ?
1344
            ($dateofbirth) ?
1345
            "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?  and dateofbirth=?" :
1345
            "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?  and dateofbirth=?" :
1346
            "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?";
1346
            "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?";
1347
1348
    if ( C4::Context->preference('IndependentBranches') ) {
1349
        my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
1350
        $request .= " AND branchcode IN ( $branches )";
1351
    }
1352
1347
    my $sth = $dbh->prepare($request);
1353
    my $sth = $dbh->prepare($request);
1348
    if ($collectivity) {
1354
    if ($collectivity) {
1349
        $sth->execute( uc($surname) );
1355
        $sth->execute( uc($surname) );
Lines 1996-2008 sub GetBorrowersToExpunge { Link Here
1996
    my $filterdate     = $params->{'not_borrowered_since'};
2002
    my $filterdate     = $params->{'not_borrowered_since'};
1997
    my $filterexpiry   = $params->{'expired_before'};
2003
    my $filterexpiry   = $params->{'expired_before'};
1998
    my $filtercategory = $params->{'category_code'};
2004
    my $filtercategory = $params->{'category_code'};
1999
    my $filterbranch   = $params->{'branchcode'} ||
2005
    my $filterbranch   = $params->{'branchcode'};
2000
                        ((C4::Context->preference('IndependentBranches')
2006
    my @filterbranches =
2001
                             && C4::Context->userenv 
2007
      (      C4::Context->preference('IndependentBranches')
2002
                             && !C4::Context->IsSuperLibrarian()
2008
          && C4::Context->userenv
2003
                             && C4::Context->userenv->{branch})
2009
          && !C4::Context->IsSuperLibrarian()
2004
                         ? C4::Context->userenv->{branch}
2010
          && C4::Context->userenv->{branch} )
2005
                         : "");  
2011
      ? GetIndependentGroupModificationRights()
2012
      : ($filterbranch);
2006
2013
2007
    my $dbh   = C4::Context->dbh;
2014
    my $dbh   = C4::Context->dbh;
2008
    my $query = "
2015
    my $query = "
Lines 2017-2025 sub GetBorrowersToExpunge { Link Here
2017
        AND borrowernumber NOT IN (SELECT guarantorid FROM borrowers WHERE guarantorid IS NOT NULL AND guarantorid <> 0)
2024
        AND borrowernumber NOT IN (SELECT guarantorid FROM borrowers WHERE guarantorid IS NOT NULL AND guarantorid <> 0)
2018
   ";
2025
   ";
2019
    my @query_params;
2026
    my @query_params;
2020
    if ( $filterbranch && $filterbranch ne "" ) {
2027
    if ( @filterbranches ) {
2021
        $query.= " AND borrowers.branchcode = ? ";
2028
        my $placeholders = join( ',', ('?') x @filterbranches );
2022
        push( @query_params, $filterbranch );
2029
        $query.= " AND borrowers.branchcode IN ( $placeholders )";
2030
        push( @query_params, @filterbranches );
2023
    }
2031
    }
2024
    if ( $filterexpiry ) {
2032
    if ( $filterexpiry ) {
2025
        $query .= " AND dateexpiry < ? ";
2033
        $query .= " AND dateexpiry < ? ";
Lines 2062-2074 I<$result> is a ref to an array which all elements are a hasref. Link Here
2062
=cut
2070
=cut
2063
2071
2064
sub GetBorrowersWhoHaveNeverBorrowed {
2072
sub GetBorrowersWhoHaveNeverBorrowed {
2065
    my $filterbranch = shift || 
2073
    my $filterbranch = shift;
2066
                        ((C4::Context->preference('IndependentBranches')
2074
2067
                             && C4::Context->userenv 
2075
    my @filterbranches =
2068
                             && !C4::Context->IsSuperLibrarian()
2076
      (      C4::Context->preference('IndependentBranches')
2069
                             && C4::Context->userenv->{branch})
2077
          && C4::Context->userenv
2070
                         ? C4::Context->userenv->{branch}
2078
          && !C4::Context->IsSuperLibrarian()
2071
                         : "");  
2079
          && C4::Context->userenv->{branch} )
2080
      ? GetIndependentGroupModificationRights()
2081
      : ($filterbranch);
2082
2072
    my $dbh   = C4::Context->dbh;
2083
    my $dbh   = C4::Context->dbh;
2073
    my $query = "
2084
    my $query = "
2074
        SELECT borrowers.borrowernumber,max(timestamp) as latestissue
2085
        SELECT borrowers.borrowernumber,max(timestamp) as latestissue
Lines 2076-2085 sub GetBorrowersWhoHaveNeverBorrowed { Link Here
2076
          LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
2087
          LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
2077
        WHERE issues.borrowernumber IS NULL
2088
        WHERE issues.borrowernumber IS NULL
2078
   ";
2089
   ";
2090
2079
    my @query_params;
2091
    my @query_params;
2080
    if ($filterbranch && $filterbranch ne ""){ 
2092
    if (@filterbranches) {
2081
        $query.=" AND borrowers.branchcode= ?";
2093
        my $placeholders = join( ',', ('?') x @filterbranches );
2082
        push @query_params,$filterbranch;
2094
        $query .= " AND borrowers.branchcode IN ( $placeholders ) ";
2095
        push( @query_params, @filterbranches );
2083
    }
2096
    }
2084
    warn $query if $debug;
2097
    warn $query if $debug;
2085
  
2098
  
Lines 2112-2136 This hashref is containt the number of time this borrowers has borrowed before I Link Here
2112
sub GetBorrowersWithIssuesHistoryOlderThan {
2125
sub GetBorrowersWithIssuesHistoryOlderThan {
2113
    my $dbh  = C4::Context->dbh;
2126
    my $dbh  = C4::Context->dbh;
2114
    my $date = shift ||POSIX::strftime("%Y-%m-%d",localtime());
2127
    my $date = shift ||POSIX::strftime("%Y-%m-%d",localtime());
2115
    my $filterbranch = shift || 
2128
    my $filterbranch = shift;
2116
                        ((C4::Context->preference('IndependentBranches')
2129
2117
                             && C4::Context->userenv 
2130
    my @filterbranches =
2118
                             && !C4::Context->IsSuperLibrarian()
2131
      (      C4::Context->preference('IndependentBranches')
2119
                             && C4::Context->userenv->{branch})
2132
          && C4::Context->userenv
2120
                         ? C4::Context->userenv->{branch}
2133
          && !C4::Context->IsSuperLibrarian()
2121
                         : "");  
2134
          && C4::Context->userenv->{branch} )
2135
      ? GetIndependentGroupModificationRights()
2136
      : ($filterbranch);
2137
2122
    my $query = "
2138
    my $query = "
2123
       SELECT count(borrowernumber) as n,borrowernumber
2139
       SELECT count(borrowernumber) as n,borrowernumber
2124
       FROM old_issues
2140
       FROM old_issues
2125
       WHERE returndate < ?
2141
       WHERE returndate < ?
2126
         AND borrowernumber IS NOT NULL 
2142
         AND borrowernumber IS NOT NULL 
2127
    "; 
2143
    "; 
2144
2128
    my @query_params;
2145
    my @query_params;
2129
    push @query_params, $date;
2146
    push( @query_params, $date );
2130
    if ($filterbranch){
2147
2131
        $query.="   AND branchcode = ?";
2148
    if (@filterbranches) {
2132
        push @query_params, $filterbranch;
2149
        my $placeholders = join( ',', ('?') x @filterbranches );
2133
    }    
2150
        $query .= " AND branchcode IN ( $placeholders ) ";
2151
        push( @query_params, @filterbranches );
2152
    }
2153
2134
    $query.=" GROUP BY borrowernumber ";
2154
    $query.=" GROUP BY borrowernumber ";
2135
    warn $query if $debug;
2155
    warn $query if $debug;
2136
    my $sth = $dbh->prepare($query);
2156
    my $sth = $dbh->prepare($query);
(-)a/C4/Serials.pm (-13 / +96 lines)
Lines 31-36 use C4::Log; # logaction Link Here
31
use C4::Debug;
31
use C4::Debug;
32
use C4::Serials::Frequency;
32
use C4::Serials::Frequency;
33
use C4::Serials::Numberpattern;
33
use C4::Serials::Numberpattern;
34
use C4::Branch qw(GetIndependentGroupModificationRights);
34
35
35
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
36
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
36
37
Lines 231-237 sub GetSerialInformation { Link Here
231
    my ($serialid) = @_;
232
    my ($serialid) = @_;
232
    my $dbh        = C4::Context->dbh;
233
    my $dbh        = C4::Context->dbh;
233
    my $query      = qq|
234
    my $query      = qq|
234
        SELECT serial.*, serial.notes as sernotes, serial.status as serstatus,subscription.*,subscription.subscriptionid as subsid
235
        SELECT serial.*,
236
               serial.notes as sernotes,
237
               serial.status as serstatus,
238
               subscription.*,
239
               subscription.subscriptionid as subsid
240
    |;
241
    if (   C4::Context->preference('IndependentBranches')
242
        && C4::Context->userenv
243
        && C4::Context->userenv->{'flags'} % 2 != 1
244
        && C4::Context->userenv->{'branch'} ) {
245
        my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
246
        $query .= qq|
247
            , ( ( subscription.branchcode NOT IN ( $branches ) ) AND subscription.branchcode <> '' AND subscription.branchcode IS NOT NULL ) AS cannotedit
248
        |;
249
    }
250
    $query .= qq|
235
        FROM   serial LEFT JOIN subscription ON subscription.subscriptionid=serial.subscriptionid
251
        FROM   serial LEFT JOIN subscription ON subscription.subscriptionid=serial.subscriptionid
236
        WHERE  serialid = ?
252
        WHERE  serialid = ?
237
    |;
253
    |;
Lines 330-347 subscription, subscriptionhistory, aqbooksellers.name, biblio.title Link Here
330
sub GetSubscription {
346
sub GetSubscription {
331
    my ($subscriptionid) = @_;
347
    my ($subscriptionid) = @_;
332
    my $dbh              = C4::Context->dbh;
348
    my $dbh              = C4::Context->dbh;
333
    my $query            = qq(
349
350
    my $query = qq|
334
        SELECT  subscription.*,
351
        SELECT  subscription.*,
335
                subscriptionhistory.*,
352
                subscriptionhistory.*,
336
                aqbooksellers.name AS aqbooksellername,
353
                aqbooksellers.name AS aqbooksellername,
337
                biblio.title AS bibliotitle,
354
                biblio.title AS bibliotitle,
338
                subscription.biblionumber as bibnum
355
                subscription.biblionumber as bibnum
356
    |;
357
358
    if (   C4::Context->preference('IndependentBranches')
359
        && C4::Context->userenv
360
        && C4::Context->userenv->{'flags'} % 2 != 1
361
        && C4::Context->userenv->{'branch'} )
362
    {
363
        my $branches =
364
          GetIndependentGroupModificationRights( { stringify => 1 } );
365
366
        $query .= qq|
367
            , ( ( subscription.branchcode NOT IN ( $branches ) ) AND subscription.branchcode <> '' AND subscription.branchcode IS NOT NULL ) AS cannotedit
368
        |;
369
    }
370
371
    $query .= qq|
339
       FROM subscription
372
       FROM subscription
340
       LEFT JOIN subscriptionhistory ON subscription.subscriptionid=subscriptionhistory.subscriptionid
373
       LEFT JOIN subscriptionhistory ON subscription.subscriptionid=subscriptionhistory.subscriptionid
341
       LEFT JOIN aqbooksellers ON subscription.aqbooksellerid=aqbooksellers.id
374
       LEFT JOIN aqbooksellers ON subscription.aqbooksellerid=aqbooksellers.id
342
       LEFT JOIN biblio ON biblio.biblionumber=subscription.biblionumber
375
       LEFT JOIN biblio ON biblio.biblionumber=subscription.biblionumber
343
       WHERE subscription.subscriptionid = ?
376
       WHERE subscription.subscriptionid = ?
344
    );
377
    |;
345
378
346
    $debug and warn "query : $query\nsubsid :$subscriptionid";
379
    $debug and warn "query : $query\nsubsid :$subscriptionid";
347
    my $sth = $dbh->prepare($query);
380
    my $sth = $dbh->prepare($query);
Lines 364-371 sub GetFullSubscription { Link Here
364
    return unless ($subscriptionid);
397
    return unless ($subscriptionid);
365
398
366
    my $dbh              = C4::Context->dbh;
399
    my $dbh              = C4::Context->dbh;
367
    my $query            = qq|
400
368
  SELECT    serial.serialid,
401
    my $query = qq|
402
        SELECT
403
            serial.serialid,
369
            serial.serialseq,
404
            serial.serialseq,
370
            serial.planneddate, 
405
            serial.planneddate, 
371
            serial.publisheddate, 
406
            serial.publisheddate, 
Lines 376-381 sub GetFullSubscription { Link Here
376
            biblio.title as bibliotitle,
411
            biblio.title as bibliotitle,
377
            subscription.branchcode AS branchcode,
412
            subscription.branchcode AS branchcode,
378
            subscription.subscriptionid AS subscriptionid
413
            subscription.subscriptionid AS subscriptionid
414
    |;
415
416
    if (   C4::Context->preference('IndependentBranches')
417
        && C4::Context->userenv
418
        && C4::Context->userenv->{'flags'} % 2 != 1
419
        && C4::Context->userenv->{'branch'} )
420
    {
421
        my $branches =
422
          GetIndependentGroupModificationRights( { stringify => 1 } );
423
424
        $query .= qq|
425
            , ( ( subscription.branchcode NOT IN ( $branches ) ) AND subscription.branchcode <> '' AND subscription.branchcode IS NOT NULL ) AS cannotedit
426
        |;
427
    }
428
429
    $query .= qq|
379
  FROM      serial 
430
  FROM      serial 
380
  LEFT JOIN subscription ON 
431
  LEFT JOIN subscription ON 
381
          (serial.subscriptionid=subscription.subscriptionid )
432
          (serial.subscriptionid=subscription.subscriptionid )
Lines 496-501 sub GetSubscriptionsFromBiblionumber { Link Here
496
        $subs->{ "periodicity" . $subs->{periodicity} }     = 1;
547
        $subs->{ "periodicity" . $subs->{periodicity} }     = 1;
497
        $subs->{ "numberpattern" . $subs->{numberpattern} } = 1;
548
        $subs->{ "numberpattern" . $subs->{numberpattern} } = 1;
498
        $subs->{ "status" . $subs->{'status'} }             = 1;
549
        $subs->{ "status" . $subs->{'status'} }             = 1;
550
        $subs->{'cannotedit'} = (
551
                 C4::Context->preference('IndependentBranches')
552
              && C4::Context->userenv
553
              && !C4::Context->IsSuperLibrarian()
554
              && C4::Context->userenv->{branch}
555
              && $subs->{branchcode}
556
              && GetIndependentGroupModificationRights(
557
                { for => $subs->{branchcode} }
558
              )
559
        );
499
560
500
        if ( $subs->{enddate} eq '0000-00-00' ) {
561
        if ( $subs->{enddate} eq '0000-00-00' ) {
501
            $subs->{enddate} = '';
562
            $subs->{enddate} = '';
Lines 520-527 sub GetSubscriptionsFromBiblionumber { Link Here
520
sub GetFullSubscriptionsFromBiblionumber {
581
sub GetFullSubscriptionsFromBiblionumber {
521
    my ($biblionumber) = @_;
582
    my ($biblionumber) = @_;
522
    my $dbh            = C4::Context->dbh;
583
    my $dbh            = C4::Context->dbh;
523
    my $query          = qq|
584
524
  SELECT    serial.serialid,
585
    my $query = qq|
586
        SELECT
587
            serial.serialid,
525
            serial.serialseq,
588
            serial.serialseq,
526
            serial.planneddate, 
589
            serial.planneddate, 
527
            serial.publisheddate, 
590
            serial.publisheddate, 
Lines 531-536 sub GetFullSubscriptionsFromBiblionumber { Link Here
531
            biblio.title as bibliotitle,
594
            biblio.title as bibliotitle,
532
            subscription.branchcode AS branchcode,
595
            subscription.branchcode AS branchcode,
533
            subscription.subscriptionid AS subscriptionid
596
            subscription.subscriptionid AS subscriptionid
597
    |;
598
599
    if (   C4::Context->preference('IndependentBranches')
600
        && C4::Context->userenv
601
        && C4::Context->userenv->{'flags'} != 1
602
        && C4::Context->userenv->{'branch'} )
603
    {
604
        my $branches =
605
          GetIndependentGroupModificationRights( { stringify => 1 } );
606
607
        $query .= qq|
608
            , ( ( subscription.branchcode NOT IN ( $branches ) ) AND subscription.branchcode <> '' AND subscription.branchcode IS NOT NULL ) AS cannotedit
609
        |;
610
    }
611
612
    $query .= qq|
534
  FROM      serial 
613
  FROM      serial 
535
  LEFT JOIN subscription ON 
614
  LEFT JOIN subscription ON 
536
          (serial.subscriptionid=subscription.subscriptionid)
615
          (serial.subscriptionid=subscription.subscriptionid)
Lines 2820-2826 sub can_show_subscription { Link Here
2820
sub _can_do_on_subscription {
2899
sub _can_do_on_subscription {
2821
    my ( $subscription, $userid, $permission ) = @_;
2900
    my ( $subscription, $userid, $permission ) = @_;
2822
    return 0 unless C4::Context->userenv;
2901
    return 0 unless C4::Context->userenv;
2902
2823
    my $flags = C4::Context->userenv->{flags};
2903
    my $flags = C4::Context->userenv->{flags};
2904
2824
    $userid ||= C4::Context->userenv->{'id'};
2905
    $userid ||= C4::Context->userenv->{'id'};
2825
2906
2826
    if ( C4::Context->preference('IndependentBranches') ) {
2907
    if ( C4::Context->preference('IndependentBranches') ) {
Lines 2829-2840 sub _can_do_on_subscription { Link Here
2829
              or
2910
              or
2830
              C4::Auth::haspermission( $userid, { serials => 'superserials' } )
2911
              C4::Auth::haspermission( $userid, { serials => 'superserials' } )
2831
              or (
2912
              or (
2832
                  C4::Auth::haspermission( $userid,
2913
                  C4::Auth::haspermission(
2833
                      { serials => $permission } )
2914
                      $userid, { serials => $permission }
2915
                  )
2834
                  and (  not defined $subscription->{branchcode}
2916
                  and (  not defined $subscription->{branchcode}
2835
                      or $subscription->{branchcode} eq ''
2917
                      or $subscription->{branchcode} eq ''
2836
                      or $subscription->{branchcode} eq
2918
                      or $subscription->{branchcode} eq
2837
                      C4::Context->userenv->{'branch'} )
2919
                      C4::Context->userenv->{'branch'} )
2920
              )
2921
              or GetIndependentGroupModificationRights(
2922
                  { for => $subscription->{branchcode} }
2838
              );
2923
              );
2839
    }
2924
    }
2840
    else {
2925
    else {
Lines 2842-2851 sub _can_do_on_subscription { Link Here
2842
          if C4::Context->IsSuperLibrarian()
2927
          if C4::Context->IsSuperLibrarian()
2843
              or
2928
              or
2844
              C4::Auth::haspermission( $userid, { serials => 'superserials' } )
2929
              C4::Auth::haspermission( $userid, { serials => 'superserials' } )
2845
              or C4::Auth::haspermission(
2930
              or C4::Auth::haspermission( $userid, { serials => $permission } )
2846
                  $userid, { serials => $permission }
2931
            ,;
2847
              ),
2848
        ;
2849
    }
2932
    }
2850
    return 0;
2933
    return 0;
2851
}
2934
}
(-)a/C4/Suggestions.pm (-20 / +31 lines)
Lines 32-37 use C4::Letters; Link Here
32
use List::MoreUtils qw(any);
32
use List::MoreUtils qw(any);
33
use C4::Dates qw(format_date_in_iso);
33
use C4::Dates qw(format_date_in_iso);
34
use base qw(Exporter);
34
use base qw(Exporter);
35
use C4::Branch qw(GetIndependentGroupModificationRights);
35
36
36
our $VERSION = 3.07.00.049;
37
our $VERSION = 3.07.00.049;
37
our @EXPORT  = qw(
38
our @EXPORT  = qw(
Lines 132-149 sub SearchSuggestion { Link Here
132
    }
133
    }
133
134
134
    # filter on user branch
135
    # filter on user branch
135
    if ( C4::Context->preference('IndependentBranches') ) {
136
    if (   C4::Context->preference('IndependentBranches')
136
        my $userenv = C4::Context->userenv;
137
        && !C4::Context->IsSuperLibrarian()
137
        if ($userenv) {
138
        && !$suggestion->{branchcode} )
138
            if ( !C4::Context->IsSuperLibrarian() && !$suggestion->{branchcode} )
139
    {
139
            {
140
        my $branches =
140
                push @sql_params, $$userenv{branch};
141
          GetIndependentGroupModificationRights( { stringify => 1 } );
141
                push @query,      q{
142
        push( @query, qq{ AND (suggestions.branchcode IN ( $branches ) OR suggestions.branchcode='') } );
142
                    AND (suggestions.branchcode=? OR suggestions.branchcode='')
143
    }
143
                };
144
    else {
144
            }
145
        }
146
    } else {
147
        if ( defined $suggestion->{branchcode} && $suggestion->{branchcode} ) {
145
        if ( defined $suggestion->{branchcode} && $suggestion->{branchcode} ) {
148
            unless ( $suggestion->{branchcode} eq '__ANY__' ) {
146
            unless ( $suggestion->{branchcode} eq '__ANY__' ) {
149
                push @sql_params, $suggestion->{branchcode};
147
                push @sql_params, $suggestion->{branchcode};
Lines 340-352 sub GetSuggestionByStatus { Link Here
340
338
341
    # filter on branch
339
    # filter on branch
342
    if ( C4::Context->preference("IndependentBranches") || $branchcode ) {
340
    if ( C4::Context->preference("IndependentBranches") || $branchcode ) {
343
        my $userenv = C4::Context->userenv;
341
        if (   C4::Context->userenv
344
        if ($userenv) {
342
            && C4::Context->preference("IndependentBranches")
345
            unless ( C4::Context->IsSuperLibrarian() ) {
343
            && !C4::Context->IsSuperLibrarian() )
346
                push @sql_params, $userenv->{branch};
344
        {
347
                $query .= q{ AND (U1.branchcode = ? OR U1.branchcode ='') };
345
348
            }
346
            my $branches =
347
              GetIndependentGroupModificationRights( { stringify => 1 } );
348
349
            $query .= qq{
350
                AND (U1.branchcode IN ( $branches ) OR U1.branchcode ='')
351
            };
349
        }
352
        }
353
350
        if ($branchcode) {
354
        if ($branchcode) {
351
            push @sql_params, $branchcode;
355
            push @sql_params, $branchcode;
352
            $query .= q{ AND (U1.branchcode = ? OR U1.branchcode ='') };
356
            $query .= q{ AND (U1.branchcode = ? OR U1.branchcode ='') };
Lines 392-403 sub CountSuggestion { Link Here
392
    if ( C4::Context->preference("IndependentBranches")
396
    if ( C4::Context->preference("IndependentBranches")
393
        && !C4::Context->IsSuperLibrarian() )
397
        && !C4::Context->IsSuperLibrarian() )
394
    {
398
    {
395
        my $query = q{
399
        my $branches =
400
          GetIndependentGroupModificationRights( { stringify => 1 } );
401
402
        my $query = qq{
396
            SELECT count(*)
403
            SELECT count(*)
397
            FROM suggestions
404
            FROM suggestions
398
                LEFT JOIN borrowers ON borrowers.borrowernumber=suggestions.suggestedby
405
                LEFT JOIN borrowers ON borrowers.borrowernumber=suggestions.suggestedby
399
            WHERE STATUS=?
406
            WHERE STATUS=?
400
                AND (borrowers.branchcode='' OR borrowers.branchcode=?)
407
                AND (
408
                    borrowers.branchcode IN ( $branches )
409
                    OR
410
                    borrowers.branchcode=?
411
                )
401
        };
412
        };
402
        $sth = $dbh->prepare($query);
413
        $sth = $dbh->prepare($query);
403
        $sth->execute( $status, $userenv->{branch} );
414
        $sth->execute( $status, $userenv->{branch} );
(-)a/acqui/basket.pl (-4 / +18 lines)
Lines 36-41 use C4::Members qw/GetMember/; #needed for permissions checking for changing ba Link Here
36
use C4::Items;
36
use C4::Items;
37
use C4::Suggestions;
37
use C4::Suggestions;
38
use Date::Calc qw/Add_Delta_Days/;
38
use Date::Calc qw/Add_Delta_Days/;
39
use C4::Branch qw/GetIndependentGroupModificationRights/;
39
40
40
=head1 NAME
41
=head1 NAME
41
42
Lines 155-164 if ( $op eq 'delete_confirm' ) { Link Here
155
    if ( C4::Context->preference("IndependentBranches") ) {
156
    if ( C4::Context->preference("IndependentBranches") ) {
156
        my $userenv = C4::Context->userenv;
157
        my $userenv = C4::Context->userenv;
157
        unless ( C4::Context->IsSuperLibrarian() ) {
158
        unless ( C4::Context->IsSuperLibrarian() ) {
158
            my $validtest = ( $basket->{creationdate} eq '' )
159
            my $validtest =
160
                 ( $basket->{creationdate} eq '' )
159
              || ( $userenv->{branch} eq $basket->{branch} )
161
              || ( $userenv->{branch} eq $basket->{branch} )
160
              || ( $userenv->{branch} eq '' )
162
              || ( $userenv->{branch} eq '' )
161
              || ( $basket->{branch}  eq '' );
163
              || ( $basket->{branch}  eq '' )
164
              || (
165
                GetIndependentGroupModificationRights(
166
                    { for => $basket->{branch} }
167
                )
168
              );
169
162
            unless ($validtest) {
170
            unless ($validtest) {
163
                print $query->redirect("../mainpage.pl");
171
                print $query->redirect("../mainpage.pl");
164
                exit 1;
172
                exit 1;
Lines 255-264 if ( $op eq 'delete_confirm' ) { Link Here
255
    if ( C4::Context->preference("IndependentBranches") ) {
263
    if ( C4::Context->preference("IndependentBranches") ) {
256
        my $userenv = C4::Context->userenv;
264
        my $userenv = C4::Context->userenv;
257
        unless ( C4::Context->IsSuperLibrarian() ) {
265
        unless ( C4::Context->IsSuperLibrarian() ) {
258
            my $validtest = ( $basket->{creationdate} eq '' )
266
            my $validtest =
267
                 ( $basket->{creationdate} eq '' )
259
              || ( $userenv->{branch} eq $basket->{branch} )
268
              || ( $userenv->{branch} eq $basket->{branch} )
260
              || ( $userenv->{branch} eq '' )
269
              || ( $userenv->{branch} eq '' )
261
              || ( $basket->{branch}  eq '' );
270
              || ( $basket->{branch}  eq '' )
271
              || (
272
                GetIndependentGroupModificationRights(
273
                    { for => $basket->{branch} }
274
                )
275
              );
262
            unless ($validtest) {
276
            unless ($validtest) {
263
                print $query->redirect("../mainpage.pl");
277
                print $query->redirect("../mainpage.pl");
264
                exit 1;
278
                exit 1;
(-)a/admin/branches.pl (-37 / +15 lines)
Lines 258-264 sub editbranchform { Link Here
258
        $oldprinter = $data->{'branchprinter'} || '';
258
        $oldprinter = $data->{'branchprinter'} || '';
259
        _branch_to_template($data, $innertemplate);
259
        _branch_to_template($data, $innertemplate);
260
    }
260
    }
261
    $innertemplate->param( categoryloop => $catinfo );
261
    $innertemplate->param( branch_categories  => $catinfo );
262
262
263
    foreach my $thisprinter ( keys %$printers ) {
263
    foreach my $thisprinter ( keys %$printers ) {
264
        push @printerloop, {
264
        push @printerloop, {
Lines 277-301 sub editbranchform { Link Here
277
}
277
}
278
278
279
sub editcatform {
279
sub editcatform {
280
280
    my ( $categorycode, $innertemplate ) = @_;
281
    # prepares the edit form...
281
    $innertemplate->param( category => GetBranchCategory($categorycode) );
282
    my ($categorycode,$innertemplate) = @_;
283
    # warn "cat : $categorycode";
284
	my @cats;
285
    my $data;
286
	if ($categorycode) {
287
        my $data = GetBranchCategory($categorycode);
288
        $innertemplate->param(
289
            categorycode    => $data->{'categorycode'},
290
            categoryname    => $data->{'categoryname'},
291
            codedescription => $data->{'codedescription'},
292
            show_in_pulldown => $data->{'show_in_pulldown'},
293
		);
294
    }
295
	for my $ctype (GetCategoryTypes()) {
296
		push @cats , { type => $ctype , selected => ($data->{'categorytype'} and $data->{'categorytype'} eq $ctype) };
297
	}
298
    $innertemplate->param(categorytype => \@cats);
299
}
282
}
300
283
301
sub branchinfotable {
284
sub branchinfotable {
Lines 366-390 sub branchinfotable { Link Here
366
349
367
        push @loop_data, \%row;
350
        push @loop_data, \%row;
368
    }
351
    }
369
    my @branchcategories = ();
352
370
	for my $ctype ( GetCategoryTypes() ) {
353
    my $catinfo = GetBranchCategories();
371
        my $catinfo = GetBranchCategories($ctype);
354
    my $categories;
372
        my @categories;
355
    foreach my $cat (@$catinfo) {
373
		foreach my $cat (@$catinfo) {
356
        $categories->{ $cat->{categorytype} }->{ $cat->{'categorycode'} } = {
374
            push @categories, {
357
            categoryname    => $cat->{'categoryname'},
375
                categoryname    => $cat->{'categoryname'},
358
            codedescription => $cat->{'codedescription'},
376
                categorycode    => $cat->{'categorycode'},
359
        };
377
                codedescription => $cat->{'codedescription'},
360
    }
378
                categorytype    => $cat->{'categorytype'},
361
379
            };
380
    	}
381
        push @branchcategories, { categorytype => $ctype , $ctype => 1 , catloop => ( @categories ? \@categories : undef) };
382
	}
383
    $innertemplate->param(
362
    $innertemplate->param(
384
        branches         => \@loop_data,
363
        branches          => \@loop_data,
385
        branchcategories => \@branchcategories
364
        branch_categories => $categories
386
    );
365
    );
387
388
}
366
}
389
367
390
sub _branch_to_template {
368
sub _branch_to_template {
(-)a/catalogue/moredetail.pl (-5 / +10 lines)
Lines 172-184 foreach my $item (@items){ Link Here
172
        $item->{status_advisory} = 1;
172
        $item->{status_advisory} = 1;
173
    }
173
    }
174
174
175
    if (C4::Context->preference("IndependentBranches")) {
175
    if ( C4::Context->preference("IndependentBranches") ) {
176
        #verifying rights
176
        unless (
177
        my $userenv = C4::Context->userenv();
177
            C4::Context->IsSuperLibrarian()
178
        unless (C4::Context->IsSuperLibrarian() or ($userenv->{'branch'} eq $item->{'homebranch'})) {
178
            || GetIndependentGroupModificationRights(
179
                $item->{'nomod'}=1;
179
                { for => $item->{'homebranch'} }
180
            )
181
          )
182
        {
183
            $item->{'nomod'} = 1;
180
        }
184
        }
181
    }
185
    }
186
182
    $item->{'homebranchname'} = GetBranchName($item->{'homebranch'});
187
    $item->{'homebranchname'} = GetBranchName($item->{'homebranch'});
183
    $item->{'holdingbranchname'} = GetBranchName($item->{'holdingbranch'});
188
    $item->{'holdingbranchname'} = GetBranchName($item->{'holdingbranch'});
184
    if ($item->{'datedue'}) {
189
    if ($item->{'datedue'}) {
(-)a/cataloguing/additem.pl (-2 / +11 lines)
Lines 695-704 foreach my $field (@fields) { Link Here
695
						|| $subfieldvalue;
695
						|| $subfieldvalue;
696
        }
696
        }
697
697
698
        if (($field->tag eq $branchtagfield) && ($subfieldcode eq $branchtagsubfield) && C4::Context->preference("IndependentBranches")) {
698
        if (   $field->tag eq $branchtagfield
699
            && $subfieldcode eq $branchtagsubfield
700
            && C4::Context->preference("IndependentBranches") )
701
        {
699
            #verifying rights
702
            #verifying rights
700
            my $userenv = C4::Context->userenv();
703
            my $userenv = C4::Context->userenv();
701
            unless (C4::Context->IsSuperLibrarian() or (($userenv->{'branch'} eq $subfieldvalue))){
704
            unless (
705
                C4::Context->IsSuperLibrarian()
706
                || GetIndependentGroupModificationRights(
707
                    { for => $subfieldvalue }
708
                )
709
              )
710
            {
702
                $this_row{'nomod'} = 1;
711
                $this_row{'nomod'} = 1;
703
            }
712
            }
704
        }
713
        }
(-)a/circ/circulation-home.pl (-2 / +5 lines)
Lines 23-28 use C4::Auth; Link Here
23
use C4::Output;
23
use C4::Output;
24
use C4::Context;
24
use C4::Context;
25
use C4::Koha;
25
use C4::Koha;
26
use C4::Branch qw/GetIndependentGroupModificationRights/;
26
27
27
my $query = new CGI;
28
my $query = new CGI;
28
my ($template, $loggedinuser, $cookie, $flags)
29
my ($template, $loggedinuser, $cookie, $flags)
Lines 38-45 my $fa = getframeworkinfo('FA'); Link Here
38
$template->param( fast_cataloging => 1 ) if (defined $fa);
39
$template->param( fast_cataloging => 1 ) if (defined $fa);
39
40
40
# Checking if the transfer page needs to be displayed
41
# Checking if the transfer page needs to be displayed
41
$template->param( display_transfer => 1 ) if ( ($flags->{'superlibrarian'} == 1) || (C4::Context->preference("IndependentBranches") == 0) );
42
$template->param( display_transfer => 1 )
42
$template->{'VARS'}->{'AllowOfflineCirculation'} = C4::Context->preference('AllowOfflineCirculation');
43
  if ( $flags->{'superlibrarian'} == 1
44
    || scalar GetIndependentGroupModificationRights() );
43
45
46
$template->{'VARS'}->{'AllowOfflineCirculation'} = C4::Context->preference('AllowOfflineCirculation');
44
47
45
output_html_with_http_headers $query, $cookie, $template->output;
48
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/circ/pendingreserves.pl (-2 / +3 lines)
Lines 36-41 use C4::Auth; Link Here
36
use C4::Dates qw/format_date format_date_in_iso/;
36
use C4::Dates qw/format_date format_date_in_iso/;
37
use C4::Debug;
37
use C4::Debug;
38
use Date::Calc qw/Today Add_Delta_YMD/;
38
use Date::Calc qw/Today Add_Delta_YMD/;
39
use C4::Branch qw/GetIndependentGroupModificationRights/;
39
40
40
my $input = new CGI;
41
my $input = new CGI;
41
my $startdate=$input->param('from');
42
my $startdate=$input->param('from');
Lines 153-160 if ( $run_report ) { Link Here
153
154
154
155
155
    if (C4::Context->preference('IndependentBranches')){
156
    if (C4::Context->preference('IndependentBranches')){
156
        $strsth .= " AND items.holdingbranch=? ";
157
        my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
157
        push @query_params, C4::Context->userenv->{'branch'};
158
        $strsth .= " AND items.holdingbranch IN ( $branches ) ";
158
    }
159
    }
159
    $strsth .= " GROUP BY reserves.biblionumber ORDER BY biblio.title ";
160
    $strsth .= " GROUP BY reserves.biblionumber ORDER BY biblio.title ";
160
161
(-)a/circ/reserveratios.pl (-3 / +3 lines)
Lines 120-128 my $strsth = Link Here
120
 $sqldatewhere
120
 $sqldatewhere
121
";
121
";
122
122
123
if (C4::Context->preference('IndependentBranches')){
123
if ( C4::Context->preference('IndependentBranches') ) {
124
    $strsth .= " AND items.holdingbranch=? ";
124
    my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
125
    push @query_params, C4::Context->userenv->{'branch'};
125
    $strsth .= " AND items.holdingbranch IN ( $branches ) ";
126
}
126
}
127
127
128
$strsth .= " GROUP BY reserves.biblionumber ORDER BY reservecount DESC";
128
$strsth .= " GROUP BY reserves.biblionumber ORDER BY reservecount DESC";
(-)a/installer/data/mysql/kohastructure.sql (-1 / +1 lines)
Lines 365-371 CREATE TABLE `branchcategories` ( -- information related to library/branch group Link Here
365
  `categorycode` varchar(10) NOT NULL default '', -- unique identifier for the library/branch group
365
  `categorycode` varchar(10) NOT NULL default '', -- unique identifier for the library/branch group
366
  `categoryname` varchar(32), -- name of the library/branch group
366
  `categoryname` varchar(32), -- name of the library/branch group
367
  `codedescription` mediumtext, -- longer description of the library/branch group
367
  `codedescription` mediumtext, -- longer description of the library/branch group
368
  `categorytype` varchar(16), -- says whether this is a search group or a properties group
368
  `categorytype` ENUM(  'searchdomain',  'independent_group' ) NULL DEFAULT NULL, -- says whether this is a search group or an independent group
369
  `show_in_pulldown` tinyint(1) NOT NULL DEFAULT '0', -- says this group should be in the opac libararies pulldown if it is enabled
369
  `show_in_pulldown` tinyint(1) NOT NULL DEFAULT '0', -- says this group should be in the opac libararies pulldown if it is enabled
370
  PRIMARY KEY  (`categorycode`),
370
  PRIMARY KEY  (`categorycode`),
371
  KEY `show_in_pulldown` (`show_in_pulldown`)
371
  KEY `show_in_pulldown` (`show_in_pulldown`)
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +17 lines)
Lines 6938-6944 $DBversion = "3.13.00.002"; Link Here
6938
if ( CheckVersion($DBversion) ) {
6938
if ( CheckVersion($DBversion) ) {
6939
   $dbh->do("UPDATE systempreferences SET variable = 'IndependentBranches' WHERE variable = 'IndependantBranches'");
6939
   $dbh->do("UPDATE systempreferences SET variable = 'IndependentBranches' WHERE variable = 'IndependantBranches'");
6940
   print "Upgrade to $DBversion done (Bug 10080 - Change system pref IndependantBranches to IndependentBranches)\n";
6940
   print "Upgrade to $DBversion done (Bug 10080 - Change system pref IndependantBranches to IndependentBranches)\n";
6941
   SetVersion ($DBversion);
6941
    SetVersion ($DBversion);
6942
}
6942
}
6943
6943
6944
$DBversion = '3.13.00.003';
6944
$DBversion = '3.13.00.003';
Lines 8471-8476 if ( CheckVersion($DBversion) ) { Link Here
8471
    SetVersion($DBversion);
8471
    SetVersion($DBversion);
8472
}
8472
}
8473
8473
8474
$DBversion = "3.17.00.XXX";
8475
if ( CheckVersion($DBversion) ) {
8476
    $dbh->do(q{
8477
            DELETE FROM branchcategories WHERE categorytype = 'properties'
8478
    });
8479
8480
    $dbh->do(q{
8481
        ALTER TABLE branchcategories
8482
        CHANGE categorytype categorytype
8483
          ENUM( 'searchdomain', 'independent_group' )
8484
            NULL DEFAULT NULL
8485
    });
8486
    print "Upgrade to $DBversion done (Remove branch property groups, add independent groups)\n";
8487
    SetVersion ($DBversion);
8488
}
8489
8474
=head1 FUNCTIONS
8490
=head1 FUNCTIONS
8475
8491
8476
=head2 TableExists($table)
8492
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt (-71 / +139 lines)
Lines 100-119 tinyMCE.init({ Link Here
100
        </li>
100
        </li>
101
	</ol>
101
	</ol>
102
	</fieldset>
102
	</fieldset>
103
	[% IF ( categoryloop ) %]<fieldset class="rows"><legend>Group(s):</legend>
103
104
        <ol>
104
     [% IF ( branch_categories ) %]
105
		[% FOREACH categoryloo IN categoryloop %]
105
        <fieldset class="rows">
106
            <li><label for="[% categoryloo.categorycode %]">[% categoryloo.categoryname %]: </label>
106
            <legend>Group(s):</legend>
107
                [% IF categoryloo.selected %]
107
            <ol>
108
                    <input type="checkbox" id="[% categoryloo.categorycode %]" name="[% categoryloo.categorycode %]" checked="checked" />
108
                <fieldset>
109
                [% ELSE %]
109
                    <legend>Search domain</legend>
110
                    <input type="checkbox" id="[% categoryloo.categorycode %]" name="[% categoryloo.categorycode %]" />
110
                    [% FOREACH bc IN branch_categories %]
111
                [% END %]
111
                        [% IF bc.categorytype == "searchdomain" %]
112
                <span class="hint">[% categoryloo.codedescription %]</span>
112
                            <li>
113
            </li>
113
                                <label for="[% bc.categorycode %]">[% bc.categoryname %]: </label>
114
        [% END %]
114
                                [% IF ( bc.selected ) %]
115
		</ol>
115
                                    <input type="checkbox" id="[% bc.categorycode %]" name="[% bc.categorycode %]" checked="checked" />
116
</fieldset>[% END %]
116
                                [% ELSE %]
117
                                    <input type="checkbox" id="[% bc.categorycode %]" name="[% bc.categorycode %]" />
118
                                [% END %]
119
                                <span class="hint">[% bc.codedescription %]</span>
120
                            </li>
121
                        [% END %]
122
                    [% END %]
123
                </fieldset>
124
            </ol>
125
            <ol>
126
                <fieldset>
127
                    <legend>Independent library groups</legend>
128
                    [% FOREACH bc IN branch_categories %]
129
                        [% IF bc.categorytype == "independent_group" %]
130
                            <li>
131
                                <label for="[% bc.categorycode %]">[% bc.categoryname %]: </label>
132
                                [% IF ( bc.selected ) %]
133
                                    <input type="checkbox" id="[% bc.categorycode %]" name="[% bc.categorycode %]" checked="checked" />
134
                                [% ELSE %]
135
                                    <input type="checkbox" id="[% bc.categorycode %]" name="[% bc.categorycode %]" />
136
                                [% END %]
137
                                <span class="hint">[% bc.codedescription %]</span>
138
                            </li>
139
                        [% END %]
140
                    [% END %]
141
                <li><label>Note:</label><span class="hint">If independent library groups are enabled ( via the IndependentBranches system preference ), a library may access and alter records and patrons from libraries in any group that also library belongs to. A library may belong to multiple library groups.</span></li>
142
                </fieldset>
143
            </ol>
144
        </fieldset>
145
    [% END %]
146
117
	<fieldset class="rows">
147
	<fieldset class="rows">
118
	<ol>
148
	<ol>
119
        <li><label for="branchaddress1">Address line 1: </label><input type="text" name="branchaddress1" id="branchaddress1" size="60" value="[% branchaddress1 |html %]" /></li>
149
        <li><label for="branchaddress1">Address line 1: </label><input type="text" name="branchaddress1" id="branchaddress1" size="60" value="[% branchaddress1 |html %]" /></li>
Lines 249-338 tinyMCE.init({ Link Here
249
	[% ELSE %]
279
	[% ELSE %]
250
	<div class="dialog message">There are no libraries defined. <a href="/cgi-bin/koha/admin/branches.pl?op=add">Start defining libraries</a>.</div>
280
	<div class="dialog message">There are no libraries defined. <a href="/cgi-bin/koha/admin/branches.pl?op=add">Start defining libraries</a>.</div>
251
	[% END %]
281
	[% END %]
252
    
282
253
   [% IF ( branchcategories ) %]
283
    <h3>Search domain groups</h3>
254
   [% FOREACH branchcategorie IN branchcategories %]
284
    [% IF branch_categories.searchdomain %]
255
    <h3>Group(s):  [% IF ( branchcategorie.properties ) %]Properties[% ELSE %][% IF ( branchcategorie.searchdomain ) %]Search domain[% END %][% END %]</h3>
285
        <table>
256
    [% IF ( branchcategorie.catloop ) %]
286
            <thead>
257
      <table>
287
                <tr>
258
        <thead>
288
                    <th>Name</th>
259
          <tr>
289
                    <th>Code</th>
260
            <th>Name</th>
290
                    <th>Description</th>
261
            <th>Code</th>
291
                    <th>&nbsp;</th>
262
            <th>Description</th>
292
                    <th>&nbsp;</th>
263
            <th>&nbsp;</th>
293
                  </tr>
264
            <th>&nbsp;</th>
294
            </thead>
265
          </tr>
295
            <tbody>
266
        </thead>
296
                [% FOREACH bc IN branch_categories.searchdomain %]
267
        <tbody>
297
                    <tr>
268
          [% FOREACH catloo IN branchcategorie.catloop %]
298
                      <td>[% bc.value.categoryname %]</td>
269
            <tr>
299
                      <td>[% bc.key %]</td>
270
              <td>[% catloo.categoryname %]</td>
300
                      <td>[% bc.value.codedescription %]</td>
271
              <td>[% catloo.categorycode %]</td>
301
                      <td>
272
              <td>[% catloo.codedescription %]</td>
302
                        <a href="?op=editcategory&amp;categorycode=[% bc.key |url %]">Edit</a>
273
              <td>
303
                      </td>
274
                <a href="[% catloo.action %]?op=editcategory&amp;categorycode=[% catloo.categorycode |url %]">Edit</a>
304
                      <td>
275
              </td>
305
                        <a href="?op=delete_category&amp;categorycode=[% bc.key |url %]">Delete</a>
276
              <td>
306
                      </td>
277
                <a href="[% catloo.action %]?op=delete_category&amp;categorycode=[% catloo.categorycode |url %]">Delete</a>
307
                    </tr>
278
              </td>
308
                [% END %]
279
            </tr>
309
            </tbody>
280
          [% END %]
310
        </table>
281
        </tbody>
311
    [% ELSE %]
282
      </table>
312
        No search domain groups defined.
313
    [% END %]
314
    <a href="/cgi-bin/koha/admin/branches.pl?op=editcategory">Add a new group</a>.
315
316
    <h3>Independent library groups:</h3>
317
    [% IF branch_categories.independent_group %]
318
        <table>
319
            <thead>
320
                <tr>
321
                    <th>Name</th>
322
                    <th>Code</th>
323
                    <th>Description</th>
324
                    <th>&nbsp;</th>
325
                    <th>&nbsp;</th>
326
                  </tr>
327
            </thead>
328
            <tbody>
329
                [% FOREACH bc IN branch_categories.independent_group %]
330
                    <tr>
331
                      <td>[% bc.value.categoryname %]</td>
332
                      <td>[% bc.key %]</td>
333
                      <td>[% bc.value.codedescription %]</td>
334
                      <td>
335
                        <a href="?op=editcategory&amp;categorycode=[% bc.key |url %]">Edit</a>
336
                      </td>
337
                      <td>
338
                        <a href="?op=delete_category&amp;categorycode=[% bc.key |url %]">Delete</a>
339
                      </td>
340
                    </tr>
341
                [% END %]
342
            </tbody>
343
        </table>
283
    [% ELSE %]
344
    [% ELSE %]
284
      No [% IF ( branchcategorie.properties ) %]properties[% ELSIF ( branchcategorie.searchdomain ) %]search domain[% END %] defined. <a href="/cgi-bin/koha/admin/branches.pl?op=editcategory">Add a new group</a>.
345
        No independent library groups defined.
285
    [% END %]
346
    [% END %]
286
  [% END %]
347
    <a href="/cgi-bin/koha/admin/branches.pl?op=editcategory">Add a new group</a>.
287
  [% ELSE %]
288
    <p>No groups defined.</p>
289
  [% END %] <!-- NAME="branchcategories" -->
290
[% END %]
348
[% END %]
291
349
292
[% IF ( editcategory ) %]
350
[% IF ( editcategory ) %]
293
    <h3>[% IF ( categorycode ) %]Edit group [% categorycode %][% ELSE %]Add group[% END %]</h3>
351
    <h3>[% IF ( category ) %]Edit group [% category.categorycode %][% ELSE %]Add group[% END %]</h3>
294
    <form action="[% action %]" name="Aform" method="post">
352
    <form action="[% action %]" name="Aform" method="post">
295
    <input type="hidden" name="op" value="addcategory_validate" />
353
    <input type="hidden" name="op" value="addcategory_validate" />
296
	[% IF ( categorycode ) %]
354
    [% IF ( category.categorycode ) %]
297
	<input type="hidden" name="add" value="0">
355
        <input type="hidden" name="add" value="0">
298
	[% ELSE %]
356
    [% ELSE %]
299
	<input type="hidden" name="add" value="1">
357
        <input type="hidden" name="add" value="1">
300
	[% END %]
358
    [% END %]
301
    <fieldset class="rows">
359
    <fieldset class="rows">
302
        
360
        
303
        <ol><li>
361
        <ol><li>
304
                [% IF ( categorycode ) %]
362
                [% IF ( category.categorycode ) %]
305
				<span class="label">Category code: </span>
363
				<span class="label">Category code: </span>
306
                    <input type="hidden" name="categorycode" id="categorycode" value="[% categorycode |html %]" />
364
                    <input type="hidden" name="categorycode" id="categorycode" value="[% category.categorycode | html %]" />
307
                    [% categorycode %]
365
                    [% category.categorycode %]
308
                [% ELSE %]
366
                [% ELSE %]
309
                <label for="categorycode">Category code:</label>
367
                    <label for="categorycode">Category code:</label>
310
                    <input type="text" name="categorycode" id="categorycode" size="10" maxlength="10" value="[% categorycode |html %]" />
368
                    <input type="text" name="categorycode" id="categorycode" size="10" maxlength="10" value="[% categorycode | html %]" />
311
                [% END %]
369
                [% END %]
312
            </li>
370
            </li>
313
        <li>
371
        <li>
314
            <label for="categoryname">Name: </label>
372
            <label for="categoryname">Name: </label>
315
            <input type="text" name="categoryname" id="categoryname" size="32" maxlength="32" value="[% categoryname |html %]" />
373
            <input type="text" name="categoryname" id="categoryname" size="32" maxlength="32" value="[% category.categoryname | html %]" />
316
        </li>
374
        </li>
317
        <li>
375
        <li>
318
            <label for="codedescription">Description: </label>
376
            <label for="codedescription">Description: </label>
319
            <input type="text" name="codedescription" id="codedescription" size="70" value="[% codedescription |html %]" />
377
            <input type="text" name="codedescription" id="codedescription" size="70" value="[% category.codedescription | html %]" />
320
        </li>
378
        </li>
321
		<li>
379
		<li>
322
        <label for="categorytype">Category type: </label>
380
        <label for="categorytype">Category type: </label>
323
            <select id="categorytype" name="categorytype">
381
            <select id="categorytype" name="categorytype">
324
            [% FOREACH categorytyp IN categorytype %]
382
                [% IF ( category.categorytype == 'searchdomain' ) %]
325
                [% IF ( categorytyp.selected ) %]
383
                    <option value="searchdomain" selected="selected">Search domain</option>
326
                    <option value="[% categorytyp.type %]" selected="selected">
327
                [% ELSE %]
384
                [% ELSE %]
328
                    <option value="[% categorytyp.type %]">
385
                    <option value="searchdomain">Search domain</option>
329
                [% END %] [% categorytyp.type %]</option>
386
                [% END %]
330
            [% END %]
387
388
                [% IF ( category.categorytype == 'independent_group' ) %]
389
                    <option value="independent_group" selected="selected">Independent group</option>
390
                [% ELSE %]
391
                    <option value="independent_group">Independent group</option>
392
                [% END %]
331
            </select>
393
            </select>
332
		</li>
394
		</li>
333
        <li>
395
        <li>
334
            <label for="show_in_pulldown">Show in search pulldown: </label>
396
            <label for="show_in_pulldown">Show in search pulldown: </label>
335
            [% IF ( show_in_pulldown ) %]
397
            [% IF ( category.show_in_pulldown ) %]
336
                <input type="checkbox" name="show_in_pulldown" id="show_in_pulldown" checked="checked"/>
398
                <input type="checkbox" name="show_in_pulldown" id="show_in_pulldown" checked="checked"/>
337
            [% ELSE %]
399
            [% ELSE %]
338
                <input type="checkbox" name="show_in_pulldown" id="show_in_pulldown" />
400
                <input type="checkbox" name="show_in_pulldown" id="show_in_pulldown" />
Lines 340-346 tinyMCE.init({ Link Here
340
        </li>
402
        </li>
341
		</ol>
403
		</ol>
342
    </fieldset>
404
    </fieldset>
343
	<fieldset class="action"><input type="submit" value="Update" /></fieldset>
405
  <fieldset class="action">
406
        [% IF category %]
407
            <input type="submit" value="Update group" />
408
        [% ELSE %]
409
            <input type="submit" value="Add group" />
410
        [% END %]
411
    </fieldset>
344
    </form>
412
    </form>
345
[% END %]
413
[% END %]
346
414
(-)a/members/deletemem.pl (-4 / +10 lines)
Lines 66-76 if ($bor->{category_type} eq "S") { Link Here
66
    }
66
    }
67
}
67
}
68
68
69
if (C4::Context->preference("IndependentBranches")) {
69
if ( C4::Context->preference("IndependentBranches") ) {
70
    my $userenv = C4::Context->userenv;
71
    if ( !C4::Context->IsSuperLibrarian() && $bor->{'branchcode'}){
70
    if ( !C4::Context->IsSuperLibrarian() && $bor->{'branchcode'}){
72
        unless ($userenv->{branch} eq $bor->{'branchcode'}){
71
        unless (
73
            print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_OTHERLIBRARY");
72
            GetIndependentGroupModificationRights(
73
                { for => $bor->{'branchcode'} }
74
            )
75
          )
76
        {
77
            print $input->redirect(
78
                "/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_OTHERLIBRARY"
79
            );
74
            exit;
80
            exit;
75
        }
81
        }
76
    }
82
    }
(-)a/members/member.pl (-1 / +1 lines)
Lines 57-63 $input->delete( Link Here
57
    'new_patron_list',    'borrowernumber',
57
    'new_patron_list',    'borrowernumber',
58
);
58
);
59
59
60
my $patron = $input->Vars;
60
my $patron = { $input->Vars };
61
foreach (keys %$patron){
61
foreach (keys %$patron){
62
	delete $$patron{$_} unless($$patron{$_});
62
	delete $$patron{$_} unless($$patron{$_});
63
}
63
}
(-)a/t/db_dependent/Branch.t (-6 / +71 lines)
Lines 21-27 use Modern::Perl; Link Here
21
use C4::Context;
21
use C4::Context;
22
use Data::Dumper;
22
use Data::Dumper;
23
23
24
use Test::More tests => 36;
24
use Test::More tests => 69;
25
25
26
use C4::Branch;
26
use C4::Branch;
27
27
Lines 172-185 my $cat1 = { Link Here
172
    categorycode     => 'CAT1',
172
    categorycode     => 'CAT1',
173
    categoryname     => 'catname1',
173
    categoryname     => 'catname1',
174
    codedescription  => 'catdesc1',
174
    codedescription  => 'catdesc1',
175
    categorytype     => 'cattype1',
175
    categorytype     => 'searchdomain',
176
    show_in_pulldown => 1
176
    show_in_pulldown => 1
177
};
177
};
178
my $cat2 = {
178
my $cat2 = {
179
    add              => 1,
179
    add              => 1,
180
    categorycode     => 'CAT2',
180
    categorycode     => 'CAT2',
181
    categoryname     => 'catname2',
181
    categoryname     => 'catname2',
182
    categorytype     => 'catype2',
182
    categorytype     => 'searchdomain',
183
    codedescription  => 'catdesc2',
183
    codedescription  => 'catdesc2',
184
    show_in_pulldown => 1
184
    show_in_pulldown => 1
185
};
185
};
Lines 188-194 my %new_category = ( Link Here
188
    categorycode     => 'LIBCATCODE',
188
    categorycode     => 'LIBCATCODE',
189
    categoryname     => 'library category name',
189
    categoryname     => 'library category name',
190
    codedescription  => 'library category code description',
190
    codedescription  => 'library category code description',
191
    categorytype     => 'searchdomain',
191
    categorytype     => 'independent_group',
192
    show_in_pulldown => 1,
192
    show_in_pulldown => 1,
193
);
193
);
194
194
Lines 335-341 is( CheckCategoryUnique('CAT_NO_EXISTS'), 1, 'CAT_NO_EXISTS doesnt exist' ); Link Here
335
335
336
#Test GetCategoryTypes
336
#Test GetCategoryTypes
337
my @category_types = GetCategoryTypes();
337
my @category_types = GetCategoryTypes();
338
is_deeply(\@category_types, [ 'searchdomain', 'properties' ], 'received expected library category types');
338
is_deeply(\@category_types, [ 'searchdomain', 'independent_groups' ], 'received expected library category types');
339
339
340
$categories = GetBranchCategories(undef, undef, 'LIBCATCODE');
340
$categories = GetBranchCategories(undef, undef, 'LIBCATCODE');
341
is_deeply($categories, [ {%$cat1}, {%$cat2},{ %new_category, selected => 1 } ], 'retrieve expected, eselected library category (bug 10515)');
341
is_deeply($categories, [ {%$cat1}, {%$cat2},{ %new_category, selected => 1 } ], 'retrieve expected, eselected library category (bug 10515)');
Lines 347-352 is_deeply($categories, [ {%$cat1}, {%$cat2},{ %new_category, selected => 1 } ], Link Here
347
my $loop = GetBranchesLoop;
347
my $loop = GetBranchesLoop;
348
is( scalar(@$loop), GetBranchesCount(), 'There is the right number of branches' );
348
is( scalar(@$loop), GetBranchesCount(), 'There is the right number of branches' );
349
349
350
# Test GetIndependentGroupModificationRights
351
my @branches_bra = GetIndependentGroupModificationRights({ branch => 'BRA' });
352
is_deeply( \@branches_bra, [ 'BRA' ], 'Library with no group only has rights for its own branch' );
353
354
my $string = GetIndependentGroupModificationRights({ branch => 'BRA', stringify => 1 });
355
ok( $string eq q{'BRA'}, "String returns correctly" );
356
357
ok( GetIndependentGroupModificationRights({ branch => 'BRA', for => 'BRA' }), 'Boolean test for BRA rights to BRA returns true' );
358
ok( !GetIndependentGroupModificationRights({ branch => 'BRA', for => 'BRB' }), 'Boolean test for BRA rights to BRB returns false' );
359
ok( !GetIndependentGroupModificationRights({ branch => 'BRA', for => 'BRC' }), 'Boolean test for BRA rights to BRC returns false' );
360
ok( GetIndependentGroupModificationRights({ branch => 'BRB', for => 'BRB' }), 'Boolean test for BRB rights to BRB returns true' );
361
ok( !GetIndependentGroupModificationRights({ branch => 'BRB', for => 'BRA' }), 'Boolean test for BRB rights to BRA returns false' );
362
ok( !GetIndependentGroupModificationRights({ branch => 'BRB', for => 'BRC' }), 'Boolean test for BRB rights to BRC returns false' );
363
ok( GetIndependentGroupModificationRights({ branch => 'BRC', for => 'BRC' }), 'Boolean test for BRC rights to BRC returns true' );
364
ok( !GetIndependentGroupModificationRights({ branch => 'BRC', for => 'BRA'}), 'Boolean test for BRC rights to BRA returns false' );
365
ok( !GetIndependentGroupModificationRights({ branch => 'BRC', for => 'BRB'}), 'Boolean test for BRC rights to BRB returns false' );
366
367
ModBranch({
368
    branchcode     => 'BRA',
369
    branchname     => 'BranchA',
370
    LIBCATCODE     => 1,
371
});
372
ModBranch({
373
    branchcode     => 'BRB',
374
    branchname     => 'BranchB',
375
    LIBCATCODE     => 1,
376
});
377
378
@branches_bra = GetIndependentGroupModificationRights({ branch => 'BRA' });
379
is_deeply( \@branches_bra, [ 'BRA', 'BRB' ], 'Libraries in LIBCATCODE returned correctly' );
380
381
$string = GetIndependentGroupModificationRights({ branch => 'BRA', stringify => 1 });
382
ok( $string eq q{'BRA','BRB'}, "String returns correctly" );
383
384
ok( GetIndependentGroupModificationRights({ branch => 'BRA', for => 'BRA' }), 'Boolean test for BRA rights to BRA returns true' );
385
ok( GetIndependentGroupModificationRights({ branch => 'BRA', for => 'BRB'}), 'Boolean test for BRA rights to BRB returns true' );
386
ok( !GetIndependentGroupModificationRights({ branch => 'BRA', for => 'BRC'}), 'Boolean test for BRA rights to BRC returns false' );
387
ok( GetIndependentGroupModificationRights({ branch => 'BRB', for => 'BRB' }), 'Boolean test for BRB rights to BRB returns true' );
388
ok( GetIndependentGroupModificationRights({ branch => 'BRB', for => 'BRA'}), 'Boolean test for BRB rights to BRA returns true' );
389
ok( !GetIndependentGroupModificationRights({ branch => 'BRB', for => 'BRC'}), 'Boolean test for BRB rights to BRC returns false' );
390
ok( GetIndependentGroupModificationRights({ branch => 'BRC', for => 'BRC' }), 'Boolean test for BRC rights to BRC returns true' );
391
ok( !GetIndependentGroupModificationRights({ branch => 'BRC', for => 'BRA'}), 'Boolean test for BRC rights to BRA returns false' );
392
ok( !GetIndependentGroupModificationRights({ branch => 'BRC', for => 'BRB'}), 'Boolean test for BRC rights to BRB returns false' );
393
394
ModBranch({
395
    branchcode     => 'BRC',
396
    branchname     => 'BranchC',
397
    LIBCATCODE     => 1,
398
});
399
400
@branches_bra = GetIndependentGroupModificationRights({ branch => 'BRA' });
401
is_deeply( \@branches_bra, [ 'BRA', 'BRB', 'BRC' ], 'Library with no group only has rights for its own branch' );
402
403
ok( GetIndependentGroupModificationRights({ branch => 'BRA', for => 'BRA' }), 'Boolean test for BRA rights to BRA returns true' );
404
ok( GetIndependentGroupModificationRights({ branch => 'BRA', for => 'BRB'}), 'Boolean test for BRA rights to BRB returns true' );
405
ok( GetIndependentGroupModificationRights({ branch => 'BRA', for => 'BRC'}), 'Boolean test for BRA rights to BRC returns true' );
406
ok( GetIndependentGroupModificationRights({ branch => 'BRB', for => 'BRB' }), 'Boolean test for BRB rights to BRB returns true' );
407
ok( GetIndependentGroupModificationRights({ branch => 'BRB', for => 'BRA'}), 'Boolean test for BRB rights to BRA returns true' );
408
ok( GetIndependentGroupModificationRights({ branch => 'BRB', for => 'BRC'}), 'Boolean test for BRB rights to BRC returns true' );
409
ok( GetIndependentGroupModificationRights({ branch => 'BRC', for => 'BRC' }), 'Boolean test for BRC rights to BRC returns true' );
410
ok( GetIndependentGroupModificationRights({ branch => 'BRC', for => 'BRA'}), 'Boolean test for BRC rights to BRA returns true' );
411
ok( GetIndependentGroupModificationRights({ branch => 'BRC', for => 'BRA'}), 'Boolean test for BRC rights to BRB returns true' );
412
413
$string = GetIndependentGroupModificationRights({ branch => 'BRA', stringify => 1 });
414
ok( $string eq q{'BRA','BRB','BRC'}, "String returns correctly" );
415
350
# End transaction
416
# End transaction
351
$dbh->rollback;
417
$dbh->rollback;
352
418
353
- 

Return to bug 10276