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

1,432 lines 59.9 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 // If an applicant show the 'actions' and therefore 'book viewing' functionality
972 $contact_types = get_post_meta( $post->ID, '_contact_types', TRUE );
973 if ( is_array($contact_types) && in_array('applicant', $contact_types) )
974 {
975 add_meta_box( 'propertyhive-contact-actions', __( 'Actions', 'propertyhive' ), 'PH_Meta_Box_Contact_Actions::output', 'contact', 'side' );
976 }
977 add_meta_box( 'propertyhive-contact-notes', __( 'Contact History &amp; Notes', 'propertyhive' ), 'PH_Meta_Box_Contact_Notes::output', 'contact', 'side' );
978 }
979
980 // ENQUIRY
981 add_meta_box( 'propertyhive-enquiry-record-details', __( 'Record Details', 'propertyhive' ), 'PH_Meta_Box_Enquiry_Record_details::output', 'enquiry', 'normal', 'high' );
982 add_meta_box( 'propertyhive-enquiry-details', __( 'Enquiry Details', 'propertyhive' ), 'PH_Meta_Box_Enquiry_details::output', 'enquiry', 'normal', 'high' );
983 $tabs['tab_enquiry_details'] = array(
984 'name' => __( 'Details', 'propertyhive' ),
985 'metabox_ids' => array('propertyhive-enquiry-record-details', 'propertyhive-enquiry-details'),
986 'post_type' => 'enquiry'
987 );
988
989 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'enquiry' )
990 {
991 add_meta_box( 'propertyhive-enquiry-notes', __( 'Enquiry Notes', 'propertyhive' ), 'PH_Meta_Box_Enquiry_Notes::output', 'enquiry', 'side' );
992 }
993
994 // VIEWING
995 if (!isset($tabs)) $tabs = array();
996
997 /* VIEWING SUMMARY META BOXES */
998 $meta_boxes = array();
999 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'viewing' )
1000 {
1001 $meta_boxes[5] = array(
1002 'id' => 'propertyhive-viewing-details',
1003 'title' => __( 'Viewing Details', 'propertyhive' ),
1004 'callback' => 'PH_Meta_Box_Viewing_Details::output',
1005 'screen' => 'viewing',
1006 'context' => 'normal',
1007 'priority' => 'high'
1008 );
1009 }
1010 $meta_boxes[10] = array(
1011 'id' => 'propertyhive-viewing-event',
1012 'title' => __( 'Event Details', 'propertyhive' ),
1013 'callback' => 'PH_Meta_Box_Viewing_Event::output',
1014 'screen' => 'viewing',
1015 'context' => 'normal',
1016 'priority' => 'high'
1017 );
1018 $meta_boxes[15] = array(
1019 'id' => 'propertyhive-viewing-applicant',
1020 'title' => __( 'Applicant Details', 'propertyhive' ),
1021 'callback' => 'PH_Meta_Box_Viewing_Applicant::output',
1022 'screen' => 'viewing',
1023 'context' => 'normal',
1024 'priority' => 'high'
1025 );
1026 $meta_boxes[20] = array(
1027 'id' => 'propertyhive-viewing-property',
1028 'title' => __( 'Property Details', 'propertyhive' ),
1029 'callback' => 'PH_Meta_Box_Viewing_Property::output',
1030 'screen' => 'viewing',
1031 'context' => 'normal',
1032 'priority' => 'high'
1033 );
1034
1035 $meta_boxes = apply_filters( 'propertyhive_viewing_summary_meta_boxes', $meta_boxes );
1036 ksort($meta_boxes);
1037
1038 $ids = array();
1039 foreach ($meta_boxes as $meta_box)
1040 {
1041 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
1042 $ids[] = $meta_box['id'];
1043 }
1044
1045 $tabs['tab_viewing_summary'] = array(
1046 'name' => __( 'Summary', 'propertyhive' ),
1047 'metabox_ids' => $ids,
1048 'post_type' => 'viewing'
1049 );
1050
1051 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'viewing' )
1052 {
1053 add_meta_box( 'propertyhive-viewing-actions', __( 'Actions', 'propertyhive' ), 'PH_Meta_Box_Viewing_Actions::output', 'viewing', 'side' );
1054 add_meta_box( 'propertyhive-viewing-notes', __( 'Viewing History &amp; Notes', 'propertyhive' ), 'PH_Meta_Box_Viewing_Notes::output', 'viewing', 'side' );
1055 }
1056
1057 // OFFER
1058 if (!isset($tabs)) $tabs = array();
1059
1060 /* OFFER SUMMARY META BOXES */
1061 $meta_boxes = array();
1062 $meta_boxes[5] = array(
1063 'id' => 'propertyhive-offer-details',
1064 'title' => __( 'Offer Details', 'propertyhive' ),
1065 'callback' => 'PH_Meta_Box_Offer_Details::output',
1066 'screen' => 'offer',
1067 'context' => 'normal',
1068 'priority' => 'high'
1069 );
1070 $meta_boxes[10] = array(
1071 'id' => 'propertyhive-offer-property',
1072 'title' => __( 'Property Details', 'propertyhive' ),
1073 'callback' => 'PH_Meta_Box_Offer_Property::output',
1074 'screen' => 'offer',
1075 'context' => 'normal',
1076 'priority' => 'high'
1077 );
1078 $meta_boxes[15] = array(
1079 'id' => 'propertyhive-offer-property-owner-solicitor',
1080 'title' => __( 'Property Owner Solicitor Details', 'propertyhive' ),
1081 'callback' => 'PH_Meta_Box_Offer_Property_Owner_Solicitor::output',
1082 'screen' => 'offer',
1083 'context' => 'normal',
1084 'priority' => 'high'
1085 );
1086 $meta_boxes[20] = array(
1087 'id' => 'propertyhive-offer-applicant',
1088 'title' => __( 'Applicant Details', 'propertyhive' ),
1089 'callback' => 'PH_Meta_Box_Offer_Applicant::output',
1090 'screen' => 'offer',
1091 'context' => 'normal',
1092 'priority' => 'high'
1093 );
1094 $meta_boxes[25] = array(
1095 'id' => 'propertyhive-offer-applicant-solicitor',
1096 'title' => __( 'Applicant Solicitor Details', 'propertyhive' ),
1097 'callback' => 'PH_Meta_Box_Offer_Applicant_Solicitor::output',
1098 'screen' => 'offer',
1099 'context' => 'normal',
1100 'priority' => 'high'
1101 );
1102
1103
1104 $meta_boxes = apply_filters( 'propertyhive_offer_summary_meta_boxes', $meta_boxes );
1105 ksort($meta_boxes);
1106
1107 $ids = array();
1108 foreach ($meta_boxes as $meta_box)
1109 {
1110 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
1111 $ids[] = $meta_box['id'];
1112 }
1113
1114 $tabs['tab_offer_summary'] = array(
1115 'name' => __( 'Summary', 'propertyhive' ),
1116 'metabox_ids' => $ids,
1117 'post_type' => 'offer'
1118 );
1119
1120 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'offer' )
1121 {
1122 add_meta_box( 'propertyhive-offer-actions', __( 'Actions', 'propertyhive' ), 'PH_Meta_Box_Offer_Actions::output', 'offer', 'side' );
1123 add_meta_box( 'propertyhive-offer-notes', __( 'Offer History &amp; Notes', 'propertyhive' ), 'PH_Meta_Box_Offer_Notes::output', 'offer', 'side' );
1124 }
1125
1126 // SALE
1127 if (!isset($tabs)) $tabs = array();
1128
1129 /* SALE SUMMARY META BOXES */
1130 $meta_boxes = array();
1131 $meta_boxes[5] = array(
1132 'id' => 'propertyhive-sale-details',
1133 'title' => __( 'Sale Details', 'propertyhive' ),
1134 'callback' => 'PH_Meta_Box_Sale_Details::output',
1135 'screen' => 'sale',
1136 'context' => 'normal',
1137 'priority' => 'high'
1138 );
1139 $meta_boxes[10] = array(
1140 'id' => 'propertyhive-sale-property',
1141 'title' => __( 'Property Details', 'propertyhive' ),
1142 'callback' => 'PH_Meta_Box_Sale_Property::output',
1143 'screen' => 'sale',
1144 'context' => 'normal',
1145 'priority' => 'high'
1146 );
1147 $meta_boxes[15] = array(
1148 'id' => 'propertyhive-sale-property-owner-solicitor',
1149 'title' => __( 'Property Owner Solicitor Details', 'propertyhive' ),
1150 'callback' => 'PH_Meta_Box_Sale_Property_Owner_Solicitor::output',
1151 'screen' => 'sale',
1152 'context' => 'normal',
1153 'priority' => 'high'
1154 );
1155 $meta_boxes[20] = array(
1156 'id' => 'propertyhive-sale-applicant',
1157 'title' => __( 'Applicant Details', 'propertyhive' ),
1158 'callback' => 'PH_Meta_Box_Sale_Applicant::output',
1159 'screen' => 'sale',
1160 'context' => 'normal',
1161 'priority' => 'high'
1162 );
1163 $meta_boxes[25] = array(
1164 'id' => 'propertyhive-sale-applicant-solicitor',
1165 'title' => __( 'Applicant Solicitor Details', 'propertyhive' ),
1166 'callback' => 'PH_Meta_Box_Sale_Applicant_Solicitor::output',
1167 'screen' => 'sale',
1168 'context' => 'normal',
1169 'priority' => 'high'
1170 );
1171
1172
1173 $meta_boxes = apply_filters( 'propertyhive_offer_summary_meta_boxes', $meta_boxes );
1174 ksort($meta_boxes);
1175
1176 $ids = array();
1177 foreach ($meta_boxes as $meta_box)
1178 {
1179 add_meta_box( $meta_box['id'], $meta_box['title'], $meta_box['callback'], $meta_box['screen'], $meta_box['context'], $meta_box['priority'] );
1180 $ids[] = $meta_box['id'];
1181 }
1182
1183 $tabs['tab_offer_summary'] = array(
1184 'name' => __( 'Summary', 'propertyhive' ),
1185 'metabox_ids' => $ids,
1186 'post_type' => 'sale'
1187 );
1188
1189 if ( $pagenow != 'post-new.php' && get_post_type($post->ID) == 'sale' )
1190 {
1191 add_meta_box( 'propertyhive-sale-actions', __( 'Actions', 'propertyhive' ), 'PH_Meta_Box_Sale_Actions::output', 'sale', 'side' );
1192 add_meta_box( 'propertyhive-sale-notes', __( 'Sale History &amp; Notes', 'propertyhive' ), 'PH_Meta_Box_Sale_Notes::output', 'sale', 'side' );
1193 }
1194
1195 $tabs = apply_filters( 'propertyhive_tabs', $tabs );
1196
1197 // Force order of meta boxes
1198 $meta_box_ids = array();
1199 if ( in_array(get_post_type($post->ID), array('property', 'contact', 'enquiry', 'viewing', 'offer', 'sale')) )
1200 {
1201 foreach ( $tabs as $tab_id => $tab_options)
1202 {
1203 if ( isset($tab_options['post_type']) && $tab_options['post_type'] == get_post_type($post->ID) )
1204 {
1205 $meta_box_ids = array_merge( $meta_box_ids, $tab_options['metabox_ids'] );
1206 }
1207 }
1208 }
1209 if (!empty($meta_box_ids) )
1210 {
1211 $existing_meta_box_order = get_user_meta( get_current_user_id(), 'meta-box-order_' . get_post_type($post->ID), TRUE );
1212 if ( $existing_meta_box_order == '' )
1213 {
1214 $existing_meta_box_order = array();
1215 $existing_meta_box_order['side'] = '';
1216 $existing_meta_box_order['advanced'] = '';
1217 }
1218 $existing_meta_box_order['normal'] = implode(",", $meta_box_ids);
1219
1220 update_user_meta( get_current_user_id(), 'meta-box-order_' . get_post_type($post->ID), $existing_meta_box_order );
1221 }
1222
1223 // TO DO: move this so it works when in one column
1224 add_action( 'edit_form_after_title', array( $this, 'draw_meta_box_tabs' ), 31, 1);
1225 }
1226
1227 /**
1228 * Draw meta box tabs
1229 */
1230 public function draw_meta_box_tabs() {
1231
1232 global $post, $tabs;
1233
1234 if (!empty($tabs) && in_array($post->post_type, array('property', 'contact', 'enquiry', 'viewing', 'offer', 'sale')))
1235 {
1236 $meta_boxes_under_tabs = array();
1237
1238 $i = 0;
1239 echo '<div id="propertyhive_metabox_tabs" style="margin-top:15px">';
1240 foreach ($tabs as $tab_id => $tab)
1241 {
1242 if (isset($tab['post_type']) && $post->post_type == $tab['post_type'])
1243 {
1244 echo '<a href="#' . implode("|#", $tab['metabox_ids']) . '" id="' . $tab_id . '" class="button' . ( ($i == 0) ? ' button-primary' : '') . '"';
1245 if ( isset($tab['ajax_actions']) )
1246 {
1247 echo ' data-ajax-actions="' . implode("|", $tab['ajax_actions']) . '"';
1248 }
1249 echo '>' . $tab['name'] . '</a> ';
1250
1251 $meta_boxes_under_tabs[] = $tab['metabox_ids'];
1252
1253 ++$i;
1254 }
1255 }
1256 echo '</div><br>';
1257
1258 if (!empty($meta_boxes_under_tabs))
1259 {
1260 echo '
1261 <script>
1262 var meta_boxes_under_tabs = ' . json_encode($meta_boxes_under_tabs) . ';
1263
1264 var ajax_actions_executed = new Array();
1265
1266 jQuery(document).ready(function()
1267 {
1268 // Hide all on page load
1269 hide_meta_box_tabs();
1270
1271 // Show first meta box
1272 //jQuery(\'#\' + meta_boxes_under_tabs[0][0] + \'\').show();
1273 for (var i in meta_boxes_under_tabs[0])
1274 {
1275 jQuery(\'#\' + meta_boxes_under_tabs[0][i] + \'\').show();
1276 }
1277 //jQuery(\'#propertyhive_metabox_tabs a:first-child\').trigger(\'click\');
1278
1279 // Set first button as primary
1280 jQuery(\'#propertyhive_metabox_tabs a:first-child\').addClass(\'button-primary\');
1281
1282 // Hide meta boxes and show correct one when tab clicked
1283 jQuery(\'#propertyhive_metabox_tabs a\').click(function()
1284 {
1285 hide_meta_box_tabs();
1286
1287 var this_href = jQuery(this).attr(\'href\').split(\'|\');
1288
1289 for (var i in this_href)
1290 {
1291 jQuery(this_href[i]).show();
1292 }
1293
1294 jQuery(this).addClass(\'button-primary\');
1295
1296 ' . ( ( $post->post_type == 'property' ) ? 'if (jQuery(this).attr(\'id\') == \'tab_details\') { showHideDepartmentMetaBox(); }' : '' ) . '
1297 ' . ( ( $post->post_type == 'property' ) ? 'if (jQuery(this).attr(\'id\') == \'tab_descriptions\') { showHideRoomsMetaBox(); }' : '' ) . '
1298 ' . ( ( $post->post_type == 'property' ) ? 'if (jQuery(this).attr(\'id\') == \'tab_descriptions\') { showHideDescriptionsMetaBox(); }' : '' ) . '
1299
1300 if ( jQuery(this).attr(\'data-ajax-actions\') && jQuery(this).attr(\'data-ajax-actions\') != \'\' )
1301 {
1302 var ajax_actions = jQuery(this).attr(\'data-ajax-actions\').split(\'|\');
1303
1304 for ( var i in ajax_actions )
1305 {
1306 var ajax_action = ajax_actions[i].split(\'^\');
1307
1308 jQuery(\'#\' + ajax_action[0].replace(\'get_\', \'propertyhive_\')).html(\'Loading...\');
1309
1310 //if () // only do action once
1311 //{
1312 var data = {
1313 action: \'propertyhive_\' + ajax_action[0],
1314 post_id: ' . $post->ID . ',
1315 security: ajax_action[1]
1316 }
1317
1318 jQuery.post( \'' . admin_url('admin-ajax.php') . '\', data, function(response)
1319 {
1320 jQuery(\'#\' + ajax_action[0].replace(\'get_\', \'propertyhive_\')).html(response);
1321 }, \'html\');
1322 //}
1323 }
1324 }
1325
1326 return false;
1327 });
1328
1329 // Set default tab if hash set
1330 if (window.location.hash != \'\')
1331 {
1332 jQuery("#propertyhive_metabox_tabs a[href=\'" + window.location.hash + "\']").trigger(\'click\');
1333 }
1334 });
1335
1336 function hide_meta_box_tabs()
1337 {
1338 for (var i in meta_boxes_under_tabs)
1339 {
1340 for (var j in meta_boxes_under_tabs[i])
1341 {
1342 jQuery(\'#\' + meta_boxes_under_tabs[i][j] + \'\').hide();
1343 }
1344 }
1345
1346 jQuery(\'#propertyhive_metabox_tabs a\').removeClass(\'button-primary\');
1347 }
1348 </script>
1349 ';
1350 }
1351 }
1352
1353 }
1354
1355 /**
1356 * Remove bloat
1357 */
1358 public function remove_meta_boxes() {
1359 //remove_meta_box( 'submitdiv', 'property', 'side' );
1360 remove_meta_box( 'postexcerpt', 'property', 'normal' );
1361 remove_meta_box( 'pageparentdiv', 'property', 'side' );
1362 remove_meta_box( 'commentstatusdiv', 'property', 'normal' );
1363 remove_meta_box( 'commentstatusdiv', 'property', 'side' );
1364 remove_meta_box( 'commentsdiv', 'product', 'normal' );
1365 }
1366
1367 /**
1368 * Rename core meta boxes
1369 */
1370 public function rename_meta_boxes() {
1371 global $post;
1372
1373 // Comments/Reviews
1374 if ( isset( $post ) && ( 'publish' == $post->post_status || 'private' == $post->post_status ) ) {
1375 //remove_meta_box( 'commentsdiv', 'product', 'normal' );
1376
1377 //add_meta_box( 'commentsdiv', __( 'Reviews', 'propertyhive' ), 'post_comment_meta_box', 'product', 'normal' );
1378 }
1379 }
1380
1381 /**
1382 * Check if we're saving, then trigger an action based on the post type
1383 *
1384 * @param int $post_id
1385 * @param object $post
1386 */
1387 public function save_meta_boxes( $post_id, $post ) {
1388 // $post_id and $post are required
1389 if ( empty( $post_id ) || empty( $post ) ) {
1390 return;
1391 }
1392
1393 // Dont' save meta boxes for revisions or autosaves
1394 if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
1395 return;
1396 }
1397
1398 // Check the nonce
1399 if ( empty( $_POST['propertyhive_meta_nonce'] ) || ! wp_verify_nonce( $_POST['propertyhive_meta_nonce'], 'propertyhive_save_data' ) ) {
1400 return;
1401 }
1402
1403 // Check the post being saved == the $post_id to prevent triggering this call for other save_post events
1404 if ( empty( $_POST['post_ID'] ) || $_POST['post_ID'] != $post_id ) {
1405 return;
1406 }
1407
1408 // Check user has permission to edit
1409 if ( ! current_user_can( 'edit_post', $post_id ) ) {
1410 return;
1411 }
1412
1413 // Check the post type
1414 if ( ! in_array( $post->post_type, array( 'property', 'contact', 'enquiry', 'viewing', 'offer', 'sale' ) ) ) {
1415 return;
1416 }
1417
1418 if ( isset($_POST['post_parent']) && $_POST['post_parent'] != '' && $_POST['post_parent'] != '0' )
1419 {
1420 global $wpdb;
1421
1422 $wpdb->update( $wpdb->posts, array( 'post_parent' => $_POST['post_parent'] ), array( 'ID' => $post_id ) );
1423 }
1424
1425 do_action( 'propertyhive_process_' . $post->post_type . '_meta', $post_id, $post );
1426 }
1427
1428 }
1429
1430 new PH_Admin_Meta_Boxes();
1431
1432 }