default.php
6 days ago
default_currency.php
6 days ago
default_currency_details.php
6 days ago
default_currency_providers.php
6 days ago
default_email.php
6 days ago
default_email_attachments.php
6 days ago
default_email_mail.php
6 days ago
default_email_notifications.php
6 days ago
default_email_template.php
6 days ago
default_global.php
6 days ago
default_global_calendars.php
6 days ago
default_global_columns.php
6 days ago
default_global_gdpr.php
6 days ago
default_global_sync.php
6 days ago
default_global_system.php
6 days ago
default_global_timezone.php
6 days ago
default_global_zip.php
6 days ago
default_listings.php
6 days ago
default_listings_employees.php
6 days ago
default_listings_services.php
6 days ago
default_shop.php
6 days ago
default_shop_details.php
6 days ago
default_shop_invoice.php
6 days ago
default_shop_packages.php
6 days ago
default_shop_recurrence.php
6 days ago
default_shop_reviews.php
6 days ago
default_shop_subscriptions.php
6 days ago
default_shop_waitlist.php
6 days ago
index.html
6 days ago
default_global_zip.php
363 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 | $params = $this->params; |
| 15 | |
| 16 | $vik = VAPApplication::getInstance(); |
| 17 | |
| 18 | /** |
| 19 | * Trigger event to display custom HTML. |
| 20 | * In case it is needed to include any additional fields, |
| 21 | * it is possible to create a plugin and attach it to an event |
| 22 | * called "onDisplayViewConfigGlobalZIP". The event method |
| 23 | * receives the view instance as argument. |
| 24 | * |
| 25 | * @since 1.7 |
| 26 | */ |
| 27 | $forms = $this->onDisplayView('GlobalZIP'); |
| 28 | |
| 29 | ?> |
| 30 | |
| 31 | <div class="config-fieldset"> |
| 32 | |
| 33 | <div class="config-fieldset-body"> |
| 34 | |
| 35 | <!-- ZIP CODE ID - Select --> |
| 36 | |
| 37 | <?php |
| 38 | $elements = array( |
| 39 | JHtml::fetch('select.option', '', ''), |
| 40 | ); |
| 41 | |
| 42 | foreach ($this->customFields as $cf) |
| 43 | { |
| 44 | // take only text, textarea and select |
| 45 | if (in_array($cf['type'], array('text', 'textarea', 'select'))) |
| 46 | { |
| 47 | $name = $cf['langname']; |
| 48 | |
| 49 | if ($cf['rule'] == 'zip') |
| 50 | { |
| 51 | $name .= ' ( !! )'; |
| 52 | } |
| 53 | |
| 54 | $elements[] = JHtml::fetch('select.option', $cf['id'], $name); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | $help = $vik->createPopover(array( |
| 59 | 'title' => JText::translate('VAPMANAGECONFIG32'), |
| 60 | 'content' => JText::translate('VAPMANAGECONFIG32_DESC'), |
| 61 | )); |
| 62 | |
| 63 | echo $vik->openControl(JText::translate('VAPMANAGECONFIG32') . $help); ?> |
| 64 | <select name="zipcfid" id="vapzipfieldselect"> |
| 65 | <?php echo JHtml::fetch('select.options', $elements, 'value', 'text', $params['zipcfid']); ?> |
| 66 | </select> |
| 67 | <?php echo $vik->closeControl(); ?> |
| 68 | |
| 69 | <!-- ZIP CODES LIST --> |
| 70 | |
| 71 | <?php |
| 72 | $zip_codes = empty($params['zipcodes']) ? array() : json_decode($params['zipcodes'], true); |
| 73 | |
| 74 | $control = array(); |
| 75 | $control['style'] = $params['zipcfid'] <= 0 ? 'display:none;' : ''; |
| 76 | |
| 77 | echo $vik->openControl(JText::translate('VAPMANAGECONFIG34'), 'vapzipchild', $control); ?> |
| 78 | <div id="vapzipcodescont"> |
| 79 | <?php |
| 80 | foreach ($zip_codes as $i => $zip) |
| 81 | { |
| 82 | ?> |
| 83 | <div class="vapzcrow inline-fields" style="margin-bottom: 5px; align-items: center;"> |
| 84 | |
| 85 | <input type="text" name="zip_code_from[]" style="vertical-align: middle; margin-right: 4px;" value="<?php echo $zip['from']; ?>" size="10" placeholder="<?php echo $this->escape(JText::translate('VAPMANAGEWD3')); ?>" /> |
| 86 | <input type="text" name="zip_code_to[]" style="vertical-align: middle; margin-right: 4px;" value="<?php echo $zip['to']; ?>" size="10" placeholder="<?php echo $this->escape(JText::translate('VAPMANAGEWD4')); ?>" /> |
| 87 | <a href="javascript:void(0)" class="remove-zip-code no-underline"> |
| 88 | <i class="fas fa-minus-circle no big"></i> |
| 89 | </a> |
| 90 | |
| 91 | </div> |
| 92 | <?php |
| 93 | } |
| 94 | ?> |
| 95 | </div> |
| 96 | |
| 97 | <div> |
| 98 | <button type="button" class="btn" id="vapaddzipbutton"> |
| 99 | <?php echo JText::translate('VAPMANAGECONFIG35'); ?> |
| 100 | </button> |
| 101 | </div> |
| 102 | <?php echo $vik->closeControl(); ?> |
| 103 | |
| 104 | <!-- VALIDATE ZIP CODE - Test --> |
| 105 | |
| 106 | <?php |
| 107 | $control = array(); |
| 108 | $control['style'] = $params['zipcfid'] <= 0 ? 'display:none;' : ''; |
| 109 | |
| 110 | echo $vik->openControl(JText::translate('VAPMANAGECONFIG36'), 'vapzipchild', $control); ?> |
| 111 | <div class="input-append"> |
| 112 | <input type="text" id="vaptryziptext" size="10" /> |
| 113 | |
| 114 | <button type="button" id="vaptryzipbtn" class="btn"> |
| 115 | <?php echo JText::translate("VAPMANAGECONFIG37"); ?> |
| 116 | |
| 117 | <i id="vaploadimgspan" style="margin-left: 4px;"></i> |
| 118 | </button> |
| 119 | </div> |
| 120 | <?php echo $vik->closeControl(); ?> |
| 121 | |
| 122 | <!-- UPLOAD ZIP LIST - File --> |
| 123 | |
| 124 | <?php |
| 125 | $control = array(); |
| 126 | $control['style'] = $params['zipcfid'] <= 0 ? 'display:none;' : ''; |
| 127 | |
| 128 | $help = $vik->createPopover(array( |
| 129 | 'title' => JText::translate('VAPMANAGECONFIG39'), |
| 130 | 'content' => JText::translate('VAPMANAGECONFIG41'), |
| 131 | )); |
| 132 | |
| 133 | echo $vik->openControl(JText::translate('VAPMANAGECONFIG39') . $help, 'vapzipchild', $control); ?> |
| 134 | <input type="file" id="zipfile" style="display:none;" /> |
| 135 | |
| 136 | <button type="button" class="btn" id="zip-uploader"> |
| 137 | <?php echo JText::translate("VAPMANAGECONFIG40"); ?> |
| 138 | </button> |
| 139 | <?php echo $vik->closeControl(); ?> |
| 140 | |
| 141 | <!-- Define role to detect the supported hook --> |
| 142 | <!-- {"rule":"customizer","event":"onDisplayViewConfigGlobalZIP","key":"basic","type":"field"} --> |
| 143 | |
| 144 | <?php |
| 145 | /** |
| 146 | * Look for any additional fields to be pushed within |
| 147 | * the Global > ZIP Codes > ZIP fieldset. |
| 148 | * |
| 149 | * @since 1.7 |
| 150 | */ |
| 151 | if (isset($forms['basic'])) |
| 152 | { |
| 153 | echo $forms['basic']; |
| 154 | |
| 155 | // unset details form to avoid displaying it twice |
| 156 | unset($forms['basic']); |
| 157 | } |
| 158 | ?> |
| 159 | |
| 160 | </div> |
| 161 | |
| 162 | </div> |
| 163 | |
| 164 | <!-- Define role to detect the supported hook --> |
| 165 | <!-- {"rule":"customizer","event":"onDisplayViewConfigGlobalZIP","type":"fieldset"} --> |
| 166 | |
| 167 | <?php |
| 168 | /** |
| 169 | * Iterate remaining forms to be displayed as new fieldsets |
| 170 | * within the Global > ZIP tab. |
| 171 | * |
| 172 | * @since 1.7 |
| 173 | */ |
| 174 | foreach ($forms as $formTitle => $formHtml) |
| 175 | { |
| 176 | ?> |
| 177 | <div class="config-fieldset"> |
| 178 | |
| 179 | <div class="config-fieldset-head"> |
| 180 | <h3><?php echo JText::translate($formTitle); ?></h3> |
| 181 | </div> |
| 182 | |
| 183 | <div class="config-fieldset-body"> |
| 184 | <?php echo $formHtml; ?> |
| 185 | </div> |
| 186 | |
| 187 | </div> |
| 188 | <?php |
| 189 | } |
| 190 | ?> |
| 191 | |
| 192 | <?php |
| 193 | JText::script('VAPMANAGECONFIG38'); |
| 194 | JText::script('VAPMANAGEWD3'); |
| 195 | JText::script('VAPMANAGEWD4'); |
| 196 | ?> |
| 197 | |
| 198 | <script> |
| 199 | |
| 200 | jQuery(function($) { |
| 201 | $('#vapzipfieldselect').select2({ |
| 202 | placeholder: Joomla.JText._('VAPMANAGECONFIG38'), |
| 203 | allowClear: true, |
| 204 | width: 250, |
| 205 | }); |
| 206 | |
| 207 | $('#vapzipfieldselect').on('change', function() { |
| 208 | if (parseInt($(this).val()) > 0) { |
| 209 | $('.vapzipchild').show(); |
| 210 | } else { |
| 211 | $('.vapzipchild').hide(); |
| 212 | } |
| 213 | }); |
| 214 | |
| 215 | // create lambda to validate the ZIP code |
| 216 | const validateZipCode = () => { |
| 217 | let input = $('#vaptryziptext'); |
| 218 | // get zip code |
| 219 | let zip = input.val(); |
| 220 | |
| 221 | if (zip.length == 0) { |
| 222 | return false; |
| 223 | } |
| 224 | |
| 225 | let data = []; |
| 226 | |
| 227 | let zipFrom = []; |
| 228 | let zipTo = []; |
| 229 | |
| 230 | $('input[name="zip_code_from[]"]').each(function() { |
| 231 | zipFrom.push($(this).val()); |
| 232 | }); |
| 233 | |
| 234 | $('input[name="zip_code_to[]"]').each(function() { |
| 235 | zipTo.push($(this).val()); |
| 236 | }); |
| 237 | |
| 238 | for (let i = 0; i < zipFrom.length; i++) { |
| 239 | let tmp = { |
| 240 | from: zipFrom[i], |
| 241 | to: zipTo[i], |
| 242 | }; |
| 243 | |
| 244 | if (tmp.from && !tmp.to) { |
| 245 | tmp.to = tmp.from; |
| 246 | } else if (tmp.to && !tmp.from) { |
| 247 | tmp.from = tmp.to; |
| 248 | } |
| 249 | |
| 250 | data.push(tmp); |
| 251 | } |
| 252 | |
| 253 | // disable input for a while |
| 254 | input.prop('readonly', true); |
| 255 | |
| 256 | let icon = $('#vaploadimgspan'); |
| 257 | icon.attr('class', 'fas fa-spinner fa-spin'); |
| 258 | |
| 259 | UIAjax.do( |
| 260 | '<?php echo $vik->ajaxUrl('index.php?option=com_vikappointments&task=configuration.testzip'); ?>', |
| 261 | { |
| 262 | zipcode: zip, |
| 263 | pool: data, |
| 264 | field: $('#vapzipfieldselect').val(), |
| 265 | }, |
| 266 | (result) => { |
| 267 | input.prop('readonly', false); |
| 268 | |
| 269 | if (result) { |
| 270 | icon.attr('class', 'fas fa-check-circle ok'); |
| 271 | } else { |
| 272 | icon.attr('class', 'far fa-circle no'); |
| 273 | } |
| 274 | }, |
| 275 | (error) => { |
| 276 | input.prop('readonly', false); |
| 277 | icon.attr('class', 'far fa-circle no'); |
| 278 | } |
| 279 | ); |
| 280 | } |
| 281 | |
| 282 | $('#vaptryziptext').on('change', validateZipCode); |
| 283 | $('#vaptryzipbtn').on('click', validateZipCode); |
| 284 | |
| 285 | // define internal callback to add a new zip code interval |
| 286 | const addZipCode = (fromZip, toZip) => { |
| 287 | let from = $('<input type="text" name="zip_code_from[]" style="vertical-align: middle; margin-right: 4px;" size="10" />') |
| 288 | .attr('placeholder', Joomla.JText._('VAPMANAGEWD3')); |
| 289 | |
| 290 | if (fromZip) { |
| 291 | from.val(fromZip); |
| 292 | } |
| 293 | |
| 294 | let to = $('<input type="text" name="zip_code_to[]" style="vertical-align: middle; margin-right: 4px;" size="10" />') |
| 295 | .attr('placeholder', Joomla.JText._('VAPMANAGEWD4')); |
| 296 | |
| 297 | if (toZip) { |
| 298 | to.val(toZip); |
| 299 | } |
| 300 | |
| 301 | let del = $( |
| 302 | '<a href="javascript:void(0)" class="remove-zip-code no-underline">\n'+ |
| 303 | '<i class="fas fa-minus-circle no big"></i>\n'+ |
| 304 | '</a>' |
| 305 | ); |
| 306 | |
| 307 | let block = $('<div class="vapzcrow inline-fields" style="margin-bottom: 5px; align-items: center;"></div>') |
| 308 | .append(from).append("\n") |
| 309 | .append(to).append("\n") |
| 310 | .append(del); |
| 311 | |
| 312 | $('#vapzipcodescont').append(block); |
| 313 | }; |
| 314 | |
| 315 | $('#vapaddzipbutton').on('click', () => { |
| 316 | addZipCode(); |
| 317 | }); |
| 318 | |
| 319 | $(document).on('click', '.remove-zip-code', function() { |
| 320 | $(this).closest('.vapzcrow').remove(); |
| 321 | }); |
| 322 | |
| 323 | $('#zip-uploader').on('click', () => { |
| 324 | // unset selected files before showing the dialog |
| 325 | $('input#zipfile').val(null).trigger('click'); |
| 326 | }); |
| 327 | |
| 328 | $('input#zipfile').on('change', function() { |
| 329 | // execute AJAX uploads after selecting the files |
| 330 | let files = $(this)[0].files; |
| 331 | |
| 332 | if (files.length == 0) { |
| 333 | return false; |
| 334 | } |
| 335 | |
| 336 | var formData = new FormData(); |
| 337 | formData.append('file', files[0]); |
| 338 | |
| 339 | UIAjax.upload( |
| 340 | // end-point URL |
| 341 | '<?php echo $vik->ajaxUrl('index.php?option=com_vikappointments&task=configuration.uploadzip'); ?>', |
| 342 | // file post data |
| 343 | formData, |
| 344 | // success callback |
| 345 | (resp) => { |
| 346 | // iterate ZIP codes found and append them within the list |
| 347 | resp.forEach((interval) => { |
| 348 | addZipCode(interval.from, interval.to); |
| 349 | }); |
| 350 | }, |
| 351 | (error) => { |
| 352 | console.error(error); |
| 353 | |
| 354 | if (error.responseText) { |
| 355 | alert(error.responseText); |
| 356 | } |
| 357 | } |
| 358 | ); |
| 359 | }); |
| 360 | }); |
| 361 | |
| 362 | </script> |
| 363 |