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

(-)a/C4/Acquisition.pm (-7 / +80 lines)
Lines 32-37 use Koha::DateUtils qw( dt_from_string output_pref ); Link Here
32
use Koha::Acquisition::Order;
32
use Koha::Acquisition::Order;
33
use Koha::Acquisition::Bookseller;
33
use Koha::Acquisition::Bookseller;
34
use Koha::Number::Price;
34
use Koha::Number::Price;
35
use C4::Branch qw(GetIndependentGroupModificationRights);
35
36
36
use C4::Koha qw( subfield_is_koha_internal_p );
37
use C4::Koha qw( subfield_is_koha_internal_p );
37
38
Lines 1894-1899 sub TransferOrder { Link Here
1894
1895
1895
=head2 FUNCTIONS ABOUT PARCELS
1896
=head2 FUNCTIONS ABOUT PARCELS
1896
1897
1898
=cut
1899
1900
#------------------------------------------------------------#
1901
1902
=head3 GetParcel
1903
1904
  @results = &GetParcel($booksellerid, $code, $date);
1905
1906
Looks up all of the received items from the supplier with the given
1907
bookseller ID at the given date, for the given code (bookseller Invoice number). Ignores cancelled and completed orders.
1908
1909
C<@results> is an array of references-to-hash. The keys of each element are fields from
1910
the aqorders, biblio, and biblioitems tables of the Koha database.
1911
1912
C<@results> is sorted alphabetically by book title.
1913
1914
=cut
1915
1916
sub GetParcel {
1917
    #gets all orders from a certain supplier, orders them alphabetically
1918
    my ( $supplierid, $code, $datereceived ) = @_;
1919
    my $dbh     = C4::Context->dbh;
1920
    my @results = ();
1921
    $code .= '%'
1922
    if $code;  # add % if we search on a given code (otherwise, let him empty)
1923
    my $strsth ="
1924
        SELECT  authorisedby,
1925
                creationdate,
1926
                aqbasket.basketno,
1927
                closedate,surname,
1928
                firstname,
1929
                aqorders.biblionumber,
1930
                aqorders.ordernumber,
1931
                aqorders.parent_ordernumber,
1932
                aqorders.quantity,
1933
                aqorders.quantityreceived,
1934
                aqorders.unitprice,
1935
                aqorders.listprice,
1936
                aqorders.rrp,
1937
                aqorders.ecost,
1938
                aqorders.gstrate,
1939
                biblio.title
1940
        FROM aqorders
1941
        LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno
1942
        LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
1943
        LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber
1944
        LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid
1945
        WHERE
1946
            aqbasket.booksellerid = ?
1947
            AND aqinvoices.invoicenumber LIKE ?
1948
            AND aqorders.datereceived = ? ";
1949
1950
    my @query_params = ( $supplierid, $code, $datereceived );
1951
    if ( C4::Context->preference("IndependentBranches") ) {
1952
        unless ( C4::Context->IsSuperLibrarian() ) {
1953
            my $branches =
1954
              GetIndependentGroupModificationRights( { stringify => 1 } );
1955
            $strsth .= " AND ( borrowers.branchcode IN ( $branches ) OR borrowers.branchcode  = '')";
1956
        }
1957
    }
1958
    $strsth .= " ORDER BY aqbasket.basketno";
1959
    my $result_set = $dbh->selectall_arrayref(
1960
        $strsth,
1961
        { Slice => {} },
1962
        @query_params);
1963
1964
    return @{$result_set};
1965
}
1966
1967
#------------------------------------------------------------#
1968
1897
=head3 GetParcels
1969
=head3 GetParcels
1898
1970
1899
  $results = &GetParcels($bookseller, $order, $code, $datefrom, $dateto);
1971
  $results = &GetParcels($bookseller, $order, $code, $datefrom, $dateto);
Lines 2095-2102 sub GetLateOrders { Link Here
2095
    }
2167
    }
2096
    if (C4::Context->preference("IndependentBranches")
2168
    if (C4::Context->preference("IndependentBranches")
2097
            && !C4::Context->IsSuperLibrarian() ) {
2169
            && !C4::Context->IsSuperLibrarian() ) {
2098
        $from .= ' AND borrowers.branchcode LIKE ? ';
2170
        my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
2099
        push @query_params, C4::Context->userenv->{branch};
2171
        $from .= qq{ AND borrowers.branchcode IN ( $branches ) };
2100
    }
2172
    }
2101
    $from .= " AND orderstatus <> 'cancelled' ";
2173
    $from .= " AND orderstatus <> 'cancelled' ";
2102
    my $query = "$select $from $having\nORDER BY latesince, basketno, borrowers.branchcode, supplier";
2174
    my $query = "$select $from $having\nORDER BY latesince, basketno, borrowers.branchcode, supplier";
Lines 2320-2330 sub GetHistory { Link Here
2320
    }
2392
    }
2321
2393
2322
2394
2323
    if ( C4::Context->preference("IndependentBranches") ) {
2395
    if ( C4::Context->preference("IndependentBranches")
2324
        unless ( C4::Context->IsSuperLibrarian() ) {
2396
        && !C4::Context->IsSuperLibrarian() )
2325
            $query .= " AND (borrowers.branchcode = ? OR borrowers.branchcode ='' ) ";
2397
    {
2326
            push @query_params, C4::Context->userenv->{branch};
2398
        my $branches =
2327
        }
2399
          GetIndependentGroupModificationRights( { stringify => 1 } );
2400
        $query .= qq{ AND ( borrowers.branchcode = ? OR borrowers.branchcode IN ( $branches ) ) };
2328
    }
2401
    }
2329
    $query .= " ORDER BY id";
2402
    $query .= " ORDER BY id";
2330
2403
(-)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 298-304 C<$results> is an hashref Link Here
298
300
299
sub GetBranchCategory {
301
sub GetBranchCategory {
300
    my ($catcode) = @_;
302
    my ($catcode) = @_;
301
    return unless $catcode;
303
    unless ( $catcode ) {
304
        carp("No category code passed in!");
305
        return;
306
    }
302
307
303
    my $dbh = C4::Context->dbh;
308
    my $dbh = C4::Context->dbh;
304
    my $sth;
309
    my $sth;
Lines 369-375 the categories were already here, and minimally used. Link Here
369
374
370
	#TODO  manage category types.  rename possibly to 'agency domains' ? as borrowergroups are called categories.
375
	#TODO  manage category types.  rename possibly to 'agency domains' ? as borrowergroups are called categories.
371
sub GetCategoryTypes {
376
sub GetCategoryTypes {
372
	return ( 'searchdomain','properties');
377
 return ( 'searchdomain','independent_groups');
373
}
378
}
374
379
375
=head2 GetBranch
380
=head2 GetBranch
Lines 424-429 sub GetBranchesInCategory { Link Here
424
	return( \@branches );
429
	return( \@branches );
425
}
430
}
426
431
432
=head2 GetIndependentGroupModificationRights
433
434
    GetIndependentGroupModificationRights(
435
                                           {
436
                                               branch => $this_branch,
437
                                               for => $other_branch,
438
                                               stringify => 1,
439
                                           }
440
                                          );
441
442
    Returns a list of branches this branch shares a common
443
    independent group with.
444
445
    If 'branch' is not provided, it will be looked up via
446
    C4::Context->userenv->{branch}.
447
448
    If 'for' is provided, the lookup is limited to that branch.
449
450
    If called in a list context, returns a list of
451
    branchcodes ( including $this_branch ).
452
453
    If called in a scalar context, it returns
454
    a count of matching branchcodes. Returns 1 if
455
456
    If stringify param is passed, the return value will
457
    be a string of the comma delimited branchcodes. This
458
    is useful for "branchcode IN $branchcodes" clauses
459
    in SQL queries.
460
461
    $this_branch and $other_branch are equal for efficiency.
462
463
    So you can write:
464
    my @branches = GetIndependentGroupModificationRights();
465
    or something like:
466
    if ( GetIndependentGroupModificationRights( { for => $other_branch } ) ) { do_stuff(); }
467
468
=cut
469
470
sub GetIndependentGroupModificationRights {
471
    my ($params) = @_;
472
473
    my $this_branch  = $params->{branch};
474
    my $other_branch = $params->{for};
475
    my $stringify    = $params->{stringify};
476
477
    $this_branch ||= C4::Context->userenv->{branch};
478
479
    carp("No branch found!") unless ($this_branch);
480
481
    return 1 if ( $this_branch eq $other_branch );
482
483
    my $sql = q{
484
        SELECT DISTINCT(branchcode)
485
        FROM branchrelations
486
        JOIN branchcategories USING ( categorycode )
487
        WHERE categorycode IN (
488
            SELECT categorycode
489
            FROM branchrelations
490
            WHERE branchcode = ?
491
        )
492
        AND branchcategories.categorytype = 'independent_group'
493
    };
494
495
    my @params;
496
    push( @params, $this_branch );
497
498
    if ($other_branch) {
499
        $sql .= q{ AND branchcode = ? };
500
        push( @params, $other_branch );
501
    }
502
503
    my $dbh = C4::Context->dbh;
504
    my @branchcodes = @{ $dbh->selectcol_arrayref( $sql, {}, @params ) };
505
506
    if ( $stringify ) {
507
        if ( @branchcodes ) {
508
            return join( ',', map { qq{'$_'} } @branchcodes );
509
        } else {
510
            return qq{'$this_branch'};
511
        }
512
    }
513
514
    if ( wantarray() ) {
515
        if ( @branchcodes ) {
516
            return @branchcodes;
517
        } else {
518
            return $this_branch;
519
        }
520
    } else {
521
        return scalar(@branchcodes);
522
    }
523
}
524
427
=head2 GetBranchInfo
525
=head2 GetBranchInfo
428
526
429
$results = GetBranchInfo($branchcode);
527
$results = GetBranchInfo($branchcode);
(-)a/C4/Circulation.pm (-5 / +16 lines)
Lines 912-925 sub CanBookBeIssued { Link Here
912
        $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
912
        $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
913
    }
913
    }
914
    if ( C4::Context->preference("IndependentBranches") ) {
914
    if ( C4::Context->preference("IndependentBranches") ) {
915
        my $userenv = C4::Context->userenv;
916
        unless ( C4::Context->IsSuperLibrarian() ) {
915
        unless ( C4::Context->IsSuperLibrarian() ) {
917
            if ( $item->{C4::Context->preference("HomeOrHoldingBranch")} ne $userenv->{branch} ){
916
            unless (
917
                GetIndependentGroupModificationRights(
918
                    {
919
                        for => $item->{ C4::Context->preference(
920
                                "HomeOrHoldingBranch") }
921
                    }
922
                )
923
              )
924
            {
918
                $issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
925
                $issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
919
                $issuingimpossible{'itemhomebranch'} = $item->{C4::Context->preference("HomeOrHoldingBranch")};
926
                $issuingimpossible{'itemhomebranch'} =
927
                  $item->{ C4::Context->preference("HomeOrHoldingBranch") };
920
            }
928
            }
921
            $needsconfirmation{BORRNOTSAMEBRANCH} = GetBranchName( $borrower->{'branchcode'} )
929
922
              if ( $borrower->{'branchcode'} ne $userenv->{branch} );
930
            $needsconfirmation{BORRNOTSAMEBRANCH} =
931
              GetBranchName( $borrower->{'branchcode'} )
932
              if (
933
                $borrower->{'branchcode'} ne C4::Context->userenv->{branch} );
923
        }
934
        }
924
    }
935
    }
925
    #
936
    #
(-)a/C4/Items.pm (-10 / +21 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 Koha::Database;
40
use Koha::Database;
40
41
Lines 1352-1361 sub GetItemsInfo { Link Here
1352
    my $serial;
1353
    my $serial;
1353
1354
1354
    my $userenv = C4::Context->userenv;
1355
    my $userenv = C4::Context->userenv;
1355
    my $want_not_same_branch = C4::Context->preference("IndependentBranches") && !C4::Context->IsSuperLibrarian();
1356
    while ( my $data = $sth->fetchrow_hashref ) {
1356
    while ( my $data = $sth->fetchrow_hashref ) {
1357
        if ( $data->{borrowernumber} && $want_not_same_branch) {
1357
        if ( C4::Context->preference("IndependentBranches") && $userenv ) {
1358
            $data->{'NOTSAMEBRANCH'} = $data->{'bcode'} ne $userenv->{branch};
1358
            unless ( C4::Context->IsSuperLibrarian()
1359
                || GetIndependentGroupModificationRights( { for => $data->{'bcode'} } ) )
1360
            {
1361
                $data->{'NOTSAMEBRANCH'} = $data->{'bcode'} ne $userenv->{branch};
1362
            }
1359
        }
1363
        }
1360
1364
1361
        $serial ||= $data->{'serial'};
1365
        $serial ||= $data->{'serial'};
Lines 2300-2311 sub DelItemCheck { Link Here
2300
2304
2301
    my $item = GetItem($itemnumber);
2305
    my $item = GetItem($itemnumber);
2302
2306
2303
    if ($onloan){
2307
    if ($onloan) {
2304
        $error = "book_on_loan" 
2308
        $error = "book_on_loan";
2305
    }
2309
    }
2306
    elsif ( !C4::Context->IsSuperLibrarian()
2310
    elsif (
2307
        and C4::Context->preference("IndependentBranches")
2311
           !C4::Context->IsSuperLibrarian()
2308
        and ( C4::Context->userenv->{branch} ne $item->{'homebranch'} ) )
2312
        && C4::Context->preference("IndependentBranches")
2313
        && !GetIndependentGroupModificationRights(
2314
            {
2315
                for => $item->{ C4::Context->preference("HomeOrHoldingBranch") }
2316
            }
2317
        )
2318
      )
2309
    {
2319
    {
2310
        $error = "not_same_branch";
2320
        $error = "not_same_branch";
2311
    }
2321
    }
Lines 2980-2987 sub PrepareItemrecordDisplay { Link Here
2980
                    if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
2990
                    if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
2981
                        if (   ( C4::Context->preference("IndependentBranches") )
2991
                        if (   ( C4::Context->preference("IndependentBranches") )
2982
                            && !C4::Context->IsSuperLibrarian() ) {
2992
                            && !C4::Context->IsSuperLibrarian() ) {
2983
                            my $sth = $dbh->prepare( "SELECT branchcode,branchname FROM branches WHERE branchcode = ? ORDER BY branchname" );
2993
                            my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
2984
                            $sth->execute( C4::Context->userenv->{branch} );
2994
                            my $sth = $dbh->prepare( "SELECT branchcode,branchname FROM branches WHERE branchcode IN ( $branches ) ORDER BY branchname" );
2995
                            $sth->execute();
2985
                            push @authorised_values, ""
2996
                            push @authorised_values, ""
2986
                              unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2997
                              unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2987
                            while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
2998
                            while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
(-)a/C4/Letters.pm (+2 lines)
Lines 209-214 sub getletter { Link Here
209
    my ( $module, $code, $branchcode, $message_transport_type ) = @_;
209
    my ( $module, $code, $branchcode, $message_transport_type ) = @_;
210
    $message_transport_type //= '%';
210
    $message_transport_type //= '%';
211
211
212
    $branchcode ||= q{};
213
212
    if ( C4::Context->preference('IndependentBranches')
214
    if ( C4::Context->preference('IndependentBranches')
213
            and $branchcode
215
            and $branchcode
214
            and C4::Context->userenv ) {
216
            and C4::Context->userenv ) {
(-)a/C4/Members.pm (-32 / +54 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 42-47 use Text::Unaccent qw( unac_string ); Link Here
42
use Koha::AuthUtils qw(hash_password);
43
use Koha::AuthUtils qw(hash_password);
43
use Koha::Database;
44
use Koha::Database;
44
use Module::Load;
45
use Module::Load;
46
use C4::Branch qw( GetIndependentGroupModificationRights );
45
if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
47
if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
46
    load Koha::NorwegianPatronDB, qw( NLUpdateHashedPIN NLEncryptPIN NLSync );
48
    load Koha::NorwegianPatronDB, qw( NLUpdateHashedPIN NLEncryptPIN NLSync );
47
}
49
}
Lines 1293-1298 sub checkuniquemember { Link Here
1293
            ($dateofbirth) ?
1295
            ($dateofbirth) ?
1294
            "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?  and dateofbirth=?" :
1296
            "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?  and dateofbirth=?" :
1295
            "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?";
1297
            "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?";
1298
1299
    if ( C4::Context->preference('IndependentBranches') ) {
1300
        my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
1301
        $request .= " AND branchcode IN ( $branches )";
1302
    }
1303
1296
    my $sth = $dbh->prepare($request);
1304
    my $sth = $dbh->prepare($request);
1297
    if ($collectivity) {
1305
    if ($collectivity) {
1298
        $sth->execute( uc($surname) );
1306
        $sth->execute( uc($surname) );
Lines 1984-1996 sub GetBorrowersToExpunge { Link Here
1984
    my $filterdate     = $params->{'not_borrowered_since'};
1992
    my $filterdate     = $params->{'not_borrowered_since'};
1985
    my $filterexpiry   = $params->{'expired_before'};
1993
    my $filterexpiry   = $params->{'expired_before'};
1986
    my $filtercategory = $params->{'category_code'};
1994
    my $filtercategory = $params->{'category_code'};
1987
    my $filterbranch   = $params->{'branchcode'} ||
1995
    my $filterbranch   = $params->{'branchcode'};
1988
                        ((C4::Context->preference('IndependentBranches')
1996
    my @filterbranches =
1989
                             && C4::Context->userenv 
1997
      (      C4::Context->preference('IndependentBranches')
1990
                             && !C4::Context->IsSuperLibrarian()
1998
          && C4::Context->userenv
1991
                             && C4::Context->userenv->{branch})
1999
          && !C4::Context->IsSuperLibrarian()
1992
                         ? C4::Context->userenv->{branch}
2000
          && C4::Context->userenv->{branch} )
1993
                         : "");  
2001
      ? GetIndependentGroupModificationRights()
2002
      : ($filterbranch);
1994
2003
1995
    my $dbh   = C4::Context->dbh;
2004
    my $dbh   = C4::Context->dbh;
1996
    my $query = q|
2005
    my $query = q|
Lines 2012-2020 sub GetBorrowersToExpunge { Link Here
2012
   |;
2021
   |;
2013
2022
2014
    my @query_params;
2023
    my @query_params;
2015
    if ( $filterbranch && $filterbranch ne "" ) {
2024
    if ( @filterbranches ) {
2016
        $query.= " AND borrowers.branchcode = ? ";
2025
        my $placeholders = join( ',', ('?') x @filterbranches );
2017
        push( @query_params, $filterbranch );
2026
        $query.= " AND borrowers.branchcode IN ( $placeholders )";
2027
        push( @query_params, @filterbranches );
2018
    }
2028
    }
2019
    if ( $filterexpiry ) {
2029
    if ( $filterexpiry ) {
2020
        $query .= " AND dateexpiry < ? ";
2030
        $query .= " AND dateexpiry < ? ";
Lines 2057-2069 I<$result> is a ref to an array which all elements are a hasref. Link Here
2057
=cut
2067
=cut
2058
2068
2059
sub GetBorrowersWhoHaveNeverBorrowed {
2069
sub GetBorrowersWhoHaveNeverBorrowed {
2060
    my $filterbranch = shift || 
2070
    my $filterbranch = shift;
2061
                        ((C4::Context->preference('IndependentBranches')
2071
2062
                             && C4::Context->userenv 
2072
    my @filterbranches =
2063
                             && !C4::Context->IsSuperLibrarian()
2073
      (      C4::Context->preference('IndependentBranches')
2064
                             && C4::Context->userenv->{branch})
2074
          && C4::Context->userenv
2065
                         ? C4::Context->userenv->{branch}
2075
          && !C4::Context->IsSuperLibrarian()
2066
                         : "");  
2076
          && C4::Context->userenv->{branch} )
2077
      ? GetIndependentGroupModificationRights()
2078
      : ($filterbranch);
2079
2067
    my $dbh   = C4::Context->dbh;
2080
    my $dbh   = C4::Context->dbh;
2068
    my $query = "
2081
    my $query = "
2069
        SELECT borrowers.borrowernumber,max(timestamp) as latestissue
2082
        SELECT borrowers.borrowernumber,max(timestamp) as latestissue
Lines 2071-2080 sub GetBorrowersWhoHaveNeverBorrowed { Link Here
2071
          LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
2084
          LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
2072
        WHERE issues.borrowernumber IS NULL
2085
        WHERE issues.borrowernumber IS NULL
2073
   ";
2086
   ";
2087
2074
    my @query_params;
2088
    my @query_params;
2075
    if ($filterbranch && $filterbranch ne ""){ 
2089
    if (@filterbranches) {
2076
        $query.=" AND borrowers.branchcode= ?";
2090
        my $placeholders = join( ',', ('?') x @filterbranches );
2077
        push @query_params,$filterbranch;
2091
        $query .= " AND borrowers.branchcode IN ( $placeholders ) ";
2092
        push( @query_params, @filterbranches );
2078
    }
2093
    }
2079
    warn $query if $debug;
2094
    warn $query if $debug;
2080
  
2095
  
Lines 2107-2131 This hashref is containt the number of time this borrowers has borrowed before I Link Here
2107
sub GetBorrowersWithIssuesHistoryOlderThan {
2122
sub GetBorrowersWithIssuesHistoryOlderThan {
2108
    my $dbh  = C4::Context->dbh;
2123
    my $dbh  = C4::Context->dbh;
2109
    my $date = shift ||POSIX::strftime("%Y-%m-%d",localtime());
2124
    my $date = shift ||POSIX::strftime("%Y-%m-%d",localtime());
2110
    my $filterbranch = shift || 
2125
    my $filterbranch = shift;
2111
                        ((C4::Context->preference('IndependentBranches')
2126
2112
                             && C4::Context->userenv 
2127
    my @filterbranches =
2113
                             && !C4::Context->IsSuperLibrarian()
2128
      (      C4::Context->preference('IndependentBranches')
2114
                             && C4::Context->userenv->{branch})
2129
          && C4::Context->userenv
2115
                         ? C4::Context->userenv->{branch}
2130
          && !C4::Context->IsSuperLibrarian()
2116
                         : "");  
2131
          && C4::Context->userenv->{branch} )
2132
      ? GetIndependentGroupModificationRights()
2133
      : ($filterbranch);
2134
2117
    my $query = "
2135
    my $query = "
2118
       SELECT count(borrowernumber) as n,borrowernumber
2136
       SELECT count(borrowernumber) as n,borrowernumber
2119
       FROM old_issues
2137
       FROM old_issues
2120
       WHERE returndate < ?
2138
       WHERE returndate < ?
2121
         AND borrowernumber IS NOT NULL 
2139
         AND borrowernumber IS NOT NULL 
2122
    "; 
2140
    "; 
2141
2123
    my @query_params;
2142
    my @query_params;
2124
    push @query_params, $date;
2143
    push( @query_params, $date );
2125
    if ($filterbranch){
2144
2126
        $query.="   AND branchcode = ?";
2145
    if (@filterbranches) {
2127
        push @query_params, $filterbranch;
2146
        my $placeholders = join( ',', ('?') x @filterbranches );
2128
    }    
2147
        $query .= " AND branchcode IN ( $placeholders ) ";
2148
        push( @query_params, @filterbranches );
2149
    }
2150
2129
    $query.=" GROUP BY borrowernumber ";
2151
    $query.=" GROUP BY borrowernumber ";
2130
    warn $query if $debug;
2152
    warn $query if $debug;
2131
    my $sth = $dbh->prepare($query);
2153
    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 196-202 sub GetSerialInformation { Link Here
196
    my ($serialid) = @_;
197
    my ($serialid) = @_;
197
    my $dbh        = C4::Context->dbh;
198
    my $dbh        = C4::Context->dbh;
198
    my $query      = qq|
199
    my $query      = qq|
199
        SELECT serial.*, serial.notes as sernotes, serial.status as serstatus,subscription.*,subscription.subscriptionid as subsid
200
        SELECT serial.*,
201
               serial.notes as sernotes,
202
               serial.status as serstatus,
203
               subscription.*,
204
               subscription.subscriptionid as subsid
205
    |;
206
    if (   C4::Context->preference('IndependentBranches')
207
        && C4::Context->userenv
208
        && C4::Context->userenv->{'flags'} % 2 != 1
209
        && C4::Context->userenv->{'branch'} ) {
210
        my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
211
        $query .= qq|
212
            , ( ( subscription.branchcode NOT IN ( $branches ) ) AND subscription.branchcode <> '' AND subscription.branchcode IS NOT NULL ) AS cannotedit
213
        |;
214
    }
215
    $query .= qq|
200
        FROM   serial LEFT JOIN subscription ON subscription.subscriptionid=serial.subscriptionid
216
        FROM   serial LEFT JOIN subscription ON subscription.subscriptionid=serial.subscriptionid
201
        WHERE  serialid = ?
217
        WHERE  serialid = ?
202
    |;
218
    |;
Lines 299-316 subscription, subscriptionhistory, aqbooksellers.name, biblio.title Link Here
299
sub GetSubscription {
315
sub GetSubscription {
300
    my ($subscriptionid) = @_;
316
    my ($subscriptionid) = @_;
301
    my $dbh              = C4::Context->dbh;
317
    my $dbh              = C4::Context->dbh;
302
    my $query            = qq(
318
319
    my $query = qq|
303
        SELECT  subscription.*,
320
        SELECT  subscription.*,
304
                subscriptionhistory.*,
321
                subscriptionhistory.*,
305
                aqbooksellers.name AS aqbooksellername,
322
                aqbooksellers.name AS aqbooksellername,
306
                biblio.title AS bibliotitle,
323
                biblio.title AS bibliotitle,
307
                subscription.biblionumber as bibnum
324
                subscription.biblionumber as bibnum
325
    |;
326
327
    if (   C4::Context->preference('IndependentBranches')
328
        && C4::Context->userenv
329
        && C4::Context->userenv->{'flags'} % 2 != 1
330
        && C4::Context->userenv->{'branch'} )
331
    {
332
        my $branches =
333
          GetIndependentGroupModificationRights( { stringify => 1 } );
334
335
        $query .= qq|
336
            , ( ( subscription.branchcode NOT IN ( $branches ) ) AND subscription.branchcode <> '' AND subscription.branchcode IS NOT NULL ) AS cannotedit
337
        |;
338
    }
339
340
    $query .= qq|
308
       FROM subscription
341
       FROM subscription
309
       LEFT JOIN subscriptionhistory ON subscription.subscriptionid=subscriptionhistory.subscriptionid
342
       LEFT JOIN subscriptionhistory ON subscription.subscriptionid=subscriptionhistory.subscriptionid
310
       LEFT JOIN aqbooksellers ON subscription.aqbooksellerid=aqbooksellers.id
343
       LEFT JOIN aqbooksellers ON subscription.aqbooksellerid=aqbooksellers.id
311
       LEFT JOIN biblio ON biblio.biblionumber=subscription.biblionumber
344
       LEFT JOIN biblio ON biblio.biblionumber=subscription.biblionumber
312
       WHERE subscription.subscriptionid = ?
345
       WHERE subscription.subscriptionid = ?
313
    );
346
    |;
314
347
315
    $debug and warn "query : $query\nsubsid :$subscriptionid";
348
    $debug and warn "query : $query\nsubsid :$subscriptionid";
316
    my $sth = $dbh->prepare($query);
349
    my $sth = $dbh->prepare($query);
Lines 333-340 sub GetFullSubscription { Link Here
333
    return unless ($subscriptionid);
366
    return unless ($subscriptionid);
334
367
335
    my $dbh              = C4::Context->dbh;
368
    my $dbh              = C4::Context->dbh;
336
    my $query            = qq|
369
337
  SELECT    serial.serialid,
370
    my $query = qq|
371
        SELECT
372
            serial.serialid,
338
            serial.serialseq,
373
            serial.serialseq,
339
            serial.planneddate, 
374
            serial.planneddate, 
340
            serial.publisheddate, 
375
            serial.publisheddate, 
Lines 345-350 sub GetFullSubscription { Link Here
345
            biblio.title as bibliotitle,
380
            biblio.title as bibliotitle,
346
            subscription.branchcode AS branchcode,
381
            subscription.branchcode AS branchcode,
347
            subscription.subscriptionid AS subscriptionid
382
            subscription.subscriptionid AS subscriptionid
383
    |;
384
385
    if (   C4::Context->preference('IndependentBranches')
386
        && C4::Context->userenv
387
        && C4::Context->userenv->{'flags'} % 2 != 1
388
        && C4::Context->userenv->{'branch'} )
389
    {
390
        my $branches =
391
          GetIndependentGroupModificationRights( { stringify => 1 } );
392
393
        $query .= qq|
394
            , ( ( subscription.branchcode NOT IN ( $branches ) ) AND subscription.branchcode <> '' AND subscription.branchcode IS NOT NULL ) AS cannotedit
395
        |;
396
    }
397
398
    $query .= qq|
348
  FROM      serial 
399
  FROM      serial 
349
  LEFT JOIN subscription ON 
400
  LEFT JOIN subscription ON 
350
          (serial.subscriptionid=subscription.subscriptionid )
401
          (serial.subscriptionid=subscription.subscriptionid )
Lines 465-470 sub GetSubscriptionsFromBiblionumber { Link Here
465
        $subs->{ "periodicity" . $subs->{periodicity} }     = 1;
516
        $subs->{ "periodicity" . $subs->{periodicity} }     = 1;
466
        $subs->{ "numberpattern" . $subs->{numberpattern} } = 1;
517
        $subs->{ "numberpattern" . $subs->{numberpattern} } = 1;
467
        $subs->{ "status" . $subs->{'status'} }             = 1;
518
        $subs->{ "status" . $subs->{'status'} }             = 1;
519
        $subs->{'cannotedit'} = (
520
                 C4::Context->preference('IndependentBranches')
521
              && C4::Context->userenv
522
              && !C4::Context->IsSuperLibrarian()
523
              && C4::Context->userenv->{branch}
524
              && $subs->{branchcode}
525
              && GetIndependentGroupModificationRights(
526
                { for => $subs->{branchcode} }
527
              )
528
        );
468
529
469
        if ( $subs->{enddate} eq '0000-00-00' ) {
530
        if ( $subs->{enddate} eq '0000-00-00' ) {
470
            $subs->{enddate} = '';
531
            $subs->{enddate} = '';
Lines 489-496 sub GetSubscriptionsFromBiblionumber { Link Here
489
sub GetFullSubscriptionsFromBiblionumber {
550
sub GetFullSubscriptionsFromBiblionumber {
490
    my ($biblionumber) = @_;
551
    my ($biblionumber) = @_;
491
    my $dbh            = C4::Context->dbh;
552
    my $dbh            = C4::Context->dbh;
492
    my $query          = qq|
553
493
  SELECT    serial.serialid,
554
    my $query = qq|
555
        SELECT
556
            serial.serialid,
494
            serial.serialseq,
557
            serial.serialseq,
495
            serial.planneddate, 
558
            serial.planneddate, 
496
            serial.publisheddate, 
559
            serial.publisheddate, 
Lines 500-505 sub GetFullSubscriptionsFromBiblionumber { Link Here
500
            biblio.title as bibliotitle,
563
            biblio.title as bibliotitle,
501
            subscription.branchcode AS branchcode,
564
            subscription.branchcode AS branchcode,
502
            subscription.subscriptionid AS subscriptionid
565
            subscription.subscriptionid AS subscriptionid
566
    |;
567
568
    if (   C4::Context->preference('IndependentBranches')
569
        && C4::Context->userenv
570
        && C4::Context->userenv->{'flags'} != 1
571
        && C4::Context->userenv->{'branch'} )
572
    {
573
        my $branches =
574
          GetIndependentGroupModificationRights( { stringify => 1 } );
575
576
        $query .= qq|
577
            , ( ( subscription.branchcode NOT IN ( $branches ) ) AND subscription.branchcode <> '' AND subscription.branchcode IS NOT NULL ) AS cannotedit
578
        |;
579
    }
580
581
    $query .= qq|
503
  FROM      serial 
582
  FROM      serial 
504
  LEFT JOIN subscription ON 
583
  LEFT JOIN subscription ON 
505
          (serial.subscriptionid=subscription.subscriptionid)
584
          (serial.subscriptionid=subscription.subscriptionid)
Lines 2701-2707 sub can_show_subscription { Link Here
2701
sub _can_do_on_subscription {
2780
sub _can_do_on_subscription {
2702
    my ( $subscription, $userid, $permission ) = @_;
2781
    my ( $subscription, $userid, $permission ) = @_;
2703
    return 0 unless C4::Context->userenv;
2782
    return 0 unless C4::Context->userenv;
2783
2704
    my $flags = C4::Context->userenv->{flags};
2784
    my $flags = C4::Context->userenv->{flags};
2785
2705
    $userid ||= C4::Context->userenv->{'id'};
2786
    $userid ||= C4::Context->userenv->{'id'};
2706
2787
2707
    if ( C4::Context->preference('IndependentBranches') ) {
2788
    if ( C4::Context->preference('IndependentBranches') ) {
Lines 2710-2721 sub _can_do_on_subscription { Link Here
2710
              or
2791
              or
2711
              C4::Auth::haspermission( $userid, { serials => 'superserials' } )
2792
              C4::Auth::haspermission( $userid, { serials => 'superserials' } )
2712
              or (
2793
              or (
2713
                  C4::Auth::haspermission( $userid,
2794
                  C4::Auth::haspermission(
2714
                      { serials => $permission } )
2795
                      $userid, { serials => $permission }
2796
                  )
2715
                  and (  not defined $subscription->{branchcode}
2797
                  and (  not defined $subscription->{branchcode}
2716
                      or $subscription->{branchcode} eq ''
2798
                      or $subscription->{branchcode} eq ''
2717
                      or $subscription->{branchcode} eq
2799
                      or $subscription->{branchcode} eq
2718
                      C4::Context->userenv->{'branch'} )
2800
                      C4::Context->userenv->{'branch'} )
2801
              )
2802
              or GetIndependentGroupModificationRights(
2803
                  { for => $subscription->{branchcode} }
2719
              );
2804
              );
2720
    }
2805
    }
2721
    else {
2806
    else {
Lines 2723-2732 sub _can_do_on_subscription { Link Here
2723
          if C4::Context->IsSuperLibrarian()
2808
          if C4::Context->IsSuperLibrarian()
2724
              or
2809
              or
2725
              C4::Auth::haspermission( $userid, { serials => 'superserials' } )
2810
              C4::Auth::haspermission( $userid, { serials => 'superserials' } )
2726
              or C4::Auth::haspermission(
2811
              or C4::Auth::haspermission( $userid, { serials => $permission } )
2727
                  $userid, { serials => $permission }
2812
            ,;
2728
              ),
2729
        ;
2730
    }
2813
    }
2731
    return 0;
2814
    return 0;
2732
}
2815
}
(-)a/C4/Suggestions.pm (-20 / +31 lines)
Lines 33-38 use Koha::DateUtils qw( dt_from_string ); Link Here
33
use List::MoreUtils qw(any);
33
use List::MoreUtils qw(any);
34
use C4::Dates qw(format_date_in_iso);
34
use C4::Dates qw(format_date_in_iso);
35
use base qw(Exporter);
35
use base qw(Exporter);
36
use C4::Branch qw(GetIndependentGroupModificationRights);
36
37
37
our $VERSION = 3.07.00.049;
38
our $VERSION = 3.07.00.049;
38
our @EXPORT  = qw(
39
our @EXPORT  = qw(
Lines 135-152 sub SearchSuggestion { Link Here
135
    }
136
    }
136
137
137
    # filter on user branch
138
    # filter on user branch
138
    if ( C4::Context->preference('IndependentBranches') ) {
139
    if (   C4::Context->preference('IndependentBranches')
139
        my $userenv = C4::Context->userenv;
140
        && !C4::Context->IsSuperLibrarian()
140
        if ($userenv) {
141
        && !$suggestion->{branchcode} )
141
            if ( !C4::Context->IsSuperLibrarian() && !$suggestion->{branchcode} )
142
    {
142
            {
143
        my $branches =
143
                push @sql_params, $$userenv{branch};
144
          GetIndependentGroupModificationRights( { stringify => 1 } );
144
                push @query,      q{
145
        push( @query, qq{ AND (suggestions.branchcode IN ( $branches ) OR suggestions.branchcode='') } );
145
                    AND (suggestions.branchcode=? OR suggestions.branchcode='')
146
    }
146
                };
147
    else {
147
            }
148
        }
149
    } else {
150
        if ( defined $suggestion->{branchcode} && $suggestion->{branchcode} ) {
148
        if ( defined $suggestion->{branchcode} && $suggestion->{branchcode} ) {
151
            unless ( $suggestion->{branchcode} eq '__ANY__' ) {
149
            unless ( $suggestion->{branchcode} eq '__ANY__' ) {
152
                push @sql_params, $suggestion->{branchcode};
150
                push @sql_params, $suggestion->{branchcode};
Lines 344-356 sub GetSuggestionByStatus { Link Here
344
342
345
    # filter on branch
343
    # filter on branch
346
    if ( C4::Context->preference("IndependentBranches") || $branchcode ) {
344
    if ( C4::Context->preference("IndependentBranches") || $branchcode ) {
347
        my $userenv = C4::Context->userenv;
345
        if (   C4::Context->userenv
348
        if ($userenv) {
346
            && C4::Context->preference("IndependentBranches")
349
            unless ( C4::Context->IsSuperLibrarian() ) {
347
            && !C4::Context->IsSuperLibrarian() )
350
                push @sql_params, $userenv->{branch};
348
        {
351
                $query .= q{ AND (U1.branchcode = ? OR U1.branchcode ='') };
349
352
            }
350
            my $branches =
351
              GetIndependentGroupModificationRights( { stringify => 1 } );
352
353
            $query .= qq{
354
                AND (U1.branchcode IN ( $branches ) OR U1.branchcode ='')
355
            };
353
        }
356
        }
357
354
        if ($branchcode) {
358
        if ($branchcode) {
355
            push @sql_params, $branchcode;
359
            push @sql_params, $branchcode;
356
            $query .= q{ AND (U1.branchcode = ? OR U1.branchcode ='') };
360
            $query .= q{ AND (U1.branchcode = ? OR U1.branchcode ='') };
Lines 396-407 sub CountSuggestion { Link Here
396
    if ( C4::Context->preference("IndependentBranches")
400
    if ( C4::Context->preference("IndependentBranches")
397
        && !C4::Context->IsSuperLibrarian() )
401
        && !C4::Context->IsSuperLibrarian() )
398
    {
402
    {
399
        my $query = q{
403
        my $branches =
404
          GetIndependentGroupModificationRights( { stringify => 1 } );
405
406
        my $query = qq{
400
            SELECT count(*)
407
            SELECT count(*)
401
            FROM suggestions
408
            FROM suggestions
402
                LEFT JOIN borrowers ON borrowers.borrowernumber=suggestions.suggestedby
409
                LEFT JOIN borrowers ON borrowers.borrowernumber=suggestions.suggestedby
403
            WHERE STATUS=?
410
            WHERE STATUS=?
404
                AND (borrowers.branchcode='' OR borrowers.branchcode=?)
411
                AND (
412
                    borrowers.branchcode IN ( $branches )
413
                    OR
414
                    borrowers.branchcode=?
415
                )
405
        };
416
        };
406
        $sth = $dbh->prepare($query);
417
        $sth = $dbh->prepare($query);
407
        $sth->execute( $status, $userenv->{branch} );
418
        $sth->execute( $status, $userenv->{branch} );
(-)a/acqui/basket.pl (-2 / +9 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 217-226 if ( $op eq 'delete_confirm' ) { Link Here
217
    if ( C4::Context->preference("IndependentBranches") ) {
218
    if ( C4::Context->preference("IndependentBranches") ) {
218
        my $userenv = C4::Context->userenv;
219
        my $userenv = C4::Context->userenv;
219
        unless ( C4::Context->IsSuperLibrarian() ) {
220
        unless ( C4::Context->IsSuperLibrarian() ) {
220
            my $validtest = ( $basket->{creationdate} eq '' )
221
            my $validtest =
222
                 ( $basket->{creationdate} eq '' )
221
              || ( $userenv->{branch} eq $basket->{branch} )
223
              || ( $userenv->{branch} eq $basket->{branch} )
222
              || ( $userenv->{branch} eq '' )
224
              || ( $userenv->{branch} eq '' )
223
              || ( $basket->{branch}  eq '' );
225
              || ( $basket->{branch}  eq '' )
226
              || (
227
                GetIndependentGroupModificationRights(
228
                    { for => $basket->{branch} }
229
                )
230
              );
224
            unless ($validtest) {
231
            unless ($validtest) {
225
                print $query->redirect("../mainpage.pl");
232
                print $query->redirect("../mainpage.pl");
226
                exit 1;
233
                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
        $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 176-188 foreach my $item (@items){ Link Here
176
        $item->{status_advisory} = 1;
176
        $item->{status_advisory} = 1;
177
    }
177
    }
178
178
179
    if (C4::Context->preference("IndependentBranches")) {
179
    if ( C4::Context->preference("IndependentBranches") ) {
180
        #verifying rights
180
        unless (
181
        my $userenv = C4::Context->userenv();
181
            C4::Context->IsSuperLibrarian()
182
        unless (C4::Context->IsSuperLibrarian() or ($userenv->{'branch'} eq $item->{'homebranch'})) {
182
            || GetIndependentGroupModificationRights(
183
                $item->{'nomod'}=1;
183
                { for => $item->{'homebranch'} }
184
            )
185
          )
186
        {
187
            $item->{'nomod'} = 1;
184
        }
188
        }
185
    }
189
    }
190
186
    $item->{'homebranchname'} = GetBranchName($item->{'homebranch'});
191
    $item->{'homebranchname'} = GetBranchName($item->{'homebranch'});
187
    $item->{'holdingbranchname'} = GetBranchName($item->{'holdingbranch'});
192
    $item->{'holdingbranchname'} = GetBranchName($item->{'holdingbranch'});
188
    if ($item->{'datedue'}) {
193
    if ($item->{'datedue'}) {
(-)a/cataloguing/additem.pl (-2 / +11 lines)
Lines 751-760 foreach my $field (@fields) { Link Here
751
						|| $subfieldvalue;
751
						|| $subfieldvalue;
752
        }
752
        }
753
753
754
        if (($field->tag eq $branchtagfield) && ($subfieldcode eq $branchtagsubfield) && C4::Context->preference("IndependentBranches")) {
754
        if (   $field->tag eq $branchtagfield
755
            && $subfieldcode eq $branchtagsubfield
756
            && C4::Context->preference("IndependentBranches") )
757
        {
755
            #verifying rights
758
            #verifying rights
756
            my $userenv = C4::Context->userenv();
759
            my $userenv = C4::Context->userenv();
757
            unless (C4::Context->IsSuperLibrarian() or (($userenv->{'branch'} eq $subfieldvalue))){
760
            unless (
761
                C4::Context->IsSuperLibrarian()
762
                || GetIndependentGroupModificationRights(
763
                    { for => $subfieldvalue }
764
                )
765
              )
766
            {
758
                $this_row{'nomod'} = 1;
767
                $this_row{'nomod'} = 1;
759
            }
768
            }
760
        }
769
        }
(-)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) = get_template_and_user(
29
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user(
Lines 40-47 my $fa = getframeworkinfo('FA'); Link Here
40
$template->param( fast_cataloging => 1 ) if (defined $fa);
41
$template->param( fast_cataloging => 1 ) if (defined $fa);
41
42
42
# Checking if the transfer page needs to be displayed
43
# Checking if the transfer page needs to be displayed
43
$template->param( display_transfer => 1 ) if ( ($flags->{'superlibrarian'} == 1) || (C4::Context->preference("IndependentBranches") == 0) );
44
$template->param( display_transfer => 1 )
44
$template->{'VARS'}->{'AllowOfflineCirculation'} = C4::Context->preference('AllowOfflineCirculation');
45
  if ( $flags->{'superlibrarian'} == 1
46
    || scalar GetIndependentGroupModificationRights() );
45
47
48
$template->{'VARS'}->{'AllowOfflineCirculation'} = C4::Context->preference('AllowOfflineCirculation');
46
49
47
output_html_with_http_headers $query, $cookie, $template->output;
50
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 124-132 my $strsth = Link Here
124
 $sqldatewhere
124
 $sqldatewhere
125
";
125
";
126
126
127
if (C4::Context->preference('IndependentBranches')){
127
if ( C4::Context->preference('IndependentBranches') ) {
128
    $strsth .= " AND items.holdingbranch=? ";
128
    my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
129
    push @query_params, C4::Context->userenv->{'branch'};
129
    $strsth .= " AND items.holdingbranch IN ( $branches ) ";
130
}
130
}
131
131
132
$strsth .= " GROUP BY reserves.biblionumber ORDER BY reservecount DESC";
132
$strsth .= " GROUP BY reserves.biblionumber ORDER BY reservecount DESC";
(-)a/installer/data/mysql/atomicupdate/bug_10276.sql (+6 lines)
Line 0 Link Here
1
DELETE FROM branchcategories WHERE categorytype = 'properties';
2
3
ALTER TABLE branchcategories
4
CHANGE categorytype categorytype
5
ENUM( 'searchdomain', 'independent_group' )
6
NULL DEFAULT NULL;
(-)a/installer/data/mysql/kohastructure.sql (-1 / +1 lines)
Lines 385-391 CREATE TABLE `branchcategories` ( -- information related to library/branch group Link Here
385
  `categorycode` varchar(10) NOT NULL default '', -- unique identifier for the library/branch group
385
  `categorycode` varchar(10) NOT NULL default '', -- unique identifier for the library/branch group
386
  `categoryname` varchar(32), -- name of the library/branch group
386
  `categoryname` varchar(32), -- name of the library/branch group
387
  `codedescription` mediumtext, -- longer description of the library/branch group
387
  `codedescription` mediumtext, -- longer description of the library/branch group
388
  `categorytype` varchar(16), -- says whether this is a search group or a properties group
388
  `categorytype` ENUM(  'searchdomain',  'independent_group' ) NULL DEFAULT NULL, -- says whether this is a search group or an independent group
389
  `show_in_pulldown` tinyint(1) NOT NULL DEFAULT '0', -- says this group should be in the opac libararies pulldown if it is enabled
389
  `show_in_pulldown` tinyint(1) NOT NULL DEFAULT '0', -- says this group should be in the opac libararies pulldown if it is enabled
390
  PRIMARY KEY  (`categorycode`),
390
  PRIMARY KEY  (`categorycode`),
391
  KEY `show_in_pulldown` (`show_in_pulldown`)
391
  KEY `show_in_pulldown` (`show_in_pulldown`)
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +1 lines)
Lines 6985-6991 $DBversion = "3.13.00.002"; Link Here
6985
if ( CheckVersion($DBversion) ) {
6985
if ( CheckVersion($DBversion) ) {
6986
   $dbh->do("UPDATE systempreferences SET variable = 'IndependentBranches' WHERE variable = 'IndependantBranches'");
6986
   $dbh->do("UPDATE systempreferences SET variable = 'IndependentBranches' WHERE variable = 'IndependantBranches'");
6987
   print "Upgrade to $DBversion done (Bug 10080 - Change system pref IndependantBranches to IndependentBranches)\n";
6987
   print "Upgrade to $DBversion done (Bug 10080 - Change system pref IndependantBranches to IndependentBranches)\n";
6988
   SetVersion ($DBversion);
6988
    SetVersion ($DBversion);
6989
}
6989
}
6990
6990
6991
$DBversion = '3.13.00.003';
6991
$DBversion = '3.13.00.003';
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt (-70 / +138 lines)
Lines 112-131 tinyMCE.init({ Link Here
112
        </li>
112
        </li>
113
	</ol>
113
	</ol>
114
	</fieldset>
114
	</fieldset>
115
	[% IF ( categoryloop ) %]<fieldset class="rows"><legend>Group(s):</legend>
115
116
        <ol>
116
     [% IF ( branch_categories ) %]
117
		[% FOREACH categoryloo IN categoryloop %]
117
        <fieldset class="rows">
118
            <li><label for="[% categoryloo.categorycode %]">[% categoryloo.categoryname %]: </label>
118
            <legend>Group(s):</legend>
119
                [% IF categoryloo.selected %]
119
            <ol>
120
                    <input type="checkbox" id="[% categoryloo.categorycode %]" name="[% categoryloo.categorycode %]" checked="checked" />
120
                <fieldset>
121
                [% ELSE %]
121
                    <legend>Search domain</legend>
122
                    <input type="checkbox" id="[% categoryloo.categorycode %]" name="[% categoryloo.categorycode %]" />
122
                    [% FOREACH bc IN branch_categories %]
123
                [% END %]
123
                        [% IF bc.categorytype == "searchdomain" %]
124
                <span class="hint">[% categoryloo.codedescription %]</span>
124
                            <li>
125
            </li>
125
                                <label for="[% bc.categorycode %]">[% bc.categoryname %]: </label>
126
        [% END %]
126
                                [% IF ( bc.selected ) %]
127
		</ol>
127
                                    <input type="checkbox" id="[% bc.categorycode %]" name="[% bc.categorycode %]" checked="checked" />
128
</fieldset>[% END %]
128
                                [% ELSE %]
129
                                    <input type="checkbox" id="[% bc.categorycode %]" name="[% bc.categorycode %]" />
130
                                [% END %]
131
                                <span class="hint">[% bc.codedescription %]</span>
132
                            </li>
133
                        [% END %]
134
                    [% END %]
135
                </fieldset>
136
            </ol>
137
            <ol>
138
                <fieldset>
139
                    <legend>Independent library groups</legend>
140
                    [% FOREACH bc IN branch_categories %]
141
                        [% IF bc.categorytype == "independent_group" %]
142
                            <li>
143
                                <label for="[% bc.categorycode %]">[% bc.categoryname %]: </label>
144
                                [% IF ( bc.selected ) %]
145
                                    <input type="checkbox" id="[% bc.categorycode %]" name="[% bc.categorycode %]" checked="checked" />
146
                                [% ELSE %]
147
                                    <input type="checkbox" id="[% bc.categorycode %]" name="[% bc.categorycode %]" />
148
                                [% END %]
149
                                <span class="hint">[% bc.codedescription %]</span>
150
                            </li>
151
                        [% END %]
152
                    [% END %]
153
                <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>
154
                </fieldset>
155
            </ol>
156
        </fieldset>
157
    [% END %]
158
129
	<fieldset class="rows">
159
	<fieldset class="rows">
130
	<ol>
160
	<ol>
131
        <li><label for="branchaddress1">Address line 1: </label><input type="text" name="branchaddress1" id="branchaddress1" size="60" value="[% branchaddress1 |html %]" /></li>
161
        <li><label for="branchaddress1">Address line 1: </label><input type="text" name="branchaddress1" id="branchaddress1" size="60" value="[% branchaddress1 |html %]" /></li>
Lines 260-348 tinyMCE.init({ Link Here
260
	<div class="dialog message">There are no libraries defined. <a href="/cgi-bin/koha/admin/branches.pl?op=add">Start defining libraries</a>.</div>
290
	<div class="dialog message">There are no libraries defined. <a href="/cgi-bin/koha/admin/branches.pl?op=add">Start defining libraries</a>.</div>
261
	[% END %]
291
	[% END %]
262
292
263
   [% IF ( branchcategories ) %]
293
    <h3>Search domain groups</h3>
264
   [% FOREACH branchcategorie IN branchcategories %]
294
    [% IF branch_categories.searchdomain %]
265
    <h3>Group(s):  [% IF ( branchcategorie.properties ) %]Properties[% ELSE %][% IF ( branchcategorie.searchdomain ) %]Search domain[% END %][% END %]</h3>
295
        <table>
266
    [% IF ( branchcategorie.catloop ) %]
296
            <thead>
267
      <table>
297
                <tr>
268
        <thead>
298
                    <th>Name</th>
269
          <tr>
299
                    <th>Code</th>
270
            <th>Name</th>
300
                    <th>Description</th>
271
            <th>Code</th>
301
                    <th>&nbsp;</th>
272
            <th>Description</th>
302
                    <th>&nbsp;</th>
273
            <th>&nbsp;</th>
303
                  </tr>
274
            <th>&nbsp;</th>
304
            </thead>
275
          </tr>
305
            <tbody>
276
        </thead>
306
                [% FOREACH bc IN branch_categories.searchdomain %]
277
        <tbody>
307
                    <tr>
278
          [% FOREACH catloo IN branchcategorie.catloop %]
308
                      <td>[% bc.value.categoryname %]</td>
279
            <tr>
309
                      <td>[% bc.key %]</td>
280
              <td>[% catloo.categoryname %]</td>
310
                      <td>[% bc.value.codedescription %]</td>
281
              <td>[% catloo.categorycode %]</td>
311
                      <td>
282
              <td>[% catloo.codedescription %]</td>
312
                        <a href="?op=editcategory&amp;categorycode=[% bc.key |url %]">Edit</a>
283
              <td>
313
                      </td>
284
                <a href="[% catloo.action %]?op=editcategory&amp;categorycode=[% catloo.categorycode |url %]">Edit</a>
314
                      <td>
285
              </td>
315
                        <a href="?op=delete_category&amp;categorycode=[% bc.key |url %]">Delete</a>
286
              <td>
316
                      </td>
287
                <a href="[% catloo.action %]?op=delete_category&amp;categorycode=[% catloo.categorycode |url %]">Delete</a>
317
                    </tr>
288
              </td>
318
                [% END %]
289
            </tr>
319
            </tbody>
290
          [% END %]
320
        </table>
291
        </tbody>
321
    [% ELSE %]
292
      </table>
322
        No search domain groups defined.
323
    [% END %]
324
    <a href="/cgi-bin/koha/admin/branches.pl?op=editcategory">Add a new group</a>.
325
326
    <h3>Independent library groups:</h3>
327
    [% IF branch_categories.independent_group %]
328
        <table>
329
            <thead>
330
                <tr>
331
                    <th>Name</th>
332
                    <th>Code</th>
333
                    <th>Description</th>
334
                    <th>&nbsp;</th>
335
                    <th>&nbsp;</th>
336
                  </tr>
337
            </thead>
338
            <tbody>
339
                [% FOREACH bc IN branch_categories.independent_group %]
340
                    <tr>
341
                      <td>[% bc.value.categoryname %]</td>
342
                      <td>[% bc.key %]</td>
343
                      <td>[% bc.value.codedescription %]</td>
344
                      <td>
345
                        <a href="?op=editcategory&amp;categorycode=[% bc.key |url %]">Edit</a>
346
                      </td>
347
                      <td>
348
                        <a href="?op=delete_category&amp;categorycode=[% bc.key |url %]">Delete</a>
349
                      </td>
350
                    </tr>
351
                [% END %]
352
            </tbody>
353
        </table>
293
    [% ELSE %]
354
    [% ELSE %]
294
      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>.
355
        No independent library groups defined.
295
    [% END %]
356
    [% END %]
296
  [% END %]
357
    <a href="/cgi-bin/koha/admin/branches.pl?op=editcategory">Add a new group</a>.
297
  [% ELSE %]
298
    <p>No groups defined.</p>
299
  [% END %] <!-- NAME="branchcategories" -->
300
[% END %]
358
[% END %]
301
359
302
[% IF ( editcategory ) %]
360
[% IF ( editcategory ) %]
303
    <h3>[% IF ( categorycode ) %]Edit group [% categorycode %][% ELSE %]Add group[% END %]</h3>
361
    <h3>[% IF ( category ) %]Edit group [% category.categorycode %][% ELSE %]Add group[% END %]</h3>
304
    <form action="[% action %]" name="Aform" method="post">
362
    <form action="[% action %]" name="Aform" method="post">
305
    <input type="hidden" name="op" value="addcategory_validate" />
363
    <input type="hidden" name="op" value="addcategory_validate" />
306
	[% IF ( categorycode ) %]
364
    [% IF ( category.categorycode ) %]
307
	<input type="hidden" name="add" value="0">
365
        <input type="hidden" name="add" value="0">
308
	[% ELSE %]
366
    [% ELSE %]
309
	<input type="hidden" name="add" value="1">
367
        <input type="hidden" name="add" value="1">
310
	[% END %]
368
    [% END %]
311
    <fieldset class="rows">
369
    <fieldset class="rows">
312
370
313
        <ol><li>
371
        <ol><li>
314
                [% IF ( categorycode ) %]
372
                [% IF ( category.categorycode ) %]
315
				<span class="label">Category code: </span>
373
				<span class="label">Category code: </span>
316
                    <input type="hidden" name="categorycode" id="categorycode" value="[% categorycode |html %]" />
374
                    <input type="hidden" name="categorycode" id="categorycode" value="[% category.categorycode | html %]" />
317
                    [% categorycode %]
375
                    [% category.categorycode %]
318
                [% ELSE %]
376
                [% ELSE %]
319
                <label for="categorycode">Category code:</label>
377
                    <label for="categorycode">Category code:</label>
320
                    <input type="text" name="categorycode" id="categorycode" size="10" maxlength="10" value="[% categorycode |html %]" />
378
                    <input type="text" name="categorycode" id="categorycode" size="10" maxlength="10" value="[% categorycode | html %]" />
321
                [% END %]
379
                [% END %]
322
            </li>
380
            </li>
323
        <li>
381
        <li>
324
            <label for="categoryname">Name: </label>
382
            <label for="categoryname">Name: </label>
325
            <input type="text" name="categoryname" id="categoryname" size="32" maxlength="32" value="[% categoryname |html %]" />
383
            <input type="text" name="categoryname" id="categoryname" size="32" maxlength="32" value="[% category.categoryname | html %]" />
326
        </li>
384
        </li>
327
        <li>
385
        <li>
328
            <label for="codedescription">Description: </label>
386
            <label for="codedescription">Description: </label>
329
            <input type="text" name="codedescription" id="codedescription" size="70" value="[% codedescription |html %]" />
387
            <input type="text" name="codedescription" id="codedescription" size="70" value="[% category.codedescription | html %]" />
330
        </li>
388
        </li>
331
		<li>
389
		<li>
332
        <label for="categorytype">Category type: </label>
390
        <label for="categorytype">Category type: </label>
333
            <select id="categorytype" name="categorytype">
391
            <select id="categorytype" name="categorytype">
334
            [% FOREACH categorytyp IN categorytype %]
392
                [% IF ( category.categorytype == 'searchdomain' ) %]
335
                [% IF ( categorytyp.selected ) %]
393
                    <option value="searchdomain" selected="selected">Search domain</option>
336
                    <option value="[% categorytyp.type %]" selected="selected">
337
                [% ELSE %]
394
                [% ELSE %]
338
                    <option value="[% categorytyp.type %]">
395
                    <option value="searchdomain">Search domain</option>
339
                [% END %] [% categorytyp.type %]</option>
396
                [% END %]
340
            [% END %]
397
398
                [% IF ( category.categorytype == 'independent_group' ) %]
399
                    <option value="independent_group" selected="selected">Independent group</option>
400
                [% ELSE %]
401
                    <option value="independent_group">Independent group</option>
402
                [% END %]
341
            </select>
403
            </select>
342
		</li>
404
		</li>
343
        <li>
405
        <li>
344
            <label for="show_in_pulldown">Show in search pulldown: </label>
406
            <label for="show_in_pulldown">Show in search pulldown: </label>
345
            [% IF ( show_in_pulldown ) %]
407
            [% IF ( category.show_in_pulldown ) %]
346
                <input type="checkbox" name="show_in_pulldown" id="show_in_pulldown" checked="checked"/>
408
                <input type="checkbox" name="show_in_pulldown" id="show_in_pulldown" checked="checked"/>
347
            [% ELSE %]
409
            [% ELSE %]
348
                <input type="checkbox" name="show_in_pulldown" id="show_in_pulldown" />
410
                <input type="checkbox" name="show_in_pulldown" id="show_in_pulldown" />
Lines 350-356 tinyMCE.init({ Link Here
350
        </li>
412
        </li>
351
		</ol>
413
		</ol>
352
    </fieldset>
414
    </fieldset>
353
	<fieldset class="action"><input type="submit" value="Update" /></fieldset>
415
  <fieldset class="action">
416
        [% IF category %]
417
            <input type="submit" value="Update group" />
418
        [% ELSE %]
419
            <input type="submit" value="Add group" />
420
        [% END %]
421
    </fieldset>
354
    </form>
422
    </form>
355
[% END %]
423
[% END %]
356
424
(-)a/members/deletemem.pl (-4 / +10 lines)
Lines 91-101 if ($bor->{category_type} eq "S") { Link Here
91
    }
91
    }
92
}
92
}
93
93
94
if (C4::Context->preference("IndependentBranches")) {
94
if ( C4::Context->preference("IndependentBranches") ) {
95
    my $userenv = C4::Context->userenv;
96
    if ( !C4::Context->IsSuperLibrarian() && $bor->{'branchcode'}){
95
    if ( !C4::Context->IsSuperLibrarian() && $bor->{'branchcode'}){
97
        unless ($userenv->{branch} eq $bor->{'branchcode'}){
96
        unless (
98
            print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_OTHERLIBRARY");
97
            GetIndependentGroupModificationRights(
98
                { for => $bor->{'branchcode'} }
99
            )
100
          )
101
        {
102
            print $input->redirect(
103
                "/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_OTHERLIBRARY"
104
            );
99
            exit;
105
            exit;
100
        }
106
        }
101
    }
107
    }
(-)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 178-191 my $cat1 = { Link Here
178
    categorycode     => 'CAT1',
178
    categorycode     => 'CAT1',
179
    categoryname     => 'catname1',
179
    categoryname     => 'catname1',
180
    codedescription  => 'catdesc1',
180
    codedescription  => 'catdesc1',
181
    categorytype     => 'cattype1',
181
    categorytype     => 'searchdomain',
182
    show_in_pulldown => 1
182
    show_in_pulldown => 1
183
};
183
};
184
my $cat2 = {
184
my $cat2 = {
185
    add              => 1,
185
    add              => 1,
186
    categorycode     => 'CAT2',
186
    categorycode     => 'CAT2',
187
    categoryname     => 'catname2',
187
    categoryname     => 'catname2',
188
    categorytype     => 'catype2',
188
    categorytype     => 'searchdomain',
189
    codedescription  => 'catdesc2',
189
    codedescription  => 'catdesc2',
190
    show_in_pulldown => 1
190
    show_in_pulldown => 1
191
};
191
};
Lines 194-200 my %new_category = ( Link Here
194
    categorycode     => 'LIBCATCODE',
194
    categorycode     => 'LIBCATCODE',
195
    categoryname     => 'library category name',
195
    categoryname     => 'library category name',
196
    codedescription  => 'library category code description',
196
    codedescription  => 'library category code description',
197
    categorytype     => 'searchdomain',
197
    categorytype     => 'independent_group',
198
    show_in_pulldown => 1,
198
    show_in_pulldown => 1,
199
);
199
);
200
200
Lines 343-349 is( CheckCategoryUnique('CAT_NO_EXISTS'), 1, 'CAT_NO_EXISTS doesnt exist' ); Link Here
343
343
344
#Test GetCategoryTypes
344
#Test GetCategoryTypes
345
my @category_types = GetCategoryTypes();
345
my @category_types = GetCategoryTypes();
346
is_deeply(\@category_types, [ 'searchdomain', 'properties' ], 'received expected library category types');
346
is_deeply(\@category_types, [ 'searchdomain', 'independent_groups' ], 'received expected library category types');
347
347
348
$categories = GetBranchCategories(undef, undef, 'LIBCATCODE');
348
$categories = GetBranchCategories(undef, undef, 'LIBCATCODE');
349
is_deeply($categories, [ {%$cat1}, {%$cat2},{ %new_category, selected => 1 } ], 'retrieve expected, eselected library category (bug 10515)');
349
is_deeply($categories, [ {%$cat1}, {%$cat2},{ %new_category, selected => 1 } ], 'retrieve expected, eselected library category (bug 10515)');
Lines 355-360 is_deeply($categories, [ {%$cat1}, {%$cat2},{ %new_category, selected => 1 } ], Link Here
355
my $loop = GetBranchesLoop;
355
my $loop = GetBranchesLoop;
356
is( scalar(@$loop), GetBranchesCount(), 'There is the right number of branches' );
356
is( scalar(@$loop), GetBranchesCount(), 'There is the right number of branches' );
357
357
358
# Test GetIndependentGroupModificationRights
359
my @branches_bra = GetIndependentGroupModificationRights({ branch => 'BRA' });
360
is_deeply( \@branches_bra, [ 'BRA' ], 'Library with no group only has rights for its own branch' );
361
362
my $string = GetIndependentGroupModificationRights({ branch => 'BRA', stringify => 1 });
363
ok( $string eq q{'BRA'}, "String returns correctly" );
364
365
ok( GetIndependentGroupModificationRights({ branch => 'BRA', for => 'BRA' }), 'Boolean test for BRA rights to BRA returns true' );
366
ok( !GetIndependentGroupModificationRights({ branch => 'BRA', for => 'BRB' }), 'Boolean test for BRA rights to BRB returns false' );
367
ok( !GetIndependentGroupModificationRights({ branch => 'BRA', for => 'BRC' }), 'Boolean test for BRA rights to BRC returns false' );
368
ok( GetIndependentGroupModificationRights({ branch => 'BRB', for => 'BRB' }), 'Boolean test for BRB rights to BRB returns true' );
369
ok( !GetIndependentGroupModificationRights({ branch => 'BRB', for => 'BRA' }), 'Boolean test for BRB rights to BRA returns false' );
370
ok( !GetIndependentGroupModificationRights({ branch => 'BRB', for => 'BRC' }), 'Boolean test for BRB rights to BRC returns false' );
371
ok( GetIndependentGroupModificationRights({ branch => 'BRC', for => 'BRC' }), 'Boolean test for BRC rights to BRC returns true' );
372
ok( !GetIndependentGroupModificationRights({ branch => 'BRC', for => 'BRA'}), 'Boolean test for BRC rights to BRA returns false' );
373
ok( !GetIndependentGroupModificationRights({ branch => 'BRC', for => 'BRB'}), 'Boolean test for BRC rights to BRB returns false' );
374
375
ModBranch({
376
    branchcode     => 'BRA',
377
    branchname     => 'BranchA',
378
    LIBCATCODE     => 1,
379
});
380
ModBranch({
381
    branchcode     => 'BRB',
382
    branchname     => 'BranchB',
383
    LIBCATCODE     => 1,
384
});
385
386
@branches_bra = GetIndependentGroupModificationRights({ branch => 'BRA' });
387
is_deeply( \@branches_bra, [ 'BRA', 'BRB' ], 'Libraries in LIBCATCODE returned correctly' );
388
389
$string = GetIndependentGroupModificationRights({ branch => 'BRA', stringify => 1 });
390
ok( $string eq q{'BRA','BRB'}, "String returns correctly" );
391
392
ok( GetIndependentGroupModificationRights({ branch => 'BRA', for => 'BRA' }), 'Boolean test for BRA rights to BRA returns true' );
393
ok( GetIndependentGroupModificationRights({ branch => 'BRA', for => 'BRB'}), 'Boolean test for BRA rights to BRB returns true' );
394
ok( !GetIndependentGroupModificationRights({ branch => 'BRA', for => 'BRC'}), 'Boolean test for BRA rights to BRC returns false' );
395
ok( GetIndependentGroupModificationRights({ branch => 'BRB', for => 'BRB' }), 'Boolean test for BRB rights to BRB returns true' );
396
ok( GetIndependentGroupModificationRights({ branch => 'BRB', for => 'BRA'}), 'Boolean test for BRB rights to BRA returns true' );
397
ok( !GetIndependentGroupModificationRights({ branch => 'BRB', for => 'BRC'}), 'Boolean test for BRB rights to BRC returns false' );
398
ok( GetIndependentGroupModificationRights({ branch => 'BRC', for => 'BRC' }), 'Boolean test for BRC rights to BRC returns true' );
399
ok( !GetIndependentGroupModificationRights({ branch => 'BRC', for => 'BRA'}), 'Boolean test for BRC rights to BRA returns false' );
400
ok( !GetIndependentGroupModificationRights({ branch => 'BRC', for => 'BRB'}), 'Boolean test for BRC rights to BRB returns false' );
401
402
ModBranch({
403
    branchcode     => 'BRC',
404
    branchname     => 'BranchC',
405
    LIBCATCODE     => 1,
406
});
407
408
@branches_bra = GetIndependentGroupModificationRights({ branch => 'BRA' });
409
is_deeply( \@branches_bra, [ 'BRA', 'BRB', 'BRC' ], 'Library with no group only has rights for its own branch' );
410
411
ok( GetIndependentGroupModificationRights({ branch => 'BRA', for => 'BRA' }), 'Boolean test for BRA rights to BRA returns true' );
412
ok( GetIndependentGroupModificationRights({ branch => 'BRA', for => 'BRB'}), 'Boolean test for BRA rights to BRB returns true' );
413
ok( GetIndependentGroupModificationRights({ branch => 'BRA', for => 'BRC'}), 'Boolean test for BRA rights to BRC returns true' );
414
ok( GetIndependentGroupModificationRights({ branch => 'BRB', for => 'BRB' }), 'Boolean test for BRB rights to BRB returns true' );
415
ok( GetIndependentGroupModificationRights({ branch => 'BRB', for => 'BRA'}), 'Boolean test for BRB rights to BRA returns true' );
416
ok( GetIndependentGroupModificationRights({ branch => 'BRB', for => 'BRC'}), 'Boolean test for BRB rights to BRC returns true' );
417
ok( GetIndependentGroupModificationRights({ branch => 'BRC', for => 'BRC' }), 'Boolean test for BRC rights to BRC returns true' );
418
ok( GetIndependentGroupModificationRights({ branch => 'BRC', for => 'BRA'}), 'Boolean test for BRC rights to BRA returns true' );
419
ok( GetIndependentGroupModificationRights({ branch => 'BRC', for => 'BRA'}), 'Boolean test for BRC rights to BRB returns true' );
420
421
$string = GetIndependentGroupModificationRights({ branch => 'BRA', stringify => 1 });
422
ok( $string eq q{'BRA','BRB','BRC'}, "String returns correctly" );
423
358
# End transaction
424
# End transaction
359
$dbh->rollback;
425
$dbh->rollback;
360
426
361
- 

Return to bug 10276