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

(-)a/C4/Acquisition.pm (-7 / +80 lines)
Lines 33-38 use Koha::DateUtils qw( dt_from_string output_pref ); Link Here
33
use Koha::Acquisition::Order;
33
use Koha::Acquisition::Order;
34
use Koha::Acquisition::Bookseller;
34
use Koha::Acquisition::Bookseller;
35
use Koha::Number::Price;
35
use Koha::Number::Price;
36
use C4::Branch qw(GetIndependentGroupModificationRights);
36
37
37
use Time::localtime;
38
use Time::localtime;
38
use HTML::Entities;
39
use HTML::Entities;
Lines 1893-1898 sub TransferOrder { Link Here
1893
1894
1894
=head2 FUNCTIONS ABOUT PARCELS
1895
=head2 FUNCTIONS ABOUT PARCELS
1895
1896
1897
=cut
1898
1899
#------------------------------------------------------------#
1900
1901
=head3 GetParcel
1902
1903
  @results = &GetParcel($booksellerid, $code, $date);
1904
1905
Looks up all of the received items from the supplier with the given
1906
bookseller ID at the given date, for the given code (bookseller Invoice number). Ignores cancelled and completed orders.
1907
1908
C<@results> is an array of references-to-hash. The keys of each element are fields from
1909
the aqorders, biblio, and biblioitems tables of the Koha database.
1910
1911
C<@results> is sorted alphabetically by book title.
1912
1913
=cut
1914
1915
sub GetParcel {
1916
    #gets all orders from a certain supplier, orders them alphabetically
1917
    my ( $supplierid, $code, $datereceived ) = @_;
1918
    my $dbh     = C4::Context->dbh;
1919
    my @results = ();
1920
    $code .= '%'
1921
    if $code;  # add % if we search on a given code (otherwise, let him empty)
1922
    my $strsth ="
1923
        SELECT  authorisedby,
1924
                creationdate,
1925
                aqbasket.basketno,
1926
                closedate,surname,
1927
                firstname,
1928
                aqorders.biblionumber,
1929
                aqorders.ordernumber,
1930
                aqorders.parent_ordernumber,
1931
                aqorders.quantity,
1932
                aqorders.quantityreceived,
1933
                aqorders.unitprice,
1934
                aqorders.listprice,
1935
                aqorders.rrp,
1936
                aqorders.ecost,
1937
                aqorders.gstrate,
1938
                biblio.title
1939
        FROM aqorders
1940
        LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno
1941
        LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
1942
        LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber
1943
        LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid
1944
        WHERE
1945
            aqbasket.booksellerid = ?
1946
            AND aqinvoices.invoicenumber LIKE ?
1947
            AND aqorders.datereceived = ? ";
1948
1949
    my @query_params = ( $supplierid, $code, $datereceived );
1950
    if ( C4::Context->preference("IndependentBranches") ) {
1951
        unless ( C4::Context->IsSuperLibrarian() ) {
1952
            my $branches =
1953
              GetIndependentGroupModificationRights( { stringify => 1 } );
1954
            $strsth .= " AND ( borrowers.branchcode IN ( $branches ) OR borrowers.branchcode  = '')";
1955
        }
1956
    }
1957
    $strsth .= " ORDER BY aqbasket.basketno";
1958
    my $result_set = $dbh->selectall_arrayref(
1959
        $strsth,
1960
        { Slice => {} },
1961
        @query_params);
1962
1963
    return @{$result_set};
1964
}
1965
1966
#------------------------------------------------------------#
1967
1896
=head3 GetParcels
1968
=head3 GetParcels
1897
1969
1898
  $results = &GetParcels($bookseller, $order, $code, $datefrom, $dateto);
1970
  $results = &GetParcels($bookseller, $order, $code, $datefrom, $dateto);
Lines 2094-2101 sub GetLateOrders { Link Here
2094
    }
2166
    }
2095
    if (C4::Context->preference("IndependentBranches")
2167
    if (C4::Context->preference("IndependentBranches")
2096
            && !C4::Context->IsSuperLibrarian() ) {
2168
            && !C4::Context->IsSuperLibrarian() ) {
2097
        $from .= ' AND borrowers.branchcode LIKE ? ';
2169
        my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
2098
        push @query_params, C4::Context->userenv->{branch};
2170
        $from .= qq{ AND borrowers.branchcode IN ( $branches ) };
2099
    }
2171
    }
2100
    $from .= " AND orderstatus <> 'cancelled' ";
2172
    $from .= " AND orderstatus <> 'cancelled' ";
2101
    my $query = "$select $from $having\nORDER BY latesince, basketno, borrowers.branchcode, supplier";
2173
    my $query = "$select $from $having\nORDER BY latesince, basketno, borrowers.branchcode, supplier";
Lines 2319-2329 sub GetHistory { Link Here
2319
    }
2391
    }
2320
2392
2321
2393
2322
    if ( C4::Context->preference("IndependentBranches") ) {
2394
    if ( C4::Context->preference("IndependentBranches")
2323
        unless ( C4::Context->IsSuperLibrarian() ) {
2395
        && !C4::Context->IsSuperLibrarian() )
2324
            $query .= " AND (borrowers.branchcode = ? OR borrowers.branchcode ='' ) ";
2396
    {
2325
            push @query_params, C4::Context->userenv->{branch};
2397
        my $branches =
2326
        }
2398
          GetIndependentGroupModificationRights( { stringify => 1 } );
2399
        $query .= qq{ AND ( borrowers.branchcode = ? OR borrowers.branchcode IN ( $branches ) ) };
2327
    }
2400
    }
2328
    $query .= " ORDER BY id";
2401
    $query .= " ORDER BY id";
2329
2402
(-)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 368-374 the categories were already here, and minimally used. Link Here
368
373
369
	#TODO  manage category types.  rename possibly to 'agency domains' ? as borrowergroups are called categories.
374
	#TODO  manage category types.  rename possibly to 'agency domains' ? as borrowergroups are called categories.
370
sub GetCategoryTypes {
375
sub GetCategoryTypes {
371
	return ( 'searchdomain','properties');
376
 return ( 'searchdomain','independent_groups');
372
}
377
}
373
378
374
=head2 GetBranch
379
=head2 GetBranch
Lines 423-428 sub GetBranchesInCategory { Link Here
423
	return( \@branches );
428
	return( \@branches );
424
}
429
}
425
430
431
=head2 GetIndependentGroupModificationRights
432
433
    GetIndependentGroupModificationRights(
434
                                           {
435
                                               branch => $this_branch,
436
                                               for => $other_branch,
437
                                               stringify => 1,
438
                                           }
439
                                          );
440
441
    Returns a list of branches this branch shares a common
442
    independent group with.
443
444
    If 'branch' is not provided, it will be looked up via
445
    C4::Context->userenv->{branch}.
446
447
    If 'for' is provided, the lookup is limited to that branch.
448
449
    If called in a list context, returns a list of
450
    branchcodes ( including $this_branch ).
451
452
    If called in a scalar context, it returns
453
    a count of matching branchcodes. Returns 1 if
454
455
    If stringify param is passed, the return value will
456
    be a string of the comma delimited branchcodes. This
457
    is useful for "branchcode IN $branchcodes" clauses
458
    in SQL queries.
459
460
    $this_branch and $other_branch are equal for efficiency.
461
462
    So you can write:
463
    my @branches = GetIndependentGroupModificationRights();
464
    or something like:
465
    if ( GetIndependentGroupModificationRights( { for => $other_branch } ) ) { do_stuff(); }
466
467
=cut
468
469
sub GetIndependentGroupModificationRights {
470
    my ($params) = @_;
471
472
    my $this_branch  = $params->{branch};
473
    my $other_branch = $params->{for};
474
    my $stringify    = $params->{stringify};
475
476
    $this_branch ||= C4::Context->userenv->{branch};
477
478
    carp("No branch found!") unless ($this_branch);
479
480
    return 1 if ( $this_branch eq $other_branch );
481
482
    my $sql = q{
483
        SELECT DISTINCT(branchcode)
484
        FROM branchrelations
485
        JOIN branchcategories USING ( categorycode )
486
        WHERE categorycode IN (
487
            SELECT categorycode
488
            FROM branchrelations
489
            WHERE branchcode = ?
490
        )
491
        AND branchcategories.categorytype = 'independent_group'
492
    };
493
494
    my @params;
495
    push( @params, $this_branch );
496
497
    if ($other_branch) {
498
        $sql .= q{ AND branchcode = ? };
499
        push( @params, $other_branch );
500
    }
501
502
    my $dbh = C4::Context->dbh;
503
    my @branchcodes = @{ $dbh->selectcol_arrayref( $sql, {}, @params ) };
504
505
    if ( $stringify ) {
506
        if ( @branchcodes ) {
507
            return join( ',', map { qq{'$_'} } @branchcodes );
508
        } else {
509
            return qq{'$this_branch'};
510
        }
511
    }
512
513
    if ( wantarray() ) {
514
        if ( @branchcodes ) {
515
            return @branchcodes;
516
        } else {
517
            return $this_branch;
518
        }
519
    } else {
520
        return scalar(@branchcodes);
521
    }
522
}
523
426
=head2 GetBranchInfo
524
=head2 GetBranchInfo
427
525
428
$results = GetBranchInfo($branchcode);
526
$results = GetBranchInfo($branchcode);
(-)a/C4/Circulation.pm (-5 / +16 lines)
Lines 911-924 sub CanBookBeIssued { Link Here
911
        $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
911
        $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
912
    }
912
    }
913
    if ( C4::Context->preference("IndependentBranches") ) {
913
    if ( C4::Context->preference("IndependentBranches") ) {
914
        my $userenv = C4::Context->userenv;
915
        unless ( C4::Context->IsSuperLibrarian() ) {
914
        unless ( C4::Context->IsSuperLibrarian() ) {
916
            if ( $item->{C4::Context->preference("HomeOrHoldingBranch")} ne $userenv->{branch} ){
915
            unless (
916
                GetIndependentGroupModificationRights(
917
                    {
918
                        for => $item->{ C4::Context->preference(
919
                                "HomeOrHoldingBranch") }
920
                    }
921
                )
922
              )
923
            {
917
                $issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
924
                $issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
918
                $issuingimpossible{'itemhomebranch'} = $item->{C4::Context->preference("HomeOrHoldingBranch")};
925
                $issuingimpossible{'itemhomebranch'} =
926
                  $item->{ C4::Context->preference("HomeOrHoldingBranch") };
919
            }
927
            }
920
            $needsconfirmation{BORRNOTSAMEBRANCH} = GetBranchName( $borrower->{'branchcode'} )
928
921
              if ( $borrower->{'branchcode'} ne $userenv->{branch} );
929
            $needsconfirmation{BORRNOTSAMEBRANCH} =
930
              GetBranchName( $borrower->{'branchcode'} )
931
              if (
932
                $borrower->{'branchcode'} ne C4::Context->userenv->{branch} );
922
        }
933
        }
923
    }
934
    }
924
    #
935
    #
(-)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 1333-1342 sub GetItemsInfo { Link Here
1333
    my $serial;
1334
    my $serial;
1334
1335
1335
    my $userenv = C4::Context->userenv;
1336
    my $userenv = C4::Context->userenv;
1336
    my $want_not_same_branch = C4::Context->preference("IndependentBranches") && !C4::Context->IsSuperLibrarian();
1337
    while ( my $data = $sth->fetchrow_hashref ) {
1337
    while ( my $data = $sth->fetchrow_hashref ) {
1338
        if ( $data->{borrowernumber} && $want_not_same_branch) {
1338
        if ( C4::Context->preference("IndependentBranches") && $userenv ) {
1339
            $data->{'NOTSAMEBRANCH'} = $data->{'bcode'} ne $userenv->{branch};
1339
            unless ( C4::Context->IsSuperLibrarian()
1340
                || GetIndependentGroupModificationRights( { for => $data->{'bcode'} } ) )
1341
            {
1342
                $data->{'NOTSAMEBRANCH'} = $data->{'bcode'} ne $userenv->{branch};
1343
            }
1340
        }
1344
        }
1341
1345
1342
        $serial ||= $data->{'serial'};
1346
        $serial ||= $data->{'serial'};
Lines 2279-2290 sub DelItemCheck { Link Here
2279
2283
2280
    my $item = GetItem($itemnumber);
2284
    my $item = GetItem($itemnumber);
2281
2285
2282
    if ($onloan){
2286
    if ($onloan) {
2283
        $error = "book_on_loan" 
2287
        $error = "book_on_loan";
2284
    }
2288
    }
2285
    elsif ( !C4::Context->IsSuperLibrarian()
2289
    elsif (
2286
        and C4::Context->preference("IndependentBranches")
2290
           !C4::Context->IsSuperLibrarian()
2287
        and ( C4::Context->userenv->{branch} ne $item->{'homebranch'} ) )
2291
        && C4::Context->preference("IndependentBranches")
2292
        && !GetIndependentGroupModificationRights(
2293
            {
2294
                for => $item->{ C4::Context->preference("HomeOrHoldingBranch") }
2295
            }
2296
        )
2297
      )
2288
    {
2298
    {
2289
        $error = "not_same_branch";
2299
        $error = "not_same_branch";
2290
    }
2300
    }
Lines 2959-2966 sub PrepareItemrecordDisplay { Link Here
2959
                    if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
2969
                    if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
2960
                        if (   ( C4::Context->preference("IndependentBranches") )
2970
                        if (   ( C4::Context->preference("IndependentBranches") )
2961
                            && !C4::Context->IsSuperLibrarian() ) {
2971
                            && !C4::Context->IsSuperLibrarian() ) {
2962
                            my $sth = $dbh->prepare( "SELECT branchcode,branchname FROM branches WHERE branchcode = ? ORDER BY branchname" );
2972
                            my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
2963
                            $sth->execute( C4::Context->userenv->{branch} );
2973
                            my $sth = $dbh->prepare( "SELECT branchcode,branchname FROM branches WHERE branchcode IN ( $branches ) ORDER BY branchname" );
2974
                            $sth->execute();
2964
                            push @authorised_values, ""
2975
                            push @authorised_values, ""
2965
                              unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2976
                              unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2966
                            while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
2977
                            while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
(-)a/C4/Letters.pm (+1 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 ||= 'email';
210
    $message_transport_type ||= 'email';
211
211
212
    $branchcode ||= q{};
212
213
213
    if ( C4::Context->preference('IndependentBranches')
214
    if ( C4::Context->preference('IndependentBranches')
214
            and $branchcode
215
            and $branchcode
(-)a/C4/Members.pm (-47 / +65 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 44-49 use Text::Unaccent qw( unac_string ); Link Here
44
use Koha::AuthUtils qw(hash_password);
45
use Koha::AuthUtils qw(hash_password);
45
use Koha::Database;
46
use Koha::Database;
46
use Module::Load;
47
use Module::Load;
48
use C4::Branch qw( GetIndependentGroupModificationRights );
47
if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
49
if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
48
    load Koha::NorwegianPatronDB, qw( NLUpdateHashedPIN NLEncryptPIN NLSync );
50
    load Koha::NorwegianPatronDB, qw( NLUpdateHashedPIN NLEncryptPIN NLSync );
49
}
51
}
Lines 261-283 sub Search { Link Here
261
    # $showallbranches was not used at the time SearchMember() was mainstreamed into Search().
263
    # $showallbranches was not used at the time SearchMember() was mainstreamed into Search().
262
    # Mentioning for the reference
264
    # Mentioning for the reference
263
265
264
    if ( C4::Context->preference("IndependentBranches") ) { # && !$showallbranches){
266
    if ( C4::Context->preference("IndependentBranches") ) {
265
        if ( my $userenv = C4::Context->userenv ) {
267
        unless ( C4::Context->IsSuperLibrarian() ) {
266
            my $branch =  $userenv->{'branch'};
268
            $filter = clone($filter);    # Modify a copy only
267
            if ( !C4::Context->IsSuperLibrarian() && $branch ){
269
            my @branches = GetIndependentGroupModificationRights();
268
                if (my $fr = ref $filter) {
270
            if ( my $fr = ref $filter ) {
269
                    if ( $fr eq "HASH" ) {
271
                if ( $fr eq "HASH" ) {
270
                        $filter->{branchcode} = $branch;
272
                    $filter->{branchcode} = \@branches;
271
                    }
272
                    else {
273
                        foreach (@$filter) {
274
                            $_ = { '' => $_ } unless ref $_;
275
                            $_->{branchcode} = $branch;
276
                        }
277
                    }
278
                }
273
                }
279
                else {
274
                else {
280
                    $filter = { '' => $filter, branchcode => $branch };
275
                    foreach (@$filter) {
276
                        $_ = { '' => $_ } unless ref $_;
277
                        $_->{branchcode} = \@branches;
278
                    }
281
                }
279
                }
282
            }
280
            }
283
        }
281
        }
Lines 1411-1416 sub checkuniquemember { Link Here
1411
            ($dateofbirth) ?
1409
            ($dateofbirth) ?
1412
            "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?  and dateofbirth=?" :
1410
            "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?  and dateofbirth=?" :
1413
            "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?";
1411
            "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?";
1412
1413
    if ( C4::Context->preference('IndependentBranches') ) {
1414
        my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
1415
        $request .= " AND branchcode IN ( $branches )";
1416
    }
1417
1414
    my $sth = $dbh->prepare($request);
1418
    my $sth = $dbh->prepare($request);
1415
    if ($collectivity) {
1419
    if ($collectivity) {
1416
        $sth->execute( uc($surname) );
1420
        $sth->execute( uc($surname) );
Lines 2102-2114 sub GetBorrowersToExpunge { Link Here
2102
    my $filterdate     = $params->{'not_borrowered_since'};
2106
    my $filterdate     = $params->{'not_borrowered_since'};
2103
    my $filterexpiry   = $params->{'expired_before'};
2107
    my $filterexpiry   = $params->{'expired_before'};
2104
    my $filtercategory = $params->{'category_code'};
2108
    my $filtercategory = $params->{'category_code'};
2105
    my $filterbranch   = $params->{'branchcode'} ||
2109
    my $filterbranch   = $params->{'branchcode'};
2106
                        ((C4::Context->preference('IndependentBranches')
2110
    my @filterbranches =
2107
                             && C4::Context->userenv 
2111
      (      C4::Context->preference('IndependentBranches')
2108
                             && !C4::Context->IsSuperLibrarian()
2112
          && C4::Context->userenv
2109
                             && C4::Context->userenv->{branch})
2113
          && !C4::Context->IsSuperLibrarian()
2110
                         ? C4::Context->userenv->{branch}
2114
          && C4::Context->userenv->{branch} )
2111
                         : "");  
2115
      ? GetIndependentGroupModificationRights()
2116
      : ($filterbranch);
2112
2117
2113
    my $dbh   = C4::Context->dbh;
2118
    my $dbh   = C4::Context->dbh;
2114
    my $query = "
2119
    my $query = "
Lines 2123-2131 sub GetBorrowersToExpunge { Link Here
2123
        AND borrowernumber NOT IN (SELECT guarantorid FROM borrowers WHERE guarantorid IS NOT NULL AND guarantorid <> 0)
2128
        AND borrowernumber NOT IN (SELECT guarantorid FROM borrowers WHERE guarantorid IS NOT NULL AND guarantorid <> 0)
2124
   ";
2129
   ";
2125
    my @query_params;
2130
    my @query_params;
2126
    if ( $filterbranch && $filterbranch ne "" ) {
2131
    if ( @filterbranches ) {
2127
        $query.= " AND borrowers.branchcode = ? ";
2132
        my $placeholders = join( ',', ('?') x @filterbranches );
2128
        push( @query_params, $filterbranch );
2133
        $query.= " AND borrowers.branchcode IN ( $placeholders )";
2134
        push( @query_params, @filterbranches );
2129
    }
2135
    }
2130
    if ( $filterexpiry ) {
2136
    if ( $filterexpiry ) {
2131
        $query .= " AND dateexpiry < ? ";
2137
        $query .= " AND dateexpiry < ? ";
Lines 2168-2180 I<$result> is a ref to an array which all elements are a hasref. Link Here
2168
=cut
2174
=cut
2169
2175
2170
sub GetBorrowersWhoHaveNeverBorrowed {
2176
sub GetBorrowersWhoHaveNeverBorrowed {
2171
    my $filterbranch = shift || 
2177
    my $filterbranch = shift;
2172
                        ((C4::Context->preference('IndependentBranches')
2178
2173
                             && C4::Context->userenv 
2179
    my @filterbranches =
2174
                             && !C4::Context->IsSuperLibrarian()
2180
      (      C4::Context->preference('IndependentBranches')
2175
                             && C4::Context->userenv->{branch})
2181
          && C4::Context->userenv
2176
                         ? C4::Context->userenv->{branch}
2182
          && !C4::Context->IsSuperLibrarian()
2177
                         : "");  
2183
          && C4::Context->userenv->{branch} )
2184
      ? GetIndependentGroupModificationRights()
2185
      : ($filterbranch);
2186
2178
    my $dbh   = C4::Context->dbh;
2187
    my $dbh   = C4::Context->dbh;
2179
    my $query = "
2188
    my $query = "
2180
        SELECT borrowers.borrowernumber,max(timestamp) as latestissue
2189
        SELECT borrowers.borrowernumber,max(timestamp) as latestissue
Lines 2182-2191 sub GetBorrowersWhoHaveNeverBorrowed { Link Here
2182
          LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
2191
          LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
2183
        WHERE issues.borrowernumber IS NULL
2192
        WHERE issues.borrowernumber IS NULL
2184
   ";
2193
   ";
2194
2185
    my @query_params;
2195
    my @query_params;
2186
    if ($filterbranch && $filterbranch ne ""){ 
2196
    if (@filterbranches) {
2187
        $query.=" AND borrowers.branchcode= ?";
2197
        my $placeholders = join( ',', ('?') x @filterbranches );
2188
        push @query_params,$filterbranch;
2198
        $query .= " AND borrowers.branchcode IN ( $placeholders ) ";
2199
        push( @query_params, @filterbranches );
2189
    }
2200
    }
2190
    warn $query if $debug;
2201
    warn $query if $debug;
2191
  
2202
  
Lines 2218-2242 This hashref is containt the number of time this borrowers has borrowed before I Link Here
2218
sub GetBorrowersWithIssuesHistoryOlderThan {
2229
sub GetBorrowersWithIssuesHistoryOlderThan {
2219
    my $dbh  = C4::Context->dbh;
2230
    my $dbh  = C4::Context->dbh;
2220
    my $date = shift ||POSIX::strftime("%Y-%m-%d",localtime());
2231
    my $date = shift ||POSIX::strftime("%Y-%m-%d",localtime());
2221
    my $filterbranch = shift || 
2232
    my $filterbranch = shift;
2222
                        ((C4::Context->preference('IndependentBranches')
2233
2223
                             && C4::Context->userenv 
2234
    my @filterbranches =
2224
                             && !C4::Context->IsSuperLibrarian()
2235
      (      C4::Context->preference('IndependentBranches')
2225
                             && C4::Context->userenv->{branch})
2236
          && C4::Context->userenv
2226
                         ? C4::Context->userenv->{branch}
2237
          && !C4::Context->IsSuperLibrarian()
2227
                         : "");  
2238
          && C4::Context->userenv->{branch} )
2239
      ? GetIndependentGroupModificationRights()
2240
      : ($filterbranch);
2241
2228
    my $query = "
2242
    my $query = "
2229
       SELECT count(borrowernumber) as n,borrowernumber
2243
       SELECT count(borrowernumber) as n,borrowernumber
2230
       FROM old_issues
2244
       FROM old_issues
2231
       WHERE returndate < ?
2245
       WHERE returndate < ?
2232
         AND borrowernumber IS NOT NULL 
2246
         AND borrowernumber IS NOT NULL 
2233
    "; 
2247
    "; 
2248
2234
    my @query_params;
2249
    my @query_params;
2235
    push @query_params, $date;
2250
    push( @query_params, $date );
2236
    if ($filterbranch){
2251
2237
        $query.="   AND branchcode = ?";
2252
    if (@filterbranches) {
2238
        push @query_params, $filterbranch;
2253
        my $placeholders = join( ',', ('?') x @filterbranches );
2239
    }    
2254
        $query .= " AND branchcode IN ( $placeholders ) ";
2255
        push( @query_params, @filterbranches );
2256
    }
2257
2240
    $query.=" GROUP BY borrowernumber ";
2258
    $query.=" GROUP BY borrowernumber ";
2241
    warn $query if $debug;
2259
    warn $query if $debug;
2242
    my $sth = $dbh->prepare($query);
2260
    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 173-179 sub GetSerialInformation { Link Here
173
    my ($serialid) = @_;
174
    my ($serialid) = @_;
174
    my $dbh        = C4::Context->dbh;
175
    my $dbh        = C4::Context->dbh;
175
    my $query      = qq|
176
    my $query      = qq|
176
        SELECT serial.*, serial.notes as sernotes, serial.status as serstatus,subscription.*,subscription.subscriptionid as subsid
177
        SELECT serial.*,
178
               serial.notes as sernotes,
179
               serial.status as serstatus,
180
               subscription.*,
181
               subscription.subscriptionid as subsid
182
    |;
183
    if (   C4::Context->preference('IndependentBranches')
184
        && C4::Context->userenv
185
        && C4::Context->userenv->{'flags'} % 2 != 1
186
        && C4::Context->userenv->{'branch'} ) {
187
        my $branches = GetIndependentGroupModificationRights( { stringify => 1 } );
188
        $query .= qq|
189
            , ( ( subscription.branchcode NOT IN ( $branches ) ) AND subscription.branchcode <> '' AND subscription.branchcode IS NOT NULL ) AS cannotedit
190
        |;
191
    }
192
    $query .= qq|
177
        FROM   serial LEFT JOIN subscription ON subscription.subscriptionid=serial.subscriptionid
193
        FROM   serial LEFT JOIN subscription ON subscription.subscriptionid=serial.subscriptionid
178
        WHERE  serialid = ?
194
        WHERE  serialid = ?
179
    |;
195
    |;
Lines 276-293 subscription, subscriptionhistory, aqbooksellers.name, biblio.title Link Here
276
sub GetSubscription {
292
sub GetSubscription {
277
    my ($subscriptionid) = @_;
293
    my ($subscriptionid) = @_;
278
    my $dbh              = C4::Context->dbh;
294
    my $dbh              = C4::Context->dbh;
279
    my $query            = qq(
295
296
    my $query = qq|
280
        SELECT  subscription.*,
297
        SELECT  subscription.*,
281
                subscriptionhistory.*,
298
                subscriptionhistory.*,
282
                aqbooksellers.name AS aqbooksellername,
299
                aqbooksellers.name AS aqbooksellername,
283
                biblio.title AS bibliotitle,
300
                biblio.title AS bibliotitle,
284
                subscription.biblionumber as bibnum
301
                subscription.biblionumber as bibnum
302
    |;
303
304
    if (   C4::Context->preference('IndependentBranches')
305
        && C4::Context->userenv
306
        && C4::Context->userenv->{'flags'} % 2 != 1
307
        && C4::Context->userenv->{'branch'} )
308
    {
309
        my $branches =
310
          GetIndependentGroupModificationRights( { stringify => 1 } );
311
312
        $query .= qq|
313
            , ( ( subscription.branchcode NOT IN ( $branches ) ) AND subscription.branchcode <> '' AND subscription.branchcode IS NOT NULL ) AS cannotedit
314
        |;
315
    }
316
317
    $query .= qq|
285
       FROM subscription
318
       FROM subscription
286
       LEFT JOIN subscriptionhistory ON subscription.subscriptionid=subscriptionhistory.subscriptionid
319
       LEFT JOIN subscriptionhistory ON subscription.subscriptionid=subscriptionhistory.subscriptionid
287
       LEFT JOIN aqbooksellers ON subscription.aqbooksellerid=aqbooksellers.id
320
       LEFT JOIN aqbooksellers ON subscription.aqbooksellerid=aqbooksellers.id
288
       LEFT JOIN biblio ON biblio.biblionumber=subscription.biblionumber
321
       LEFT JOIN biblio ON biblio.biblionumber=subscription.biblionumber
289
       WHERE subscription.subscriptionid = ?
322
       WHERE subscription.subscriptionid = ?
290
    );
323
    |;
291
324
292
    $debug and warn "query : $query\nsubsid :$subscriptionid";
325
    $debug and warn "query : $query\nsubsid :$subscriptionid";
293
    my $sth = $dbh->prepare($query);
326
    my $sth = $dbh->prepare($query);
Lines 310-317 sub GetFullSubscription { Link Here
310
    return unless ($subscriptionid);
343
    return unless ($subscriptionid);
311
344
312
    my $dbh              = C4::Context->dbh;
345
    my $dbh              = C4::Context->dbh;
313
    my $query            = qq|
346
314
  SELECT    serial.serialid,
347
    my $query = qq|
348
        SELECT
349
            serial.serialid,
315
            serial.serialseq,
350
            serial.serialseq,
316
            serial.planneddate, 
351
            serial.planneddate, 
317
            serial.publisheddate, 
352
            serial.publisheddate, 
Lines 322-327 sub GetFullSubscription { Link Here
322
            biblio.title as bibliotitle,
357
            biblio.title as bibliotitle,
323
            subscription.branchcode AS branchcode,
358
            subscription.branchcode AS branchcode,
324
            subscription.subscriptionid AS subscriptionid
359
            subscription.subscriptionid AS subscriptionid
360
    |;
361
362
    if (   C4::Context->preference('IndependentBranches')
363
        && C4::Context->userenv
364
        && C4::Context->userenv->{'flags'} % 2 != 1
365
        && C4::Context->userenv->{'branch'} )
366
    {
367
        my $branches =
368
          GetIndependentGroupModificationRights( { stringify => 1 } );
369
370
        $query .= qq|
371
            , ( ( subscription.branchcode NOT IN ( $branches ) ) AND subscription.branchcode <> '' AND subscription.branchcode IS NOT NULL ) AS cannotedit
372
        |;
373
    }
374
375
    $query .= qq|
325
  FROM      serial 
376
  FROM      serial 
326
  LEFT JOIN subscription ON 
377
  LEFT JOIN subscription ON 
327
          (serial.subscriptionid=subscription.subscriptionid )
378
          (serial.subscriptionid=subscription.subscriptionid )
Lines 442-447 sub GetSubscriptionsFromBiblionumber { Link Here
442
        $subs->{ "periodicity" . $subs->{periodicity} }     = 1;
493
        $subs->{ "periodicity" . $subs->{periodicity} }     = 1;
443
        $subs->{ "numberpattern" . $subs->{numberpattern} } = 1;
494
        $subs->{ "numberpattern" . $subs->{numberpattern} } = 1;
444
        $subs->{ "status" . $subs->{'status'} }             = 1;
495
        $subs->{ "status" . $subs->{'status'} }             = 1;
496
        $subs->{'cannotedit'} = (
497
                 C4::Context->preference('IndependentBranches')
498
              && C4::Context->userenv
499
              && !C4::Context->IsSuperLibrarian()
500
              && C4::Context->userenv->{branch}
501
              && $subs->{branchcode}
502
              && GetIndependentGroupModificationRights(
503
                { for => $subs->{branchcode} }
504
              )
505
        );
445
506
446
        if ( $subs->{enddate} eq '0000-00-00' ) {
507
        if ( $subs->{enddate} eq '0000-00-00' ) {
447
            $subs->{enddate} = '';
508
            $subs->{enddate} = '';
Lines 466-473 sub GetSubscriptionsFromBiblionumber { Link Here
466
sub GetFullSubscriptionsFromBiblionumber {
527
sub GetFullSubscriptionsFromBiblionumber {
467
    my ($biblionumber) = @_;
528
    my ($biblionumber) = @_;
468
    my $dbh            = C4::Context->dbh;
529
    my $dbh            = C4::Context->dbh;
469
    my $query          = qq|
530
470
  SELECT    serial.serialid,
531
    my $query = qq|
532
        SELECT
533
            serial.serialid,
471
            serial.serialseq,
534
            serial.serialseq,
472
            serial.planneddate, 
535
            serial.planneddate, 
473
            serial.publisheddate, 
536
            serial.publisheddate, 
Lines 477-482 sub GetFullSubscriptionsFromBiblionumber { Link Here
477
            biblio.title as bibliotitle,
540
            biblio.title as bibliotitle,
478
            subscription.branchcode AS branchcode,
541
            subscription.branchcode AS branchcode,
479
            subscription.subscriptionid AS subscriptionid
542
            subscription.subscriptionid AS subscriptionid
543
    |;
544
545
    if (   C4::Context->preference('IndependentBranches')
546
        && C4::Context->userenv
547
        && C4::Context->userenv->{'flags'} != 1
548
        && C4::Context->userenv->{'branch'} )
549
    {
550
        my $branches =
551
          GetIndependentGroupModificationRights( { stringify => 1 } );
552
553
        $query .= qq|
554
            , ( ( subscription.branchcode NOT IN ( $branches ) ) AND subscription.branchcode <> '' AND subscription.branchcode IS NOT NULL ) AS cannotedit
555
        |;
556
    }
557
558
    $query .= qq|
480
  FROM      serial 
559
  FROM      serial 
481
  LEFT JOIN subscription ON 
560
  LEFT JOIN subscription ON 
482
          (serial.subscriptionid=subscription.subscriptionid)
561
          (serial.subscriptionid=subscription.subscriptionid)
Lines 2762-2768 sub can_show_subscription { Link Here
2762
sub _can_do_on_subscription {
2841
sub _can_do_on_subscription {
2763
    my ( $subscription, $userid, $permission ) = @_;
2842
    my ( $subscription, $userid, $permission ) = @_;
2764
    return 0 unless C4::Context->userenv;
2843
    return 0 unless C4::Context->userenv;
2844
2765
    my $flags = C4::Context->userenv->{flags};
2845
    my $flags = C4::Context->userenv->{flags};
2846
2766
    $userid ||= C4::Context->userenv->{'id'};
2847
    $userid ||= C4::Context->userenv->{'id'};
2767
2848
2768
    if ( C4::Context->preference('IndependentBranches') ) {
2849
    if ( C4::Context->preference('IndependentBranches') ) {
Lines 2771-2782 sub _can_do_on_subscription { Link Here
2771
              or
2852
              or
2772
              C4::Auth::haspermission( $userid, { serials => 'superserials' } )
2853
              C4::Auth::haspermission( $userid, { serials => 'superserials' } )
2773
              or (
2854
              or (
2774
                  C4::Auth::haspermission( $userid,
2855
                  C4::Auth::haspermission(
2775
                      { serials => $permission } )
2856
                      $userid, { serials => $permission }
2857
                  )
2776
                  and (  not defined $subscription->{branchcode}
2858
                  and (  not defined $subscription->{branchcode}
2777
                      or $subscription->{branchcode} eq ''
2859
                      or $subscription->{branchcode} eq ''
2778
                      or $subscription->{branchcode} eq
2860
                      or $subscription->{branchcode} eq
2779
                      C4::Context->userenv->{'branch'} )
2861
                      C4::Context->userenv->{'branch'} )
2862
              )
2863
              or GetIndependentGroupModificationRights(
2864
                  { for => $subscription->{branchcode} }
2780
              );
2865
              );
2781
    }
2866
    }
2782
    else {
2867
    else {
Lines 2784-2793 sub _can_do_on_subscription { Link Here
2784
          if C4::Context->IsSuperLibrarian()
2869
          if C4::Context->IsSuperLibrarian()
2785
              or
2870
              or
2786
              C4::Auth::haspermission( $userid, { serials => 'superserials' } )
2871
              C4::Auth::haspermission( $userid, { serials => 'superserials' } )
2787
              or C4::Auth::haspermission(
2872
              or C4::Auth::haspermission( $userid, { serials => $permission } )
2788
                  $userid, { serials => $permission }
2873
            ,;
2789
              ),
2790
        ;
2791
    }
2874
    }
2792
    return 0;
2875
    return 0;
2793
}
2876
}
(-)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 133-150 sub SearchSuggestion { Link Here
133
    }
134
    }
134
135
135
    # filter on user branch
136
    # filter on user branch
136
    if ( C4::Context->preference('IndependentBranches') ) {
137
    if (   C4::Context->preference('IndependentBranches')
137
        my $userenv = C4::Context->userenv;
138
        && !C4::Context->IsSuperLibrarian()
138
        if ($userenv) {
139
        && !$suggestion->{branchcode} )
139
            if ( !C4::Context->IsSuperLibrarian() && !$suggestion->{branchcode} )
140
    {
140
            {
141
        my $branches =
141
                push @sql_params, $$userenv{branch};
142
          GetIndependentGroupModificationRights( { stringify => 1 } );
142
                push @query,      q{
143
        push( @query, qq{ AND (suggestions.branchcode IN ( $branches ) OR suggestions.branchcode='') } );
143
                    AND (suggestions.branchcode=? OR suggestions.branchcode='')
144
    }
144
                };
145
    else {
145
            }
146
        }
147
    } else {
148
        if ( defined $suggestion->{branchcode} && $suggestion->{branchcode} ) {
146
        if ( defined $suggestion->{branchcode} && $suggestion->{branchcode} ) {
149
            unless ( $suggestion->{branchcode} eq '__ANY__' ) {
147
            unless ( $suggestion->{branchcode} eq '__ANY__' ) {
150
                push @sql_params, $suggestion->{branchcode};
148
                push @sql_params, $suggestion->{branchcode};
Lines 342-354 sub GetSuggestionByStatus { Link Here
342
340
343
    # filter on branch
341
    # filter on branch
344
    if ( C4::Context->preference("IndependentBranches") || $branchcode ) {
342
    if ( C4::Context->preference("IndependentBranches") || $branchcode ) {
345
        my $userenv = C4::Context->userenv;
343
        if (   C4::Context->userenv
346
        if ($userenv) {
344
            && C4::Context->preference("IndependentBranches")
347
            unless ( C4::Context->IsSuperLibrarian() ) {
345
            && !C4::Context->IsSuperLibrarian() )
348
                push @sql_params, $userenv->{branch};
346
        {
349
                $query .= q{ AND (U1.branchcode = ? OR U1.branchcode ='') };
347
350
            }
348
            my $branches =
349
              GetIndependentGroupModificationRights( { stringify => 1 } );
350
351
            $query .= qq{
352
                AND (U1.branchcode IN ( $branches ) OR U1.branchcode ='')
353
            };
351
        }
354
        }
355
352
        if ($branchcode) {
356
        if ($branchcode) {
353
            push @sql_params, $branchcode;
357
            push @sql_params, $branchcode;
354
            $query .= q{ AND (U1.branchcode = ? OR U1.branchcode ='') };
358
            $query .= q{ AND (U1.branchcode = ? OR U1.branchcode ='') };
Lines 394-405 sub CountSuggestion { Link Here
394
    if ( C4::Context->preference("IndependentBranches")
398
    if ( C4::Context->preference("IndependentBranches")
395
        && !C4::Context->IsSuperLibrarian() )
399
        && !C4::Context->IsSuperLibrarian() )
396
    {
400
    {
397
        my $query = q{
401
        my $branches =
402
          GetIndependentGroupModificationRights( { stringify => 1 } );
403
404
        my $query = qq{
398
            SELECT count(*)
405
            SELECT count(*)
399
            FROM suggestions
406
            FROM suggestions
400
                LEFT JOIN borrowers ON borrowers.borrowernumber=suggestions.suggestedby
407
                LEFT JOIN borrowers ON borrowers.borrowernumber=suggestions.suggestedby
401
            WHERE STATUS=?
408
            WHERE STATUS=?
402
                AND (borrowers.branchcode='' OR borrowers.branchcode=?)
409
                AND (
410
                    borrowers.branchcode IN ( $branches )
411
                    OR
412
                    borrowers.branchcode=?
413
                )
403
        };
414
        };
404
        $sth = $dbh->prepare($query);
415
        $sth = $dbh->prepare($query);
405
        $sth->execute( $status, $userenv->{branch} );
416
        $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 257-266 if ( $op eq 'delete_confirm' ) { Link Here
257
    if ( C4::Context->preference("IndependentBranches") ) {
265
    if ( C4::Context->preference("IndependentBranches") ) {
258
        my $userenv = C4::Context->userenv;
266
        my $userenv = C4::Context->userenv;
259
        unless ( C4::Context->IsSuperLibrarian() ) {
267
        unless ( C4::Context->IsSuperLibrarian() ) {
260
            my $validtest = ( $basket->{creationdate} eq '' )
268
            my $validtest =
269
                 ( $basket->{creationdate} eq '' )
261
              || ( $userenv->{branch} eq $basket->{branch} )
270
              || ( $userenv->{branch} eq $basket->{branch} )
262
              || ( $userenv->{branch} eq '' )
271
              || ( $userenv->{branch} eq '' )
263
              || ( $basket->{branch}  eq '' );
272
              || ( $basket->{branch}  eq '' )
273
              || (
274
                GetIndependentGroupModificationRights(
275
                    { for => $basket->{branch} }
276
                )
277
              );
264
            unless ($validtest) {
278
            unless ($validtest) {
265
                print $query->redirect("../mainpage.pl");
279
                print $query->redirect("../mainpage.pl");
266
                exit 1;
280
                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 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 731-740 foreach my $field (@fields) { Link Here
731
						|| $subfieldvalue;
731
						|| $subfieldvalue;
732
        }
732
        }
733
733
734
        if (($field->tag eq $branchtagfield) && ($subfieldcode eq $branchtagsubfield) && C4::Context->preference("IndependentBranches")) {
734
        if (   $field->tag eq $branchtagfield
735
            && $subfieldcode eq $branchtagsubfield
736
            && C4::Context->preference("IndependentBranches") )
737
        {
735
            #verifying rights
738
            #verifying rights
736
            my $userenv = C4::Context->userenv();
739
            my $userenv = C4::Context->userenv();
737
            unless (C4::Context->IsSuperLibrarian() or (($userenv->{'branch'} eq $subfieldvalue))){
740
            unless (
741
                C4::Context->IsSuperLibrarian()
742
                || GetIndependentGroupModificationRights(
743
                    { for => $subfieldvalue }
744
                )
745
              )
746
            {
738
                $this_row{'nomod'} = 1;
747
                $this_row{'nomod'} = 1;
739
            }
748
            }
740
        }
749
        }
(-)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/kohastructure.sql (-1 / +1 lines)
Lines 383-389 CREATE TABLE `branchcategories` ( -- information related to library/branch group Link Here
383
  `categorycode` varchar(10) NOT NULL default '', -- unique identifier for the library/branch group
383
  `categorycode` varchar(10) NOT NULL default '', -- unique identifier for the library/branch group
384
  `categoryname` varchar(32), -- name of the library/branch group
384
  `categoryname` varchar(32), -- name of the library/branch group
385
  `codedescription` mediumtext, -- longer description of the library/branch group
385
  `codedescription` mediumtext, -- longer description of the library/branch group
386
  `categorytype` varchar(16), -- says whether this is a search group or a properties group
386
  `categorytype` ENUM(  'searchdomain',  'independent_group' ) NULL DEFAULT NULL, -- says whether this is a search group or an independent group
387
  `show_in_pulldown` tinyint(1) NOT NULL DEFAULT '0', -- says this group should be in the opac libararies pulldown if it is enabled
387
  `show_in_pulldown` tinyint(1) NOT NULL DEFAULT '0', -- says this group should be in the opac libararies pulldown if it is enabled
388
  PRIMARY KEY  (`categorycode`),
388
  PRIMARY KEY  (`categorycode`),
389
  KEY `show_in_pulldown` (`show_in_pulldown`)
389
  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 9773-9778 if ( CheckVersion($DBversion) ) { Link Here
9773
    SetVersion ($DBversion);
9773
    SetVersion ($DBversion);
9774
}
9774
}
9775
9775
9776
$DBversion = "3.17.00.XXX";
9777
if ( CheckVersion($DBversion) ) {
9778
    $dbh->do(q{
9779
            DELETE FROM branchcategories WHERE categorytype = 'properties'
9780
    });
9781
9782
    $dbh->do(q{
9783
        ALTER TABLE branchcategories
9784
        CHANGE categorytype categorytype
9785
          ENUM( 'searchdomain', 'independent_group' )
9786
            NULL DEFAULT NULL
9787
    });
9788
    print "Upgrade to $DBversion done (Remove branch property groups, add independent groups)\n";
9789
    SetVersion ($DBversion);
9790
}
9791
9776
=head1 FUNCTIONS
9792
=head1 FUNCTIONS
9777
9793
9778
=head2 TableExists($table)
9794
=head2 TableExists($table)
(-)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 85-95 if ($bor->{category_type} eq "S") { Link Here
85
    }
85
    }
86
}
86
}
87
87
88
if (C4::Context->preference("IndependentBranches")) {
88
if ( C4::Context->preference("IndependentBranches") ) {
89
    my $userenv = C4::Context->userenv;
90
    if ( !C4::Context->IsSuperLibrarian() && $bor->{'branchcode'}){
89
    if ( !C4::Context->IsSuperLibrarian() && $bor->{'branchcode'}){
91
        unless ($userenv->{branch} eq $bor->{'branchcode'}){
90
        unless (
92
            print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_OTHERLIBRARY");
91
            GetIndependentGroupModificationRights(
92
                { for => $bor->{'branchcode'} }
93
            )
94
          )
95
        {
96
            print $input->redirect(
97
                "/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_OTHERLIBRARY"
98
            );
93
            exit;
99
            exit;
94
        }
100
        }
95
    }
101
    }
(-)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