5 [% USE TablesSettings %]
6 [% USE AuthorisedValues %]
8 [% INCLUDE 'doc-head-open.inc' %]
10 <title>Upload plugin</title>
12 <title>Upload › Tools › Koha</title>
14 [% INCLUDE 'doc-head-close.inc' %]
16 [% BLOCK plugin_pars %]
18 <input type="hidden" name="plugin" value="1" />
19 <input type="hidden" name="index" value="[% index | html %]" />
23 [% BLOCK breadcrumbs %]
24 [% WRAPPER 'sub-header.inc' %]
25 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
28 <a href="/cgi-bin/koha/mainpage.pl">Home</a>
31 <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
34 <a href="/cgi-bin/koha/tools/upload.pl">Upload</a>
37 <a href="#" aria-current="page">
38 [% IF mode=='new' || mode =='deleted'%]
39 Add new upload or search
51 <form method="post" action="/cgi-bin/koha/tools/upload.pl" id="uploadfile" enctype="multipart/form-data">
52 [% PROCESS plugin_pars %]
53 <fieldset class="rows" id="uploadform">
54 <legend>Upload new files</legend>
57 <div id="fileuploadform">
58 <label for="fileToUpload">Select files: </label>
59 <input type="file" id="fileToUpload" name="fileToUpload" multiple/>
62 [% IF uploadcategories %]
64 <label for="uploadcategory">Category: </label>
65 <select id="uploadcategory" name="uploadcategory">
67 <option value=""></option>
69 [% FOREACH cat IN uploadcategories %]
70 <option value="[% cat.code | html %]">[% cat.name | html %]</option>
77 [% IF uploadcategories %]
78 <div class="hint">Note: For temporary uploads do not select a category.</div>
81 Note: No upload categories are defined.
82 [% IF ( CAN_user_parameters_manage_auth_values ) -%]
83 <span>Add values to the <a href="/cgi-bin/koha/admin/authorised_values.pl?searchfield=UPLOAD">UPLOAD authorized value category</a> otherwise all uploads will be marked as temporary.</span>
85 <span>An administrator must add values to the UPLOAD authorized value category otherwise all uploads will be marked as temporary.</span>
93 <input type="hidden" id="public" name="public" value="1"/>
95 <label id="public_cb">Allow public downloads:</label>
96 <input type="checkbox" id="public" name="public" />
100 <fieldset class="action">
101 <button id="fileuploadbutton" class="btn btn-primary">Upload</button>
102 <button id="fileuploadcancel">Cancel</button>
105 <div id="fileuploadpanel">
106 <div id="fileuploadstatus" class="progress_panel">Upload progress:
107 <progress id="fileuploadprogress" max="100" value="0">
109 <span class="fileuploadpercent">0</span>%
111 <div id="fileuploadfailed"></div>
116 [% BLOCK form_browse %]
117 [% IF uploadcategories %]
118 <form method="post" id="browsefile" action="/cgi-bin/koha/tools/upload.pl">
119 [% PROCESS plugin_pars %]
120 <input type="hidden" name="op" value="browse"/>
121 <fieldset class="brief">
122 <h4>Search uploads by category</h4>
125 <label for="browsecategory">Category: </label>
126 <select id="browsecategory" name="browsecategory" required="required">
127 <option value="">Choose</option>
128 [% FOREACH cat IN uploadcategories %]
129 [% IF cat.code == browsecategory %]
130 <option value="[% cat.code | html %]" selected="selected">[% cat.name | html %]</option>
132 <option value="[% cat.code | html %]">[% cat.name | html %]</option>
138 <fieldset class="action">
139 <button id="browsebutton" class="btn btn-primary">Search</button>
146 [% BLOCK form_search %]
147 <form method="post" id="searchfile" action="/cgi-bin/koha/tools/upload.pl">
148 [% PROCESS plugin_pars %]
149 <input type="hidden" name="op" value="search"/>
150 <fieldset class="brief">
151 <h4>Search uploads by name or hashvalue</h4>
154 <label for="term">Search term: </label>
155 <input type="text" id="term" name="term" value=""/>
158 <fieldset class="action">
159 <button id="searchbutton" class="btn btn-primary">Search</button>
165 [% BLOCK submitter %]
166 <form id="submitter" style="display:none;" method="post">
167 [% PROCESS plugin_pars %]
168 <input type="hidden" name="op" id="op" value=""/>
169 <input type="hidden" name="id" id="id" value="" />
170 <input type="hidden" name="msg" id="msg" value="" />
176 <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
183 <fieldset class="action">
184 <button class="submit">Back</button>
190 [% BLOCK newsearch %]
191 <form id="newsearch">
192 <fieldset class="action">
193 <button id="new_search">New search</button>
197 <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
201 [% BLOCK table_results %]
202 <div class="page-section">
203 <table id="uploadresults">
211 [% IF !plugin %]<th>Public</th>[% END %]
212 [% IF !plugin %]<th>Temporary</th>[% END %]
213 <th class="NoSort noExport">Actions</th>
217 [% FOREACH record IN uploads %]
219 <td>[% record.filename | html %]</td>
220 <td>[% record.filesize | html %]</td>
221 <td>[% record.hashvalue | html %]</td>
222 <td data-order="[% record.dtcreated | html %]">[% record.dtcreated | $KohaDates with_hours = 1 %]</td>
224 <a href="/cgi-bin/koha/tools/upload.pl?op=browse&browsecategory=[% record.uploadcategorycode | uri %]">[% AuthorisedValues.GetByCode( 'UPLOAD', record.uploadcategorycode ) | html %]</a>
228 [% IF record.public %]
229 <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>
234 <td>[% IF record.permanent %]No[% ELSE %]Yes[% END %]</td>
238 <button class="btn btn-default btn-xs choose_entry" data-record-hashvalue="[% record.hashvalue | html %]"><i class="fa fa-plus"></i> Choose</button>
240 <button class="btn btn-default btn-xs download_entry" data-record-id="[% record.id | html %]"><i class="fa fa-download"></i> Download</button>
241 [% IF record.owner == owner || CAN_user_tools_upload_manage %]
242 <button class="btn btn-default btn-xs delete_entry" data-record-id="[% record.id | html %]"><i class="fa fa-trash"></i> Delete</button>
249 </div> <!-- /.page-section -->
253 #fileuploadstatus,#fileuploadfailed { display : none; }
254 #fileuploadstatus { margin:.4em; }
255 #fileuploadprogress { width:150px;height:10px;border:1px solid #666;background:url('[% interface | html %]/[% theme | html %]/img/progress.png') -300px 0px no-repeat; }
262 <body id="tools_upload" class="tools">
263 <div class="main container-fluid">
265 <div class="col-sm-12">
268 <body id="tools_upload" class="tools">
269 [% INCLUDE 'header.inc' %]
270 [% INCLUDE 'cat-search.inc' %]
271 [% PROCESS breadcrumbs %]
273 <div class="main container-fluid">
275 <div class="col-sm-10 col-sm-push-2">
280 <div class="dialog alert" id="myalerts" style="display:none;"></div>
282 [% PROCESS submitter %]
283 [% IF mode == 'new' || mode == 'deleted' %]
284 [% PROCESS form_new %]
286 [% IF uploadcategories %]
287 <div class="col-xs-6">
288 [% PROCESS form_browse %]
290 <div class="col-xs-6">
292 <div class="col-xs-12">
294 [% PROCESS form_search %]
298 [% ELSIF mode == 'report' %]
299 <div id="toolbar" class="btn-toolbar">
300 <a href="/cgi-bin/koha/tools/upload.pl" class="btn btn-default">Upload file</a>
303 <h3>Your request gave the following results:</h3>
304 [% PROCESS table_results %]
308 <h4>Sorry, your request had no results.</h4>
309 [% PROCESS newsearch %]
315 </div> <!-- /.col-sm-10.col-sm-push-2 -->
317 <div class="col-sm-2 col-sm-pull-10">
319 [% IF mode == 'report' %]
320 [% PROCESS form_browse %]
321 [% PROCESS form_search %]
325 [% INCLUDE 'tools-menu.inc' %]
327 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
328 </div> <!-- /.row -->
331 </div> <!-- .col-sm-12 -->
332 </div> <!-- /.row -->
336 [% MACRO jsinclude BLOCK %]
337 [% Asset.js("js/tools-menu.js") | $raw %]
338 [% INCLUDE 'datatables.inc' %]
339 [% Asset.js("js/file-upload.js") | $raw %]
340 [% INCLUDE 'columns_settings.inc' %]
342 function StartUpload() {
343 if( $('#fileToUpload').prop('files').length == 0 ) return;
344 $('#fileToUpload').prop('disabled',true);
345 $('#fileuploadbutton').hide();
346 $("#fileuploadcancel").show();
347 $("#fileuploadfailed").html('');
348 $("#myalerts").hide('');
349 $("#myalerts").html('');
350 $("#fileuploadstatus").show();
351 $("#uploadedfileid").val('');
352 $("#searchfile").hide();
353 $("#lastbreadcrumb").text( _("Add a new upload") );
356 if( $("#uploadcategory").val() )
357 cat = encodeURIComponent( $("#uploadcategory").val() );
358 if( cat ) xtra= 'category=' + cat + '&';
360 xtra = xtra + 'public=1&temp=0';
362 if( !cat ) xtra = 'temp=1&';
363 if( $('#public').prop('checked') ) xtra = xtra + 'public=1';
365 xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), xtra, cbUpload );
367 function CancelUpload() {
368 if( xhr ) xhr.abort();
369 $("#fileuploadstatus").hide();
370 $('#fileToUpload').prop('disabled', false);
371 $('#fileuploadbutton').show();
372 $("#fileuploadcancel").hide();
373 $("#fileuploadfailed").show();
374 $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
376 function cbUpload( status, fileid, err ) {
377 $('#fileToUpload').prop('disabled', false);
378 if( status=='done' ) {
379 var e = err? JSON.stringify(err): '';
380 SubmitMe( 'search', fileid, e );
382 $('#fileuploadbutton').show();
383 $("#fileuploadcancel").hide();
384 $("#fileuploadstatus").hide();
385 $("#fileuploadfailed").show();
386 $("#fileuploadfailed").html( _("Upload status: ") +
387 ( status=='failed'? _("Failed"):
388 ( status=='denied'? _("Denied"): status ))
393 function ShowAlerts(err) {
395 for( var file in err ) {
396 str= str + '<p>' + file + ': ' +
397 errMESSAGES( err[file].code ) + '</p>';
400 $('#myalerts').html(str);
401 $('#myalerts').show();
404 function errMESSAGES(code) {
407 case 'UPLERR_ALREADY_EXISTS':
408 rv = _("This file already exists (in this category).");
410 case 'UPLERR_CANNOT_WRITE':
411 rv = _("File could not be created. Check permissions.");
413 case 'UPLERR_NO_ROOT_DIR':
414 rv = _("Your koha-conf.xml does not contain a valid upload_path.");
416 case 'UPLERR_NO_TEMP_DIR':
417 rv = _("No temporary directory found.");
419 case 'UPLERR_FILE_NOT_READ':
420 rv = _("File could not be read.");
422 case 'UPL_FILE_DELETED': // An alert, no error
423 rv = _("File has been deleted.");
425 case 'UPLERR_FILE_NOT_DELETED':
426 rv = _("File or upload record could not be deleted.");
433 function CheckSearch() {
434 if( $("#term").val()=="" ) {
435 alert( _("Please enter a search term.") );
440 function SubmitMe(op, id, msg ) {
441 $("#submitter #op").val( op );
442 $("#submitter #id").val( id );
443 $("#submitter #msg").val( msg );
444 $("#submitter").submit();
446 function DeleteEntry(id) {
447 if( !confirm( _("Do you really want to delete this upload?") ))
450 SubmitMe( 'delete', id );
452 function ClearField() {
454 $(window.opener.document).find('#[% index | html %]').val( '' );
457 function Choose(hashval) {
458 var res = '[% Koha.Preference('OPACBaseURL') | html %]';
459 res = res.replace( /\/$/, '');
460 res = res + '/cgi-bin/koha/opac-retrieve-file.pl?id=' + hashval;
462 $(window.opener.document).find('#[% index | html %]').val( res );
466 var table_settings = [% TablesSettings.GetTableSettings( 'tools', 'upload', 'uploadresults', 'json' ) | $raw %];
468 table_settings['columns'].splice(6, 1);
469 table_settings['columns'].splice(5, 1);
471 $(document).ready(function() {
472 KohaTable("uploadresults",{
476 ShowAlerts( [% msg | html %] );
478 $("#fileuploadcancel").hide();
479 $("#public_cb").click(function() {
480 $("#public").click();
482 $("#fileuploadbutton").on("click",function(e){
486 $("#fileuploadcancel").on("click",function(e){
490 $("#searchbutton").on("click",function(){
491 return CheckSearch();
493 $("#uploadresults tbody").on("click",".choose_entry",function(e){
495 var record_hashvalue = $(this).data("record-hashvalue");
496 Choose( record_hashvalue );
498 $("#uploadresults tbody").on("click",".download_entry",function(e){
500 var record_id = $(this).data("record-id");
501 SubmitMe( 'download', record_id );
503 $("#uploadresults tbody").on("click",".delete_entry",function(e){
505 var record_id = $(this).data("record-id");
506 DeleteEntry( record_id );
508 $("#new_search").on("click",function(e){
513 if ( window.isSecureContext ) {
514 $(".get-file").on("click", function(e){
516 if( navigator.clipboard && navigator.clipboard.writeText){
517 navigator.clipboard.writeText( $(this).attr("href") );
518 $(this).attr("data-original-title", _( "Link copied to the clipboard" ) )
522 $(".get-file").tooltip({
523 delay: { "show": 100, "hide": 500 }
524 }).on("hidden.bs.tooltip", function(){
525 $(this).attr("data-original-title", _( "Copy link to this file" ) );
532 [% INCLUDE 'intranet-bottom.inc' %]