default.php
4 years ago
default_settings.php
4 years ago
default_settings_basic.php
2 years ago
default_templates.php
4 years ago
default_templates_admin.php
4 years ago
default_templates_customer.php
2 years ago
index.html
7 years ago
default_settings_basic.php
369 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 | JHtml::fetch('vaphtml.assets.intltel', 'input[name="smsapiadminphone"]'); |
| 15 | |
| 16 | $params = $this->params; |
| 17 | |
| 18 | $vik = VAPApplication::getInstance(); |
| 19 | |
| 20 | list($params['smsapitocust'], $params['smsapitoemp'], $params['smsapitoadmin']) = explode(',', $params['smsapito']); |
| 21 | |
| 22 | /** |
| 23 | * Trigger event to display custom HTML. |
| 24 | * In case it is needed to include any additional fields, |
| 25 | * it is possible to create a plugin and attach it to an event |
| 26 | * called "onDisplayViewConfigsmsapiSettingsDetails". The event method |
| 27 | * receives the view instance as argument. |
| 28 | * |
| 29 | * @since 1.7 |
| 30 | */ |
| 31 | $forms = $this->onDisplayView('SettingsDetails'); |
| 32 | |
| 33 | ?> |
| 34 | |
| 35 | <!-- BASIC --> |
| 36 | |
| 37 | <div class="config-fieldset"> |
| 38 | |
| 39 | <div class="config-fieldset-head"> |
| 40 | <h3><?php echo JText::translate('VAPCONFIGTABNAME4'); ?></h3> |
| 41 | </div> |
| 42 | |
| 43 | <div class="config-fieldset-body"> |
| 44 | |
| 45 | <!-- SMS APIs FILE - Select --> |
| 46 | |
| 47 | <?php |
| 48 | $options = JHtml::fetch('vaphtml.admin.smsdrivers', $blank = ''); |
| 49 | |
| 50 | echo $vik->openControl(JText::translate('VAPMANAGECONFIGSMS1')); ?> |
| 51 | <select name="smsapi" id="smsapiselect"> |
| 52 | <?php echo JHtml::fetch('select.options', $options, 'value', 'text', $params['smsapi']); ?> |
| 53 | </select> |
| 54 | <?php echo $vik->closeControl(); ?> |
| 55 | |
| 56 | <!-- ENABLE AUTO SMS APIs - Checkbox --> |
| 57 | |
| 58 | <?php |
| 59 | $yes = $vik->initRadioElement('', '', $params['smsenabled'] == 1, 'onclick="smsEnabledValueChanged(1);"'); |
| 60 | $no = $vik->initRadioElement('', '', $params['smsenabled'] == 0, 'onclick="smsEnabledValueChanged(0);"'); |
| 61 | |
| 62 | $help = $vik->createPopover(array( |
| 63 | 'title' => JText::translate('VAPMANAGECONFIGSMS2'), |
| 64 | 'content' => JText::translate('VAPMANAGECONFIGSMS2_DESC'), |
| 65 | )); |
| 66 | |
| 67 | echo $vik->openControl(JText::translate('VAPMANAGECONFIGSMS2') . $help); |
| 68 | echo $vik->radioYesNo('smsenabled', $yes, $no); |
| 69 | echo $vik->closeControl(); |
| 70 | ?> |
| 71 | |
| 72 | <!-- SMS TO CUSTOMERS - Checkbox --> |
| 73 | |
| 74 | <?php |
| 75 | $control = array(); |
| 76 | $control['style'] = $params['smsenabled'] ? '' : 'display:none;'; |
| 77 | |
| 78 | // send to customers |
| 79 | $yes = $vik->initRadioElement('', '', $params['smsapitocust'] == 1); |
| 80 | $no = $vik->initRadioElement('', '', $params['smsapitocust'] == 0); |
| 81 | |
| 82 | $help = $vik->createPopover(array( |
| 83 | 'title' => JText::translate('VAPMANAGECONFIGSMS3'), |
| 84 | 'content' => JText::translate('VAPMANAGECONFIGSMS3_DESC'), |
| 85 | )); |
| 86 | |
| 87 | echo $vik->openControl(JText::translate('VAPMANAGECONFIGSMS3') . $help, 'smsenabled-child', $control); |
| 88 | echo $vik->radioYesNo('smsapitocust', $yes, $no); |
| 89 | echo $vik->closeControl(); |
| 90 | ?> |
| 91 | |
| 92 | <!-- SMS TO EMPLOYEES - Checkbox --> |
| 93 | |
| 94 | <?php |
| 95 | // send to customers |
| 96 | $yes = $vik->initRadioElement('', '', $params['smsapitoemp'] == 1); |
| 97 | $no = $vik->initRadioElement('', '', $params['smsapitoemp'] == 0); |
| 98 | |
| 99 | $help = $vik->createPopover(array( |
| 100 | 'title' => JText::translate('VAPMANAGECONFIGSMS9'), |
| 101 | 'content' => JText::translate('VAPMANAGECONFIGSMS9_DESC'), |
| 102 | )); |
| 103 | |
| 104 | echo $vik->openControl(JText::translate('VAPMANAGECONFIGSMS9') . $help, 'smsenabled-child', $control); |
| 105 | echo $vik->radioYesNo('smsapitoemp', $yes, $no); |
| 106 | echo $vik->closeControl(); |
| 107 | ?> |
| 108 | |
| 109 | <!-- SMS TO ADMIN - Checkbox --> |
| 110 | |
| 111 | <?php |
| 112 | // send to customers |
| 113 | $yes = $vik->initRadioElement('', '', $params['smsapitoadmin'] == 1); |
| 114 | $no = $vik->initRadioElement('', '', $params['smsapitoadmin'] == 0); |
| 115 | |
| 116 | $help = $vik->createPopover(array( |
| 117 | 'title' => JText::translate('VAPMANAGECONFIGSMS10'), |
| 118 | 'content' => JText::translate('VAPMANAGECONFIGSMS10_DESC'), |
| 119 | )); |
| 120 | |
| 121 | echo $vik->openControl(JText::translate('VAPMANAGECONFIGSMS10') . $help, 'smsenabled-child', $control); |
| 122 | echo $vik->radioYesNo('smsapitoadmin', $yes, $no); |
| 123 | echo $vik->closeControl(); |
| 124 | ?> |
| 125 | |
| 126 | <!-- ADMIN PHONE - Text --> |
| 127 | |
| 128 | <?php |
| 129 | $help = $vik->createPopover(array( |
| 130 | 'title' => JText::translate('VAPMANAGECONFIGSMS4'), |
| 131 | 'content' => JText::translate('VAPMANAGECONFIGSMS4_DESC'), |
| 132 | )); |
| 133 | |
| 134 | echo $vik->openControl(JText::translate('VAPMANAGECONFIGSMS4') . $help); ?> |
| 135 | <input type="tel" name="smsapiadminphone" value="<?php echo $params['smsapiadminphone']; ?>" /> |
| 136 | <?php echo $vik->closeControl(); ?> |
| 137 | |
| 138 | <!-- SMS API ESTIMATE - Form --> |
| 139 | |
| 140 | <?php |
| 141 | $can_estimate = false; |
| 142 | |
| 143 | try |
| 144 | { |
| 145 | $smsdriver = $vik->getSmsInstance($params['smsapi']); |
| 146 | |
| 147 | if (method_exists($smsdriver, 'estimate')) |
| 148 | { |
| 149 | $can_estimate = true; |
| 150 | |
| 151 | echo $vik->openControl(JText::translate('VAPMANAGECONFIGSMS7')); ?> |
| 152 | <span id="usercreditsp">/</span> |
| 153 | |
| 154 | <button type="button" class="btn" id="estimate-credit-btn"> |
| 155 | <?php echo JText::translate("VAPMANAGECONFIGSMS8"); ?> |
| 156 | </button> |
| 157 | <?php echo $vik->closeControl(); |
| 158 | } |
| 159 | } |
| 160 | catch (Exception $e) |
| 161 | { |
| 162 | // no SMS driver |
| 163 | } |
| 164 | ?> |
| 165 | |
| 166 | <!-- Define role to detect the supported hook --> |
| 167 | <!-- {"rule":"customizer","event":"onDisplayViewConfigsmsapiSettingsDetails","key":"basic","type":"field"} --> |
| 168 | |
| 169 | <?php |
| 170 | /** |
| 171 | * Look for any additional fields to be pushed within |
| 172 | * the Settings > Settings > SMS APIs fieldset. |
| 173 | * |
| 174 | * @since 1.7 |
| 175 | */ |
| 176 | if (isset($forms['basic'])) |
| 177 | { |
| 178 | echo $forms['basic']; |
| 179 | |
| 180 | // unset details form to avoid displaying it twice |
| 181 | unset($forms['basic']); |
| 182 | } |
| 183 | ?> |
| 184 | |
| 185 | </div> |
| 186 | |
| 187 | </div> |
| 188 | |
| 189 | <!-- PARAMS --> |
| 190 | |
| 191 | <div class="config-fieldset"> |
| 192 | |
| 193 | <div class="config-fieldset-head"> |
| 194 | <h3><?php echo JText::translate('VAPMANAGECONFIGSMS5'); ?></h3> |
| 195 | </div> |
| 196 | |
| 197 | <div class="config-fieldset-body" id="vap-smsapi-params-table"> |
| 198 | <?php |
| 199 | if (empty($params['smsapi'])) |
| 200 | { |
| 201 | echo $vik->alert(JText::translate('VAPMANAGEPAYMENT9')); |
| 202 | } |
| 203 | ?> |
| 204 | </div> |
| 205 | |
| 206 | </div> |
| 207 | |
| 208 | <div id="smsapi-no-params" style="display:none;"> |
| 209 | <?php echo $vik->alert(JText::translate('VAPMANAGEPAYMENT9')); ?> |
| 210 | </div> |
| 211 | |
| 212 | <div id="smsapi-connection-err" style="display:none;"> |
| 213 | <?php echo $vik->alert(JText::translate('VAP_AJAX_GENERIC_ERROR'), 'error'); ?> |
| 214 | </div> |
| 215 | |
| 216 | <!-- Define role to detect the supported hook --> |
| 217 | <!-- {"rule":"customizer","event":"onDisplayViewConfigsmsapiSettingsDetails","type":"fieldset"} --> |
| 218 | |
| 219 | <?php |
| 220 | /** |
| 221 | * Iterate remaining forms to be displayed as new fieldsets |
| 222 | * within the Settings > Settings tab. |
| 223 | * |
| 224 | * @since 1.7 |
| 225 | */ |
| 226 | foreach ($forms as $formTitle => $formHtml) |
| 227 | { |
| 228 | ?> |
| 229 | <div class="config-fieldset"> |
| 230 | |
| 231 | <div class="config-fieldset-head"> |
| 232 | <h3><?php echo JText::translate($formTitle); ?></h3> |
| 233 | </div> |
| 234 | |
| 235 | <div class="config-fieldset-body"> |
| 236 | <?php echo $formHtml; ?> |
| 237 | </div> |
| 238 | |
| 239 | </div> |
| 240 | <?php |
| 241 | } |
| 242 | ?> |
| 243 | |
| 244 | <style> |
| 245 | .vap-uc-text-green{ |
| 246 | color: green; |
| 247 | font-weight: bold; |
| 248 | } |
| 249 | |
| 250 | .vap-uc-text-red{ |
| 251 | color: red; |
| 252 | font-weight: bold; |
| 253 | } |
| 254 | </style> |
| 255 | |
| 256 | <?php |
| 257 | JText::script('VAPFILTERSELECTFILE'); |
| 258 | JText::script('VAP_AJAX_GENERIC_ERROR'); |
| 259 | ?> |
| 260 | |
| 261 | <script> |
| 262 | |
| 263 | jQuery(function($) { |
| 264 | $('#smsapiselect').select2({ |
| 265 | placeholder: Joomla.JText._('VAPFILTERSELECTFILE'), |
| 266 | allowClear: true, |
| 267 | width: 300, |
| 268 | }); |
| 269 | |
| 270 | $('#smsapiselect').on('change', function() { |
| 271 | var driver = $(this).val(); |
| 272 | |
| 273 | // destroy select2 |
| 274 | $('#vap-smsapi-params-table select').select2('destroy'); |
| 275 | |
| 276 | $('#vap-smsapi-params-table').html(''); |
| 277 | |
| 278 | if (!driver) { |
| 279 | // no driver selected, display message |
| 280 | $('#vap-smsapi-params-table').html($('#smsapi-no-params').html()); |
| 281 | return false; |
| 282 | } |
| 283 | |
| 284 | UIAjax.do( |
| 285 | '<?php echo $vik->ajaxUrl('index.php?option=com_vikappointments&task=configsmsapi.driverfields'); ?>', |
| 286 | { |
| 287 | driver: driver, |
| 288 | }, |
| 289 | function(resp) { |
| 290 | $('#vap-smsapi-params-table').html(resp); |
| 291 | |
| 292 | // render select |
| 293 | $('#vap-smsapi-params-table select').each(function() { |
| 294 | $(this).select2({ |
| 295 | // disable search for select with 3 or lower options |
| 296 | minimumResultsForSearch: $(this).find('option').length > 3 ? 0 : -1, |
| 297 | allowClear: false, |
| 298 | width: 285, |
| 299 | }); |
| 300 | }); |
| 301 | |
| 302 | // init helpers |
| 303 | $('#vap-smsapi-params-table .vap-quest-popover').popover({sanitize: false, container: 'body', trigger: 'hover', html: true}); |
| 304 | |
| 305 | $('#vap-smsapi-params-table').trigger('smsapi.load'); |
| 306 | }, |
| 307 | function(error) { |
| 308 | // display connection error message |
| 309 | $('#vap-smsapi-params-table').html($('#smsapi-connection-err').html()); |
| 310 | } |
| 311 | ); |
| 312 | }); |
| 313 | |
| 314 | <?php |
| 315 | if (!empty($params['smsapi'])) |
| 316 | { |
| 317 | ?>$('#smsapiselect').trigger('change');<?php |
| 318 | } |
| 319 | ?> |
| 320 | |
| 321 | $('#estimate-credit-btn').on('click', () => { |
| 322 | UIAjax.do( |
| 323 | '<?php echo $vik->ajaxUrl('index.php?option=com_vikappointments&task=configsmsapi.apicredit'); ?>', |
| 324 | { |
| 325 | driver: '<?php echo $params['smsapi']; ?>', |
| 326 | phone: $('input[name="smsapiadminphone"]').intlTelInput('getNumber'), |
| 327 | }, |
| 328 | (credit) => { |
| 329 | credit = parseFloat(credit); |
| 330 | |
| 331 | if (isNaN(credit)) { |
| 332 | credit = 0; |
| 333 | } |
| 334 | |
| 335 | if (credit > 0) { |
| 336 | $('#usercreditsp').addClass('vap-uc-text-green'); |
| 337 | $('#usercreditsp').removeClass('vap-uc-text-red'); |
| 338 | } else { |
| 339 | $('#usercreditsp').addClass('vap-uc-text-red'); |
| 340 | $('#usercreditsp').removeClass('vap-uc-text-green'); |
| 341 | } |
| 342 | |
| 343 | $('#usercreditsp').html(VAPCurrency.getInstance().format(credit)); |
| 344 | }, |
| 345 | function(error) { |
| 346 | if (!error.responseText) { |
| 347 | // use default connection lost error |
| 348 | error.responseText = Joomla.JText._('VAP_AJAX_GENERIC_ERROR'); |
| 349 | } |
| 350 | |
| 351 | $('#usercreditsp').html('/'); |
| 352 | |
| 353 | // raise error |
| 354 | alert(error.responseText); |
| 355 | } |
| 356 | ); |
| 357 | }); |
| 358 | }); |
| 359 | |
| 360 | function smsEnabledValueChanged(is) { |
| 361 | if (is) { |
| 362 | jQuery('.smsenabled-child').show(); |
| 363 | } else { |
| 364 | jQuery('.smsenabled-child').hide(); |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | </script> |
| 369 |