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