class-evf-field-address.php
1 year ago
class-evf-field-ai.php
1 year ago
class-evf-field-captcha.php
4 weeks ago
class-evf-field-checkbox.php
2 months ago
class-evf-field-color.php
4 weeks ago
class-evf-field-country.php
2 months ago
class-evf-field-credit-card.php
4 weeks ago
class-evf-field-date-time.php
4 weeks ago
class-evf-field-divider.php
2 years ago
class-evf-field-email.php
1 year ago
class-evf-field-file-upload.php
1 year ago
class-evf-field-first-name.php
1 year ago
class-evf-field-hcaptcha.php
4 months ago
class-evf-field-hidden.php
1 year ago
class-evf-field-html.php
9 months ago
class-evf-field-image-upload.php
1 year ago
class-evf-field-last-name.php
1 year ago
class-evf-field-likert.php
1 year ago
class-evf-field-lookup.php
4 weeks ago
class-evf-field-number.php
1 year ago
class-evf-field-password.php
4 weeks ago
class-evf-field-payment-authorize-net.php
4 weeks ago
class-evf-field-payment-checkbox.php
4 weeks ago
class-evf-field-payment-coupon.php
4 weeks ago
class-evf-field-payment-gateway-selector.php
4 weeks ago
class-evf-field-payment-quantity.php
4 weeks ago
class-evf-field-payment-radio.php
4 weeks ago
class-evf-field-payment-single.php
4 weeks ago
class-evf-field-payment-square.php
1 year ago
class-evf-field-payment-subscription-plan.php
4 weeks ago
class-evf-field-payment-subtotal.php
4 weeks ago
class-evf-field-payment-total.php
4 weeks ago
class-evf-field-phone.php
1 year ago
class-evf-field-privacy-policy.php
2 months ago
class-evf-field-private-note.php
1 year ago
class-evf-field-progress.php
4 weeks ago
class-evf-field-radio.php
2 months ago
class-evf-field-range-slider.php
4 weeks ago
class-evf-field-rating.php
2 months ago
class-evf-field-recaptcha.php
4 months ago
class-evf-field-repeater.php
4 weeks ago
class-evf-field-reset.php
4 weeks ago
class-evf-field-scale-rating.php
1 year ago
class-evf-field-select.php
1 year ago
class-evf-field-signature.php
4 weeks ago
class-evf-field-text.php
1 year ago
class-evf-field-textarea.php
1 year ago
class-evf-field-title.php
2 years ago
class-evf-field-turnstile.php
4 months ago
class-evf-field-url.php
1 year ago
class-evf-field-wysiwyg.php
2 months ago
class-evf-field-yes-no.php
1 year ago
payment-amount-helpers.php
4 weeks ago
class-evf-field-date-time.php
1190 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Date and Time field. |
| 4 | * |
| 5 | * @package EverestForms\Fields |
| 6 | * @since 1.0.0 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * EVF_Field_Date_Time class. |
| 13 | */ |
| 14 | class EVF_Field_Date_Time extends EVF_Form_Fields { |
| 15 | |
| 16 | /** |
| 17 | * Constructor. |
| 18 | */ |
| 19 | public function __construct() { |
| 20 | $this->name = esc_html__( 'Date / Time', 'everest-forms' ); |
| 21 | $this->type = 'date-time'; |
| 22 | $this->icon = 'evf-icon evf-icon-calendar'; |
| 23 | $this->order = 20; |
| 24 | $this->group = 'advanced'; |
| 25 | $this->settings = array( |
| 26 | 'basic-options' => array( |
| 27 | 'field_options' => array( |
| 28 | 'label', |
| 29 | 'choose_format', |
| 30 | 'choose_style', |
| 31 | 'description', |
| 32 | 'required', |
| 33 | 'required_field_message_setting', |
| 34 | 'required_field_message', |
| 35 | ), |
| 36 | ), |
| 37 | 'advanced-options' => array( |
| 38 | 'field_options' => array( |
| 39 | 'placeholder', |
| 40 | 'meta', |
| 41 | 'datetime_options', |
| 42 | 'label_hide', |
| 43 | 'css', |
| 44 | ), |
| 45 | ), |
| 46 | ); |
| 47 | |
| 48 | parent::__construct(); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Hook in tabs. |
| 53 | */ |
| 54 | public function init_hooks() { |
| 55 | add_action( 'everest_forms_shortcode_scripts', array( $this, 'load_assets' ) ); |
| 56 | add_filter( 'everest_forms_field_properties_' . $this->type, array( $this, 'field_properties' ), 5, 3 ); |
| 57 | add_filter( 'everest_forms_entry_save_fields', array( $this, 'save_timezone' ), 10, 3 ); |
| 58 | add_filter( 'everest_forms_html_field_value', array( $this, 'entry_html' ), 10, 5 ); |
| 59 | add_filter( 'everest_forms_date_time_properties', array( $this, 'set_default_timezone' ), 10, 2 ); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Date field format option. |
| 64 | * |
| 65 | * @since 1.4.9 |
| 66 | * @param array $field Field Data. |
| 67 | */ |
| 68 | public function choose_format( $field ) { |
| 69 | $format = ! empty( $field['datetime_format'] ) ? esc_attr( $field['datetime_format'] ) : 'date'; |
| 70 | $format_label = $this->field_element( |
| 71 | 'label', |
| 72 | $field, |
| 73 | array( |
| 74 | 'slug' => 'datetime_format', |
| 75 | 'value' => esc_html__( 'Format', 'everest-forms' ), |
| 76 | 'tooltip' => esc_html__( 'Select a format for the date field.', 'everest-forms' ), |
| 77 | ), |
| 78 | false |
| 79 | ); |
| 80 | $format_select = $this->field_element( |
| 81 | 'select', |
| 82 | $field, |
| 83 | array( |
| 84 | 'slug' => 'datetime_format', |
| 85 | 'value' => $format, |
| 86 | 'options' => array( |
| 87 | 'date' => esc_html__( 'Date', 'everest-forms' ), |
| 88 | 'time' => esc_html__( 'Time', 'everest-forms' ), |
| 89 | 'date-time' => esc_html__( 'Both', 'everest-forms' ), |
| 90 | ), |
| 91 | ), |
| 92 | false |
| 93 | ); |
| 94 | $args = array( |
| 95 | 'slug' => 'datetime_format', |
| 96 | 'content' => $format_label . $format_select, |
| 97 | ); |
| 98 | $this->field_element( 'row', $field, $args ); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Date field style option. |
| 103 | * |
| 104 | * @since 1.7.5 |
| 105 | * @param array $field Field Data. |
| 106 | */ |
| 107 | public function choose_style( $field ) { |
| 108 | $style = ! empty( $field['datetime_style'] ) ? esc_attr( $field['datetime_style'] ) : 'picker'; |
| 109 | $style_label = $this->field_element( |
| 110 | 'label', |
| 111 | $field, |
| 112 | array( |
| 113 | 'slug' => 'datetime_style', |
| 114 | 'value' => esc_html__( 'Style', 'everest-forms' ), |
| 115 | 'tooltip' => esc_html__( 'Select a style for the date field.', 'everest-forms' ), |
| 116 | ), |
| 117 | false |
| 118 | ); |
| 119 | $style_select = $this->field_element( |
| 120 | 'select', |
| 121 | $field, |
| 122 | array( |
| 123 | 'slug' => 'datetime_style', |
| 124 | 'value' => $style, |
| 125 | 'options' => array( |
| 126 | 'picker' => esc_html__( 'Picker', 'everest-forms' ), |
| 127 | 'dropdown' => esc_html__( 'Dropdown', 'everest-forms' ), |
| 128 | ), |
| 129 | ), |
| 130 | false |
| 131 | ); |
| 132 | $args = array( |
| 133 | 'slug' => 'datetime_style', |
| 134 | 'content' => $style_label . $style_select, |
| 135 | ); |
| 136 | $this->field_element( 'row', $field, $args ); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Date and time advanced field options. |
| 141 | * |
| 142 | * @since 1.4.9 |
| 143 | * @param array $field Field Data. |
| 144 | */ |
| 145 | public function datetime_options( $field ) { |
| 146 | $format = ! empty( $field['datetime_format'] ) ? esc_attr( $field['datetime_format'] ) : 'date'; |
| 147 | $class_name = isset( $field['enable_min_max'] ) && '1' === $field['enable_min_max'] ? '' : 'everest-forms-hidden'; |
| 148 | $field['date_mode'] = isset( $field['date_mode'] ) ? $field['date_mode'] : 'single'; |
| 149 | $field['date_mode'] = isset( $field['date_range'] ) && '1' === $field['date_range'] ? 'range' : $field['date_mode']; |
| 150 | |
| 151 | $this->field_element( |
| 152 | 'label', |
| 153 | $field, |
| 154 | array( |
| 155 | 'slug' => 'datetime_advanced', |
| 156 | 'value' => esc_html__( 'Date & Time Format', 'everest-forms' ), |
| 157 | 'tooltip' => esc_html__( 'Advanced date and time formatting options.', 'everest-forms' ), |
| 158 | ), |
| 159 | true |
| 160 | ); |
| 161 | |
| 162 | echo '<div class="format-selected-' . esc_attr( $format ) . ' format-selected">'; |
| 163 | echo '<div class="everest-forms-border-container everest-forms-date">'; |
| 164 | echo '<h4 class="everest-forms-border-container-title">' . esc_html__( 'Date', 'everest-forms' ) . '</h4>'; // phpcs:ignore WordPress.Security.NonceVerification |
| 165 | |
| 166 | $date_format_label = $this->field_element( |
| 167 | 'label', |
| 168 | $field, |
| 169 | array( |
| 170 | 'slug' => 'date_format', |
| 171 | 'value' => esc_html__( 'Date Format', 'everest-forms' ), |
| 172 | 'tooltip' => esc_html__( 'Choose a desire date format to display.', 'everest-forms' ), |
| 173 | ), |
| 174 | false |
| 175 | ); |
| 176 | |
| 177 | $date_format_types = array( |
| 178 | 'Y-m-d' => date_i18n( 'Y-m-d' ) . ' (Y-m-d)', |
| 179 | 'F j, Y' => date_i18n( 'F j, Y' ) . ' (F j, Y)', |
| 180 | 'm/d/Y' => date_i18n( 'm/d/Y' ) . ' (m/d/Y)', |
| 181 | 'd/m/Y' => date_i18n( 'd/m/Y' ) . ' (d/m/Y)', |
| 182 | 'Y.m.d' => date_i18n( 'Y.m.d' ) . ' (Y.m.d)', |
| 183 | 'F,Y' => date_i18n( 'F,Y' ) . ' (F,Y)', |
| 184 | 'm.d.y' => date_i18n( 'm.d.y' ) . ' (m.d.y)', |
| 185 | 'd.m.y' => date_i18n( 'd.m.y' ) . ' (d.m.y)', |
| 186 | 'd.m.y' => date_i18n( 'd.m.Y' ) . ' (d.m.Y)', |
| 187 | 'm-d-y' => date_i18n( 'm-d-y' ) . ' (m-d-y)', |
| 188 | ); |
| 189 | |
| 190 | /** |
| 191 | * Filter to modify the date format options. |
| 192 | * |
| 193 | * @since 3.2.2 |
| 194 | */ |
| 195 | $date_format_options = apply_filters( 'everest_forms_date_format_options', $date_format_types ); |
| 196 | $date_format_select = $this->field_element( |
| 197 | 'select', |
| 198 | $field, |
| 199 | array( |
| 200 | 'slug' => 'date_format', |
| 201 | 'value' => isset( $field['date_format'] ) ? $field['date_format'] : 'Y-m-d', |
| 202 | 'class' => 'evf-date-format', |
| 203 | 'options' => $date_format_options, |
| 204 | ), |
| 205 | false |
| 206 | ); |
| 207 | |
| 208 | // Disable certain dates option. |
| 209 | $clear_disabled_dates_button = sprintf( '<a href="#" class="evf-clear-disabled-dates after-label-description">%s</a>', esc_html__( 'Clear', 'everest-forms' ) ); |
| 210 | $disable_dates_label = $this->field_element( |
| 211 | 'label', |
| 212 | $field, |
| 213 | array( |
| 214 | 'slug' => 'disable_dates', |
| 215 | 'value' => esc_html__( 'Disable Dates', 'everest-forms' ), |
| 216 | 'tooltip' => esc_html__( 'Select which dates you want to disable.', 'everest-forms' ), |
| 217 | 'after_tooltip' => $clear_disabled_dates_button, |
| 218 | ), |
| 219 | false |
| 220 | ); |
| 221 | $disable_dates = $this->field_element( |
| 222 | 'text', |
| 223 | $field, |
| 224 | array( |
| 225 | 'slug' => 'disable_dates', |
| 226 | 'value' => isset( $field['disable_dates'] ) ? $field['disable_dates'] : '', |
| 227 | 'class' => 'everest-forms-disable-dates', |
| 228 | 'data' => array( |
| 229 | 'date-format' => isset( $field['date_format'] ) ? $field['date_format'] : 'Y-m-d', |
| 230 | ), |
| 231 | ), |
| 232 | false |
| 233 | ); |
| 234 | |
| 235 | $current_date_mode = $this->field_element( |
| 236 | 'radio', |
| 237 | $field, |
| 238 | array( |
| 239 | 'slug' => 'date_mode', |
| 240 | 'default' => isset( $field['date_mode'] ) ? $field['date_mode'] : 'single', |
| 241 | 'desc' => esc_html__( 'Date Mode', 'everest-forms' ), |
| 242 | 'tooltip' => esc_html__( 'Select your desire date mode.', 'everest-forms' ), |
| 243 | 'options' => array( |
| 244 | 'single' => 'Single', |
| 245 | 'range' => 'Range', |
| 246 | 'multiple' => 'Multiple', |
| 247 | ), |
| 248 | ), |
| 249 | false |
| 250 | ); |
| 251 | |
| 252 | $date_localization_label = $this->field_element( |
| 253 | 'label', |
| 254 | $field, |
| 255 | array( |
| 256 | 'slug' => 'date_localization', |
| 257 | 'value' => esc_html__( 'Date Localization', 'everest-forms' ), |
| 258 | 'tooltip' => esc_html__( 'Choose a desire date localization to display.', 'everest-forms' ), |
| 259 | ), |
| 260 | false |
| 261 | ); |
| 262 | |
| 263 | $date_localization_select = $this->field_element( |
| 264 | 'select', |
| 265 | $field, |
| 266 | array( |
| 267 | 'slug' => 'date_localization', |
| 268 | 'value' => isset( $field['date_localization'] ) ? $field['date_localization'] : 'en', |
| 269 | 'options' => array( |
| 270 | 'en' => 'English', |
| 271 | 'ar' => 'Arabic', |
| 272 | 'at' => 'Austria', |
| 273 | 'az' => 'Azerbaijan', |
| 274 | 'be' => 'Belarusian', |
| 275 | 'bg' => 'Bulgarian', |
| 276 | 'bn' => 'Bangla', |
| 277 | 'bs' => 'Bosnian', |
| 278 | 'cat' => 'Catalan', |
| 279 | 'cs' => 'Czech', |
| 280 | 'cy' => 'Welsh', |
| 281 | 'da' => 'Danish', |
| 282 | 'de' => 'German', |
| 283 | 'eo' => 'Esperanto', |
| 284 | 'es' => 'Spanish', |
| 285 | 'et' => 'Estonian', |
| 286 | 'fa' => 'Persian', |
| 287 | 'fi' => 'Finnish', |
| 288 | 'fo' => 'Faroese', |
| 289 | 'fr' => 'French', |
| 290 | 'ga' => 'Irish', |
| 291 | 'gr' => 'Greek', |
| 292 | 'he' => 'Hebrew', |
| 293 | 'hi' => 'Hindi', |
| 294 | 'hr' => 'Croatian', |
| 295 | 'hu' => 'Hungarian', |
| 296 | 'id' => 'Indonesian', |
| 297 | 'is' => 'Icelandic', |
| 298 | 'it' => 'Italian', |
| 299 | 'ja' => 'Japanese', |
| 300 | 'ka' => 'Georgian', |
| 301 | 'ko' => 'Korean', |
| 302 | 'km' => 'Khmer', |
| 303 | 'kz' => 'Kazakh', |
| 304 | 'lt' => 'Lithuanian', |
| 305 | 'lv' => 'Latvian', |
| 306 | 'mk' => 'Macedonian', |
| 307 | 'mn' => 'Mongolian', |
| 308 | 'ms' => 'Malaysian', |
| 309 | 'my' => 'Burmese', |
| 310 | 'nl' => 'Dutch', |
| 311 | 'no' => 'Norwegian', |
| 312 | 'pa' => 'Punjabi', |
| 313 | 'pl' => 'Polish', |
| 314 | 'pt' => 'Portuguese', |
| 315 | 'ro' => 'Romanian', |
| 316 | 'ru' => 'Russian', |
| 317 | 'si' => 'Sinhala', |
| 318 | 'sk' => 'Slovak', |
| 319 | 'sl' => 'Slovenian', |
| 320 | 'sq' => 'Albanian', |
| 321 | 'sr' => 'Serbian', |
| 322 | 'sv' => 'Swedish', |
| 323 | 'th' => 'Thai', |
| 324 | 'tr' => 'Turkish', |
| 325 | 'uk' => 'Ukrainian', |
| 326 | 'vn' => 'Vietnamese', |
| 327 | 'zh' => 'Mandarin', |
| 328 | 'zh_tw' => 'MandarinTraditional', |
| 329 | ), |
| 330 | ), |
| 331 | false |
| 332 | ); |
| 333 | |
| 334 | $date_timezone_label = $this->field_element( |
| 335 | 'label', |
| 336 | $field, |
| 337 | array( |
| 338 | 'slug' => 'date_timezone', |
| 339 | 'value' => esc_html__( 'Timezone', 'everest-forms' ), |
| 340 | 'tooltip' => esc_html__( 'Choose a desired timezone to save datetime in.', 'everest-forms' ), |
| 341 | ), |
| 342 | false |
| 343 | ); |
| 344 | |
| 345 | $date_timezone_select = $this->field_element( |
| 346 | 'select', |
| 347 | $field, |
| 348 | array( |
| 349 | 'slug' => 'date_timezone', |
| 350 | 'value' => isset( $field['date_timezone'] ) ? $field['date_timezone'] : '', |
| 351 | 'options' => $this->get_timezones(), |
| 352 | ), |
| 353 | false |
| 354 | ); |
| 355 | |
| 356 | $current_date_default = $this->field_element( |
| 357 | 'toggle', |
| 358 | $field, |
| 359 | array( |
| 360 | 'slug' => 'date_default', |
| 361 | 'value' => isset( $field['date_default'] ) ? $field['date_default'] : '', |
| 362 | 'desc' => esc_html__( 'Default to current date.', 'everest-forms' ), |
| 363 | 'tooltip' => esc_html__( 'Check this option to set current date as default.', 'everest-forms' ), |
| 364 | ), |
| 365 | false |
| 366 | ); |
| 367 | |
| 368 | $enable_past_date_disable = $this->field_element( |
| 369 | 'toggle', |
| 370 | $field, |
| 371 | array( |
| 372 | 'slug' => 'past_date_disable', |
| 373 | 'value' => isset( $field['past_date_disable'] ) ? $field['past_date_disable'] : '', |
| 374 | 'desc' => esc_html__( 'Disable the past date', 'everest-forms' ), |
| 375 | 'tooltip' => esc_html__( 'Check this option to disable the past date', 'everest-forms' ), |
| 376 | ), |
| 377 | false |
| 378 | ); |
| 379 | |
| 380 | $enable_min_max = $this->field_element( |
| 381 | 'toggle', |
| 382 | $field, |
| 383 | array( |
| 384 | 'slug' => 'enable_min_max', |
| 385 | 'value' => isset( $field['enable_min_max'] ) ? $field['enable_min_max'] : '', |
| 386 | 'desc' => esc_html__( 'Enable Min Max date.', 'everest-forms' ), |
| 387 | 'tooltip' => esc_html__( 'Check this option to set min max date.', 'everest-forms' ), |
| 388 | ), |
| 389 | false |
| 390 | ); |
| 391 | |
| 392 | $min_date_label = $this->field_element( |
| 393 | 'label', |
| 394 | $field, |
| 395 | array( |
| 396 | 'slug' => 'min_date', |
| 397 | 'value' => esc_html__( 'Minimum Date', 'everest-forms' ), |
| 398 | 'tooltip' => esc_html__( 'Select minium date.', 'everest-forms' ), |
| 399 | ), |
| 400 | false |
| 401 | ); |
| 402 | |
| 403 | $min_date = $this->field_element( |
| 404 | 'text', |
| 405 | $field, |
| 406 | array( |
| 407 | 'slug' => 'min_date', |
| 408 | 'value' => isset( $field['min_date'] ) ? $field['min_date'] : '', |
| 409 | 'class' => 'everest-forms-min-date', |
| 410 | ), |
| 411 | false |
| 412 | ); |
| 413 | |
| 414 | $max_date_label = $this->field_element( |
| 415 | 'label', |
| 416 | $field, |
| 417 | array( |
| 418 | 'slug' => 'max_date', |
| 419 | 'value' => esc_html__( 'Maximum Date', 'everest-forms' ), |
| 420 | 'tooltip' => esc_html__( 'Select maximum date.', 'everest-forms' ), |
| 421 | ), |
| 422 | false |
| 423 | ); |
| 424 | |
| 425 | $max_date = $this->field_element( |
| 426 | 'text', |
| 427 | $field, |
| 428 | array( |
| 429 | 'slug' => 'max_date', |
| 430 | 'value' => isset( $field['max_date'] ) ? $field['max_date'] : '', |
| 431 | 'class' => 'everest-forms-max-date', |
| 432 | ), |
| 433 | false |
| 434 | ); |
| 435 | |
| 436 | $set_date_range = $this->field_element( |
| 437 | 'toggle', |
| 438 | $field, |
| 439 | array( |
| 440 | 'slug' => 'set_date_range', |
| 441 | 'value' => isset( $field['set_date_range'] ) ? $field['set_date_range'] : '', |
| 442 | 'desc' => esc_html__( 'Enable Custom Input', 'everest-forms' ), |
| 443 | 'tooltip' => esc_html__( "Check this option to set date range 'x' days after today.", 'everest-forms' ), |
| 444 | ), |
| 445 | false |
| 446 | ); |
| 447 | |
| 448 | $min_date_range_level = $this->field_element( |
| 449 | 'label', |
| 450 | $field, |
| 451 | array( |
| 452 | 'slug' => 'min_date_range', |
| 453 | 'value' => esc_html__( 'Minimum Date', 'everest-forms' ), |
| 454 | 'tooltip' => esc_html__( 'Number of days after today or before for negative numbers. Example: today or +14 days or -5 days.', 'everest-forms' ), |
| 455 | ), |
| 456 | false |
| 457 | ); |
| 458 | |
| 459 | $min_date_range = $this->field_element( |
| 460 | 'text', |
| 461 | $field, |
| 462 | array( |
| 463 | 'slug' => 'min_date_range', |
| 464 | 'value' => isset( $field['min_date_range'] ) ? $field['min_date_range'] : '', |
| 465 | 'class' => 'everest-forms-min-date-range', |
| 466 | 'placeholder' => 'e.g. today', |
| 467 | ), |
| 468 | false |
| 469 | ); |
| 470 | |
| 471 | $max_date_range_label = $this->field_element( |
| 472 | 'label', |
| 473 | $field, |
| 474 | array( |
| 475 | 'slug' => 'max_date_range', |
| 476 | 'value' => esc_html__( 'Maximum Date', 'everest-forms' ), |
| 477 | 'tooltip' => esc_html__( 'Number of days after today or before for negative numbers. Example: today or +14 days or -5 days.', 'everest-forms' ), |
| 478 | ), |
| 479 | false |
| 480 | ); |
| 481 | |
| 482 | $max_date_range = $this->field_element( |
| 483 | 'text', |
| 484 | $field, |
| 485 | array( |
| 486 | 'slug' => 'max_date_range', |
| 487 | 'value' => isset( $field['max_date_range'] ) ? $field['max_date_range'] : '', |
| 488 | 'class' => 'everest-forms-max-date-range', |
| 489 | 'placeholder' => 'e.g. +14 days', |
| 490 | ), |
| 491 | false |
| 492 | ); |
| 493 | |
| 494 | $args = array( |
| 495 | 'slug' => 'date_format', |
| 496 | 'content' => $date_format_label . $date_format_select . $disable_dates_label . $disable_dates . $date_localization_label . $date_localization_select . $date_timezone_label . $date_timezone_select . '<div class="everest-forms-checklist everest-forms-checklist-inline">' . $current_date_mode . '</div><div class="everest-forms-current-date-format">' . $current_date_default . '</div><div class="everest-forms-past-date-disable-format">' . $enable_past_date_disable . '</div><div class="everest-forms-min-max-date-format">' . $enable_min_max . '</div><div class="everest-forms-min-max-date-range-format ' . $class_name . '">' . $set_date_range . '</div><div class="everest-forms-min-max-date-option ' . $class_name . '">' . $min_date_label . $min_date . $max_date_label . $max_date . '</div><div class="everest-forms-min-max-date-range-option ' . $class_name . '">' . $min_date_range_level . $min_date_range . $max_date_range_label . $max_date_range . '</div>', |
| 497 | ); |
| 498 | $this->field_element( 'row', $field, $args ); |
| 499 | |
| 500 | echo '</div>'; |
| 501 | |
| 502 | echo '<div class="everest-forms-border-container everest-forms-time">'; |
| 503 | echo '<h4 class="everest-forms-border-container-title">' . esc_html__( 'Time', 'everest-forms' ) . '</h4>'; // phpcs:ignore WordPress.Security.NonceVerification |
| 504 | |
| 505 | $time_format_label = $this->field_element( |
| 506 | 'label', |
| 507 | $field, |
| 508 | array( |
| 509 | 'slug' => 'time_interval', |
| 510 | 'value' => esc_html__( 'Time interval and format', 'everest-forms' ), |
| 511 | 'tooltip' => esc_html__( 'Choose time interval and format to display.', 'everest-forms' ), |
| 512 | ), |
| 513 | false |
| 514 | ); |
| 515 | |
| 516 | $time_interval_select = '<div class="input-group-col-2">'; |
| 517 | $time_interval_select .= $this->field_element( |
| 518 | 'select', |
| 519 | $field, |
| 520 | array( |
| 521 | 'slug' => 'time_interval', |
| 522 | 'value' => isset( $field['time_interval'] ) ? $field['time_interval'] : '', |
| 523 | 'class' => 'time_interval', |
| 524 | 'options' => array( |
| 525 | '15' => esc_html__( '15 minutes', 'everest-forms' ), |
| 526 | '30' => esc_html__( '30 minutes', 'everest-forms' ), |
| 527 | '60' => esc_html__( '1 hour', 'everest-forms' ), |
| 528 | ), |
| 529 | ), |
| 530 | false |
| 531 | ); |
| 532 | $time_format_select = $this->field_element( |
| 533 | 'select', |
| 534 | $field, |
| 535 | array( |
| 536 | 'slug' => 'time_format', |
| 537 | 'value' => isset( $field['time_format'] ) ? $field['time_format'] : '', |
| 538 | 'class' => 'time_format', |
| 539 | 'options' => array( |
| 540 | 'g:i A' => esc_html__( '12 H', 'everest-forms' ), |
| 541 | 'H:i' => esc_html__( '24 H', 'everest-forms' ), |
| 542 | ), |
| 543 | ), |
| 544 | false |
| 545 | ); |
| 546 | $time_format_select .= '</div>'; |
| 547 | |
| 548 | $min_time_select = '<div class="input-group-col-2">'; |
| 549 | $min_time_select .= $this->field_element( |
| 550 | 'select', |
| 551 | $field, |
| 552 | array( |
| 553 | 'slug' => 'min_time_hour', |
| 554 | 'value' => isset( $field['min_time_hour'] ) ? $field['min_time_hour'] : 9, |
| 555 | 'class' => 'min_time_hour', |
| 556 | 'options' => $this->get_minute_hours( $field, 'hours' ), |
| 557 | ), |
| 558 | false |
| 559 | ); |
| 560 | $min_time_select .= $this->field_element( |
| 561 | 'select', |
| 562 | $field, |
| 563 | array( |
| 564 | 'slug' => 'min_time_minute', |
| 565 | 'value' => isset( $field['min_time_minute'] ) ? $field['min_time_minute'] : 30, |
| 566 | 'class' => 'min_time_minute', |
| 567 | 'options' => $this->get_minute_hours( $field, 'minutes' ), |
| 568 | ), |
| 569 | false |
| 570 | ); |
| 571 | $min_time_select .= '</div>'; |
| 572 | |
| 573 | $max_time_select = '<div class="input-group-col-2">'; |
| 574 | $max_time_select .= $this->field_element( |
| 575 | 'select', |
| 576 | $field, |
| 577 | array( |
| 578 | 'slug' => 'max_time_hour', |
| 579 | 'value' => isset( $field['max_time_hour'] ) ? $field['max_time_hour'] : 18, |
| 580 | 'class' => 'max_time_hour', |
| 581 | 'options' => $this->get_minute_hours( $field, 'hours' ), |
| 582 | ), |
| 583 | false |
| 584 | ); |
| 585 | $max_time_select .= $this->field_element( |
| 586 | 'select', |
| 587 | $field, |
| 588 | array( |
| 589 | 'slug' => 'max_time_minute', |
| 590 | 'value' => isset( $field['max_time_minute'] ) ? $field['max_time_minute'] : 30, |
| 591 | 'class' => 'max_time_minute', |
| 592 | 'options' => $this->get_minute_hours( $field, 'minutes' ), |
| 593 | ), |
| 594 | false |
| 595 | ); |
| 596 | $max_time_select .= '</div>'; |
| 597 | |
| 598 | $enable_min_max_time = '<div class="input-group-col-2">'; |
| 599 | |
| 600 | $enable_min_max_time .= $this->field_element( |
| 601 | 'toggle', |
| 602 | $field, |
| 603 | array( |
| 604 | 'slug' => 'enable_min_max_time', |
| 605 | 'value' => isset( $field['enable_min_max_time'] ) ? $field['enable_min_max_time'] : '', |
| 606 | 'desc' => esc_html__( 'Enable Min Max Time.', 'everest-forms' ), |
| 607 | 'tooltip' => esc_html__( 'Check this option to set min max time.', 'everest-forms' ), |
| 608 | ), |
| 609 | false |
| 610 | ); |
| 611 | $enable_min_max_time .= '</div>'; |
| 612 | |
| 613 | $select_min_time = $this->field_element( |
| 614 | 'label', |
| 615 | $field, |
| 616 | array( |
| 617 | 'slug' => 'select_min_time', |
| 618 | 'value' => esc_html__( 'Minimum Time', 'everest-forms' ), |
| 619 | 'tooltip' => esc_html__( 'Select minium time.', 'everest-forms' ), |
| 620 | ), |
| 621 | false |
| 622 | ); |
| 623 | |
| 624 | $select_max_time = $this->field_element( |
| 625 | 'label', |
| 626 | $field, |
| 627 | array( |
| 628 | 'slug' => 'select_max_time', |
| 629 | 'value' => esc_html__( 'Maximum Time', 'everest-forms' ), |
| 630 | 'tooltip' => esc_html__( 'Select maximum time.', 'everest-forms' ), |
| 631 | ), |
| 632 | false |
| 633 | ); |
| 634 | $args = array( |
| 635 | 'slug' => 'time_interval_format', |
| 636 | 'content' => $time_format_label . $time_interval_select . $time_format_select . $enable_min_max_time . $select_min_time . $min_time_select . $select_max_time . $max_time_select, |
| 637 | ); |
| 638 | $this->field_element( 'row', $field, $args ); |
| 639 | |
| 640 | echo '</div>'; |
| 641 | echo '<div class="everest-forms-border-container everest-forms-slot-booking">'; |
| 642 | echo '<h4 class="everest-forms-border-container-title">' . esc_html__( 'Slot Booking', 'everest-forms' ) . '</h4>'; // phpcs:ignore WordPress.Security.NonceVerification |
| 643 | |
| 644 | $slot_booking_toggle = $this->field_element( |
| 645 | 'toggle', |
| 646 | $field, |
| 647 | array( |
| 648 | 'slug' => 'slot_booking_advanced', |
| 649 | 'desc' => esc_html__( 'Enable Slot Booking', 'everest-forms' ), |
| 650 | 'value' => isset( $field['slot_booking_advanced'] ) ? $field['slot_booking_advanced'] : false, |
| 651 | 'tooltip' => esc_html__( 'Enable to use date/time field as slot booking.', 'everest-forms' ), |
| 652 | 'class' => 'slot-booking-advanced ', |
| 653 | 'default' => false, |
| 654 | ), |
| 655 | false |
| 656 | ); |
| 657 | |
| 658 | $args = array( |
| 659 | 'slug' => 'slot_booking_advanced_setting', |
| 660 | 'content' => $slot_booking_toggle, |
| 661 | ); |
| 662 | $this->field_element( 'row', $field, $args ); |
| 663 | echo '</div>'; |
| 664 | echo '</div>'; |
| 665 | } |
| 666 | |
| 667 | /** |
| 668 | * Time Hours/Minutes Provider. |
| 669 | * |
| 670 | * @since 1.7.5 |
| 671 | * @param mixed $field field data. |
| 672 | * @param string $required required type. |
| 673 | */ |
| 674 | public function get_minute_hours( $field, $required = 'hours' ) { |
| 675 | $required_array = array(); |
| 676 | if ( 'hours' === $required ) { |
| 677 | // Hours Array. |
| 678 | $period = ''; |
| 679 | for ( $i = 0; $i <= 23; $i++ ) { |
| 680 | if ( isset( $field['time_format'] ) && 'H:i' === $field['time_format'] ) { |
| 681 | $required_array [] = ( $i < 10 ? '0' . $i : $i ) . $period; |
| 682 | } else { |
| 683 | if ( $i < 12 ) { |
| 684 | $period = ' AM'; |
| 685 | } else { |
| 686 | $period = ' PM'; |
| 687 | } |
| 688 | $hour = $i; |
| 689 | if ( 0 === $i ) { |
| 690 | $hour = 12; |
| 691 | } |
| 692 | if ( $hour > 12 ) { |
| 693 | $hour = $i - 12; |
| 694 | } |
| 695 | $required_array [] = $hour . $period; |
| 696 | } |
| 697 | } |
| 698 | } else { |
| 699 | // Minutes Array. |
| 700 | for ( $i = 0; $i <= 59; $i++ ) { |
| 701 | $required_array [] = ( $i < 10 ) ? '0' . $i : $i; |
| 702 | } |
| 703 | } |
| 704 | return $required_array; |
| 705 | } |
| 706 | |
| 707 | /** |
| 708 | * Define additional field properties. |
| 709 | * |
| 710 | * @since 1.0.0 |
| 711 | * |
| 712 | * @param array $properties Field properties. |
| 713 | * @param array $field Field settings. |
| 714 | * @param array $form_data Form data and settings. |
| 715 | * |
| 716 | * @return array of additional field properties. |
| 717 | */ |
| 718 | public function field_properties( $properties, $field, $form_data ) { |
| 719 | // Input primary: data-time-interval. |
| 720 | if ( ! empty( $field['time_interval'] ) ) { |
| 721 | $properties['inputs']['primary']['attr']['data-time-interval'] = esc_attr( $field['time_interval'] ); |
| 722 | } |
| 723 | |
| 724 | // Input primary: Disabled dates data. |
| 725 | if ( ! empty( $field['disable_dates'] ) ) { |
| 726 | $properties['inputs']['primary']['attr']['data-disable-dates'] = esc_attr( $field['disable_dates'] ); |
| 727 | } |
| 728 | |
| 729 | // Input primary: Booked slot. |
| 730 | if ( isset( $field['slot_booking_advanced'] ) && evf_string_to_bool( $field['slot_booking_advanced'] ) ) { |
| 731 | $properties['inputs']['primary']['attr']['data-slot-booking'] = esc_attr( $field['slot_booking_advanced'] ); |
| 732 | $properties['inputs']['primary']['attr']['data-form-id'] = esc_attr( $form_data['id'] ); |
| 733 | } |
| 734 | |
| 735 | // Input primary: data-date-time. |
| 736 | if ( ! empty( $field['datetime_format'] ) ) { |
| 737 | $properties['inputs']['primary']['attr']['data-date-time'] = esc_attr( $field['datetime_format'] ); |
| 738 | |
| 739 | // Input primary: data-mode. |
| 740 | if ( 'time' !== $field['datetime_format'] ) { |
| 741 | if ( isset( $field['date_range'] ) && '1' === $field['date_range'] ) { |
| 742 | $properties['inputs']['primary']['attr']['data-mode'] = 'range'; |
| 743 | } else { |
| 744 | $properties['inputs']['primary']['attr']['data-mode'] = isset( $field['date_mode'] ) ? $field['date_mode'] : 'single'; |
| 745 | } |
| 746 | $properties['inputs']['primary']['attr']['data-locale'] = isset( $field['date_localization'] ) ? $field['date_localization'] : 'en'; |
| 747 | $properties['inputs']['primary']['attr']['data-min-date'] = isset( $field['enable_min_max'], $field['min_date'] ) && ! isset( $field['set_date_range'] ) ? $field['min_date'] : ''; |
| 748 | $properties['inputs']['primary']['attr']['data-max-date'] = isset( $field['enable_min_max'], $field['max_date'] ) && ! isset( $field['set_date_range'] ) ? $field['max_date'] : ''; |
| 749 | $properties['inputs']['primary']['attr']['data-min-date-range'] = isset( $field['set_date_range'], $field['enable_min_max'], $field['min_date_range'] ) ? $field['min_date_range'] : ''; |
| 750 | $properties['inputs']['primary']['attr']['data-max-date-range'] = isset( $field['set_date_range'], $field['enable_min_max'], $field['max_date_range'] ) ? $field['max_date_range'] : ''; |
| 751 | } |
| 752 | |
| 753 | if ( 'date' !== $field['datetime_format'] ) { |
| 754 | if ( isset( $field['enable_min_max_time'] ) ) { |
| 755 | $properties['inputs']['primary']['attr']['data-min-hour'] = isset( $field['min_time_hour'] ) ? $field['min_time_hour'] : ''; |
| 756 | $properties['inputs']['primary']['attr']['data-min-minute'] = isset( $field['min_time_minute'] ) ? $field['min_time_minute'] : ''; |
| 757 | $properties['inputs']['primary']['attr']['data-max-hour'] = isset( $field['max_time_hour'] ) ? $field['max_time_hour'] : ''; |
| 758 | $properties['inputs']['primary']['attr']['data-max-minute'] = isset( $field['max_time_minute'] ) ? $field['max_time_minute'] : ''; |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | // Input primary: data-date-format and value. |
| 763 | switch ( $field['datetime_format'] ) { |
| 764 | case 'date': |
| 765 | $properties['inputs']['primary']['attr']['value'] = isset( $field['date_default'] ) ? esc_attr( date_i18n( $field['date_format'] ) ) : ''; |
| 766 | $properties['inputs']['primary']['attr']['data-date-format'] = ! empty( $field['date_format'] ) ? str_replace( 'g:i A', 'h:i K', esc_attr( $field['date_format'] ) ) : ''; |
| 767 | $properties['inputs']['primary']['attr']['data-past-disable-date'] = isset( $field['past_date_disable'] ) ? esc_attr( date_i18n( $field['date_format'] ) ) : ''; |
| 768 | break; |
| 769 | case 'time': |
| 770 | $properties['inputs']['primary']['attr']['value'] = ''; |
| 771 | $properties['inputs']['primary']['attr']['data-date-format'] = ! empty( $field['time_format'] ) ? str_replace( 'g:i A', 'h:i K', esc_attr( $field['time_format'] ) ) : 'g:i A'; |
| 772 | break; |
| 773 | case 'date-time': |
| 774 | if ( ! empty( $field['time_format'] ) ) { |
| 775 | $date_format = esc_attr( $field['date_format'] ) . ' ' . esc_attr( $field['time_format'] ); |
| 776 | $properties['inputs']['primary']['attr']['value'] = isset( $field['date_default'] ) ? esc_attr( date_i18n( $date_format ) ) : ''; |
| 777 | $properties['inputs']['primary']['attr']['data-date-format'] = ! empty( $field['date_format'] ) ? str_replace( 'g:i A', 'h:i K', esc_attr( $date_format ) ) : ''; |
| 778 | $properties['inputs']['primary']['attr']['data-past-disable-date'] = isset( $field['past_date_disable'] ) ? esc_attr( date_i18n( $field['date_format'] ) ) : ''; |
| 779 | } else { |
| 780 | $date_format = esc_attr( $field['date_format'] ) . ' g:i A'; |
| 781 | $properties['inputs']['primary']['attr']['value'] = isset( $field['date_default'] ) ? esc_attr( date_i18n( $date_format ) ) : ''; |
| 782 | $properties['inputs']['primary']['attr']['data-date-format'] = ! empty( $field['date_format'] ) ? str_replace( 'g:i A', 'h:i K', esc_attr( $date_format ) ) : ''; |
| 783 | $properties['inputs']['primary']['attr']['data-past-disable-date'] = isset( $field['past_date_disable'] ) ? esc_attr( date_i18n( $field['date_format'] ) ) : ''; |
| 784 | } |
| 785 | break; |
| 786 | } |
| 787 | } |
| 788 | return apply_filters( 'everest_forms_date_time_properties', $properties, $field ); |
| 789 | } |
| 790 | |
| 791 | /** |
| 792 | * Field preview inside the builder. |
| 793 | * |
| 794 | * @since 1.0.0 |
| 795 | * |
| 796 | * @param array $field Field data and settings. |
| 797 | */ |
| 798 | public function field_preview( $field ) { |
| 799 | // Define data. |
| 800 | $placeholder = ! empty( $field['placeholder'] ) ? esc_attr( $field['placeholder'] ) : ''; |
| 801 | |
| 802 | // Label. |
| 803 | $this->field_preview_option( 'label', $field ); |
| 804 | |
| 805 | // Primary input. |
| 806 | echo '<input type="text" placeholder="' . esc_attr( $placeholder ) . '" class="widefat" disabled>'; |
| 807 | |
| 808 | // Description. |
| 809 | $this->field_preview_option( 'description', $field ); |
| 810 | } |
| 811 | |
| 812 | /** |
| 813 | * Field display on the form front-end. |
| 814 | * |
| 815 | * @since 1.0.0 |
| 816 | * |
| 817 | * @param array $field Field Data. |
| 818 | * @param array $field_atts Field attributes. |
| 819 | * @param array $form_data All Form Data. |
| 820 | */ |
| 821 | public function field_display( $field, $field_atts, $form_data ) { |
| 822 | // Define data. |
| 823 | $primary = $field['properties']['inputs']['primary']; |
| 824 | |
| 825 | $class = array_merge( array( 'flatpickr-field' ), $primary['class'] ); |
| 826 | |
| 827 | if ( ! array_key_exists( 'datetime_style', $field ) || 'picker' === $field['datetime_style'] ) { |
| 828 | $class = array_merge( array( 'flatpickr-field' ), $primary['class'] ); |
| 829 | // Primary field. |
| 830 | printf( |
| 831 | '<input type="text" %s %s >', |
| 832 | evf_html_attributes( $primary['id'], $class, $primary['data'], $primary['attr'] ), |
| 833 | esc_attr( $primary['required'] ) |
| 834 | ); |
| 835 | } else { |
| 836 | $class = array_merge( array( 'date-dropdown-field' ), $primary['class'] ); |
| 837 | echo '<div class="date-time-container">'; |
| 838 | |
| 839 | printf( |
| 840 | '<input type="text" %s %s >', |
| 841 | evf_html_attributes( $primary['id'], $class, $primary['data'], $primary['attr'] ), |
| 842 | esc_attr( $primary['required'] ) |
| 843 | ); |
| 844 | |
| 845 | if ( 'date-time' === $field['datetime_format'] || 'date' === $field['datetime_format'] ) { |
| 846 | $data_date_format = $primary['attr']['data-date-format']; |
| 847 | |
| 848 | if ( 'F j, Y' === $data_date_format || 'm/d/Y' === $data_date_format || 'F j, Y H:i' === $data_date_format || 'F j, Y h:i K' === $data_date_format || 'm/d/Y H:i' === $data_date_format || 'm/d/Y h:i K' === $data_date_format ) { |
| 849 | $this->get_month_html( $primary ); |
| 850 | $this->get_day_html( $primary ); |
| 851 | $this->get_year_html( $primary ); |
| 852 | } elseif ( 'd/m/Y' === $data_date_format || 'd/m/Y H:i' === $data_date_format || 'd/m/Y h:i K' === $data_date_format ) { |
| 853 | $this->get_day_html( $primary ); |
| 854 | $this->get_month_html( $primary ); |
| 855 | $this->get_year_html( $primary ); |
| 856 | } else { |
| 857 | $this->get_year_html( $primary ); |
| 858 | $this->get_month_html( $primary ); |
| 859 | $this->get_day_html( $primary ); |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | if ( 'date-time' === $field['datetime_format'] ) { |
| 864 | echo '<span class="date-time-space-filler"></span>'; |
| 865 | } |
| 866 | |
| 867 | if ( 'time' === $field['datetime_format'] || 'date-time' === $field['datetime_format'] ) { |
| 868 | |
| 869 | $min_hour = isset( $field['min_time_hour'], $field['enable_min_max_time'] ) ? $field['min_time_hour'] : 0; |
| 870 | $max_hour = isset( $field['min_time_hour'], $field['enable_min_max_time'] ) ? $field['max_time_hour'] : 23; |
| 871 | |
| 872 | // For Hours. |
| 873 | printf( |
| 874 | '<select value = "%s" %s>', |
| 875 | esc_attr( ( gmdate( 'H' ) >= $min_hour && ( gmdate( 'H' ) <= $max_hour ) ) ? gmdate( 'H' ) : $min_hour ), |
| 876 | evf_html_attributes( 'hour-select-' . esc_attr( $primary['id'] ) ) |
| 877 | ); |
| 878 | |
| 879 | for ( $i = $min_hour; $i <= $max_hour; $i++ ) { |
| 880 | printf( |
| 881 | '<option value="%s" %s>%s</option>', |
| 882 | esc_attr( $i ), |
| 883 | (int) gmdate( 'H' ) === $i ? 'selected' : '', |
| 884 | esc_html( $this->get_minute_hours( $field, 'hours' )[ $i ] ) |
| 885 | ); |
| 886 | } |
| 887 | |
| 888 | echo '</select>'; |
| 889 | |
| 890 | $time_interval = isset( $field['time_interval'] ) ? $field['time_interval'] : 1; |
| 891 | |
| 892 | // For Minutes. |
| 893 | printf( |
| 894 | '<select %s>', |
| 895 | evf_html_attributes( 'minute-select-' . esc_attr( $primary['id'] ) ) |
| 896 | ); |
| 897 | echo '</select>'; |
| 898 | } |
| 899 | |
| 900 | echo '</div>'; |
| 901 | } |
| 902 | } |
| 903 | |
| 904 | /** |
| 905 | * Register/queue frontend scripts. |
| 906 | * |
| 907 | * @param array $atts Shortcode attributes. |
| 908 | */ |
| 909 | public static function load_assets( $atts ) { |
| 910 | $form_id = isset( $atts['id'] ) ? wp_unslash( $atts['id'] ) : ''; // WPCS: CSRF ok, input var ok, sanitization ok. |
| 911 | $form_obj = evf()->form->get( $form_id ); |
| 912 | $form_data = ! empty( $form_obj->post_content ) ? evf_decode( $form_obj->post_content ) : ''; |
| 913 | |
| 914 | if ( ! empty( $form_data['form_fields'] ) ) { |
| 915 | $data_i10ns = array(); |
| 916 | foreach ( $form_data['form_fields'] as $form_field ) { |
| 917 | if ( 'date-time' === $form_field['type'] && isset( $form_field['datetime_style'] ) && 'picker' === $form_field['datetime_style'] ) { |
| 918 | $data_i10n = isset( $form_field['date_localization'] ) ? $form_field['date_localization'] : 'en'; |
| 919 | |
| 920 | if ( ! in_array( $data_i10n, $data_i10ns, true ) && 'en' !== $data_i10n ) { |
| 921 | $data_i10ns[] = $data_i10n; |
| 922 | } |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | if ( ! empty( $data_i10ns ) ) { |
| 927 | foreach ( $data_i10ns as $data_i10n ) { |
| 928 | if ( wp_script_is( 'flatpickr' ) ) { |
| 929 | wp_enqueue_script( 'flatpickr-localization-' . $data_i10n, evf()->plugin_url() . '/assets/js/flatpickr/dist/I10n/' . $data_i10n . '.js', array(), EVF_VERSION, true ); |
| 930 | } |
| 931 | } |
| 932 | } |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | /** |
| 937 | * Print HTML for year. |
| 938 | * |
| 939 | * @param array $primary Primary. |
| 940 | * @return void |
| 941 | */ |
| 942 | private function get_year_html( $primary ) { |
| 943 | // For Years. |
| 944 | printf( |
| 945 | '<select value="%s" %s >', |
| 946 | esc_attr( gmdate( 'Y' ) ), |
| 947 | evf_html_attributes( 'year-select-' . esc_attr( $primary['id'] ) ) |
| 948 | ); |
| 949 | // Build the select options. |
| 950 | $end_date = gmdate( 'Y' ) + 100; |
| 951 | $start_date = $end_date - 200; |
| 952 | |
| 953 | for ( $i = $end_date; $i >= $start_date; $i-- ) { |
| 954 | printf( |
| 955 | '<option value="%s" %s>%s</option>', |
| 956 | esc_attr( $i ), |
| 957 | (int) gmdate( 'Y' ) === $i ? 'selected' : '', |
| 958 | esc_html( $i ) |
| 959 | ); |
| 960 | } |
| 961 | echo '</select>'; |
| 962 | } |
| 963 | |
| 964 | /** |
| 965 | * Print HTML for month. |
| 966 | * |
| 967 | * @param array $primary Primary. |
| 968 | * @return void |
| 969 | */ |
| 970 | private function get_month_html( $primary ) { |
| 971 | // For Months. |
| 972 | printf( |
| 973 | '<select value="%s" %s >', |
| 974 | esc_attr( gmdate( 'm' ) ), |
| 975 | evf_html_attributes( 'month-select-' . esc_attr( $primary['id'] ) ) |
| 976 | ); |
| 977 | // Build the select options. |
| 978 | for ( $i = 1; $i <= 12; $i++ ) { |
| 979 | $month = ( $i < 10 ) ? '0' . $i : $i; |
| 980 | printf( |
| 981 | '<option value="%s" %s>%s</option>', |
| 982 | esc_attr( $i ), |
| 983 | (int) gmdate( 'm' ) === $i ? 'selected' : '', |
| 984 | esc_html( $month ) |
| 985 | ); |
| 986 | } |
| 987 | echo '</select>'; |
| 988 | } |
| 989 | |
| 990 | /** |
| 991 | * Print HTML for day. |
| 992 | * |
| 993 | * @param array $primary Primary. |
| 994 | * @return void |
| 995 | */ |
| 996 | private function get_day_html( $primary ) { |
| 997 | // For Days. |
| 998 | printf( |
| 999 | '<select value="%s" %s >', |
| 1000 | esc_attr( gmdate( 'd' ) ), |
| 1001 | evf_html_attributes( 'day-select-' . esc_attr( $primary['id'] ) ) |
| 1002 | ); |
| 1003 | // Build the select options. |
| 1004 | for ( $i = 1; $i <= 32; $i++ ) { |
| 1005 | $day = $i < 10 ? '0' . $i : $i; |
| 1006 | printf( |
| 1007 | '<option value="%s" %s>%s</option>', |
| 1008 | esc_attr( $i ), |
| 1009 | (int) gmdate( 'd' ) === $i ? 'selected' : '', |
| 1010 | esc_html( $day ) |
| 1011 | ); |
| 1012 | } |
| 1013 | echo '</select>'; |
| 1014 | } |
| 1015 | |
| 1016 | |
| 1017 | |
| 1018 | /** |
| 1019 | * Returns a list of all timezones. |
| 1020 | */ |
| 1021 | public function get_timezones() { |
| 1022 | |
| 1023 | $utc_timezone = new DateTimeZone( 'UTC' ); |
| 1024 | $timezones = DateTimeZone::listIdentifiers(); |
| 1025 | $timezones_array = array( |
| 1026 | 'Default' => 'Default', |
| 1027 | ); |
| 1028 | |
| 1029 | foreach ( $timezones as $timezone ) { |
| 1030 | try { |
| 1031 | $dtz = new DateTimeZone( $timezone ); |
| 1032 | } catch ( Exception $e ) { |
| 1033 | // Skip identifiers that the system timezone database does not recognize. |
| 1034 | continue; |
| 1035 | } |
| 1036 | $offset = $dtz->getOffset( new DateTime( 'now', $utc_timezone ) ); |
| 1037 | |
| 1038 | $offset_hours = abs( intval( $offset / 3600 ) ); |
| 1039 | $offset_minutes = abs( intval( ( $offset % 3600 ) / 60 ) ); |
| 1040 | $offset_sign = ( $offset < 0 ) ? '-' : '+'; |
| 1041 | |
| 1042 | $offset_string = sprintf( '%s%02d:%02d', $offset_sign, $offset_hours, $offset_minutes ); |
| 1043 | |
| 1044 | $timezone_parts = explode( '/', $timezone ); |
| 1045 | $timezone_parts = implode( '/', array_reverse( $timezone_parts ) ); |
| 1046 | |
| 1047 | $timezones_array[ $timezone ] = $timezone_parts . " ($offset_string)"; |
| 1048 | } |
| 1049 | |
| 1050 | return $timezones_array; |
| 1051 | } |
| 1052 | |
| 1053 | |
| 1054 | |
| 1055 | /** |
| 1056 | * Save timezone data for datetime field. |
| 1057 | * |
| 1058 | * @param [array] $field Field. |
| 1059 | * @param [array] $form_data Form Data. |
| 1060 | * @param [int] $entry_id Entry Id. |
| 1061 | * @return array |
| 1062 | */ |
| 1063 | public function save_timezone( $field, $form_data, $entry_id ) { |
| 1064 | global $wpdb; |
| 1065 | |
| 1066 | $field_id = isset( $field['id'] ) ? $field['id'] : 0; |
| 1067 | |
| 1068 | if ( $field_id ) { |
| 1069 | $fields_settings = $form_data['form_fields']; |
| 1070 | $field_settings = isset( $fields_settings[ $field_id ] ) ? $fields_settings[ $field_id ] : array(); |
| 1071 | |
| 1072 | if ( ! empty( $field_settings ) && isset( $field_settings['date_timezone'] ) ) { |
| 1073 | |
| 1074 | $date_timezone = $field_settings['date_timezone']; |
| 1075 | |
| 1076 | if ( ! empty( $date_timezone ) && 'Default' !== $date_timezone ) { |
| 1077 | |
| 1078 | $entry_metadata = array( |
| 1079 | 'entry_id' => $entry_id, |
| 1080 | 'meta_key' => sanitize_key( $field_settings['meta-key'] . '_timezone' ), |
| 1081 | 'meta_value' => maybe_serialize( $date_timezone ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value |
| 1082 | ); |
| 1083 | |
| 1084 | // Insert entry meta. |
| 1085 | $wpdb->insert( $wpdb->prefix . 'evf_entrymeta', $entry_metadata ); |
| 1086 | } |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | return $field; |
| 1091 | } |
| 1092 | |
| 1093 | |
| 1094 | |
| 1095 | /** |
| 1096 | * Adds Timezone for datetime column in entries table if available. |
| 1097 | * |
| 1098 | * @param [string] $value Value. |
| 1099 | * @param [string] $entry_meta Entry Meta. |
| 1100 | * @param [array] $entry Entry. |
| 1101 | * @param [string] $type Type. |
| 1102 | * @param [string] $meta_key Meta Key. |
| 1103 | * |
| 1104 | * @return string |
| 1105 | */ |
| 1106 | public function entry_html( $value, $entry_meta, $entry, $type, $meta_key = '' ) { |
| 1107 | $field_metas = isset( $entry->meta ) && is_array( $entry->meta ) ? $entry->meta : array(); |
| 1108 | |
| 1109 | $timezone_key = isset( $meta_key['meta_key'] ) |
| 1110 | ? sanitize_key( $meta_key['meta_key'] ) . '_timezone' |
| 1111 | : sanitize_key( (string) $meta_key ) . '_timezone'; |
| 1112 | |
| 1113 | if ( isset( $meta_key['meta_key'], $field_metas[ $timezone_key ] ) && ! empty( $meta_key['meta_key'] ) ) { |
| 1114 | $timezone_value = sanitize_text_field( wp_unslash( (string) $field_metas[ $timezone_key ] ) ); |
| 1115 | $all_timezones = $this->get_timezones(); |
| 1116 | |
| 1117 | if ( is_array( $all_timezones ) && isset( $all_timezones[ $timezone_value ] ) ) { |
| 1118 | $value .= '<p>' . esc_html( $all_timezones[ $timezone_value ] ) . '</p>'; |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | return $value; |
| 1123 | } |
| 1124 | |
| 1125 | |
| 1126 | |
| 1127 | /** |
| 1128 | * Set default date time in frontend if timezone set. |
| 1129 | * |
| 1130 | * @param [array] $properties Properties array. |
| 1131 | * @param [array] $field Field properties. |
| 1132 | * @return array |
| 1133 | */ |
| 1134 | public function set_default_timezone( $properties, $field ) { |
| 1135 | // Does not set default date time if default date feature is not enabled.` |
| 1136 | if ( ! isset( $field['date_default'] ) || 1 !== absint( $field['date_default'] ) ) { |
| 1137 | return $properties; |
| 1138 | } |
| 1139 | |
| 1140 | if ( ! empty( $field['date_timezone'] ) && 'Default' !== $field['date_timezone'] ) { |
| 1141 | $timezone = $field['date_timezone']; |
| 1142 | |
| 1143 | if ( in_array( $timezone, timezone_identifiers_list(), true ) ) { |
| 1144 | |
| 1145 | $dtz = new DateTimeZone( $timezone ); |
| 1146 | $datetime = new DateTime( 'now', $dtz ); |
| 1147 | |
| 1148 | switch ( $field['datetime_format'] ) { |
| 1149 | case 'date': |
| 1150 | $properties['inputs']['primary']['attr']['value'] = esc_attr( $datetime->format( $field['date_format'] ) ); |
| 1151 | break; |
| 1152 | |
| 1153 | case 'date-time': |
| 1154 | if ( ! empty( $field['time_format'] ) ) { |
| 1155 | $date_format = esc_attr( $field['date_format'] ) . ' ' . esc_attr( $field['time_format'] ); |
| 1156 | $properties['inputs']['primary']['attr']['value'] = esc_attr( $datetime->format( $date_format ) ); |
| 1157 | } else { |
| 1158 | $date_format = esc_attr( $field['date_format'] ) . ' g:i A'; |
| 1159 | $properties['inputs']['primary']['attr']['value'] = esc_attr( $datetime->format( $date_format ) ); |
| 1160 | } |
| 1161 | break; |
| 1162 | } |
| 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | return $properties; |
| 1167 | } |
| 1168 | /** |
| 1169 | * Form's field list for google calendar. |
| 1170 | * |
| 1171 | * @param int $form_id form id. |
| 1172 | */ |
| 1173 | public static function get_form_fields( $form_id ) { |
| 1174 | $text_field_name_option_list = array( |
| 1175 | '' => __( '---Select Field---', 'everest-forms' ), |
| 1176 | ); |
| 1177 | if ( ! empty( $form_id ) && 'none' !== $form_id ) { |
| 1178 | $form = json_decode( get_post_field( 'post_content', $form_id ) ); |
| 1179 | $text_field = apply_filters( 'evf_support_field_type_for_google_event', array( 'first-name', 'last-name', 'text', 'textarea' ) ); |
| 1180 | $form_arr = isset( $form->form_fields ) ? (array) $form->form_fields : array(); |
| 1181 | foreach ( $form_arr as $key => $value ) { |
| 1182 | if ( in_array( $value->type, $text_field, true ) ) { |
| 1183 | $text_field_name_option_list[ $key ] = $value->label; |
| 1184 | } |
| 1185 | } |
| 1186 | } |
| 1187 | return $text_field_name_option_list; |
| 1188 | } |
| 1189 | } |
| 1190 |