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

(-)a/C4/Budgets.pm (-5 / +18 lines)
Lines 359-370 sub GetBudgetAuthCats { Link Here
359
# -------------------------------------------------------------------
359
# -------------------------------------------------------------------
360
sub GetAuthvalueDropbox {
360
sub GetAuthvalueDropbox {
361
    my ( $authcat, $default ) = @_;
361
    my ( $authcat, $default ) = @_;
362
    my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
362
    my $dbh = C4::Context->dbh;
363
    my $dbh = C4::Context->dbh;
363
    my $sth = $dbh->prepare(
364
364
        'SELECT authorised_value,lib FROM authorised_values
365
    my $query = qq{
365
        WHERE category = ? ORDER BY lib'
366
        SELECT *
366
    );
367
        FROM authorised_values
367
    $sth->execute( $authcat );
368
    };
369
    $query .= qq{
370
          LEFT JOIN authorised_values_branches ON ( id = av_id )
371
    } if $branch_limit;
372
    $query .= qq{
373
        WHERE category = ?
374
    };
375
    $query .= " AND ( branchcode = ? OR branchcode IS NULL )" if $branch_limit;
376
    $query .= " GROUP BY lib ORDER BY category, lib, lib_opac";
377
    my $sth = $dbh->prepare($query);
378
    $sth->execute( $authcat, $branch_limit ? $branch_limit : () );
379
380
368
    my $option_list = [];
381
    my $option_list = [];
369
    my @authorised_values = ( q{} );
382
    my @authorised_values = ( q{} );
370
    while (my ($value, $lib) = $sth->fetchrow_array) {
383
    while (my ($value, $lib) = $sth->fetchrow_array) {
(-)a/C4/Category.pm (-7 / +18 lines)
Lines 74-86 C<description>. Link Here
74
=cut
74
=cut
75
75
76
sub all {
76
sub all {
77
    my $class = shift;
77
    my ( $class ) = @_;
78
    map {
78
    my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
79
        utf8::encode($_->{description});
79
    my $dbh = C4::Context->dbh;
80
        $class->new($_);
80
    # The categories table is small enough for
81
    } @{C4::Context->dbh->selectall_arrayref(
81
    # `SELECT *` to be harmless.
82
        "SELECT * FROM categories ORDER BY description", { Slice => {} }
82
    my $query = "SELECT * FROM categories";
83
    )};
83
    $query .= qq{
84
        LEFT JOIN categories_branches ON categories_branches.categorycode = categories.categorycode
85
        WHERE categories_branches.branchcode = ? OR categories_branches.branchcode IS NULL
86
    } if $branch_limit;
87
    $query .= " ORDER BY description";
88
    return map { $class->new($_) } @{
89
        $dbh->selectall_arrayref(
90
            $query,
91
            { Slice => {} },
92
            $branch_limit ? $branch_limit : ()
93
        )
94
    };
84
}
95
}
85
96
86
97
(-)a/C4/Input.pm (-26 / +41 lines)
Lines 119-151 Returns NULL if no authorised values found Link Here
119
=cut
119
=cut
120
120
121
sub buildCGIsort {
121
sub buildCGIsort {
122
	my ($name,$input_name,$data) = @_;
122
    my ( $name, $input_name, $data ) = @_;
123
	my $dbh=C4::Context->dbh;
123
    my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
124
	my $query=qq{SELECT * FROM authorised_values WHERE category=? order by lib};
124
125
	my $sth=$dbh->prepare($query);
125
    my $dbh=C4::Context->dbh;
126
	$sth->execute($name);
126
    my $query = qq{
127
	my $CGISort;
127
        SELECT *
128
	if ($sth->rows>0){
128
        FROM authorised_values
129
		my @values;
129
    };
130
		my %labels;
130
    $query .= qq{
131
131
          LEFT JOIN authorised_values_branches ON ( id = av_id )
132
		for (my $i =0;$i<$sth->rows;$i++){
132
    } if $branch_limit;
133
			my $results = $sth->fetchrow_hashref;
133
    $query .= qq{
134
			push @values, $results->{authorised_value};
134
        WHERE category = ?
135
			$labels{$results->{authorised_value}}=$results->{lib};
135
    };
136
		}
136
    $query .= qq{ AND ( branchcode = ? OR branchcode IS NULL )} if $branch_limit;
137
		$CGISort= CGI::scrolling_list(
137
    $query .= qq{ GROUP BY lib ORDER BY lib};
138
					-name => $input_name,
138
139
					-id =>   $input_name,
139
    my $sth=$dbh->prepare($query);
140
					-values => \@values,
140
    $sth->execute( $branch_limit ? $branch_limit : (), $name );
141
					-labels => \%labels,
141
    my $CGISort;
142
					-default=> $data,
142
    if ($sth->rows>0){
143
					-size => 1,
143
        my @values;
144
					-multiple => 0);
144
        my %labels;
145
	}
145
146
	$sth->finish;
146
        for (my $i =0;$i<$sth->rows;$i++){
147
	return $CGISort;
147
            my $results = $sth->fetchrow_hashref;
148
            push @values, $results->{authorised_value};
149
            $labels{$results->{authorised_value}}=$results->{lib};
150
        }
151
        $CGISort= CGI::scrolling_list(
152
                    -name => $input_name,
153
                    -id =>   $input_name,
154
                    -values => \@values,
155
                    -labels => \%labels,
156
                    -default=> $data,
157
                    -size => 1,
158
                    -multiple => 0);
159
    }
160
    $sth->finish;
161
    return $CGISort;
148
}
162
}
163
149
END { }       # module clean-up code here (global destructor)
164
END { }       # module clean-up code here (global destructor)
150
165
151
1;
166
1;
(-)a/C4/Koha.pm (-12 / +34 lines)
Lines 1019-1046 C<$opac> If set to a true value, displays OPAC descriptions rather than normal o Link Here
1019
=cut
1019
=cut
1020
1020
1021
sub GetAuthorisedValues {
1021
sub GetAuthorisedValues {
1022
    my ($category,$selected,$opac) = @_;
1022
    my ( $category, $selected, $opac ) = @_;
1023
    my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
1023
    my @results;
1024
    my @results;
1024
    my $dbh      = C4::Context->dbh;
1025
    my $dbh      = C4::Context->dbh;
1025
    my $query    = "SELECT * FROM authorised_values";
1026
    my $query = qq{
1026
    $query .= " WHERE category = '" . $category . "'" if $category;
1027
        SELECT *
1027
    $query .= " ORDER BY category, lib, lib_opac";
1028
        FROM authorised_values
1029
    };
1030
    $query .= qq{
1031
          LEFT JOIN authorised_values_branches ON ( id = av_id )
1032
    } if $branch_limit;
1033
    my @where_strings;
1034
    my @where_args;
1035
    if($category) {
1036
        push @where_strings, "category = ?";
1037
        push @where_args, $category;
1038
    }
1039
    if($branch_limit) {
1040
        push @where_strings, "( branchcode = ? OR branchcode IS NULL )";
1041
        push @where_args, $branch_limit;
1042
    }
1043
    if(@where_strings > 0) {
1044
        $query .= " WHERE " . join(" AND ", @where_strings);
1045
    }
1046
    $query .= " GROUP BY lib ORDER BY category, lib, lib_opac";
1047
1028
    my $sth = $dbh->prepare($query);
1048
    my $sth = $dbh->prepare($query);
1029
    $sth->execute;
1049
1050
    $sth->execute( @where_args );
1030
    while (my $data=$sth->fetchrow_hashref) {
1051
    while (my $data=$sth->fetchrow_hashref) {
1031
        if ( (defined($selected)) && ($selected eq $data->{'authorised_value'}) ) {
1052
        if ( defined $selected and $selected eq $data->{authorised_value} ) {
1032
            $data->{'selected'} = 1;
1053
            $data->{selected} = 1;
1033
        }
1054
        }
1034
        else {
1055
        else {
1035
            $data->{'selected'} = 0;
1056
            $data->{selected} = 0;
1036
        }
1057
        }
1037
        if ($opac && $data->{'lib_opac'}) {
1058
1038
            $data->{'lib'} = $data->{'lib_opac'};
1059
        if ($opac && $data->{lib_opac}) {
1060
            $data->{lib} = $data->{lib_opac};
1039
        }
1061
        }
1040
        push @results, $data;
1062
        push @results, $data;
1041
    }
1063
    }
1042
    #my $data = $sth->fetchall_arrayref({});
1064
    $sth->finish;
1043
    return \@results; #$data;
1065
    return \@results;
1044
}
1066
}
1045
1067
1046
=head2 GetAuthorisedValueCategories
1068
=head2 GetAuthorisedValueCategories
(-)a/C4/Members.pm (-21 / +42 lines)
Lines 1384-1403 to category descriptions. Link Here
1384
1384
1385
#'
1385
#'
1386
sub GetborCatFromCatType {
1386
sub GetborCatFromCatType {
1387
    my ( $category_type, $action ) = @_;
1387
    my ( $category_type, $action, $no_branch_limit ) = @_;
1388
	# FIXME - This API  seems both limited and dangerous. 
1388
1389
    my $branch_limit = $no_branch_limit
1390
        ? 0
1391
        : C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
1392
1393
    # FIXME - This API  seems both limited and dangerous. 
1389
    my $dbh     = C4::Context->dbh;
1394
    my $dbh     = C4::Context->dbh;
1390
    my $request = qq|   SELECT categorycode,description 
1395
1391
            FROM categories 
1396
    my $request = qq{
1392
            $action
1397
        SELECT categories.categorycode, categories.description
1393
            ORDER BY categorycode|;
1398
        FROM categories
1394
    my $sth = $dbh->prepare($request);
1399
    };
1395
	if ($action) {
1400
    $request .= qq{
1396
        $sth->execute($category_type);
1401
        LEFT JOIN categories_branches ON categories.categorycode = categories_branches.categorycode
1397
    }
1402
    } if $branch_limit;
1398
    else {
1403
    if($action) {
1399
        $sth->execute();
1404
        $request .= " $action ";
1405
        $request .= " AND (branchcode = ? OR branchcode IS NULL) GROUP BY description" if $branch_limit;
1406
    } else {
1407
        $request .= " WHERE branchcode = ? OR branchcode IS NULL GROUP BY description" if $branch_limit;
1400
    }
1408
    }
1409
    $request .= " ORDER BY categorycode";
1410
1411
    my $sth = $dbh->prepare($request);
1412
    $sth->execute(
1413
        $action ? $category_type : (),
1414
        $branch_limit ? $branch_limit : ()
1415
    );
1401
1416
1402
    my %labels;
1417
    my %labels;
1403
    my @codes;
1418
    my @codes;
Lines 1406-1411 sub GetborCatFromCatType { Link Here
1406
        push @codes, $data->{'categorycode'};
1421
        push @codes, $data->{'categorycode'};
1407
        $labels{ $data->{'categorycode'} } = $data->{'description'};
1422
        $labels{ $data->{'categorycode'} } = $data->{'description'};
1408
    }
1423
    }
1424
    $sth->finish;
1409
    return ( \@codes, \%labels );
1425
    return ( \@codes, \%labels );
1410
}
1426
}
1411
1427
Lines 1464-1479 If no category code provided, the function returns all the categories. Link Here
1464
=cut
1480
=cut
1465
1481
1466
sub GetBorrowercategoryList {
1482
sub GetBorrowercategoryList {
1483
    my $no_branch_limit = @_ ? shift : 0;
1484
    my $branch_limit = $no_branch_limit
1485
        ? 0
1486
        : C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
1467
    my $dbh       = C4::Context->dbh;
1487
    my $dbh       = C4::Context->dbh;
1468
    my $sth       =
1488
    my $query = "SELECT * FROM categories";
1469
    $dbh->prepare(
1489
    $query .= qq{
1470
    "SELECT * 
1490
        LEFT JOIN categories_branches ON categories.categorycode = categories_branches.categorycode
1471
    FROM categories 
1491
        WHERE branchcode = ? OR branchcode IS NULL GROUP BY description
1472
    ORDER BY description"
1492
    } if $branch_limit;
1473
        );
1493
    $query .= " ORDER BY description";
1474
    $sth->execute;
1494
    my $sth = $dbh->prepare( $query );
1475
    my $data =
1495
    $sth->execute( $branch_limit ? $branch_limit : () );
1476
    $sth->fetchall_arrayref({});
1496
    my $data = $sth->fetchall_arrayref( {} );
1497
    $sth->finish;
1477
    return $data;
1498
    return $data;
1478
}    # sub getborrowercategory
1499
}    # sub getborrowercategory
1479
1500
(-)a/C4/Members/AttributeTypes.pm (-4 / +58 lines)
Lines 69-80 If $all_fields is true, then each hashref also contains the other fields from bo Link Here
69
=cut
69
=cut
70
70
71
sub GetAttributeTypes {
71
sub GetAttributeTypes {
72
    my ($all) = @_;
72
    my $all    = @_   ? shift : 0;
73
    my $select = $all ? '*' : 'code, description, class';
73
    my $no_branch_limit = @_ ? shift : 0;
74
    my $branch_limit = $no_branch_limit
75
        ? 0
76
        : C4::Context->userenv ? C4::Context->userenv->{"branch"} : 0;
77
    my $select = $all ? '*'   : 'DISTINCT(code), description';
78
74
    my $dbh = C4::Context->dbh;
79
    my $dbh = C4::Context->dbh;
75
    my $sth = $dbh->prepare("SELECT $select FROM borrower_attribute_types ORDER by code");
80
    my $query = "SELECT $select FROM borrower_attribute_types";
76
    $sth->execute();
81
    $query .= qq{
82
        LEFT JOIN borrower_attribute_types_branches ON bat_code = code
83
        WHERE b_branchcode = ? OR b_branchcode IS NULL
84
    } if $branch_limit;
85
    $query .= " ORDER BY code";
86
    my $sth    = $dbh->prepare($query);
87
    $sth->execute( $branch_limit ? $branch_limit : () );
77
    my $results = $sth->fetchall_arrayref({});
88
    my $results = $sth->fetchall_arrayref({});
89
    $sth->finish;
78
    return @$results;
90
    return @$results;
79
}
91
}
80
92
Lines 166-171 sub fetch { Link Here
166
    $self->{'category_description'}      = $row->{'category_description'};
178
    $self->{'category_description'}      = $row->{'category_description'};
167
    $self->{'class'}                     = $row->{'class'};
179
    $self->{'class'}                     = $row->{'class'};
168
180
181
    $sth = $dbh->prepare("SELECT branchcode, branchname FROM borrower_attribute_types_branches, branches WHERE b_branchcode = branchcode AND bat_code = ?;");
182
    $sth->execute( $code );
183
    while ( my $data = $sth->fetchrow_hashref ) {
184
        push @{ $self->{branches} }, $data;
185
    }
186
    $sth->finish();
187
169
    bless $self, $class;
188
    bless $self, $class;
170
    return $self;
189
    return $self;
171
}
190
}
Lines 219-224 sub store { Link Here
219
    $sth->bind_param(11, $self->{'code'});
238
    $sth->bind_param(11, $self->{'code'});
220
    $sth->execute;
239
    $sth->execute;
221
240
241
    if ( defined $$self{branches} ) {
242
        $sth = $dbh->prepare("DELETE FROM borrower_attribute_types_branches WHERE bat_code = ?");
243
        $sth->execute( $$self{code} );
244
        $sth = $dbh->prepare(
245
            "INSERT INTO borrower_attribute_types_branches
246
                        ( bat_code, b_branchcode )
247
                        VALUES ( ?, ? )"
248
        );
249
        for my $branchcode ( @{$$self{branches}} ) {
250
            next if not $branchcode;
251
            $sth->bind_param( 1, $$self{code} );
252
            $sth->bind_param( 2, $branchcode );
253
            $sth->execute;
254
        }
255
    }
256
    $sth->finish;
222
}
257
}
223
258
224
=head2 code
259
=head2 code
Lines 250-255 sub description { Link Here
250
    @_ ? $self->{'description'} = shift : $self->{'description'};
285
    @_ ? $self->{'description'} = shift : $self->{'description'};
251
}
286
}
252
287
288
=head2 branches
289
290
=over 4
291
292
my $branches = $attr_type->branches();
293
$attr_type->branches($branches);
294
295
=back
296
297
Accessor.
298
299
=cut
300
301
sub branches {
302
    my $self = shift;
303
    @_ ? $self->{branches} = shift : $self->{branches};
304
}
305
253
=head2 repeatable
306
=head2 repeatable
254
307
255
  my $repeatable = $attr_type->repeatable();
308
  my $repeatable = $attr_type->repeatable();
Lines 432-437 sub delete { Link Here
432
    my $dbh = C4::Context->dbh;
485
    my $dbh = C4::Context->dbh;
433
    my $sth = $dbh->prepare_cached("DELETE FROM borrower_attribute_types WHERE code = ?");
486
    my $sth = $dbh->prepare_cached("DELETE FROM borrower_attribute_types WHERE code = ?");
434
    $sth->execute($code);
487
    $sth->execute($code);
488
    $sth->finish;
435
}
489
}
436
490
437
=head2 num_patrons
491
=head2 num_patrons
(-)a/C4/Members/Attributes.pm (+2 lines)
Lines 71-76 marked for OPAC display are returned. Link Here
71
sub GetBorrowerAttributes {
71
sub GetBorrowerAttributes {
72
    my $borrowernumber = shift;
72
    my $borrowernumber = shift;
73
    my $opac_only = @_ ? shift : 0;
73
    my $opac_only = @_ ? shift : 0;
74
    my $branch_limit = @_ ? shift : 0;
74
75
75
    my $dbh = C4::Context->dbh();
76
    my $dbh = C4::Context->dbh();
76
    my $query = "SELECT code, description, attribute, lib, password, display_checkout, category_code, class
77
    my $query = "SELECT code, description, attribute, lib, password, display_checkout, category_code, class
Lines 95-100 sub GetBorrowerAttributes { Link Here
95
            class             => $row->{'class'},
96
            class             => $row->{'class'},
96
        }
97
        }
97
    }
98
    }
99
    $sth->finish;
98
    return \@results;
100
    return \@results;
99
}
101
}
100
102
(-)a/admin/authorised_values.pl (-4 / +62 lines)
Lines 22-27 use warnings; Link Here
22
22
23
use CGI;
23
use CGI;
24
use C4::Auth;
24
use C4::Auth;
25
use C4::Branch;
25
use C4::Context;
26
use C4::Context;
26
use C4::Koha;
27
use C4::Koha;
27
use C4::Output;
28
use C4::Output;
Lines 67-79 $template->param( script_name => $script_name, Link Here
67
# called by default. Used to create form to add or  modify a record
68
# called by default. Used to create form to add or  modify a record
68
if ($op eq 'add_form') {
69
if ($op eq 'add_form') {
69
	my $data;
70
	my $data;
71
    my @selected_branches;
70
	if ($id) {
72
	if ($id) {
71
		my $sth=$dbh->prepare("select id, category, authorised_value, lib, lib_opac, imageurl from authorised_values where id=?");
73
		my $sth=$dbh->prepare("select id, category, authorised_value, lib, lib_opac, imageurl from authorised_values where id=?");
72
		$sth->execute($id);
74
		$sth->execute($id);
73
		$data=$sth->fetchrow_hashref;
75
		$data=$sth->fetchrow_hashref;
76
        $sth = $dbh->prepare("SELECT b.branchcode, b.branchname FROM authorised_values_branches AS avb, branches AS b WHERE avb.branchcode = b.branchcode AND avb.av_id = ?;");
77
        $sth->execute( $id );
78
        while ( my $branch = $sth->fetchrow_hashref ) {
79
            push @selected_branches, $branch;
80
        }
74
	} else {
81
	} else {
75
		$data->{'category'} = $input->param('category');
82
		$data->{'category'} = $input->param('category');
76
	}
83
	}
84
85
    my $branches = GetBranches;
86
    my @branches_loop;
87
88
    foreach my $branch (sort keys %$branches) {
89
        my $selected = ( grep {$_->{branchcode} eq $branch} @selected_branches ) ? 1 : 0;
90
        push @branches_loop, {
91
            branchcode => $branches->{$branch}{branchcode},
92
            branchname => $branches->{$branch}{branchname},
93
            selected => $selected,
94
        };
95
    }
96
77
	if ($id) {
97
	if ($id) {
78
		$template->param(action_modify => 1);
98
		$template->param(action_modify => 1);
79
		$template->param('heading_modify_authorized_value_p' => 1);
99
		$template->param('heading_modify_authorized_value_p' => 1);
Lines 92-97 if ($op eq 'add_form') { Link Here
92
                         id               => $data->{'id'},
112
                         id               => $data->{'id'},
93
                         imagesets        => C4::Koha::getImageSets( checked => $data->{'imageurl'} ),
113
                         imagesets        => C4::Koha::getImageSets( checked => $data->{'imageurl'} ),
94
                         offset           => $offset,
114
                         offset           => $offset,
115
                         branches_loop    => \@branches_loop,
95
                     );
116
                     );
96
                          
117
                          
97
################## ADD_VALIDATE ##################################
118
################## ADD_VALIDATE ##################################
Lines 102-107 if ($op eq 'add_form') { Link Here
102
    my $imageurl     = $input->param( 'imageurl' ) || '';
123
    my $imageurl     = $input->param( 'imageurl' ) || '';
103
	$imageurl = '' if $imageurl =~ /removeImage/;
124
	$imageurl = '' if $imageurl =~ /removeImage/;
104
    my $duplicate_entry = 0;
125
    my $duplicate_entry = 0;
126
    my @branches = $input->param('branches');
105
127
106
    if ( $id ) { # Update
128
    if ( $id ) { # Update
107
        my $sth = $dbh->prepare( "SELECT category, authorised_value FROM authorised_values WHERE id = ? ");
129
        my $sth = $dbh->prepare( "SELECT category, authorised_value FROM authorised_values WHERE id = ? ");
Lines 125-131 if ($op eq 'add_form') { Link Here
125
            my $lib_opac = $input->param('lib_opac');
147
            my $lib_opac = $input->param('lib_opac');
126
            undef $lib if ($lib eq ""); # to insert NULL instead of a blank string
148
            undef $lib if ($lib eq ""); # to insert NULL instead of a blank string
127
            undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string
149
            undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string
128
            $sth->execute($new_category, $new_authorised_value, $lib, $lib_opac, $imageurl, $id);          
150
            $sth->execute($new_category, $new_authorised_value, $lib, $lib_opac, $imageurl, $id);
151
            if ( @branches ) {
152
                $sth = $dbh->prepare("DELETE FROM authorised_values_branches WHERE av_id = ?");
153
                $sth->execute( $id );
154
                $sth = $dbh->prepare(
155
                    "INSERT INTO authorised_values_branches
156
                                ( av_id, branchcode )
157
                                VALUES ( ?, ? )"
158
                );
159
                for my $branchcode ( @branches ) {
160
                    next if not $branchcode;
161
                    $sth->execute($id, $branchcode);
162
                }
163
            }
164
            $sth->finish;
129
            print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$new_category."&offset=$offset\"></html>";
165
            print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$new_category."&offset=$offset\"></html>";
130
            exit;
166
            exit;
131
        }
167
        }
Lines 137-149 if ($op eq 'add_form') { Link Here
137
        ($duplicate_entry) = $sth->fetchrow_array();
173
        ($duplicate_entry) = $sth->fetchrow_array();
138
        unless ( $duplicate_entry ) {
174
        unless ( $duplicate_entry ) {
139
            my $sth=$dbh->prepare( 'INSERT INTO authorised_values
175
            my $sth=$dbh->prepare( 'INSERT INTO authorised_values
140
                                    ( id, category, authorised_value, lib, lib_opac, imageurl )
176
                                    ( category, authorised_value, lib, lib_opac, imageurl )
141
                                    values (?, ?, ?, ?, ?, ?)' );
177
                                    values (?, ?, ?, ?, ?)' );
142
    	    my $lib = $input->param('lib');
178
    	    my $lib = $input->param('lib');
143
    	    my $lib_opac = $input->param('lib_opac');
179
    	    my $lib_opac = $input->param('lib_opac');
144
    	    undef $lib if ($lib eq ""); # to insert NULL instead of a blank string
180
    	    undef $lib if ($lib eq ""); # to insert NULL instead of a blank string
145
    	    undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string
181
    	    undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string
146
    	    $sth->execute($id, $new_category, $new_authorised_value, $lib, $lib_opac, $imageurl );
182
            $sth->execute( $new_category, $new_authorised_value, $lib, $lib_opac, $imageurl );
183
            $id = $dbh->{'mysql_insertid'};
184
            if ( @branches ) {
185
                $sth = $dbh->prepare(
186
                    "INSERT INTO authorised_values_branches
187
                                ( av_id, branchcode )
188
                                VALUES ( ?, ? )"
189
                );
190
                for my $branchcode ( @branches ) {
191
                    next if not $branchcode;
192
                    $sth->execute($id, $branchcode);
193
                }
194
            }
147
    	    print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$input->param('category')."&offset=$offset\"></html>";
195
    	    print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$input->param('category')."&offset=$offset\"></html>";
148
    	    exit;
196
    	    exit;
149
        }
197
        }
Lines 176-181 if ($op eq 'add_form') { Link Here
176
	my $id = $input->param('id');
224
	my $id = $input->param('id');
177
	my $sth=$dbh->prepare("delete from authorised_values where id=?");
225
	my $sth=$dbh->prepare("delete from authorised_values where id=?");
178
	$sth->execute($id);
226
	$sth->execute($id);
227
    $sth = $dbh->prepare("DELETE FROM authorised_values_branches WHERE id = ?");
228
    $sth->execute($id);
179
	print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=$searchfield&offset=$offset\"></html>";
229
	print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=$searchfield&offset=$offset\"></html>";
180
	exit;
230
	exit;
181
													# END $OP eq DELETE_CONFIRMED
231
													# END $OP eq DELETE_CONFIRMED
Lines 218-224 sub default_form { Link Here
218
    my $count = scalar(@$results);
268
    my $count = scalar(@$results);
219
	my @loop_data = ();
269
	my @loop_data = ();
220
	# builds value list
270
	# builds value list
271
    my $dbh = C4::Context->dbh;
272
    $sth = $dbh->prepare("SELECT b.branchcode, b.branchname FROM authorised_values_branches AS avb, branches AS b WHERE avb.branchcode = b.branchcode AND avb.av_id = ?");
221
	for (my $i=0; $i < $count; $i++){
273
	for (my $i=0; $i < $count; $i++){
274
        $sth->execute( $results->[$i]{id} );
275
        my @selected_branches;
276
        while ( my $branch = $sth->fetchrow_hashref ) {
277
            push @selected_branches, $branch;
278
        }
222
		my %row_data;  # get a fresh hash for the row data
279
		my %row_data;  # get a fresh hash for the row data
223
		$row_data{category}              = $results->[$i]{'category'};
280
		$row_data{category}              = $results->[$i]{'category'};
224
		$row_data{authorised_value}      = $results->[$i]{'authorised_value'};
281
		$row_data{authorised_value}      = $results->[$i]{'authorised_value'};
Lines 227-232 sub default_form { Link Here
227
		$row_data{imageurl}              = getitemtypeimagelocation( 'intranet', $results->[$i]{'imageurl'} );
284
		$row_data{imageurl}              = getitemtypeimagelocation( 'intranet', $results->[$i]{'imageurl'} );
228
		$row_data{edit}                  = "$script_name?op=add_form&amp;id=".$results->[$i]{'id'}."&amp;offset=$offset";
285
		$row_data{edit}                  = "$script_name?op=add_form&amp;id=".$results->[$i]{'id'}."&amp;offset=$offset";
229
		$row_data{delete}                = "$script_name?op=delete_confirm&amp;searchfield=$searchfield&amp;id=".$results->[$i]{'id'}."&amp;offset=$offset";
286
		$row_data{delete}                = "$script_name?op=delete_confirm&amp;searchfield=$searchfield&amp;id=".$results->[$i]{'id'}."&amp;offset=$offset";
287
        $row_data{branches}              = \@selected_branches;
230
		push(@loop_data, \%row_data);
288
		push(@loop_data, \%row_data);
231
	}
289
	}
232
290
(-)a/admin/categorie.pl (-5 / +50 lines)
Lines 36-46 Link Here
36
# with Koha; if not, write to the Free Software Foundation, Inc.,
36
# with Koha; if not, write to the Free Software Foundation, Inc.,
37
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
37
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
38
38
39
use strict;
39
use Modern::Perl;
40
#use warnings; FIXME - Bug 2505
40
41
use CGI;
41
use CGI;
42
use C4::Context;
42
use C4::Context;
43
use C4::Auth;
43
use C4::Auth;
44
use C4::Branch;
44
use C4::Output;
45
use C4::Output;
45
use C4::Dates;
46
use C4::Dates;
46
use C4::Form::MessagingPreferences;
47
use C4::Form::MessagingPreferences;
Lines 90-105 if ($op eq 'add_form') { Link Here
90
	
91
	
91
	#---- if primkey exists, it's a modify action, so read values to modify...
92
	#---- if primkey exists, it's a modify action, so read values to modify...
92
	my $data;
93
	my $data;
94
    my @selected_branches;
93
	if ($categorycode) {
95
	if ($categorycode) {
94
		my $dbh = C4::Context->dbh;
96
		my $dbh = C4::Context->dbh;
95
		my $sth=$dbh->prepare("select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,hidelostitems,overduenoticerequired,category_type from categories where categorycode=?");
97
		my $sth=$dbh->prepare("select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,hidelostitems,overduenoticerequired,category_type from categories where categorycode=?");
96
		$sth->execute($categorycode);
98
		$sth->execute($categorycode);
97
		$data=$sth->fetchrow_hashref;
99
		$data=$sth->fetchrow_hashref;
98
		$sth->finish;
100
99
	}
101
        $sth = $dbh->prepare("SELECT b.branchcode, b.branchname FROM categories_branches AS cb, branches AS b WHERE cb.branchcode = b.branchcode AND cb.categorycode = ?");
102
        $sth->execute( $categorycode );
103
        while ( my $branch = $sth->fetchrow_hashref ) {
104
            push @selected_branches, $branch;
105
        }
106
        $sth->finish;
107
    }
100
108
101
    $data->{'enrolmentperioddate'} = undef if ($data->{'enrolmentperioddate'} eq '0000-00-00');
109
    $data->{'enrolmentperioddate'} = undef if ($data->{'enrolmentperioddate'} eq '0000-00-00');
102
110
111
    my $branches = GetBranches;
112
    my @branches_loop;
113
    foreach my $branch (sort keys %$branches) {
114
        my $selected = ( grep {$$_{branchcode} eq $branch} @selected_branches ) ? 1 : 0;
115
        push @branches_loop, {
116
            branchcode => $$branches{$branch}{branchcode},
117
            branchname => $$branches{$branch}{branchname},
118
            selected => $selected,
119
        };
120
    }
121
103
	$template->param(description        => $data->{'description'},
122
	$template->param(description        => $data->{'description'},
104
				enrolmentperiod         => $data->{'enrolmentperiod'},
123
				enrolmentperiod         => $data->{'enrolmentperiod'},
105
				enrolmentperioddate     => C4::Dates::format_date($data->{'enrolmentperioddate'}),
124
				enrolmentperioddate     => C4::Dates::format_date($data->{'enrolmentperioddate'}),
Lines 115-120 if ($op eq 'add_form') { Link Here
115
                SMSSendDriver => C4::Context->preference("SMSSendDriver"),
134
                SMSSendDriver => C4::Context->preference("SMSSendDriver"),
116
                TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"),
135
                TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"),
117
				"type_".$data->{'category_type'} => 1,
136
				"type_".$data->{'category_type'} => 1,
137
                branches_loop           => \@branches_loop,
118
				);
138
				);
119
    if (C4::Context->preference('EnhancedMessagingPreferences')) {
139
    if (C4::Context->preference('EnhancedMessagingPreferences')) {
120
        C4::Form::MessagingPreferences::set_form_values({ categorycode => $categorycode } , $template);
140
        C4::Form::MessagingPreferences::set_form_values({ categorycode => $categorycode } , $template);
Lines 133-138 if ($op eq 'add_form') { Link Here
133
	if ($is_a_modif) {
153
	if ($is_a_modif) {
134
            my $sth=$dbh->prepare("UPDATE categories SET description=?,enrolmentperiod=?, enrolmentperioddate=?,upperagelimit=?,dateofbirthrequired=?,enrolmentfee=?,reservefee=?,hidelostitems=?,overduenoticerequired=?,category_type=? WHERE categorycode=?");
154
            my $sth=$dbh->prepare("UPDATE categories SET description=?,enrolmentperiod=?, enrolmentperioddate=?,upperagelimit=?,dateofbirthrequired=?,enrolmentfee=?,reservefee=?,hidelostitems=?,overduenoticerequired=?,category_type=? WHERE categorycode=?");
135
            $sth->execute(map { $input->param($_) } ('description','enrolmentperiod','enrolmentperioddate','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','hidelostitems','overduenoticerequired','category_type','categorycode'));
155
            $sth->execute(map { $input->param($_) } ('description','enrolmentperiod','enrolmentperioddate','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','hidelostitems','overduenoticerequired','category_type','categorycode'));
156
            my @branches = $input->param("branches");
157
            if ( @branches ) {
158
                $sth = $dbh->prepare("DELETE FROM categories_branches WHERE categorycode = ?");
159
                $sth->execute( $input->param( "categorycode" ) );
160
                $sth = $dbh->prepare(
161
                    "INSERT INTO categories_branches
162
                                ( categorycode, branchcode )
163
                                VALUES ( ?, ? )"
164
                );
165
                for my $branchcode ( @branches ) {
166
                    next if not $branchcode;
167
                    $sth->bind_param( 1, $input->param( "categorycode" ) );
168
                    $sth->bind_param( 2, $branchcode );
169
                    $sth->execute;
170
                }
171
            }
136
            $sth->finish;
172
            $sth->finish;
137
        } else {
173
        } else {
138
            my $sth=$dbh->prepare("INSERT INTO categories  (categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,reservefee,hidelostitems,overduenoticerequired,category_type) values (?,?,?,?,?,?,?,?,?,?,?)");
174
            my $sth=$dbh->prepare("INSERT INTO categories  (categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,reservefee,hidelostitems,overduenoticerequired,category_type) values (?,?,?,?,?,?,?,?,?,?,?)");
Lines 197-203 if ($op eq 'add_form') { Link Here
197
	$template->param(else => 1);
233
	$template->param(else => 1);
198
	my @loop;
234
	my @loop;
199
	my ($count,$results)=StringSearch($searchfield,'web');
235
	my ($count,$results)=StringSearch($searchfield,'web');
236
    my $dbh = C4::Context->dbh;
237
    my $sth = $dbh->prepare("SELECT b.branchcode, b.branchname FROM categories_branches AS cb, branches AS b WHERE cb.branchcode = b.branchcode AND cb.categorycode = ?");
200
	for (my $i=0; $i < $count; $i++){
238
	for (my $i=0; $i < $count; $i++){
239
        $sth->execute( $results->[$i]{'categorycode'} );
240
        my @selected_branches;
241
        while ( my $branch = $sth->fetchrow_hashref ) {
242
            push @selected_branches, $branch;
243
        }
201
		my %row = (
244
		my %row = (
202
		        categorycode            => $results->[$i]{'categorycode'},
245
		        categorycode            => $results->[$i]{'categorycode'},
203
				description             => $results->[$i]{'description'},
246
				description             => $results->[$i]{'description'},
Lines 211-217 if ($op eq 'add_form') { Link Here
211
				reservefee              => sprintf("%.2f",$results->[$i]{'reservefee'}),
254
				reservefee              => sprintf("%.2f",$results->[$i]{'reservefee'}),
212
                                hidelostitems           => $results->[$i]{'hidelostitems'},
255
                                hidelostitems           => $results->[$i]{'hidelostitems'},
213
				category_type           => $results->[$i]{'category_type'},
256
				category_type           => $results->[$i]{'category_type'},
214
				"type_".$results->[$i]{'category_type'} => 1);
257
				"type_".$results->[$i]{'category_type'} => 1,
258
                branches                => \@selected_branches,
259
        );
215
        if (C4::Context->preference('EnhancedMessagingPreferences')) {
260
        if (C4::Context->preference('EnhancedMessagingPreferences')) {
216
            my $brief_prefs = _get_brief_messaging_prefs($results->[$i]{'categorycode'});
261
            my $brief_prefs = _get_brief_messaging_prefs($results->[$i]{'categorycode'});
217
            $row{messaging_prefs} = $brief_prefs if @$brief_prefs;
262
            $row{messaging_prefs} = $brief_prefs if @$brief_prefs;
(-)a/admin/patron-attr-types.pl (-6 / +38 lines)
Lines 19-30 Link Here
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
#
20
#
21
21
22
use strict;
22
use Modern::Perl;
23
use warnings;
23
24
use CGI;
24
use CGI;
25
use List::MoreUtils qw/uniq/;
25
use List::MoreUtils qw/uniq/;
26
26
27
use C4::Auth;
27
use C4::Auth;
28
use C4::Branch;
28
use C4::Context;
29
use C4::Context;
29
use C4::Output;
30
use C4::Output;
30
use C4::Koha;
31
use C4::Koha;
Lines 82-91 exit 0; Link Here
82
sub add_attribute_type_form {
83
sub add_attribute_type_form {
83
    my $template = shift;
84
    my $template = shift;
84
85
86
    my $branches = GetBranches;
87
    my @branches_loop;
88
    foreach my $branch (sort keys %$branches) {
89
        push @branches_loop, {
90
            branchcode => $$branches{$branch}{branchcode},
91
            branchname => $$branches{$branch}{branchname},
92
        };
93
    }
94
85
    $template->param(
95
    $template->param(
86
        attribute_type_form => 1,
96
        attribute_type_form => 1,
87
        confirm_op => 'add_attribute_type_confirmed',
97
        confirm_op => 'add_attribute_type_confirmed',
88
        categories => GetBorrowercategoryList,
98
        categories => GetBorrowercategoryList,
99
        branches_loop => \@branches_loop,
89
    );
100
    );
90
    authorised_value_category_list($template);
101
    authorised_value_category_list($template);
91
    pa_classes($template);
102
    pa_classes($template);
Lines 162-167 sub add_update_attribute_type { Link Here
162
    $attr_type->display_checkout($display_checkout);
173
    $attr_type->display_checkout($display_checkout);
163
    $attr_type->category_code($input->param('category_code'));
174
    $attr_type->category_code($input->param('category_code'));
164
    $attr_type->class($input->param('class'));
175
    $attr_type->class($input->param('class'));
176
    my @branches = $input->param('branches');
177
    $attr_type->branches( \@branches );
165
178
166
    if ($op eq 'edit') {
179
    if ($op eq 'edit') {
167
        $template->param(edited_attribute_type => $attr_type->code());
180
        $template->param(edited_attribute_type => $attr_type->code());
Lines 244-249 sub edit_attribute_type_form { Link Here
244
    authorised_value_category_list($template, $attr_type->authorised_value_category());
257
    authorised_value_category_list($template, $attr_type->authorised_value_category());
245
    pa_classes( $template, $attr_type->class );
258
    pa_classes( $template, $attr_type->class );
246
259
260
261
    my $branches = GetBranches;
262
    my @branches_loop;
263
    my $selected_branches = $attr_type->branches;
264
    foreach my $branch (sort keys %$branches) {
265
        my $selected = ( grep {$$_{branchcode} eq $branch} @$selected_branches ) ? 1 : 0;
266
        push @branches_loop, {
267
            branchcode => $branches->{$branch}{branchcode},
268
            branchname => $branches->{$branch}{branchname},
269
            selected => $selected,
270
        };
271
    }
272
    $template->param( branches_loop => \@branches_loop );
273
247
    $template->param ( category_code => $attr_type->category_code );
274
    $template->param ( category_code => $attr_type->category_code );
248
    $template->param ( category_description => $attr_type->category_description );
275
    $template->param ( category_description => $attr_type->category_description );
249
276
Lines 259-279 sub edit_attribute_type_form { Link Here
259
sub patron_attribute_type_list {
286
sub patron_attribute_type_list {
260
    my $template = shift;
287
    my $template = shift;
261
288
262
    my @attr_types = C4::Members::AttributeTypes::GetAttributeTypes();
289
    my @attr_types = C4::Members::AttributeTypes::GetAttributeTypes( 1, 1 );
263
    my @classes = uniq( map {$_->{class}} @attr_types );
290
291
    my @classes = uniq( map { $_->{class} } @attr_types );
264
    @classes = sort @classes;
292
    @classes = sort @classes;
265
293
266
    my @attributes_loop;
294
    my @attributes_loop;
267
    for my $class (@classes) {
295
    for my $class (@classes) {
268
        my @items;
296
        my ( @items, $branches );
269
        for my $attr (@attr_types) {
297
        for my $attr (@attr_types) {
270
            push @items, $attr if $attr->{class} eq $class
298
            next if $attr->{class} ne $class;
299
            my $attr_type = C4::Members::AttributeTypes->fetch($attr->{code});
300
            $attr->{branches} = $attr_type->branches;
301
            push @items, $attr;
271
        }
302
        }
272
        my $lib = GetAuthorisedValueByCode( 'PA_CLASS', $class ) || $class;
303
        my $lib = GetAuthorisedValueByCode( 'PA_CLASS', $class ) || $class;
273
        push @attributes_loop, {
304
        push @attributes_loop, {
274
            class => $class,
305
            class => $class,
275
            items => \@items,
306
            items => \@items,
276
            lib   => $lib,
307
            lib   => $lib,
308
            branches => $branches,
277
        };
309
        };
278
    }
310
    }
279
    $template->param(available_attribute_types => \@attributes_loop);
311
    $template->param(available_attribute_types => \@attributes_loop);
(-)a/cataloguing/addbiblio.pl (-7 / +15 lines)
Lines 219-226 sub build_authorized_values_list { Link Here
219
        $value = $default_source unless $value;
219
        $value = $default_source unless $value;
220
    }
220
    }
221
    else {
221
    else {
222
        my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
222
        $authorised_values_sth->execute(
223
        $authorised_values_sth->execute(
223
            $tagslib->{$tag}->{$subfield}->{authorised_value} );
224
            $tagslib->{$tag}->{$subfield}->{authorised_value},
225
            $branch_limit ? $branch_limit : (),
226
        );
224
227
225
        push @authorised_values, ""
228
        push @authorised_values, ""
226
          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
229
          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
Lines 230-235 sub build_authorized_values_list { Link Here
230
            $authorised_lib{$value} = $lib;
233
            $authorised_lib{$value} = $lib;
231
        }
234
        }
232
    }
235
    }
236
    $authorised_values_sth->finish;
233
    return CGI::scrolling_list(
237
    return CGI::scrolling_list(
234
        -name     => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
238
        -name     => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
235
        -values   => \@authorised_values,
239
        -values   => \@authorised_values,
Lines 521-532 sub build_tabs { Link Here
521
    my @loop_data = ();
525
    my @loop_data = ();
522
    my $tag;
526
    my $tag;
523
527
524
    my $authorised_values_sth = $dbh->prepare(
528
    my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
525
        "select authorised_value,lib
529
    my $query = "SELECT authorised_value, lib
526
        from authorised_values
530
                FROM authorised_values";
527
        where category=? order by lib"
531
    $query .= qq{ LEFT JOIN authorised_values_branches ON ( id = av_id )} if $branch_limit;
528
    );
532
    $query .= " WHERE category = ?";
529
    
533
    $query .= " AND ( branchcode = ? OR branchcode IS NULL )" if $branch_limit;
534
    $query .= " GROUP BY lib ORDER BY lib, lib_opac";
535
    my $authorised_values_sth = $dbh->prepare( $query );
536
530
    # in this array, we will push all the 10 tabs
537
    # in this array, we will push all the 10 tabs
531
    # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
538
    # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
532
    my @BIG_LOOP;
539
    my @BIG_LOOP;
Lines 711-716 sub build_tabs { Link Here
711
            };
718
            };
712
        }
719
        }
713
    }
720
    }
721
    $authorised_values_sth->finish;
714
    $template->param( BIG_LOOP => \@BIG_LOOP );
722
    $template->param( BIG_LOOP => \@BIG_LOOP );
715
}
723
}
716
724
(-)a/cataloguing/additem.pl (-7 / +6 lines)
Lines 104-111 sub generate_subfield_form { Link Here
104
  
104
  
105
  my $frameworkcode = &GetFrameworkCode($biblionumber);
105
  my $frameworkcode = &GetFrameworkCode($biblionumber);
106
        my %subfield_data;
106
        my %subfield_data;
107
        my $dbh = C4::Context->dbh;        
107
        my $dbh = C4::Context->dbh;
108
        my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib");
109
        
108
        
110
        my $index_subfield = int(rand(1000000)); 
109
        my $index_subfield = int(rand(1000000)); 
111
        if ($subfieldtag eq '@'){
110
        if ($subfieldtag eq '@'){
Lines 200-210 sub generate_subfield_form { Link Here
200
                  #---- "true" authorised value
199
                  #---- "true" authorised value
201
            }
200
            }
202
            else {
201
            else {
203
                  push @authorised_values, "" unless ( $subfieldlib->{mandatory} );
202
                  push @authorised_values, qq{} unless ( $subfieldlib->{mandatory} );
204
                  $authorised_values_sth->execute( $subfieldlib->{authorised_value} );
203
                  my $av = GetAuthorisedValues( $subfieldlib->{authorised_value} );
205
                  while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
204
                  for my $r ( @$av ) {
206
                      push @authorised_values, $value;
205
                      push @authorised_values, $r->{authorised_value};
207
                      $authorised_lib{$value} = $lib;
206
                      $authorised_lib{$r->{authorised_value}} = $r->{lib};
208
                  }
207
                  }
209
            }
208
            }
210
209
(-)a/installer/data/mysql/kohastructure.sql (+38 lines)
Lines 2867-2872 CREATE TABLE `quotes` ( Link Here
2867
  PRIMARY KEY (`id`)
2867
  PRIMARY KEY (`id`)
2868
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2868
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2869
2869
2870
--
2871
-- Table structure for table categories_branches
2872
--
2873
2874
DROP TABLE IF EXISTS categories_branches;
2875
CREATE TABLE categories_branches( -- association table between categories and branches
2876
    categorycode VARCHAR(10),
2877
    branchcode VARCHAR(10),
2878
    FOREIGN KEY (categorycode) REFERENCES categories(categorycode) ON DELETE CASCADE,
2879
    FOREIGN KEY (branchcode) REFERENCES branches(branchcode) ON DELETE CASCADE
2880
) ENGINE=INNODB DEFAULT CHARSET=utf8;
2881
2882
--
2883
-- Table structure for table authorised_values_branches
2884
--
2885
2886
DROP TABLE IF EXISTS authorised_values_branches;
2887
CREATE TABLE authorised_values_branches( -- association table between authorised_values and branches
2888
    av_id INTEGER,
2889
    branchcode VARCHAR(10),
2890
    FOREIGN KEY (av_id) REFERENCES authorised_values(id) ON DELETE CASCADE,
2891
    FOREIGN KEY (branchcode) REFERENCES branches(branchcode) ON DELETE CASCADE
2892
) ENGINE=INNODB DEFAULT CHARSET=utf8;
2893
2894
2895
--
2896
-- Table structure for table borrower_attribute_types_branches
2897
--
2898
2899
DROP TABLE IF EXISTS borrower_attribute_types_branches;
2900
CREATE TABLE borrower_attribute_types_branches( -- association table between borrower_attribute_types and branches
2901
    bat_code VARCHAR(10),
2902
    b_branchcode VARCHAR(10),
2903
    FOREIGN KEY (bat_code) REFERENCES borrower_attribute_types(code) ON DELETE CASCADE,
2904
    FOREIGN KEY (b_branchcode) REFERENCES branches(branchcode) ON DELETE CASCADE
2905
) ENGINE=INNODB DEFAULT CHARSET=utf8;
2906
2907
2870
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
2908
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
2871
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
2909
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
2872
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
2910
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
(-)a/installer/data/mysql/updatedatabase.pl (+13 lines)
Lines 5635-5640 if(C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
5635
    SetVersion($DBversion);
5635
    SetVersion($DBversion);
5636
}
5636
}
5637
5637
5638
5639
$DBversion = "3.09.00.XXX";
5640
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5641
    $dbh->do(qq{CREATE TABLE borrower_attribute_types_branches(bat_code VARCHAR(10), b_branchcode VARCHAR(10),FOREIGN KEY (bat_code) REFERENCES borrower_attribute_types(code) ON DELETE CASCADE,FOREIGN KEY (b_branchcode) REFERENCES branches(branchcode) ON DELETE CASCADE ) ENGINE=INNODB DEFAULT CHARSET=utf8;});
5642
5643
    $dbh->do(qq{CREATE TABLE categories_branches(categorycode VARCHAR(10), branchcode VARCHAR(10), FOREIGN KEY (categorycode) REFERENCES categories(categorycode) ON DELETE CASCADE, FOREIGN KEY (branchcode) REFERENCES branches(branchcode) ON DELETE CASCADE ) ENGINE=INNODB DEFAULT CHARSET=utf8;});
5644
5645
    $dbh->do(qq{CREATE TABLE authorised_values_branches(av_id INTEGER, branchcode VARCHAR(10), FOREIGN KEY (av_id) REFERENCES authorised_values(id) ON DELETE CASCADE, FOREIGN KEY  (branchcode) REFERENCES branches(branchcode) ON DELETE CASCADE ) ENGINE=INNODB DEFAULT CHARSET=utf8;});
5646
5647
    print "Upgrade to $DBversion done (Add 3 associations tables with branches)\n";
5648
    SetVersion($DBversion);
5649
}
5650
5638
=head1 FUNCTIONS
5651
=head1 FUNCTIONS
5639
5652
5640
=head2 TableExists($table)
5653
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt (-1 / +31 lines)
Lines 13-19 Link Here
13
		sortList: [[1,0]],
13
		sortList: [[1,0]],
14
		headers: { 4: { sorter: false}, 5: { sorter: false}}
14
		headers: { 4: { sorter: false}, 5: { sorter: false}}
15
		   		}).tablesorterPager({container: $("#pagertable_authorized_values"),positionFixed: false,size: 50});
15
		   		}).tablesorterPager({container: $("#pagertable_authorized_values"),positionFixed: false,size: 50});
16
	
16
17
    if ( $("#branches option:selected").length < 1 ) {
18
        $("#branches option:first").attr("selected", "selected");
19
    }
17
}); </script>
20
}); </script>
18
21
19
<script type="text/JavaScript" language="JavaScript">
22
<script type="text/JavaScript" language="JavaScript">
Lines 78-83 Link Here
78
            <label for="lib_opac">Description (OPAC)</label>
81
            <label for="lib_opac">Description (OPAC)</label>
79
            <input type="text" name="lib_opac" id="lib_opac" value="[% lib_opac %]" maxlength="80" />
82
            <input type="text" name="lib_opac" id="lib_opac" value="[% lib_opac %]" maxlength="80" />
80
        </li>
83
        </li>
84
        <li><label for="branches">Branches limitation: </label>
85
            <select id="branches" name="branches" multiple size="10">
86
                <option value="">All branches</option>
87
                [% FOREACH branch IN branches_loop %]
88
                  [% IF ( branch.selected ) %]
89
                    <option selected="selected" value="[% branch.branchcode %]">[% branch.branchname %]</option>
90
                  [% ELSE %]
91
                    <option value="[% branch.branchcode %]">[% branch.branchname %]</option>
92
                  [% END %]
93
                [% END %]
94
            </select>
95
            <span>Select All if this authorised value must to be displayed all the time. Otherwise select librairies you want to associate with this value.
96
            </span>
97
        </li>
98
81
		</ol>
99
		</ol>
82
        <div id="icons" class="toptabs" style="clear:both">
100
        <div id="icons" class="toptabs" style="clear:both">
83
        <h5 style="margin-left:10px;">Choose an icon:</h5>
101
        <h5 style="margin-left:10px;">Choose an icon:</h5>
Lines 231-236 Link Here
231
	<th>Description</th>
249
	<th>Description</th>
232
	<th>Description (OPAC)</th>
250
	<th>Description (OPAC)</th>
233
	<th>Icon</th>
251
	<th>Icon</th>
252
    <th>Branches limitations</th>
234
	<th>Edit</th>
253
	<th>Edit</th>
235
	<th>Delete</th>
254
	<th>Delete</th>
236
	</tr>
255
	</tr>
Lines 245-250 Link Here
245
	<td>[% loo.lib %]</td>
264
	<td>[% loo.lib %]</td>
246
	<td>[% loo.lib_opac %]</td>
265
	<td>[% loo.lib_opac %]</td>
247
	<td>[% IF ( loo.imageurl ) %]<img src="[% loo.imageurl %]" alt=""/>[% ELSE %]&nbsp;[% END %]</td>
266
	<td>[% IF ( loo.imageurl ) %]<img src="[% loo.imageurl %]" alt=""/>[% ELSE %]&nbsp;[% END %]</td>
267
    <td>
268
        [% IF loo.branches.size > 0 %]
269
            [% branches_str = "" %]
270
            [% FOREACH branch IN loo.branches %]
271
                [% branches_str = branches_str _ " " _ branch.branchname _ "(" _ branch.branchcode _ ")" %]
272
            [% END %]
273
            <a href="#" title="[% branches_str %]">[% loo.branches.size %] branches limitations</a>
274
        [% ELSE %]
275
            No limitation
276
        [% END %]
277
    </td>
248
	<td><a href="[% loo.edit %]">Edit</a></td>
278
	<td><a href="[% loo.edit %]">Edit</a></td>
249
	<td><a href="[% loo.delete %]">Delete</a></td>
279
	<td><a href="[% loo.delete %]">Delete</a></td>
250
</tr>
280
</tr>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tt (-1 / +32 lines)
Lines 14-19 Link Here
14
		headers: { 11: { sorter: false}}
14
		headers: { 11: { sorter: false}}
15
	}).tablesorterPager({container: $("#pagertable_categorie"),positionFixed: false,size: 20});
15
	}).tablesorterPager({container: $("#pagertable_categorie"),positionFixed: false,size: 20});
16
    $( "#enrolmentperioddate" ).datepicker({ minDate: 1 }); // Require that "until date" be in the future
16
    $( "#enrolmentperioddate" ).datepicker({ minDate: 1 }); // Require that "until date" be in the future
17
18
    if ( $("#branches option:selected").length < 1 ) {
19
        $("#branches option:first").attr("selected", "selected");
20
    }
17
}); </script>
21
}); </script>
18
<script type="text/javascript">
22
<script type="text/javascript">
19
//<![CDATA[
23
//<![CDATA[
Lines 179-185 Link Here
179
					[% IF ( type_P ) %]<option value="P" selected="selected">Professional</option>[% ELSE %]<option value="P">Professional</option>[% END %]
183
					[% IF ( type_P ) %]<option value="P" selected="selected">Professional</option>[% ELSE %]<option value="P">Professional</option>[% END %]
180
					[% IF ( type_X ) %]<option value="X" selected="selected">Statistical</option>[% ELSE %]<option value="X">Statistical</option>[% END %]
184
					[% IF ( type_X ) %]<option value="X" selected="selected">Statistical</option>[% ELSE %]<option value="X">Statistical</option>[% END %]
181
					</select>
185
					</select>
182
	</li></ol>
186
    </li>
187
    <li><label for="branches">Branches limitation: </label>
188
        <select id="branches" name="branches" multiple size="10">
189
            <option value="">All branches</option>
190
            [% FOREACH branch IN branches_loop %]
191
              [% IF ( branch.selected ) %]
192
                <option selected="selected" value="[% branch.branchcode %]">[% branch.branchname %]</option>
193
              [% ELSE %]
194
                <option value="[% branch.branchcode %]">[% branch.branchname %]</option>
195
              [% END %]
196
            [% END %]
197
        </select>
198
        <span>Select All if this category type must to be displayed all the time. Otherwise select librairies you want to associate with this value.
199
        </span>
200
    </li>
201
    </ol>
183
</fieldset>
202
</fieldset>
184
203
185
    [% IF ( EnhancedMessagingPreferences ) %]
204
    [% IF ( EnhancedMessagingPreferences ) %]
Lines 292-297 Confirm deletion of category [% categorycode |html %][% END %]</legend> Link Here
292
            [% IF ( EnhancedMessagingPreferences ) %]
311
            [% IF ( EnhancedMessagingPreferences ) %]
293
            <th scope="col">Messaging</th>
312
            <th scope="col">Messaging</th>
294
            [% END %]
313
            [% END %]
314
            <th scope="col">Branches limitations</th>
295
			<th scope="col" colspan="2">&nbsp; </th>
315
			<th scope="col" colspan="2">&nbsp; </th>
296
		</thead>
316
		</thead>
297
		[% FOREACH loo IN loop %]
317
		[% FOREACH loo IN loop %]
Lines 345-350 Confirm deletion of category [% categorycode |html %][% END %]</legend> Link Here
345
                            [% END %]
365
                            [% END %]
346
                        </td>
366
                        </td>
347
                        [% END %]
367
                        [% END %]
368
                        <td>
369
                            [% IF loo.branches.size > 0 %]
370
                                [% branches_str = "" %]
371
                                [% FOREACH branch IN loo.branches %]
372
                                    [% branches_str = branches_str _ " " _ branch.branchname _ "(" _ branch.branchcode _ ")" %]
373
                                [% END %]
374
                                <a href="#" title="[% branches_str %]">[% loo.branches.size %] branches limitations</a>
375
                            [% ELSE %]
376
                                No limitation
377
                            [% END %]
378
                        </td>
348
                        <td><a href="[% loo.script_name %]?op=add_form&amp;categorycode=[% loo.categorycode |uri %]">Edit</a></td>
379
                        <td><a href="[% loo.script_name %]?op=add_form&amp;categorycode=[% loo.categorycode |uri %]">Edit</a></td>
349
                        <td><a href="[% loo.script_name %]?op=delete_confirm&amp;categorycode=[% loo.categorycode |uri %]">Delete</a></td>
380
                        <td><a href="[% loo.script_name %]?op=delete_confirm&amp;categorycode=[% loo.categorycode |uri %]">Delete</a></td>
350
		</tr>
381
		</tr>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt (+31 lines)
Lines 15-20 Link Here
15
15
16
<script type="text/javascript">
16
<script type="text/javascript">
17
//<![CDATA[
17
//<![CDATA[
18
$(document).ready(function() {
19
    if ( $("#branches option:selected").length < 1 ) {
20
        $("#branches option:first").attr("selected", "selected");
21
    }
22
} );
18
23
19
function DoCancel(f) {
24
function DoCancel(f) {
20
  f.op.value='';
25
  f.op.value='';
Lines 186-191 function CheckAttributeTypeForm(f) { Link Here
186
                  to be chosen from the authorized value list.  However, an authorized value list is not 
191
                  to be chosen from the authorized value list.  However, an authorized value list is not 
187
                  enforced during batch patron import.</span>
192
                  enforced during batch patron import.</span>
188
        </li>
193
        </li>
194
        <li><label for="branches">Branches limitation: </label>
195
            <select id="branches" name="branches" multiple size="10">
196
                <option value="">All branches</option>
197
                [% FOREACH branch IN branches_loop %]
198
                  [% IF ( branch.selected ) %]
199
                    <option selected="selected" value="[% branch.branchcode %]">[% branch.branchname %]</option>
200
                  [% ELSE %]
201
                    <option value="[% branch.branchcode %]">[% branch.branchname %]</option>
202
                  [% END %]
203
                [% END %]
204
            </select>
205
            <span>Select All if this attribute type must to be displayed all the time. Otherwise select librairies you want to associate with this value.
206
            </span>
207
        </li>
189
        <li>
208
        <li>
190
            <label for="category">Category: </label>
209
            <label for="category">Category: </label>
191
            <select name="category_code" id="category">
210
            <select name="category_code" id="category">
Lines 287-292 function CheckAttributeTypeForm(f) { Link Here
287
          <th>Code</th>
306
          <th>Code</th>
288
          <th>Description</th>
307
          <th>Description</th>
289
          <th>Actions</th>
308
          <th>Actions</th>
309
          <th>Branches limitation</th>
290
        </tr>
310
        </tr>
291
      </thead>
311
      </thead>
292
      <tbody>
312
      <tbody>
Lines 295-300 function CheckAttributeTypeForm(f) { Link Here
295
            <td>[% item.code |html %]</td>
315
            <td>[% item.code |html %]</td>
296
            <td>[% item.description %]</td>
316
            <td>[% item.description %]</td>
297
            <td>
317
            <td>
318
                [% IF item.branches > 0 %]
319
                    [% branches_str = "" %]
320
                    [% FOREACH branch IN item.branches %]
321
                        [% branches_str = branches_str _ " " _ branch.branchname _ "(" _ branch.branchcode _ ")" %]
322
                    [% END %]
323
                    <a href="#" title="[% branches_str %]">[% item.branches.size %] branches limitations</a>
324
                [% ELSE %]
325
                    No limitation
326
                [% END %]
327
            </td>
328
            <td>
298
              <a href="[% item.script_name %]?op=edit_attribute_type&amp;code=[% item.code |html %]">Edit</a>
329
              <a href="[% item.script_name %]?op=edit_attribute_type&amp;code=[% item.code |html %]">Edit</a>
299
              <a href="[% item.script_name %]?op=delete_attribute_type&amp;code=[% item.code |html %]">Delete</a>
330
              <a href="[% item.script_name %]?op=delete_attribute_type&amp;code=[% item.code |html %]">Delete</a>
300
            </td>
331
            </td>
(-)a/members/member.pl (-2 / +2 lines)
Lines 135-142 foreach my $borrower(@$results[$from..$to-1]){ Link Here
135
135
136
  my %row = (
136
  my %row = (
137
    count => $index++,
137
    count => $index++,
138
	%$borrower,
138
    %$borrower,
139
	%{$categories_dislay{$$borrower{categorycode}}},
139
    (defined $categories_dislay{ $borrower->{categorycode} }?   %{ $categories_dislay{ $borrower->{categorycode} } }:()),
140
    overdues => $od,
140
    overdues => $od,
141
    issues => $issue,
141
    issues => $issue,
142
    odissue => "$od/$issue",
142
    odissue => "$od/$issue",
(-)a/tools/batchMod.pl (-2 / +10 lines)
Lines 265-271 if ($op eq "show"){ Link Here
265
# now, build the item form for entering a new item
265
# now, build the item form for entering a new item
266
my @loop_data =();
266
my @loop_data =();
267
my $i=0;
267
my $i=0;
268
my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib");
268
my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
269
my $query = qq{SELECT authorised_value, lib FROM authorised_values};
270
$query  .= qq{ LEFT JOIN authorised_values_branches ON ( id = av_id ) } if $branch_limit;
271
$query  .= qq{ WHERE category = ?};
272
$query  .= qq{ AND ( branchcode = ? OR branchcode IS NULL ) } if $branch_limit;
273
$query  .= qq{ GROUP BY lib ORDER BY lib, lib_opac};
274
my $authorised_values_sth = $dbh->prepare( $query );
269
275
270
my $branches = GetBranchesLoop();  # build once ahead of time, instead of multiple times later.
276
my $branches = GetBranchesLoop();  # build once ahead of time, instead of multiple times later.
271
277
Lines 358-364 foreach my $tag (sort keys %{$tagslib}) { Link Here
358
      }
364
      }
359
      else {
365
      else {
360
          push @authorised_values, ""; # unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
366
          push @authorised_values, ""; # unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
361
          $authorised_values_sth->execute( $tagslib->{$tag}->{$subfield}->{authorised_value} );
367
          $authorised_values_sth->execute( $tagslib->{$tag}->{$subfield}->{authorised_value}, $branch_limit ? $branch_limit : () );
362
          while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
368
          while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
363
              push @authorised_values, $value;
369
              push @authorised_values, $value;
364
              $authorised_lib{$value} = $lib;
370
              $authorised_lib{$value} = $lib;
Lines 426-431 foreach my $tag (sort keys %{$tagslib}) { Link Here
426
    $i++
432
    $i++
427
  }
433
  }
428
} # -- End foreach tag
434
} # -- End foreach tag
435
$authorised_values_sth->finish;
436
429
437
430
438
431
    # what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
439
    # what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
(-)a/tools/import_borrowers.pl (-2 / +1 lines)
Lines 304-310 if ( $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
304
} else {
304
} else {
305
    if ($extended) {
305
    if ($extended) {
306
        my @matchpoints = ();
306
        my @matchpoints = ();
307
        my @attr_types = C4::Members::AttributeTypes::GetAttributeTypes();
307
        my @attr_types = C4::Members::AttributeTypes::GetAttributeTypes(undef, 1);
308
        foreach my $type (@attr_types) {
308
        foreach my $type (@attr_types) {
309
            my $attr_type = C4::Members::AttributeTypes->fetch($type->{code});
309
            my $attr_type = C4::Members::AttributeTypes->fetch($type->{code});
310
            if ($attr_type->unique_id()) {
310
            if ($attr_type->unique_id()) {
311
- 

Return to bug 7919