private static function _save_search($args)
 {
     extract($args);
     if (!empty($user) && !empty($hash)) {
         if (!user_can($user->ID, self::$_capabilities['save_search']) || user_can($user->ID, self::$_capabilities['view_leads'])) {
             return 'User does not have the capability to save searches.';
         }
         if (empty($name_exists)) {
             $saved_searches = !empty($user->{self::$_meta_keys['lead']['saved_searches']}) ? $user->{self::$_meta_keys['lead']['saved_searches']} : array();
             $this_search = array('hash' => $hash, 'name' => $search_name);
             if (!empty($user->{self::$_meta_keys['api_user_id']})) {
                 $saved_search_criteria = DispletRetsIdxResidentialsModel::get_search_criteria_from_hash($hash);
                 $saved_search_id = DispletRetsIdxUsersApiController::create_saved_search($user->{self::$_meta_keys['api_user_id']}, $search_name, $saved_search_criteria);
                 if (isset($saved_search_id)) {
                     $this_search['api_id'] = $saved_search_id;
                 }
             }
             $saved_searches[] = $this_search;
             update_user_meta($user->ID, self::$_meta_keys['lead']['saved_searches'], $saved_searches);
             new DispletRetsIdxEmail('saved_search', array('agent_id' => DispletRetsIdxLeadsModel::get_assigned_agent_id($user->ID), 'lender_id' => DispletRetsIdxLeadsModel::get_assigned_lender_id($user->ID), 'search_url' => trailingslashit(get_permalink(self::$_options['search_results_page_id'])) . $hash, 'user_email' => $user->user_email, 'user_name' => $user->display_name, 'user_phone' => $user->{self::$_meta_keys['lead']['phone']}));
             do_action('displetretsidx_post_lead_saved_search', $user->ID, $this_search);
             return 'Saved Search';
         }
     }
 }
 private static function _new($user_id, $args)
 {
     extract(wp_parse_args($args, array('address' => '', 'appointment1' => '', 'appointment2' => '', 'city' => '', 'email' => '', 'message' => '', 'mls_number' => '', 'name' => '', 'phone' => '', 'state' => '', 'url' => '', 'zip' => '')));
     $assigned_agent_id = DispletRetsIdxLeadsModel::get_assigned_agent_id($user_id);
     $assigned_lender_id = DispletRetsIdxLeadsModel::get_assigned_lender_id($user_id);
     $comma_separated_address_components = array_filter(array($address, $city, $state), 'trim');
     $address = !empty($comma_separated_address_components) ? implode(', ', $comma_separated_address_components) : '';
     if (!empty($zip)) {
         $address .= ' ' . trim($zip);
     }
     new DispletRetsIdxEmail('showing_request', array('agent_id' => $assigned_agent_id, 'lender_id' => $assigned_lender_id, 'property_address' => trim($address), 'property_mls' => $mls_number, 'property_url' => $url, 'user_appointment' => $appointment1, 'user_appointment2' => $appointment2, 'user_email' => $email, 'user_message' => $message, 'user_name' => $name, 'user_phone' => $phone));
     $inquiry_details = array('email' => $email, 'name' => $name, 'phone' => $phone, 'address' => $address, 'first_appointment' => $appointment1, 'second_appointment' => $appointment2, 'message' => $message);
     DispletRetsIdxPropertyInquiriesController::update_property_inquiries($user_id, $inquiry_details);
     DispletRetsIdxUsersController::send_to_zapier($inquiry_details, 'showing');
 }
 public static function save_property()
 {
     check_ajax_referer('displet_save_property_nonce');
     if (isset($_POST['action']) && $_POST['action'] == 'displet_save_property_request') {
         if (!is_user_logged_in()) {
             echo 'You are not logged in. Please sign in or create an account and try again.';
         } elseif (current_user_can('displet_save_properties') && !current_user_can('manage_options')) {
             if (!empty($_POST['type'])) {
                 $user = wp_get_current_user();
                 if (!empty($user->ID)) {
                     $base = get_permalink(self::$_options['property_details_page_id']);
                     $url = str_replace($base, '', $_POST['url']);
                     $saved_properties = get_user_meta($user->ID, 'displet_saved_properties', true);
                     $message = !empty($_POST['message']) ? stripslashes($_POST['message']) : '';
                     $saved_property = array('address' => $_POST['address'], 'image_url' => $_POST['image_url'], 'message' => $message, 'price' => $_POST['price'], 'rating' => $_POST['rating'], 'square_feet' => $_POST['square_feet'], 'sysid' => $_POST['sysid'], 'type' => $_POST['type'], 'url' => $url, 'zip' => $_POST['zip']);
                     $saved_property['api_id'] = DispletRetsIdxSavedPropertiesController::send_saved_property_to_api($user->ID, $saved_property);
                     if (!empty($saved_property['sysid'])) {
                         if (!empty($saved_properties[$saved_property['sysid']]) && !empty($saved_properties[$saved_property['sysid']]['message'])) {
                             $saved_property['message'] .= PHP_EOL . PHP_EOL . $saved_properties[$saved_property['sysid']]['message'];
                         }
                         $saved_properties[$saved_property['sysid']] = $saved_property;
                     } else {
                         $saved_properties[] = $saved_property;
                     }
                     update_user_meta($user->ID, 'displet_saved_properties', $saved_properties);
                     update_user_meta($user->ID, 'displet_saved_properties_count', count($saved_properties));
                     new DispletRetsIdxEmail('saved_property', array('agent_id' => DispletRetsIdxLeadsModel::get_assigned_agent_id($user->ID), 'lender_id' => DispletRetsIdxLeadsModel::get_assigned_lender_id($user->ID), 'property_address' => $_POST['address'], 'property_url' => $_POST['url'], 'user_email' => $user->user_email, 'user_message' => $message, 'user_name' => $user->display_name, 'user_phone' => $user->displet_phone));
                     do_action('displetretsidx_post_lead_saved_property', $user->ID, $saved_property);
                     echo 'This property has been saved.';
                 } else {
                     echo 'You are not logged in. Please sign in or create an account and try again.';
                 }
             } else {
                 echo 'Please select Save as favorite, Save as possibility, or Just save notes.';
             }
         } else {
             echo 'The current user does not have the capability to save properties.';
         }
         die;
     }
     echo 'We\'re sorry, there was an error processing your request. Please try again.';
     die;
 }
 public static function send_email_to_friend_request()
 {
     check_ajax_referer('displet_email_friend_nonce');
     if (isset($_POST['action']) && $_POST['action'] == 'displet_email_friend_request') {
         if (!empty($_POST['email']) && is_email($_POST['email'])) {
             $user = wp_get_current_user();
             $assigned_agent_id = !empty($user->ID) ? DispletRetsIdxLeadsModel::get_assigned_agent_id($user->ID) : false;
             $assigned_lender_id = !empty($user->ID) ? DispletRetsIdxLeadsModel::get_assigned_lender_id($user->ID) : false;
             $user_name = !empty($user->display_name) ? $user->display_name : 'A Friend';
             $user_email = !empty($user->user_email) ? $user->user_email : false;
             $address = trim($_POST['address']) . ', ' . trim($_POST['city']) . ', ' . trim($_POST['state']) . ' ' . trim($_POST['zip']);
             new DispletRetsIdxEmail('emailed_friend', array('agent_id' => $assigned_agent_id, 'friend_email' => $_POST['email'], 'friend_name' => $_POST['name'], 'lender_id' => $assigned_lender_id, 'property_address' => $address, 'property_url' => $_POST['url'], 'user_email' => $user_email, 'user_message' => $_POST['message'], 'user_name' => $user_name));
             echo 'Your message has been sent.';
         } else {
             echo 'Please enter a valid email address.';
         }
         die;
     }
     echo 'We\'re sorry, there was an error processing your request. Please try again.';
     die;
 }