PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / views / managereservation / tmpl / default_fields.php
vikappointments / admin / views / managereservation / tmpl Last commit date
default.php 6 days ago default_details.php 6 days ago default_details_appointments.php 6 days ago default_details_appointments_modal.php 6 days ago default_details_appointments_option_modal.php 6 days ago default_details_appointments_table.php 6 days ago default_details_billing.php 6 days ago default_details_order.php 6 days ago default_details_order_custmail.php 6 days ago default_fields.php 6 days ago default_orderstatus.php 6 days ago default_orderstatus_history.php 6 days ago default_orderstatus_manage.php 6 days ago default_usernotes.php 6 days ago default_usernotes_main.php 6 days ago default_usernotes_sidebar.php 6 days ago index.html 6 days ago
default_fields.php
223 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 $vik = VAPApplication::getInstance();
15
16 $has_repeat_fields = VAPCustomFieldsRenderer::hasRepeatableFields($this->customFields);
17
18 // check whether we should use a fieldset title for the main custom fields box
19 $need_title = isset($this->forms['fields']) || ($this->reservation->people > 1 && $has_repeat_fields);
20
21 ?>
22
23 <div class="row-fluid">
24
25 <!-- LEFT SIDE -->
26
27 <div class="span6 full-width">
28
29 <div class="row-fluid">
30 <div class="span12">
31 <?php
32 echo $vik->openFieldset($need_title ? JText::translate('VAPMANAGECUSTOMERTITLE2') : '');
33
34 /**
35 * Render the custom fields form by using the apposite helper.
36 *
37 * Looking for a way to override the custom fields? Take a look
38 * at "/layouts/form/fields/" folder, which should contain all
39 * the supported types of custom fields.
40 *
41 * @since 1.7
42 */
43 echo VAPCustomFieldsRenderer::display($this->customFields, $this->reservation->custom_f, $strict = false);
44
45 echo $vik->closeFieldset();
46 ?>
47 </div>
48 </div>
49
50 </div>
51
52 <!-- RIGHT SIDE -->
53
54 <div class="span6 full-width">
55
56 <?php
57 if ($has_repeat_fields)
58 {
59 /**
60 * Display custom fields also for the other participants.
61 *
62 * @since 1.7
63 */
64 for ($i = 0; $i < $this->reservation->people - 1; $i++)
65 {
66 if (isset($this->reservation->attendees[$i]))
67 {
68 $attendee = $this->reservation->attendees[$i];
69
70 // fetch attendee data
71 $attendeeData = isset($attendee['fields']) ? $attendee['fields'] : array();
72
73 if (isset($attendee['uploads']))
74 {
75 // inject uploaded files within custom fields
76 $attendeeData = array_merge($attendeeData, (array) $attendee['uploads']);
77 }
78 }
79 else
80 {
81 // empty details
82 $attendee = null;
83 $attendeeData = array();
84 }
85 ?>
86 <div class="row-fluid">
87 <div class="span12">
88 <?php
89 echo $vik->openFieldset(JText::sprintf('VAP_N_ATTENDEE', $i + 2));
90
91 /**
92 * Tries to auto-populate the fields with the details assigned to the current attendee.
93 *
94 * The fourth boolean flag is set to instruct the method that the customers are usual to
95 * enter the first name before the last name. Use false to auto-populate the fields in
96 * the opposite way.
97 */
98 VAPCustomFieldsRenderer::autoPopulate($attendeeData, $this->customFields, $attendee, $firstNameComesFirst = true);
99
100 // render the custom fields form by using the apposite helper
101 echo VAPCustomFieldsRenderer::displayAttendee($i + 1, $this->customFields, $attendeeData, $strict = false);
102
103 echo $vik->closeFieldset();
104 ?>
105 </div>
106 </div>
107 <?php
108 }
109 }
110
111 /**
112 * Look for any additional fields to be pushed within
113 * the "Custom Fields" fieldset (right-side).
114 *
115 * NOTE: retrieved from "onDisplayViewReservation" hook.
116 *
117 * @since 1.7
118 */
119 if (isset($this->forms['fields']))
120 {
121 ?>
122 <div class="row-fluid">
123 <div class="span12">
124 <?php
125 echo $vik->openEmptyFieldset();
126 echo $this->forms['fields'];
127 echo $vik->closeEmptyFieldset();
128 ?>
129 </div>
130 </div>
131 <?php
132
133 // unset details form to avoid displaying it twice
134 unset($this->forms['fields']);
135 }
136 ?>
137
138 </div>
139
140 <!-- Define role to detect the supported hook -->
141 <!-- {"rule":"customizer","event":"onDisplayViewReservation","type":"field","key":"fields"} -->
142
143 </div>
144
145 <?php
146 // create name-id custom fields lookup
147 $lookup = array();
148
149 foreach ($this->customFields as $field)
150 {
151 $lookup[$field['name']] = $field['id'];
152 }
153
154 JText::script('JGLOBAL_SELECT_AN_OPTION');
155 ?>
156
157 <script>
158
159 const CUSTOM_FIELDS_LOOKUP = <?php echo json_encode($lookup); ?>;
160
161 jQuery(function($) {
162 // render select
163 $('select.custom-field').each(function() {
164 // check whether the first option is a placeholder
165 let hasPlaceholder = $(this).find('option').first().text().length == 0;
166
167 $(this).select2({
168 // check whether we should specify a placeholder
169 placeholder: hasPlaceholder ? Joomla.JText._('JGLOBAL_SELECT_AN_OPTION') : '',
170 // disable search for select with 3 or lower options
171 minimumResultsForSearch: $(this).find('option').length > 3 ? 0 : -1,
172 // check whether the field supports empty values
173 allowClear: !$(this).hasClass('required') && hasPlaceholder ? true : false,
174 width: '90%',
175 });
176 });
177 });
178
179 function compileCustomFields(fields) {
180 jQuery.each(fields, function(name, value) {
181 if (!CUSTOM_FIELDS_LOOKUP.hasOwnProperty(name)) {
182 // field not found, next one
183 return true;
184 }
185
186 const input = jQuery('*[name="vapcf' + CUSTOM_FIELDS_LOOKUP[name] + '"]');
187
188 if (input.length) {
189 if (input.is('select')) {
190 if (input.find('option[value="' + value + '"]').length) {
191 // refresh select value if the option exists
192 input.select2('val', value);
193 } else {
194 // otherwise select the first option
195 input.select2('val', input.find('option').first().val());
196 }
197 } else if (input.is(':checkbox')) {
198 // check/uncheck the input
199 input.prop('checked', value ? true : false);
200 } else if (input.hasClass('phone-field')) {
201 // update phone number
202 input.intlTelInput('setNumber', value);
203 } else {
204 // otherwise refresh as default input
205 try {
206 input.val(value);
207
208 if (input.data('alt-value') !== undefined) {
209 // we are probably updating a calendar,
210 // make sure to update also the alt value
211 input.attr('data-alt-value', value);
212 }
213 } catch (error) {
214 // catch error because input file might raise
215 // an error while trying to set a value
216 }
217 }
218 }
219 });
220 }
221
222 </script>
223