PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / views / backups / tmpl / default_modal.php
vikappointments / admin / views / backups / tmpl Last commit date
default.php 2 days ago default_modal.php 2 days ago index.html 2 days ago
default_modal.php
223 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 $vik = VAPApplication::getInstance();
15
16 ?>
17
18 <div style="padding: 10px;">
19
20 <div class="row-fluid">
21 <div class="span12">
22 <?php echo $vik->openEmptyFieldset(); ?>
23
24 <!-- ACTION - Select -->
25
26 <?php
27 $options = [
28 JHtml::fetch('select.option', 'create', JText::translate('VAPBACKUPACTIONCREATE')),
29 JHtml::fetch('select.option', 'upload', JText::translate('VAPBACKUPACTIONUPLOAD')),
30 ];
31
32 echo $vik->openControl(JText::translate('VAPMANAGEMEDIA17')); ?>
33 <select name="action" id="vap-create-action-sel">
34 <?php echo JHtml::fetch('select.options', $options); ?>
35 </select>
36 <?php echo $vik->closeControl(); ?>
37
38 <!-- TYPE - Select -->
39
40 <?php
41 $options = [];
42
43 foreach ($this->exportTypes as $id => $type)
44 {
45 $options[] = JHtml::fetch('select.option', $id, $type->getName());
46 }
47
48 echo $vik->openControl(JText::translate('VAPBACKUPCONFIG1'), 'backup-action-create'); ?>
49 <select name="type" id="vap-create-type-sel">
50 <?php echo JHtml::fetch('select.options', $options, 'value', 'text', VAPFactory::getConfig()->get('backuptype')); ?>
51 </select>
52 <?php echo $vik->closeControl(); ?>
53
54 <?php echo $vik->closeEmptyFieldset(); ?>
55 </div>
56 </div>
57
58 <div class="row-fluid backup-action-upload" style="display: none;">
59 <div class="span12">
60 <?php echo $vik->openEmptyFieldset(); ?>
61
62 <div class="vap-media-droptarget" style="position: relative;">
63 <p class="icon">
64 <i class="fas fa-upload" style="font-size: 48px;"></i>
65 </p>
66
67 <div class="lead">
68 <a href="javascript: void(0);" id="upload-file"><?php echo JText::translate('VAPMANUALUPLOAD'); ?></a>&nbsp;<?php echo JText::translate('VAPBACKUPDRAGDROP'); ?>
69 </div>
70
71 <p class="maxsize">
72 <?php echo JText::sprintf('JGLOBAL_MAXIMUM_UPLOAD_SIZE_LIMIT', JHtml::fetch('vikappointments.maxuploadsize')); ?>
73 </p>
74
75 <input type="file" id="legacy-upload" multiple style="display: none;"/>
76
77 <div class="vap-selected-archives" style="position: absolute; bottom: 6px; left: 6px; display: none;">
78
79 </div>
80
81 <div class="vap-upload-progress" style="position: absolute; bottom: 6px; right: 6px; display: flex; visibility: hidden;">
82 <progress value="0" max="100">0%</progress>
83 </div>
84 </div>
85
86 <?php echo $vik->closeEmptyFieldset(); ?>
87 </div>
88 </div>
89
90 </div>
91
92 <?php
93 JText::script('VAPCONNECTIONLOSTERROR');
94 ?>
95
96 <script>
97 (function($) {
98 'use strict';
99
100 let dragCounter = 0;
101 let file = 0;
102
103 const addFile = (files) => {
104 const bar = $('.vap-selected-archives');
105
106 if (files && files.length) {
107 file = files[0];
108 const badge = $('<span class="badge badge-info"></span>').text(file.name);
109 bar.html(badge).show();
110 } else {
111 file = null;
112 bar.hide().html('');
113 }
114 }
115
116 const saveBackup = (btn) => {
117 const formData = new FormData();
118
119 const action = $('#vap-create-action-sel').val();
120 formData.append('ajax', 1);
121 formData.append('backup_action', action);
122
123 if (action === 'create') {
124 formData.append('type', $('#vap-create-type-sel').val());
125 } else {
126 formData.append('file', file);
127 }
128
129 const progressBox = $('.vap-upload-progress');
130 progressBox.css('visibility', 'visible');
131
132 $(btn).prop('disabled', true);
133
134 UIAjax.upload(
135 // end-point URL
136 '<?php echo $vik->ajaxUrl('index.php?option=com_vikappointments&task=backup.save'); ?>',
137 // file post data
138 formData,
139 // success callback
140 (resp) => {
141 // auto-close the modal
142 vapCloseJModal('newbackup');
143
144 // then schedule an auto-refresh by clearing all the filters
145 setTimeout(() => {
146 clearFilters();
147 }, 1000);
148 },
149 // failure callback
150 (error) => {
151 alert(error.responseText || Joomla.JText._('VAPCONNECTIONLOSTERROR'));
152 $(btn).prop('disabled', false);
153
154 progressBox.css('visibility', 'hidden');
155 },
156 // progress callback
157 (progress) => {
158 // update progress
159 progressBox.find('progress').val(progress).text(progress + '%');
160 }
161 );
162 }
163
164 $(function() {
165 VikRenderer.chosen('#vap-create-action-sel, #vap-create-type-sel');
166
167 $('#vap-create-action-sel').on('change', function() {
168 if ($(this).val() === 'create') {
169 $('.backup-action-upload').hide();
170 $('.backup-action-create').show();
171 } else {
172 $('.backup-action-create').hide();
173 $('.backup-action-upload').show();
174 }
175 });
176
177 // drag&drop actions on target div
178
179 $('.vap-media-droptarget').on('drag dragstart dragend dragover dragenter dragleave drop', (e) => {
180 e.preventDefault();
181 e.stopPropagation();
182 });
183
184 $('.vap-media-droptarget').on('dragenter', function(e) {
185 // increase the drag counter because we may
186 // enter into a child element
187 dragCounter++;
188
189 $(this).addClass('drag-enter');
190 });
191
192 $('.vap-media-droptarget').on('dragleave', function(e) {
193 // decrease the drag counter to check if we
194 // left the main container
195 dragCounter--;
196
197 if (dragCounter <= 0) {
198 $(this).removeClass('drag-enter');
199 }
200 });
201
202 $('.vap-media-droptarget').on('drop', function(e) {
203 $(this).removeClass('drag-enter');
204
205 addFile(e.originalEvent.dataTransfer.files);
206 });
207
208 $('.vap-media-droptarget #upload-file').on('click', function() {
209 // unset selected files before showing the dialog
210 $('input#legacy-upload').val(null).trigger('click');
211 });
212
213 $('input#legacy-upload').on('change', function() {
214 addFile($(this)[0].files);
215 });
216
217 $('button[data-role="backup.save"]').on('click', function() {
218 saveBackup(this);
219 });
220 });
221 })(jQuery);
222 </script>
223