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);
103 my $OPACBaseURL = C4::Context->preference('OPACBaseURL') // '';
104 $OPACBaseURL =~ s#/$##;
106 $template->param(MissingURL => 1);
108 if($id && $OPACBaseURL) {
109 my $return = "$OPACBaseURL/cgi-bin/koha/opac-retrieve-file.pl?id=$id";
113 uploaded_file => $uploaded_file,
116 $template->param(error => 1);
118 } elsif ($delete || ($id && ($dangling==0 || $dangling==1))) {
119 # If there's already a file uploaded for this field,
120 # We handle its deletion
122 if(C4::UploadedFiles::DelUploadedFile($id)==0) {;
123 $template->param(error => 1);
125 $template->param(success => 1);
129 my $upload_path = C4::Context->config('upload_path');
131 my $filefield = CGI::filefield(
132 -name => 'uploaded_file',
139 dirs => finddirs($upload_path)
143 dirs_tree => $dirs_tree,
144 filefield => $filefield
147 $template->param( error_upload_path_not_configured => 1 );
150 if (!$uploaded_file && !$dir && $from_popup) {
151 $template->param(error_nothing_selected => 1);
153 elsif (!$uploaded_file && $dir) {
154 $template->param(error_no_file_selected => 1);
156 if ($uploaded_file and not $dir) {
157 $template->param(error_no_dir_selected => 1);
167 output_html_with_http_headers $input, $cookie, $template->output;
170 # Build a hierarchy of directories
173 my $upload_path = C4::Context->config('upload_path');
176 my @files = glob("$base/*");
178 if (-d $_ and -w $_) {
179 my $lastdirname = basename($_);
181 $dirname =~ s/^$upload_path//g;
184 name => $lastdirname,
200 This plugin allow to upload files on the server and reference it in a marc
203 Two system preference are used:
207 =item * upload_path: the real absolute path where files will be stored
209 =item * OPACBaseURL: for building URLs to be stored in MARC