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 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
27 <a href="/cgi-bin/koha/mainpage.pl">Home</a>
30 <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
33 <a href="/cgi-bin/koha/tools/upload.pl">Upload</a>
36 <a href="#" aria-current="page">
37 [% IF mode=='new' || mode =='deleted'%]
38 Add new upload or search
49 <form method="post" action="/cgi-bin/koha/tools/upload.pl" id="uploadfile" enctype="multipart/form-data">
50 [% PROCESS plugin_pars %]
51 <fieldset class="rows" id="uploadform">
52 <legend>Upload new files</legend>
55 <div id="fileuploadform">
56 <label for="fileToUpload">Select files: </label>
57 <input type="file" id="fileToUpload" name="fileToUpload" multiple/>
60 [% IF uploadcategories %]
62 <label for="uploadcategory">Category: </label>
63 <select id="uploadcategory" name="uploadcategory">
65 <option value=""></option>
67 [% FOREACH cat IN uploadcategories %]
68 <option value="[% cat.code | html %]">[% cat.name | html %]</option>
75 [% IF uploadcategories %]
76 <div class="hint">Note: For temporary uploads do not select a category.</div>
79 Note: No upload categories are defined.
80 [% IF ( CAN_user_parameters_manage_auth_values ) -%]
81 <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>
83 <span>An administrator must add values to the UPLOAD authorized value category otherwise all uploads will be marked as temporary.</span>
91 <input type="hidden" id="public" name="public" value="1"/>
93 <label id="public_cb">Allow public downloads:</label>
94 <input type="checkbox" id="public" name="public" />
98 <fieldset class="action">
99 <button id="fileuploadbutton">Upload</button>
100 <button id="fileuploadcancel">Cancel</button>
103 <div id="fileuploadpanel">
104 <div id="fileuploadstatus" class="progress_panel">Upload progress:
105 <progress id="fileuploadprogress" max="100" value="0">
107 <span class="fileuploadpercent">0</span>%
109 <div id="fileuploadfailed"></div>
114 [% BLOCK form_browse %]
115 [% IF uploadcategories %]
116 <form method="post" id="browsefile" action="/cgi-bin/koha/tools/upload.pl">
117 [% PROCESS plugin_pars %]
118 <input type="hidden" name="op" value="browse"/>
119 <fieldset class="brief">
120 <h4>Search uploads by category</h4>
123 <label for="browsecategory">Category: </label>
124 <select id="browsecategory" name="browsecategory" required="required">
125 <option value="">Choose</option>
126 [% FOREACH cat IN uploadcategories %]
127 [% IF cat.code == browsecategory %]
128 <option value="[% cat.code | html %]" selected="selected">[% cat.name | html %]</option>
130 <option value="[% cat.code | html %]">[% cat.name | html %]</option>
136 <fieldset class="action">
137 <button id="browsebutton" class="submit">Search</button>
144 [% BLOCK form_search %]
145 <form method="post" id="searchfile" action="/cgi-bin/koha/tools/upload.pl">
146 [% PROCESS plugin_pars %]
147 <input type="hidden" name="op" value="search"/>
148 <fieldset class="brief">
149 <h4>Search uploads by name or hashvalue</h4>
152 <label for="term">Search term: </label>
153 <input type="text" id="term" name="term" value=""/>
156 <fieldset class="action">
157 <button id="searchbutton" class="submit">Search</button>
163 [% BLOCK submitter %]
164 <form id="submitter" style="display:none;" method="post">
165 [% PROCESS plugin_pars %]
166 <input type="hidden" name="op" id="op" value=""/>
167 <input type="hidden" name="id" id="id" value="" />
168 <input type="hidden" name="msg" id="msg" value="" />
174 <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
181 <fieldset class="action">
182 <button class="submit">Back</button>
188 [% BLOCK newsearch %]
189 <form id="newsearch">
190 <fieldset class="action">
191 <button id="new_search">New search</button>
195 <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
199 [% BLOCK table_results %]
200 <table id="uploadresults">
208 [% IF !plugin %]<th>Public</th>[% END %]
209 [% IF !plugin %]<th>Temporary</th>[% END %]
210 <th class="NoSort noExport">Actions</th>
214 [% FOREACH record IN uploads %]
216 <td>[% record.filename | html %]</td>
217 <td>[% record.filesize | html %]</td>
218 <td>[% record.hashvalue | html %]</td>
219 <td data-order="[% record.dtcreated | html %]">[% record.dtcreated | $KohaDates with_hours = 1 %]</td>
221 <a href="/cgi-bin/koha/tools/upload.pl?op=browse&browsecategory=[% record.uploadcategorycode | uri %]">[% AuthorisedValues.GetByCode( 'UPLOAD', record.uploadcategorycode ) | html %]</a>
225 [% IF record.public %]
226 <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>
231 <td>[% IF record.permanent %]No[% ELSE %]Yes[% END %]</td>
235 <button class="btn btn-default btn-xs choose_entry" data-record-hashvalue="[% record.hashvalue | html %]"><i class="fa fa-plus"></i> Choose</button>
237 <button class="btn btn-default btn-xs download_entry" data-record-id="[% record.id | html %]"><i class="fa fa-download"></i> Download</button>
238 [% IF record.owner == owner || CAN_user_tools_upload_manage %]
239 <button class="btn btn-default btn-xs delete_entry" data-record-id="[% record.id | html %]"><i class="fa fa-trash"></i> Delete</button>
249 #fileuploadstatus,#fileuploadfailed { display : none; }
250 #fileuploadstatus { margin:.4em; }
251 #fileuploadprogress { width:150px;height:10px;border:1px solid #666;background:url('[% interface | html %]/[% theme | html %]/img/progress.png') -300px 0px no-repeat; }
258 <body id="tools_upload" class="tools">
259 <div class="main container-fluid">
261 <div class="col-sm-12">
264 <body id="tools_upload" class="tools">
265 [% INCLUDE 'header.inc' %]
266 [% INCLUDE 'cat-search.inc' %]
267 [% PROCESS breadcrumbs %]
269 <div class="main container-fluid">
271 <div class="col-sm-10 col-sm-push-2">
276 <div class="dialog alert" id="myalerts" style="display:none;"></div>
278 [% PROCESS submitter %]
279 [% IF mode == 'new' || mode == 'deleted' %]
280 [% PROCESS form_new %]
282 [% IF uploadcategories %]
283 <div class="col-xs-6">
284 [% PROCESS form_browse %]
286 <div class="col-xs-6">
288 <div class="col-xs-12">
290 [% PROCESS form_search %]
294 [% ELSIF mode == 'report' %]
295 <div id="toolbar" class="btn-toolbar">
296 <a href="/cgi-bin/koha/tools/upload.pl" class="btn btn-default">Upload file</a>
299 <h3>Your request gave the following results:</h3>
300 [% PROCESS table_results %]
304 <h4>Sorry, your request had no results.</h4>
305 [% PROCESS newsearch %]
311 </div> <!-- /.col-sm-10.col-sm-push-2 -->
313 <div class="col-sm-2 col-sm-pull-10">
315 [% IF mode == 'report' %]
316 [% PROCESS form_browse %]
317 [% PROCESS form_search %]
321 [% INCLUDE 'tools-menu.inc' %]
323 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
324 </div> <!-- /.row -->
327 </div> <!-- .col-sm-12 -->
328 </div> <!-- /.row -->
332 [% MACRO jsinclude BLOCK %]
333 [% Asset.js("js/tools-menu.js") | $raw %]
334 [% INCLUDE 'datatables.inc' %]
335 [% Asset.js("js/file-upload.js") | $raw %]
336 [% INCLUDE 'columns_settings.inc' %]
338 function StartUpload() {
339 if( $('#fileToUpload').prop('files').length == 0 ) return;
340 $('#fileToUpload').prop('disabled',true);
341 $('#fileuploadbutton').hide();
342 $("#fileuploadcancel").show();
343 $("#fileuploadfailed").html('');
344 $("#myalerts").hide('');
345 $("#myalerts").html('');
346 $("#fileuploadstatus").show();
347 $("#uploadedfileid").val('');
348 $("#searchfile").hide();
349 $("#lastbreadcrumb").text( _("Add a new upload") );
352 if( $("#uploadcategory").val() )
353 cat = encodeURIComponent( $("#uploadcategory").val() );
354 if( cat ) xtra= 'category=' + cat + '&';
356 xtra = xtra + 'public=1&temp=0';
358 if( !cat ) xtra = 'temp=1&';
359 if( $('#public').prop('checked') ) xtra = xtra + 'public=1';
361 xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), xtra, cbUpload );
363 function CancelUpload() {
364 if( xhr ) xhr.abort();
365 $("#fileuploadstatus").hide();
366 $('#fileToUpload').prop('disabled', false);
367 $('#fileuploadbutton').show();
368 $("#fileuploadcancel").hide();
369 $("#fileuploadfailed").show();
370 $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
372 function cbUpload( status, fileid, err ) {
373 $('#fileToUpload').prop('disabled', false);
374 if( status=='done' ) {
375 var e = err? JSON.stringify(err): '';
376 SubmitMe( 'search', fileid, e );
378 $('#fileuploadbutton').show();
379 $("#fileuploadcancel").hide();
380 $("#fileuploadstatus").hide();
381 $("#fileuploadfailed").show();
382 $("#fileuploadfailed").html( _("Upload status: ") +
383 ( status=='failed'? _("Failed"):
384 ( status=='denied'? _("Denied"): status ))
389 function ShowAlerts(err) {
391 for( var file in err ) {
392 str= str + '<p>' + file + ': ' +
393 errMESSAGES( err[file].code ) + '</p>';
396 $('#myalerts').html(str);
397 $('#myalerts').show();
400 function errMESSAGES(code) {
403 case 'UPLERR_ALREADY_EXISTS':
404 rv = _("This file already exists (in this category).");
406 case 'UPLERR_CANNOT_WRITE':
407 rv = _("File could not be created. Check permissions.");
409 case 'UPLERR_NO_ROOT_DIR':
410 rv = _("Your koha-conf.xml does not contain a valid upload_path.");
412 case 'UPLERR_NO_TEMP_DIR':
413 rv = _("No temporary directory found.");
415 case 'UPLERR_FILE_NOT_READ':
416 rv = _("File could not be read.");
418 case 'UPL_FILE_DELETED': // An alert, no error
419 rv = _("File has been deleted.");
421 case 'UPLERR_FILE_NOT_DELETED':
422 rv = _("File or upload record could not be deleted.");
429 function CheckSearch() {
430 if( $("#term").val()=="" ) {
431 alert( _("Please enter a search term.") );
436 function SubmitMe(op, id, msg ) {
437 $("#submitter #op").val( op );
438 $("#submitter #id").val( id );
439 $("#submitter #msg").val( msg );
440 $("#submitter").submit();
442 function DeleteEntry(id) {
443 if( !confirm( _("Do you really want to delete this upload?") ))
446 SubmitMe( 'delete', id );
448 function ClearField() {
450 $(window.opener.document).find('#[% index | html %]').val( '' );
453 function Choose(hashval) {
454 var res = '[% Koha.Preference('OPACBaseURL') | html %]';
455 res = res.replace( /\/$/, '');
456 res = res + '/cgi-bin/koha/opac-retrieve-file.pl?id=' + hashval;
458 $(window.opener.document).find('#[% index | html %]').val( res );
462 var table_settings = [% TablesSettings.GetTableSettings( 'tools', 'upload', 'uploadresults', 'json' ) | $raw %];
464 table_settings['columns'].splice(6, 1);
465 table_settings['columns'].splice(5, 1);
467 $(document).ready(function() {
468 KohaTable("uploadresults",{
472 ShowAlerts( [% msg | html %] );
474 $("#fileuploadcancel").hide();
475 $("#public_cb").click(function() {
476 $("#public").click();
478 $("#fileuploadbutton").on("click",function(e){
482 $("#fileuploadcancel").on("click",function(e){
486 $("#searchbutton").on("click",function(){
487 return CheckSearch();
489 $("#uploadresults tbody").on("click",".choose_entry",function(e){
491 var record_hashvalue = $(this).data("record-hashvalue");
492 Choose( record_hashvalue );
494 $("#uploadresults tbody").on("click",".download_entry",function(e){
496 var record_id = $(this).data("record-id");
497 SubmitMe( 'download', record_id );
499 $("#uploadresults tbody").on("click",".delete_entry",function(e){
501 var record_id = $(this).data("record-id");
502 DeleteEntry( record_id );
504 $("#new_search").on("click",function(e){
509 if ( window.isSecureContext ) {
510 $(".get-file").on("click", function(e){
512 if( navigator.clipboard && navigator.clipboard.writeText){
513 navigator.clipboard.writeText( $(this).attr("href") );
514 $(this).attr("data-original-title", _( "Link copied to the clipboard" ) )
518 $(".get-file").tooltip({
519 delay: { "show": 100, "hide": 500 }
520 }).on("hidden.bs.tooltip", function(){
521 $(this).attr("data-original-title", _( "Copy link to this file" ) );
528 [% INCLUDE 'intranet-bottom.inc' %]