|
Lines 23-29
use JSON;
Link Here
|
| 23 |
|
23 |
|
| 24 |
use C4::Auth; |
24 |
use C4::Auth; |
| 25 |
use C4::Output; |
25 |
use C4::Output; |
| 26 |
use Koha::UploadedFile; |
|
|
| 27 |
use Koha::UploadedFiles; |
26 |
use Koha::UploadedFiles; |
| 28 |
|
27 |
|
| 29 |
my $input = CGI::->new; |
28 |
my $input = CGI::->new; |
|
Lines 47-68
$template->param(
Link Here
|
| 47 |
index => $index, |
46 |
index => $index, |
| 48 |
owner => $loggedinuser, |
47 |
owner => $loggedinuser, |
| 49 |
plugin => $plugin, |
48 |
plugin => $plugin, |
|
|
49 |
uploadcategories => Koha::UploadedFiles->getCategories, |
| 50 |
); |
50 |
); |
| 51 |
|
51 |
|
| 52 |
if ( $op eq 'new' ) { |
52 |
if ( $op eq 'new' ) { |
| 53 |
$template->param( |
53 |
$template->param( |
| 54 |
mode => 'new', |
54 |
mode => 'new', |
| 55 |
uploadcategories => Koha::UploadedFile->getCategories, |
|
|
| 56 |
); |
55 |
); |
| 57 |
output_html_with_http_headers $input, $cookie, $template->output; |
56 |
output_html_with_http_headers $input, $cookie, $template->output; |
| 58 |
|
57 |
|
| 59 |
} elsif ( $op eq 'search' ) { |
58 |
} elsif ( $op eq 'search' ) { |
| 60 |
my $uploads; |
59 |
my $uploads; |
| 61 |
if( $id ) { |
60 |
if( $id ) { |
| 62 |
my $rec = Koha::UploadedFiles->search({ |
61 |
my $rec = Koha::UploadedFiles->find( $id ); |
| 63 |
id => $id, |
62 |
undef $rec if $rec && $plugin && !$rec->public; |
| 64 |
$plugin? ( public => 1 ) : (), |
|
|
| 65 |
})->next; |
| 66 |
push @$uploads, $rec->unblessed if $rec; |
63 |
push @$uploads, $rec->unblessed if $rec; |
| 67 |
} else { |
64 |
} else { |
| 68 |
$uploads = Koha::UploadedFiles->search_term({ |
65 |
$uploads = Koha::UploadedFiles->search_term({ |
|
Lines 80-113
if ( $op eq 'new' ) {
Link Here
|
| 80 |
|
77 |
|
| 81 |
} elsif ( $op eq 'delete' ) { |
78 |
} elsif ( $op eq 'delete' ) { |
| 82 |
# delete only takes the id parameter |
79 |
# delete only takes the id parameter |
| 83 |
my $upload = $plugin? |
80 |
my $rec = Koha::UploadedFiles->find($id); |
| 84 |
Koha::UploadedFiles->search({ public => 1, id => $id })->next: |
81 |
undef $rec if $rec && $plugin && !$rec->public; |
| 85 |
Koha::UploadedFiles->find($id); |
82 |
my $fn = $rec ? $rec->filename : ''; |
| 86 |
my $fn = $upload? $upload->delete: undef; |
83 |
my $delete = $rec ? $rec->delete : undef; |
| 87 |
#TODO Improve error handling |
84 |
#TODO Improve error handling |
| 88 |
my $msg = $fn? |
85 |
my $msg = $delete |
| 89 |
JSON::to_json({ $fn => 6 }): |
86 |
? JSON::to_json({ $fn => 6 }) |
| 90 |
JSON::to_json({ |
87 |
: $id |
| 91 |
$upload? $upload->filename: ( $id? "id $id": '[No id]' ), 7, |
88 |
? JSON::to_json({ $fn || $id, 7 }) |
| 92 |
}); |
89 |
: ''; |
| 93 |
$template->param( |
90 |
$template->param( |
| 94 |
mode => 'deleted', |
91 |
mode => 'deleted', |
| 95 |
msg => $msg, |
92 |
msg => $msg, |
| 96 |
uploadcategories => Koha::UploadedFile->getCategories, |
|
|
| 97 |
); |
93 |
); |
| 98 |
output_html_with_http_headers $input, $cookie, $template->output; |
94 |
output_html_with_http_headers $input, $cookie, $template->output; |
| 99 |
|
95 |
|
| 100 |
} elsif ( $op eq 'download' ) { |
96 |
} elsif ( $op eq 'download' ) { |
| 101 |
my $rec = Koha::UploadedFiles->search({ |
97 |
my $rec = Koha::UploadedFiles->find( $id ); |
| 102 |
id => $id, |
98 |
undef $rec if $rec && $plugin && !$rec->public; |
| 103 |
$plugin? ( public => 1 ) : (), |
|
|
| 104 |
})->next; |
| 105 |
my $fh = $rec? $rec->file_handle: undef; |
99 |
my $fh = $rec? $rec->file_handle: undef; |
| 106 |
if ( !$rec || !$fh ) { |
100 |
if ( !$rec || !$fh ) { |
| 107 |
$template->param( |
101 |
$template->param( |
| 108 |
mode => 'new', |
102 |
mode => 'new', |
| 109 |
msg => JSON::to_json( { $id => 5 } ), |
103 |
msg => JSON::to_json( { $id => 5 } ), |
| 110 |
uploadcategories => Koha::UploadedFile->getCategories, |
|
|
| 111 |
); |
104 |
); |
| 112 |
output_html_with_http_headers $input, $cookie, $template->output; |
105 |
output_html_with_http_headers $input, $cookie, $template->output; |
| 113 |
} else { |
106 |
} else { |
| 114 |
- |
|
|