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

(-)a/C4/Acquisition.pm (-10 / +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 1882-1890 sub GetParcel { Link Here
1882
    my @query_params = ( $supplierid, $code, $datereceived );
1883
    my @query_params = ( $supplierid, $code, $datereceived );
1883
    if ( C4::Context->preference("IndependentBranches") ) {
1884
    if ( C4::Context->preference("IndependentBranches") ) {
1884
        unless ( C4::Context->IsSuperLibrarian() ) {
1885
        unless ( C4::Context->IsSuperLibrarian() ) {
1885
            $strsth .= " and (borrowers.branchcode = ?
1886
            my $branches =
1886
                        or borrowers.branchcode  = '')";
1887
              GetIndependentGroupModificationRights( { stringify => 1 } );
1887
            push @query_params, C4::Context->userenv->{branch};
1888
            $strsth .= " AND ( borrowers.branchcode IN ( $branches ) OR borrowers.branchcode  = '')";
1888
        }
1889
        }
1889
    }
1890
    }
1890
    $strsth .= " ORDER BY aqbasket.basketno";
1891
    $strsth .= " ORDER BY aqbasket.basketno";
Lines 2095-2102 sub GetLateOrders { Link Here
2095
    }
2096
    }
2096
    if (C4::Context->preference("IndependentBranches")
2097
    if (C4::Context->preference("IndependentBranches")
2097
            && !C4::Context->IsSuperLibrarian() ) {
2098
            && !C4::Context->IsSuperLibrarian() ) {
2098
        $from .= ' AND borrowers.branchcode LIKE ? ';
2099
        my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
2099
        push @query_params, C4::Context->userenv->{branch};
2100
        $from .= qq{ AND borrowers.branchcode IN ( $branches ) };
2100
    }
2101
    }
2101
    $from .= " AND orderstatus <> 'cancelled' ";
2102
    $from .= " AND orderstatus <> 'cancelled' ";
2102
    my $query = "$select $from $having\nORDER BY latesince, basketno, borrowers.branchcode, supplier";
2103
    my $query = "$select $from $having\nORDER BY latesince, basketno, borrowers.branchcode, supplier";
Lines 2307-2317 sub GetHistory { Link Here
2307
        push @query_params, "%$basketgroupname%";
2308
        push @query_params, "%$basketgroupname%";
2308
    }
2309
    }
2309
2310
2310
    if ( C4::Context->preference("IndependentBranches") ) {
2311
    if ( C4::Context->preference("IndependentBranches")
2311
        unless ( C4::Context->IsSuperLibrarian() ) {
2312
        && !C4::Context->IsSuperLibrarian() )
2312
            $query .= " AND (borrowers.branchcode = ? OR borrowers.branchcode ='' ) ";
2313
    {
2313
            push @query_params, C4::Context->userenv->{branch};
2314
        my $branches =
2314
        }
2315
          GetIndependentGroupModificationRights( { stringify => 1 } );
2316
        $query .= qq{ AND ( borrowers.branchcode = ? OR borrowers.branchcode IN ( $branches ) ) };
2315
    }
2317
    }
2316
    $query .= " ORDER BY id";
2318
    $query .= " ORDER BY id";
2317
    my $sth = $dbh->prepare($query);
2319
    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 895-908 sub CanBookBeIssued { Link Here
895
        $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
895
        $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
896
    }
896
    }
897
    if ( C4::Context->preference("IndependentBranches") ) {
897
    if ( C4::Context->preference("IndependentBranches") ) {
898
        my $userenv = C4::Context->userenv;
899
        unless ( C4::Context->IsSuperLibrarian() ) {
898
        unless ( C4::Context->IsSuperLibrarian() ) {
900
            if ( $item->{C4::Context->preference("HomeOrHoldingBranch")} ne $userenv->{branch} ){
899
            unless (
900
                GetIndependentGroupModificationRights(
901
                    {
902
                        for => $item->{ C4::Context->preference(
903
                                "HomeOrHoldingBranch") }
904
                    }
905
                )
906
              )
907
            {
901
                $issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
908
                $issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
902
                $issuingimpossible{'itemhomebranch'} = $item->{C4::Context->preference("HomeOrHoldingBranch")};
909
                $issuingimpossible{'itemhomebranch'} =
910
                  $item->{ C4::Context->preference("HomeOrHoldingBranch") };
903
            }
911
            }
904
            $needsconfirmation{BORRNOTSAMEBRANCH} = GetBranchName( $borrower->{'branchcode'} )
912
905
              if ( $borrower->{'branchcode'} ne $userenv->{branch} );
913
            $needsconfirmation{BORRNOTSAMEBRANCH} =
914
              GetBranchName( $borrower->{'branchcode'} )
915
              if (
916
                $borrower->{'branchcode'} ne C4::Context->userenv->{branch} );
906
        }
917
        }
907
    }
918
    }
908
919
(-)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 2748-2755 sub PrepareItemrecordDisplay { Link Here
2748
                    if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
2759
                    if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
2749
                        if (   ( C4::Context->preference("IndependentBranches") )
2760
                        if (   ( C4::Context->preference("IndependentBranches") )
2750
                            && !C4::Context->IsSuperLibrarian() ) {
2761
                            && !C4::Context->IsSuperLibrarian() ) {
2751
                            my $sth = $dbh->prepare( "SELECT branchcode,branchname FROM branches WHERE branchcode = ? ORDER BY branchname" );
2762
                            my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
2752
                            $sth->execute( C4::Context->userenv->{branch} );
2763
                            my $sth = $dbh->prepare( "SELECT branchcode,branchname FROM branches WHERE branchcode IN ( $branches ) ORDER BY branchname" );
2764
                            $sth->execute();
2753
                            push @authorised_values, ""
2765
                            push @authorised_values, ""
2754
                              unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2766
                              unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2755
                            while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
2767
                            while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
(-)a/C4/Letters.pm (+1 lines)
Lines 126-131 our %letter; Link Here
126
sub getletter {
126
sub getletter {
127
    my ( $module, $code, $branchcode ) = @_;
127
    my ( $module, $code, $branchcode ) = @_;
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 257-281 sub Search { Link Here
257
    # $showallbranches was not used at the time SearchMember() was mainstreamed into Search().
258
    # $showallbranches was not used at the time SearchMember() was mainstreamed into Search().
258
    # Mentioning for the reference
259
    # Mentioning for the reference
259
260
260
    if ( C4::Context->preference("IndependentBranches") ) { # && !$showallbranches){
261
    if ( C4::Context->preference("IndependentBranches") ) {
261
        if ( my $userenv = C4::Context->userenv ) {
262
        unless ( C4::Context->IsSuperLibrarian() ) {
262
            my $branch =  $userenv->{'branch'};
263
            $filter = clone($filter);    # Modify a copy only
263
            if ( !C4::Context->IsSuperLibrarian() && $branch ){
264
            my @branches = GetIndependentGroupModificationRights();
264
                if (my $fr = ref $filter) {
265
            if ( my $fr = ref $filter ) {
265
                    if ( $fr eq "HASH" ) {
266
                if ( $fr eq "HASH" ) {
266
                        $filter->{branchcode} = $branch;
267
                    $filter->{branchcode} = \@branches;
267
                    }
268
                    else {
269
                        foreach (@$filter) {
270
                            $_ = { '' => $_ } unless ref $_;
271
                            $_->{branchcode} = $branch;
272
                        }
273
                    }
274
                }
268
                }
275
                else {
269
                else {
276
                    $filter = { '' => $filter, branchcode => $branch };
270
                    foreach (@$filter) {
271
                        $_ = { '' => $_ } unless ref $_;
272
                        $_->{branchcode} = \@branches;
273
                    }
277
                }
274
                }
278
            }      
275
            }
276
            else {
277
                $filter = { '' => $filter, branchcode => \@branches };
278
            }
279
        }
279
        }
280
    }
280
    }
281
281
Lines 1313-1318 sub checkuniquemember { Link Here
1313
            ($dateofbirth) ?
1313
            ($dateofbirth) ?
1314
            "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?  and dateofbirth=?" :
1314
            "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?  and dateofbirth=?" :
1315
            "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?";
1315
            "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?";
1316
1317
    if ( C4::Context->preference('IndependentBranches') ) {
1318
        my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
1319
        $request .= " AND branchcode IN ( $branches )";
1320
    }
1321
1316
    my $sth = $dbh->prepare($request);
1322
    my $sth = $dbh->prepare($request);
1317
    if ($collectivity) {
1323
    if ($collectivity) {
1318
        $sth->execute( uc($surname) );
1324
        $sth->execute( uc($surname) );
Lines 1976-1988 sub GetBorrowersToExpunge { Link Here
1976
    my $filterdate     = $params->{'not_borrowered_since'};
1982
    my $filterdate     = $params->{'not_borrowered_since'};
1977
    my $filterexpiry   = $params->{'expired_before'};
1983
    my $filterexpiry   = $params->{'expired_before'};
1978
    my $filtercategory = $params->{'category_code'};
1984
    my $filtercategory = $params->{'category_code'};
1979
    my $filterbranch   = $params->{'branchcode'} ||
1985
    my $filterbranch   = $params->{'branchcode'};
1980
                        ((C4::Context->preference('IndependentBranches')
1986
    my @filterbranches =
1981
                             && C4::Context->userenv 
1987
      (      C4::Context->preference('IndependentBranches')
1982
                             && !C4::Context->IsSuperLibrarian()
1988
          && C4::Context->userenv
1983
                             && C4::Context->userenv->{branch})
1989
          && !C4::Context->IsSuperLibrarian()
1984
                         ? C4::Context->userenv->{branch}
1990
          && C4::Context->userenv->{branch} )
1985
                         : "");  
1991
      ? GetIndependentGroupModificationRights()
1992
      : ($filterbranch);
1986
1993
1987
    my $dbh   = C4::Context->dbh;
1994
    my $dbh   = C4::Context->dbh;
1988
    my $query = "
1995
    my $query = "
Lines 1997-2005 sub GetBorrowersToExpunge { Link Here
1997
        AND borrowernumber NOT IN (SELECT guarantorid FROM borrowers WHERE guarantorid IS NOT NULL AND guarantorid <> 0)
2004
        AND borrowernumber NOT IN (SELECT guarantorid FROM borrowers WHERE guarantorid IS NOT NULL AND guarantorid <> 0)
1998
   ";
2005
   ";
1999
    my @query_params;
2006
    my @query_params;
2000
    if ( $filterbranch && $filterbranch ne "" ) {
2007
    if ( @filterbranches ) {
2001
        $query.= " AND borrowers.branchcode = ? ";
2008
        my $placeholders = join( ',', ('?') x @filterbranches );
2002
        push( @query_params, $filterbranch );
2009
        $query.= " AND borrowers.branchcode IN ( $placeholders )";
2010
        push( @query_params, @filterbranches );
2003
    }
2011
    }
2004
    if ( $filterexpiry ) {
2012
    if ( $filterexpiry ) {
2005
        $query .= " AND dateexpiry < ? ";
2013
        $query .= " AND dateexpiry < ? ";
Lines 2042-2054 I<$result> is a ref to an array which all elements are a hasref. Link Here
2042
=cut
2050
=cut
2043
2051
2044
sub GetBorrowersWhoHaveNeverBorrowed {
2052
sub GetBorrowersWhoHaveNeverBorrowed {
2045
    my $filterbranch = shift || 
2053
    my $filterbranch = shift;
2046
                        ((C4::Context->preference('IndependentBranches')
2054
2047
                             && C4::Context->userenv 
2055
    my @filterbranches =
2048
                             && !C4::Context->IsSuperLibrarian()
2056
      (      C4::Context->preference('IndependentBranches')
2049
                             && C4::Context->userenv->{branch})
2057
          && C4::Context->userenv
2050
                         ? C4::Context->userenv->{branch}
2058
          && !C4::Context->IsSuperLibrarian()
2051
                         : "");  
2059
          && C4::Context->userenv->{branch} )
2060
      ? GetIndependentGroupModificationRights()
2061
      : ($filterbranch);
2062
2052
    my $dbh   = C4::Context->dbh;
2063
    my $dbh   = C4::Context->dbh;
2053
    my $query = "
2064
    my $query = "
2054
        SELECT borrowers.borrowernumber,max(timestamp) as latestissue
2065
        SELECT borrowers.borrowernumber,max(timestamp) as latestissue
Lines 2056-2065 sub GetBorrowersWhoHaveNeverBorrowed { Link Here
2056
          LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
2067
          LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
2057
        WHERE issues.borrowernumber IS NULL
2068
        WHERE issues.borrowernumber IS NULL
2058
   ";
2069
   ";
2070
2059
    my @query_params;
2071
    my @query_params;
2060
    if ($filterbranch && $filterbranch ne ""){ 
2072
    if (@filterbranches) {
2061
        $query.=" AND borrowers.branchcode= ?";
2073
        my $placeholders = join( ',', ('?') x @filterbranches );
2062
        push @query_params,$filterbranch;
2074
        $query .= " AND borrowers.branchcode IN ( $placeholders ) ";
2075
        push( @query_params, @filterbranches );
2063
    }
2076
    }
2064
    warn $query if $debug;
2077
    warn $query if $debug;
2065
  
2078
  
Lines 2092-2116 This hashref is containt the number of time this borrowers has borrowed before I Link Here
2092
sub GetBorrowersWithIssuesHistoryOlderThan {
2105
sub GetBorrowersWithIssuesHistoryOlderThan {
2093
    my $dbh  = C4::Context->dbh;
2106
    my $dbh  = C4::Context->dbh;
2094
    my $date = shift ||POSIX::strftime("%Y-%m-%d",localtime());
2107
    my $date = shift ||POSIX::strftime("%Y-%m-%d",localtime());
2095
    my $filterbranch = shift || 
2108
    my $filterbranch = shift;
2096
                        ((C4::Context->preference('IndependentBranches')
2109
2097
                             && C4::Context->userenv 
2110
    my @filterbranches =
2098
                             && !C4::Context->IsSuperLibrarian()
2111
      (      C4::Context->preference('IndependentBranches')
2099
                             && C4::Context->userenv->{branch})
2112
          && C4::Context->userenv
2100
                         ? C4::Context->userenv->{branch}
2113
          && !C4::Context->IsSuperLibrarian()
2101
                         : "");  
2114
          && C4::Context->userenv->{branch} )
2115
      ? GetIndependentGroupModificationRights()
2116
      : ($filterbranch);
2117
2102
    my $query = "
2118
    my $query = "
2103
       SELECT count(borrowernumber) as n,borrowernumber
2119
       SELECT count(borrowernumber) as n,borrowernumber
2104
       FROM old_issues
2120
       FROM old_issues
2105
       WHERE returndate < ?
2121
       WHERE returndate < ?
2106
         AND borrowernumber IS NOT NULL 
2122
         AND borrowernumber IS NOT NULL 
2107
    "; 
2123
    "; 
2124
2108
    my @query_params;
2125
    my @query_params;
2109
    push @query_params, $date;
2126
    push( @query_params, $date );
2110
    if ($filterbranch){
2127
2111
        $query.="   AND branchcode = ?";
2128
    if (@filterbranches) {
2112
        push @query_params, $filterbranch;
2129
        my $placeholders = join( ',', ('?') x @filterbranches );
2113
    }    
2130
        $query .= " AND branchcode IN ( $placeholders ) ";
2131
        push( @query_params, @filterbranches );
2132
    }
2133
2114
    $query.=" GROUP BY borrowernumber ";
2134
    $query.=" GROUP BY borrowernumber ";
2115
    warn $query if $debug;
2135
    warn $query if $debug;
2116
    my $sth = $dbh->prepare($query);
2136
    my $sth = $dbh->prepare($query);
(-)a/C4/Serials.pm (-17 / +99 lines)
Lines 30-35 use C4::Log; # logaction Link Here
30
use C4::Debug;
30
use C4::Debug;
31
use C4::Serials::Frequency;
31
use C4::Serials::Frequency;
32
use C4::Serials::Numberpattern;
32
use C4::Serials::Numberpattern;
33
use C4::Branch qw(GetIndependentGroupModificationRights);
33
34
34
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
35
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
35
36
Lines 230-236 sub GetSerialInformation { Link Here
230
    my ($serialid) = @_;
231
    my ($serialid) = @_;
231
    my $dbh        = C4::Context->dbh;
232
    my $dbh        = C4::Context->dbh;
232
    my $query      = qq|
233
    my $query      = qq|
233
        SELECT serial.*, serial.notes as sernotes, serial.status as serstatus,subscription.*,subscription.subscriptionid as subsid
234
        SELECT serial.*,
235
               serial.notes as sernotes,
236
               serial.status as serstatus,
237
               subscription.*,
238
               subscription.subscriptionid as subsid
239
    |;
240
    if (   C4::Context->preference('IndependentBranches')
241
        && C4::Context->userenv
242
        && C4::Context->userenv->{'flags'} % 2 != 1
243
        && C4::Context->userenv->{'branch'} ) {
244
        my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
245
        $query .= qq|
246
            , ( ( subscription.branchcode NOT IN ( $branches ) ) AND subscription.branchcode <> '' AND subscription.branchcode IS NOT NULL ) AS cannotedit
247
        |;
248
    }
249
    $query .= qq|
234
        FROM   serial LEFT JOIN subscription ON subscription.subscriptionid=serial.subscriptionid
250
        FROM   serial LEFT JOIN subscription ON subscription.subscriptionid=serial.subscriptionid
235
        WHERE  serialid = ?
251
        WHERE  serialid = ?
236
    |;
252
    |;
Lines 329-346 subscription, subscriptionhistory, aqbooksellers.name, biblio.title Link Here
329
sub GetSubscription {
345
sub GetSubscription {
330
    my ($subscriptionid) = @_;
346
    my ($subscriptionid) = @_;
331
    my $dbh              = C4::Context->dbh;
347
    my $dbh              = C4::Context->dbh;
332
    my $query            = qq(
348
349
    my $query = qq|
333
        SELECT  subscription.*,
350
        SELECT  subscription.*,
334
                subscriptionhistory.*,
351
                subscriptionhistory.*,
335
                aqbooksellers.name AS aqbooksellername,
352
                aqbooksellers.name AS aqbooksellername,
336
                biblio.title AS bibliotitle,
353
                biblio.title AS bibliotitle,
337
                subscription.biblionumber as bibnum
354
                subscription.biblionumber as bibnum
355
    |;
356
357
    if (   C4::Context->preference('IndependentBranches')
358
        && C4::Context->userenv
359
        && C4::Context->userenv->{'flags'} % 2 != 1
360
        && C4::Context->userenv->{'branch'} )
361
    {
362
        my $branches =
363
          GetIndependentGroupModificationRights( { stringify => 1 } );
364
365
        $query .= qq|
366
            , ( ( subscription.branchcode NOT IN ( $branches ) ) AND subscription.branchcode <> '' AND subscription.branchcode IS NOT NULL ) AS cannotedit
367
        |;
368
    }
369
370
    $query .= qq|
338
       FROM subscription
371
       FROM subscription
339
       LEFT JOIN subscriptionhistory ON subscription.subscriptionid=subscriptionhistory.subscriptionid
372
       LEFT JOIN subscriptionhistory ON subscription.subscriptionid=subscriptionhistory.subscriptionid
340
       LEFT JOIN aqbooksellers ON subscription.aqbooksellerid=aqbooksellers.id
373
       LEFT JOIN aqbooksellers ON subscription.aqbooksellerid=aqbooksellers.id
341
       LEFT JOIN biblio ON biblio.biblionumber=subscription.biblionumber
374
       LEFT JOIN biblio ON biblio.biblionumber=subscription.biblionumber
342
       WHERE subscription.subscriptionid = ?
375
       WHERE subscription.subscriptionid = ?
343
    );
376
    |;
344
377
345
    $debug and warn "query : $query\nsubsid :$subscriptionid";
378
    $debug and warn "query : $query\nsubsid :$subscriptionid";
346
    my $sth = $dbh->prepare($query);
379
    my $sth = $dbh->prepare($query);
Lines 363-370 sub GetFullSubscription { Link Here
363
    return unless ($subscriptionid);
396
    return unless ($subscriptionid);
364
397
365
    my $dbh              = C4::Context->dbh;
398
    my $dbh              = C4::Context->dbh;
366
    my $query            = qq|
399
367
  SELECT    serial.serialid,
400
    my $query = qq|
401
        SELECT
402
            serial.serialid,
368
            serial.serialseq,
403
            serial.serialseq,
369
            serial.planneddate, 
404
            serial.planneddate, 
370
            serial.publisheddate, 
405
            serial.publisheddate, 
Lines 375-380 sub GetFullSubscription { Link Here
375
            biblio.title as bibliotitle,
410
            biblio.title as bibliotitle,
376
            subscription.branchcode AS branchcode,
411
            subscription.branchcode AS branchcode,
377
            subscription.subscriptionid AS subscriptionid
412
            subscription.subscriptionid AS subscriptionid
413
    |;
414
415
    if (   C4::Context->preference('IndependentBranches')
416
        && C4::Context->userenv
417
        && C4::Context->userenv->{'flags'} % 2 != 1
418
        && C4::Context->userenv->{'branch'} )
419
    {
420
        my $branches =
421
          GetIndependentGroupModificationRights( { stringify => 1 } );
422
423
        $query .= qq|
424
            , ( ( subscription.branchcode NOT IN ( $branches ) ) AND subscription.branchcode <> '' AND subscription.branchcode IS NOT NULL ) AS cannotedit
425
        |;
426
    }
427
428
    $query .= qq|
378
  FROM      serial 
429
  FROM      serial 
379
  LEFT JOIN subscription ON 
430
  LEFT JOIN subscription ON 
380
          (serial.subscriptionid=subscription.subscriptionid )
431
          (serial.subscriptionid=subscription.subscriptionid )
Lines 495-500 sub GetSubscriptionsFromBiblionumber { Link Here
495
        $subs->{ "periodicity" . $subs->{periodicity} }     = 1;
546
        $subs->{ "periodicity" . $subs->{periodicity} }     = 1;
496
        $subs->{ "numberpattern" . $subs->{numberpattern} } = 1;
547
        $subs->{ "numberpattern" . $subs->{numberpattern} } = 1;
497
        $subs->{ "status" . $subs->{'status'} }             = 1;
548
        $subs->{ "status" . $subs->{'status'} }             = 1;
549
        $subs->{'cannotedit'} = (
550
                 C4::Context->preference('IndependentBranches')
551
              && C4::Context->userenv
552
              && !C4::Context->IsSuperLibrarian()
553
              && C4::Context->userenv->{branch}
554
              && $subs->{branchcode}
555
              && GetIndependentGroupModificationRights(
556
                { for => $subs->{branchcode} }
557
              )
558
        );
498
559
499
        if ( $subs->{enddate} eq '0000-00-00' ) {
560
        if ( $subs->{enddate} eq '0000-00-00' ) {
500
            $subs->{enddate} = '';
561
            $subs->{enddate} = '';
Lines 519-526 sub GetSubscriptionsFromBiblionumber { Link Here
519
sub GetFullSubscriptionsFromBiblionumber {
580
sub GetFullSubscriptionsFromBiblionumber {
520
    my ($biblionumber) = @_;
581
    my ($biblionumber) = @_;
521
    my $dbh            = C4::Context->dbh;
582
    my $dbh            = C4::Context->dbh;
522
    my $query          = qq|
583
523
  SELECT    serial.serialid,
584
    my $query = qq|
585
        SELECT
586
            serial.serialid,
524
            serial.serialseq,
587
            serial.serialseq,
525
            serial.planneddate, 
588
            serial.planneddate, 
526
            serial.publisheddate, 
589
            serial.publisheddate, 
Lines 530-535 sub GetFullSubscriptionsFromBiblionumber { Link Here
530
            biblio.title as bibliotitle,
593
            biblio.title as bibliotitle,
531
            subscription.branchcode AS branchcode,
594
            subscription.branchcode AS branchcode,
532
            subscription.subscriptionid AS subscriptionid
595
            subscription.subscriptionid AS subscriptionid
596
    |;
597
598
    if (   C4::Context->preference('IndependentBranches')
599
        && C4::Context->userenv
600
        && C4::Context->userenv->{'flags'} != 1
601
        && C4::Context->userenv->{'branch'} )
602
    {
603
        my $branches =
604
          GetIndependentGroupModificationRights( { stringify => 1 } );
605
606
        $query .= qq|
607
            , ( ( subscription.branchcode NOT IN ( $branches ) ) AND subscription.branchcode <> '' AND subscription.branchcode IS NOT NULL ) AS cannotedit
608
        |;
609
    }
610
611
    $query .= qq|
533
  FROM      serial 
612
  FROM      serial 
534
  LEFT JOIN subscription ON 
613
  LEFT JOIN subscription ON 
535
          (serial.subscriptionid=subscription.subscriptionid)
614
          (serial.subscriptionid=subscription.subscriptionid)
Lines 2837-2857 Return 1 if the subscription is editable by the current logged user (or a given Link Here
2837
2916
2838
sub can_edit_subscription {
2917
sub can_edit_subscription {
2839
    my ( $subscription, $userid ) = @_;
2918
    my ( $subscription, $userid ) = @_;
2919
2840
    return 0 unless C4::Context->userenv;
2920
    return 0 unless C4::Context->userenv;
2921
2841
    my $flags = C4::Context->userenv->{flags};
2922
    my $flags = C4::Context->userenv->{flags};
2923
2842
    $userid ||= C4::Context->userenv->{'id'};
2924
    $userid ||= C4::Context->userenv->{'id'};
2925
2843
    my $independent_branches = C4::Context->preference('IndependentBranches');
2926
    my $independent_branches = C4::Context->preference('IndependentBranches');
2844
    return 1 unless $independent_branches;
2927
    return 1 unless $independent_branches;
2845
    if( C4::Context->IsSuperLibrarian()
2928
2846
        or C4::Auth::haspermission( $userid, {serials => 'superserials'}),
2929
    return
2847
        or C4::Auth::haspermission( $userid, {serials => 'edit_subscription'}),
2930
         C4::Context->IsSuperLibrarian()
2848
        or not defined $subscription->{branchcode}
2931
      or C4::Auth::haspermission( $userid, { serials => 'superserials' } ),
2849
        or $subscription->{branchcode} eq ''
2932
      or C4::Auth::haspermission( $userid, { serials => 'edit_subscription' } ),
2850
        or $subscription->{branchcode} eq C4::Context->userenv->{'branch'}
2933
      or not defined $subscription->{branchcode}
2851
    ) {
2934
      or $subscription->{branchcode} eq ''
2852
        return 1;
2935
      or GetIndependentGroupModificationRights(
2853
    }
2936
        { for => $subscription->{branchcode} } );
2854
     return 0;
2855
}
2937
}
2856
2938
2857
1;
2939
1;
(-)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 258-267 if ( $op eq 'delete_confirm' ) { Link Here
258
    if ( C4::Context->preference("IndependentBranches") ) {
266
    if ( C4::Context->preference("IndependentBranches") ) {
259
        my $userenv = C4::Context->userenv;
267
        my $userenv = C4::Context->userenv;
260
        unless ( C4::Context->IsSuperLibrarian() ) {
268
        unless ( C4::Context->IsSuperLibrarian() ) {
261
            my $validtest = ( $basket->{creationdate} eq '' )
269
            my $validtest =
270
                 ( $basket->{creationdate} eq '' )
262
              || ( $userenv->{branch} eq $basket->{branch} )
271
              || ( $userenv->{branch} eq $basket->{branch} )
263
              || ( $userenv->{branch} eq '' )
272
              || ( $userenv->{branch} eq '' )
264
              || ( $basket->{branch}  eq '' );
273
              || ( $basket->{branch}  eq '' )
274
              || (
275
                GetIndependentGroupModificationRights(
276
                    { for => $basket->{branch} }
277
                )
278
              );
265
            unless ($validtest) {
279
            unless ($validtest) {
266
                print $query->redirect("../mainpage.pl");
280
                print $query->redirect("../mainpage.pl");
267
                exit 1;
281
                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 154-161 if ( $run_report ) { Link Here
154
155
155
156
156
    if (C4::Context->preference('IndependentBranches')){
157
    if (C4::Context->preference('IndependentBranches')){
157
        $strsth .= " AND items.holdingbranch=? ";
158
        my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
158
        push @query_params, C4::Context->userenv->{'branch'};
159
        $strsth .= " AND items.holdingbranch IN ( $branches ) ";
159
    }
160
    }
160
    $strsth .= " GROUP BY reserves.biblionumber ORDER BY biblio.title ";
161
    $strsth .= " GROUP BY reserves.biblionumber ORDER BY biblio.title ";
161
162
(-)a/circ/reserveratios.pl (-3 / +3 lines)
Lines 113-121 my $strsth = Link Here
113
 $sqldatewhere
113
 $sqldatewhere
114
";
114
";
115
115
116
if (C4::Context->preference('IndependentBranches')){
116
if ( C4::Context->preference('IndependentBranches') ) {
117
    $strsth .= " AND items.holdingbranch=? ";
117
    my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
118
    push @query_params, C4::Context->userenv->{'branch'};
118
    $strsth .= " AND items.holdingbranch IN ( $branches ) ";
119
}
119
}
120
120
121
$strsth .= " GROUP BY reserves.biblionumber ORDER BY reservecount DESC";
121
$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 8012-8017 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
8012
    SetVersion($DBversion);
8012
    SetVersion($DBversion);
8013
}
8013
}
8014
8014
8015
$DBversion = "3.15.00.XXX";
8016
if ( CheckVersion($DBversion) ) {
8017
    $dbh->do(q{
8018
            DELETE FROM branchcategories WHERE categorytype = 'properties'
8019
    });
8020
8021
    $dbh->do(q{
8022
        ALTER TABLE branchcategories
8023
        CHANGE categorytype categorytype
8024
          ENUM( 'searchdomain', 'independent_group' )
8025
            NULL DEFAULT NULL
8026
    });
8027
    print "Upgrade to $DBversion done (Remove branch property groups, add independent groups)\n";
8028
    SetVersion ($DBversion);
8029
}
8030
8015
=head1 FUNCTIONS
8031
=head1 FUNCTIONS
8016
8032
8017
=head2 TableExists($table)
8033
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt (-71 / +139 lines)
Lines 101-120 tinyMCE.init({ Link Here
101
        </li>
101
        </li>
102
	</ol>
102
	</ol>
103
	</fieldset>
103
	</fieldset>
104
	[% IF ( categoryloop ) %]<fieldset class="rows"><legend>Group(s):</legend>
104
105
        <ol>
105
     [% IF ( branch_categories ) %]
106
		[% FOREACH categoryloo IN categoryloop %]
106
        <fieldset class="rows">
107
            <li><label for="[% categoryloo.categorycode %]">[% categoryloo.categoryname %]: </label>
107
            <legend>Group(s):</legend>
108
                [% IF categoryloo.selected %]
108
            <ol>
109
                    <input type="checkbox" id="[% categoryloo.categorycode %]" name="[% categoryloo.categorycode %]" checked="checked" />
109
                <fieldset>
110
                [% ELSE %]
110
                    <legend>Search domain</legend>
111
                    <input type="checkbox" id="[% categoryloo.categorycode %]" name="[% categoryloo.categorycode %]" />
111
                    [% FOREACH bc IN branch_categories %]
112
                [% END %]
112
                        [% IF bc.categorytype == "searchdomain" %]
113
                <span class="hint">[% categoryloo.codedescription %]</span>
113
                            <li>
114
            </li>
114
                                <label for="[% bc.categorycode %]">[% bc.categoryname %]: </label>
115
        [% END %]
115
                                [% IF ( bc.selected ) %]
116
		</ol>
116
                                    <input type="checkbox" id="[% bc.categorycode %]" name="[% bc.categorycode %]" checked="checked" />
117
</fieldset>[% END %]
117
                                [% ELSE %]
118
                                    <input type="checkbox" id="[% bc.categorycode %]" name="[% bc.categorycode %]" />
119
                                [% END %]
120
                                <span class="hint">[% bc.codedescription %]</span>
121
                            </li>
122
                        [% END %]
123
                    [% END %]
124
                </fieldset>
125
            </ol>
126
            <ol>
127
                <fieldset>
128
                    <legend>Independent library groups</legend>
129
                    [% FOREACH bc IN branch_categories %]
130
                        [% IF bc.categorytype == "independent_group" %]
131
                            <li>
132
                                <label for="[% bc.categorycode %]">[% bc.categoryname %]: </label>
133
                                [% IF ( bc.selected ) %]
134
                                    <input type="checkbox" id="[% bc.categorycode %]" name="[% bc.categorycode %]" checked="checked" />
135
                                [% ELSE %]
136
                                    <input type="checkbox" id="[% bc.categorycode %]" name="[% bc.categorycode %]" />
137
                                [% END %]
138
                                <span class="hint">[% bc.codedescription %]</span>
139
                            </li>
140
                        [% END %]
141
                    [% END %]
142
                <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>
143
                </fieldset>
144
            </ol>
145
        </fieldset>
146
    [% END %]
147
118
	<fieldset class="rows">
148
	<fieldset class="rows">
119
	<ol>
149
	<ol>
120
        <li><label for="branchaddress1">Address line 1: </label><input type="text" name="branchaddress1" id="branchaddress1" size="60" value="[% branchaddress1 |html %]" /></li>
150
        <li><label for="branchaddress1">Address line 1: </label><input type="text" name="branchaddress1" id="branchaddress1" size="60" value="[% branchaddress1 |html %]" /></li>
Lines 250-339 tinyMCE.init({ Link Here
250
	[% ELSE %]
280
	[% ELSE %]
251
	<div class="dialog message">There are no libraries defined. <a href="/cgi-bin/koha/admin/branches.pl?op=add">Start defining libraries</a>.</div>
281
	<div class="dialog message">There are no libraries defined. <a href="/cgi-bin/koha/admin/branches.pl?op=add">Start defining libraries</a>.</div>
252
	[% END %]
282
	[% END %]
253
    
283
254
   [% IF ( branchcategories ) %]
284
    <h3>Search domain groups</h3>
255
   [% FOREACH branchcategorie IN branchcategories %]
285
    [% IF branch_categories.searchdomain %]
256
    <h3>Group(s):  [% IF ( branchcategorie.properties ) %]Properties[% ELSE %][% IF ( branchcategorie.searchdomain ) %]Search domain[% END %][% END %]</h3>
286
        <table>
257
    [% IF ( branchcategorie.catloop ) %]
287
            <thead>
258
      <table>
288
                <tr>
259
        <thead>
289
                    <th>Name</th>
260
          <tr>
290
                    <th>Code</th>
261
            <th>Name</th>
291
                    <th>Description</th>
262
            <th>Code</th>
292
                    <th>&nbsp;</th>
263
            <th>Description</th>
293
                    <th>&nbsp;</th>
264
            <th>&nbsp;</th>
294
                  </tr>
265
            <th>&nbsp;</th>
295
            </thead>
266
          </tr>
296
            <tbody>
267
        </thead>
297
                [% FOREACH bc IN branch_categories.searchdomain %]
268
        <tbody>
298
                    <tr>
269
          [% FOREACH catloo IN branchcategorie.catloop %]
299
                      <td>[% bc.value.categoryname %]</td>
270
            <tr>
300
                      <td>[% bc.key %]</td>
271
              <td>[% catloo.categoryname %]</td>
301
                      <td>[% bc.value.codedescription %]</td>
272
              <td>[% catloo.categorycode %]</td>
302
                      <td>
273
              <td>[% catloo.codedescription %]</td>
303
                        <a href="?op=editcategory&amp;categorycode=[% bc.key |url %]">Edit</a>
274
              <td>
304
                      </td>
275
                <a href="[% catloo.action %]?op=editcategory&amp;categorycode=[% catloo.categorycode |url %]">Edit</a>
305
                      <td>
276
              </td>
306
                        <a href="?op=delete_category&amp;categorycode=[% bc.key |url %]">Delete</a>
277
              <td>
307
                      </td>
278
                <a href="[% catloo.action %]?op=delete_category&amp;categorycode=[% catloo.categorycode |url %]">Delete</a>
308
                    </tr>
279
              </td>
309
                [% END %]
280
            </tr>
310
            </tbody>
281
          [% END %]
311
        </table>
282
        </tbody>
312
    [% ELSE %]
283
      </table>
313
        No search domain groups defined.
314
    [% END %]
315
    <a href="/cgi-bin/koha/admin/branches.pl?op=editcategory">Add a new group</a>.
316
317
    <h3>Independent library groups:</h3>
318
    [% IF branch_categories.independent_group %]
319
        <table>
320
            <thead>
321
                <tr>
322
                    <th>Name</th>
323
                    <th>Code</th>
324
                    <th>Description</th>
325
                    <th>&nbsp;</th>
326
                    <th>&nbsp;</th>
327
                  </tr>
328
            </thead>
329
            <tbody>
330
                [% FOREACH bc IN branch_categories.independent_group %]
331
                    <tr>
332
                      <td>[% bc.value.categoryname %]</td>
333
                      <td>[% bc.key %]</td>
334
                      <td>[% bc.value.codedescription %]</td>
335
                      <td>
336
                        <a href="?op=editcategory&amp;categorycode=[% bc.key |url %]">Edit</a>
337
                      </td>
338
                      <td>
339
                        <a href="?op=delete_category&amp;categorycode=[% bc.key |url %]">Delete</a>
340
                      </td>
341
                    </tr>
342
                [% END %]
343
            </tbody>
344
        </table>
284
    [% ELSE %]
345
    [% ELSE %]
285
      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>.
346
        No independent library groups defined.
286
    [% END %]
347
    [% END %]
287
  [% END %]
348
    <a href="/cgi-bin/koha/admin/branches.pl?op=editcategory">Add a new group</a>.
288
  [% ELSE %]
289
    <p>No groups defined.</p>
290
  [% END %] <!-- NAME="branchcategories" -->
291
[% END %]
349
[% END %]
292
350
293
[% IF ( editcategory ) %]
351
[% IF ( editcategory ) %]
294
    <h3>[% IF ( categorycode ) %]Edit group [% categorycode %][% ELSE %]Add group[% END %]</h3>
352
    <h3>[% IF ( category ) %]Edit group [% category.categorycode %][% ELSE %]Add group[% END %]</h3>
295
    <form action="[% action %]" name="Aform" method="post">
353
    <form action="[% action %]" name="Aform" method="post">
296
    <input type="hidden" name="op" value="addcategory_validate" />
354
    <input type="hidden" name="op" value="addcategory_validate" />
297
	[% IF ( categorycode ) %]
355
    [% IF ( category.categorycode ) %]
298
	<input type="hidden" name="add" value="0">
356
        <input type="hidden" name="add" value="0">
299
	[% ELSE %]
357
    [% ELSE %]
300
	<input type="hidden" name="add" value="1">
358
        <input type="hidden" name="add" value="1">
301
	[% END %]
359
    [% END %]
302
    <fieldset class="rows">
360
    <fieldset class="rows">
303
        
361
        
304
        <ol><li>
362
        <ol><li>
305
                [% IF ( categorycode ) %]
363
                [% IF ( category.categorycode ) %]
306
				<span class="label">Category code: </span>
364
				<span class="label">Category code: </span>
307
                    <input type="hidden" name="categorycode" id="categorycode" value="[% categorycode |html %]" />
365
                    <input type="hidden" name="categorycode" id="categorycode" value="[% category.categorycode | html %]" />
308
                    [% categorycode %]
366
                    [% category.categorycode %]
309
                [% ELSE %]
367
                [% ELSE %]
310
                <label for="categorycode">Category code:</label>
368
                    <label for="categorycode">Category code:</label>
311
                    <input type="text" name="categorycode" id="categorycode" size="10" maxlength="10" value="[% categorycode |html %]" />
369
                    <input type="text" name="categorycode" id="categorycode" size="10" maxlength="10" value="[% categorycode | html %]" />
312
                [% END %]
370
                [% END %]
313
            </li>
371
            </li>
314
        <li>
372
        <li>
315
            <label for="categoryname">Name: </label>
373
            <label for="categoryname">Name: </label>
316
            <input type="text" name="categoryname" id="categoryname" size="32" maxlength="32" value="[% categoryname |html %]" />
374
            <input type="text" name="categoryname" id="categoryname" size="32" maxlength="32" value="[% category.categoryname | html %]" />
317
        </li>
375
        </li>
318
        <li>
376
        <li>
319
            <label for="codedescription">Description: </label>
377
            <label for="codedescription">Description: </label>
320
            <input type="text" name="codedescription" id="codedescription" size="70" value="[% codedescription |html %]" />
378
            <input type="text" name="codedescription" id="codedescription" size="70" value="[% category.codedescription | html %]" />
321
        </li>
379
        </li>
322
		<li>
380
		<li>
323
        <label for="categorytype">Category type: </label>
381
        <label for="categorytype">Category type: </label>
324
            <select id="categorytype" name="categorytype">
382
            <select id="categorytype" name="categorytype">
325
            [% FOREACH categorytyp IN categorytype %]
383
                [% IF ( category.categorytype == 'searchdomain' ) %]
326
                [% IF ( categorytyp.selected ) %]
384
                    <option value="searchdomain" selected="selected">Search domain</option>
327
                    <option value="[% categorytyp.type %]" selected="selected">
328
                [% ELSE %]
385
                [% ELSE %]
329
                    <option value="[% categorytyp.type %]">
386
                    <option value="searchdomain">Search domain</option>
330
                [% END %] [% categorytyp.type %]</option>
387
                [% END %]
331
            [% END %]
388
389
                [% IF ( category.categorytype == 'independent_group' ) %]
390
                    <option value="independent_group" selected="selected">Independent group</option>
391
                [% ELSE %]
392
                    <option value="independent_group">Independent group</option>
393
                [% END %]
332
            </select>
394
            </select>
333
		</li>
395
		</li>
334
        <li>
396
        <li>
335
            <label for="show_in_pulldown">Show in search pulldown: </label>
397
            <label for="show_in_pulldown">Show in search pulldown: </label>
336
            [% IF ( show_in_pulldown ) %]
398
            [% IF ( category.show_in_pulldown ) %]
337
                <input type="checkbox" name="show_in_pulldown" id="show_in_pulldown" checked="checked"/>
399
                <input type="checkbox" name="show_in_pulldown" id="show_in_pulldown" checked="checked"/>
338
            [% ELSE %]
400
            [% ELSE %]
339
                <input type="checkbox" name="show_in_pulldown" id="show_in_pulldown" />
401
                <input type="checkbox" name="show_in_pulldown" id="show_in_pulldown" />
Lines 341-347 tinyMCE.init({ Link Here
341
        </li>
403
        </li>
342
		</ol>
404
		</ol>
343
    </fieldset>
405
    </fieldset>
344
	<fieldset class="action"><input type="submit" value="Update" /></fieldset>
406
  <fieldset class="action">
407
        [% IF category %]
408
            <input type="submit" value="Update group" />
409
        [% ELSE %]
410
            <input type="submit" value="Add group" />
411
        [% END %]
412
    </fieldset>
345
    </form>
413
    </form>
346
[% END %]
414
[% END %]
347
415
(-)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 58-64 $input->delete( Link Here
58
    'new_patron_list',    'borrowernumber',
58
    'new_patron_list',    'borrowernumber',
59
);
59
);
60
60
61
my $patron = $input->Vars;
61
my $patron = { $input->Vars };
62
foreach (keys %$patron){
62
foreach (keys %$patron){
63
	delete $$patron{$_} unless($$patron{$_});
63
	delete $$patron{$_} unless($$patron{$_});
64
}
64
}
(-)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