| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | if ( ! defined( 'ABSPATH' ) ) { |
| 14: | exit; |
| 15: | } |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | function epl_reports_page() { |
| 26: | $current_page = admin_url( 'edit.php?post_type=download&page=epl-reports' ); |
| 27: | $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : 'reports'; |
| 28: | ?> |
| 29: | <div class="wrap"> |
| 30: | <h1 class="nav-tab-wrapper"> |
| 31: | <a href=" |
| 32: | <?php |
| 33: | echo esc_url( |
| 34: | add_query_arg( |
| 35: | array( |
| 36: | 'tab' => 'reports', |
| 37: | 'settings-updated' => false, |
| 38: | ), |
| 39: | $current_page |
| 40: | ) |
| 41: | ); |
| 42: | ?> |
| 43: | " class="nav-tab <?php echo 'reports' === $active_tab ? esc_attr( 'nav-tab-active' ) : ''; ?>"><?php esc_html_e( 'Reports', 'easy-property-listings' ); ?></a> |
| 44: | <?php do_action( 'epl_reports_tabs' ); ?> |
| 45: | </h1> |
| 46: | |
| 47: | <?php |
| 48: | do_action( 'epl_reports_page_top' ); |
| 49: | do_action( 'epl_reports_tab_' . $active_tab ); |
| 50: | do_action( 'epl_reports_page_bottom' ); |
| 51: | ?> |
| 52: | </div><!-- .wrap --> |
| 53: | <?php |
| 54: | } |
| 55: | |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | |
| 62: | function epl_reports_default_views() { |
| 63: | |
| 64: | $views = apply_filters( 'epl_report_views', epl_get_active_post_types() ); |
| 65: | |
| 66: | return $views; |
| 67: | } |
| 68: | |
| 69: | |
| 70: | |
| 71: | |
| 72: | |
| 73: | |
| 74: | |
| 75: | |
| 76: | |
| 77: | |
| 78: | |
| 79: | function epl_get_reporting_view( $default_value = 'property' ) { |
| 80: | |
| 81: | if ( ! isset( $_GET['view'] ) || ! in_array( $_GET['view'], array_keys( epl_reports_default_views() ), true ) ) { |
| 82: | $view = $default_value; |
| 83: | } else { |
| 84: | $view = sanitize_text_field( wp_unslash( $_GET['view'] ) ); |
| 85: | } |
| 86: | |
| 87: | return apply_filters( 'epl_get_reporting_view', $view ); |
| 88: | } |
| 89: | |
| 90: | |
| 91: | |
| 92: | |
| 93: | |
| 94: | |
| 95: | |
| 96: | function epl_reports_tab_reports() { |
| 97: | |
| 98: | if ( ! is_admin() || ! epl_reports_access() ) { |
| 99: | wp_die( esc_html__( 'You do not have permission to access this report', 'easy-property-listings' ), esc_html__( 'Error', 'easy-property-listings' ), array( 'response' => 403 ) ); |
| 100: | } |
| 101: | |
| 102: | $current_view = 'property'; |
| 103: | $views = epl_reports_default_views(); |
| 104: | |
| 105: | if ( isset( $_GET['view'] ) && array_key_exists( sanitize_text_field( wp_unslash( $_GET['view'] ) ), $views ) ) { |
| 106: | $current_view = sanitize_text_field( wp_unslash( $_GET['view'] ) ); |
| 107: | } |
| 108: | |
| 109: | do_action( 'epl_reports_view_' . $current_view ); |
| 110: | } |
| 111: | add_action( 'epl_reports_tab_reports', 'epl_reports_tab_reports' ); |
| 112: | |
| 113: | |
| 114: | |
| 115: | |
| 116: | |
| 117: | |
| 118: | |
| 119: | function epl_report_views() { |
| 120: | |
| 121: | if ( ! is_admin() || ! epl_reports_access() ) { |
| 122: | return; |
| 123: | } |
| 124: | |
| 125: | $views = epl_reports_default_views(); |
| 126: | $current_view = isset( $_GET['view'] ) ? sanitize_text_field( wp_unslash( $_GET['view'] ) ) : 'property'; |
| 127: | ?> |
| 128: | <form id="epl-reports-filter" method="get"> |
| 129: | <select id="epl-reports-view" name="view"> |
| 130: | <option value="-1"><?php esc_html_e( 'Report Type', 'easy-property-listings' ); ?></option> |
| 131: | <?php foreach ( $views as $view_id => $label ) : ?> |
| 132: | <option value="<?php echo esc_attr( $view_id ); ?>" <?php selected( $view_id, $current_view ); ?>><?php echo esc_attr( $label ); ?></option> |
| 133: | <?php endforeach; ?> |
| 134: | </select> |
| 135: | |
| 136: | <?php do_action( 'epl_report_view_actions' ); ?> |
| 137: | |
| 138: | <input type="hidden" name="page" value="epl-reports"/> |
| 139: | <?php submit_button( __( 'Show', 'easy-property-listings' ), 'secondary', 'submit', false ); ?> |
| 140: | </form> |
| 141: | <?php |
| 142: | do_action( 'epl_report_view_actions_after' ); |
| 143: | } |
| 144: | |
| 145: | |
| 146: | |
| 147: | |
| 148: | |
| 149: | |
| 150: | |
| 151: | function epl_reports_property() { |
| 152: | |
| 153: | if ( ! is_admin() || ! epl_reports_access() ) { |
| 154: | return; |
| 155: | } |
| 156: | ?> |
| 157: | <div class="tablenav top"> |
| 158: | <div class="alignleft actions"><?php epl_report_views(); ?></div> |
| 159: | </div> |
| 160: | <?php |
| 161: | epl_reports_graph( 'sold', 'current', '#e50000', '#a5df41' ); |
| 162: | } |
| 163: | add_action( 'epl_reports_view_property', 'epl_reports_property' ); |
| 164: | |
| 165: | |
| 166: | |
| 167: | |
| 168: | |
| 169: | |
| 170: | |
| 171: | function epl_reports_rental() { |
| 172: | |
| 173: | if ( ! is_admin() || ! epl_reports_access() ) { |
| 174: | return; |
| 175: | } |
| 176: | ?> |
| 177: | <div class="tablenav top"> |
| 178: | <div class="alignleft actions"><?php epl_report_views(); ?></div> |
| 179: | </div> |
| 180: | <?php |
| 181: | epl_reports_graph( 'leased', 'current', '#e50000', '#a5df41' ); |
| 182: | } |
| 183: | add_action( 'epl_reports_view_rental', 'epl_reports_rental' ); |
| 184: | |
| 185: | |
| 186: | |
| 187: | |
| 188: | |
| 189: | |
| 190: | |
| 191: | function epl_reports_land() { |
| 192: | |
| 193: | if ( ! is_admin() || ! epl_reports_access() ) { |
| 194: | return; |
| 195: | } |
| 196: | ?> |
| 197: | <div class="tablenav top"> |
| 198: | <div class="alignleft actions"><?php epl_report_views(); ?></div> |
| 199: | </div> |
| 200: | <?php |
| 201: | epl_reports_graph( 'sold', 'current', '#e50000', '#a5df41' ); |
| 202: | } |
| 203: | add_action( 'epl_reports_view_land', 'epl_reports_land' ); |
| 204: | |
| 205: | |
| 206: | |
| 207: | |
| 208: | |
| 209: | |
| 210: | |
| 211: | function epl_reports_commercial() { |
| 212: | |
| 213: | if ( ! is_admin() || ! epl_reports_access() ) { |
| 214: | return; |
| 215: | } |
| 216: | ?> |
| 217: | <div class="tablenav top"> |
| 218: | <div class="alignleft actions"><?php epl_report_views(); ?></div> |
| 219: | </div> |
| 220: | <?php |
| 221: | epl_reports_graph( 'sold', 'current', '#e50000', '#a5df41' ); |
| 222: | } |
| 223: | add_action( 'epl_reports_view_commercial', 'epl_reports_commercial' ); |
| 224: | |
| 225: | |
| 226: | |
| 227: | |
| 228: | |
| 229: | |
| 230: | |
| 231: | function epl_reports_commercial_land() { |
| 232: | |
| 233: | if ( ! is_admin() || ! epl_reports_access() ) { |
| 234: | return; |
| 235: | } |
| 236: | ?> |
| 237: | <div class="tablenav top"> |
| 238: | <div class="alignleft actions"><?php epl_report_views(); ?></div> |
| 239: | </div> |
| 240: | <?php |
| 241: | epl_reports_graph( 'sold', 'current', '#e50000', '#a5df41' ); |
| 242: | } |
| 243: | add_action( 'epl_reports_view_commercial_land', 'epl_reports_commercial_land' ); |
| 244: | |
| 245: | |
| 246: | |
| 247: | |
| 248: | |
| 249: | |
| 250: | |
| 251: | function epl_reports_business() { |
| 252: | |
| 253: | if ( ! is_admin() || ! epl_reports_access() ) { |
| 254: | return; |
| 255: | } |
| 256: | ?> |
| 257: | <div class="tablenav top"> |
| 258: | <div class="alignleft actions"><?php epl_report_views(); ?></div> |
| 259: | </div> |
| 260: | <?php |
| 261: | epl_reports_graph( 'sold', 'current', '#e50000', '#a5df41' ); |
| 262: | } |
| 263: | add_action( 'epl_reports_view_business', 'epl_reports_business' ); |
| 264: | |
| 265: | |
| 266: | |
| 267: | |
| 268: | |
| 269: | |
| 270: | |
| 271: | function epl_reports_rural() { |
| 272: | |
| 273: | if ( ! is_admin() || ! epl_reports_access() ) { |
| 274: | return; |
| 275: | } |
| 276: | ?> |
| 277: | <div class="tablenav top"> |
| 278: | <div class="alignleft actions"><?php epl_report_views(); ?></div> |
| 279: | </div> |
| 280: | <?php |
| 281: | epl_reports_graph( 'sold', 'current', '#e50000', '#a5df41' ); |
| 282: | } |
| 283: | add_action( 'epl_reports_view_rural', 'epl_reports_rural' ); |
| 284: | |
| 285: | |
| 286: | |
| 287: | |
| 288: | |
| 289: | |
| 290: | function epl_reports_access() { |
| 291: | $allowed = epl_get_option( 'min_reports_access' ); |
| 292: | $allowed = empty( $allowed ) ? 'level_10' : $allowed; |
| 293: | return current_user_can( $allowed ) ? true : false; |
| 294: | } |
| 295: | |