|
Lines 20-25
Link Here
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use CGI qw ( -utf8 ); |
22 |
use CGI qw ( -utf8 ); |
|
|
23 |
use List::MoreUtils qw(any); |
| 24 |
|
| 23 |
use C4::Auth; |
25 |
use C4::Auth; |
| 24 |
use C4::Context; |
26 |
use C4::Context; |
| 25 |
use C4::Koha; |
27 |
use C4::Koha; |
|
Lines 49-70
our ($template, $borrowernumber, $cookie)= get_template_and_user({
Link Here
|
| 49 |
################## ADD_FORM ################################## |
51 |
################## ADD_FORM ################################## |
| 50 |
# called by default. Used to create form to add or modify a record |
52 |
# called by default. Used to create form to add or modify a record |
| 51 |
if ($op eq 'add_form') { |
53 |
if ($op eq 'add_form') { |
| 52 |
my ( $selected_branches, $category, $av ); |
54 |
my ( @selected_branches, $category, $av ); |
| 53 |
if ($id) { |
55 |
if ($id) { |
| 54 |
$av = Koha::AuthorisedValues->new->find( $id ); |
56 |
$av = Koha::AuthorisedValues->new->find( $id ); |
| 55 |
$selected_branches = $av->branch_limitations; |
57 |
@selected_branches = $av->library_limits->as_list; |
| 56 |
} else { |
58 |
} else { |
| 57 |
$category = $input->param('category'); |
59 |
$category = $input->param('category'); |
| 58 |
} |
60 |
} |
| 59 |
|
61 |
|
| 60 |
my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed; |
62 |
my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } ); |
| 61 |
my @branches_loop; |
63 |
my @branches_loop; |
| 62 |
foreach my $branch ( @$branches ) { |
64 |
while ( my $branch = $branches->next ) { |
| 63 |
my $selected = ( grep {$_ eq $branch->{branchcode}} @$selected_branches ) ? 1 : 0; |
|
|
| 64 |
push @branches_loop, { |
65 |
push @branches_loop, { |
| 65 |
branchcode => $branch->{branchcode}, |
66 |
branchcode => $branch->branchcode, |
| 66 |
branchname => $branch->{branchname}, |
67 |
branchname => $branch->branchname, |
| 67 |
selected => $selected, |
68 |
selected => any {$_->branchcode eq $branch->branchcode} @selected_branches, |
| 68 |
}; |
69 |
}; |
| 69 |
} |
70 |
} |
| 70 |
|
71 |
|
|
Lines 126-132
if ($op eq 'add_form') {
Link Here
|
| 126 |
$av->imageurl( $imageurl ); |
127 |
$av->imageurl( $imageurl ); |
| 127 |
eval{ |
128 |
eval{ |
| 128 |
$av->store; |
129 |
$av->store; |
| 129 |
$av->replace_branch_limitations( \@branches ); |
130 |
$av->replace_library_limits( \@branches ); |
| 130 |
}; |
131 |
}; |
| 131 |
if ( $@ ) { |
132 |
if ( $@ ) { |
| 132 |
push @messages, {type => 'error', code => 'error_on_update' }; |
133 |
push @messages, {type => 'error', code => 'error_on_update' }; |
|
Lines 145-151
if ($op eq 'add_form') {
Link Here
|
| 145 |
|
146 |
|
| 146 |
eval { |
147 |
eval { |
| 147 |
$av->store; |
148 |
$av->store; |
| 148 |
$av->replace_branch_limitations( \@branches ); |
149 |
$av->replace_library_limits( \@branches ); |
| 149 |
}; |
150 |
}; |
| 150 |
|
151 |
|
| 151 |
if ( $@ ) { |
152 |
if ( $@ ) { |
|
Lines 230-236
if ( $op eq 'list' ) {
Link Here
|
| 230 |
$row_data{lib} = $av->lib; |
231 |
$row_data{lib} = $av->lib; |
| 231 |
$row_data{lib_opac} = $av->lib_opac; |
232 |
$row_data{lib_opac} = $av->lib_opac; |
| 232 |
$row_data{imageurl} = getitemtypeimagelocation( 'intranet', $av->imageurl ); |
233 |
$row_data{imageurl} = getitemtypeimagelocation( 'intranet', $av->imageurl ); |
| 233 |
$row_data{branches} = $av->branch_limitations; |
234 |
$row_data{branches} = $av->library_limits->as_list; |
| 234 |
$row_data{id} = $av->id; |
235 |
$row_data{id} = $av->id; |
| 235 |
push(@loop_data, \%row_data); |
236 |
push(@loop_data, \%row_data); |
| 236 |
} |
237 |
} |