PluginProbe
Property Hive / 2.3.1
Property Hive v2.3.1
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
propertyhive / includes / admin / views / html-viewing-event-meta-box.php

html-viewing-event-meta-box.php in Property Hive 2.3.1, at includes/admin/views/html-viewing-event-meta-box.php

378 lines 20.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
5 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
6 $readonly = isset($readonly) ? $readonly : false;
7
8 echo '<div class="propertyhive_meta_box">';
9
10 echo '<div class="options_group">';
11
12 wp_nonce_field( 'propertyhive_save_data', 'propertyhive_meta_nonce' );
13
14 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only calendar prefill; saving has separate nonce and object guards.
15 $propertyhive_calendar_input = wp_unslash( $_GET );
16 $propertyhive_calendar_start = isset( $propertyhive_calendar_input['start'] ) && is_scalar( $propertyhive_calendar_input['start'] ) ? absint( $propertyhive_calendar_input['start'] ) : null;
17 $propertyhive_calendar_end = isset( $propertyhive_calendar_input['end'] ) && is_scalar( $propertyhive_calendar_input['end'] ) ? absint( $propertyhive_calendar_input['end'] ) : null;
18 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view.
19 $start_date_time = get_post_meta( $post->ID, '_start_date_time', true );
20 if ( $start_date_time == '' )
21 {
22 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
23 $start_date_time = gmdate("Y-m-d H:i:s");
24
25 if ( $propertyhive_calendar_start !== null )
26 {
27 // $_GET['start'] should be a unix timestamp
28 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
29 $start_date_time = gmdate("Y-m-d H:i:s", $propertyhive_calendar_start);
30 }
31 }
32
33 echo '<p class="form-field event_start_time_field">
34
35 <label for="_start_date">' . esc_html(__('Viewing Date / Time', 'propertyhive')) . '</label>';
36
37 if ( $readonly )
38 {
39 echo esc_html(gmdate("H:i", strtotime($start_date_time)) . ' on ' . gmdate("l jS F Y", strtotime($start_date_time)));
40 }
41 else
42 {
43 echo '<input type="date" class="small" name="_start_date" id="_start_date" value="' . esc_attr(gmdate("Y-m-d", strtotime($start_date_time))) . '" placeholder="">
44 <select id="_start_time_hours" name="_start_time_hours" class="select short" style="width:55px">';
45
46 if ( $start_date_time == '' )
47 {
48 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
49 $value = gmdate("H");
50 }
51 else
52 {
53 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
54 $value = gmdate( "H", strtotime( $start_date_time ) );
55 }
56 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
57 for ( $i = 0; $i < 23; ++$i )
58 {
59 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
60 $j = str_pad($i, 2, '0', STR_PAD_LEFT);
61 echo '<option value="' . esc_attr($j) . '"';
62 if ($i == $value) { echo ' selected'; }
63 echo '>' . esc_html($j) . '</option>';
64 }
65
66 echo '</select>
67 :
68 <select id="_start_time_minutes" name="_start_time_minutes" class="select short" style="width:55px">';
69
70 if ( $start_date_time == '' )
71 {
72 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
73 $value = '';
74 }
75 else
76 {
77 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
78 $value = gmdate( "i", strtotime( $start_date_time ) );
79 }
80 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
81 for ( $i = 0; $i < 60; $i+=5 )
82 {
83 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
84 $j = str_pad($i, 2, '0', STR_PAD_LEFT);
85 echo '<option value="' . esc_attr($j) . '"';
86 if ($i == $value) { echo ' selected'; }
87 echo '>' . esc_html($j) . '</option>';
88 }
89
90 echo '</select>';
91 }
92 echo '</p>';
93
94 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
95 $durations = array(15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180);
96 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
97 $durations = apply_filters( 'propertyhive_viewing_durations', $durations );
98
99 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
100 $value = get_post_meta( $post->ID, '_duration', true );
101 if ($value == '')
102 {
103 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
104 $value = apply_filters( 'propertyhive_viewing_default_duration_minutes', 30 ) * 60; // Default is 30 minutes, unless modified by filter
105
106 if ( $propertyhive_calendar_start !== null && $propertyhive_calendar_end !== null )
107 {
108 // $_GET['start'] and $_GET['end'] should be a unix timestamp
109 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
110 $duration = ($propertyhive_calendar_end - $propertyhive_calendar_start) / 60;
111
112 if ( in_array($duration, $durations) )
113 {
114 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
115 $value = $duration * 60;
116 }
117 }
118 }
119
120 if ( !$readonly )
121 {
122 echo '<p class="form-field">
123
124 <label for="_duration">' . esc_html(__('Duration', 'propertyhive')) . '</label>
125
126 <select id="_duration" name="_duration" class="select short">';
127
128 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
129 foreach ( $durations as $duration )
130 {
131 // convert duration to reable format (i.e. 1 hour 15 minutes)
132 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
133 $hours = floor($duration / 60);
134 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
135 $minutes = $duration % 60;
136 echo '<option value="' . esc_attr(($duration * 60)) . '"' . ( $value == ($duration * 60) ? 'selected' : '' ) . '>' . esc_html(( $hours > 0 ? $hours . ' hour' . ( $hours != 1 ? 's' : '' ) : '' ) . ( $minutes != '' ? ' '. $minutes . ' minutes' : '' )) . '</option>';
137 }
138 if ( !in_array( $value / 60, $durations))
139 {
140 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
141 $hours = floor(($value / 60) / 60);
142 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
143 $minutes = ($value / 60) % 60;
144 echo '<option value="' . esc_attr($value) . '" selected>' . esc_html(( $hours > 0 ? $hours . ' hour' . ( $hours != 1 ? 's' : '' ) : '' ) . ( $minutes != '' ? ' ' . $minutes . ' minutes' : '' )) . '</option>';
145 }
146
147 echo '</select>
148
149 </p>';
150 }
151
152 echo '
153 <p class="form-field"><label for="_negotiator_ids">' . esc_html(__( 'Attending Negotiator(s)', 'propertyhive' )) . '</label>';
154
155 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
156 $negotiator_ids = get_post_meta( $post->ID, '_negotiator_id' );
157 if ( $readonly )
158 {
159 if ( !empty($negotiator_ids) )
160 {
161 $names = array();
162 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
163 foreach ( $negotiator_ids as $negotiator_id )
164 {
165 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
166 $user_info = get_userdata($negotiator_id);
167 if ( $user_info !== FALSE )
168 {
169 $names[] = $user_info->display_name;
170 }
171 }
172 echo esc_html(implode(", ", $names));
173 }
174 else
175 {
176 echo esc_html(__( 'Unaccompanied', 'propertyhive' ));
177 }
178 }
179 else
180 {
181 echo '
182 <select id="_negotiator_ids" name="_negotiator_ids[]" multiple="multiple" data-placeholder="' . esc_attr(__( 'Unaccompanied', 'propertyhive' )) . '" class="multiselect attribute_values">';
183
184 if ( isset($pagenow) && $pagenow == 'post-new.php' )
185 {
186 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
187 $negotiator_ids = array( get_current_user_id() );
188 }
189
190 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
191 $args = array(
192 'number' => 9999,
193 'orderby' => 'display_name',
194 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Legacy Property Negotiator compatibility filter; existing role filters depend on this exact public hook name.
195 'role__not_in' => apply_filters( 'property_negotiator_exclude_roles', array('property_hive_contact', 'subscriber') )
196 );
197
198 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
199 $args = apply_filters( 'propertyhive_negotiators_query', $args );
200
201 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
202 $user_query = new WP_User_Query( $args );
203
204 if ( ! empty( $user_query->results ) )
205 {
206 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
207 foreach ( $user_query->results as $user )
208 {
209 echo '<option value="' . esc_attr($user->ID) . '"';
210 if ( in_array($user->ID, $negotiator_ids) )
211 {
212 echo ' selected';
213 }
214 echo '>' . esc_html($user->display_name) . '</option>';
215 }
216 }
217
218 echo '</select>';
219 }
220 echo '</p>';
221
222 if ( isset($pagenow) && $pagenow == 'post-new.php' )
223 {
224
225 }
226 else
227 {
228 propertyhive_wp_hidden_input( array(
229 'id' => '_previous_negotiator_ids',
230 'value' => implode(",", $negotiator_ids),
231 ) );
232 }
233
234 if ( $readonly )
235 {
236 echo '<p class="form-field">
237
238 <label for="">' . esc_html(__('Booking Notes', 'propertyhive')) . '</label>
239
240 ' . nl2br(esc_html($viewing->booking_notes)) . '
241
242 </p>';
243 }
244 else
245 {
246 propertyhive_wp_textarea_input( array(
247 'id' => '_booking_notes',
248 'label' => __( 'Booking Notes', 'propertyhive' ),
249 'desc_tip' => false,
250 'class' => ''
251 ) );
252 }
253
254 if ( !$readonly && get_post_meta( $post->ID, '_status', true ) == 'pending' )
255 {
256 propertyhive_wp_checkboxes( array(
257 'id' => '_confirmed',
258 'wrapper_class' => 'confirmations',
259 'label' => __( 'Confirmed', 'propertyhive' ),
260 'options' => array(
261
262 ),
263 'desc_tip' => false,
264 ) );
265 }
266
267 do_action('propertyhive_viewing_event_fields');
268
269 echo '</div>';
270
271 echo '</div>';
272
273 $propertyhive_original_viewing_id = isset( $propertyhive_calendar_input['viewing_id'] ) && is_scalar( $propertyhive_calendar_input['viewing_id'] ) ? absint( $propertyhive_calendar_input['viewing_id'] ) : 0;
274 if ( $propertyhive_original_viewing_id > 0 )
275 {
276 echo '<input type="hidden" name="_original_viewing_id" value="' . esc_attr( $propertyhive_original_viewing_id ) . '">';
277 }
278
279 echo '<input type="hidden" name="_num_requiring_confirmation" id="_num_requiring_confirmation" value="">';
280
281 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
282 $previously_selected = array();
283 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
284 $confirmed = get_post_meta( $post->ID, '_confirmed', true );
285 if ( is_array($confirmed) && !empty($confirmed) )
286 {
287 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
288 $previously_selected = $confirmed;
289 }
290
291 echo '<script>
292
293 var previously_selected = ' . wp_json_encode( $previously_selected, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ) . ';
294
295 jQuery(document).ready(function()
296 {
297 generate_confirmation_options(true);
298
299 jQuery(\'#_negotiator_ids\').change(function()
300 {
301 generate_confirmation_options(false);
302 });
303
304 jQuery(\'#_applicant_contact_ids\').change(function()
305 {
306 generate_confirmation_options(false);
307 });
308
309 jQuery(\'#_property_id\').change(function()
310 {
311 generate_confirmation_options(false);
312 });
313 });
314
315 function generate_confirmation_options(first_load)
316 {
317 var num_requiring_confirmation = 0;
318
319 // get previously selected options so we can re-select them after updating options
320 if (!first_load)
321 {
322 previously_selected = [];
323 if ( jQuery("input[name=\'_confirmed[]\']:checked").length > 0 )
324 {
325 jQuery("input[name=\'_confirmed[]\']:checked").each(function()
326 {
327 previously_selected.push(jQuery(this).val());
328 })
329 }
330 }
331
332 var options = [];
333
334 // get applicant
335 jQuery(\'a[data-viewing-applicant-id]\').each(function()
336 {
337 options.push( { id: \'applicant-\' + jQuery(this).attr(\'data-viewing-applicant-id\'), name: \'Applicant (\' + jQuery(this).attr(\'data-viewing-applicant-name\') + \')\' } );
338 });
339
340 // get owner
341 jQuery(\'a[data-viewing-owner-id]\').each(function()
342 {
343 options.push( { id: \'owner-\' + jQuery(this).attr(\'data-viewing-owner-id\'), name: \'Owner (\' + jQuery(this).attr(\'data-viewing-owner-name\') + \')\' } );
344 });
345
346 // get negs
347 jQuery(\'#_negotiator_ids option:selected\').each(function(){ options.push( { id: \'negotiator-\' + jQuery(this).val(), name: \'Negotiator (\' + jQuery(this).text() + \')\' } ); });
348
349 // set options
350 jQuery(\'.confirmations .ph-radios\').html(\'\');
351 if ( options.length > 0 )
352 {
353 for ( var i in options )
354 {
355 var confirmation_label = jQuery(\'<label>\');
356 confirmation_label.append(jQuery(\'<input>\', { type: \'checkbox\', class: \'checkbox\', name: \'_confirmed[]\' }).val(options[i].id));
357 confirmation_label.append(document.createTextNode(\' \' + options[i].name));
358 jQuery(\'.confirmations .ph-radios\').append(jQuery(\'<li>\').append(confirmation_label));
359 num_requiring_confirmation = num_requiring_confirmation + 1;
360 }
361 }
362 else
363 {
364 jQuery(\'.confirmations .ph-radios\').html(\'<li>Please select a negotiator, applicant or property</li>\');
365 }
366
367 // reselect previously selected
368
369 for ( var i in previously_selected )
370 {
371 //console.log(previously_selected[i]);
372 jQuery("input[name=\'_confirmed[]\']").filter(function() { return this.value == previously_selected[i]; }).prop(\'checked\', true);
373 }
374
375 jQuery(\'#_num_requiring_confirmation\').val(num_requiring_confirmation);
376 }
377
378 </script>';