Bug 35241: Fix markup errors in point of sale template
[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 [%- USE KohaSpan -%]
8 [% PROCESS 'i18n.inc' %]
9 [% SET footerjs = 1 %]
10 [% INCLUDE 'doc-head-open.inc' %]
11 <title>[% FILTER collapse %]
12     [% IF mode == 'new' || mode == 'deleted' %]
13         [% t("Uploads") | html %] &rsaquo;
14     [% ELSE %]
15     [% END %]
16     [% IF mode == 'report' %]
17         [% t("Results") | html %] &rsaquo;
18         [% t("Uploads") | html %] &rsaquo;
19     [% END %]
20     [% t("Tools") | html %] &rsaquo;
21     [% t("Koha") | html %]
22 [% END %]</title>
23 [% INCLUDE 'doc-head-close.inc' %]
24
25 [% BLOCK plugin_pars %]
26     [% IF plugin %]
27         <input type="hidden" name="plugin" value="1" />
28         <input type="hidden" name="index" value="[% index | html %]" />
29     [% END %]
30 [% END %]
31
32 [% BLOCK form_new %]
33     <form method="post" action="/cgi-bin/koha/tools/upload.pl" id="uploadfile" enctype="multipart/form-data">
34         [% PROCESS plugin_pars %]
35         <fieldset class="rows" id="uploadform">
36         <legend>Upload new files</legend>
37         <ol>
38         <li>
39         <div id="fileuploadform">
40             <label for="fileToUpload">Select files: </label>
41             <input type="file" id="fileToUpload" name="fileToUpload" multiple/>
42         </div>
43         </li>
44         [% IF uploadcategories %]
45             <li>
46                 <label for="uploadcategory">Category: </label>
47                 <select id="uploadcategory" name="uploadcategory">
48                 [% IF !plugin %]
49                     <option value=""></option>
50                 [% END %]
51                 [% FOREACH cat IN uploadcategories %]
52                     <option value="[% cat.code | html %]">[% cat.name | html %]</option>
53                 [% END %]
54                 </select>
55             </li>
56         [% END %]
57         [% IF !plugin %]
58             <li>
59             [% IF uploadcategories %]
60                 <div class="hint">Note: For temporary uploads do not select a category.</div>
61             [% ELSE %]
62                 <div class="hint">
63                     Note: No upload categories are defined.
64                     [% IF ( CAN_user_parameters_manage_auth_values ) -%]
65                         [% av_UPLOAD_link = BLOCK %]<a href='/cgi-bin/koha/admin/authorised_values.pl?searchfield=UPLOAD'>UPLOAD</a>[% END %]
66                         <span>Add values to the [% av_UPLOAD_link | $raw | $KohaSpan %] authorized value category otherwise all uploads will be marked as temporary.</span>
67                     [% ELSE -%]
68                         <span>An administrator must add values to the UPLOAD authorized value category otherwise all uploads will be marked as temporary.</span>
69                     [% END %]
70                 </div>
71             [% END %]
72             </li>
73         [% END %]
74         <li>
75             [% IF plugin %]
76                 <input type="hidden" id="public" name="public" value="1"/>
77             [% ELSE %]
78                 <label id="public_cb">Allow public downloads:</label>
79                 <input type="checkbox" id="public" name="public" />
80             [% END %]
81         </li>
82         </ol>
83         </fieldset>
84         <fieldset class="action">
85             <button id="fileuploadbutton" class="btn btn-primary">Upload</button>
86             <button id="fileuploadcancel" class="btn btn-link">Cancel</button>
87         </fieldset>
88         <div id="fileuploadpanel">
89             <div id="fileuploadstatus" class="progress_panel">Upload progress:
90             <progress id="fileuploadprogress" max="100" value="0">
91             </progress>
92             <span class="fileuploadpercent">0</span>%
93             </div>
94             <div id="fileuploadfailed"></div>
95         </div>
96     </form>
97 [% END %]
98
99 [% BLOCK form_browse %]
100     [% IF uploadcategories %]
101     <form method="post" id="browsefile" action="/cgi-bin/koha/tools/upload.pl">
102         [% PROCESS plugin_pars %]
103         <input type="hidden" name="op" value="browse"/>
104         <fieldset class="brief">
105         <h4>Search uploads by category</h4>
106         <ol>
107             <li>
108                 <label for="browsecategory">Category: </label>
109                 <select id="browsecategory" name="browsecategory" required="required">
110                     <option value="">Choose</option>
111                     [% FOREACH cat IN uploadcategories %]
112                         [% IF cat.code == browsecategory %]
113                             <option value="[% cat.code | html %]" selected="selected">[% cat.name | html %]</option>
114                         [% ELSE -%]
115                             <option value="[% cat.code | html %]">[% cat.name | html %]</option>
116                         [% END %]
117                     [% END %]
118                 </select>
119             </li>
120         </ol>
121         </fieldset>
122         <fieldset class="action">
123             <button id="browsebutton" class="btn btn-primary">Search</button>
124         </fieldset>
125     </form>
126     [% END %]
127 [% END %]
128
129 [% BLOCK form_search %]
130     <form method="post" id="searchfile" action="/cgi-bin/koha/tools/upload.pl">
131         [% PROCESS plugin_pars %]
132         <input type="hidden" name="op" value="search"/>
133         <fieldset class="brief">
134         <h4>Search uploads by name or hashvalue</h4>
135         <ol>
136         <li>
137             <label for="term">Search term: </label>
138             <input type="text" id="term" name="term" value=""/>
139         </li>
140         </ol>
141         </fieldset>
142         <fieldset class="action">
143             <button id="searchbutton" class="btn btn-primary">Search</button>
144         </fieldset>
145     </form>
146 [% END %]
147
148 [% BLOCK submitter %]
149     <form id="submitter" style="display:none;" method="post">
150         [% PROCESS plugin_pars %]
151         <input type="hidden" name="op" id="op" value=""/>
152         <input type="hidden" name="id" id="id" value="" />
153         <input type="hidden" name="msg" id="msg" value="" />
154     </form>
155 [% END %]
156
157 [% BLOCK closer %]
158     [% IF plugin %]
159         <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
160     [% END %]
161 [% END %]
162
163 [% BLOCK back %]
164     [% IF !plugin %]
165         <form id="back">
166             <fieldset class="action">
167                 <button class="btn btn-default">Back</button>
168             </fieldset>
169         </form>
170     [% END %]
171 [% END %]
172
173 [% BLOCK newsearch %]
174     <form id="newsearch">
175         <fieldset class="action">
176             <button id="new_search" class="btn btn-default">New search</button>
177         </fieldset>
178     </form>
179     [% IF plugin %]
180         <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
181     [% END %]
182 [% END %]
183
184 [% BLOCK table_results %]
185     <div class="page-section">
186         <table id="uploadresults">
187             <thead>
188                 <tr>
189                     <th>Filename</th>
190                     <th>Size</th>
191                     <th>Hashvalue</th>
192                     <th>Date added</th>
193                     <th>Category</th>
194                     [% IF !plugin %]<th>Public</th>[% END %]
195                     [% IF !plugin %]<th>Temporary</th>[% END %]
196                     <th class="NoSort noExport">Actions</th>
197                 </tr>
198             </thead>
199             <tbody>
200                 [% FOREACH record IN uploads %]
201                     <tr>
202                         <td>[% record.filename | html %]</td>
203                         <td>[% record.filesize | html %]</td>
204                         <td>[% record.hashvalue | html %]</td>
205                         <td data-order="[% record.dtcreated | html %]">[% record.dtcreated | $KohaDates with_hours = 1 %]</td>
206                         <td>
207                             <a href="/cgi-bin/koha/tools/upload.pl?op=browse&browsecategory=[% record.uploadcategorycode | uri %]">[% AuthorisedValues.GetByCode( 'UPLOAD', record.uploadcategorycode ) | html %]</a>
208                         </td>
209                         [% IF !plugin %]
210                             <td>
211                                 [% IF record.public %]
212                                     <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>
213                                 [% ELSE %]
214                                     No
215                                 [% END %]
216                             </td>
217                             <td>[% IF record.permanent %]No[% ELSE %]Yes[% END %]</td>
218                         [% END %]
219                         <td class="actions">
220                             [% IF plugin %]
221                                 <button class="btn btn-default btn-xs choose_entry" data-record-hashvalue="[% record.hashvalue | html %]"><i class="fa fa-plus"></i> Choose</button>
222                             [% END %]
223                             <button class="btn btn-default btn-xs download_entry" data-record-id="[% record.id | html %]"><i class="fa fa-download"></i> Download</button>
224                             [% IF record.owner == owner || CAN_user_tools_upload_manage %]
225                                 <button class="btn btn-default btn-xs delete_entry" data-record-id="[% record.id | html %]"><i class="fa fa-trash-can"></i> Delete</button>
226                             [% END %]
227                         </td>
228                     </tr>
229                 [% END %]
230             </tbody>
231         </table>
232     </div> <!-- /.page-section -->
233 [% END %]
234
235 <style>
236     #fileuploadstatus,#fileuploadfailed { display : none; }
237     #fileuploadstatus { margin:.4em; }
238     #fileuploadprogress { width:150px;height:10px;border:1px solid #666;background:url('[% interface | html %]/[% theme | html %]/img/progress.png') -300px 0px no-repeat; }
239 </style>
240
241
242 </head>
243
244 [% IF ( plugin ) %]
245     <body id="tools_upload" class="tools">
246         <div class="main container-fluid">
247             <div class="row">
248                 <div class="col-sm-12">
249                     <main>
250 [% ELSE %]
251     <body id="tools_upload" class="tools">
252     [% WRAPPER 'header.inc' %]
253         [% INCLUDE 'cat-search.inc' %]
254     [% END %]
255     [% WRAPPER 'sub-header.inc' %]
256         [% WRAPPER breadcrumbs %]
257             [% WRAPPER breadcrumb_item %]
258                 <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
259             [% END %]
260             [% IF mode == 'new' || mode == 'deleted' %]
261                 [% WRAPPER breadcrumb_item bc_active= 1 %]
262                     <span>Uploads</span>
263                 [% END %]
264             [% ELSE %]
265                 [% WRAPPER breadcrumb_item %]
266                     <a href="/cgi-bin/koha/tools/upload.pl">Uploads</a>
267                 [% END %]
268             [% END %]
269             [% IF mode == 'report' %]
270                 [% WRAPPER breadcrumb_item bc_active= 1 %]
271                     <span>Results</span>
272                 [% END %]
273             [% END %]
274         [% END #/ WRAPPER breadcrumbs %]
275     [% END #/ WRAPPER sub-header.inc %]
276
277     <div class="main container-fluid">
278         <div class="row">
279             <div class="col-sm-10 col-sm-push-2">
280                 <main>
281 [% END %]
282
283 <h1>Uploads</h1>
284 <div class="dialog alert" id="myalerts" style="display:none;"></div>
285
286 [% PROCESS submitter %]
287 [% IF mode == 'new' || mode == 'deleted' %]
288     [% PROCESS form_new %]
289     <div class="row">
290         [% IF uploadcategories %]
291             <div class="col-xs-6">
292                 [% PROCESS form_browse %]
293             </div>
294             <div class="col-xs-6">
295         [% ELSE %]
296             <div class="col-xs-12">
297         [% END %]
298             [% PROCESS form_search %]
299         </div>
300     </div>
301     [% PROCESS closer %]
302 [% ELSIF mode == 'report' %]
303     <div id="toolbar" class="btn-toolbar">
304         <a href="/cgi-bin/koha/tools/upload.pl" class="btn btn-default">Upload file</a>
305     </div>
306     [% IF uploads %]
307         <h3>Your request gave the following results:</h3>
308         [% PROCESS table_results %]
309         [% PROCESS closer %]
310         [% PROCESS back %]
311     [% ELSE %]
312         <h4>Sorry, your request had no results.</h4>
313         [% PROCESS newsearch %]
314     [% END %]
315 [% END %]
316
317 [% IF !plugin %]
318             </main>
319         </div> <!-- /.col-sm-10.col-sm-push-2 -->
320
321         <div class="col-sm-2 col-sm-pull-10">
322             <aside>
323                 [% IF mode == 'report' %]
324                     [% PROCESS form_browse %]
325                     [% PROCESS form_search %]
326                 [% END %]
327
328
329                 [% INCLUDE 'tools-menu.inc' %]
330             </aside>
331         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
332      </div> <!-- /.row -->
333 [% ELSE %]
334             </main>
335         </div> <!-- .col-sm-12 -->
336      </div> <!-- /.row -->
337 [% END %]
338
339
340 [% MACRO jsinclude BLOCK %]
341     [% Asset.js("js/tools-menu.js") | $raw %]
342     [% INCLUDE 'datatables.inc' %]
343     [% Asset.js("js/file-upload.js") | $raw %]
344     [% INCLUDE 'columns_settings.inc' %]
345     <script>
346         function StartUpload() {
347             if( $('#fileToUpload').prop('files').length == 0 ) return;
348             $('#fileToUpload').prop('disabled',true);
349             $('#fileuploadbutton').hide();
350             $("#fileuploadcancel").show();
351             $("#fileuploadfailed").html('');
352             $("#myalerts").hide('');
353             $("#myalerts").html('');
354             $("#fileuploadstatus").show();
355             $("#uploadedfileid").val('');
356             $("#searchfile").hide();
357             $("#lastbreadcrumb").text( _("Add a new upload") );
358
359             var cat, xtra='';
360             if( $("#uploadcategory").val() )
361                 cat = encodeURIComponent( $("#uploadcategory").val() );
362             if( cat ) xtra= 'category=' + cat + '&';
363             [% IF plugin %]
364                 xtra = xtra + 'public=1&temp=0';
365             [% ELSE %]
366                 if( !cat ) xtra = 'temp=1&';
367                 if( $('#public').prop('checked') ) xtra = xtra + 'public=1';
368             [% END %]
369             xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), xtra, cbUpload );
370         }
371         function CancelUpload() {
372             if( xhr ) xhr.abort();
373             $("#fileuploadstatus").hide();
374             $('#fileToUpload').prop('disabled', false);
375             $('#fileuploadbutton').show();
376             $("#fileuploadcancel").hide();
377             $("#fileuploadfailed").show();
378             $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
379         }
380         function cbUpload( status, fileid, err ) {
381             $('#fileToUpload').prop('disabled', false);
382             if( status=='done' ) {
383                 var e = err? JSON.stringify(err): '';
384                 SubmitMe( 'search', fileid, e );
385             } else {
386                 $('#fileuploadbutton').show();
387                 $("#fileuploadcancel").hide();
388                 $("#fileuploadstatus").hide();
389                 $("#fileuploadfailed").show();
390                 $("#fileuploadfailed").html( _("Upload status: ") +
391                     ( status=='failed'? _("Failed"):
392                     ( status=='denied'? _("Denied"): status ))
393                 );
394                 ShowAlerts( err );
395             }
396         }
397         function ShowAlerts(err) {
398             var str = '';
399             for( var file in err ) {
400                 str= str + '<p>' + file + ': ' +
401                     errMESSAGES( err[file].code ) + '</p>';
402             }
403             if( str ) {
404                 $('#myalerts').html(str);
405                 $('#myalerts').show();
406             }
407         }
408         function errMESSAGES(code) {
409             var rv;
410             switch(code) {
411                 case 'UPLERR_ALREADY_EXISTS':
412                     rv = _("This file already exists (in this category).");
413                     break;
414                 case 'UPLERR_CANNOT_WRITE':
415                     rv = _("File could not be created. Check permissions.");
416                     break;
417                 case 'UPLERR_NO_ROOT_DIR':
418                     rv = _("Your koha-conf.xml does not contain a valid upload_path.");
419                     break;
420                 case 'UPLERR_NO_TEMP_DIR':
421                     rv = _("No temporary directory found.");
422                     break;
423                 case 'UPLERR_FILE_NOT_READ':
424                     rv = _("File could not be read.");
425                     break;
426                 case 'UPL_FILE_DELETED': // An alert, no error
427                     rv = _("File has been deleted.");
428                     break;
429                 case 'UPLERR_FILE_NOT_DELETED':
430                     rv = _("File or upload record could not be deleted.");
431                     break;
432                 default:
433                     rv = code;
434             }
435             return rv;
436         }
437         function CheckSearch() {
438             if( $("#term").val()=="" ) {
439                 alert( _("Please enter a search term.") );
440                 return false;
441             }
442             return true;
443         }
444         function SubmitMe(op, id, msg ) {
445             $("#submitter #op").val( op );
446             $("#submitter #id").val( id );
447             $("#submitter #msg").val( msg );
448             $("#submitter").submit();
449         }
450         function DeleteEntry(id) {
451             if( !confirm( _("Do you really want to delete this upload?") ))
452                 return false;
453             ClearField();
454             SubmitMe( 'delete', id );
455         }
456         function ClearField() {
457             [% IF plugin %]
458                 $(window.opener.document).find('#[% index | html %]').val( '' );
459             [% END %]
460         }
461         function Choose(hashval) {
462             var res = '[% Koha.Preference('OPACBaseURL') | html %]';
463             res = res.replace( /\/$/, '');
464             res = res + '/cgi-bin/koha/opac-retrieve-file.pl?id=' + hashval;
465             [% IF index %]
466                 $(window.opener.document).find('#[% index | html %]').val( res );
467             [% END %]
468             window.close();
469         }
470         var table_settings = [% TablesSettings.GetTableSettings( 'tools', 'upload', 'uploadresults', 'json' ) | $raw %];
471         [% IF plugin %]
472             table_settings['columns'].splice(6, 1);
473             table_settings['columns'].splice(5, 1);
474         [% END %]
475         $(document).ready(function() {
476             KohaTable("uploadresults",{
477             }, table_settings);
478
479             [% IF msg %]
480                 ShowAlerts( [% msg | html %] );
481             [% END %]
482             $("#fileuploadcancel").hide();
483             $("#public_cb").click(function() {
484                 $("#public").click();
485             });
486             $("#fileuploadbutton").on("click",function(e){
487                 e.preventDefault();
488                 StartUpload();
489             });
490             $("#fileuploadcancel").on("click",function(e){
491                 e.preventDefault();
492                 CancelUpload();
493             });
494             $("#searchbutton").on("click",function(){
495                 return CheckSearch();
496             });
497             $("#uploadresults tbody").on("click",".choose_entry",function(e){
498                 e.preventDefault();
499                 var record_hashvalue = $(this).data("record-hashvalue");
500                 Choose( record_hashvalue );
501             });
502             $("#uploadresults tbody").on("click",".download_entry",function(e){
503                 e.preventDefault();
504                 var record_id = $(this).data("record-id");
505                 SubmitMe( 'download', record_id );
506             });
507             $("#uploadresults tbody").on("click",".delete_entry",function(e){
508                 e.preventDefault();
509                 var record_id = $(this).data("record-id");
510                 DeleteEntry( record_id );
511             });
512             $("#new_search").on("click",function(e){
513                 e.preventDefault();
514                 SubmitMe('new');
515             });
516
517             if ( window.isSecureContext ) {
518                 $(".get-file").on("click", function(e){
519                     e.preventDefault();
520                     if( navigator.clipboard && navigator.clipboard.writeText){
521                         navigator.clipboard.writeText( $(this).attr("href") );
522                         $(this).attr("data-original-title", _( "Link copied to the clipboard" ) )
523                             .tooltip("show");
524                     }
525                 });
526                 $(".get-file").tooltip({
527                     delay: { "show": 100, "hide": 500 }
528                 }).on("hidden.bs.tooltip", function(){
529                     $(this).attr("data-original-title", _( "Copy link to this file" ) );
530                 });
531             }
532         });
533     </script>
534 [% END %]
535
536 [% INCLUDE 'intranet-bottom.inc' %]