Bug 8387: Hide headings in tools when user has no permissions for any listed below
[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>
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="main container-fluid">
204             <div class="row">
205                 <div class="col-sm-12">
206                     <main>
207 [% ELSE %]
208     <body id="tools_upload" class="tools">
209     [% INCLUDE 'header.inc' %]
210     [% INCLUDE 'cat-search.inc' %]
211     [% PROCESS breadcrumbs %]
212
213     <div class="main container-fluid">
214         <div class="row">
215             <div class="col-sm-10 col-sm-push-2">
216                 <main>
217 [% END %]
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 [% IF !plugin %]
240             </main>
241         </div> <!-- /.col-sm-10.col-sm-push-2 -->
242
243         <div class="col-sm-2 col-sm-pull-10">
244             <aside>
245                 [% INCLUDE 'tools-menu.inc' %]
246             </aside>
247         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
248      </div> <!-- /.row -->
249 [% ELSE %]
250             </main>
251         </div> <!-- .col-sm-12 -->
252      </div> <!-- /.row -->
253 [% END %]
254
255
256 [% MACRO jsinclude BLOCK %]
257     [% Asset.js("js/tools-menu.js") | $raw %]
258     [% INCLUDE 'datatables.inc' %]
259     [% Asset.js("js/file-upload.js") | $raw %]
260     <script>
261         function StartUpload() {
262             if( $('#fileToUpload').prop('files').length == 0 ) return;
263             $('#fileToUpload').prop('disabled',true);
264             $('#fileuploadbutton').hide();
265             $("#fileuploadcancel").show();
266             $("#fileuploadfailed").html('');
267             $("#myalerts").hide('');
268             $("#myalerts").html('');
269             $("#fileuploadstatus").show();
270             $("#uploadedfileid").val('');
271             $("#searchfile").hide();
272             $("#lastbreadcrumb").text( _("Add a new upload") );
273
274             var cat, xtra='';
275             if( $("#uploadcategory").val() )
276                 cat = encodeURIComponent( $("#uploadcategory").val() );
277             if( cat ) xtra= 'category=' + cat + '&';
278             [% IF plugin %]
279                 xtra = xtra + 'public=1&temp=0';
280             [% ELSE %]
281                 if( !cat ) xtra = 'temp=1&';
282                 if( $('#public').prop('checked') ) xtra = xtra + 'public=1';
283             [% END %]
284             xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), xtra, cbUpload );
285         }
286         function CancelUpload() {
287             if( xhr ) xhr.abort();
288             $("#fileuploadstatus").hide();
289             $('#fileToUpload').prop('disabled', false);
290             $('#fileuploadbutton').show();
291             $("#fileuploadcancel").hide();
292             $("#fileuploadfailed").show();
293             $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
294         }
295         function cbUpload( status, fileid, err ) {
296             $('#fileToUpload').prop('disabled', false);
297             if( status=='done' ) {
298                 var e = err? JSON.stringify(err): '';
299                 SubmitMe( 'search', fileid, e );
300             } else {
301                 $('#fileuploadbutton').show();
302                 $("#fileuploadcancel").hide();
303                 $("#fileuploadstatus").hide();
304                 $("#fileuploadfailed").show();
305                 $("#fileuploadfailed").html( _("Upload status: ") +
306                     ( status=='failed'? _("Failed"):
307                     ( status=='denied'? _("Denied"): status ))
308                 );
309                 ShowAlerts( err );
310             }
311         }
312         function ShowAlerts(err) {
313             var str = '';
314             for( var file in err ) {
315                 str= str + '<p>' + file + ': ' +
316                     errMESSAGES( err[file].code ) + '</p>';
317             }
318             if( str ) {
319                 $('#myalerts').html(str);
320                 $('#myalerts').show();
321             }
322         }
323         function errMESSAGES(code) {
324             var rv;
325             switch(code) {
326                 case 'UPLERR_ALREADY_EXISTS':
327                     rv = _("This file already exists (in this category).");
328                     break;
329                 case 'UPLERR_CANNOT_WRITE':
330                     rv = _("File could not be created. Check permissions.");
331                     break;
332                 case 'UPLERR_NO_ROOT_DIR':
333                     rv = _("Your koha-conf.xml does not contain a valid upload_path.");
334                     break;
335                 case 'UPLERR_NO_TEMP_DIR':
336                     rv = _("No temporary directory found.");
337                     break;
338                 case 'UPLERR_FILE_NOT_READ':
339                     rv = _("File could not be read.");
340                     break;
341                 case 'UPL_FILE_DELETED': // An alert, no error
342                     rv = _("File has been deleted.");
343                     break;
344                 case 'UPLERR_FILE_NOT_DELETED':
345                     rv = _("File or upload record could not be deleted.");
346                     break;
347                 default:
348                     rv = code;
349             }
350             return rv;
351         }
352         function CheckSearch() {
353             if( $("#term").val()=="" ) {
354                 alert( _("Please enter a search term.") );
355                 return false;
356             }
357             return true;
358         }
359         function SubmitMe(op, id, msg ) {
360             $("#submitter #op").val( op );
361             $("#submitter #id").val( id );
362             $("#submitter #msg").val( msg );
363             $("#submitter").submit();
364         }
365         function DeleteEntry(id) {
366             if( !confirm( _("Do you really want to delete this upload?") ))
367                 return false;
368             ClearField();
369             SubmitMe( 'delete', id );
370         }
371         function ClearField() {
372             [% IF plugin %]
373                 $(window.opener.document).find('#[% index | html %]').val( '' );
374             [% END %]
375         }
376         function Choose(hashval) {
377             var res = '[% Koha.Preference('OPACBaseURL') | html %]';
378             res = res.replace( /\/$/, '');
379             res = res + '/cgi-bin/koha/opac-retrieve-file.pl?id=' + hashval;
380             [% IF index %]
381                 $(window.opener.document).find('#[% index | html %]').val( res );
382             [% END %]
383             window.close();
384         }
385         $(document).ready(function() {
386             $("#uploadresults").dataTable($.extend(true, {}, dataTablesDefaults, {
387                 "aoColumnDefs": [
388                     { 'bSortable': false, 'aTargets': [ 'nosort' ] }
389                 ],
390                 "sPaginationType": "four_button"
391             }));
392             [% IF msg %]
393                 ShowAlerts( [% msg | html %] );
394             [% END %]
395             $("#fileuploadcancel").hide();
396             $("#public_cb").click(function() {
397                 $("#public").click();
398             });
399             $("#fileuploadbutton").on("click",function(e){
400                 e.preventDefault();
401                 StartUpload();
402             });
403             $("#fileuploadcancel").on("click",function(e){
404                 e.preventDefault();
405                 CancelUpload();
406             });
407             $("#searchbutton").on("click",function(){
408                 return CheckSearch();
409             });
410             $(".choose_entry").on("click",function(e){
411                 e.preventDefault();
412                 var record_hashvalue = $(this).data("record-hashvalue");
413                 Choose( record_hashvalue );
414             });
415             $(".download_entry").on("click",function(e){
416                 e.preventDefault();
417                 var record_id = $(this).data("record-id");
418                 SubmitMe( 'download', record_id );
419             });
420             $(".delete_entry").on("click",function(e){
421                 e.preventDefault();
422                 var record_id = $(this).data("record-id");
423                 DeleteEntry( record_id );
424             });
425             $("#new_search").on("click",function(e){
426                 e.preventDefault();
427                 SubmitMe('new');
428             });
429         });
430     </script>
431 [% END %]
432
433 [% INCLUDE 'intranet-bottom.inc' %]