4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any later
11 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with Koha; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
34 my $plugins_enabled = C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins");
38 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39 { template_name => ($plugins_enabled) ? "plugins/plugins-upload.tmpl" : "plugins/plugins-disabled.tt",
43 flagsrequired => { plugins => 'manage' },
48 my $uploadfilename = $input->param('uploadfile');
49 my $uploadfile = $input->upload('uploadfile');
50 my $op = $input->param('op');
52 my ( $total, $handled, @counts, $tempfile, $tfh );
56 if ($plugins_enabled) {
57 if ( ( $op eq 'Upload' ) && $uploadfile ) {
58 my $plugins_dir = C4::Context->config("pluginsdir");
60 my $dirname = File::Temp::tempdir( CLEANUP => 1 );
61 $debug and warn "dirname = $dirname";
64 $filesuffix = $1 if $uploadfilename =~ m/(\..+)$/i;
65 ( $tfh, $tempfile ) = File::Temp::tempfile( SUFFIX => $filesuffix, UNLINK => 1 );
67 $debug and warn "tempfile = $tempfile";
69 $errors{'NOTKPZ'} = 1 if ( $uploadfilename !~ /\.kpz$/i );
70 $errors{'NOWRITETEMP'} = 1 unless ( -w $dirname );
71 $errors{'NOWRITEPLUGINS'} = 1 unless ( -w $plugins_dir );
72 $errors{'EMPTYUPLOAD'} = 1 unless ( length($uploadfile) > 0 );
75 $template->param( ERRORS => [ \%errors ] );
77 while (<$uploadfile>) {
82 my $ae = Archive::Extract->new( archive => $tempfile, type => 'zip' );
83 unless ( $ae->extract( to => $plugins_dir ) ) {
84 warn "ERROR: " . $ae->error;
85 $errors{'UZIPFAIL'} = $uploadfilename;
86 $template->param( ERRORS => [ \%errors ] );
87 output_html_with_http_headers $input, $cookie, $template->output;
91 } elsif ( ( $op eq 'Upload' ) && !$uploadfile ) {
92 warn "Problem uploading file or no file uploaded.";
95 if ( $uploadfile && !%errors && !$template->param('ERRORS') ) {
96 print $input->redirect("/cgi-bin/koha/plugins/plugins-home.pl");
98 output_html_with_http_headers $input, $cookie, $template->output;
102 output_html_with_http_headers $input, $cookie, $template->output;