3 # Converted to new plugin style (Bug 6874/See also 13437)
5 # This file is part of Koha.
7 # Copyright (C) 2011-2012 BibLibre
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
28 use C4::UploadedFiles;
32 my $function_name = $params->{id};
34 <script type=\"text/javascript\">
35 function Click$function_name(event) {
36 var index = event.data.id;
37 var id = document.getElementById(index).value;
38 var IsFileUploadUrl=0;
39 if (id.match(/opac-retrieve-file/)) {
42 if(id.match(/id=([0-9a-f]+)/)){
45 var newin=window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=upload.pl&index=\"+index+\"&id=\"+id+\"&from_popup=0\"+\"&IsFileUploadUrl=\"+IsFileUploadUrl, 'upload', 'width=600,height=400,toolbar=false,scrollbars=no');
55 my $input = $params->{cgi};
56 my $index = $input->param('index');
57 my $id = $input->param('id');
58 my $delete = $input->param('delete');
59 my $uploaded_file = $input->param('uploaded_file');
60 my $from_popup = $input->param('from_popup');
61 my $isfileuploadurl = $input->param('IsFileUploadUrl');
62 my $dangling = C4::UploadedFiles::DanglingEntry($id,$isfileuploadurl);
64 if ($delete || ($id && ($dangling==0 || $dangling==1))) {
65 $template_name = "upload_delete_file.tt";
68 $template_name = "upload.tt";
71 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
72 { template_name => "cataloguing/value_builder/$template_name",
76 flagsrequired => { editcatalogue => '*' },
82 $template->param( dangling => 1 );
85 # Dealing with the uploaded file
86 my $dir = $input->param('uploadcategory');
87 if ($uploaded_file and $dir) {
88 my $fh = $input->upload('uploaded_file');
90 $id = C4::UploadedFiles::UploadFile($uploaded_file, $dir, $fh->handle);
91 my $OPACBaseURL = C4::Context->preference('OPACBaseURL') // '';
92 $OPACBaseURL =~ s#/$##;
94 $template->param(MissingURL => 1);
96 if($id && $OPACBaseURL) {
97 my $return = "$OPACBaseURL/cgi-bin/koha/opac-retrieve-file.pl?id=$id";
101 uploaded_file => $uploaded_file,
104 $template->param(error => 1);
106 } elsif ($delete || ($id && ($dangling==0 || $dangling==1))) {
107 # If there's already a file uploaded for this field,
108 # We handle its deletion
110 if(C4::UploadedFiles::DelUploadedFile($id)==0) {;
111 $template->param(error => 1);
113 $template->param(success => 1);
117 my $upload_path = C4::Context->config('upload_path');
119 my $filefield = CGI::filefield(
120 -name => 'uploaded_file',
124 filefield => $filefield,
125 uploadcategories => C4::UploadedFiles::getCategories(),
128 $template->param( error_upload_path_not_configured => 1 );
131 if (!$uploaded_file && !$dir && $from_popup) {
132 $template->param(error_nothing_selected => 1);
134 elsif (!$uploaded_file && $dir) {
135 $template->param(error_no_file_selected => 1);
137 if ($uploaded_file and not $dir) {
138 $template->param(error_no_dir_selected => 1);
148 output_html_with_http_headers $input, $cookie, $template->output;
151 return { builder => $builder, launcher => $launcher };
159 This plugin allows to upload files on the server and reference it in a marc
162 It uses config variable upload_path and pref OPACBaseURL.