function display_item_content()
{
    global $wpdb, $bp;
    $types = listing_types();
    $current_user = wp_get_current_user();
    $user_id = $bp->displayed_user->id;
    // get records
    $data = get_option("bepro_listings");
    if (@$data["require_payment"]) {
        $items = $wpdb->get_results("SELECT geo.*, orders.status as order_status, orders.expires, wp_posts.post_title, wp_posts.post_status FROM " . $wpdb->prefix . BEPRO_LISTINGS_TABLE_NAME . " as geo \n\t\t\tLEFT JOIN " . $wpdb->prefix . "posts as wp_posts on wp_posts.ID = geo.post_id \n\t\t\tLEFT JOIN " . BEPRO_LISTINGS_ORDERS_TABLE_NAME . " AS orders on orders.bl_order_id = geo.bl_order_id WHERE wp_posts.post_status != 'trash' AND wp_posts.post_author = " . $user_id);
    } else {
        $items = $wpdb->get_results("SELECT geo.*, wp_posts.post_title, wp_posts.post_status FROM " . $wpdb->prefix . BEPRO_LISTINGS_TABLE_NAME . " as geo \n\t\t\tLEFT JOIN " . $wpdb->prefix . "posts as wp_posts on wp_posts.ID = geo.post_id WHERE wp_posts.post_status != 'trash' AND wp_posts.post_author = " . $user_id);
    }
    $listing_url = $bp->loggedin_user->domain . $bp->current_component . "/" . BEPRO_LISTINGS_CREATE_SLUG . "/";
    //allow addons to override create listing button. The default for buddypress is to not have a button
    $add_new_button = apply_filters("bl_change_add_listing_button", false, $listing_url);
    if ($add_new_button && bp_is_my_profile()) {
        echo $add_new_button;
    }
    //allow addons to change profile template
    $bl_my_list_template = apply_filters("bl_change_my_list_template", dirname(__FILE__) . '/templates/list.php', $items);
    if ($bl_my_list_template) {
        require $bl_my_list_template;
    }
}
function bl_my_listings()
{
    global $wpdb, $post;
    $current_url = get_permalink($post->ID);
    $return_text = "";
    if (!is_user_logged_in()) {
        $return_text .= "<p>" . __("You need to be Logged In to see your Listings.", "bepro-listings") . "</p>";
        $args = array('echo' => true, 'redirect' => $current_url, 'form_id' => 'loginform', 'label_username' => __('Username'), 'label_password' => __('Password'), 'label_remember' => __('Remember Me'), 'label_log_in' => __('Log In'), 'id_username' => 'user_login', 'id_password' => 'user_pass', 'id_remember' => 'rememberme', 'id_submit' => 'wp-submit', 'remember' => true, 'value_username' => NULL, 'value_remember' => false);
        wp_login_form($args);
        return;
    }
    $types = listing_types();
    $current_user = wp_get_current_user();
    $user_id = $current_user->id;
    if (isset($_POST["save_bepro_listing"]) && !empty($_POST["save_bepro_listing"])) {
        $success = false;
        $success = bepro_listings_save();
        if ($success) {
            $success_message = apply_filters("bepro_form_success_message", "Listing Successfully Saved");
            $message = "<span class='bl_succsss_message'>" . __($success_message, "bepro-listings") . "</span>";
        } else {
            $fail_message = apply_filters("bepro_form_fail_message", __("Issue saving your listing. Please contact the website administrator", "bepro-listings"));
            $message = "<span class='bl_fail_message'>" . __($fail_message, "bepro-listings") . "</span>";
        }
        $current_user = wp_get_current_user();
        $current_url = get_permalink($post->ID);
        echo "<span class='classified_message'>" . $message . "</span>";
    }
    if (!empty($_GET["bl_manage"])) {
        if (!empty($_GET["bl_id"])) {
            bl_profile_update_listing_content();
        } else {
            bl_profile_add_listing_content();
        }
    } else {
        $data = get_option("bepro_listings");
        // get records
        if (@$data["require_payment"]) {
            $items = $wpdb->get_results("SELECT geo.*, orders.status as order_status, orders.expires, wp_posts.post_title, wp_posts.post_status FROM " . $wpdb->prefix . BEPRO_LISTINGS_TABLE_NAME . " as geo \n\t\t\t\tLEFT JOIN " . $wpdb->prefix . "posts as wp_posts on wp_posts.ID = geo.post_id \n\t\t\t\tLEFT JOIN " . BEPRO_LISTINGS_ORDERS_TABLE_NAME . " AS orders on orders.bl_order_id = geo.bl_order_id WHERE wp_posts.post_status != 'trash' AND wp_posts.post_author = " . $user_id);
        } else {
            $items = $wpdb->get_results("SELECT geo.*, wp_posts.post_title, wp_posts.post_status FROM " . $wpdb->prefix . BEPRO_LISTINGS_TABLE_NAME . " as geo \n\t\t\t\tLEFT JOIN " . $wpdb->prefix . "posts as wp_posts on wp_posts.ID = geo.post_id WHERE wp_posts.post_status != 'trash' AND wp_posts.post_author = " . $user_id);
        }
        $listing_url = "?bl_manage=1&bl_id=";
        $add_listing_button = "<p><a href='" . $listing_url . "'>" . __("Add a Listing") . "</a></p>";
        //allow addons to override create listing button
        $return_text .= apply_filters("bl_change_add_listing_button", $add_listing_button, $listing_url);
        //allow addons to change profile template
        $bl_my_list_template = apply_filters("bl_change_my_list_template", dirname(__FILE__) . '/templates/list.php', $items);
        ob_start();
        if (!empty($bl_my_list_template)) {
            include $bl_my_list_template;
        }
        $return_text .= ob_get_clean();
        return $return_text;
    }
}
function display_item_content()
{
    global $wpdb, $bp;
    $types = listing_types();
    $current_user = wp_get_current_user();
    $user_id = $bp->displayed_user->id;
    // get records
    $items = $wpdb->get_results("SELECT geo.*, wp_posts.post_title, wp_posts.post_status FROM " . $wpdb->prefix . BEPRO_LISTINGS_TABLE_NAME . " as geo \n\t\tLEFT JOIN " . $wpdb->prefix . "posts as wp_posts on wp_posts.ID = geo.post_id WHERE wp_posts.post_status != 'trash' AND wp_posts.post_author = " . $user_id);
    $listing_url = $bp->loggedin_user->domain . $bp->current_component . "/" . BEPRO_LISTINGS_CREATE_SLUG . "/";
    require dirname(__FILE__) . '/templates/list.php';
}
function bl_my_listings()
{
    global $wpdb, $post;
    $current_url = get_permalink($post->ID);
    if (!is_user_logged_in()) {
        echo "<p>You need to be Logged In to see your Listings.</p>";
        $args = array('echo' => true, 'redirect' => $current_url, 'form_id' => 'loginform', 'label_username' => __('Username'), 'label_password' => __('Password'), 'label_remember' => __('Remember Me'), 'label_log_in' => __('Log In'), 'id_username' => 'user_login', 'id_password' => 'user_pass', 'id_remember' => 'rememberme', 'id_submit' => 'wp-submit', 'remember' => true, 'value_username' => NULL, 'value_remember' => false);
        wp_login_form($args);
        return;
    }
    $types = listing_types();
    $current_user = wp_get_current_user();
    $user_id = $current_user->id;
    if (isset($_POST["save_bepro_listing"]) && !empty($_POST["save_bepro_listing"])) {
        $success = false;
        $success = bepro_listings_save();
        if ($success) {
            $message = urlencode("Success saving listing");
        } else {
            $message = urlencode("Error saving listing");
        }
        $current_user = wp_get_current_user();
        $current_url = get_permalink($post->ID);
        wp_redirect($current_url . "?message=" . $message);
        exit;
    }
    if (!empty($_GET["bl_manage"])) {
        if (!empty($_GET["bl_id"])) {
            bl_profile_update_listing_content();
        } else {
            bl_profile_add_listing_content();
        }
    } else {
        // get records
        $items = $wpdb->get_results("SELECT geo.*, wp_posts.post_title, wp_posts.post_status FROM " . $wpdb->prefix . BEPRO_LISTINGS_TABLE_NAME . " as geo \r\n\t\t\tLEFT JOIN " . $wpdb->prefix . "posts as wp_posts on wp_posts.ID = geo.post_id WHERE wp_posts.post_status != 'trash' AND wp_posts.post_author = " . $user_id);
        $listing_url = "?bl_manage=1&bl_id=";
        echo "<p><a href='" . $listing_url . "'>Add a Listing</a></p>";
        require dirname(__FILE__) . '/templates/list.php';
    }
}
    function search_filter_options($atts = array(), $echo_this = false)
    {
        global $wpdb;
        extract(shortcode_atts(array('listing_page' => $wpdb->escape($_POST["listing_page"])), $atts));
        //get settings
        $data = get_option("bepro_listings");
        //Process user requested Bepro listing types
        if (!empty($_POST["l_type"])) {
            $l_type = $_POST["l_type"];
            foreach ($l_type as $raw_t) {
                $types[$raw_t] = 1;
            }
        }
        $cat_heading = !empty($_REQUEST["l_type"]) && (is_numeric($_REQUEST["l_type"]) || is_array($_REQUEST["l_type"])) ? $data["cat_empty"] : $data["cat_heading"];
        $search_form = "<div class='filter_search_form'>\n\t\t\t<form id='filter_search_form' method='post' action='" . $listing_page . "'>\n\t\t\t\t<input type='hidden' name='name_search' value='" . $_POST["name_search"] . "'>\n\t\t\t\t<input type='hidden' name='addr_search' value='" . $_POST["addr_search"] . "'>\n\t\t\t\t<input type='hidden' name='filter_search' value='1'>\n\t\t\t\t<table>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>\n\t\t\t\t\t\t<span class='searchlabel'>" . __($cat_heading, "bepro-listings") . "</span><br />\n\t\t\t\t\t\t";
        $options = listing_types();
        foreach ($options as $opt) {
            $checked = isset($types[$opt->term_id]) ? "checked='checked'" : "";
            $search_form .= '<input type="checkbox" name="l_type[]" value="' . $opt->term_id . '" ' . $checked . '/><span class="searchcheckbox">' . $opt->name . '</span><br />';
        }
        $search_form .= '</td>
			</tr>';
        ///////////////////////////////////////////////////////////////////////
        if ($data["show_geo"] == (1 || "on")) {
            $search_form .= '
				<tr><td>
					' . __("Distance", "bepro-listings") . ': <select name="distance">
						<option value="">None</option>
						<option value="50" ' . ($_POST["distance"] == 50 ? 'selected="selected"' : "") . '>50 miles</option>
						<option value="150" ' . ($_POST["distance"] == 150 || empty($_POST["distance"]) ? 'selected="selected"' : "") . '>150 miles</option>
						<option value="250" ' . ($_POST["distance"] == 250 ? 'selected="selected"' : "") . '>250 miles</option>
						<option value="500" ' . ($_POST["distance"] == 500 ? 'selected="selected"' : "") . '>500 miles</option>
						<option value="1000" ' . ($_POST["distance"] == 1000 ? 'selected="selected"' : "") . '>1000 miles</option>
					</select>
				</td></tr>';
        }
        //min/max cost
        if ($data["show_cost"] == (1 || "on")) {
            $search_form .= '
				<tr><td>
					<span class="label_sep">' . __("Price Range", "bepro-listings") . '</span><span class="form_label">' . __("From", "bepro-listings") . '</span><input class="input_text" type="text" name="min_cost" value="' . $_POST["min_cost"] . '"><span class="form_label">' . __("To", "bepro-listings") . '</span><input class="input_text" type="text" name="max_cost" value="' . $_POST["max_cost"] . '">
				</td></tr>';
        }
        if ($data["show_date"] == 1) {
            $search_form .= '
				<tr><td>
					<span class="label_sep">' . __("Date Range", "bepro-listings") . '</span><span class="form_label">' . __("From", "bepro-listings") . '</span><input class="input_text" type="text" name="min_date" id="min_date" value="' . $_POST["min_date"] . '"><span class="form_label">' . __("To", "bepro-listings") . '</span><input class="input_text" type="text" name="max_date" id="max_date" value="' . $_POST["max_date"] . '">
				</td></tr>';
        }
        $search_form .= apply_filters("bepro_listings_search_filter", "");
        $search_form .= '
				<tr>
					<td>
						<input type="submit" class="form-submit" value="' . __("Search", "bepro-listings") . '" id="edit-submit" name="find">
						<a class="clear_search" href="' . get_bloginfo("url") . "/" . $listing_page . '"><button>Clear</button></a>
					</td>
				</tr>
			</table>
		</form></div>
		';
        if ($echo_this) {
            echo $search_form;
        } else {
            return $search_form;
        }
    }