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