From 09de76256703a64145f1821aff470bfaf2aec3f4 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 12 Jan 2012 11:49:47 +0100 Subject: [PATCH] Bug 6874: File upload in MARC --- C4/Biblio.pm | 30 +++- C4/UploadedFiles.pm | 106 ++++++++++++++ basket/basket.pl | 2 +- catalogue/MARCdetail.pl | 11 ++ catalogue/detail.pl | 2 +- cataloguing/value_builder/upload.pl | 148 ++++++++++++++++++++ installer/data/mysql/kohastructure.sql | 10 ++ installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 19 +++ .../prog/en/modules/catalogue/MARCdetail.tt | 80 +++++++++-- .../en/modules/cataloguing/value_builder/upload.tt | 47 ++++++ .../value_builder/upload_delete_file.tt | 49 +++++++ kohaversion.pl | 2 +- misc/strip_value_from_tag.pl | 60 ++++++++ opac/opac-MARCdetail.pl | 10 ++ opac/opac-basket.pl | 2 +- opac/opac-detail.pl | 2 +- opac/opac-retrieve-file.pl | 33 +++++ 18 files changed, 593 insertions(+), 21 deletions(-) create mode 100644 C4/UploadedFiles.pm create mode 100755 cataloguing/value_builder/upload.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/upload.tt create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/upload_delete_file.tt create mode 100644 misc/strip_value_from_tag.pl create mode 100755 opac/opac-retrieve-file.pl diff --git a/C4/Biblio.pm b/C4/Biblio.pm index ac78ae3..13b7d51 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -35,6 +35,7 @@ use C4::Dates qw/format_date/; use C4::Log; # logaction use C4::ClassSource; use C4::Charset; +use C4::UploadedFiles; require C4::Heading; require C4::Serials; require C4::Items; @@ -1627,7 +1628,7 @@ sub GetMarcAuthors { =head2 GetMarcUrls - $marcurls = GetMarcUrls($record,$marcflavour); + $marcurls = GetMarcUrls($record,$marcflavour,$frameworkcode); Returns arrayref of URLs from MARC data, suitable to pass to tmpl loop. Assumes web resources (not uncommon in MARC21 to omit resource type ind) @@ -1635,15 +1636,19 @@ Assumes web resources (not uncommon in MARC21 to omit resource type ind) =cut sub GetMarcUrls { - my ( $record, $marcflavour ) = @_; + my ( $record, $marcflavour, $frameworkcode ) = @_; + + my $tagslib = &GetMarcStructure(1, $frameworkcode); + my $urltag = '856'; + my $urlsubtag = 'u'; my @marcurls; - for my $field ( $record->field('856') ) { + for my $field ( $record->field($urltag) ) { my @notes; for my $note ( $field->subfield('z') ) { push @notes, { note => $note }; } - my @urls = $field->subfield('u'); + my @urls = $field->subfield($urlsubtag); foreach my $url (@urls) { my $marcurl; if ( $marcflavour eq 'MARC21' ) { @@ -1671,8 +1676,21 @@ sub GetMarcUrls { $marcurl->{'part'} = $s3 if ($link); $marcurl->{'toc'} = 1 if ( defined($s3) && $s3 =~ /^[Tt]able/ ); } else { - $marcurl->{'linktext'} = $field->subfield('2') || C4::Context->preference('URLLinkText') || $url; - $marcurl->{'MARCURL'} = $url; + if ($tagslib->{ $urltag }->{ $urlsubtag }->{value_builder} eq "upload.pl" + and $url !~ /^https?:\/\//) { + my $file = C4::UploadedFiles::GetUploadedFile($url); + my $opacbaseurl = C4::Context->preference('OPACBaseURL'); + next unless ($file and $opacbaseurl); + $marcurl->{'linktext'} = $field->subfield('2') + || C4::Context->preference('URLLinkText') + || $file->{filename}; + $marcurl->{'MARCURL'} = "$opacbaseurl/cgi-bin/koha/opac-retrieve-file.pl?id=" . $file->{id}; + } else { + $marcurl->{'linktext'} = $field->subfield('2') + || C4::Context->preference('URLLinkText') + || $url; + $marcurl->{'MARCURL'} = $url; + } } push @marcurls, $marcurl; } diff --git a/C4/UploadedFiles.pm b/C4/UploadedFiles.pm new file mode 100644 index 0000000..2e101c0 --- /dev/null +++ b/C4/UploadedFiles.pm @@ -0,0 +1,106 @@ +package C4::UploadedFiles; + +use C4::Context; +use Digest::MD5; + +sub GetUploadedFile { + my ($id) = @_; + + return unless $id; + + my $dbh = C4::Context->dbh; + my $query = qq{ + SELECT id, filename + FROM uploaded_files + WHERE id = ? + }; + my $sth = $dbh->prepare($query); + $sth->execute($id); + my $file = $sth->fetchrow_hashref; + + return $file; +} + +sub UploadFile { + my ($filename, $handle) = @_; + + my $buffer; + my $data = ''; + while($handle->read($buffer, 1024)) { + $data .= $buffer; + } + + my $ctx = new Digest::MD5; + $ctx->add($data); + my $id = $ctx->hexdigest; + + # Test if this id already exist + my $file = GetUploadedFile($id); + if($file) { + return $file->{id}; + } + + my $upload_path = C4::Context->preference("uploadPath"); + # remove trailing '/' if any + $upload_path =~ s#/$##; + my $file_path = "$upload_path/$id"; + if( -f $file_path ) { + warn "Id $id not in database, but present in filesystem, do nothing"; + return; + } + + my $out_fh; + unless(open $out_fh, '>', $file_path) { + warn "Failed to open file '$file_path': $!"; + return; + } + + print $out_fh $data; + close $out_fh; + + my $dbh = C4::Context->dbh; + my $query = qq{ + INSERT INTO uploaded_files (id, filename) + VALUES (?,?); + }; + my $sth = $dbh->prepare($query); + if($sth->execute($id, $filename)) { + return $id; + } + + return undef; +} + +sub DelUploadedFile { + my ($id) = @_; + + my $file = GetUploadedFile($id); + if($file) { + my $upload_path = C4::Context->preference("uploadPath"); + $upload_path =~ s#/$##; + my $file_path = "$upload_path/$file->{id}"; + my $file_deleted = 0; + unless( -f $file_path ) { + warn "Id $file->{id} is in database but not in filesystem, removing id from database"; + $file_deleted = 1; + } else { + if(unlink $file_path) { + $file_deleted = 1; + } + } + + unless($file_deleted) { + warn "File $file_path cannot be deleted: $!"; + } + + my $dbh = C4::Context->dbh; + my $query = qq{ + DELETE FROM uploaded_files + WHERE id = ? + }; + my $sth = $dbh->prepare($query); + return $sth->execute($id); + } +} + +1; diff --git a/basket/basket.pl b/basket/basket.pl index 8fc15e4..59894b3 100755 --- a/basket/basket.pl +++ b/basket/basket.pl @@ -65,7 +65,7 @@ foreach my $biblionumber ( @bibs ) { my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); my $marcseriesarray = GetMarcSeries ($record,$marcflavour); - my $marcurlsarray = GetMarcUrls ($record,$marcflavour); + my $marcurlsarray = GetMarcUrls ($record,$marcflavour, GetFrameworkCode($biblionumber)); my @items = GetItemsInfo( $biblionumber ); my $hasauthors = 0; diff --git a/catalogue/MARCdetail.pl b/catalogue/MARCdetail.pl index 0490076..f9460ba 100755 --- a/catalogue/MARCdetail.pl +++ b/catalogue/MARCdetail.pl @@ -82,6 +82,11 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); +my $uploadWebPath; +if (C4::Context->preference('uploadWebPath')) { + $uploadWebPath = C4::Context->preference('uploadWebPath'); +} + my $record = GetMarcBiblio($biblionumber); $template->param( ocoins => GetCOinSBiblio($record) ); @@ -216,6 +221,12 @@ for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) { GetAuthorisedValueDesc( $fields[$x_i]->tag(), $subf[$i][0], $subf[$i][1], '', $tagslib) || $subf[$i][1]; + if ($tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{value_builder} eq "upload.pl" and $uploadWebPath) { + my $file_uri = qq($uploadWebPath/$subf[$i][1]); + $subfield_data{marc_value} = qq/$subfield_data{marc_value}<\/a>/; + $subfield_data{is_file} = 1; + } + } $subfield_data{marc_subfield} = $subf[$i][0]; $subfield_data{marc_tag} = $fields[$x_i]->tag(); diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 3c95ba2..0651eb8 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -108,7 +108,7 @@ my $marcisbnsarray = GetMarcISBN( $record, $marcflavour ); my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); my $marcseriesarray = GetMarcSeries($record,$marcflavour); -my $marcurlsarray = GetMarcUrls ($record,$marcflavour); +my $marcurlsarray = GetMarcUrls ($record, $marcflavour, $fw); my $marchostsarray = GetMarcHosts($record,$marcflavour); my $subtitle = GetRecordValue('subtitle', $record, $fw); diff --git a/cataloguing/value_builder/upload.pl b/cataloguing/value_builder/upload.pl new file mode 100755 index 0000000..53211b6 --- /dev/null +++ b/cataloguing/value_builder/upload.pl @@ -0,0 +1,148 @@ +#!/usr/bin/perl + +# Copyright 2011 BibLibre +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use strict; +use warnings; + +use CGI qw/-utf8/; + +use C4::Auth; +use C4::Context; +use C4::Output; +use C4::UploadedFiles; + +my $upload_path = C4::Context->preference('uploadPath'); + +sub plugin_parameters { + my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_; + return ""; +} + +sub plugin_javascript { + my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_; + my $function_name = $field_number; + my $res = " + +"; + + return ( $function_name, $res ); +} + +sub plugin { + my ($input) = @_; + my $index = $input->param('index'); + my $id = $input->param('id'); + my $delete = $input->param('delete'); + my $uploaded_file = $input->param('uploaded_file'); + + my $template_name = ($id || $delete) + ? "upload_delete_file.tt" + : "upload.tt"; + + my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { template_name => "cataloguing/value_builder/$template_name", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { editcatalogue => '*' }, + debug => 1, + } + ); + + + my $filefield = CGI::filefield( + -name => 'uploaded_file', + -default => 'starting value', + -size => 50, + -maxlength => 80 + ); + + $template->param( + index => $index, + id => $id, + filefield => $filefield + ); + + # If there's already a file uploaded for this field, + # We handle is deletion + if ($delete) { + if(C4::UploadedFiles::DelUploadedFile($id)) {; + $template->param(success => 1); + } else { + $template->param(error => 1); + } + } + + # Dealing with the uploaded file + if ($uploaded_file) { + my $fh = $input->upload('uploaded_file'); + my $error; + my $success; + + my $id = C4::UploadedFiles::UploadFile($uploaded_file, $fh->handle); + if($id) { + $template->param( + success => 1, + uploaded_file => $uploaded_file, + id => $id + ); + } else { + $template->param(error => 1); + } + } + + output_html_with_http_headers $input, $cookie, $template->output; +} + + +1; + + +__END__ + +=head1 upload.pl + +This plugin allow to upload files on the server and reference it in a marc +field. + +Two system preferences are used: + +=over 4 + +=item uploadPath: the real absolute path where files will be stored + +=item uploadWebPath: the path from the server root directory. If you want to +access files through http://koha.tld/files, uploadWebPath must be "/files". + +=back + diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index e53a74e..b261f20 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2668,6 +2668,16 @@ CREATE TABLE `fieldmapping` ( -- koha to keyword mapping PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- +-- Table structure for table `uploaded_files` +-- + +DROP TABLE IF EXISTS `uploaded_files` +CREATE TABLE `uploaded_files` ( + `id` CHAR(32) NOT NULL PRIMARY KEY, + `filename` TEXT NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 918df5c..483cf6f 100755 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -330,3 +330,4 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('EasyAnalyticalRecords','0','If on, display in the catalogue screens tools to easily setup analytical record relationships','','YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacShowRecentComments',0,'If ON a link to recent comments will appear in the OPAC masthead',NULL,'YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('CircAutoPrintQuickSlip', '1', 'Choose what should happen when an empty barcode field is submitted in circulation: Display a print quick slip window or Clear the screen.',NULL,'YesNo'); +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('uploadPath','','Sets the upload path for the upload.pl plugin','',''); diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index a4ad03f..dc08d19 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -4605,6 +4605,25 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = "XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do(" + INSERT IGNORE INTO `systempreferences` (variable,value,explanation,options,type) + VALUES('uploadPath','','Sets the upload path for the upload.pl plugin','',''); + "); + + $dbh->do(" + CREATE TABLE `uploaded_files` ( + `id` CHAR(32) NOT NULL PRIMARY KEY, + `filename` TEXT NOT NULL + ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + "); + + print "Upgrade to $DBversion done (Adding uploadPath syspref and uploaded_files table)\n"; + SetVersion($DBversion); +} + +=item DropAllForeignKeys($table) =head1 FUNCTIONS diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt index ae86ee0..b40408f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt @@ -113,7 +113,13 @@ function Changefwk(FwkList) {   [% UNLESS ( subfiel.hide_marc ) %][% subfiel.marc_subfield %][% END %] [% subfiel.short_desc %] - [% IF ( subfiel.is_url ) %][% subfiel.marc_value |html %][% ELSE %][% subfiel.marc_value |html %][% END %] + [% IF ( subfiel.is_url ) %] + [% subfiel.marc_value |html %] + [% ELSIF ( subfiel.is_file ) %] + [% subfiel.marc_value %] + [% ELSE %] + [% subfiel.marc_value |html %] + [% END %] [% IF ( subfiel.link ) %] Search on [% subfiel.marc_value |html %] @@ -143,7 +149,13 @@ function Changefwk(FwkList) {   [% UNLESS ( subfiel.hide_marc ) %][% subfiel.marc_subfield %][% END %] [% subfiel.short_desc %] - [% IF ( subfiel.is_url ) %][% subfiel.marc_value |html %][% ELSE %][% subfiel.marc_value |html %][% END %] + [% IF ( subfiel.is_url ) %] + [% subfiel.marc_value |html %] + [% ELSIF ( subfiel.is_file ) %] + [% subfiel.marc_value %] + [% ELSE %] + [% subfiel.marc_value |html %] + [% END %] [% IF ( subfiel.link ) %] Search on [% subfiel.marc_value |html %] @@ -173,7 +185,13 @@ function Changefwk(FwkList) {   [% UNLESS ( subfiel.hide_marc ) %][% subfiel.marc_subfield %][% END %] [% subfiel.short_desc %] - [% IF ( subfiel.is_url ) %][% subfiel.marc_value |html %][% ELSE %][% subfiel.marc_value |html %][% END %] + [% IF ( subfiel.is_url ) %] + [% subfiel.marc_value |html %] + [% ELSIF ( subfiel.is_file ) %] + [% subfiel.marc_value %] + [% ELSE %] + [% subfiel.marc_value |html %] + [% END %] [% IF ( subfiel.link ) %] Search on [% subfiel.marc_value |html %] @@ -203,7 +221,13 @@ function Changefwk(FwkList) {   [% UNLESS ( subfiel.hide_marc ) %][% subfiel.marc_subfield %][% END %] [% subfiel.short_desc %] - [% IF ( subfiel.is_url ) %][% subfiel.marc_value |html %][% ELSE %][% subfiel.marc_value |html %][% END %] + [% IF ( subfiel.is_url ) %] + [% subfiel.marc_value |html %] + [% ELSIF ( subfiel.is_file ) %] + [% subfiel.marc_value %] + [% ELSE %] + [% subfiel.marc_value |html %] + [% END %] [% IF ( subfiel.link ) %] Search on [% subfiel.marc_value |html %] @@ -233,7 +257,13 @@ function Changefwk(FwkList) {   [% UNLESS ( subfiel.hide_marc ) %][% subfiel.marc_subfield %][% END %] [% subfiel.short_desc %] - [% IF ( subfiel.is_url ) %][% subfiel.marc_value |html %][% ELSE %][% subfiel.marc_value |html %][% END %] + [% IF ( subfiel.is_url ) %] + [% subfiel.marc_value |html %] + [% ELSIF (subfiel.is_file ) %] + [% subfiel.marc_value %] + [% ELSE %] + [% subfiel.marc_value |html %] + [% END %] [% IF ( subfiel.link ) %] Search on [% subfiel.marc_value |html %] @@ -263,7 +293,13 @@ function Changefwk(FwkList) {   [% UNLESS ( subfiel.hide_marc ) %][% subfiel.marc_subfield %][% END %] [% subfiel.short_desc %] - [% IF ( subfiel.is_url ) %][% subfiel.marc_value |html %][% ELSE %][% subfiel.marc_value |html %][% END %] + [% IF ( subfiel.is_url ) %] + [% subfiel.marc_value |html %] + [% ELSIF (subfiel.is_file ) %] + [% subfiel.marc_value %] + [% ELSE %] + [% subfiel.marc_value |html %] + [% END %] [% IF ( subfiel.link ) %] Search on [% subfiel.marc_value |html %] @@ -293,7 +329,13 @@ function Changefwk(FwkList) {   [% UNLESS ( subfiel.hide_marc ) %][% subfiel.marc_subfield %][% END %] [% subfiel.short_desc %] - [% IF ( subfiel.is_url ) %][% subfiel.marc_value |html %][% ELSE %][% subfiel.marc_value |html %][% END %] + [% IF ( subfiel.is_url ) %] + [% subfiel.marc_value |html %] + [% ELSIF (subfiel.is_file ) %] + [% subfiel.marc_value %] + [% ELSE %] + [% subfiel.marc_value |html %] + [% END %] [% IF ( subfiel.link ) %] Search on [% subfiel.marc_value |html %] @@ -323,7 +365,13 @@ function Changefwk(FwkList) {   [% UNLESS ( subfiel.hide_marc ) %][% subfiel.marc_subfield %][% END %] [% subfiel.short_desc %] - [% IF ( subfiel.is_url ) %][% subfiel.marc_value |html %][% ELSE %][% subfiel.marc_value |html %][% END %] + [% IF ( subfiel.is_url ) %] + [% subfiel.marc_value |html %] + [% ELSIF (subfiel.is_file ) %] + [% subfiel.marc_value %] + [% ELSE %] + [% subfiel.marc_value |html %] + [% END %] [% IF ( subfiel.link ) %] Search on [% subfiel.marc_value |html %] @@ -353,7 +401,13 @@ function Changefwk(FwkList) {   [% UNLESS ( subfiel.hide_marc ) %][% subfiel.marc_subfield %][% END %] [% subfiel.short_desc %] - [% IF ( subfiel.is_url ) %][% subfiel.marc_value |html %][% ELSE %][% subfiel.marc_value |html %][% END %] + [% IF ( subfiel.is_url ) %] + [% subfiel.marc_value |html %] + [% ELSIF (subfiel.is_file ) %] + [% subfiel.marc_value %] + [% ELSE %] + [% subfiel.marc_value |html %] + [% END %] [% IF ( subfiel.link ) %] Search on [% subfiel.marc_value |html %] @@ -383,7 +437,13 @@ function Changefwk(FwkList) {   [% UNLESS ( subfiel.hide_marc ) %][% subfiel.marc_subfield %][% END %] [% subfiel.short_desc %] - [% IF ( subfiel.is_url ) %][% subfiel.marc_value |html %][% ELSE %][% subfiel.marc_value |html %][% END %] + [% IF ( subfiel.is_url ) %] + [% subfiel.marc_value |html %] + [% ELSIF (subfiel.is_file ) %] + [% subfiel.marc_value %] + [% ELSE %] + [% subfiel.marc_value |html %] + [% END %] [% IF ( subfiel.link ) %] Search on [% subfiel.marc_value |html %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/upload.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/upload.tt new file mode 100644 index 0000000..7213282 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/upload.tt @@ -0,0 +1,47 @@ + + + + Upload plugin + + + + + + +[% IF ( success ) %] + + + + + The file [% uploaded_file %] has been successfully uploaded. +

+ +[% ELSE %] + + [% IF ( error ) %] +

Error: Failed to upload file. See logs for details.

+ + [% ELSE %] +

Please select the file to upload :

+
+ [% filefield %] + + + +
+ [% END %] + +[% END %] + + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/upload_delete_file.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/upload_delete_file.tt new file mode 100644 index 0000000..bd84d89 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/upload_delete_file.tt @@ -0,0 +1,49 @@ + + + + Upload plugin + + + + + + +[% IF ( success ) %] + + + + The file has been successfully deleted. +

+ +[% ELSE %] + + [% IF ( error ) %] + Error: Unable to delete the file. +

+ [% ELSE %] +

File deletion

+

A file has already been uploaded for this field. Do you want to delete it?

+
+ + + + + + +
+ [% END %] + +[% END %] + + + diff --git a/kohaversion.pl b/kohaversion.pl index 09b1ca2..aa2eac2 100644 --- a/kohaversion.pl +++ b/kohaversion.pl @@ -16,7 +16,7 @@ the kohaversion is divided in 4 parts : use strict; sub kohaversion { - our $VERSION = '3.07.00.007'; + our $VERSION = 'XXX'; # version needs to be set this way # so that it can be picked up by Makefile.PL # during install diff --git a/misc/strip_value_from_tag.pl b/misc/strip_value_from_tag.pl new file mode 100644 index 0000000..807e7b5 --- /dev/null +++ b/misc/strip_value_from_tag.pl @@ -0,0 +1,60 @@ +#!/usr/bin/perl + +# This script takes every biblio record in the database, +# looks for a value beginning with $find in $fieldtag$$subfieldtag +# and strips $find from this value. +# This was originally made for the file upload plugin, but might +# be used for other purposes. + +use strict; + +use Getopt::Long; +use C4::Context; +use C4::Biblio; + +my $debug = 0; + +# Which field are we processing? +my $fieldtag = "857"; +my $subfieldtag = "u"; + +# Whichi beginning pattern are we looking to delete? +my $find = "http://myurl.tld/"; +my $length = length($find); +my $pattern = qr|^$find|; + +print "Field $fieldtag\$$subfieldtag\n"; + +# Getting db connection +my $dbh = C4::Context->dbh; + +# Getting max bibnumber +my $query = "SELECT MAX(biblionumber) from biblio"; +my $sth = $dbh->prepare($query); +$sth->execute(); +my $bibliocount = $sth->fetchrow; + +warn "unable to get biblio count" and exit -1 unless $bibliocount; + +print "Biblio count : $bibliocount\n"; + +# Foreach each biblio +foreach (1..$bibliocount) { + my $found = 0; + my $record = GetMarcBiblio($_); + $debug and warn "unable to get marc for record $_" unless $record; + next unless $record; + foreach my $field ($record->field($fieldtag)) { + my $newfield = $field->clone(); + my $subfield = $newfield->subfield($subfieldtag); + if ($subfield and $subfield =~ $pattern) { + my $newsubfield = substr $subfield, $length; + $newsubfield =~ s/\s+$//; + $newfield->update($subfieldtag, $newsubfield); + $field->replace_with($newfield); + $found = 1; + } + } + print "processing $_\n" if ($found == 1); + ModBiblioMarc($record, $_, GetFrameworkCode($_)) if ($found == 1); +} diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl index ffa0a6d..4005ee4 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -90,6 +90,11 @@ if (C4::Context->preference("RequestOnOpac")) { $RequestOnOpac = 1; } +my $uploadWebPath; +if (C4::Context->preference('uploadWebPath')) { + $uploadWebPath = C4::Context->preference('uploadWebPath'); +} + # fill arrays my @loop_data = (); my $tag; @@ -161,6 +166,11 @@ for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) { } $subfield_data{marc_value} = GetAuthorisedValueDesc( $fields[$x_i]->tag(), $subf[$i][0], $subf[$i][1], '', $tagslib, '', 'opac' ); + if ($tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{value_builder} eq "upload.pl" and $uploadWebPath) { + my $file_uri = qq($uploadWebPath/$subf[$i][1]); + $subfield_data{marc_value} = qq/
$subfield_data{marc_value}<\/a>/; + } + } $subfield_data{marc_subfield} = $subf[$i][0]; $subfield_data{marc_tag} = $fields[$x_i]->tag(); diff --git a/opac/opac-basket.pl b/opac/opac-basket.pl index 5e92d15..8f31ba8 100755 --- a/opac/opac-basket.pl +++ b/opac/opac-basket.pl @@ -67,7 +67,7 @@ foreach my $biblionumber ( @bibs ) { my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); my $marcseriesarray = GetMarcSeries ($record,$marcflavour); - my $marcurlsarray = GetMarcUrls ($record,$marcflavour); + my $marcurlsarray = GetMarcUrls ($record, $marcflavour, GetFrameworkCode($biblionumber)); my @items = &GetItemsLocationInfo( $biblionumber ); my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber)); diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 8949444..1a07f4f 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -529,7 +529,7 @@ my $marcisbnsarray = GetMarcISBN ($record,$marcflavour); my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour); my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour); my $marcseriesarray = GetMarcSeries ($record,$marcflavour); -my $marcurlsarray = GetMarcUrls ($record,$marcflavour); +my $marcurlsarray = GetMarcUrls ($record, $marcflavour, $dat->{'frameworkcode'}); my $marchostsarray = GetMarcHosts($record,$marcflavour); my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber)); diff --git a/opac/opac-retrieve-file.pl b/opac/opac-retrieve-file.pl new file mode 100755 index 0000000..3f1476d --- /dev/null +++ b/opac/opac-retrieve-file.pl @@ -0,0 +1,33 @@ +#!/usr/bin/perl + +use Modern::Perl; + +use CGI; + +use C4::Context; +use C4::UploadedFiles; + +my $input = new CGI; + +my $id = $input->param('id'); +my $file = C4::UploadedFiles::GetUploadedFile($id); +exit 1 if not $file; + +my $upload_path = C4::Context->preference("uploadPath"); +$upload_path =~ s#/$##; +my $file_path = "$upload_path/$file->{id}"; + +if( -f $file_path ) { + open FH, '<', $file_path or die "Can't open file: $!"; + print $input->header( + -type => "application/octet-stream", + -attachment => $file->{filename} + ); + while() { + print $_; + } +} else { + exit 1; +} + +exit 0; -- 1.7.8.3