PluginProbe
Property Hive / 1.4.46
Property Hive v1.4.46
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 / post-types / class-ph-admin-meta-boxes.php

class-ph-admin-meta-boxes.php in Property Hive 1.4.46, at includes/admin/post-types/class-ph-admin-meta-boxes.php

1,541 lines 64.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PropertyHive Meta Boxes
4 *
5 * Sets up the write panels used by products and orders (custom post types)
6 *
7 * @author BIOSTA::
8 * @category Admin
9 * @package PropertyHive/Admin/Meta Boxes
10 * @version 1.0.0
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
15 if ( ! class_exists( 'PH_Admin_Meta_Boxes' ) )
16 {
17
18 /**
19 * PH_Admin_Meta_Boxes
20 */
21 class PH_Admin_Meta_Boxes {
22
23 private static $meta_box_errors = array();
24
25 /**
26 * Constructor
27 */
28 public function __construct() {
29
30 add_action( 'add_meta_boxes', array( $this, 'remove_meta_boxes' ), 10 );
31 add_action( 'add_meta_boxes', array( $this, 'rename_meta_boxes' ), 20 );
32 add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 30 );
33 add_action( 'save_post', array( $this, 'save_meta_boxes' ), 1, 2 );
34
35 // Save Property Meta Boxes
36 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Address::save', 10, 2 );
37 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Owner::save', 12, 2 );
38 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Record_Details::save', 13, 2 );
39 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Coordinates::save', 70, 2 );
40
41 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Department::save', 15, 2 );
42 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Residential_Details::save', 20, 2 );
43 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Residential_Lettings_Details::save', 25, 2 );
44 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Residential_Sales_Details::save', 30, 2 );
45 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Commercial_Details::save', 30, 2 );
46
47 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Marketing::save', 35, 2 );
48
49 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Rooms::save', 40, 2 );
50 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Features::save', 45, 2 );
51 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Description::save', 45, 2 );
52
53 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Photos::save', 50, 2 );
54 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Floorplans::save', 55, 2 );
55 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Brochures::save', 65, 2 );
56 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Epcs::save', 70, 2 );
57 add_action( 'propertyhive_process_property_meta', 'PH_Meta_Box_Property_Virtual_Tours::save', 75, 2 );
58
59 // Save Contact Meta Boxes
60 add_action( 'propertyhive_process_contact_meta', 'PH_Meta_Box_Contact_Correspondence_Address::save', 10, 2 );
61 add_action( 'propertyhive_process_contact_meta', 'PH_Meta_Box_Contact_Contact_Details::save', 15, 2 );
62 add_action( 'propertyhive_process_contact_meta', 'PH_Meta_Box_Contact_Relationships::save', 20, 2 );
63
64 // Save Enquiry Meta Boxes
65 if ( get_option('propertyhive_module_disabled_enquiries', '') != 'yes' )
66 {
67 add_action( 'propertyhive_process_enquiry_meta', 'PH_Meta_Box_Enquiry_Record_Details::save', 10, 2 );
68 add_action( 'propertyhive_process_enquiry_meta', 'PH_Meta_Box_Enquiry_Details::save', 15, 2 );
69 }
70
71 // Save Appraisal Meta Boxes
72 add_action( 'propertyhive_process_appraisal_meta', 'PH_Meta_Box_Appraisal_Details::save', 10, 2 );
73 add_action( 'propertyhive_process_appraisal_meta', 'PH_Meta_Box_Appraisal_Event::save', 15, 2 );
74 add_action( 'propertyhive_process_appraisal_meta', 'PH_Meta_Box_Appraisal_Property_Owner::save', 20, 2 );
75 add_action( 'propertyhive_process_appraisal_meta', 'PH_Meta_Box_Appraisal_Property::save', 25, 2 );
76
77 // Save Viewing Meta Boxes
78 add_action( 'propertyhive_process_viewing_meta', 'PH_Meta_Box_Viewing_Details::save', 10, 2 );
79 add_action( 'propertyhive_process_viewing_meta', 'PH_Meta_Box_Viewing_Event::save', 15, 2 );
80 add_action( 'propertyhive_process_viewing_meta', 'PH_Meta_Box_Viewing_Applicant::save', 20, 2 );
81 add_action( 'propertyhive_process_viewing_meta', 'PH_Meta_Box_Viewing_Property::save', 25, 2 );
82
83 // Save Offer Meta Boxes
84 add_action( 'propertyhive_process_offer_meta', 'PH_Meta_Box_Offer_Details::save', 10, 2 );
85 add_action( 'propertyhive_process_offer_meta', 'PH_Meta_Box_Offer_Applicant::save', 15, 2 );
86 add_action( 'propertyhive_process_offer_meta', 'PH_Meta_Box_Offer_Applicant_Solicitor::save', 20, 2 );
87 add_action( 'propertyhive_process_offer_meta', 'PH_Meta_Box_Offer_Property::save', 25, 2 );
88 add_action( 'propertyhive_process_offer_meta', 'PH_Meta_Box_Offer_Property_Owner_Solicitor::save', 30, 2 );
89
90 // Save Sale Meta Boxes
91 add_action( 'propertyhive_process_sale_meta', 'PH_Meta_Box_Sale_Details::save', 10, 2 );
92 add_action( 'propertyhive_process_sale_meta', 'PH_Meta_Box_Sale_Applicant_Solicitor::save', 15, 2 );
93 add_action( 'propertyhive_process_sale_meta', 'PH_Meta_Box_Sale_Property_Owner_Solicitor::save', 20, 2 );
94
95 // Error handling (for showing errors from meta boxes on next page load)
96 add_action( 'admin_notices', array( $this, 'output_errors' ) );
97 add_action( 'shutdown', array( $this, 'save_errors' ) );
98
99 $this->check_contact_create_relationship();
100 $this->check_contact_delete_relationship();
101 $this->check_remove_solicitor();
102 $this->check_create_offer();
103 $this->check_create_sale();
104 }
105
106 public function check_contact_create_relationship()
107 {
108 if ( isset($_GET['add_applicant_relationship']) && wp_verify_nonce($_GET['add_applicant_relationship'], '1') && isset($_GET['post']) )
109 {
110 // Need to add blank applicant
111 if ( get_post_type((int)$_GET['post']) != 'contact' )
112 return;
113
114 $num_applicant_profiles = get_post_meta( (int)$_GET['post'], '_applicant_profiles', TRUE );
115 if ( $num_applicant_profiles == '' )
116 {
117 $num_applicant_profiles = 0;
118 }
119
120 update_post_meta( (int)$_GET['post'], '_applicant_profile_' . $num_applicant_profiles, '' );
121 update_post_meta( (int)$_GET['post'], '_applicant_profiles', $num_applicant_profiles + 1 );
122
123 $existing_contact_types = get_post_meta( (int)$_GET['post'], '_contact_types', TRUE );
124 if ( $existing_contact_types == '' || !is_array($existing_contact_types) )
125 {
126 $existing_contact_types = array();
127 }
128 if ( !in_array( 'applicant', $existing_contact_types ) )
129 {
130 $existing_contact_types[] = 'applicant';
131 update_post_meta( (int)$_GET['post'], '_contact_types', $existing_contact_types );
132 }
133
134 // Do redirect
135 wp_redirect( admin_url( 'post.php?post=' . (int)$_GET['post'] . '&action=edit#propertyhive-contact-relationships' ) );
136 exit();
137 }
138
139 if ( isset($_GET['add_third_party_relationship']) && wp_verify_nonce($_GET['add_third_party_relationship'], '1') && isset($_GET['post']) )
140 {
141 // Need to add blank applicant
142 if ( get_post_type((int)$_GET['post']) != 'contact' )
143 return;
144
145 $existing_third_party_categories = get_post_meta( (int)$_GET['post'], '_third_party_categories', TRUE );
146 if ($existing_third_party_categories)
147 {
148 $existing_third_party_categories = array();
149 }
150 $existing_third_party_categories[] = 0;
151 update_post_meta( $_GET['post'], '_third_party_categories', $existing_third_party_categories );
152
153 $existing_contact_types = get_post_meta( (int)$_GET['post'], '_contact_types', TRUE );
154 if ( $existing_contact_types == '' || !is_array($existing_contact_types) )
155 {
156 $existing_contact_types = array();
157 }
158 if ( !in_array( 'thirdparty', $existing_contact_types ) )
159 {
160 $existing_contact_types[] = 'thirdparty';
161 update_post_meta( (int)$_GET['post'], '_contact_types', $existing_contact_types );
162 }
163 }
164 }
165
166 public function check_contact_delete_relationship()
167 {
168 if ( isset($_GET['delete_applicant_relationship']) && isset($_GET['post']) )
169 {
170 // Need to add blank applicant
171 if ( get_post_type((int)$_GET['post']) != 'contact' )
172 return;
173
174 $num_applicant_profiles = get_post_meta( (int)$_GET['post'], '_applicant_profiles', TRUE );
175 if ( $num_applicant_profiles == '' )
176 {
177 $num_applicant_profiles = 0;
178 }
179
180 for ( $i = 0; $i < $num_applicant_profiles; ++$i )
181 {
182 if ( wp_verify_nonce($_GET['delete_applicant_relationship'], $i) )
183 {
184 $deleting_applicant_profile = $i;
185
186 // We're deleting this one
187 delete_post_meta( (int)$_GET['post'], '_applicant_profile_' . $i );
188
189 // Now need to rename any that are higher than $deleting_applicant_profile
190 for ( $j = 0; $j < $num_applicant_profiles; ++$j )
191 {
192 if ( $j > $deleting_applicant_profile )
193 {
194 $this_applicant_profile = get_post_meta( (int)$_GET['post'], '_applicant_profile_' . $j );
195 update_post_meta( (int)$_GET['post'], '_applicant_profile_' . ($j - 1), $this_applicant_profile );
196 delete_post_meta( (int)$_GET['post'], '_applicant_profile_' . $j );
197 }
198 }
199
200 // remove from _contact_types if no more profiles left
201 if ( $num_applicant_profiles == 1 )
202 {
203 $existing_contact_types = get_post_meta( (int)$_GET['post'], '_contact_types', TRUE );
204 if ( $existing_contact_types == '' || !is_array($existing_contact_types) )
205 {
206 $existing_contact_types = array();
207 }
208 if( ( $key = array_search('applicant', $existing_contact_types) ) !== false )
209 {
210 unset($existing_contact_types[$key]);
211 }
212 update_post_meta( (int)$_GET['post'], '_contact_types', $existing_contact_types );
213 }
214
215 update_post_meta( (int)$_GET['post'], '_applicant_profiles', $num_applicant_profiles - 1 );
216
217 // Do redirect
218 wp_redirect( admin_url( 'post.php?post=' . (int)$_GET['post'] . '&action=edit#propertyhive-contact-relationships' ) );
219 exit();
220 }
221 }
222 }
223 }
224
225 public function check_remove_solicitor()
226 {
227 if ( isset($_GET['remove_property_owner_solicitor']) && isset($_GET['post']) )
228 {
229 if ( get_post_type((int)$_GET['post']) != 'offer' && get_post_type((int)$_GET['post']) != 'sale' )
230 return;
231
232 update_post_meta( (int)$_GET['post'], '_property_owner_solicitor_contact_id', '' );
233 }
234
235 if ( isset($_GET['remove_applicant_solicitor']) && isset($_GET['post']) )
236 {
237 if ( get_post_type((int)$_GET['post']) != 'offer' && get_post_type((int)$_GET['post']) != 'sale' )
238 return;
239
240 update_post_meta( (int)$_GET['post'], '_applicant_solicitor_contact_id', '' );
241 }
242 }
243
244 public function check_create_offer()
245 {
246 if ( isset($_GET['create_offer']) && isset($_GET['post']) )
247 {
248 if ( get_post_type((int)$_GET['post']) != 'viewing')
249 return;
250
251 $viewing = new PH_Viewing((int)$_GET['post']);
252
253 $offer_post = array(
254 'post_title' => '',
255 'post_content' => '',
256 'post_type' => 'offer',
257 'post_status' => 'publish',
258 'comment_status' => 'closed',
259 'ping_status' => 'closed',
260 );
261
262 // Insert the post into the database
263 $offer_post_id = wp_insert_post( $offer_post );
264
265 add_post_meta( $offer_post_id, '_status', 'pending' );
266 add_post_meta( $offer_post_id, '_amount', '' );
267 add_post_meta( $offer_post_id, '_applicant_contact_id', $viewing->applicant_contact_id );
268 add_post_meta( $offer_post_id, '_applicant_solicitor_contact_id', '' );
269 add_post_meta( $offer_post_id, '_property_id', $viewing->property_id );
270 add_post_meta( $offer_post_id, '_property_owner_solicitor_contact_id', '' );
271 add_post_meta( $offer_post_id, '_offer_date_time', date("Y-m-d H:i:s") );
272
273 update_post_meta( (int)$_GET['post'], '_offer_id', $offer_post_id );
274 update_post_meta( (int)$_GET['post'], '_status', 'offer_made' );
275
276 $current_user = wp_get_current_user();
277
278 // Add note/comment to viewing
279 $comment = array(
280 'note_type' => 'action',
281 'action' => 'viewing_offer_made',
282 );
283
284 $data = array(
285 'comment_post_ID' => (int)$_GET['post'],
286 'comment_author' => $current_user->display_name,
287 'comment_author_email' => 'propertyhive@noreply.com',
288 'comment_author_url' => '',
289 'comment_date' => date("Y-m-d H:i:s"),
290 'comment_content' => serialize($comment),
291 'comment_approved' => 1,
292 'comment_type' => 'propertyhive_note',
293 );
294 $comment_id = wp_insert_comment( $data );
295
296 // Do redirect
297 wp_redirect( admin_url( 'post.php?post=' . $offer_post_id . '&action=edit' ) );
298 exit();
299 }
300
301 }
302
303 public function check_create_sale()
304 {
305 if ( isset($_GET['create_sale']) && isset($_GET['post']) )
306 {
307 if ( get_post_type((int)$_GET['post']) != 'offer')
308 return;
309
310 $offer = new PH_Offer((int)$_GET['post']);
311
312 $sale_post = array(
313 'post_title' => '',
314 'post_content' => '',
315 'post_type' => 'sale',
316 'post_status' => 'publish',
317 'comment_status' => 'closed',
318 'ping_status' => 'closed',
319 );
320
321 // Insert the post into the database
322 $sale_post_id = wp_insert_post( $sale_post );
323
324 add_post_meta( $sale_post_id, '_status', 'current' );
325 add_post_meta( $sale_post_id, '_amount', $offer->amount );
326 add_post_meta( $sale_post_id, '_applicant_contact_id', $offer->applicant_contact_id );
327 add_post_meta( $sale_post_id, '_applicant_solicitor_contact_id', $offer->applicant_solicitor_contact_id );
328 add_post_meta( $sale_post_id, '_property_id', $offer->property_id );
329 add_post_meta( $sale_post_id, '_property_owner_solicitor_contact_id', $offer->property_owner_solicitor_contact_id );
330 add_post_meta( $sale_post_id, '_sale_date_time', date("Y-m-d H:i:s") );
331
332 update_post_meta( (int)$_GET['post'], '_sale_id', $sale_post_id );
333
334 $current_user = wp_get_current_user();
335
336 // Add note/comment to offer
337 $comment = array(
338 'note_type' => 'action',
339 'action' => 'offer_sale_created',
340 );
341
342 $data = array(
343 'comment_post_ID' => (int)$_GET['post'],
344 'comment_author' => $current_user->display_name,
345 'comment_author_email' => 'propertyhive@noreply.com',
346 'comment_author_url' => '',
347 'comment_date' => date("Y-m-d H:i:s"),
348 'comment_content' => serialize($comment),
349 'comment_approved' => 1,
350 'comment_type' => 'propertyhive_note',
351 );
352 $comment_id = wp_insert_comment( $data );
353
354 // Do redirect
355 wp_redirect( admin_url( 'post.php?post=' . $sale_post_id . '&action=edit' ) );
356 exit();
357 }
358
359 }
360
361 /**
362 * Add an error message
363 * @param string $text
364 */
365 public static function add_error( $text ) {
366 self::$meta_box_errors[] = $text;
367 }
368
369 /**
370 * Save errors to an option
371 */
372 public function save_errors() {
373 update_option( 'propertyhivemeta_box_errors', self::$meta_box_errors );
374 }
375
376 /**
377 * Show any stored error messages.
378 */
379 public function output_errors() {
380
381 $errors = maybe_unserialize( get_option( 'propertyhive_meta_box_errors' ) );
382
383 if ( ! empty( $errors ) ) {
384
385 echo '<div id="propertyhive_errors" class="error fade">';
386 foreach ( $errors as $error ) {
387 echo '<p>' . esc_html( $error ) . '</p>';
388 }
389 echo '</div>';
390
391 // Clear
392 delete_option( 'propertyhive_meta_box_errors' );
393 }
394 }
395
396 /**
397 * Add PH Meta boxes
398 */
399 public function add_meta_boxes() {
400
401 global $tabs, $post, $pagenow;
402
403 // PROPERTY
404 if (!isset($tabs)) $tabs = array();
405
406 /* PROPERTY SUMMARY META BOXES */
407 $meta_boxes = array();
408 $meta_boxes[5] = array(
409 'id' => 'propertyhive-property-address',
410 'title' => __( 'Property Address', 'propertyhive' ),
411 'callback' => 'PH_Meta_Box_Property_Address::output',
412 'screen' => 'property',
413 'context' => 'normal',
414 'priority' => 'high'
415 );
416 if ( get_option('propertyhive_module_disabled_contacts', '') != 'yes' )
417 {
418 $meta_boxes[10] = array(
419 'id' => 'propertyhive-property-owner',
420 'title' => __( 'Property Owner / Landlord', 'propertyhive' ),
421 'callback' => 'PH_Meta_Box_Property_Owner::output',
422 'screen' => 'property',
423 'context' => 'normal',
424 'priority' => 'high'
425 );
426 }
427 $meta_boxes[15] = array(
428 'id' => 'propertyhive-property-record-details',
429 'title' => __( 'Record Details', 'propertyhive' ),
430 'callback' => 'PH_Meta_Box_Property_Record_Details::output',
431 'screen' => 'property',
432 'context' => 'normal',
433 'priority' => 'high'
434 );
435 $meta_boxes[20] = array(
436 'id' => 'propertyhive-property-coordinates',
437 'title' => __( 'Property Location', 'propertyhive' ),
438 'callback' => 'PH_Meta_Box_Property_Coordinates::output',
439 'screen' => 'property',
440 'context' => 'normal',
441 'priority' => 'high'
442 );
443
444 $meta_boxes = apply_filters( 'propertyhive_property_summary_meta_boxes', $meta_boxes );
445 ksort($meta_boxes);
446
447 $ids = array();
448 foreach ($meta_boxes as $meta_box)
449 {
450 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
451 $ids[] = $meta_box['id'];
452 }
453
454 $tabs['tab_summary'] = array(
455 'name' => __( 'Summary', 'propertyhive' ),
456 'metabox_ids' => $ids,
457 'post_type' => 'property'
458 );
459
460
461 /* PROPERTY DETAILS META BOXES */
462 $meta_boxes = array();
463 $meta_boxes[5] = array(
464 'id' => 'propertyhive-property-department',
465 'title' => __( 'Property Department', 'propertyhive' ),
466 'callback' => 'PH_Meta_Box_Property_Department::output',
467 'screen' => 'property',
468 'context' => 'normal',
469 'priority' => 'high'
470 );
471 $meta_boxes[10] = array(
472 'id' => 'propertyhive-property-residential-sales-details',
473 'title' => __( 'Residential Sales Details', 'propertyhive' ),
474 'callback' => 'PH_Meta_Box_Property_Residential_Sales_Details::output',
475 'screen' => 'property',
476 'context' => 'normal',
477 'priority' => 'high'
478 );
479 $meta_boxes[15] = array(
480 'id' => 'propertyhive-property-residential-lettings-details',
481 'title' => __( 'Residential Lettings Details', 'propertyhive' ),
482 'callback' => 'PH_Meta_Box_Property_Residential_Lettings_Details::output',
483 'screen' => 'property',
484 'context' => 'normal',
485 'priority' => 'high'
486 );
487 $meta_boxes[20] = array(
488 'id' => 'propertyhive-property-residential-details',
489 'title' => __( 'Residential Details', 'propertyhive' ),
490 'callback' => 'PH_Meta_Box_Property_Residential_Details::output',
491 'screen' => 'property',
492 'context' => 'normal',
493 'priority' => 'high'
494 );
495 $meta_boxes[25] = array(
496 'id' => 'propertyhive-property-commercial-details',
497 'title' => __( 'Commercial Details', 'propertyhive' ),
498 'callback' => 'PH_Meta_Box_Property_Commercial_Details::output',
499 'screen' => 'property',
500 'context' => 'normal',
501 'priority' => 'high'
502 );
503
504 $meta_boxes = apply_filters( 'propertyhive_property_details_meta_boxes', $meta_boxes );
505 ksort($meta_boxes);
506
507 $ids = array();
508 foreach ($meta_boxes as $meta_box)
509 {
510 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
511 $ids[] = $meta_box['id'];
512 }
513
514 $tabs['tab_details'] = array(
515 'name' => __( 'Details', 'propertyhive' ),
516 'metabox_ids' => $ids,
517 'post_type' => 'property'
518 );
519
520 if ( get_post_meta( $post->ID, '_department', TRUE ) == 'commercial' && isset($post->post_parent) && $post->post_parent == 0 )
521 {
522 $meta_boxes = array();
523 $meta_boxes[5] = array(
524 'id' => 'propertyhive-property-commercial-units',
525 'title' => __( 'Commercial Units', 'propertyhive' ),
526 'callback' => 'PH_Meta_Box_Property_Commercial_Units::output',
527 'screen' => 'property',
528 'context' => 'normal',
529 'priority' => 'high'
530 );
531
532 $meta_boxes = apply_filters( 'propertyhive_property_commercial_units_meta_boxes', $meta_boxes );
533 ksort($meta_boxes);
534
535 $ids = array();
536 foreach ($meta_boxes as $meta_box)
537 {
538 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
539 $ids[] = $meta_box['id'];
540 }
541
542 $tabs['tab_units'] = array(
543 'name' => __( 'Units', 'propertyhive' ),
544 'metabox_ids' => $ids,
545 'post_type' => 'property'
546 );
547 }
548
549 /* PROPERTY MARKETING META BOXES */
550 $meta_boxes = array();
551 $meta_boxes[5] = array(
552 'id' => 'propertyhive-property-marketing',
553 'title' => __( 'Property Marketing', 'propertyhive' ),
554 'callback' => 'PH_Meta_Box_Property_Marketing::output',
555 'screen' => 'property',
556 'context' => 'normal',
557 'priority' => 'high'
558 );
559
560 $meta_boxes = apply_filters( 'propertyhive_property_marketing_meta_boxes', $meta_boxes );
561 ksort($meta_boxes);
562
563 $ids = array();
564 foreach ($meta_boxes as $meta_box)
565 {
566 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
567 $ids[] = $meta_box['id'];
568 }
569
570 $tabs['tab_marketing'] = array(
571 'name' => __( 'Marketing', 'propertyhive' ),
572 'metabox_ids' => $ids,
573 'post_type' => 'property'
574 );
575
576 /* PROPERTY DESCRIPTIONS META BOXES */
577 $meta_boxes = array();
578 $meta_boxes[5] = array(
579 'id' => 'propertyhive-property-features',
580 'title' => __( 'Property Features', 'propertyhive' ),
581 'callback' => 'PH_Meta_Box_Property_Features::output',
582 'screen' => 'property',
583 'context' => 'normal',
584 'priority' => 'high'
585 );
586 $meta_boxes[10] = array(
587 'id' => 'postexcerpt',
588 'title' => __( 'Property Summary Description', 'propertyhive' ),
589 'callback' => 'PH_Meta_Box_Property_Summary_Description::output',
590 'screen' => 'property',
591 'context' => 'normal',
592 'priority' => 'high'
593 );
594 $meta_boxes[15] = array(
595 'id' => 'propertyhive-property-rooms',
596 'title' => __( 'Property Rooms', 'propertyhive' ),
597 'callback' => 'PH_Meta_Box_Property_Rooms::output',
598 'screen' => 'property',
599 'context' => 'normal',
600 'priority' => 'high'
601 );
602 $meta_boxes[20] = array(
603 'id' => 'propertyhive-property-description',
604 'title' => __( 'Property Description', 'propertyhive' ),
605 'callback' => 'PH_Meta_Box_Property_Description::output',
606 'screen' => 'property',
607 'context' => 'normal',
608 'priority' => 'high'
609 );
610
611 $meta_boxes = apply_filters( 'propertyhive_property_descriptions_meta_boxes', $meta_boxes );
612 ksort($meta_boxes);
613
614 $ids = array();
615 foreach ($meta_boxes as $meta_box)
616 {
617 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
618 $ids[] = $meta_box['id'];
619 }
620
621 $tabs['tab_descriptions'] = array(
622 'name' => __( 'Descriptions', 'propertyhive' ),
623 'metabox_ids' => $ids,
624 'post_type' => 'property'
625 );
626
627 /* PROPERTY MEDIA META BOXES */
628 $meta_boxes = array();
629 $meta_boxes[5] = array(
630 'id' => 'propertyhive-property-photos',
631 'title' => __( 'Property Photos', 'propertyhive' ),
632 'callback' => 'PH_Meta_Box_Property_Photos::output',
633 'screen' => 'property',
634 'context' => 'normal',
635 'priority' => 'high'
636 );
637 $meta_boxes[10] = array(
638 'id' => 'propertyhive-property-floorplans',
639 'title' => __( 'Property Floorplans', 'propertyhive' ),
640 'callback' => 'PH_Meta_Box_Property_Floorplans::output',
641 'screen' => 'property',
642 'context' => 'normal',
643 'priority' => 'high'
644 );
645 $meta_boxes[15] = array(
646 'id' => 'propertyhive-property-brochures',
647 'title' => __( 'Property Brochures', 'propertyhive' ),
648 'callback' => 'PH_Meta_Box_Property_Brochures::output',
649 'screen' => 'property',
650 'context' => 'normal',
651 'priority' => 'high'
652 );
653 $meta_boxes[20] = array(
654 'id' => 'propertyhive-property-epcs',
655 'title' => __( 'Property EPCs', 'propertyhive' ),
656 'callback' => 'PH_Meta_Box_Property_Epcs::output',
657 'screen' => 'property',
658 'context' => 'normal',
659 'priority' => 'high'
660 );
661 $meta_boxes[25] = array(
662 'id' => 'propertyhive-property-virtual-tours',
663 'title' => __( 'Property Virtual Tours', 'propertyhive' ),
664 'callback' => 'PH_Meta_Box_Property_Virtual_Tours::output',
665 'screen' => 'property',
666 'context' => 'normal',
667 'priority' => 'high'
668 );
669
670 $meta_boxes = apply_filters( 'propertyhive_property_media_meta_boxes', $meta_boxes );
671 ksort($meta_boxes);
672
673 $ids = array();
674 foreach ($meta_boxes as $meta_box)
675 {
676 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
677 $ids[] = $meta_box['id'];
678 }
679
680 $tabs['tab_media'] = array(
681 'name' => __( 'Media', 'propertyhive' ),
682 'metabox_ids' => $ids,
683 'post_type' => 'property'
684 );
685
686 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'property' )
687 {
688 /* PROPERTY VIEWINGS META BOXES */
689 if ( get_option('propertyhive_module_disabled_viewings', '') != 'yes' )
690 {
691 $meta_boxes = array();
692 $meta_boxes[5] = array(
693 'id' => 'propertyhive-property-viewings',
694 'title' => __( 'Viewings', 'propertyhive' ),
695 'callback' => 'PH_Meta_Box_Property_Viewings::output',
696 'screen' => 'property',
697 'context' => 'normal',
698 'priority' => 'high'
699 );
700
701 $meta_boxes = apply_filters( 'propertyhive_property_viewings_meta_boxes', $meta_boxes );
702 ksort($meta_boxes);
703
704 $ids = array();
705 foreach ($meta_boxes as $meta_box)
706 {
707 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
708 $ids[] = $meta_box['id'];
709 }
710
711 $tabs['tab_viewings'] = array(
712 'name' => __( 'Viewings', 'propertyhive' ),
713 'metabox_ids' => $ids,
714 'post_type' => 'property',
715 'ajax_actions' => array( 'get_property_viewings_meta_box^' . wp_create_nonce( 'get_property_viewings_meta_box' ) ),
716 );
717 }
718
719 if ( get_option('propertyhive_module_disabled_offers_sales', '') != 'yes' )
720 {
721 if ( get_post_meta( $post->ID, '_department', TRUE ) == 'residential-sales' )
722 {
723 /* PROPERTY OFFERS META BOXES */
724 $meta_boxes = array();
725 $meta_boxes[5] = array(
726 'id' => 'propertyhive-property-offers',
727 'title' => __( 'Offers', 'propertyhive' ),
728 'callback' => 'PH_Meta_Box_Property_Offers::output',
729 'screen' => 'property',
730 'context' => 'normal',
731 'priority' => 'high'
732 );
733
734 $meta_boxes = apply_filters( 'propertyhive_property_offers_meta_boxes', $meta_boxes );
735 ksort($meta_boxes);
736
737 $ids = array();
738 foreach ($meta_boxes as $meta_box)
739 {
740 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
741 $ids[] = $meta_box['id'];
742 }
743
744 $tabs['tab_offers'] = array(
745 'name' => __( 'Offers', 'propertyhive' ),
746 'metabox_ids' => $ids,
747 'post_type' => 'property',
748 'ajax_actions' => array( 'get_property_offers_meta_box^' . wp_create_nonce( 'get_property_offers_meta_box' ) ),
749 );
750
751 /* PROPERTY SALES META BOXES */
752 $meta_boxes = array();
753 $meta_boxes[5] = array(
754 'id' => 'propertyhive-property-sales',
755 'title' => __( 'Sales', 'propertyhive' ),
756 'callback' => 'PH_Meta_Box_Property_Sales::output',
757 'screen' => 'property',
758 'context' => 'normal',
759 'priority' => 'high'
760 );
761
762 $meta_boxes = apply_filters( 'propertyhive_property_sales_meta_boxes', $meta_boxes );
763 ksort($meta_boxes);
764
765 $ids = array();
766 foreach ($meta_boxes as $meta_box)
767 {
768 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
769 $ids[] = $meta_box['id'];
770 }
771
772 $tabs['tab_sales'] = array(
773 'name' => __( 'Sales', 'propertyhive' ),
774 'metabox_ids' => $ids,
775 'post_type' => 'property',
776 'ajax_actions' => array( 'get_property_sales_meta_box^' . wp_create_nonce( 'get_property_sales_meta_box' ) ),
777 );
778 }
779 }
780 }
781
782 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'property' )
783 {
784 if ( get_option('propertyhive_module_disabled_enquiries', '') != 'yes' )
785 {
786 /* PROPERTY ENQUIRIES META BOXES */
787 $meta_boxes = array();
788 $meta_boxes[5] = array(
789 'id' => 'propertyhive-property-enquiries',
790 'title' => __( 'Enquiries', 'propertyhive' ),
791 'callback' => 'PH_Meta_Box_Property_Enquiries::output',
792 'screen' => 'property',
793 'context' => 'normal',
794 'priority' => 'high'
795 );
796
797 $meta_boxes = apply_filters( 'propertyhive_property_enquiries_meta_boxes', $meta_boxes );
798 ksort($meta_boxes);
799
800 $ids = array();
801 foreach ($meta_boxes as $meta_box)
802 {
803 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
804 $ids[] = $meta_box['id'];
805 }
806
807 $tabs['tab_enquiries'] = array(
808 'name' => __( 'Enquiries', 'propertyhive' ),
809 'metabox_ids' => $ids,
810 'post_type' => 'property'
811 );
812 }
813 }
814
815 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'property' )
816 {
817 add_meta_box( 'propertyhive-property-actions', __( 'Actions', 'propertyhive' ), 'PH_Meta_Box_Property_Actions::output', 'property', 'side' );
818 add_meta_box( 'propertyhive-property-notes', __( 'Property History &amp; Notes', 'propertyhive' ), 'PH_Meta_Box_Property_Notes::output', 'property', 'side' );
819 }
820
821 // CONTACT
822 $meta_boxes = array();
823 $meta_boxes[5] = array(
824 'id' => 'propertyhive-contact-correspondence-address',
825 'title' => __( 'Correspondence Address', 'propertyhive' ),
826 'callback' => 'PH_Meta_Box_Contact_Correspondence_Address::output',
827 'screen' => 'contact',
828 'context' => 'normal',
829 'priority' => 'high'
830 );
831 $meta_boxes[10] = array(
832 'id' => 'propertyhive-contact-contact-details',
833 'title' => __( 'Contact Details', 'propertyhive' ),
834 'callback' => 'PH_Meta_Box_Contact_Contact_Details::output',
835 'screen' => 'contact',
836 'context' => 'normal',
837 'priority' => 'high'
838 );
839
840 $meta_boxes = apply_filters( 'propertyhive_contact_details_meta_boxes', $meta_boxes );
841 ksort($meta_boxes);
842
843 $ids = array();
844 foreach ($meta_boxes as $meta_box)
845 {
846 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
847 $ids[] = $meta_box['id'];
848 }
849
850 $tabs['tab_contact_details'] = array(
851 'name' => __( 'Contact Details', 'propertyhive' ),
852 'metabox_ids' => $ids,
853 'post_type' => 'contact'
854 );
855
856 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'contact' )
857 {
858 add_meta_box( 'propertyhive-contact-relationships', __( 'Relationships', 'propertyhive' ), 'PH_Meta_Box_Contact_Relationships::output', 'contact', 'normal', 'high' );
859 $tabs['tab_contact_relationships'] = array(
860 'name' => __( 'Relationships', 'propertyhive' ),
861 'metabox_ids' => array('propertyhive-contact-relationships'),
862 'post_type' => 'contact'
863 );
864 }
865
866 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'contact' )
867 {
868 $show_viewings = false;
869 $show_offers = false;
870 $show_sales = false;
871
872 $contact_types = get_post_meta( $post->ID, '_contact_types', TRUE );
873 if ( is_array($contact_types) && in_array('applicant', $contact_types) )
874 {
875 $show_viewings = true;
876
877 $num_applicant_profiles = get_post_meta( $post->ID, '_applicant_profiles', TRUE );
878 if ( $num_applicant_profiles == '' )
879 {
880 $num_applicant_profiles = 0;
881 }
882
883 if ( $num_applicant_profiles > 0 )
884 {
885 for ( $i = 0; $i < $num_applicant_profiles; ++$i )
886 {
887 $applicant_profile = get_post_meta( $post->ID, '_applicant_profile_' . $i, TRUE );
888
889 if ( isset($applicant_profile['department']) && $applicant_profile['department'] == 'residential-sales' )
890 {
891 $show_offers = true;
892 $show_sales = true;
893 }
894 }
895 }
896 }
897 else
898 {
899 $args = array(
900 'post_type' => 'viewing',
901 'posts_per_page' => 1,
902 'fields' => 'ids',
903 'meta_query' => array(
904 array(
905 'key' => '_applicant_contact_id',
906 'value' => $post->ID
907 )
908 )
909 );
910 $viewing_query = new WP_Query( $args );
911 if ($viewing_query->have_posts())
912 {
913 $show_viewings = true;
914 }
915 wp_reset_postdata();
916
917 $args = array(
918 'post_type' => 'offer',
919 'posts_per_page' => 1,
920 'fields' => 'ids',
921 'meta_query' => array(
922 array(
923 'key' => '_applicant_contact_id',
924 'value' => $post->ID
925 )
926 )
927 );
928 $offer_query = new WP_Query( $args );
929 if ($offer_query->have_posts())
930 {
931 $show_offers = true;
932 }
933 wp_reset_postdata();
934
935 $args = array(
936 'post_type' => 'sale',
937 'posts_per_page' => 1,
938 'fields' => 'ids',
939 'meta_query' => array(
940 array(
941 'key' => '_applicant_contact_id',
942 'value' => $post->ID
943 )
944 )
945 );
946 $sale_query = new WP_Query( $args );
947 if ($sale_query->have_posts())
948 {
949 $show_sales = true;
950 }
951 wp_reset_postdata();
952 }
953
954 if ( get_option('propertyhive_module_disabled_viewings', '') != 'yes' )
955 {
956 if ( $show_viewings )
957 {
958 /* CONTACT VIEWINGS META BOXES */
959 add_meta_box( 'propertyhive-contact-viewings', __( 'Viewings', 'propertyhive' ), 'PH_Meta_Box_Contact_Viewings::output', 'contact', 'normal', 'high' );
960
961 $tabs['tab_viewings'] = array(
962 'name' => __( 'Viewings', 'propertyhive' ),
963 'metabox_ids' => array('propertyhive-contact-viewings'),
964 'post_type' => 'contact',
965 'ajax_actions' => array( 'get_contact_viewings_meta_box^' . wp_create_nonce( 'get_contact_viewings_meta_box' ) ),
966 );
967 }
968 }
969
970 if ( get_option('propertyhive_module_disabled_offers_sales', '') != 'yes' )
971 {
972 if ( $show_offers )
973 {
974 /* CONTACT OFFERS META BOXES */
975 add_meta_box( 'propertyhive-contact-offers', __( 'Offers', 'propertyhive' ), 'PH_Meta_Box_Contact_Offers::output', 'contact', 'normal', 'high' );
976
977 $tabs['tab_offers'] = array(
978 'name' => __( 'Offers', 'propertyhive' ),
979 'metabox_ids' => array('propertyhive-contact-offers'),
980 'post_type' => 'contact',
981 'ajax_actions' => array( 'get_contact_offers_meta_box^' . wp_create_nonce( 'get_contact_offers_meta_box' ) ),
982 );
983 }
984
985 if ( $show_sales )
986 {
987 /* CONTACT SALES META BOXES */
988 add_meta_box( 'propertyhive-contact-sales', __( 'Sales', 'propertyhive' ), 'PH_Meta_Box_Contact_Sales::output', 'contact', 'normal', 'high' );
989
990 $tabs['tab_sales'] = array(
991 'name' => __( 'Sales', 'propertyhive' ),
992 'metabox_ids' => array('propertyhive-contact-sales'),
993 'post_type' => 'contact',
994 'ajax_actions' => array( 'get_contact_sales_meta_box^' . wp_create_nonce( 'get_contact_sales_meta_box' ) ),
995 );
996 }
997 }
998 }
999
1000 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'contact' )
1001 {
1002
1003 add_meta_box( 'propertyhive-contact-actions', __( 'Actions', 'propertyhive' ), 'PH_Meta_Box_Contact_Actions::output', 'contact', 'side' );
1004
1005 add_meta_box( 'propertyhive-contact-notes', __( 'Contact History &amp; Notes', 'propertyhive' ), 'PH_Meta_Box_Contact_Notes::output', 'contact', 'side' );
1006 }
1007
1008 // ENQUIRY
1009 add_meta_box( 'propertyhive-enquiry-record-details', __( 'Record Details', 'propertyhive' ), 'PH_Meta_Box_Enquiry_Record_details::output', 'enquiry', 'normal', 'high' );
1010 add_meta_box( 'propertyhive-enquiry-details', __( 'Enquiry Details', 'propertyhive' ), 'PH_Meta_Box_Enquiry_details::output', 'enquiry', 'normal', 'high' );
1011 $tabs['tab_enquiry_details'] = array(
1012 'name' => __( 'Details', 'propertyhive' ),
1013 'metabox_ids' => array('propertyhive-enquiry-record-details', 'propertyhive-enquiry-details'),
1014 'post_type' => 'enquiry'
1015 );
1016
1017 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'enquiry' )
1018 {
1019 add_meta_box( 'propertyhive-enquiry-notes', __( 'Enquiry Notes', 'propertyhive' ), 'PH_Meta_Box_Enquiry_Notes::output', 'enquiry', 'side' );
1020 }
1021
1022 // APPRAISAL
1023 if (!isset($tabs)) $tabs = array();
1024
1025 /* APPRAISAL SUMMARY META BOXES */
1026 $meta_boxes = array();
1027 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'appraisal' )
1028 {
1029 $meta_boxes[5] = array(
1030 'id' => 'propertyhive-appraisal-details',
1031 'title' => __( 'Appraisal Details', 'propertyhive' ),
1032 'callback' => 'PH_Meta_Box_Appraisal_Details::output',
1033 'screen' => 'appraisal',
1034 'context' => 'normal',
1035 'priority' => 'high'
1036 );
1037 }
1038 $meta_boxes[10] = array(
1039 'id' => 'propertyhive-appraisal-event',
1040 'title' => __( 'Event Details', 'propertyhive' ),
1041 'callback' => 'PH_Meta_Box_Appraisal_Event::output',
1042 'screen' => 'appraisal',
1043 'context' => 'normal',
1044 'priority' => 'high'
1045 );
1046 $meta_boxes[15] = array(
1047 'id' => 'propertyhive-appraisal-property-owner',
1048 'title' => __( 'Property Owner Details', 'propertyhive' ),
1049 'callback' => 'PH_Meta_Box_Appraisal_Property_Owner::output',
1050 'screen' => 'appraisal',
1051 'context' => 'normal',
1052 'priority' => 'high'
1053 );
1054 $meta_boxes[20] = array(
1055 'id' => 'propertyhive-appraisal-property',
1056 'title' => __( 'Property Details', 'propertyhive' ),
1057 'callback' => 'PH_Meta_Box_Appraisal_Property::output',
1058 'screen' => 'appraisal',
1059 'context' => 'normal',
1060 'priority' => 'high'
1061 );
1062
1063 $meta_boxes = apply_filters( 'propertyhive_appraisal_summary_meta_boxes', $meta_boxes );
1064 ksort($meta_boxes);
1065
1066 $ids = array();
1067 foreach ($meta_boxes as $meta_box)
1068 {
1069 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
1070 $ids[] = $meta_box['id'];
1071 }
1072
1073 $tabs['tab_appraisal_summary'] = array(
1074 'name' => __( 'Summary', 'propertyhive' ),
1075 'metabox_ids' => $ids,
1076 'post_type' => 'appraisal'
1077 );
1078
1079 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'appraisal' )
1080 {
1081 add_meta_box( 'propertyhive-appraisal-actions', __( 'Actions', 'propertyhive' ), 'PH_Meta_Box_Appraisal_Actions::output', 'appraisal', 'side' );
1082 add_meta_box( 'propertyhive-appraisal-notes', __( 'Appraisal History &amp; Notes', 'propertyhive' ), 'PH_Meta_Box_Appraisal_Notes::output', 'appraisal', 'side' );
1083 }
1084
1085 // VIEWING
1086 if (!isset($tabs)) $tabs = array();
1087
1088 /* VIEWING SUMMARY META BOXES */
1089 $meta_boxes = array();
1090 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'viewing' )
1091 {
1092 $meta_boxes[5] = array(
1093 'id' => 'propertyhive-viewing-details',
1094 'title' => __( 'Viewing Details', 'propertyhive' ),
1095 'callback' => 'PH_Meta_Box_Viewing_Details::output',
1096 'screen' => 'viewing',
1097 'context' => 'normal',
1098 'priority' => 'high'
1099 );
1100 }
1101 $meta_boxes[10] = array(
1102 'id' => 'propertyhive-viewing-event',
1103 'title' => __( 'Event Details', 'propertyhive' ),
1104 'callback' => 'PH_Meta_Box_Viewing_Event::output',
1105 'screen' => 'viewing',
1106 'context' => 'normal',
1107 'priority' => 'high'
1108 );
1109 $meta_boxes[15] = array(
1110 'id' => 'propertyhive-viewing-applicant',
1111 'title' => __( 'Applicant Details', 'propertyhive' ),
1112 'callback' => 'PH_Meta_Box_Viewing_Applicant::output',
1113 'screen' => 'viewing',
1114 'context' => 'normal',
1115 'priority' => 'high'
1116 );
1117 $meta_boxes[20] = array(
1118 'id' => 'propertyhive-viewing-property',
1119 'title' => __( 'Property Details', 'propertyhive' ),
1120 'callback' => 'PH_Meta_Box_Viewing_Property::output',
1121 'screen' => 'viewing',
1122 'context' => 'normal',
1123 'priority' => 'high'
1124 );
1125
1126 $meta_boxes = apply_filters( 'propertyhive_viewing_summary_meta_boxes', $meta_boxes );
1127 ksort($meta_boxes);
1128
1129 $ids = array();
1130 foreach ($meta_boxes as $meta_box)
1131 {
1132 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
1133 $ids[] = $meta_box['id'];
1134 }
1135
1136 $tabs['tab_viewing_summary'] = array(
1137 'name' => __( 'Summary', 'propertyhive' ),
1138 'metabox_ids' => $ids,
1139 'post_type' => 'viewing'
1140 );
1141
1142 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'viewing' )
1143 {
1144 add_meta_box( 'propertyhive-viewing-actions', __( 'Actions', 'propertyhive' ), 'PH_Meta_Box_Viewing_Actions::output', 'viewing', 'side' );
1145 add_meta_box( 'propertyhive-viewing-notes', __( 'Viewing History &amp; Notes', 'propertyhive' ), 'PH_Meta_Box_Viewing_Notes::output', 'viewing', 'side' );
1146 }
1147
1148 // OFFER
1149 if (!isset($tabs)) $tabs = array();
1150
1151 /* OFFER SUMMARY META BOXES */
1152 $meta_boxes = array();
1153 $meta_boxes[5] = array(
1154 'id' => 'propertyhive-offer-details',
1155 'title' => __( 'Offer Details', 'propertyhive' ),
1156 'callback' => 'PH_Meta_Box_Offer_Details::output',
1157 'screen' => 'offer',
1158 'context' => 'normal',
1159 'priority' => 'high'
1160 );
1161 $meta_boxes[10] = array(
1162 'id' => 'propertyhive-offer-property',
1163 'title' => __( 'Property Details', 'propertyhive' ),
1164 'callback' => 'PH_Meta_Box_Offer_Property::output',
1165 'screen' => 'offer',
1166 'context' => 'normal',
1167 'priority' => 'high'
1168 );
1169 $meta_boxes[15] = array(
1170 'id' => 'propertyhive-offer-property-owner-solicitor',
1171 'title' => __( 'Property Owner Solicitor Details', 'propertyhive' ),
1172 'callback' => 'PH_Meta_Box_Offer_Property_Owner_Solicitor::output',
1173 'screen' => 'offer',
1174 'context' => 'normal',
1175 'priority' => 'high'
1176 );
1177 $meta_boxes[20] = array(
1178 'id' => 'propertyhive-offer-applicant',
1179 'title' => __( 'Applicant Details', 'propertyhive' ),
1180 'callback' => 'PH_Meta_Box_Offer_Applicant::output',
1181 'screen' => 'offer',
1182 'context' => 'normal',
1183 'priority' => 'high'
1184 );
1185 $meta_boxes[25] = array(
1186 'id' => 'propertyhive-offer-applicant-solicitor',
1187 'title' => __( 'Applicant Solicitor Details', 'propertyhive' ),
1188 'callback' => 'PH_Meta_Box_Offer_Applicant_Solicitor::output',
1189 'screen' => 'offer',
1190 'context' => 'normal',
1191 'priority' => 'high'
1192 );
1193
1194
1195 $meta_boxes = apply_filters( 'propertyhive_offer_summary_meta_boxes', $meta_boxes );
1196 ksort($meta_boxes);
1197
1198 $ids = array();
1199 foreach ($meta_boxes as $meta_box)
1200 {
1201 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
1202 $ids[] = $meta_box['id'];
1203 }
1204
1205 $tabs['tab_offer_summary'] = array(
1206 'name' => __( 'Summary', 'propertyhive' ),
1207 'metabox_ids' => $ids,
1208 'post_type' => 'offer'
1209 );
1210
1211 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'offer' )
1212 {
1213 add_meta_box( 'propertyhive-offer-actions', __( 'Actions', 'propertyhive' ), 'PH_Meta_Box_Offer_Actions::output', 'offer', 'side' );
1214 add_meta_box( 'propertyhive-offer-notes', __( 'Offer History &amp; Notes', 'propertyhive' ), 'PH_Meta_Box_Offer_Notes::output', 'offer', 'side' );
1215 }
1216
1217 // SALE
1218 if (!isset($tabs)) $tabs = array();
1219
1220 /* SALE SUMMARY META BOXES */
1221 $meta_boxes = array();
1222 $meta_boxes[5] = array(
1223 'id' => 'propertyhive-sale-details',
1224 'title' => __( 'Sale Details', 'propertyhive' ),
1225 'callback' => 'PH_Meta_Box_Sale_Details::output',
1226 'screen' => 'sale',
1227 'context' => 'normal',
1228 'priority' => 'high'
1229 );
1230 $meta_boxes[10] = array(
1231 'id' => 'propertyhive-sale-property',
1232 'title' => __( 'Property Details', 'propertyhive' ),
1233 'callback' => 'PH_Meta_Box_Sale_Property::output',
1234 'screen' => 'sale',
1235 'context' => 'normal',
1236 'priority' => 'high'
1237 );
1238 $meta_boxes[15] = array(
1239 'id' => 'propertyhive-sale-property-owner-solicitor',
1240 'title' => __( 'Property Owner Solicitor Details', 'propertyhive' ),
1241 'callback' => 'PH_Meta_Box_Sale_Property_Owner_Solicitor::output',
1242 'screen' => 'sale',
1243 'context' => 'normal',
1244 'priority' => 'high'
1245 );
1246 $meta_boxes[20] = array(
1247 'id' => 'propertyhive-sale-applicant',
1248 'title' => __( 'Applicant Details', 'propertyhive' ),
1249 'callback' => 'PH_Meta_Box_Sale_Applicant::output',
1250 'screen' => 'sale',
1251 'context' => 'normal',
1252 'priority' => 'high'
1253 );
1254 $meta_boxes[25] = array(
1255 'id' => 'propertyhive-sale-applicant-solicitor',
1256 'title' => __( 'Applicant Solicitor Details', 'propertyhive' ),
1257 'callback' => 'PH_Meta_Box_Sale_Applicant_Solicitor::output',
1258 'screen' => 'sale',
1259 'context' => 'normal',
1260 'priority' => 'high'
1261 );
1262
1263
1264 $meta_boxes = apply_filters( 'propertyhive_offer_summary_meta_boxes', $meta_boxes );
1265 ksort($meta_boxes);
1266
1267 $ids = array();
1268 foreach ($meta_boxes as $meta_box)
1269 {
1270 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
1271 $ids[] = $meta_box['id'];
1272 }
1273
1274 $tabs['tab_sale_summary'] = array(
1275 'name' => __( 'Summary', 'propertyhive' ),
1276 'metabox_ids' => $ids,
1277 'post_type' => 'sale'
1278 );
1279
1280 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'sale' )
1281 {
1282 add_meta_box( 'propertyhive-sale-actions', __( 'Actions', 'propertyhive' ), 'PH_Meta_Box_Sale_Actions::output', 'sale', 'side' );
1283 add_meta_box( 'propertyhive-sale-notes', __( 'Sale History &amp; Notes', 'propertyhive' ), 'PH_Meta_Box_Sale_Notes::output', 'sale', 'side' );
1284 }
1285
1286 $tabs = apply_filters( 'propertyhive_tabs', $tabs );
1287
1288 // Force order of meta boxes
1289 $meta_box_ids = array();
1290 if (
1291 in_array(
1292 get_post_type($post->ID),
1293 apply_filters( 'propertyhive_post_types_with_tabs', array('property', 'contact', 'enquiry', 'viewing', 'offer', 'sale') )
1294 )
1295 )
1296 {
1297 foreach ( $tabs as $tab_id => $tab_options)
1298 {
1299 if ( isset($tab_options['post_type']) && $tab_options['post_type'] == get_post_type($post->ID) )
1300 {
1301 $meta_box_ids = array_merge( $meta_box_ids, $tab_options['metabox_ids'] );
1302 }
1303 }
1304 }
1305
1306 if (!empty($meta_box_ids) )
1307 {
1308 $existing_meta_box_order = get_user_meta( get_current_user_id(), 'meta-box-order_' . get_post_type($post->ID), TRUE );
1309 if ( $existing_meta_box_order == '' )
1310 {
1311 $existing_meta_box_order = array();
1312 $existing_meta_box_order['side'] = '';
1313 $existing_meta_box_order['advanced'] = '';
1314 }
1315 $existing_meta_box_order['normal'] = implode(",", $meta_box_ids);
1316
1317 update_user_meta( get_current_user_id(), 'meta-box-order_' . get_post_type($post->ID), $existing_meta_box_order );
1318 }
1319
1320 // TO DO: move this so it works when in one column
1321 add_action( 'edit_form_after_title', array( $this, 'draw_meta_box_tabs' ), 31, 1);
1322 }
1323
1324 /**
1325 * Draw meta box tabs
1326 */
1327 public function draw_meta_box_tabs() {
1328
1329 global $post, $tabs;
1330
1331 if (
1332 !empty($tabs) &&
1333 in_array(
1334 $post->post_type,
1335 apply_filters( 'propertyhive_post_types_with_tabs', array('property', 'contact', 'enquiry', 'viewing', 'offer', 'sale') )
1336 )
1337 )
1338 {
1339 $meta_boxes_under_tabs = array();
1340
1341 $i = 0;
1342 echo '<div id="propertyhive_metabox_tabs" style="margin-top:15px">';
1343 foreach ($tabs as $tab_id => $tab)
1344 {
1345 if (isset($tab['post_type']) && $post->post_type == $tab['post_type'])
1346 {
1347 echo '<a href="#' . implode("|#", $tab['metabox_ids']) . '" id="' . $tab_id . '" class="button' . ( ($i == 0) ? ' button-primary' : '') . '"';
1348 if ( isset($tab['ajax_actions']) )
1349 {
1350 echo ' data-ajax-actions="' . implode("|", $tab['ajax_actions']) . '"';
1351 }
1352 echo '>' . $tab['name'] . '</a> ';
1353
1354 $meta_boxes_under_tabs[] = $tab['metabox_ids'];
1355
1356 ++$i;
1357 }
1358 }
1359 echo '</div><br>';
1360
1361 if (!empty($meta_boxes_under_tabs))
1362 {
1363 echo '
1364 <script>
1365 var meta_boxes_under_tabs = ' . json_encode($meta_boxes_under_tabs) . ';
1366
1367 var ajax_actions_executed = new Array();
1368
1369 jQuery(document).ready(function()
1370 {
1371 // Hide all on page load
1372 hide_meta_box_tabs();
1373
1374 // Show first meta box
1375 //jQuery(\'#\' + meta_boxes_under_tabs[0][0] + \'\').show();
1376 for (var i in meta_boxes_under_tabs[0])
1377 {
1378 jQuery(\'#\' + meta_boxes_under_tabs[0][i] + \'\').show();
1379 }
1380 //jQuery(\'#propertyhive_metabox_tabs a:first-child\').trigger(\'click\');
1381
1382 // Set first button as primary
1383 jQuery(\'#propertyhive_metabox_tabs a:first-child\').addClass(\'button-primary\');
1384
1385 // Hide meta boxes and show correct one when tab clicked
1386 jQuery(\'#propertyhive_metabox_tabs a\').click(function()
1387 {
1388 hide_meta_box_tabs();
1389
1390 var this_href = jQuery(this).attr(\'href\').split(\'|\');
1391
1392 for (var i in this_href)
1393 {
1394 jQuery(this_href[i]).show();
1395 }
1396
1397 jQuery(this).addClass(\'button-primary\');
1398
1399 ' . ( ( $post->post_type == 'property' ) ? 'if (jQuery(this).attr(\'id\') == \'tab_details\') { showHideDepartmentMetaBox(); }' : '' ) . '
1400 ' . ( ( $post->post_type == 'property' ) ? 'if (jQuery(this).attr(\'id\') == \'tab_descriptions\') { showHideRoomsMetaBox(); }' : '' ) . '
1401 ' . ( ( $post->post_type == 'property' ) ? 'if (jQuery(this).attr(\'id\') == \'tab_descriptions\') { showHideDescriptionsMetaBox(); }' : '' ) . '
1402
1403 if ( jQuery(this).attr(\'data-ajax-actions\') && jQuery(this).attr(\'data-ajax-actions\') != \'\' )
1404 {
1405 var ajax_actions = jQuery(this).attr(\'data-ajax-actions\').split(\'|\');
1406
1407 for ( var i in ajax_actions )
1408 {
1409 var ajax_action = ajax_actions[i].split(\'^\');
1410
1411 jQuery(\'#\' + ajax_action[0].replace(\'get_\', \'propertyhive_\')).html(\'Loading...\');
1412
1413 //if () // only do action once
1414 //{
1415 var data = {
1416 action: \'propertyhive_\' + ajax_action[0],
1417 post_id: ' . $post->ID . ',
1418 security: ajax_action[1]
1419 }
1420
1421 jQuery.post( \'' . admin_url('admin-ajax.php') . '\', data, function(response)
1422 {
1423 jQuery(\'#\' + ajax_action[0].replace(\'get_\', \'propertyhive_\')).html(response);
1424 activateTipTip();
1425 }, \'html\');
1426 //}
1427 }
1428 }
1429
1430 return false;
1431 });
1432
1433 // Set default tab if hash set
1434 if (window.location.hash != \'\')
1435 {
1436 jQuery("#propertyhive_metabox_tabs a[href=\'" + window.location.hash + "\']").trigger(\'click\');
1437 }
1438 });
1439
1440 function hide_meta_box_tabs()
1441 {
1442 for (var i in meta_boxes_under_tabs)
1443 {
1444 for (var j in meta_boxes_under_tabs[i])
1445 {
1446 jQuery(\'#\' + meta_boxes_under_tabs[i][j] + \'\').hide();
1447 }
1448 }
1449
1450 jQuery(\'#propertyhive_metabox_tabs a\').removeClass(\'button-primary\');
1451 }
1452 </script>
1453 ';
1454 }
1455 }
1456
1457 }
1458
1459 /**
1460 * Remove bloat
1461 */
1462 public function remove_meta_boxes() {
1463 //remove_meta_box( 'submitdiv', 'property', 'side' );
1464 remove_meta_box( 'postexcerpt', 'property', 'normal' );
1465 remove_meta_box( 'pageparentdiv', 'property', 'side' );
1466 remove_meta_box( 'commentstatusdiv', 'property', 'normal' );
1467 remove_meta_box( 'commentstatusdiv', 'property', 'side' );
1468 remove_meta_box( 'commentsdiv', 'product', 'normal' );
1469 }
1470
1471 /**
1472 * Rename core meta boxes
1473 */
1474 public function rename_meta_boxes() {
1475 global $post;
1476
1477 // Comments/Reviews
1478 if ( isset( $post ) && ( 'publish' == $post->post_status || 'private' == $post->post_status ) ) {
1479 //remove_meta_box( 'commentsdiv', 'product', 'normal' );
1480
1481 //add_meta_box( 'commentsdiv', __( 'Reviews', 'propertyhive' ), 'post_comment_meta_box', 'product', 'normal' );
1482 }
1483 }
1484
1485 /**
1486 * Check if we're saving, then trigger an action based on the post type
1487 *
1488 * @param int $post_id
1489 * @param object $post
1490 */
1491 public function save_meta_boxes( $post_id, $post ) {
1492 // $post_id and $post are required
1493 if ( empty( $post_id ) || empty( $post ) ) {
1494 return;
1495 }
1496
1497 // Dont' save meta boxes for revisions or autosaves
1498 if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
1499 return;
1500 }
1501
1502 // Check the nonce
1503 if ( empty( $_POST['propertyhive_meta_nonce'] ) || ! wp_verify_nonce( $_POST['propertyhive_meta_nonce'], 'propertyhive_save_data' ) ) {
1504 return;
1505 }
1506
1507 // Check the post being saved == the $post_id to prevent triggering this call for other save_post events
1508 if ( empty( $_POST['post_ID'] ) || $_POST['post_ID'] != $post_id ) {
1509 return;
1510 }
1511
1512 // Check user has permission to edit
1513 if ( ! current_user_can( 'edit_post', $post_id ) ) {
1514 return;
1515 }
1516
1517 // Check the post type
1518 if (
1519 ! in_array(
1520 $post->post_type,
1521 apply_filters( 'propertyhive_post_types_with_tabs', array('property', 'contact', 'enquiry', 'appraisal', 'viewing', 'offer', 'sale') )
1522 )
1523 ) {
1524 return;
1525 }
1526
1527 if ( isset($_POST['post_parent']) && $_POST['post_parent'] != '' && $_POST['post_parent'] != '0' )
1528 {
1529 global $wpdb;
1530
1531 $wpdb->update( $wpdb->posts, array( 'post_parent' => (int)$_POST['post_parent'] ), array( 'ID' => $post_id ) );
1532 }
1533
1534 do_action( 'propertyhive_process_' . $post->post_type . '_meta', $post_id, $post );
1535 }
1536
1537 }
1538
1539 new PH_Admin_Meta_Boxes();
1540
1541 }