1: <?php
2: /**
3: * Contact Functions
4: *
5: * @package EPL
6: * @subpackage Admin/Contacts
7: * @copyright Copyright (c) 2020, Merv Barrett
8: * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9: * @since 3.0
10: */
11:
12: // Exit if accessed directly.
13: if ( ! defined( 'ABSPATH' ) ) {
14: exit;
15: }
16:
17: // phpcs:disable WordPress.Security.NonceVerification
18:
19: /**
20: * Contacts Page
21: *
22: * Renders the contacts page contents.
23: *
24: * @since 3.0
25: * @return void
26: */
27: function epl_contacts_page() {
28: $default_views = epl_contact_views();
29: $requested_view = isset( $_GET['view'] ) ? sanitize_text_field( wp_unslash( $_GET['view'] ) ) : 'contacts';
30: if ( array_key_exists( $requested_view, $default_views ) && function_exists( $default_views[ $requested_view ] ) ) {
31: epl_render_contact_view( $requested_view, $default_views );
32: } else {
33: epl_contacts_list();
34: }
35: }
36:
37: /**
38: * Register the views for contact management
39: *
40: * @since 3.0
41: * @return array Array of views and their callbacks
42: */
43: function epl_contact_views() {
44:
45: $views = array();
46: return apply_filters( 'epl_contact_views', $views );
47: }
48:
49: /**
50: * Register the tabs for contact management
51: *
52: * @since 3.0
53: * @return array Array of tabs for the contact
54: */
55: function epl_contact_tabs() {
56:
57: $tabs = array();
58: return apply_filters( 'epl_contact_tabs', $tabs );
59: }
60:
61: /**
62: * List table of contacts
63: *
64: * @since 3.0
65: * @return void
66: */
67: function epl_contacts_list() {
68: global $epl_contacts_table;
69: $epl_contacts_table->prepare_items();
70:
71: ?>
72: <div class="wrap">
73: <h2><?php esc_html_e( 'Contacts', 'easy-property-listings' ); ?>
74: <a class="add-new-h2" href="<?php echo esc_url( admin_url( 'admin.php?page=epl-contacts&view=new-contact' ) ); ?>"><?php esc_html_e( 'Add New', 'easy-property-listings' ); ?></a>
75: <a class="add-new-h2 epl-contact-tags-page" href="<?php echo esc_url( admin_url( 'admin.php?page=epl-contacts&view=all_tags' ) ); ?>"><?php esc_html_e( 'Tags', 'easy-property-listings' ); ?></a>
76: </h2>
77: <?php do_action( 'epl_contacts_table_top' ); ?>
78: <form id="epl-contacts-filter" method="get" action="<?php echo esc_url( admin_url( 'admin.php?page=epl-contacts' ) ); ?>">
79: <?php
80: $epl_contacts_table->search_box( esc_html__( 'Search Contacts', 'easy-property-listings' ), 'epl-contacts' );
81: $epl_contacts_table->display();
82: ?>
83: <input type="hidden" name="page" value="epl-contacts" />
84: <input type="hidden" name="view" value="contacts" />
85: </form>
86: <?php do_action( 'epl_contacts_table_bottom' ); ?>
87: </div>
88: <?php
89: }
90:
91: /**
92: * Renders the contact view wrapper
93: *
94: * @since 3.0
95: * @param string $view The View being requested.
96: * @param array $callbacks The Registered views and their callback functions.
97: * @return void
98: */
99: function epl_render_contact_view( $view, $callbacks ) {
100:
101: $render = true;
102:
103: if ( ! is_admin() || ! epl_contact_access() ) {
104: epl_set_error( 'epl-no-access', esc_html__( 'You are not permitted to view this data.', 'easy-property-listings' ) );
105: $render = false;
106: }
107: if ( 'new-contact' === $view || 'all_tags' === $view ) {
108: $callbacks[ $view ]();
109: return;
110: }
111:
112: if ( ! isset( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) {
113: epl_set_error( 'epl-invalid_contact', esc_html__( 'Invalid Contact ID Provided.', 'easy-property-listings' ) );
114: $render = false;
115: }
116:
117: $contact_id = (int) $_GET['id'];
118: $contact = new EPL_Contact( $contact_id );
119:
120: if ( empty( $contact->ID ) ) {
121: epl_set_error( 'epl-invalid_contact', esc_html__( 'Invalid Contact ID Provided.', 'easy-property-listings' ) );
122: $render = false;
123: }
124:
125: $contact_tabs = epl_contact_tabs();
126: ?>
127:
128: <div class='wrap'>
129: <h2><?php esc_html_e( 'Contact Details', 'easy-property-listings' ); ?></h2>
130: <?php if ( epl_get_errors() ) : ?>
131: <div class="error settings-error">
132: <?php epl_print_errors(); ?>
133: </div>
134: <?php endif; ?>
135:
136: <?php if ( $contact && $render ) : ?>
137:
138: <div id="epl-item-tab-wrapper" class="contact-tab-wrapper">
139: <ul id="epl-item-tab-wrapper-list" class="ustomer-tab-wrapper-list">
140: <?php foreach ( $contact_tabs as $key => $tab ) : ?>
141: <?php $active = $key === $view ? true : false; ?>
142: <?php $class = $active ? 'active' : 'inactive'; ?>
143:
144: <?php if ( ! $active ) : ?>
145: <a title="<?php echo esc_attr( $tab['title'] ); ?>" aria-label="<?php echo esc_attr( $tab['title'] ); ?>" href="<?php echo esc_url( admin_url( 'admin.php?page=epl-contacts&view=' . $key . '&id=' . $contact->ID ) ); ?>">
146: <?php endif; ?>
147:
148: <li class="<?php echo sanitize_html_class( $class ); ?>"><span class="dashicons <?php echo sanitize_html_class( $tab['dashicon'] ); ?>"></span></li>
149:
150: <?php if ( ! $active ) : ?>
151: </a>
152: <?php endif; ?>
153:
154: <?php endforeach; ?>
155: </ul>
156: </div>
157:
158: <div id="epl-item-card-wrapper" class="epl-contact-card-wrapper" style="float: left">
159: <?php $callbacks[ $view ]( $contact ); ?>
160: </div>
161:
162: <?php endif; ?>
163:
164: </div>
165: <?php
166: }
167:
168: /**
169: * Contacts Tags UI
170: *
171: * @since 3.0
172: * @return void
173: */
174: function epl_all_tags_view() {
175: include_once 'contact-tags-ui.php';
176: }
177:
178: /**
179: * Create a contact
180: *
181: * @since 3.0
182: * @return void
183: */
184: function epl_new_contact_view() {
185: ?>
186:
187: <?php
188: if ( isset( $_GET['id'] ) ) {
189: $redirect = admin_url( 'admin.php?page=epl-contacts&view=meta&id=' . intval( wp_unslash( $_GET['id'] ) ) );
190: wp_safe_redirect( $redirect );
191: exit();
192: }
193: ?>
194: <div class='wrap'>
195: <h2><?php esc_html_e( 'Add Contact', 'easy-property-listings' ); ?></h2>
196: <?php if ( epl_get_errors() ) : ?>
197: <div class="error settings-error">
198: <?php epl_print_errors(); ?>
199: </div>
200: <?php endif; ?>
201:
202: <div id="epl-item-tab-wrapper" class="contact-tab-wrapper">
203: </div>
204:
205: <div id="epl-item-card-wrapper" class="epl-contact-card-wrapper" style="float: left">
206:
207: <div class="epl-info-wrapper epl-contact-section">
208: <?php
209: $args = array(
210: 'post_type' => 'epl_contact',
211: 'post_status' => 'auto-draft',
212: 'post_title' => esc_html__( 'Contact Name', 'easy-property-listings' ),
213: );
214: $contact_id = wp_insert_post( $args );
215: if ( $contact_id ) :
216: ?>
217:
218: <form id="epl-meta-contact-form" method="post" action="<?php echo esc_url( admin_url( 'admin.php?page=epl-contacts&view=new-contact&id=' . $contact_id ) ); ?>">
219:
220: <div class="epl-contact-info epl-meta-contact epl-admin-new-contact">
221: <?php do_action( 'epl_new_contact_fields' ); ?>
222:
223: <?php
224: $contact = new EPL_Contact( $contact_id );
225: $contact_meta_fields = new EPL_FORM_BUILDER();
226: $contact_fields = apply_filters(
227: 'epl_contact_new_fields',
228: array(
229:
230: array(
231: 'name' => 'title',
232: 'label' => esc_html__( 'Summary', 'easy-property-listings' ),
233: 'type' => 'text',
234: 'maxlength' => '60',
235: 'value' => $contact->name,
236: ),
237: array(
238: 'name' => 'first_name',
239: 'label' => esc_html__( 'First Name', 'easy-property-listings' ),
240: 'type' => 'text',
241: 'maxlength' => '60',
242: 'value' => $contact->get_meta( 'contact_first_name' ),
243: ),
244: array(
245: 'name' => 'last_name',
246: 'label' => esc_html__( 'Last Name', 'easy-property-listings' ),
247: 'type' => 'text',
248: 'maxlength' => '60',
249: 'value' => $contact->get_meta( 'contact_last_name' ),
250: ),
251: array(
252: 'name' => 'email',
253: 'label' => esc_html__( 'Email *', 'easy-property-listings' ),
254: 'type' => 'email',
255: 'maxlength' => '60',
256: 'value' => $contact->get_primary_email( $contact->ID ),
257: ),
258: array(
259: 'name' => 'phone',
260: 'label' => esc_html__( 'Phone', 'easy-property-listings' ),
261: 'type' => 'text',
262: 'maxlength' => '60',
263: 'value' => '',
264: ),
265: )
266: );
267:
268: $contact_meta_fields->add_fields( $contact_fields );
269: $contact_meta_fields->render_form();
270: ?>
271: <span style="color:#f00; text-align:right;">
272: <?php esc_html_e( '* Required Fields', 'easy-property-listings' ); ?>
273: </span>
274:
275: <span id="epl-contact-edit-actions">
276: <input type="hidden" name="contact_id" value="<?php echo esc_attr( $contact->ID ); ?>" />
277: <input type="hidden" name="ID" value="<?php echo esc_attr( $contact->ID ); ?>" />
278: <?php wp_nonce_field( 'new-contact', '_wpnonce', false, true ); ?>
279: <input type="hidden" name="epl_action" value="new-contact" />
280: <input type="submit" id="epl-new-contact" class="button-primary" value="<?php esc_html_e( 'Create', 'easy-property-listings' ); ?>" />
281: </span>
282:
283: </div>
284: </form>
285: <?php endif; ?>
286: </div>
287: </div>
288: </div>
289: <?php
290: }
291:
292: /**
293: * View a contact
294: *
295: * @param [type] $contact The Contact object being displayed.
296: * @since 3.0
297: * @return void
298: */
299: function epl_contacts_view( $contact ) {
300:
301: $contact_edit_role = apply_filters( 'epl_edit_contacts_role', 'manage_options' );
302:
303: ?>
304:
305: <?php do_action( 'epl_contact_card_top', $contact ); ?>
306:
307: <?php do_action( 'epl_pre_contact_quick_edit_options', $contact ); ?>
308:
309: <?php do_action( 'epl_contact_action_menus', $contact ); ?>
310:
311: <?php do_action( 'epl_contact_entry_header', $contact ); ?>
312:
313: <?php do_action( 'epl_contact_assigned_tags', $contact ); ?>
314:
315: <?php do_action( 'epl_post_contact_quick_edit_options', $contact ); ?>
316:
317:
318: <div class="epl-info-wrapper epl-contact-section epl-contact-single-display">
319: <input type="hidden" id="epl_contact_id" value="<?php echo esc_attr( $contact->ID ); ?>"/>
320:
321: <div class="epl-item-info epl-contact-info">
322:
323: <?php do_action( 'epl_contact_avatar', $contact ); ?>
324:
325: <div class="epl-contact-id right">
326: <?php do_action( 'epl_contact_social_icons', $contact ); ?>
327: </div>
328:
329: <div class="epl-contact-main-wrapper left">
330: <?php do_action( 'epl_contact_contact_details', $contact ); ?>
331: </div>
332:
333: </div>
334: </div>
335:
336: <?php do_action( 'epl_contact_before_tables_wrapper', $contact ); ?>
337:
338: <?php do_action( 'epl_contact_background_info', $contact ); ?>
339:
340: <div id="epl-item-tables-wrapper" class="contact-tables-wrapper epl-contact-section">
341:
342: <?php do_action( 'epl_contact_before_tables', $contact ); ?>
343:
344: <?php do_action( 'epl_contact_recent_activities', $contact ); ?>
345:
346: <?php do_action( 'epl_contact_after_tables', $contact ); ?>
347:
348: </div>
349: <?php do_action( 'epl_contact_card_bottom', $contact ); ?>
350: <?php
351: }
352:
353: /**
354: * View the meta of a contact
355: *
356: * @param [type] $contact The Contact being displayed.
357: *
358: * @since 3.0
359: *
360: * @return void
361: */
362: function epl_contact_meta_view( $contact ) {
363:
364: $this_user = wp_get_current_user();
365: if ( ! is_admin() || ! epl_contact_access() ) {
366: wp_die( esc_html__( 'You do not have permission to see this page.', 'easy-property-listings' ) );
367: }
368: ?>
369:
370: <?php do_action( 'epl_contact_edit_top', $contact ); ?>
371:
372: <?php do_action( 'epl_pre_contact_quick_edit_options', $contact ); ?>
373:
374: <?php do_action( 'epl_contact_action_menus', $contact ); ?>
375:
376: <form id="epl-meta-contact-form" method="post" action="<?php echo esc_url( admin_url( 'admin.php?page=epl-contacts&view=meta&id=' . $contact->ID ) ); ?>">
377:
378: <?php do_action( 'epl_contact_entry_header_editable', $contact ); ?>
379:
380: <?php do_action( 'epl_contact_assigned_tags', $contact ); ?>
381:
382: <?php do_action( 'epl_post_contact_quick_edit_options', $contact ); ?>
383:
384: <div class="epl-info-wrapper epl-contact-section">
385:
386: <div class="epl-item-info epl-contact-info">
387:
388: <?php do_action( 'epl_contact_avatar', $contact ); ?>
389:
390: <div class="epl-contact-edit-main-wrapper left">
391:
392: <input type="hidden" id="epl_contact_id" value="<?php echo esc_attr( $contact->ID ); ?>"/>
393:
394: <div class="epl-contact-info epl-meta-contact">
395: <?php do_action( 'epl_contact_meta_fields', $contact ); ?>
396:
397: <?php
398: $contact_meta_fields = new EPL_FORM_BUILDER();
399: $contact_phones = $contact->get_meta( 'contact_phones' );
400: $contact_phones = array_filter( $contact_phones );
401: $contact_phone = isset( $contact_phones['phone'] ) ? $contact_phones['phone'] : '';
402:
403: $contact_emails = (array) $contact->get_meta( 'contact_emails' );
404: $contact_emails = array_filter( $contact_emails );
405: $contact_email = isset( $contact_emails['email'] ) ? $contact_emails['email'] : '';
406: $fields = array(
407: array(
408: 'class' => 'col-1 epl-inner-div',
409: 'id' => 'epl-contact-basic-details',
410: 'fields' => apply_filters(
411: 'epl_contact_basic_fields',
412: array(
413: array(
414: 'name' => 'contact_first_name',
415: 'type' => 'text',
416: 'maxlength' => '60',
417: 'value' => $contact->get_meta( 'contact_first_name' ),
418: ),
419:
420: array(
421: 'name' => 'contact_last_name',
422: 'type' => 'text',
423: 'maxlength' => '60',
424: 'value' => $contact->get_meta( 'contact_last_name' ),
425: ),
426: )
427: ),
428: ),
429: array(
430: 'label' => '',
431: 'class' => 'col-1 epl-inner-div',
432: 'id' => 'epl-contact-professional-details',
433: 'help' => esc_html__( 'Professional Details', 'easy-property-listings' ) . '<hr/>',
434: 'fields' => apply_filters(
435: 'epl_contact_professional_fields',
436: array(
437: array(
438: 'name' => 'contact_title',
439: 'label' => esc_html__( 'Title', 'easy-property-listings' ),
440: 'type' => 'text',
441: 'value' => $contact->get_meta( 'contact_title' ),
442: ),
443: array(
444: 'name' => 'contact_company',
445: 'label' => esc_html__( 'Company', 'easy-property-listings' ),
446: 'type' => 'text',
447: 'value' => $contact->get_meta( 'contact_company' ),
448: ),
449: )
450: ),
451: ),
452: array(
453: 'label' => '',
454: 'class' => 'col-1 epl-inner-div',
455: 'id' => 'epl-contact-contact-details',
456: 'help' => esc_html__( 'Contact Details', 'easy-property-listings' ) . '<hr/>',
457: 'fields' => apply_filters(
458: 'epl_contact_contact_fields',
459: array(
460: array(
461: 'name' => 'contact_phones[phone]',
462: 'label' => esc_html__( 'Phone', 'easy-property-listings' ),
463: 'type' => 'text',
464: 'class' => 'epl-contact-addable',
465: 'maxlength' => '60',
466: 'value' => $contact_phone,
467: ),
468:
469: array(
470: 'name' => 'contact_emails[email]',
471: 'label' => esc_html__( 'Email', 'easy-property-listings' ),
472: 'type' => 'email',
473: 'class' => 'epl-contact-addable-email',
474: 'maxlength' => '60',
475: 'value' => $contact_email,
476: ),
477:
478: array(
479: 'name' => 'contact_website',
480: 'label' => esc_html__( 'Website', 'easy-property-listings' ),
481: 'type' => 'text',
482: 'maxlength' => '60',
483: 'value' => $contact->get_meta( 'contact_website' ),
484: ),
485: ),
486: $contact
487: ),
488: ),
489: array(
490: 'label' => '',
491: 'class' => 'col-1 epl-inner-div',
492: 'id' => 'epl-contact-custom-details',
493: 'help' => esc_html__( 'Custom Fields', 'easy-property-listings' ) . '<hr/>',
494: 'fields' => apply_filters(
495: 'epl_contact_custom_fields',
496: array(
497: array(
498: 'name' => 'contact_referred_by',
499: 'label' => esc_html__( 'Referred By', 'easy-property-listings' ),
500: 'type' => 'text',
501: 'maxlength' => '60',
502: 'value' => $contact->get_meta( 'contact_referred_by' ),
503: ),
504: array(
505: 'name' => 'contact_custom_1',
506: 'label' => esc_html__( 'Custom Field 1', 'easy-property-listings' ),
507: 'type' => 'text',
508: 'maxlength' => '60',
509: 'value' => $contact->get_meta( 'contact_custom_1' ),
510: ),
511: array(
512: 'name' => 'contact_custom_2',
513: 'label' => esc_html__( 'Custom Field 2', 'easy-property-listings' ),
514: 'type' => 'text',
515: 'maxlength' => '60',
516: 'value' => $contact->get_meta( 'contact_custom_2' ),
517: ),
518: )
519: ),
520: ),
521: array(
522: 'label' => '',
523: 'class' => 'col-1 epl-inner-div',
524: 'id' => 'epl-contact-social-details',
525: 'help' => esc_html__( 'Social Networks', 'easy-property-listings' ) . '<hr/>',
526: 'fields' => apply_filters(
527: 'epl_contact_social_fields',
528: array(
529:
530: array(
531: 'name' => 'contact_facebook',
532: 'label' => esc_html__( 'Facebook', 'easy-property-listings' ),
533: 'type' => 'text',
534: 'maxlength' => '60',
535: 'value' => $contact->get_meta( 'contact_facebook' ),
536: ),
537: array(
538: 'name' => 'contact_twitter',
539: 'label' => esc_html__( 'Twitter', 'easy-property-listings' ),
540: 'type' => 'text',
541: 'maxlength' => '60',
542: 'value' => $contact->get_meta( 'contact_twitter' ),
543: ),
544: array(
545: 'name' => 'contact_google_plus',
546: 'label' => esc_html__( 'Google Plus', 'easy-property-listings' ),
547: 'type' => 'text',
548: 'maxlength' => '60',
549: 'value' => $contact->get_meta( 'contact_google_plus' ),
550: ),
551: array(
552: 'name' => 'contact_linked_in',
553: 'label' => esc_html__( 'Linked In', 'easy-property-listings' ),
554: 'type' => 'text',
555: 'maxlength' => '60',
556: 'value' => $contact->get_meta( 'contact_linked_in' ),
557: ),
558: )
559: ),
560: ),
561: array(
562: 'label' => '',
563: 'class' => 'col-1 epl-inner-div',
564: 'id' => 'epl-contact-address-details',
565: 'help' => esc_html__( 'Address', 'easy-property-listings' ) . '<hr/>',
566: 'fields' => array(
567: array(
568: 'name' => 'contact_street_number',
569: 'label' => esc_html__( 'Street Number', 'easy-property-listings' ),
570: 'type' => 'text',
571: 'maxlength' => '200',
572: 'value' => $contact->get_meta( 'contact_street_number' ),
573: ),
574: array(
575: 'name' => 'contact_street_name',
576: 'label' => esc_html__( 'Street Name', 'easy-property-listings' ),
577: 'type' => 'text',
578: 'maxlength' => '200',
579: 'value' => $contact->get_meta( 'contact_street_name' ),
580: ),
581: array(
582: 'name' => 'contact_suburb',
583: 'label' => esc_html__( 'Suburb', 'easy-property-listings' ),
584: 'type' => 'text',
585: 'maxlength' => '200',
586: 'value' => $contact->get_meta( 'contact_suburb' ),
587: ),
588: array(
589: 'name' => 'contact_state',
590: 'label' => esc_html__( 'State', 'easy-property-listings' ),
591: 'type' => 'text',
592: 'maxlength' => '200',
593: 'value' => $contact->get_meta( 'contact_state' ),
594: ),
595: array(
596: 'name' => 'contact_postcode',
597: 'label' => esc_html__( 'Postcode', 'easy-property-listings' ),
598: 'type' => 'text',
599: 'maxlength' => '200',
600: 'value' => $contact->get_meta( 'contact_postcode' ),
601: ),
602: array(
603: 'name' => 'contact_country',
604: 'label' => esc_html__( 'Country', 'easy-property-listings' ),
605: 'type' => 'text',
606: 'maxlength' => '200',
607: 'value' => $contact->get_meta( 'contact_country' ),
608: ),
609: ),
610: ),
611: array(
612: 'label' => '',
613: 'class' => 'col-1 epl-inner-div',
614: 'id' => 'epl-contact-wpuser-details',
615: 'help' => esc_html__( 'Author', 'easy-property-listings' ) . '<hr/>',
616: 'fields' => apply_filters(
617: 'epl_contact_wpuser_info_fields',
618: array(
619: array(
620: 'name' => 'contact_wp_user',
621: 'id' => 'epl_contact_wp_user',
622: 'type' => 'text',
623: 'autocomplete' => 'off',
624: 'value' => $contact->get_meta( 'contact_wp_user' ),
625: ),
626: array(
627: 'name' => 'contact_wp_user_id',
628: 'id' => 'epl_contact_wp_user_id',
629: 'type' => 'hidden',
630: 'value' => $contact->get_meta( 'contact_wp_user_id' ),
631: ),
632: )
633: ),
634: ),
635: array(
636: 'label' => '',
637: 'class' => 'col-1 epl-inner-div',
638: 'id' => 'epl-contact-bginfo-details',
639: 'help' => esc_html__( 'Background Info', 'easy-property-listings' ) . '<hr/>',
640: 'fields' => apply_filters(
641: 'epl_contact_background_info_fields',
642: array(
643: array(
644: 'name' => 'post_content',
645: 'type' => 'textarea',
646: 'value' => $contact->background_info,
647: ),
648: )
649: ),
650: ),
651: );
652: $contact_meta_fields->add_sections( $fields );
653: $contact_meta_fields->render_form();
654: ?>
655:
656: <span id="epl-contact-edit-actions">
657: <input type="hidden" name="contact_id" value="<?php echo esc_attr( $contact->ID ); ?>" />
658: <?php wp_nonce_field( 'meta-contact', '_wpnonce', false, true ); ?>
659: <input type="hidden" name="epl_action" value="meta-contact" />
660: <input type="submit" id="epl-meta-contact" class="button-primary" value="<?php esc_html_e( 'Update', 'easy-property-listings' ); ?>" />
661: </span>
662:
663: </div>
664:
665: </div>
666:
667: </div>
668:
669:
670: </div>
671: </form>
672: <?php
673: }
674:
675: /**
676: * View the notes of a contact
677: *
678: * @param EPL_Contact $contact The Contact being displayed.
679: *
680: * @since 3.0
681: * @since 3.5 Fix: Contacts, added accessibility labels to select elements & fix paginated link warnings when empty.
682: *
683: * @return void
684: */
685: function epl_contact_notes_view( $contact ) {
686:
687: $paged = isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) ? absint( wp_unslash( $_GET['paged'] ) ) : 1;
688: $paged = absint( $paged );
689: $note_count = $contact->get_notes_count();
690: $per_page = apply_filters( 'epl_contact_notes_per_page', 20 );
691: $total_pages = ceil( $note_count / $per_page );
692:
693: $contact_notes = $contact->get_notes( $per_page, $paged );
694: ?>
695:
696: <div id="epl-item-notes-wrapper">
697: <div class="epl-item-notes-header">
698: <?php echo wp_kses_post( get_avatar( $contact->email, 30 ) ); ?> <span><?php echo esc_attr( $contact->name ); ?></span>
699: </div>
700: <h3><?php esc_html_e( 'Notes', 'easy-property-listings' ); ?></h3>
701:
702: <?php if ( 1 === $paged ) : ?>
703: <div style="display: block; margin-bottom: 35px;">
704: <form id="epl-add-contact-note" method="post" action="<?php echo esc_url( admin_url( 'admin.php?page=epl-contacts&view=notes&id=' . $contact->ID ) ); ?>">
705: <textarea id="contact-note" name="contact_note" class="epl-contact-note-input" rows="10"></textarea>
706: <br />
707: <input type="hidden" id="epl-contact-id" name="contact_id" value="<?php echo esc_attr( $contact->ID ); ?>" />
708: <input type="hidden" name="epl_action" value="add-contact-note" />
709: <br />
710: <label class ="epl-contact-select-label" >
711: <select aria-label="<?php esc_attr_e( 'Select listing for note', 'easy-property-listings' ); ?>" class="epl-contact-note-select" id="contact-note-listing">
712: <option value=''><?php esc_html_e( 'Note for Listing', 'easy-property-listings' ); ?></option>
713: <?php
714: if ( ! empty( $contact->listing_ids ) ) {
715: foreach ( $contact->listing_ids as $listing_id ) {
716: echo '<option value="' . esc_attr( $listing_id ) . '">' . esc_html( get_the_title( $listing_id ) ) . '</option>';
717: }
718: }
719: ?>
720: </select>
721: </label>
722: <label class ="epl-contact-select-label" >
723: <select aria-label="<?php esc_attr_e( 'Select label for note', 'easy-property-listings' ); ?>" class="epl-contact-note-select" id="contact-activity-type">
724: <?php
725: foreach ( $contact->get_activity_types() as $act_key => $act_name ) {
726: echo '<option value="' . esc_attr( $act_key ) . '">' . esc_html( $act_name ) . '</option>';
727: }
728: ?>
729: </select>
730: </label>
731: <br />
732: <?php wp_nonce_field( 'add-contact-note', 'add_contact_note_nonce', true, true ); ?>
733: <input id="add-contact-note" class="right button-primary" type="submit" value="Add Note" />
734: </form>
735: </div>
736: <?php endif; ?>
737:
738: <?php
739: $pagination_args = array(
740: 'base' => '%_%',
741: 'format' => '?paged=%#%',
742: 'total' => $total_pages,
743: 'current' => $paged,
744: 'show_all' => true,
745: );
746: ?>
747:
748: <div id="epl-contact-notes">
749: <?php if ( count( $contact_notes ) > 0 ) : ?>
750: <?php foreach ( $contact_notes as $key => $note ) : ?>
751: <div class="epl-contact-note-wrapper dashboard-comment-wrap comment-item <?php echo esc_attr( $note->comment_type ); ?>" >
752: <span class="epl-note-content-meta">
753: <span class="epl-note-for-listing">
754: <?php
755: echo isset( $note->post_title ) ? esc_attr( $note->post_title ) : '';
756: ?>
757: </span>
758: <span class="epl-note-time">
759: <?php
760: echo esc_attr( date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ) );
761: ?>
762: </span>
763: </span>
764: <span class="epl-note-content-wrap">
765: <?php echo wp_kses_post( stripslashes( $note->comment_content ) ); ?>
766: </span>
767: </div>
768: <?php endforeach; ?>
769: <?php else : ?>
770: <div class="epl-no-contact-notes">
771: <?php esc_html_e( 'No Contact Notes', 'easy-property-listings' ); ?>
772: </div>
773: <?php endif; ?>
774: </div>
775: <div class="epl-note-pagination">
776: <?php
777: $paginated_links = paginate_links( $pagination_args );
778: if ( ! is_null( $paginated_links ) ) {
779: echo wp_kses_post( $paginated_links );
780: }
781: ?>
782: </div>
783:
784: </div>
785: <?php
786: }
787:
788: /**
789: * Contact Delete View
790: *
791: * @param [type] $contact The Contact being displayed.
792: *
793: * @since 3.0
794: *
795: * @return void
796: */
797: function epl_contacts_delete_view( $contact ) {
798: $contact_edit_role = apply_filters( 'epl_edit_contacts_role', 'manage_options' );
799: ?>
800:
801: <?php do_action( 'epl_contact_delete_top', $contact ); ?>
802:
803: <div class="epl-info-wrapper epl-contact-section">
804:
805: <form id="epl-delete-contact-form" method="post" action="<?php echo esc_url( admin_url( 'admin.php?page=epl-contacts&view=delete&id=' . $contact->ID ) ); ?>">
806:
807: <div class="epl-item-notes-header">
808: <?php echo wp_kses_post( get_avatar( $contact->email, 30 ) ); ?> <span><?php echo esc_attr( $contact->name ); ?></span>
809: </div>
810:
811: <div class="epl-contact-info epl-wrapper-delete-contact">
812:
813: <span class="epl-delete-contact-options">
814: <p>
815: <input type="checkbox" class="epl-checkbox epl-contact-delete-confirm" id="epl-contact-delete-confirm" name="epl-contact-delete-confirm">
816: <label for="epl-contact-delete-confirm"><?php esc_html_e( 'Are you sure you want to delete this contact?', 'easy-property-listings' ); ?></label>
817: </p>
818:
819: <?php do_action( 'epl_contact_delete_inputs', $contact ); ?>
820: </span>
821:
822: <span id="epl-contact-edit-actions">
823: <input type="hidden" name="contact_id" value="<?php echo esc_attr( $contact->ID ); ?>" />
824: <?php wp_nonce_field( 'delete-contact', '_wpnonce', false, true ); ?>
825: <input type="hidden" name="epl_action" value="delete-contact" />
826: <input type="submit" disabled="disabled" id="epl-delete-contact" class="button-primary" value="<?php esc_html_e( 'Delete Contact', 'easy-property-listings' ); ?>" />
827: <a id="epl-delete-contact-cancel" href="<?php echo esc_attr( admin_url( 'admin.php?page=epl-contacts&view=overview&id=' . $contact->ID ) ); ?>" class="delete"><?php esc_html_e( 'Cancel', 'easy-property-listings' ); ?></a>
828: </span>
829:
830: </div>
831: </form>
832: </div>
833: <?php
834: do_action( 'epl_contact_delete_bottom', $contact );
835: }
836:
837: /**
838: * View contact listings
839: *
840: * @param [type] $contact contact object.
841: *
842: * @since 3.0
843: */
844: function epl_contacts_listing_view( $contact ) {
845:
846: ?>
847:
848: <?php do_action( 'epl_contact_card_top', $contact ); ?>
849:
850: <?php do_action( 'epl_pre_contact_quick_edit_options', $contact ); ?>
851:
852: <?php do_action( 'epl_contact_action_menus', $contact ); ?>
853:
854: <?php do_action( 'epl_contact_entry_header', $contact ); ?>
855:
856: <?php do_action( 'epl_contact_assigned_tags', $contact ); ?>
857:
858: <?php do_action( 'epl_post_contact_quick_edit_options', $contact ); ?>
859:
860:
861: <div class="epl-info-wrapper epl-contact-section epl-contact-single-display">
862: <input type="hidden" id="epl_contact_id" value="<?php echo esc_attr( $contact->ID ); ?>"/>
863:
864: <div class="epl-item-info epl-contact-info">
865:
866: <?php do_action( 'epl_contact_avatar', $contact ); ?>
867:
868: <div class="epl-contact-id right">
869: <?php do_action( 'epl_contact_social_icons', $contact ); ?>
870: </div>
871:
872: <div class="epl-contact-main-wrapper left">
873: <?php do_action( 'epl_contact_contact_details', $contact ); ?>
874: </div>
875:
876: </div>
877:
878: </div>
879:
880: <?php do_action( 'epl_contact_before_tables_wrapper', $contact ); ?>
881:
882: <div id="epl-item-tables-wrapper" class="contact-tables-wrapper epl-contact-section">
883:
884: <?php do_action( 'epl_contact_before_tables', $contact ); ?>
885:
886: <?php do_action( 'epl_contact_recent_interests', $contact ); ?>
887:
888: <?php do_action( 'epl_contact_after_tables', $contact ); ?>
889:
890: </div>
891: <?php do_action( 'epl_contact_card_bottom', $contact ); ?>
892: <?php
893: }
894:
895: /**
896: * View contact listings
897: *
898: * @since 3.0
899: */
900: function epl_add_contact_screen_options() {
901: global $epl_contacts_table;
902: $option = 'per_page';
903: $args = array(
904: 'label' => esc_html__( 'Contacts', 'easy-property-listings' ),
905: 'default' => 10,
906: 'option' => 'contacts_per_page',
907: );
908: add_screen_option( $option, $args );
909: include_once dirname( __FILE__ ) . '/class-epl-contact-reports-table.php'; // phpcs:ignore Modernize.FunctionCalls.Dirname.FileConstant
910: $epl_contacts_table = new EPL_Contact_Reports_Table();
911: }
912:
913: /**
914: * Contact Table Options
915: *
916: * @param string $status Status.
917: * @param string $option Option.
918: * @param string $value Value.
919: *
920: * @return string
921: */
922: function epl_contact_table_set_option( $status, $option, $value ) {
923: return $value;
924: }
925:
926: /**
927: * Contact screen options
928: *
929: * @since 3.0
930: */
931: function epl_add_contact_screen_opts() {
932: global $epl_contact_page_hook;
933: add_action( "load-$epl_contact_page_hook", 'epl_add_contact_screen_options' );
934: add_filter( 'set-screen-option', 'epl_contact_table_set_option', 10, 3 );
935: }
936: add_action( 'admin_menu', 'epl_add_contact_screen_opts', 99 );
937: