3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 die("Koha plugins are disabled!")
34 unless C4::Context->preference('UseKohaPlugins');
38 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39 { template_name => "plugins/plugins-upload.tmpl",
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 ( ( $op eq 'Upload' ) && $uploadfile ) {
57 my $plugins_dir = C4::Context->config("pluginsdir");
59 my $dirname = File::Temp::tempdir( CLEANUP => 1 );
60 $debug and warn "dirname = $dirname";
63 $filesuffix = $1 if $uploadfilename =~ m/(\..+)$/i;
64 ( $tfh, $tempfile ) = File::Temp::tempfile( SUFFIX => $filesuffix, UNLINK => 1 );
66 $debug and warn "tempfile = $tempfile";
68 $errors{'NOTKPZ'} = 1 if ( $uploadfilename !~ /\.kpz$/i );
69 $errors{'NOWRITETEMP'} = 1 unless ( -w $dirname );
70 $errors{'NOWRITEPLUGINS'} = 1 unless ( -w $plugins_dir );
71 $errors{'EMPTYUPLOAD'} = 1 unless ( length($uploadfile) > 0 );
74 $template->param( ERRORS => [ \%errors ] );
76 while (<$uploadfile>) {
81 my $ae = Archive::Extract->new( archive => $tempfile, type => 'zip' );
82 unless ( $ae->extract( to => $plugins_dir ) ) {
83 warn "ERROR: " . $ae->error;
84 $errors{'UZIPFAIL'} = $uploadfilename;
85 $template->param( ERRORS => [ \%errors ] );
86 output_html_with_http_headers $input, $cookie, $template->output;
90 } elsif ( ( $op eq 'Upload' ) && !$uploadfile ) {
91 warn "Problem uploading file or no file uploaded.";
94 if ( $uploadfile && !%errors && !$template->param('ERRORS') ) {
95 print $input->redirect("/cgi-bin/koha/plugins/plugins-home.pl");
97 output_html_with_http_headers $input, $cookie, $template->output;