PluginProbe
Property Hive / 1.4.49
Property Hive v1.4.49
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.49, at includes/admin/post-types/class-ph-admin-meta-boxes.php

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