5 [% USE TablesSettings %]
6 [% USE AuthorisedValues %]
9 [% INCLUDE 'doc-head-open.inc' %]
11 <title>Upload plugin</title>
13 <title>Upload › Tools › Koha</title>
15 [% INCLUDE 'doc-head-close.inc' %]
17 [% BLOCK plugin_pars %]
19 <input type="hidden" name="plugin" value="1" />
20 <input type="hidden" name="index" value="[% index | html %]" />
24 [% BLOCK breadcrumbs %]
25 [% WRAPPER 'sub-header.inc' %]
26 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
29 <a href="/cgi-bin/koha/mainpage.pl">Home</a>
32 <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
35 <a href="/cgi-bin/koha/tools/upload.pl">Upload</a>
38 <a href="#" aria-current="page">
39 [% IF mode=='new' || mode =='deleted'%]
40 Add new upload or search
52 <form method="post" action="/cgi-bin/koha/tools/upload.pl" id="uploadfile" enctype="multipart/form-data">
53 [% PROCESS plugin_pars %]
54 <fieldset class="rows" id="uploadform">
55 <legend>Upload new files</legend>
58 <div id="fileuploadform">
59 <label for="fileToUpload">Select files: </label>
60 <input type="file" id="fileToUpload" name="fileToUpload" multiple/>
63 [% IF uploadcategories %]
65 <label for="uploadcategory">Category: </label>
66 <select id="uploadcategory" name="uploadcategory">
68 <option value=""></option>
70 [% FOREACH cat IN uploadcategories %]
71 <option value="[% cat.code | html %]">[% cat.name | html %]</option>
78 [% IF uploadcategories %]
79 <div class="hint">Note: For temporary uploads do not select a category.</div>
82 Note: No upload categories are defined.
83 [% IF ( CAN_user_parameters_manage_auth_values ) -%]
84 [% av_UPLOAD_link = BLOCK %]<a href='/cgi-bin/koha/admin/authorised_values.pl?searchfield=UPLOAD'>UPLOAD</a>[% END %]
85 <span>Add values to the [% av_UPLOAD_link | $KohaSpan %] authorized value category otherwise all uploads will be marked as temporary.</span>
87 <span>An administrator must add values to the UPLOAD authorized value category otherwise all uploads will be marked as temporary.</span>
95 <input type="hidden" id="public" name="public" value="1"/>
97 <label id="public_cb">Allow public downloads:</label>
98 <input type="checkbox" id="public" name="public" />
102 <fieldset class="action">
103 <button id="fileuploadbutton" class="btn btn-primary">Upload</button>
104 <button id="fileuploadcancel">Cancel</button>
107 <div id="fileuploadpanel">
108 <div id="fileuploadstatus" class="progress_panel">Upload progress:
109 <progress id="fileuploadprogress" max="100" value="0">
111 <span class="fileuploadpercent">0</span>%
113 <div id="fileuploadfailed"></div>
118 [% BLOCK form_browse %]
119 [% IF uploadcategories %]
120 <form method="post" id="browsefile" action="/cgi-bin/koha/tools/upload.pl">
121 [% PROCESS plugin_pars %]
122 <input type="hidden" name="op" value="browse"/>
123 <fieldset class="brief">
124 <h4>Search uploads by category</h4>
127 <label for="browsecategory">Category: </label>
128 <select id="browsecategory" name="browsecategory" required="required">
129 <option value="">Choose</option>
130 [% FOREACH cat IN uploadcategories %]
131 [% IF cat.code == browsecategory %]
132 <option value="[% cat.code | html %]" selected="selected">[% cat.name | html %]</option>
134 <option value="[% cat.code | html %]">[% cat.name | html %]</option>
140 <fieldset class="action">
141 <button id="browsebutton" class="btn btn-primary">Search</button>
148 [% BLOCK form_search %]
149 <form method="post" id="searchfile" action="/cgi-bin/koha/tools/upload.pl">
150 [% PROCESS plugin_pars %]
151 <input type="hidden" name="op" value="search"/>
152 <fieldset class="brief">
153 <h4>Search uploads by name or hashvalue</h4>
156 <label for="term">Search term: </label>
157 <input type="text" id="term" name="term" value=""/>
160 <fieldset class="action">
161 <button id="searchbutton" class="btn btn-primary">Search</button>
167 [% BLOCK submitter %]
168 <form id="submitter" style="display:none;" method="post">
169 [% PROCESS plugin_pars %]
170 <input type="hidden" name="op" id="op" value=""/>
171 <input type="hidden" name="id" id="id" value="" />
172 <input type="hidden" name="msg" id="msg" value="" />
178 <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
185 <fieldset class="action">
186 <button class="submit">Back</button>
192 [% BLOCK newsearch %]
193 <form id="newsearch">
194 <fieldset class="action">
195 <button id="new_search">New search</button>
199 <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
203 [% BLOCK table_results %]
204 <div class="page-section">
205 <table id="uploadresults">
213 [% IF !plugin %]<th>Public</th>[% END %]
214 [% IF !plugin %]<th>Temporary</th>[% END %]
215 <th class="NoSort noExport">Actions</th>
219 [% FOREACH record IN uploads %]
221 <td>[% record.filename | html %]</td>
222 <td>[% record.filesize | html %]</td>
223 <td>[% record.hashvalue | html %]</td>
224 <td data-order="[% record.dtcreated | html %]">[% record.dtcreated | $KohaDates with_hours = 1 %]</td>
226 <a href="/cgi-bin/koha/tools/upload.pl?op=browse&browsecategory=[% record.uploadcategorycode | uri %]">[% AuthorisedValues.GetByCode( 'UPLOAD', record.uploadcategorycode ) | html %]</a>
230 [% IF record.public %]
231 <a href="[% Koha.Preference('OPACBaseURL') | url %]/cgi-bin/koha/opac-retrieve-file.pl?id=[% record.hashvalue | uri %]" class="get-file" data-toggle="tooltip"><i class="fa fa-link" aria-hidden="true"></i> Yes</a>
236 <td>[% IF record.permanent %]No[% ELSE %]Yes[% END %]</td>
240 <button class="btn btn-default btn-xs choose_entry" data-record-hashvalue="[% record.hashvalue | html %]"><i class="fa fa-plus"></i> Choose</button>
242 <button class="btn btn-default btn-xs download_entry" data-record-id="[% record.id | html %]"><i class="fa fa-download"></i> Download</button>
243 [% IF record.owner == owner || CAN_user_tools_upload_manage %]
244 <button class="btn btn-default btn-xs delete_entry" data-record-id="[% record.id | html %]"><i class="fa fa-trash"></i> Delete</button>
251 </div> <!-- /.page-section -->
255 #fileuploadstatus,#fileuploadfailed { display : none; }
256 #fileuploadstatus { margin:.4em; }
257 #fileuploadprogress { width:150px;height:10px;border:1px solid #666;background:url('[% interface | html %]/[% theme | html %]/img/progress.png') -300px 0px no-repeat; }
264 <body id="tools_upload" class="tools">
265 <div class="main container-fluid">
267 <div class="col-sm-12">
270 <body id="tools_upload" class="tools">
271 [% INCLUDE 'header.inc' %]
272 [% INCLUDE 'cat-search.inc' %]
273 [% PROCESS breadcrumbs %]
275 <div class="main container-fluid">
277 <div class="col-sm-10 col-sm-push-2">
282 <div class="dialog alert" id="myalerts" style="display:none;"></div>
284 [% PROCESS submitter %]
285 [% IF mode == 'new' || mode == 'deleted' %]
286 [% PROCESS form_new %]
288 [% IF uploadcategories %]
289 <div class="col-xs-6">
290 [% PROCESS form_browse %]
292 <div class="col-xs-6">
294 <div class="col-xs-12">
296 [% PROCESS form_search %]
300 [% ELSIF mode == 'report' %]
301 <div id="toolbar" class="btn-toolbar">
302 <a href="/cgi-bin/koha/tools/upload.pl" class="btn btn-default">Upload file</a>
305 <h3>Your request gave the following results:</h3>
306 [% PROCESS table_results %]
310 <h4>Sorry, your request had no results.</h4>
311 [% PROCESS newsearch %]
317 </div> <!-- /.col-sm-10.col-sm-push-2 -->
319 <div class="col-sm-2 col-sm-pull-10">
321 [% IF mode == 'report' %]
322 [% PROCESS form_browse %]
323 [% PROCESS form_search %]
327 [% INCLUDE 'tools-menu.inc' %]
329 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
330 </div> <!-- /.row -->
333 </div> <!-- .col-sm-12 -->
334 </div> <!-- /.row -->
338 [% MACRO jsinclude BLOCK %]
339 [% Asset.js("js/tools-menu.js") | $raw %]
340 [% INCLUDE 'datatables.inc' %]
341 [% Asset.js("js/file-upload.js") | $raw %]
342 [% INCLUDE 'columns_settings.inc' %]
344 function StartUpload() {
345 if( $('#fileToUpload').prop('files').length == 0 ) return;
346 $('#fileToUpload').prop('disabled',true);
347 $('#fileuploadbutton').hide();
348 $("#fileuploadcancel").show();
349 $("#fileuploadfailed").html('');
350 $("#myalerts").hide('');
351 $("#myalerts").html('');
352 $("#fileuploadstatus").show();
353 $("#uploadedfileid").val('');
354 $("#searchfile").hide();
355 $("#lastbreadcrumb").text( _("Add a new upload") );
358 if( $("#uploadcategory").val() )
359 cat = encodeURIComponent( $("#uploadcategory").val() );
360 if( cat ) xtra= 'category=' + cat + '&';
362 xtra = xtra + 'public=1&temp=0';
364 if( !cat ) xtra = 'temp=1&';
365 if( $('#public').prop('checked') ) xtra = xtra + 'public=1';
367 xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), xtra, cbUpload );
369 function CancelUpload() {
370 if( xhr ) xhr.abort();
371 $("#fileuploadstatus").hide();
372 $('#fileToUpload').prop('disabled', false);
373 $('#fileuploadbutton').show();
374 $("#fileuploadcancel").hide();
375 $("#fileuploadfailed").show();
376 $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
378 function cbUpload( status, fileid, err ) {
379 $('#fileToUpload').prop('disabled', false);
380 if( status=='done' ) {
381 var e = err? JSON.stringify(err): '';
382 SubmitMe( 'search', fileid, e );
384 $('#fileuploadbutton').show();
385 $("#fileuploadcancel").hide();
386 $("#fileuploadstatus").hide();
387 $("#fileuploadfailed").show();
388 $("#fileuploadfailed").html( _("Upload status: ") +
389 ( status=='failed'? _("Failed"):
390 ( status=='denied'? _("Denied"): status ))
395 function ShowAlerts(err) {
397 for( var file in err ) {
398 str= str + '<p>' + file + ': ' +
399 errMESSAGES( err[file].code ) + '</p>';
402 $('#myalerts').html(str);
403 $('#myalerts').show();
406 function errMESSAGES(code) {
409 case 'UPLERR_ALREADY_EXISTS':
410 rv = _("This file already exists (in this category).");
412 case 'UPLERR_CANNOT_WRITE':
413 rv = _("File could not be created. Check permissions.");
415 case 'UPLERR_NO_ROOT_DIR':
416 rv = _("Your koha-conf.xml does not contain a valid upload_path.");
418 case 'UPLERR_NO_TEMP_DIR':
419 rv = _("No temporary directory found.");
421 case 'UPLERR_FILE_NOT_READ':
422 rv = _("File could not be read.");
424 case 'UPL_FILE_DELETED': // An alert, no error
425 rv = _("File has been deleted.");
427 case 'UPLERR_FILE_NOT_DELETED':
428 rv = _("File or upload record could not be deleted.");
435 function CheckSearch() {
436 if( $("#term").val()=="" ) {
437 alert( _("Please enter a search term.") );
442 function SubmitMe(op, id, msg ) {
443 $("#submitter #op").val( op );
444 $("#submitter #id").val( id );
445 $("#submitter #msg").val( msg );
446 $("#submitter").submit();
448 function DeleteEntry(id) {
449 if( !confirm( _("Do you really want to delete this upload?") ))
452 SubmitMe( 'delete', id );
454 function ClearField() {
456 $(window.opener.document).find('#[% index | html %]').val( '' );
459 function Choose(hashval) {
460 var res = '[% Koha.Preference('OPACBaseURL') | html %]';
461 res = res.replace( /\/$/, '');
462 res = res + '/cgi-bin/koha/opac-retrieve-file.pl?id=' + hashval;
464 $(window.opener.document).find('#[% index | html %]').val( res );
468 var table_settings = [% TablesSettings.GetTableSettings( 'tools', 'upload', 'uploadresults', 'json' ) | $raw %];
470 table_settings['columns'].splice(6, 1);
471 table_settings['columns'].splice(5, 1);
473 $(document).ready(function() {
474 KohaTable("uploadresults",{
478 ShowAlerts( [% msg | html %] );
480 $("#fileuploadcancel").hide();
481 $("#public_cb").click(function() {
482 $("#public").click();
484 $("#fileuploadbutton").on("click",function(e){
488 $("#fileuploadcancel").on("click",function(e){
492 $("#searchbutton").on("click",function(){
493 return CheckSearch();
495 $("#uploadresults tbody").on("click",".choose_entry",function(e){
497 var record_hashvalue = $(this).data("record-hashvalue");
498 Choose( record_hashvalue );
500 $("#uploadresults tbody").on("click",".download_entry",function(e){
502 var record_id = $(this).data("record-id");
503 SubmitMe( 'download', record_id );
505 $("#uploadresults tbody").on("click",".delete_entry",function(e){
507 var record_id = $(this).data("record-id");
508 DeleteEntry( record_id );
510 $("#new_search").on("click",function(e){
515 if ( window.isSecureContext ) {
516 $(".get-file").on("click", function(e){
518 if( navigator.clipboard && navigator.clipboard.writeText){
519 navigator.clipboard.writeText( $(this).attr("href") );
520 $(this).attr("data-original-title", _( "Link copied to the clipboard" ) )
524 $(".get-file").tooltip({
525 delay: { "show": 100, "hide": 500 }
526 }).on("hidden.bs.tooltip", function(){
527 $(this).attr("data-original-title", _( "Copy link to this file" ) );
534 [% INCLUDE 'intranet-bottom.inc' %]