PluginProbe
Property Hive / 2.2.5
Property Hive v2.2.5
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.2.5, at includes/admin/views/html-viewing-event-meta-box.php

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