5 [% INCLUDE 'doc-head-open.inc' %]
7 <title>Upload plugin</title>
9 <title>Koha › Tools › Upload</title>
11 [% INCLUDE 'doc-head-close.inc' %]
13 [% BLOCK plugin_pars %]
15 <input type="hidden" name="plugin" value="1" />
16 <input type="hidden" name="index" value="[% index | html %]" />
20 [% BLOCK breadcrumbs %]
21 <div id="breadcrumbs">
22 <a href="/cgi-bin/koha/mainpage.pl">Home</a>
24 <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
26 <a href="/cgi-bin/koha/tools/upload.pl">Upload</a>
28 <span id="lastbreadcrumb">
29 [% IF mode=='new' || mode =='deleted'%]
30 Add new upload or search
39 <form method="post" action="/cgi-bin/koha/tools/upload.pl" id="uploadfile" enctype="multipart/form-data">
40 [% PROCESS plugin_pars %]
41 <fieldset class="rows" id="uploadform">
42 <legend>Upload new files</legend>
45 <div id="fileuploadform">
46 <label for="fileToUpload">Select files: </label>
47 <input type="file" id="fileToUpload" name="fileToUpload" multiple/>
50 [% IF uploadcategories %]
52 <label for="uploadcategory">Category: </label>
53 <select id="uploadcategory" name="uploadcategory">
55 <option value=""></option>
57 [% FOREACH cat IN uploadcategories %]
58 <option value="[% cat.code | html %]">[% cat.name | html %]</option>
65 [% IF uploadcategories %]
66 <div class="hint">Note: For temporary uploads do not select a category.</div>
68 <div class="hint">Note: No upload categories are defined. Add values to the UPLOAD authorized value category otherwise all uploads will be marked as temporary.</div>
74 <input type="hidden" id="public" name="public" value="1"/>
76 <label id="public_cb">Allow public downloads:</label>
77 <input type="checkbox" id="public" name="public" />
81 <fieldset class="action">
82 <button id="fileuploadbutton">Upload</button>
83 <button id="fileuploadcancel">Cancel</button>
86 <div id="fileuploadpanel">
87 <div id="fileuploadstatus" class="progress_panel">Upload progress:
88 <progress id="fileuploadprogress" max="100" value="0">
90 <span class="fileuploadpercent">0</span>%
92 <div id="fileuploadfailed"></div>
97 [% BLOCK form_search %]
98 <form method="post" id="searchfile" action="/cgi-bin/koha/tools/upload.pl" enctype="multipart/form-data">
99 [% PROCESS plugin_pars %]
100 <input type="hidden" name="op" value="search"/>
101 <fieldset class="rows">
102 <legend>Search uploads by name or hashvalue</legend>
105 <label for="term">Search term: </label>
106 <input type="text" id="term" name="term" value=""/>
109 <fieldset class="action">
110 <button id="searchbutton" class="submit">Search</button>
116 [% BLOCK submitter %]
117 <form id="submitter" style="display:none;" method="post">
118 [% PROCESS plugin_pars %]
119 <input type="hidden" name="op" id="op" value=""/>
120 <input type="hidden" name="id" id="id" value="" />
121 <input type="hidden" name="msg" id="msg" value="" />
127 <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
134 <fieldset class="action">
135 <button class="submit">Back</button>
141 [% BLOCK newsearch %]
142 <form id="newsearch">
143 <fieldset class="action">
144 <button id="new_search">New search</button>
148 <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
152 [% BLOCK table_results %]
153 <table id="uploadresults">
160 [% IF !plugin %]<th>Public</th>[% END %]
161 [% IF !plugin %]<th>Temporary</th>[% END %]
162 <th class="NoSort noExport">Actions</th>
166 [% FOREACH record IN uploads %]
168 <td>[% record.filename | html %]</td>
169 <td>[% record.filesize | html %]</td>
170 <td>[% record.hashvalue | html %]</td>
171 <td>[% record.uploadcategorycode | html %]</td>
174 [% IF record.public %]
175 <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>
180 <td>[% IF record.permanent %]No[% ELSE %]Yes[% END %]</td>
184 <button class="btn btn-default btn-xs choose_entry" data-record-hashvalue="[% record.hashvalue | html %]"><i class="fa fa-plus"></i> Choose</button>
186 <button class="btn btn-default btn-xs download_entry" data-record-id="[% record.id | html %]"><i class="fa fa-download"></i> Download</button>
187 [% IF record.owner == owner || CAN_user_tools_upload_manage %]
188 <button class="btn btn-default btn-xs delete_entry" data-record-id="[% record.id | html %]"><i class="fa fa-trash"></i> Delete</button>
198 #fileuploadstatus,#fileuploadfailed { display : none; }
199 #fileuploadstatus { margin:.4em; }
200 #fileuploadprogress { width:150px;height:10px;border:1px solid #666;background:url('[% interface | html %]/[% theme | html %]/img/progress.png') -300px 0px no-repeat; }
207 <body id="tools_upload" class="tools">
208 <div class="main container-fluid">
210 <div class="col-sm-12">
213 <body id="tools_upload" class="tools">
214 [% INCLUDE 'header.inc' %]
215 [% INCLUDE 'cat-search.inc' %]
216 [% PROCESS breadcrumbs %]
218 <div class="main container-fluid">
220 <div class="col-sm-10 col-sm-push-2">
225 <div class="dialog alert" id="myalerts" style="display:none;"></div>
227 [% PROCESS submitter %]
228 [% IF mode == 'new' || mode == 'deleted' %]
229 [% PROCESS form_new %]
230 [% PROCESS form_search %]
232 [% ELSIF mode == 'report' %]
234 <h3>Your request gave the following results:</h3>
235 [% PROCESS table_results %]
239 <h4>Sorry, your request had no results.</h4>
240 [% PROCESS newsearch %]
246 </div> <!-- /.col-sm-10.col-sm-push-2 -->
248 <div class="col-sm-2 col-sm-pull-10">
250 [% INCLUDE 'tools-menu.inc' %]
252 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
253 </div> <!-- /.row -->
256 </div> <!-- .col-sm-12 -->
257 </div> <!-- /.row -->
261 [% MACRO jsinclude BLOCK %]
262 [% Asset.js("js/tools-menu.js") | $raw %]
263 [% INCLUDE 'datatables.inc' %]
264 [% Asset.js("js/file-upload.js") | $raw %]
265 [% INCLUDE 'columns_settings.inc' %]
267 function StartUpload() {
268 if( $('#fileToUpload').prop('files').length == 0 ) return;
269 $('#fileToUpload').prop('disabled',true);
270 $('#fileuploadbutton').hide();
271 $("#fileuploadcancel").show();
272 $("#fileuploadfailed").html('');
273 $("#myalerts").hide('');
274 $("#myalerts").html('');
275 $("#fileuploadstatus").show();
276 $("#uploadedfileid").val('');
277 $("#searchfile").hide();
278 $("#lastbreadcrumb").text( _("Add a new upload") );
281 if( $("#uploadcategory").val() )
282 cat = encodeURIComponent( $("#uploadcategory").val() );
283 if( cat ) xtra= 'category=' + cat + '&';
285 xtra = xtra + 'public=1&temp=0';
287 if( !cat ) xtra = 'temp=1&';
288 if( $('#public').prop('checked') ) xtra = xtra + 'public=1';
290 xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), xtra, cbUpload );
292 function CancelUpload() {
293 if( xhr ) xhr.abort();
294 $("#fileuploadstatus").hide();
295 $('#fileToUpload').prop('disabled', false);
296 $('#fileuploadbutton').show();
297 $("#fileuploadcancel").hide();
298 $("#fileuploadfailed").show();
299 $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
301 function cbUpload( status, fileid, err ) {
302 $('#fileToUpload').prop('disabled', false);
303 if( status=='done' ) {
304 var e = err? JSON.stringify(err): '';
305 SubmitMe( 'search', fileid, e );
307 $('#fileuploadbutton').show();
308 $("#fileuploadcancel").hide();
309 $("#fileuploadstatus").hide();
310 $("#fileuploadfailed").show();
311 $("#fileuploadfailed").html( _("Upload status: ") +
312 ( status=='failed'? _("Failed"):
313 ( status=='denied'? _("Denied"): status ))
318 function ShowAlerts(err) {
320 for( var file in err ) {
321 str= str + '<p>' + file + ': ' +
322 errMESSAGES( err[file].code ) + '</p>';
325 $('#myalerts').html(str);
326 $('#myalerts').show();
329 function errMESSAGES(code) {
332 case 'UPLERR_ALREADY_EXISTS':
333 rv = _("This file already exists (in this category).");
335 case 'UPLERR_CANNOT_WRITE':
336 rv = _("File could not be created. Check permissions.");
338 case 'UPLERR_NO_ROOT_DIR':
339 rv = _("Your koha-conf.xml does not contain a valid upload_path.");
341 case 'UPLERR_NO_TEMP_DIR':
342 rv = _("No temporary directory found.");
344 case 'UPLERR_FILE_NOT_READ':
345 rv = _("File could not be read.");
347 case 'UPL_FILE_DELETED': // An alert, no error
348 rv = _("File has been deleted.");
350 case 'UPLERR_FILE_NOT_DELETED':
351 rv = _("File or upload record could not be deleted.");
358 function CheckSearch() {
359 if( $("#term").val()=="" ) {
360 alert( _("Please enter a search term.") );
365 function SubmitMe(op, id, msg ) {
366 $("#submitter #op").val( op );
367 $("#submitter #id").val( id );
368 $("#submitter #msg").val( msg );
369 $("#submitter").submit();
371 function DeleteEntry(id) {
372 if( !confirm( _("Do you really want to delete this upload?") ))
375 SubmitMe( 'delete', id );
377 function ClearField() {
379 $(window.opener.document).find('#[% index | html %]').val( '' );
382 function Choose(hashval) {
383 var res = '[% Koha.Preference('OPACBaseURL') | html %]';
384 res = res.replace( /\/$/, '');
385 res = res + '/cgi-bin/koha/opac-retrieve-file.pl?id=' + hashval;
387 $(window.opener.document).find('#[% index | html %]').val( res );
391 $(document).ready(function() {
392 KohaTable("uploadresults",{
394 { 'bSortable': false, 'aTargets': [ 'NoSort' ] }
398 ShowAlerts( [% msg | html %] );
400 $("#fileuploadcancel").hide();
401 $("#public_cb").click(function() {
402 $("#public").click();
404 $("#fileuploadbutton").on("click",function(e){
408 $("#fileuploadcancel").on("click",function(e){
412 $("#searchbutton").on("click",function(){
413 return CheckSearch();
415 $("#uploadresults tbody").on("click",".choose_entry",function(e){
417 var record_hashvalue = $(this).data("record-hashvalue");
418 Choose( record_hashvalue );
420 $("#uploadresults tbody").on("click",".download_entry",function(e){
422 var record_id = $(this).data("record-id");
423 SubmitMe( 'download', record_id );
425 $("#uploadresults tbody").on("click",".delete_entry",function(e){
427 var record_id = $(this).data("record-id");
428 DeleteEntry( record_id );
430 $("#new_search").on("click",function(e){
435 if ( window.isSecureContext ) {
436 $(".get-file").on("click", function(e){
438 if( navigator.clipboard && navigator.clipboard.writeText){
439 navigator.clipboard.writeText( $(this).attr("href") );
440 $(this).attr("data-original-title", _( "Link copied to the clipboard" ) )
444 $(".get-file").tooltip({
445 delay: { "show": 100, "hide": 500 }
446 }).on("hidden.bs.tooltip", function(){
447 $(this).attr("data-original-title", _( "Copy link to this file" ) );
454 [% INCLUDE 'intranet-bottom.inc' %]