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-management-dates-meta-box.php

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

376 lines 22.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 // 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.
7 $key_date_type_terms = get_terms( array_merge( wp_parse_args( array(
8 'hide_empty' => false,
9 'parent' => 0
10 ) ), array( 'taxonomy' => 'management_key_date_type' ) ) );
11
12 // 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.
13 $recurrence_rules = get_option( 'propertyhive_key_date_type', array() );
14 // 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.
15 $recurrence_rules = is_array( $recurrence_rules ) ? $recurrence_rules : array();
16
17 // 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.
18 $parent_post_type = get_post_type( $post_id );
19
20 // 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.
21 $meta_query = array();
22
23 switch ( $parent_post_type )
24 {
25 case 'property' :
26 {
27 // 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.
28 $meta_query = array(
29 array(
30 'key' => '_property_id',
31 'value' => $post_id,
32 ),
33 array(
34 'key' => '_tenancy_id',
35 'compare' => 'NOT EXISTS',
36 ),
37 );
38 break;
39 }
40 case 'tenancy' :
41 {
42 // 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.
43 $parent_property_id = get_post_meta( $post_id, '_property_id', true );
44 // 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.
45 $meta_query = array(
46 array(
47 'relation' => 'OR',
48 array(
49 'key' => '_tenancy_id',
50 'value' => $post_id,
51 ),
52 array(
53 'key' => '_property_id',
54 'value' => $parent_property_id,
55 ),
56 ),
57 );
58 break;
59 }
60 }
61
62 if ( isset($selected_status) && !empty($selected_status) )
63 {
64 switch ( $selected_status )
65 {
66 case 'upcoming_and_overdue':
67 {
68 // 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.
69 $meta_query[] = array(
70 'key' => '_key_date_status',
71 'value' => array('pending', 'booked'),
72 'compare' => 'IN'
73 );
74
75 // 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.
76 $upcoming_threshold = new DateTime('+ ' . apply_filters( 'propertyhive_key_date_upcoming_days', 7 ) . ' DAYS');
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 $meta_query[] = array(
79 'key' => '_date_due',
80 'value' => $upcoming_threshold->format('Y-m-d'),
81 'type' => 'date',
82 'compare' => '<=',
83 );
84 break;
85 }
86 case 'overdue':
87 {
88 // 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.
89 $meta_query[] = array(
90 'key' => '_key_date_status',
91 'value' => array('pending', 'booked'),
92 'compare' => 'IN'
93 );
94
95 // 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.
96 $meta_query[] = array(
97 'key' => '_date_due',
98 'value' => gmdate('Y-m-d'),
99 'type' => 'date',
100 'compare' => '<',
101 );
102 break;
103 }
104 default:
105 {
106 // 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.
107 $meta_query[] = array(
108 'key' => '_key_date_status',
109 'value' => $selected_status,
110 );
111 break;
112 }
113 }
114 }
115
116 if ( isset($selected_type_id) && !empty($selected_type_id) )
117 {
118 // 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.
119 $meta_query[] = array(
120 'key' => '_key_date_type_id',
121 'value' => $selected_type_id,
122 );
123 }
124
125 // 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.
126 $key_dates = get_posts(array (
127 'post_type' => 'key_date',
128 'nopaging' => true,
129 // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- The complete management-date grid selects records by existing property/tenancy relationships and date/status metadata.
130 'meta_query' => $meta_query,
131 'orderby' => 'meta_value',
132 // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Management dates are ordered by their stored due date to preserve the grid's chronological behavior.
133 'meta_key' => '_date_due',
134 'order' => 'DESC',
135
136 ));
137 ?>
138
139 <div class="tablenav top">
140
141 <div class="alignleft actions">
142
143 <select name="_key_date_type_id" id="_type_id_filter">
144 <option value=""><?php echo esc_html(__( 'All Types', 'propertyhive' )); ?></option>
145 <?php
146 if ( !empty( $key_date_type_terms ) && !is_wp_error( $key_date_type_terms ) )
147 {
148 // 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.
149 foreach ($key_date_type_terms as $key_date_type_term)
150 {
151 // 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.
152 $recurrence_type = isset($recurrence_rules[$key_date_type_term->term_id]) ? $recurrence_rules[$key_date_type_term->term_id]['recurrence_type'] : '';
153 if ( $parent_post_type == 'tenancy' || ( $parent_post_type == 'property' && $recurrence_type == 'property_management' ) )
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 $selected = ( isset($selected_type_id) && $selected_type_id == $key_date_type_term->term_id ) ? ' selected' : '';
157 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The selected fragment is only the fixed literal ' selected' or an empty string; option name/value are escaped.
158 echo '<option value="' . esc_attr($key_date_type_term->term_id) . '"' . $selected . '>' . esc_html($key_date_type_term->name) . '</option>';
159 }
160 }
161 }
162 ?>
163 </select>
164
165 <select name="status" id="_date_status_filter">
166 <option value="">All Statuses</option>
167 <option value="upcoming_and_overdue" <?php echo ( isset($selected_status) && $selected_status == 'upcoming_and_overdue' ) ? 'selected' : ''; ?>>Upcoming & Overdue</option>
168 <option value="overdue" <?php echo ( isset($selected_status) && $selected_status == 'overdue' ) ? 'selected' : ''; ?>> Overdue</option>
169 <option value="booked" <?php echo ( isset($selected_status) && $selected_status == 'booked' ) ? 'selected' : ''; ?>> Booked</option>
170 <option value="complete" <?php echo ( isset($selected_status) && $selected_status == 'complete' ) ? 'selected' : ''; ?>> Complete</option>
171 <option value="pending" <?php echo ( isset($selected_status) && $selected_status == 'pending' ) ? 'selected' : ''; ?>> Pending</option>
172 <option value="on_hold" <?php echo ( isset($selected_status) && $selected_status == 'on_hold' ) ? 'selected' : ''; ?>> On Hold</option>
173 <option value="cancelled" <?php echo ( isset($selected_status) && $selected_status == 'cancelled' ) ? 'selected' : ''; ?>> Cancelled</option>
174 </select>
175
176 <input type="button" name="filter_action" id="filter-key-dates-grid" class="button" value="Filter">
177
178 </div>
179 <div class="tablenav-pages one-page">
180 <span class="displaying-num"><?php echo count($key_dates); ?> item<?php echo count($key_dates) != 1 ? 's' : ''; ?></span>
181 </div>
182
183 <br class="clear">
184
185 </div>
186
187 <h2 class="screen-reader-text">Posts list</h2>
188 <table class="wp-list-table widefat fixed striped table-view-list posts" style="border-collapse: collapse;">
189
190 <thead>
191 <tr>
192 <th scope="col" id="description" class="manage-column column-description">
193 Description
194 </th>
195 <th scope="col" id="notes" class="manage-column column-notes">
196 Notes
197 </th>
198 <th scope="col" id="tenants" class="manage-column column-tenants">
199 Tenants
200 </th>
201 <th scope="col" id="date_due" class="manage-column column-date_due">
202 <span>Date Due</span>
203 </th>
204 <th scope="col" id="status" class="manage-column column-status">
205 Status
206 </th>
207 </tr>
208 </thead>
209
210 <tbody id="the-list">
211 <?php
212 if ( count($key_dates) > 0 )
213 {
214 // 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.
215 foreach ( $key_dates as $key_date_post )
216 {
217 // 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.
218 $key_date = new PH_Key_Date( $key_date_post );
219 ?>
220 <tr id="post-<?php echo (int)$key_date_post->ID; ?>" class="post-<?php echo esc_attr($key_date_post->ID); ?> key-date-row">
221 <td class="description column-description" data-colname="Description">
222 <div class="cell-main-content"><?php echo esc_html( $key_date->description() ); ?></div>
223 <div class="row-actions">
224 <span class="inline hide-if-no-js">
225 <button type="button" id="<?php echo esc_attr($key_date_post->ID); ?>" class="button-link meta-box-quick-edit">
226 Quick&nbsp;Edit
227 </button>
228 |
229 </span>
230 <span class="trash">
231 <a href="" id="<?php echo esc_attr($key_date_post->ID); ?>" class="submitdelete meta-box-delete">Delete</a>
232 </span>
233 </div>
234 </td>
235 <td class="notes column-notes" data-colname="Notes">
236 <div class="cell-main-content"><?php echo !empty($key_date->notes()) ? nl2br( esc_html($key_date->notes()) ) : '-'; ?></div>
237 <div class="hidden hidden-key-date-notes"><?php echo esc_html($key_date->notes()); ?></div>
238 </td>
239 <td class="tenants column-tenants" data-colname="Tenants">
240 <div class="cell-main-content">
241 <?php
242 // 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.
243 $tenants = '';
244 if ( !empty($key_date->tenancy_id) )
245 {
246 // 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.
247 $tenancy = $key_date->tenancy();
248 // 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.
249 $tenants = $tenancy->get_tenants(false, true);
250 }
251 echo !empty($tenants) ? wp_kses_post( $tenants ) : '-';
252 ?>
253 </div>
254 </td>
255 <td class="date_due column-date_due" data-colname="Date Due">
256 <?php
257 if ( $key_date->date_due()->format( 'H:i' ) == '00:00' )
258 {
259 // 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.
260 $date_format = 'jS F Y';
261 }
262 else
263 {
264 // 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.
265 $date_format = 'H:i jS F Y';
266 }
267 ?>
268 <div class="cell-main-content"><?php echo esc_html($key_date->date_due()->format( $date_format )); ?></div>
269 </td>
270 <td class="status column-status" data-colname="Status">
271 <div class="cell-main-content"><?php echo esc_html(ucwords( str_replace("_", " ", $key_date->status() ) )); ?></div>
272 <div class="hidden hidden-date-type-id"><?php echo esc_html($key_date->key_date_type_id()); ?></div>
273 </td>
274 </tr>
275 <?php
276 }
277 }
278 else
279 {
280 ?>
281 <tr class="no-items">
282 <td class="colspanchange" colspan="5">No key dates found</td>
283 </tr>
284 <?php
285 }
286 ?>
287 </tbody>
288
289 <tfoot>
290
291 <tr>
292 <th scope="col" class="manage-column column-description">
293 Description
294 </th>
295 <th scope="col" class="manage-column column-notes">
296 Notes
297 </th>
298 <th scope="col" class="manage-column column-tenants">
299 Tenants
300 </th>
301 <th scope="col" class="manage-column column-date_due">
302 <span>Date Due</span>
303 </th>
304 <th scope="col" class="manage-column column-status">
305 Status
306 </th>
307 </tr>
308
309 </tfoot>
310
311 </table>
312 <br>
313 <div class="propertyhive_meta_box">
314 <div class="options_group">
315 <p class="form-field _add_key_date_type_field">
316 <label for="_add_key_date_type"><?php echo esc_html(__('Key Date Type', 'propertyhive')); ?></label>
317 <select id="_add_key_date_type" name="_add_key_date_type" class="select short">
318 <option value="">Select Type</option>
319 <?php
320 if ( !empty( $key_date_type_terms ) && !is_wp_error( $key_date_type_terms ) )
321 {
322 // 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.
323 foreach ($key_date_type_terms as $key_date_type_term)
324 {
325 // 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.
326 $recurrence_type = isset($recurrence_rules[$key_date_type_term->term_id]) ? $recurrence_rules[$key_date_type_term->term_id]['recurrence_type'] : '';
327 if ( $parent_post_type == 'tenancy' || ( $parent_post_type == 'property' && $recurrence_type == 'property_management' ) )
328 {
329 echo '<option value="' . esc_attr($key_date_type_term->term_id) . '">' . esc_html($key_date_type_term->name) . '</option>';
330 }
331 }
332 }
333 ?>
334 </select>
335 </p>
336 <p class="form-field _add_key_date_description_field">
337 <label for="_add_key_date_description"><?php echo esc_html(__('Description', 'propertyhive')); ?></label>
338 <input type="text" id="_add_key_date_description" name="_add_key_date_description" value="" class="short">
339 </p>
340 <p class="form-field _add_key_date_due_field">
341 <label for="_add_key_date_due"><?php echo esc_html(__('Date Due', 'propertyhive')); ?></label>
342 <input type="date" class="small" name="_add_key_date_due" id="_add_key_date_due" value="<?php echo esc_attr(gmdate("Y-m-d")); ?>" placeholder="">
343
344 <select id="_add_key_date_due_hours" name="_add_key_date_due_hours" class="select short" style="width:55px">';
345 <?php
346 // 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.
347 for ( $i = 0; $i < 23; ++$i )
348 {
349 // 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.
350 $j = str_pad($i, 2, '0', STR_PAD_LEFT);
351 echo '<option value="' . esc_attr($j) . '">' . esc_html($j) . '</option>';
352 }
353 ?>
354 </select>
355 :
356 <select id="_add_key_date_due_minutes" name="_add_key_date_due_minutes" class="select short" style="width:55px">
357 <?php
358 // 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.
359 for ( $i = 0; $i < 60; $i+=5 )
360 {
361 // 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.
362 $j = str_pad($i, 2, '0', STR_PAD_LEFT);
363 echo '<option value="' . esc_attr($j) . '">' . esc_html($j) . '</option>';
364 }
365 ?>
366 </select>
367 </p>
368 <p class="form-field _add_key_notes_field">
369 <label for="_add_key_date_notes"><?php echo esc_html(__('Notes', 'propertyhive')); ?></label>
370 <textarea id="_add_key_date_notes" name="_add_key_date_notes" class="short"></textarea>
371 </p>
372 <p>
373 <a href="#" class="add_key_date button button-primary"><?php echo esc_html(__( 'Add Key Date', 'propertyhive' )); ?></a>
374 </p>
375 </div>
376 </div>