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

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