Bug 22770: DBRev 19.05.00.003
[koha.git] / admin / overdrive.pl
1 #!/usr/bin/perl
2
3 # Copyright Koha Development Team
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21 use CGI qw ( -utf8 );
22 use C4::Auth;
23 use C4::Context;
24 use C4::Output;
25
26 use Koha::Libraries;
27 use Koha::Library::OverDriveInfos;
28
29 my $input         = CGI->new;
30 my @branchcodes   = $input->multi_param('branchcode');
31 my @authnames     = $input->multi_param('authname');
32 my $op            = $input->param('op');
33
34 our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
35     {   template_name   => 'admin/overdrive.tt',
36         query           => $input,
37         type            => 'intranet',
38         authnotrequired => 0,
39         flagsrequired   => { parameters => 'parameters_remaining_permissions' },
40     }
41 );
42
43 if ( $op && $op eq 'update' ) {
44     my %od_info;
45     @od_info{ @branchcodes } = @authnames;
46     while( my($branchcode,$authname) = each %od_info){
47         my $cur_info = Koha::Library::OverDriveInfos->find($branchcode);
48         if( $cur_info ) {
49             $cur_info->authname($authname)->store;
50         } else {
51             Koha::Library::OverDriveInfo->new({
52                 branchcode => $branchcode,
53                 authname   => $authname,
54             })->store;
55         }
56     }
57 }
58
59 my @branches = Koha::Libraries->search();
60 my @branch_od_info;
61 foreach my $branch ( @branches ){
62     my $od_info =  Koha::Library::OverDriveInfos->find($branch->branchcode);
63     if( $od_info ){
64         push @branch_od_info, { branchcode => $od_info->branchcode, authname => $od_info->authname };
65     } else {
66         push @branch_od_info, { branchcode => $branch->branchcode, authname => "" };
67     }
68 }
69
70 $template->param(
71     branches => \@branch_od_info,
72 );
73
74 output_html_with_http_headers $input, $cookie, $template->output;