4 [% USE TablesSettings %]
6 [% INCLUDE 'doc-head-open.inc' %]
8 <title>Upload plugin</title>
10 <title>Koha › Tools › Upload</title>
12 [% INCLUDE 'doc-head-close.inc' %]
14 [% BLOCK plugin_pars %]
16 <input type="hidden" name="plugin" value="1" />
17 <input type="hidden" name="index" value="[% index | html %]" />
21 [% BLOCK breadcrumbs %]
22 <div id="breadcrumbs">
23 <a href="/cgi-bin/koha/mainpage.pl">Home</a>
25 <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
27 <a href="/cgi-bin/koha/tools/upload.pl">Upload</a>
29 <span id="lastbreadcrumb">
30 [% IF mode=='new' || mode =='deleted'%]
31 Add new upload or search
40 <form method="post" action="/cgi-bin/koha/tools/upload.pl" id="uploadfile" enctype="multipart/form-data">
41 [% PROCESS plugin_pars %]
42 <fieldset class="rows" id="uploadform">
43 <legend>Upload new files</legend>
46 <div id="fileuploadform">
47 <label for="fileToUpload">Select files: </label>
48 <input type="file" id="fileToUpload" name="fileToUpload" multiple/>
51 [% IF uploadcategories %]
53 <label for="uploadcategory">Category: </label>
54 <select id="uploadcategory" name="uploadcategory">
56 <option value=""></option>
58 [% FOREACH cat IN uploadcategories %]
59 <option value="[% cat.code | html %]">[% cat.name | html %]</option>
66 [% IF uploadcategories %]
67 <div class="hint">Note: For temporary uploads do not select a category.</div>
69 <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>
75 <input type="hidden" id="public" name="public" value="1"/>
77 <label id="public_cb">Allow public downloads:</label>
78 <input type="checkbox" id="public" name="public" />
82 <fieldset class="action">
83 <button id="fileuploadbutton">Upload</button>
84 <button id="fileuploadcancel">Cancel</button>
87 <div id="fileuploadpanel">
88 <div id="fileuploadstatus" class="progress_panel">Upload progress:
89 <progress id="fileuploadprogress" max="100" value="0">
91 <span class="fileuploadpercent">0</span>%
93 <div id="fileuploadfailed"></div>
98 [% BLOCK form_browse %]
99 [% IF uploadcategories %]
100 <form method="post" id="browsefile" action="/cgi-bin/koha/tools/upload.pl" enctype="multipart/form-data">
101 [% PROCESS plugin_pars %]
102 <input type="hidden" name="op" value="browse"/>
103 <fieldset class="rows">
104 <legend>Search uploads by category</legend>
107 <label for="browsecategory">Category: </label>
108 <select id="browsecategory" name="browsecategory">
109 [% FOREACH cat IN uploadcategories %]
110 <option value="[% cat.code | html %]">[% cat.name | html %]</option>
115 <fieldset class="action">
116 <button id="browsebutton" class="submit">Search</button>
123 [% BLOCK form_search %]
124 <form method="post" id="searchfile" action="/cgi-bin/koha/tools/upload.pl" enctype="multipart/form-data">
125 [% PROCESS plugin_pars %]
126 <input type="hidden" name="op" value="search"/>
127 <fieldset class="rows">
128 <legend>Search uploads by name or hashvalue</legend>
131 <label for="term">Search term: </label>
132 <input type="text" id="term" name="term" value=""/>
135 <fieldset class="action">
136 <button id="searchbutton" class="submit">Search</button>
142 [% BLOCK submitter %]
143 <form id="submitter" style="display:none;" method="post">
144 [% PROCESS plugin_pars %]
145 <input type="hidden" name="op" id="op" value=""/>
146 <input type="hidden" name="id" id="id" value="" />
147 <input type="hidden" name="msg" id="msg" value="" />
153 <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
160 <fieldset class="action">
161 <button class="submit">Back</button>
167 [% BLOCK newsearch %]
168 <form id="newsearch">
169 <fieldset class="action">
170 <button id="new_search">New search</button>
174 <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
178 [% BLOCK table_results %]
179 <table id="uploadresults">
186 [% IF !plugin %]<th>Public</th>[% END %]
187 [% IF !plugin %]<th>Temporary</th>[% END %]
188 <th class="NoSort noExport">Actions</th>
192 [% FOREACH record IN uploads %]
194 <td>[% record.filename | html %]</td>
195 <td>[% record.filesize | html %]</td>
196 <td>[% record.hashvalue | html %]</td>
197 <td>[% record.uploadcategorycode | html %]</td>
200 [% IF record.public %]
201 <a href="[% Koha.Preference('OPACBaseURL') | url %]/cgi-bin/koha/opac-retrieve-file.pl?id=[% record.hashvalue | uri %]" class="get-file" data-toggle="tooltip" title="Copy link to this file"><i class="fa fa-link" aria-hidden="true"></i> Yes</a>
206 <td>[% IF record.permanent %]No[% ELSE %]Yes[% END %]</td>
210 <button class="btn btn-default btn-xs choose_entry" data-record-hashvalue="[% record.hashvalue | html %]"><i class="fa fa-plus"></i> Choose</button>
212 <button class="btn btn-default btn-xs download_entry" data-record-id="[% record.id | html %]"><i class="fa fa-download"></i> Download</button>
213 [% IF record.owner == owner || CAN_user_tools_upload_manage %]
214 <button class="btn btn-default btn-xs delete_entry" data-record-id="[% record.id | html %]"><i class="fa fa-trash"></i> Delete</button>
224 #fileuploadstatus,#fileuploadfailed { display : none; }
225 #fileuploadstatus { margin:.4em; }
226 #fileuploadprogress { width:150px;height:10px;border:1px solid #666;background:url('[% interface | html %]/[% theme | html %]/img/progress.png') -300px 0px no-repeat; }
233 <body id="tools_upload" class="tools">
234 <div class="main container-fluid">
236 <div class="col-sm-12">
239 <body id="tools_upload" class="tools">
240 [% INCLUDE 'header.inc' %]
241 [% INCLUDE 'cat-search.inc' %]
242 [% PROCESS breadcrumbs %]
244 <div class="main container-fluid">
246 <div class="col-sm-10 col-sm-push-2">
251 <div class="dialog alert" id="myalerts" style="display:none;"></div>
253 [% PROCESS submitter %]
254 [% IF mode == 'new' || mode == 'deleted' %]
255 [% PROCESS form_new %]
256 [% PROCESS form_browse %]
257 [% PROCESS form_search %]
259 [% ELSIF mode == 'report' %]
261 <h3>Your request gave the following results:</h3>
262 [% PROCESS table_results %]
266 <h4>Sorry, your request had no results.</h4>
267 [% PROCESS newsearch %]
273 </div> <!-- /.col-sm-10.col-sm-push-2 -->
275 <div class="col-sm-2 col-sm-pull-10">
277 [% INCLUDE 'tools-menu.inc' %]
279 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
280 </div> <!-- /.row -->
283 </div> <!-- .col-sm-12 -->
284 </div> <!-- /.row -->
288 [% MACRO jsinclude BLOCK %]
289 [% Asset.js("js/tools-menu.js") | $raw %]
290 [% INCLUDE 'datatables.inc' %]
291 [% Asset.js("js/file-upload.js") | $raw %]
292 [% INCLUDE 'columns_settings.inc' %]
294 function StartUpload() {
295 if( $('#fileToUpload').prop('files').length == 0 ) return;
296 $('#fileToUpload').prop('disabled',true);
297 $('#fileuploadbutton').hide();
298 $("#fileuploadcancel").show();
299 $("#fileuploadfailed").html('');
300 $("#myalerts").hide('');
301 $("#myalerts").html('');
302 $("#fileuploadstatus").show();
303 $("#uploadedfileid").val('');
304 $("#searchfile").hide();
305 $("#lastbreadcrumb").text( _("Add a new upload") );
308 if( $("#uploadcategory").val() )
309 cat = encodeURIComponent( $("#uploadcategory").val() );
310 if( cat ) xtra= 'category=' + cat + '&';
312 xtra = xtra + 'public=1&temp=0';
314 if( !cat ) xtra = 'temp=1&';
315 if( $('#public').prop('checked') ) xtra = xtra + 'public=1';
317 xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), xtra, cbUpload );
319 function CancelUpload() {
320 if( xhr ) xhr.abort();
321 $("#fileuploadstatus").hide();
322 $('#fileToUpload').prop('disabled', false);
323 $('#fileuploadbutton').show();
324 $("#fileuploadcancel").hide();
325 $("#fileuploadfailed").show();
326 $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
328 function cbUpload( status, fileid, err ) {
329 $('#fileToUpload').prop('disabled', false);
330 if( status=='done' ) {
331 var e = err? JSON.stringify(err): '';
332 SubmitMe( 'search', fileid, e );
334 $('#fileuploadbutton').show();
335 $("#fileuploadcancel").hide();
336 $("#fileuploadstatus").hide();
337 $("#fileuploadfailed").show();
338 $("#fileuploadfailed").html( _("Upload status: ") +
339 ( status=='failed'? _("Failed"):
340 ( status=='denied'? _("Denied"): status ))
345 function ShowAlerts(err) {
347 for( var file in err ) {
348 str= str + '<p>' + file + ': ' +
349 errMESSAGES( err[file].code ) + '</p>';
352 $('#myalerts').html(str);
353 $('#myalerts').show();
356 function errMESSAGES(code) {
359 case 'UPLERR_ALREADY_EXISTS':
360 rv = _("This file already exists (in this category).");
362 case 'UPLERR_CANNOT_WRITE':
363 rv = _("File could not be created. Check permissions.");
365 case 'UPLERR_NO_ROOT_DIR':
366 rv = _("Your koha-conf.xml does not contain a valid upload_path.");
368 case 'UPLERR_NO_TEMP_DIR':
369 rv = _("No temporary directory found.");
371 case 'UPLERR_FILE_NOT_READ':
372 rv = _("File could not be read.");
374 case 'UPL_FILE_DELETED': // An alert, no error
375 rv = _("File has been deleted.");
377 case 'UPLERR_FILE_NOT_DELETED':
378 rv = _("File or upload record could not be deleted.");
385 function CheckSearch() {
386 if( $("#term").val()=="" ) {
387 alert( _("Please enter a search term.") );
392 function SubmitMe(op, id, msg ) {
393 $("#submitter #op").val( op );
394 $("#submitter #id").val( id );
395 $("#submitter #msg").val( msg );
396 $("#submitter").submit();
398 function DeleteEntry(id) {
399 if( !confirm( _("Do you really want to delete this upload?") ))
402 SubmitMe( 'delete', id );
404 function ClearField() {
406 $(window.opener.document).find('#[% index | html %]').val( '' );
409 function Choose(hashval) {
410 var res = '[% Koha.Preference('OPACBaseURL') | html %]';
411 res = res.replace( /\/$/, '');
412 res = res + '/cgi-bin/koha/opac-retrieve-file.pl?id=' + hashval;
414 $(window.opener.document).find('#[% index | html %]').val( res );
418 $(document).ready(function() {
419 KohaTable("uploadresults",{});
421 ShowAlerts( [% msg | html %] );
423 $("#fileuploadcancel").hide();
424 $("#public_cb").click(function() {
425 $("#public").click();
427 $("#fileuploadbutton").on("click",function(e){
431 $("#fileuploadcancel").on("click",function(e){
435 $("#searchbutton").on("click",function(){
436 return CheckSearch();
438 $("#uploadresults tbody").on("click",".choose_entry",function(e){
440 var record_hashvalue = $(this).data("record-hashvalue");
441 Choose( record_hashvalue );
443 $("#uploadresults tbody").on("click",".download_entry",function(e){
445 var record_id = $(this).data("record-id");
446 SubmitMe( 'download', record_id );
448 $("#uploadresults tbody").on("click",".delete_entry",function(e){
450 var record_id = $(this).data("record-id");
451 DeleteEntry( record_id );
453 $("#new_search").on("click",function(e){
458 if ( window.isSecureContext ) {
459 $(".get-file").on("click", function(e){
461 if( navigator.clipboard && navigator.clipboard.writeText){
462 navigator.clipboard.writeText( $(this).attr("href") );
463 $(this).attr("data-original-title", _( "Link copied to the clipboard" ) )
467 $(".get-file").tooltip({
468 delay: { "show": 100, "hide": 500 }
469 }).on("hidden.bs.tooltip", function(){
470 $(this).attr("data-original-title", _( "Copy link to this file" ) );
477 [% INCLUDE 'intranet-bottom.inc' %]