From 18ac0af8013188cc1af92f2f146e071fe817e050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nazl=C4=B1=20=C3=87etin?= Date: Wed, 30 Jan 2019 14:34:12 +0000 Subject: [PATCH] Bug 20208: Development - Peddie School - Custom file upload paths --- Koha/UploadedFiles.pm | 15 +++++++++- installer/data/mysql/atomicupdate/bug_20208.perl | 3 ++ .../intranet-tmpl/prog/en/modules/tools/upload.tt | 35 ++++++++++++++++++++-- tools/upload-file.pl | 4 +-- tools/upload.pl | 1 + 5 files changed, 52 insertions(+), 6 deletions(-) diff --git a/Koha/UploadedFiles.pm b/Koha/UploadedFiles.pm index b6804f299b..3e88247c9c 100644 --- a/Koha/UploadedFiles.pm +++ b/Koha/UploadedFiles.pm @@ -159,7 +159,8 @@ sub search_term { } return $self->search( [ { filename => { like => '%'.$term.'%' }, %public }, - { hashvalue => { like => '%'.$params->{term}.'%' }, %public } ], + { hashvalue => { like => '%'.$params->{term}.'%' }, %public }, + { dir => { like => '%'.$params->{term}.'%' }, %public } ], { order_by => { -asc => 'id' }}, ); } @@ -178,6 +179,18 @@ sub getCategories { [ map {{ code => $_->{authorised_value}, name => $_->{lib} }} @$cats ]; } +=head3 getPaths + +getPaths returns a list of upload path codes and names + +=cut + +sub getPaths { + my ( $class ) = @_; + my $cats = C4::Koha::GetAuthorisedValues('UPLOAD_PATH'); + [ map {{ code => $_->{authorised_value}, name => $_->{lib} }} @$cats ]; +} + =head3 _type Returns name of corresponding DBIC resultset diff --git a/installer/data/mysql/atomicupdate/bug_20208.perl b/installer/data/mysql/atomicupdate/bug_20208.perl index 00e750ef41..5d82ae61c6 100644 --- a/installer/data/mysql/atomicupdate/bug_20208.perl +++ b/installer/data/mysql/atomicupdate/bug_20208.perl @@ -9,6 +9,9 @@ if( CheckVersion( $DBversion ) ) { }); $dbh->do("ALTER TABLE `uploaded_files` MODIFY COLUMN `dir` mediumtext DEFAULT NULL"); } + $dbh->do(q{ + INSERT IGNORE INTO authorised_value_categories( category_name ) VALUES ('UPLOAD_PATH') + }); SetVersion( $DBversion ); print "Upgrade to $DBversion done (Bug 20208 - Development - Peddie School - Custom file upload paths)\n"; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt index 443e25b4b6..ef7d2f092c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt @@ -48,6 +48,26 @@ +
  • + + +
  • + [% IF uploadpaths %] +
  • + + +
  • + [% END %] [% IF uploadcategories %]
  • @@ -156,7 +176,9 @@ Filename Size + File checksum Hashvalue + Upload path Category [% IF !plugin %]Public[% END %] [% IF !plugin %]Temporary[% END %] @@ -168,7 +190,9 @@ [% record.filename | html %] [% record.filesize | html %] + [% IF record.checksum %]Yes[% ELSE %]No[% END %] [% record.hashvalue | html %] + [% record.dir | html %] [% record.uploadcategorycode | html %] [% IF !plugin %] [% IF record.public %]Yes[% ELSE %]No[% END %] @@ -271,16 +295,21 @@ $("#searchfile").hide(); $("#lastbreadcrumb").text( _("Add a new upload") ); - var cat, xtra=''; + var dir, cat, xtra=''; if( $("#uploadcategory").val() ) cat = encodeURIComponent( $("#uploadcategory").val() ); if( cat ) xtra= 'category=' + cat + '&'; + [% IF plugin %] - xtra = xtra + 'public=1&temp=0'; + xtra = xtra + 'public=1&temp=0&'; [% ELSE %] if( !cat ) xtra = 'temp=1&'; - if( $('#public').prop('checked') ) xtra = xtra + 'public=1'; + if( $('#public').prop('checked') ) xtra = xtra + 'public=1&'; [% END %] + if( $("#uploadpath").val() ) + dir = encodeURIComponent( $("#uploadpath").val() ); + if( dir ) xtra= xtra + 'dir=' + dir + '&'; + xtra = xtra + 'checksum=' + $('#checksum:checked').val(); xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), xtra, cbUpload ); } function CancelUpload() { diff --git a/tools/upload-file.pl b/tools/upload-file.pl index 86ef2c5dc2..3448be02be 100755 --- a/tools/upload-file.pl +++ b/tools/upload-file.pl @@ -75,8 +75,8 @@ sub upload_pars { # this sub parses QUERY_STRING in order to build the $qstr = Encode::decode_utf8( uri_unescape( $qstr ) ); # category could include a utf8 character my $rv = {}; - foreach my $p ( qw[public category temp] ) { - if( $qstr =~ /(^|&)$p=(\w+)(&|$)/ ) { + foreach my $p ( qw[public category temp checksum dir] ) { + if( $qstr =~ /(^|&)$p=([\w\/\_]*)(&|$)/ ) { $rv->{$p} = $2; } } diff --git a/tools/upload.pl b/tools/upload.pl index afb7c516f9..f35e6d9cbd 100755 --- a/tools/upload.pl +++ b/tools/upload.pl @@ -51,6 +51,7 @@ $template->param( owner => $loggedinuser, plugin => $plugin, uploadcategories => Koha::UploadedFiles->getCategories, + uploadpaths => Koha::UploadedFiles->getPaths, ); if ( $op eq 'new' ) { -- 2.11.0