3 # Copyright 2011-2012 BibLibre
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 use C4::UploadedFiles;
29 my $upload_path = C4::Context->preference('uploadPath');
31 sub plugin_parameters {
32 my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_;
36 sub plugin_javascript {
37 my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
38 my $function_name = $field_number;
40 <script type=\"text/javascript\">
41 function Focus$function_name(subfield_managed) {
45 function Blur$function_name(subfield_managed) {
49 function Clic$function_name(index) {
50 var id = document.getElementById(index).value;
51 if(id.match(/id=([0-9a-f]+)/)){
54 window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=upload.pl&index=\"+index+\"&id=\"+id, 'upload', 'width=600,height=400,toolbar=false,scrollbars=no');
60 return ( $function_name, $res );
65 my $index = $input->param('index');
66 my $id = $input->param('id');
67 my $delete = $input->param('delete');
68 my $uploaded_file = $input->param('uploaded_file');
70 my $template_name = ($id || $delete)
71 ? "upload_delete_file.tt"
74 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
75 { template_name => "cataloguing/value_builder/$template_name",
79 flagsrequired => { editcatalogue => '*' },
84 # Dealing with the uploaded file
86 my $fh = $input->upload('uploaded_file');
87 my $dir = $input->param('dir');
89 $id = C4::UploadedFiles::UploadFile($uploaded_file, $dir, $fh->handle);
91 my $OPACBaseURL = C4::Context->preference('OPACBaseURL');
92 $OPACBaseURL =~ s#/$##;
93 my $return = "$OPACBaseURL/cgi-bin/koha/opac-retrieve-file.pl?id=$id";
97 uploaded_file => $uploaded_file,
100 $template->param(error => 1);
102 } elsif ($delete || $id) {
103 # If there's already a file uploaded for this field,
104 # We handle its deletion
106 if(C4::UploadedFiles::DelUploadedFile($id)) {;
107 $template->param(success => 1);
109 $template->param(error => 1);
113 my $filefield = CGI::filefield(
114 -name => 'uploaded_file',
121 dirs => finddirs($upload_path)
125 dirs_tree => $dirs_tree,
126 filefield => $filefield
135 output_html_with_http_headers $input, $cookie, $template->output;
138 # Build a hierarchy of directories
140 my $base = shift || $upload_path;
143 my @files = <$base/*>;
145 if (-d $_ and -w $_) {
146 my $lastdirname = basename($_);
148 $dirname =~ s/^$upload_path//g;
151 name => $lastdirname,
167 This plugin allow to upload files on the server and reference it in a marc
170 Two system preference are used:
174 =item * uploadPath: the real absolute path where files will be stored
176 =item * OPACBaseURL: for building URLs to be stored in MARC