]> git.koha-community.org Git - koha.git/blob - koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt
Bug 32282: Fixed capitalisation of ID in User ID
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / upload.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE KohaDates %]
5 [% USE TablesSettings %]
6 [% USE AuthorisedValues %]
7 [% SET footerjs = 1 %]
8 [% INCLUDE 'doc-head-open.inc' %]
9 [% IF plugin %]
10     <title>Upload plugin</title>
11 [% ELSE %]
12     <title>Upload &rsaquo; Tools &rsaquo; Koha</title>
13 [% END %]
14 [% INCLUDE 'doc-head-close.inc' %]
15
16 [% BLOCK plugin_pars %]
17     [% IF plugin %]
18         <input type="hidden" name="plugin" value="1" />
19         <input type="hidden" name="index" value="[% index | html %]" />
20     [% END %]
21 [% END %]
22
23 [% BLOCK breadcrumbs %]
24     [% WRAPPER 'sub-header.inc' %]
25     <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
26         <ol>
27             <li>
28                 <a href="/cgi-bin/koha/mainpage.pl">Home</a>
29             </li>
30             <li>
31                 <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
32             </li>
33             <li>
34                 <a href="/cgi-bin/koha/tools/upload.pl">Upload</a>
35             </li>
36             <li>
37                 <a href="#" aria-current="page">
38                     [% IF mode=='new' || mode =='deleted'%]
39                         Add new upload or search
40                     [% ELSE %]
41                         Results
42                     [% END %]
43                 </a>
44             </li>
45         </ol>
46     </nav>
47     [% END %]
48 [% END %]
49
50 [% BLOCK form_new %]
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>
55         <ol>
56         <li>
57         <div id="fileuploadform">
58             <label for="fileToUpload">Select files: </label>
59             <input type="file" id="fileToUpload" name="fileToUpload" multiple/>
60         </div>
61         </li>
62         [% IF uploadcategories %]
63             <li>
64                 <label for="uploadcategory">Category: </label>
65                 <select id="uploadcategory" name="uploadcategory">
66                 [% IF !plugin %]
67                     <option value=""></option>
68                 [% END %]
69                 [% FOREACH cat IN uploadcategories %]
70                     <option value="[% cat.code | html %]">[% cat.name | html %]</option>
71                 [% END %]
72                 </select>
73             </li>
74         [% END %]
75         [% IF !plugin %]
76             <li>
77             [% IF uploadcategories %]
78                 <div class="hint">Note: For temporary uploads do not select a category.</div>
79             [% ELSE %]
80                 <div class="hint">
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>
84                     [% ELSE -%]
85                         <span>An administrator must add values to the UPLOAD authorized value category otherwise all uploads will be marked as temporary.</span>
86                     [% END %]
87                 </div>
88             [% END %]
89             </li>
90         [% END %]
91         <li>
92             [% IF plugin %]
93                 <input type="hidden" id="public" name="public" value="1"/>
94             [% ELSE %]
95                 <label id="public_cb">Allow public downloads:</label>
96                 <input type="checkbox" id="public" name="public" />
97             [% END %]
98         </li>
99         </ol>
100         <fieldset class="action">
101             <button id="fileuploadbutton" class="btn btn-primary">Upload</button>
102             <button id="fileuploadcancel">Cancel</button>
103         </fieldset>
104         </fieldset>
105         <div id="fileuploadpanel">
106             <div id="fileuploadstatus" class="progress_panel">Upload progress:
107             <progress id="fileuploadprogress" max="100" value="0">
108             </progress>
109             <span class="fileuploadpercent">0</span>%
110             </div>
111             <div id="fileuploadfailed"></div>
112         </div>
113     </form>
114 [% END %]
115
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>
123         <ol>
124             <li>
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>
131                         [% ELSE -%]
132                             <option value="[% cat.code | html %]">[% cat.name | html %]</option>
133                         [% END %]
134                     [% END %]
135                 </select>
136             </li>
137         </ol>
138         <fieldset class="action">
139             <button id="browsebutton" class="btn btn-primary">Search</button>
140         </fieldset>
141         </fieldset>
142     </form>
143     [% END %]
144 [% END %]
145
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>
152         <ol>
153         <li>
154             <label for="term">Search term: </label>
155             <input type="text" id="term" name="term" value=""/>
156         </li>
157         </ol>
158         <fieldset class="action">
159             <button id="searchbutton" class="btn btn-primary">Search</button>
160         </fieldset>
161         </fieldset>
162     </form>
163 [% END %]
164
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="" />
171     </form>
172 [% END %]
173
174 [% BLOCK closer %]
175     [% IF plugin %]
176         <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
177     [% END %]
178 [% END %]
179
180 [% BLOCK back %]
181     [% IF !plugin %]
182         <form id="back">
183             <fieldset class="action">
184                 <button class="submit">Back</button>
185             </fieldset>
186         </form>
187     [% END %]
188 [% END %]
189
190 [% BLOCK newsearch %]
191     <form id="newsearch">
192         <fieldset class="action">
193             <button id="new_search">New search</button>
194         </fieldset>
195     </form>
196     [% IF plugin %]
197         <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
198     [% END %]
199 [% END %]
200
201 [% BLOCK table_results %]
202     <div class="page-section">
203         <table id="uploadresults">
204             <thead>
205                 <tr>
206                     <th>Filename</th>
207                     <th>Size</th>
208                     <th>Hashvalue</th>
209                     <th>Date added</th>
210                     <th>Category</th>
211                     [% IF !plugin %]<th>Public</th>[% END %]
212                     [% IF !plugin %]<th>Temporary</th>[% END %]
213                     <th class="NoSort noExport">Actions</th>
214                 </tr>
215             </thead>
216             <tbody>
217                 [% FOREACH record IN uploads %]
218                     <tr>
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>
223                         <td>
224                             <a href="/cgi-bin/koha/tools/upload.pl?op=browse&browsecategory=[% record.uploadcategorycode | uri %]">[% AuthorisedValues.GetByCode( 'UPLOAD', record.uploadcategorycode ) | html %]</a>
225                         </td>
226                         [% IF !plugin %]
227                             <td>
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>
230                                 [% ELSE %]
231                                     No
232                                 [% END %]
233                             </td>
234                             <td>[% IF record.permanent %]No[% ELSE %]Yes[% END %]</td>
235                         [% END %]
236                         <td class="actions">
237                             [% IF plugin %]
238                                 <button class="btn btn-default btn-xs choose_entry" data-record-hashvalue="[% record.hashvalue | html %]"><i class="fa fa-plus"></i> Choose</button>
239                             [% END %]
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>
243                             [% END %]
244                         </td>
245                     </tr>
246                 [% END %]
247             </tbody>
248         </table>
249     </div> <!-- /.page-section -->
250 [% END %]
251
252 <style>
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; }
256 </style>
257
258
259 </head>
260
261 [% IF ( plugin ) %]
262     <body id="tools_upload" class="tools">
263         <div class="main container-fluid">
264             <div class="row">
265                 <div class="col-sm-12">
266                     <main>
267 [% ELSE %]
268     <body id="tools_upload" class="tools">
269     [% INCLUDE 'header.inc' %]
270     [% INCLUDE 'cat-search.inc' %]
271     [% PROCESS breadcrumbs %]
272
273     <div class="main container-fluid">
274         <div class="row">
275             <div class="col-sm-10 col-sm-push-2">
276                 <main>
277 [% END %]
278
279 <h1>Upload</h1>
280 <div class="dialog alert" id="myalerts" style="display:none;"></div>
281
282 [% PROCESS submitter %]
283 [% IF mode == 'new' || mode == 'deleted' %]
284     [% PROCESS form_new %]
285     <div class="row">
286         [% IF uploadcategories %]
287             <div class="col-xs-6">
288                 [% PROCESS form_browse %]
289             </div>
290             <div class="col-xs-6">
291         [% ELSE %]
292             <div class="col-xs-12">
293         [% END %]
294             [% PROCESS form_search %]
295         </div>
296     </div>
297     [% PROCESS closer %]
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>
301     </div>
302     [% IF uploads %]
303         <h3>Your request gave the following results:</h3>
304         [% PROCESS table_results %]
305         [% PROCESS closer %]
306         [% PROCESS back %]
307     [% ELSE %]
308         <h4>Sorry, your request had no results.</h4>
309         [% PROCESS newsearch %]
310     [% END %]
311 [% END %]
312
313 [% IF !plugin %]
314             </main>
315         </div> <!-- /.col-sm-10.col-sm-push-2 -->
316
317         <div class="col-sm-2 col-sm-pull-10">
318             <aside>
319                 [% IF mode == 'report' %]
320                     [% PROCESS form_browse %]
321                     [% PROCESS form_search %]
322                 [% END %]
323
324
325                 [% INCLUDE 'tools-menu.inc' %]
326             </aside>
327         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
328      </div> <!-- /.row -->
329 [% ELSE %]
330             </main>
331         </div> <!-- .col-sm-12 -->
332      </div> <!-- /.row -->
333 [% END %]
334
335
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' %]
341     <script>
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") );
354
355             var cat, xtra='';
356             if( $("#uploadcategory").val() )
357                 cat = encodeURIComponent( $("#uploadcategory").val() );
358             if( cat ) xtra= 'category=' + cat + '&';
359             [% IF plugin %]
360                 xtra = xtra + 'public=1&temp=0';
361             [% ELSE %]
362                 if( !cat ) xtra = 'temp=1&';
363                 if( $('#public').prop('checked') ) xtra = xtra + 'public=1';
364             [% END %]
365             xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), xtra, cbUpload );
366         }
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 ") );
375         }
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 );
381             } else {
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 ))
389                 );
390                 ShowAlerts( err );
391             }
392         }
393         function ShowAlerts(err) {
394             var str = '';
395             for( var file in err ) {
396                 str= str + '<p>' + file + ': ' +
397                     errMESSAGES( err[file].code ) + '</p>';
398             }
399             if( str ) {
400                 $('#myalerts').html(str);
401                 $('#myalerts').show();
402             }
403         }
404         function errMESSAGES(code) {
405             var rv;
406             switch(code) {
407                 case 'UPLERR_ALREADY_EXISTS':
408                     rv = _("This file already exists (in this category).");
409                     break;
410                 case 'UPLERR_CANNOT_WRITE':
411                     rv = _("File could not be created. Check permissions.");
412                     break;
413                 case 'UPLERR_NO_ROOT_DIR':
414                     rv = _("Your koha-conf.xml does not contain a valid upload_path.");
415                     break;
416                 case 'UPLERR_NO_TEMP_DIR':
417                     rv = _("No temporary directory found.");
418                     break;
419                 case 'UPLERR_FILE_NOT_READ':
420                     rv = _("File could not be read.");
421                     break;
422                 case 'UPL_FILE_DELETED': // An alert, no error
423                     rv = _("File has been deleted.");
424                     break;
425                 case 'UPLERR_FILE_NOT_DELETED':
426                     rv = _("File or upload record could not be deleted.");
427                     break;
428                 default:
429                     rv = code;
430             }
431             return rv;
432         }
433         function CheckSearch() {
434             if( $("#term").val()=="" ) {
435                 alert( _("Please enter a search term.") );
436                 return false;
437             }
438             return true;
439         }
440         function SubmitMe(op, id, msg ) {
441             $("#submitter #op").val( op );
442             $("#submitter #id").val( id );
443             $("#submitter #msg").val( msg );
444             $("#submitter").submit();
445         }
446         function DeleteEntry(id) {
447             if( !confirm( _("Do you really want to delete this upload?") ))
448                 return false;
449             ClearField();
450             SubmitMe( 'delete', id );
451         }
452         function ClearField() {
453             [% IF plugin %]
454                 $(window.opener.document).find('#[% index | html %]').val( '' );
455             [% END %]
456         }
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;
461             [% IF index %]
462                 $(window.opener.document).find('#[% index | html %]').val( res );
463             [% END %]
464             window.close();
465         }
466         var table_settings = [% TablesSettings.GetTableSettings( 'tools', 'upload', 'uploadresults', 'json' ) | $raw %];
467         [% IF plugin %]
468             table_settings['columns'].splice(6, 1);
469             table_settings['columns'].splice(5, 1);
470         [% END %]
471         $(document).ready(function() {
472             KohaTable("uploadresults",{
473             }, table_settings);
474
475             [% IF msg %]
476                 ShowAlerts( [% msg | html %] );
477             [% END %]
478             $("#fileuploadcancel").hide();
479             $("#public_cb").click(function() {
480                 $("#public").click();
481             });
482             $("#fileuploadbutton").on("click",function(e){
483                 e.preventDefault();
484                 StartUpload();
485             });
486             $("#fileuploadcancel").on("click",function(e){
487                 e.preventDefault();
488                 CancelUpload();
489             });
490             $("#searchbutton").on("click",function(){
491                 return CheckSearch();
492             });
493             $("#uploadresults tbody").on("click",".choose_entry",function(e){
494                 e.preventDefault();
495                 var record_hashvalue = $(this).data("record-hashvalue");
496                 Choose( record_hashvalue );
497             });
498             $("#uploadresults tbody").on("click",".download_entry",function(e){
499                 e.preventDefault();
500                 var record_id = $(this).data("record-id");
501                 SubmitMe( 'download', record_id );
502             });
503             $("#uploadresults tbody").on("click",".delete_entry",function(e){
504                 e.preventDefault();
505                 var record_id = $(this).data("record-id");
506                 DeleteEntry( record_id );
507             });
508             $("#new_search").on("click",function(e){
509                 e.preventDefault();
510                 SubmitMe('new');
511             });
512
513             if ( window.isSecureContext ) {
514                 $(".get-file").on("click", function(e){
515                     e.preventDefault();
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" ) )
519                             .tooltip("show");
520                     }
521                 });
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" ) );
526                 });
527             }
528         });
529     </script>
530 [% END %]
531
532 [% INCLUDE 'intranet-bottom.inc' %]