3 # This file is part of Koha.
5 # Copyright (C) 2011-2012 BibLibre
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.
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.
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>.
27 use C4::UploadedFiles;
29 sub plugin_parameters {
30 my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_;
34 sub plugin_javascript {
35 my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
36 my $function_name = $field_number;
38 <script type=\"text/javascript\">
39 function Focus$function_name(subfield_managed) {
43 function Blur$function_name(subfield_managed) {
47 function Clic$function_name(index) {
48 var id = document.getElementById(index).value;
49 var IsFileUploadUrl=0;
50 if (id.match(/opac-retrieve-file/)) {
53 if(id.match(/id=([0-9a-f]+)/)){
56 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');
63 return ( $function_name, $res );
68 my $index = $input->param('index');
69 my $id = $input->param('id');
70 my $delete = $input->param('delete');
71 my $uploaded_file = $input->param('uploaded_file');
72 my $from_popup = $input->param('from_popup');
73 my $isfileuploadurl = $input->param('IsFileUploadUrl');
74 my $dangling = C4::UploadedFiles::DanglingEntry($id,$isfileuploadurl);
76 if ($delete || ($id && ($dangling==0 || $dangling==1))) {
77 $template_name = "upload_delete_file.tt";
80 $template_name = "upload.tt";
83 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
84 { template_name => "cataloguing/value_builder/$template_name",
88 flagsrequired => { editcatalogue => '*' },
94 $template->param( dangling => 1 );
97 # Dealing with the uploaded file
98 my $dir = $input->param('dir');
99 if ($uploaded_file and $dir) {
100 my $fh = $input->upload('uploaded_file');
102 $id = C4::UploadedFiles::UploadFile($uploaded_file, $dir, $fh->handle);
104 my $OPACBaseURL = C4::Context->preference('OPACBaseURL');
105 $OPACBaseURL =~ s#/$##;
106 my $return = "$OPACBaseURL/cgi-bin/koha/opac-retrieve-file.pl?id=$id";
110 uploaded_file => $uploaded_file,
113 $template->param(error => 1);
115 } elsif ($delete || ($id && ($dangling==0 || $dangling==1))) {
116 # If there's already a file uploaded for this field,
117 # We handle its deletion
119 if(C4::UploadedFiles::DelUploadedFile($id)==0) {;
120 $template->param(error => 1);
122 $template->param(success => 1);
126 my $upload_path = C4::Context->config('upload_path');
128 my $filefield = CGI::filefield(
129 -name => 'uploaded_file',
136 dirs => finddirs($upload_path)
140 dirs_tree => $dirs_tree,
141 filefield => $filefield
144 $template->param( error_upload_path_not_configured => 1 );
147 if (!$uploaded_file && !$dir && $from_popup) {
148 $template->param(error_nothing_selected => 1);
150 elsif (!$uploaded_file && $dir) {
151 $template->param(error_no_file_selected => 1);
153 if ($uploaded_file and not $dir) {
154 $template->param(error_no_dir_selected => 1);
164 output_html_with_http_headers $input, $cookie, $template->output;
167 # Build a hierarchy of directories
170 my $upload_path = C4::Context->config('upload_path');
173 my @files = glob("$base/*");
175 if (-d $_ and -w $_) {
176 my $lastdirname = basename($_);
178 $dirname =~ s/^$upload_path//g;
181 name => $lastdirname,
197 This plugin allow to upload files on the server and reference it in a marc
200 Two system preference are used:
204 =item * upload_path: the real absolute path where files will be stored
206 =item * OPACBaseURL: for building URLs to be stored in MARC