Bug 13618: Add html filters to all the variables
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / upload.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% SET footerjs = 1 %]
5 [% INCLUDE 'doc-head-open.inc' %]
6 [% IF plugin %]
7     <title>Upload plugin</title>
8 [% ELSE %]
9     <title>Koha &rsaquo; Tools &rsaquo; Upload</title>
10 [% END %]
11 [% INCLUDE 'doc-head-close.inc' %]
12 [% Asset.css("css/datatables.css") | $raw %]
13
14 [% BLOCK plugin_pars %]
15     [% IF plugin %]
16         <input type="hidden" name="plugin" value="1" />
17         <input type="hidden" name="index" value="[% index | html %]" />
18     [% END %]
19 [% END %]
20
21 [% BLOCK breadcrumbs %]
22     <div id="breadcrumbs">
23         <a href="/cgi-bin/koha/mainpage.pl">Home</a>
24         &rsaquo;
25         <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
26         &rsaquo;
27         <a href="/cgi-bin/koha/tools/upload.pl">Upload</a>
28         &rsaquo;
29         <span id="lastbreadcrumb">
30         [% IF mode=='new' || mode =='deleted'%]
31             Add new upload or search
32         [% ELSE %]
33             Results
34         [% END %]
35         </span>
36     </div>
37 [% END %]
38
39 [% BLOCK form_new %]
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>
44         <ol>
45         <li>
46         <div id="fileuploadform">
47             <label for="fileToUpload">Select files: </label>
48             <input type="file" id="fileToUpload" name="fileToUpload" multiple/>
49         </div>
50         </li>
51         [% IF uploadcategories %]
52             <li>
53                 <label for="uploadcategory">Category: </label>
54                 <select id="uploadcategory" name="uploadcategory">
55                 [% IF !plugin %]
56                     <option value=""></option>
57                 [% END %]
58                 [% FOREACH cat IN uploadcategories %]
59                     <option value="[% cat.code | html %]">[% cat.name | html %]</option>
60                 [% END %]
61                 </select>
62             </li>
63         [% END %]
64         [% IF !plugin %]
65             <li>
66             [% IF uploadcategories %]
67                 <div class="hint">Note: For temporary uploads do not select a category.</div>
68             [% ELSE %]
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>
70             [% END %]
71             </li>
72         [% END %]
73         <li>
74             [% IF plugin %]
75                 <input type="hidden" id="public" name="public" value="1"/>
76             [% ELSE %]
77                 <label id="public_cb">Allow public downloads:</label>
78                 <input type="checkbox" id="public" name="public" />
79             [% END %]
80         </li>
81         </ol>
82         <fieldset class="action">
83             <button id="fileuploadbutton">Upload</button>
84             <button id="fileuploadcancel">Cancel</button>
85         </fieldset>
86         </fieldset>
87         <div id="fileuploadpanel">
88             <div id="fileuploadstatus" class="progress_panel">Upload progress:
89             <progress id="fileuploadprogress" max="100" value="0">
90             </progress>
91             <span class="fileuploadpercent">0</span>%
92             </div>
93             <div id="fileuploadfailed"></div>
94         </div>
95     </form>
96 [% END %]
97
98 [% BLOCK form_search %]
99     <form method="post" id="searchfile" action="/cgi-bin/koha/tools/upload.pl" enctype="multipart/form-data">
100         [% PROCESS plugin_pars %]
101         <input type="hidden" name="op" value="search"/>
102         <fieldset class="rows">
103         <legend>Search uploads by name or hashvalue</legend>
104         <ol>
105         <li>
106             <label for="term">Search term: </label>
107             <input type="text" id="term" name="term" value=""/>
108         </li>
109         </ol>
110         <fieldset class="action">
111             <button id="searchbutton" class="submit">Search</button>
112         </fieldset>
113         </fieldset>
114     </form>
115 [% END %]
116
117 [% BLOCK submitter %]
118     <form id="submitter" style="display:none;" method="post">
119         [% PROCESS plugin_pars %]
120         <input type="hidden" name="op" id="op" value=""/>
121         <input type="hidden" name="id" id="id" value="" />
122         <input type="hidden" name="msg" id="msg" value="" />
123     </form>
124 [% END %]
125
126 [% BLOCK closer %]
127     [% IF plugin %]
128         <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
129     [% END %]
130 [% END %]
131
132 [% BLOCK back %]
133     [% IF !plugin %]
134         <form id="back">
135             <fieldset class="action">
136                 <button class="submit">Back</button>
137             </fieldset>
138         </form>
139     [% END %]
140 [% END %]
141
142 [% BLOCK newsearch %]
143     <form id="newsearch">
144         <fieldset class="action">
145             <button id="new_search">New search</button>
146         </fieldset>
147     </form>
148     [% IF plugin %]
149         <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
150     [% END %]
151 [% END %]
152
153 [% BLOCK table_results %]
154     <table id="uploadresults">
155     <thead>
156     <tr>
157         <th>Filename</th>
158         <th>Size</th>
159         <th>Hashvalue</th>
160         <th>Category</th>
161         [% IF !plugin %]<th>Public</th>[% END %]
162         [% IF !plugin %]<th>Temporary</th>[% END %]
163         <th class="nosort">Actions</th>
164     </tr>
165     </thead>
166     <tbody>
167     [% FOREACH record IN uploads %]
168     <tr>
169         <td>[% record.filename | html %]</td>
170         <td>[% record.filesize | html %]</td>
171         <td>[% record.hashvalue | html %]</td>
172         <td>[% record.uploadcategorycode | html %]</td>
173         [% IF !plugin %]
174             <td>[% IF record.public %]Yes[% ELSE %]No[% END %]</td>
175             <td>[% IF record.permanent %]No[% ELSE %]Yes[% END %]</td>
176         [% END %]
177         <td class="actions">
178             [% IF plugin %]
179                 <button class="btn btn-default btn-xs choose_entry" data-record-hashvalue="[% record.hashvalue | html %]"><i class="fa fa-plus"></i> Choose</button>
180             [% END %]
181             <button class="btn btn-default btn-xs download_entry" data-record-id="[% record.id | html %]"><i class="fa fa-download"></i> Download</button>
182             [% IF record.owner == owner || CAN_user_tools_upload_manage %]
183                 <button class="btn btn-default btn-xs delete_entry" data-record-id="[% record.id | html %]"><i class="fa fa-trash"></i> Delete</button>
184             [% END %]
185         </td>
186    </tr>
187    [% END %]
188    </tbody>
189    </table>
190 [% END %]
191
192 <style type="text/css">
193     #fileuploadstatus,#fileuploadfailed { display : none; }
194     #fileuploadstatus { margin:.4em; }
195     #fileuploadprogress { width:150px;height:10px;border:1px solid #666;background:url('[% interface | html %]/[% theme | html %]/img/progress.png') -300px 0px no-repeat; }
196 </style>
197
198
199 </head>
200
201 [% IF ( plugin ) %]
202     <body id="tools_upload" class="tools">
203         <div class="yui-t7">
204             <div id="bd">
205                 <div class="yui-g">
206 [% ELSE %]
207     <body id="tools_upload" class="tools">
208     [% INCLUDE 'header.inc' %]
209     [% INCLUDE 'cat-search.inc' %]
210     [% PROCESS breadcrumbs %]
211     <div id="doc3" class="yui-t2">
212         <div id="bd">
213             <div id="yui-main">
214                 <div class="yui-b">
215 [% END %]
216
217
218
219 <h1>Upload</h1>
220 <div class="dialog alert" id="myalerts" style="display:none;"></div>
221
222 [% PROCESS submitter %]
223 [% IF mode == 'new' || mode == 'deleted' %]
224     [% PROCESS form_new %]
225     [% PROCESS form_search %]
226     [% PROCESS closer %]
227 [% ELSIF mode == 'report' %]
228     [% IF uploads %]
229         <h3>Your request gave the following results:</h3>
230         [% PROCESS table_results %]
231         [% PROCESS closer %]
232         [% PROCESS back %]
233     [% ELSE %]
234         <h4>Sorry, your request had no results.</h4>
235         [% PROCESS newsearch %]
236     [% END %]
237 [% END %]
238
239 </div>
240
241 [% IF !plugin %]
242 </div>
243     <div class="yui-b noprint">
244         [% INCLUDE 'tools-menu.inc' %]
245     </div>
246 [% END %]
247
248 </div>
249
250 [% MACRO jsinclude BLOCK %]
251     [% Asset.js("js/tools-menu.js") | $raw %]
252     [% INCLUDE 'datatables.inc' %]
253     [% Asset.js("js/file-upload.js") | $raw %]
254     <script type="text/javascript">
255         function StartUpload() {
256             if( $('#fileToUpload').prop('files').length == 0 ) return;
257             $('#fileToUpload').prop('disabled',true);
258             $('#fileuploadbutton').hide();
259             $("#fileuploadcancel").show();
260             $("#fileuploadfailed").html('');
261             $("#myalerts").hide('');
262             $("#myalerts").html('');
263             $("#fileuploadstatus").show();
264             $("#uploadedfileid").val('');
265             $("#searchfile").hide();
266             $("#lastbreadcrumb").text( _("Add a new upload") );
267
268             var cat, xtra='';
269             if( $("#uploadcategory").val() )
270                 cat = encodeURIComponent( $("#uploadcategory").val() );
271             if( cat ) xtra= 'category=' + cat + '&';
272             [% IF plugin %]
273                 xtra = xtra + 'public=1&temp=0';
274             [% ELSE %]
275                 if( !cat ) xtra = 'temp=1&';
276                 if( $('#public').prop('checked') ) xtra = xtra + 'public=1';
277             [% END %]
278             xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), xtra, cbUpload );
279         }
280         function CancelUpload() {
281             if( xhr ) xhr.abort();
282             $("#fileuploadstatus").hide();
283             $('#fileToUpload').prop('disabled', false);
284             $('#fileuploadbutton').show();
285             $("#fileuploadcancel").hide();
286             $("#fileuploadfailed").show();
287             $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
288         }
289         function cbUpload( status, fileid, err ) {
290             $('#fileToUpload').prop('disabled', false);
291             if( status=='done' ) {
292                 var e = err? JSON.stringify(err): '';
293                 SubmitMe( 'search', fileid, e );
294             } else {
295                 $('#fileuploadbutton').show();
296                 $("#fileuploadcancel").hide();
297                 $("#fileuploadstatus").hide();
298                 $("#fileuploadfailed").show();
299                 $("#fileuploadfailed").html( _("Upload status: ") +
300                     ( status=='failed'? _("Failed"):
301                     ( status=='denied'? _("Denied"): status ))
302                 );
303                 ShowAlerts( err );
304             }
305         }
306         function ShowAlerts(err) {
307             var str = '';
308             for( var file in err ) {
309                 str= str + '<p>' + file + ': ' +
310                     errMESSAGES( err[file].code ) + '</p>';
311             }
312             if( str ) {
313                 $('#myalerts').html(str);
314                 $('#myalerts').show();
315             }
316         }
317         function errMESSAGES(code) {
318             var rv;
319             switch(code) {
320                 case 'UPLERR_ALREADY_EXISTS':
321                     rv = _("This file already exists (in this category).");
322                     break;
323                 case 'UPLERR_CANNOT_WRITE':
324                     rv = _("File could not be created. Check permissions.");
325                     break;
326                 case 'UPLERR_NO_ROOT_DIR':
327                     rv = _("Your koha-conf.xml does not contain a valid upload_path.");
328                     break;
329                 case 'UPLERR_NO_TEMP_DIR':
330                     rv = _("No temporary directory found.");
331                     break;
332                 case 'UPLERR_FILE_NOT_READ':
333                     rv = _("File could not be read.");
334                     break;
335                 case 'UPL_FILE_DELETED': // An alert, no error
336                     rv = _("File has been deleted.");
337                     break;
338                 case 'UPLERR_FILE_NOT_DELETED':
339                     rv = _("File or upload record could not be deleted.");
340                     break;
341                 default:
342                     rv = code;
343             }
344             return rv;
345         }
346         function CheckSearch() {
347             if( $("#term").val()=="" ) {
348                 alert( _("Please enter a search term.") );
349                 return false;
350             }
351             return true;
352         }
353         function SubmitMe(op, id, msg ) {
354             $("#submitter #op").val( op );
355             $("#submitter #id").val( id );
356             $("#submitter #msg").val( msg );
357             $("#submitter").submit();
358         }
359         function DeleteEntry(id) {
360             if( !confirm( _("Do you really want to delete this upload?") ))
361                 return false;
362             ClearField();
363             SubmitMe( 'delete', id );
364         }
365         function ClearField() {
366             [% IF plugin %]
367                 $(window.opener.document).find('#[% index | html %]').val( '' );
368             [% END %]
369         }
370         function Choose(hashval) {
371             var res = '[% Koha.Preference('OPACBaseURL') | html %]';
372             res = res.replace( /\/$/, '');
373             res = res + '/cgi-bin/koha/opac-retrieve-file.pl?id=' + hashval;
374             [% IF index %]
375                 $(window.opener.document).find('#[% index | html %]').val( res );
376             [% END %]
377             window.close();
378         }
379         $(document).ready(function() {
380             $("#uploadresults").dataTable($.extend(true, {}, dataTablesDefaults, {
381                 "aoColumnDefs": [
382                     { 'bSortable': false, 'aTargets': [ 'nosort' ] }
383                 ],
384                 "sPaginationType": "four_button"
385             }));
386             [% IF msg %]
387                 ShowAlerts( [% msg | html %] );
388             [% END %]
389             $("#fileuploadcancel").hide();
390             $("#public_cb").click(function() {
391                 $("#public").click();
392             });
393             $("#fileuploadbutton").on("click",function(e){
394                 e.preventDefault();
395                 StartUpload();
396             });
397             $("#fileuploadcancel").on("click",function(e){
398                 e.preventDefault();
399                 CancelUpload();
400             });
401             $("#searchbutton").on("click",function(){
402                 return CheckSearch();
403             });
404             $(".choose_entry").on("click",function(e){
405                 e.preventDefault();
406                 var record_hashvalue = $(this).data("record-hashvalue");
407                 Choose( record_hashvalue );
408             });
409             $(".download_entry").on("click",function(e){
410                 e.preventDefault();
411                 var record_id = $(this).data("record-id");
412                 SubmitMe( 'download', record_id );
413             });
414             $(".delete_entry").on("click",function(e){
415                 e.preventDefault();
416                 var record_id = $(this).data("record-id");
417                 DeleteEntry( record_id );
418             });
419             $("#new_search").on("click",function(e){
420                 e.preventDefault();
421                 SubmitMe('new');
422             });
423         });
424     </script>
425 [% END %]
426
427 [% INCLUDE 'intranet-bottom.inc' %]