PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 2.0.3
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v2.0.3
3.5.2 3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / includes / fields / class-evf-field-date-time.php
everest-forms / includes / fields Last commit date
class-evf-field-address.php 7 years ago class-evf-field-ai.php 2 years ago class-evf-field-captcha.php 2 years ago class-evf-field-checkbox.php 3 years ago class-evf-field-color.php 3 years ago class-evf-field-country.php 7 years ago class-evf-field-credit-card.php 2 years ago class-evf-field-date-time.php 2 years ago class-evf-field-divider.php 4 years ago class-evf-field-email.php 2 years ago class-evf-field-file-upload.php 6 years ago class-evf-field-first-name.php 2 years ago class-evf-field-hidden.php 7 years ago class-evf-field-html.php 7 years ago class-evf-field-image-upload.php 7 years ago class-evf-field-last-name.php 2 years ago class-evf-field-likert.php 2 years ago class-evf-field-lookup.php 2 years ago class-evf-field-number.php 2 years ago class-evf-field-password.php 7 years ago class-evf-field-payment-authorize-net.php 2 years ago class-evf-field-payment-checkbox.php 7 years ago class-evf-field-payment-coupon.php 2 years ago class-evf-field-payment-quantity.php 5 years ago class-evf-field-payment-radio.php 7 years ago class-evf-field-payment-single.php 7 years ago class-evf-field-payment-subtotal.php 3 years ago class-evf-field-payment-total.php 6 years ago class-evf-field-phone.php 7 years ago class-evf-field-privacy-policy.php 4 years ago class-evf-field-progress.php 3 years ago class-evf-field-radio.php 3 years ago class-evf-field-range-slider.php 6 years ago class-evf-field-rating.php 7 years ago class-evf-field-repeater.php 2 years ago class-evf-field-reset.php 3 years ago class-evf-field-scale-rating.php 2 years ago class-evf-field-select.php 3 years ago class-evf-field-signature.php 7 years ago class-evf-field-text.php 2 years ago class-evf-field-textarea.php 3 years ago class-evf-field-title.php 6 years ago class-evf-field-url.php 2 years ago class-evf-field-wysiwyg.php 4 years ago class-evf-field-yes-no.php 2 years ago
class-evf-field-date-time.php
1137 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 'meta',
30 'choose_format',
31 'choose_style',
32 'description',
33 'required',
34 'required_field_message_setting',
35 'required_field_message',
36 ),
37 ),
38 'advanced-options' => array(
39 'field_options' => array(
40 'placeholder',
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_select = $this->field_element(
178 'select',
179 $field,
180 array(
181 'slug' => 'date_format',
182 'value' => isset( $field['date_format'] ) ? $field['date_format'] : 'Y-m-d',
183 'class' => 'evf-date-format',
184 'options' => array(
185 'Y-m-d' => date_i18n( 'Y-m-d' ) . ' (Y-m-d)',
186 'F j, Y' => date_i18n( 'F j, Y' ) . ' (F j, Y)',
187 'm/d/Y' => date_i18n( 'm/d/Y' ) . ' (m/d/Y)',
188 'd/m/Y' => date_i18n( 'd/m/Y' ) . ' (d/m/Y)',
189 ),
190 ),
191 false
192 );
193
194 // Disable certain dates option.
195 $clear_disabled_dates_button = sprintf( '<a href="#" class="evf-clear-disabled-dates after-label-description">%s</a>', esc_html__( 'Clear', 'everest-forms' ) );
196 $disable_dates_label = $this->field_element(
197 'label',
198 $field,
199 array(
200 'slug' => 'disable_dates',
201 'value' => esc_html__( 'Disable Dates', 'everest-forms' ),
202 'tooltip' => esc_html__( 'Select which dates you want to disable.', 'everest-forms' ),
203 'after_tooltip' => $clear_disabled_dates_button,
204 ),
205 false
206 );
207 $disable_dates = $this->field_element(
208 'text',
209 $field,
210 array(
211 'slug' => 'disable_dates',
212 'value' => isset( $field['disable_dates'] ) ? $field['disable_dates'] : '',
213 'class' => 'everest-forms-disable-dates',
214 'data' => array(
215 'date-format' => isset( $field['date_format'] ) ? $field['date_format'] : 'Y-m-d',
216 ),
217 ),
218 false
219 );
220
221 $current_date_mode = $this->field_element(
222 'radio',
223 $field,
224 array(
225 'slug' => 'date_mode',
226 'default' => isset( $field['date_mode'] ) ? $field['date_mode'] : 'single',
227 'desc' => esc_html__( 'Date Mode', 'everest-forms' ),
228 'tooltip' => esc_html__( 'Select your desire date mode.', 'everest-forms' ),
229 'options' => array(
230 'single' => 'Single',
231 'range' => 'Range',
232 'multiple' => 'Multiple',
233 ),
234 ),
235 false
236 );
237
238 $date_localization_label = $this->field_element(
239 'label',
240 $field,
241 array(
242 'slug' => 'date_localization',
243 'value' => esc_html__( 'Date Localization', 'everest-forms' ),
244 'tooltip' => esc_html__( 'Choose a desire date localization to display.', 'everest-forms' ),
245 ),
246 false
247 );
248
249 $date_localization_select = $this->field_element(
250 'select',
251 $field,
252 array(
253 'slug' => 'date_localization',
254 'value' => isset( $field['date_localization'] ) ? $field['date_localization'] : 'en',
255 'options' => array(
256 'en' => 'English',
257 'ar' => 'Arabic',
258 'at' => 'Austria',
259 'az' => 'Azerbaijan',
260 'be' => 'Belarusian',
261 'bg' => 'Bulgarian',
262 'bn' => 'Bangla',
263 'bs' => 'Bosnian',
264 'cat' => 'Catalan',
265 'cs' => 'Czech',
266 'cy' => 'Welsh',
267 'da' => 'Danish',
268 'de' => 'German',
269 'eo' => 'Esperanto',
270 'es' => 'Spanish',
271 'et' => 'Estonian',
272 'fa' => 'Persian',
273 'fi' => 'Finnish',
274 'fo' => 'Faroese',
275 'fr' => 'French',
276 'ga' => 'Irish',
277 'gr' => 'Greek',
278 'he' => 'Hebrew',
279 'hi' => 'Hindi',
280 'hr' => 'Croatian',
281 'hu' => 'Hungarian',
282 'id' => 'Indonesian',
283 'is' => 'Icelandic',
284 'it' => 'Italian',
285 'ja' => 'Japanese',
286 'ka' => 'Georgian',
287 'ko' => 'Korean',
288 'km' => 'Khmer',
289 'kz' => 'Kazakh',
290 'lt' => 'Lithuanian',
291 'lv' => 'Latvian',
292 'mk' => 'Macedonian',
293 'mn' => 'Mongolian',
294 'ms' => 'Malaysian',
295 'my' => 'Burmese',
296 'nl' => 'Dutch',
297 'no' => 'Norwegian',
298 'pa' => 'Punjabi',
299 'pl' => 'Polish',
300 'pt' => 'Portuguese',
301 'ro' => 'Romanian',
302 'ru' => 'Russian',
303 'si' => 'Sinhala',
304 'sk' => 'Slovak',
305 'sl' => 'Slovenian',
306 'sq' => 'Albanian',
307 'sr' => 'Serbian',
308 'sv' => 'Swedish',
309 'th' => 'Thai',
310 'tr' => 'Turkish',
311 'uk' => 'Ukrainian',
312 'vn' => 'Vietnamese',
313 'zh' => 'Mandarin',
314 'zh_tw' => 'MandarinTraditional',
315 ),
316 ),
317 false
318 );
319
320 $date_timezone_label = $this->field_element(
321 'label',
322 $field,
323 array(
324 'slug' => 'date_timezone',
325 'value' => esc_html__( 'Timezone', 'everest-forms' ),
326 'tooltip' => esc_html__( 'Choose a desired timezone to save datetime in.', 'everest-forms' ),
327 ),
328 false
329 );
330
331 $date_timezone_select = $this->field_element(
332 'select',
333 $field,
334 array(
335 'slug' => 'date_timezone',
336 'value' => isset( $field['date_timezone'] ) ? $field['date_timezone'] : '',
337 'options' => $this->get_timezones(),
338 ),
339 false
340 );
341
342 $current_date_default = $this->field_element(
343 'checkbox',
344 $field,
345 array(
346 'slug' => 'date_default',
347 'value' => isset( $field['date_default'] ) ? $field['date_default'] : '',
348 'desc' => esc_html__( 'Default to current date.', 'everest-forms' ),
349 'tooltip' => esc_html__( 'Check this option to set current date as default.', 'everest-forms' ),
350 ),
351 false
352 );
353
354 $enable_past_date_disable = $this->field_element(
355 'checkbox',
356 $field,
357 array(
358 'slug' => 'past_date_disable',
359 'value' => isset( $field['past_date_disable'] ) ? $field['past_date_disable'] : '',
360 'desc' => esc_html__( 'Disable the past date', 'everest-forms' ),
361 'tooltip' => esc_html__( 'Check this option to disable the past date', 'everest-forms' ),
362 ),
363 false
364 );
365
366 $enable_min_max = $this->field_element(
367 'checkbox',
368 $field,
369 array(
370 'slug' => 'enable_min_max',
371 'value' => isset( $field['enable_min_max'] ) ? $field['enable_min_max'] : '',
372 'desc' => esc_html__( 'Enable Min Max date.', 'everest-forms' ),
373 'tooltip' => esc_html__( 'Check this option to set min max date.', 'everest-forms' ),
374 ),
375 false
376 );
377
378 $slot_booking_toggle = $this->field_element(
379 'checkbox',
380 $field,
381 array(
382 'slug' => 'slot_booking_advanced',
383 'desc' => esc_html__( 'Slot Booking', 'everest-forms' ),
384 'value' => isset( $field['slot_booking_advanced'] ) ? $field['slot_booking_advanced'] : false,
385 'tooltip' => esc_html__( 'Enable to use date/time field as slot booking.', 'everest-forms' ),
386 'class' => 'slot-booking-advanced ',
387 'default' => false,
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 'checkbox',
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-slot-booking">' . $slot_booking_toggle . '</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 'checkbox',
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>';
642 }
643
644 /**
645 * Time Hours/Minutes Provider.
646 *
647 * @since 1.7.5
648 * @param mixed $field field data.
649 * @param string $required required type.
650 */
651 public function get_minute_hours( $field, $required = 'hours' ) {
652 $required_array = array();
653 if ( 'hours' === $required ) {
654 // Hours Array.
655 $period = '';
656 for ( $i = 0; $i <= 23; $i++ ) {
657 if ( isset( $field['time_format'] ) && 'H:i' === $field['time_format'] ) {
658 $required_array [] = ( $i < 10 ? '0' . $i : $i ) . $period;
659 } else {
660 if ( $i < 12 ) {
661 $period = ' AM';
662 } else {
663 $period = ' PM';
664 }
665 $hour = $i;
666 if ( 0 === $i ) {
667 $hour = 12;
668 }
669 if ( $hour > 12 ) {
670 $hour = $i - 12;
671 }
672 $required_array [] = $hour . $period;
673 }
674 }
675 } else {
676 // Minutes Array.
677 for ( $i = 0; $i <= 59; $i++ ) {
678 $required_array [] = ( $i < 10 ) ? '0' . $i : $i;
679 }
680 }
681 return $required_array;
682 }
683
684 /**
685 * Define additional field properties.
686 *
687 * @since 1.0.0
688 *
689 * @param array $properties Field properties.
690 * @param array $field Field settings.
691 * @param array $form_data Form data and settings.
692 *
693 * @return array of additional field properties.
694 */
695 public function field_properties( $properties, $field, $form_data ) {
696 // Input primary: data-time-interval.
697 if ( ! empty( $field['time_interval'] ) ) {
698 $properties['inputs']['primary']['attr']['data-time-interval'] = esc_attr( $field['time_interval'] );
699 }
700
701 // Input primary: Disabled dates data.
702 if ( ! empty( $field['disable_dates'] ) ) {
703 $properties['inputs']['primary']['attr']['data-disable-dates'] = esc_attr( $field['disable_dates'] );
704 }
705
706 // Input primary: Booked slot.
707 if ( isset( $field['slot_booking_advanced'] ) && evf_string_to_bool( $field['slot_booking_advanced'] ) ) {
708 $properties['inputs']['primary']['attr']['data-slot-booking'] = esc_attr( $field['slot_booking_advanced'] );
709 $properties['inputs']['primary']['attr']['data-form-id'] = esc_attr( $form_data['id'] );
710 }
711
712 // Input primary: data-date-time.
713 if ( ! empty( $field['datetime_format'] ) ) {
714 $properties['inputs']['primary']['attr']['data-date-time'] = esc_attr( $field['datetime_format'] );
715
716 // Input primary: data-mode.
717 if ( 'time' !== $field['datetime_format'] ) {
718 if ( isset( $field['date_range'] ) && '1' === $field['date_range'] ) {
719 $properties['inputs']['primary']['attr']['data-mode'] = 'range';
720 } else {
721 $properties['inputs']['primary']['attr']['data-mode'] = isset( $field['date_mode'] ) ? $field['date_mode'] : 'single';
722 }
723 $properties['inputs']['primary']['attr']['data-locale'] = isset( $field['date_localization'] ) ? $field['date_localization'] : 'en';
724 $properties['inputs']['primary']['attr']['data-min-date'] = isset( $field['enable_min_max'], $field['min_date'] ) && ! isset( $field['set_date_range'] ) ? $field['min_date'] : '';
725 $properties['inputs']['primary']['attr']['data-max-date'] = isset( $field['enable_min_max'], $field['max_date'] ) && ! isset( $field['set_date_range'] ) ? $field['max_date'] : '';
726 $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'] : '';
727 $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'] : '';
728 }
729
730 if ( 'date' !== $field['datetime_format'] ) {
731 if ( isset( $field['enable_min_max_time'] ) ) {
732 $properties['inputs']['primary']['attr']['data-min-hour'] = isset( $field['min_time_hour'] ) ? $field['min_time_hour'] : '';
733 $properties['inputs']['primary']['attr']['data-min-minute'] = isset( $field['min_time_minute'] ) ? $field['min_time_minute'] : '';
734 $properties['inputs']['primary']['attr']['data-max-hour'] = isset( $field['max_time_hour'] ) ? $field['max_time_hour'] : '';
735 $properties['inputs']['primary']['attr']['data-max-minute'] = isset( $field['max_time_minute'] ) ? $field['max_time_minute'] : '';
736 }
737 }
738
739 // Input primary: data-date-format and value.
740 switch ( $field['datetime_format'] ) {
741 case 'date':
742 $properties['inputs']['primary']['attr']['value'] = isset( $field['date_default'] ) ? esc_attr( date_i18n( $field['date_format'] ) ) : '';
743 $properties['inputs']['primary']['attr']['data-date-format'] = ! empty( $field['date_format'] ) ? str_replace( 'g:i A', 'h:i K', esc_attr( $field['date_format'] ) ) : '';
744 $properties['inputs']['primary']['attr']['data-past-disable-date'] = isset( $field['past_date_disable'] ) ? esc_attr( date_i18n( 'Y-m-d' ) ) : '';
745 break;
746 case 'time':
747 $properties['inputs']['primary']['attr']['value'] = '';
748 $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';
749 break;
750 case 'date-time':
751 if ( ! empty( $field['time_format'] ) ) {
752 $date_format = esc_attr( $field['date_format'] ) . ' ' . esc_attr( $field['time_format'] );
753 $properties['inputs']['primary']['attr']['value'] = isset( $field['date_default'] ) ? esc_attr( date_i18n( $date_format ) ) : '';
754 $properties['inputs']['primary']['attr']['data-date-format'] = ! empty( $field['date_format'] ) ? str_replace( 'g:i A', 'h:i K', esc_attr( $date_format ) ) : '';
755 $properties['inputs']['primary']['attr']['data-past-disable-date'] = isset( $field['past_date_disable'] ) ? esc_attr( date_i18n( 'Y-m-d' ) ) : '';
756 } else {
757 $date_format = esc_attr( $field['date_format'] ) . ' g:i A';
758 $properties['inputs']['primary']['attr']['value'] = isset( $field['date_default'] ) ? esc_attr( date_i18n( $date_format ) ) : '';
759 $properties['inputs']['primary']['attr']['data-date-format'] = ! empty( $field['date_format'] ) ? str_replace( 'g:i A', 'h:i K', esc_attr( $date_format ) ) : '';
760 $properties['inputs']['primary']['attr']['data-past-disable-date'] = isset( $field['past_date_disable'] ) ? esc_attr( date_i18n( 'Y-m-d' ) ) : '';
761 }
762 break;
763 }
764 }
765 return apply_filters( 'everest_forms_date_time_properties', $properties, $field );
766 }
767
768 /**
769 * Field preview inside the builder.
770 *
771 * @since 1.0.0
772 *
773 * @param array $field Field data and settings.
774 */
775 public function field_preview( $field ) {
776 // Define data.
777 $placeholder = ! empty( $field['placeholder'] ) ? esc_attr( $field['placeholder'] ) : '';
778
779 // Label.
780 $this->field_preview_option( 'label', $field );
781
782 // Primary input.
783 echo '<input type="text" placeholder="' . esc_attr( $placeholder ) . '" class="widefat" disabled>';
784
785 // Description.
786 $this->field_preview_option( 'description', $field );
787 }
788
789 /**
790 * Field display on the form front-end.
791 *
792 * @since 1.0.0
793 *
794 * @param array $field Field Data.
795 * @param array $field_atts Field attributes.
796 * @param array $form_data All Form Data.
797 */
798 public function field_display( $field, $field_atts, $form_data ) {
799 // Define data.
800 $primary = $field['properties']['inputs']['primary'];
801
802 $class = array_merge( array( 'flatpickr-field' ), $primary['class'] );
803
804 if ( ! array_key_exists( 'datetime_style', $field ) || 'picker' === $field['datetime_style'] ) {
805 $class = array_merge( array( 'flatpickr-field' ), $primary['class'] );
806 // Primary field.
807 printf(
808 '<input type="text" %s %s >',
809 evf_html_attributes( $primary['id'], $class, $primary['data'], $primary['attr'] ),
810 esc_attr( $primary['required'] )
811 );
812 } else {
813 $class = array_merge( array( 'date-dropdown-field' ), $primary['class'] );
814 echo '<div class="date-time-container">';
815
816 printf(
817 '<input type="text" %s %s >',
818 evf_html_attributes( $primary['id'], $class, $primary['data'], $primary['attr'] ),
819 esc_attr( $primary['required'] )
820 );
821
822 if ( 'date-time' === $field['datetime_format'] || 'date' === $field['datetime_format'] ) {
823 $data_date_format = $primary['attr']['data-date-format'];
824
825 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 ) {
826 $this->get_month_html( $primary );
827 $this->get_day_html( $primary );
828 $this->get_year_html( $primary );
829 } elseif ( 'd/m/Y' === $data_date_format || 'd/m/Y H:i' === $data_date_format || 'd/m/Y h:i K' === $data_date_format ) {
830 $this->get_day_html( $primary );
831 $this->get_month_html( $primary );
832 $this->get_year_html( $primary );
833 } else {
834 $this->get_year_html( $primary );
835 $this->get_month_html( $primary );
836 $this->get_day_html( $primary );
837 }
838 }
839
840 if ( 'date-time' === $field['datetime_format'] ) {
841 echo '<span class="date-time-space-filler"></span>';
842 }
843
844 if ( 'time' === $field['datetime_format'] || 'date-time' === $field['datetime_format'] ) {
845
846 $min_hour = isset( $field['min_time_hour'], $field['enable_min_max_time'] ) ? $field['min_time_hour'] : 0;
847 $max_hour = isset( $field['min_time_hour'], $field['enable_min_max_time'] ) ? $field['max_time_hour'] : 23;
848
849 // For Hours.
850 printf(
851 '<select value = "%s" %s>',
852 esc_attr( ( gmdate( 'H' ) >= $min_hour && ( gmdate( 'H' ) <= $max_hour ) ) ? gmdate( 'H' ) : $min_hour ),
853 evf_html_attributes( 'hour-select-' . esc_attr( $primary['id'] ) )
854 );
855
856 for ( $i = $min_hour; $i <= $max_hour; $i++ ) {
857 printf(
858 '<option value="%s" %s>%s</option>',
859 esc_attr( $i ),
860 (int) gmdate( 'H' ) === $i ? 'selected' : '',
861 esc_html( $this->get_minute_hours( $field, 'hours' )[ $i ] )
862 );
863 }
864
865 echo '</select>';
866
867 $time_interval = isset( $field['time_interval'] ) ? $field['time_interval'] : 1;
868
869 // For Minutes.
870 printf(
871 '<select %s>',
872 evf_html_attributes( 'minute-select-' . esc_attr( $primary['id'] ) )
873 );
874 echo '</select>';
875 }
876
877 echo '</div>';
878 }
879
880 }
881
882 /**
883 * Register/queue frontend scripts.
884 *
885 * @param array $atts Shortcode attributes.
886 */
887 public static function load_assets( $atts ) {
888 $form_id = isset( $atts['id'] ) ? wp_unslash( $atts['id'] ) : ''; // WPCS: CSRF ok, input var ok, sanitization ok.
889 $form_obj = evf()->form->get( $form_id );
890 $form_data = ! empty( $form_obj->post_content ) ? evf_decode( $form_obj->post_content ) : '';
891
892 if ( ! empty( $form_data['form_fields'] ) ) {
893 $data_i10ns = array();
894 foreach ( $form_data['form_fields'] as $form_field ) {
895 if ( 'date-time' === $form_field['type'] && isset( $form_field['datetime_style'] ) && 'picker' === $form_field['datetime_style'] ) {
896 $data_i10n = isset( $form_field['date_localization'] ) ? $form_field['date_localization'] : 'en';
897
898 if ( ! in_array( $data_i10n, $data_i10ns, true ) && 'en' !== $data_i10n ) {
899 $data_i10ns[] = $data_i10n;
900 }
901 }
902 }
903
904 if ( ! empty( $data_i10ns ) ) {
905 foreach ( $data_i10ns as $data_i10n ) {
906 if ( wp_script_is( 'flatpickr' ) ) {
907 wp_enqueue_script( 'flatpickr-localization-' . $data_i10n, evf()->plugin_url() . '/assets/js/flatpickr/dist/I10n/' . $data_i10n . '.js', array(), EVF_VERSION, true );
908 }
909 }
910 }
911 }
912
913 }
914
915 /**
916 * Print HTML for year.
917 *
918 * @param array $primary Primary.
919 * @return void
920 */
921 private function get_year_html( $primary ) {
922 // For Years.
923 printf(
924 '<select value="%s" %s >',
925 esc_attr( gmdate( 'Y' ) ),
926 evf_html_attributes( 'year-select-' . esc_attr( $primary['id'] ) )
927 );
928 // Build the select options.
929 $end_date = gmdate( 'Y' ) + 100;
930 $start_date = $end_date - 200;
931
932 for ( $i = $end_date; $i >= $start_date; $i-- ) {
933 printf(
934 '<option value="%s" %s>%s</option>',
935 esc_attr( $i ),
936 (int) gmdate( 'Y' ) === $i ? 'selected' : '',
937 esc_html( $i )
938 );
939 }
940 echo '</select>';
941 }
942
943 /**
944 * Print HTML for month.
945 *
946 * @param array $primary Primary.
947 * @return void
948 */
949 private function get_month_html( $primary ) {
950 // For Months.
951 printf(
952 '<select value="%s" %s >',
953 esc_attr( gmdate( 'm' ) ),
954 evf_html_attributes( 'month-select-' . esc_attr( $primary['id'] ) )
955 );
956 // Build the select options.
957 for ( $i = 1; $i <= 12; $i++ ) {
958 $month = ( $i < 10 ) ? '0' . $i : $i;
959 printf(
960 '<option value="%s" %s>%s</option>',
961 esc_attr( $i ),
962 (int) gmdate( 'm' ) === $i ? 'selected' : '',
963 esc_html( $month )
964 );
965 }
966 echo '</select>';
967 }
968
969 /**
970 * Print HTML for day.
971 *
972 * @param array $primary Primary.
973 * @return void
974 */
975 private function get_day_html( $primary ) {
976 // For Days.
977 printf(
978 '<select value="%s" %s >',
979 esc_attr( gmdate( 'd' ) ),
980 evf_html_attributes( 'day-select-' . esc_attr( $primary['id'] ) )
981 );
982 // Build the select options.
983 for ( $i = 1; $i <= 32; $i++ ) {
984 $day = $i < 10 ? '0' . $i : $i;
985 printf(
986 '<option value="%s" %s>%s</option>',
987 esc_attr( $i ),
988 (int) gmdate( 'd' ) === $i ? 'selected' : '',
989 esc_html( $day )
990 );
991 }
992 echo '</select>';
993 }
994
995
996
997 /**
998 * Returns a list of all timezones.
999 */
1000 public function get_timezones() {
1001
1002 $utc_timezone = new DateTimeZone( 'UTC' );
1003 $timezones = DateTimeZone::listIdentifiers();
1004 $timezones_array = array(
1005 'Default' => 'Default',
1006 );
1007
1008 foreach ( $timezones as $timezone ) {
1009 $dtz = new DateTimeZone( $timezone );
1010 $offset = $dtz->getOffset( new DateTime( 'now', $utc_timezone ) );
1011
1012 $offset_hours = abs( intval( $offset / 3600 ) );
1013 $offset_minutes = abs( intval( ( $offset % 3600 ) / 60 ) );
1014 $offset_sign = ( $offset < 0 ) ? '-' : '+';
1015
1016 $offset_string = sprintf( '%s%02d:%02d', $offset_sign, $offset_hours, $offset_minutes );
1017
1018 $timezone_parts = explode( '/', $timezone );
1019 $timezone_parts = implode( '/', array_reverse( $timezone_parts ) );
1020
1021 $timezones_array[ $timezone ] = $timezone_parts . " ($offset_string)";
1022 }
1023
1024 return $timezones_array;
1025 }
1026
1027
1028
1029 /**
1030 * Save timezone data for datetime field.
1031 *
1032 * @param [array] $field Field.
1033 * @param [array] $form_data Form Data.
1034 * @param [int] $entry_id Entry Id.
1035 * @return array
1036 */
1037 public function save_timezone( $field, $form_data, $entry_id ) {
1038 global $wpdb;
1039
1040 $field_id = isset( $field['id'] ) ? $field['id'] : 0;
1041
1042 if ( $field_id ) {
1043 $fields_settings = $form_data['form_fields'];
1044 $field_settings = isset( $fields_settings[ $field_id ] ) ? $fields_settings[ $field_id ] : array();
1045
1046 if ( ! empty( $field_settings ) && isset( $field_settings['date_timezone'] ) ) {
1047
1048 $date_timezone = $field_settings['date_timezone'];
1049
1050 if ( ! empty( $date_timezone ) && 'Default' !== $date_timezone ) {
1051
1052 $entry_metadata = array(
1053 'entry_id' => $entry_id,
1054 'meta_key' => sanitize_key( $field_settings['meta-key'] . '_timezone' ),
1055 'meta_value' => maybe_serialize( $date_timezone ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
1056 );
1057
1058 // Insert entry meta.
1059 $wpdb->insert( $wpdb->prefix . 'evf_entrymeta', $entry_metadata );
1060 }
1061 }
1062 }
1063
1064 return $field;
1065 }
1066
1067
1068
1069 /**
1070 * Adds Timezone for datetime column in entries table if available.
1071 *
1072 * @param [string] $value Value.
1073 * @param [string] $entry_meta Entry Meta.
1074 * @param [array] $entry Entry.
1075 * @param [string] $type Type.
1076 * @param [string] $meta_key Meta Key.
1077 *
1078 * @return string
1079 */
1080 public function entry_html( $value, $entry_meta, $entry, $type, $meta_key = '' ) {
1081
1082 $field_metas = isset( $entry->meta ) ? $entry->meta : array();
1083 $timezone_key = $meta_key . '_timezone';
1084
1085 if ( ! empty( $meta_key ) && isset( $field_metas[ $timezone_key ] ) ) {
1086 $timezone_value = $field_metas[ $timezone_key ];
1087 $all_timezones = $this->get_timezones();
1088
1089 if ( isset( $all_timezones[ $timezone_value ] ) ) {
1090 $value .= '<p>' . $all_timezones[ $timezone_value ] . '</p>';
1091 }
1092 }
1093
1094 return $value;
1095 }
1096
1097
1098
1099 /**
1100 * Set default date time in frontend if timezone set.
1101 *
1102 * @param [array] $properties Properties array.
1103 * @param [array] $field Field properties.
1104 * @return array
1105 */
1106 public function set_default_timezone( $properties, $field ) {
1107
1108 if ( ! empty( $field['date_timezone'] ) && 'Default' !== $field['date_timezone'] ) {
1109 $timezone = $field['date_timezone'];
1110
1111 if ( in_array( $timezone, timezone_identifiers_list(), true ) ) {
1112
1113 $dtz = new DateTimeZone( $timezone );
1114 $datetime = new DateTime( 'now', $dtz );
1115
1116 switch ( $field['datetime_format'] ) {
1117 case 'date':
1118 $properties['inputs']['primary']['attr']['value'] = esc_attr( $datetime->format( $field['date_format'] ) );
1119 break;
1120
1121 case 'date-time':
1122 if ( ! empty( $field['time_format'] ) ) {
1123 $date_format = esc_attr( $field['date_format'] ) . ' ' . esc_attr( $field['time_format'] );
1124 $properties['inputs']['primary']['attr']['value'] = esc_attr( $datetime->format( $date_format ) );
1125 } else {
1126 $date_format = esc_attr( $field['date_format'] ) . ' g:i A';
1127 $properties['inputs']['primary']['attr']['value'] = esc_attr( $datetime->format( $date_format ) );
1128 }
1129 break;
1130 }
1131 }
1132 }
1133
1134 return $properties;
1135 }
1136 }
1137