function notify_new_listing($listingID)
 {
     global $conn, $lang, $config;
     $display = '';
     require_once $config['basepath'] . '/include/misc.inc.php';
     $misc = new misc();
     require_once $config['basepath'] . '/include/search.inc.php';
     $notify_count = 0;
     $sql = "SELECT userdb_id, usersavedsearches_title, usersavedsearches_query_string, usersavedsearches_notify FROM " . $config['table_prefix'] . "usersavedsearches WHERE usersavedsearches_notify = 'yes'";
     $recordSet = $conn->Execute($sql);
     if ($recordSet === false) {
         $misc->log_error($sql);
     }
     while (!$recordSet->EOF) {
         $query_string = $misc->make_db_unsafe($recordSet->fields['usersavedsearches_query_string']);
         $user_id = $recordSet->fields['userdb_id'];
         $search_title = $misc->make_db_unsafe($recordSet->fields['usersavedsearches_title']);
         // Break Quesry String up into $_GET variables.
         unset($_GET);
         $query_string = urldecode($query_string);
         $criteria = explode('&', $query_string);
         foreach ($criteria as $crit) {
             if ($crit != '') {
                 $pieces = explode('=', $crit);
                 $pos = strpos($pieces[0], '[]');
                 if ($pos !== false) {
                     $name = substr($pieces[0], 0, -2);
                     $_GET[$name][] = $pieces[1];
                 } else {
                     $_GET[$pieces[0]] = $pieces[1];
                 }
             }
         }
         if (!isset($_GET)) {
             $_GET[] = '';
         }
         $matched_listing_ids = search_page::search_results(true);
         if (in_array($listingID, $matched_listing_ids)) {
             // Listing Matches Search
             $sql = "SELECT userdb_user_name, userdb_emailaddress FROM " . $config['table_prefix'] . "userdb WHERE userdb_id = " . $user_id;
             $recordSet2 = $conn->Execute($sql);
             if ($recordSet2 === false) {
                 $misc->log_error($sql);
             }
             $email = $misc->make_db_unsafe($recordSet2->fields['userdb_emailaddress']);
             $user_name = $misc->make_db_unsafe($recordSet2->fields['userdb_user_name']);
             $message = $lang['automated_email'] . "\r\n\r\n\r\n" . date("F j, Y, g:i:s a") . "\r\n\r\n" . $lang['new_listing_notify_long'] . "'" . $search_title . "'.\r\n\r\n" . $lang['click_on_link_to_view_listing'] . "\r\n\r\n{$config['baseurl']}/index.php?action=listingview&listingID=" . $listingID . "\r\n\r\n\r\n" . $lang['click_to_view_saved_searches'] . "\r\n\r\n{$config['baseurl']}/index.php?action=view_saved_searches\r\n\r\n\r\n" . $lang['automated_email'] . "\r\n";
             // Send Mail
             $sent = $misc->send_email($config['admin_name'], $config['admin_email'], $email, $message, $lang['new_listing_notify']);
             $notify_count++;
         }
         $recordSet->MoveNext();
         if ($notify_count > 0) {
             $display .= $lang['new_listing_email_sent'] . $notify_count . $lang['new_listing_email_users'] . '<br />';
         }
     }
     // while
     return $display;
 }
 function replace_user_action()
 {
     global $lang, $config;
     require_once $config['basepath'] . '/include/login.inc.php';
     $login = new login();
     switch ($_GET['action']) {
         case 'index':
             $_GET['PageID'] = 1;
             require_once $config['basepath'] . '/include/page_display.inc.php';
             $search = new page_display();
             $data = $search->display();
             break;
         case 'member_login':
             $data = $login->display_login('Member');
             break;
         case 'search_step_2':
             require_once $config['basepath'] . '/include/search.inc.php';
             $search = new search_page();
             $data = $search->create_searchpage();
             break;
         case 'searchpage':
             require_once $config['basepath'] . '/include/search.inc.php';
             $search = new search_page();
             $data = $search->create_search_page_logic();
             break;
         case 'searchresults':
             require_once $config['basepath'] . '/include/search.inc.php';
             $search = new search_page();
             $data = $search->search_results();
             break;
         case 'listingview':
             require_once $config['basepath'] . '/include/listing.inc.php';
             $listing = new listing_pages();
             $data = $listing->listing_view();
             break;
         case 'addtofavorites':
             require_once $config['basepath'] . '/include/members_favorites.inc.php';
             $listing = new membersfavorites();
             $data = $listing->addtofavorites();
             break;
         case 'view_favorites':
             require_once $config['basepath'] . '/include/members_favorites.inc.php';
             $listing = new membersfavorites();
             $data = $listing->view_favorites();
             break;
         case 'view_saved_searches':
             require_once $config['basepath'] . '/include/members_search.inc.php';
             $listing = new memberssearch();
             $data = $listing->view_saved_searches();
             break;
         case 'save_search':
             require_once $config['basepath'] . '/include/members_search.inc.php';
             $listing = new memberssearch();
             $data = $listing->save_search();
             break;
         case 'delete_search':
             require_once $config['basepath'] . '/include/members_search.inc.php';
             $listing = new memberssearch();
             $data = $listing->delete_search();
             break;
         case 'delete_favorites':
             require_once $config['basepath'] . '/include/members_favorites.inc.php';
             $listing = new membersfavorites();
             $data = $listing->delete_favorites();
             break;
         case 'page_display':
             require_once $config['basepath'] . '/include/page_display.inc.php';
             $search = new page_display();
             $data = $search->display();
             break;
         case 'calculator':
             require_once $config['basepath'] . '/include/calculators.inc.php';
             $calc = new calculators();
             $data = $calc->start_calc();
             break;
         case 'view_listing_image':
             require_once $config['basepath'] . '/include/images.inc.php';
             $image = new image_handler();
             $data = $image->view_image('listing');
             break;
         case 'view_user_image':
             require_once $config['basepath'] . '/include/images.inc.php';
             $image = new image_handler();
             $data = $image->view_image('userimage');
             break;
         case 'rss_featured_listings':
             require_once $config['basepath'] . '/include/rss.inc.php';
             $rss = new rss();
             $data = $rss->rss_view('featured');
             break;
         case 'rss_lastmodified_listings':
             require_once $config['basepath'] . '/include/rss.inc.php';
             $rss = new rss();
             $data = $rss->rss_view('lastmodified');
             break;
         case 'view_user':
             require_once $config['basepath'] . '/include/user.inc.php';
             $user = new user();
             $data = $user->view_user();
             break;
         case 'view_users':
             require_once $config['basepath'] . '/include/user.inc.php';
             $user = new user();
             $data = $user->view_users();
             break;
         case 'edit_profile':
             require_once $config['basepath'] . '/include/user_manager.inc.php';
             if (!isset($_GET['user_id'])) {
                 $_GET['user_id'] = 0;
             }
             $user_managment = new user_managment();
             $data = $user_managment->edit_member_profile($_GET['user_id']);
             break;
         case 'signup':
             if (isset($_GET['type'])) {
                 require_once $config['basepath'] . '/include/user_manager.inc.php';
                 $listing = new user_managment();
                 $data = $listing->user_signup($_GET['type']);
             }
             break;
         case 'show_vtour':
             if (isset($_GET['listingID'])) {
                 require_once $config['basepath'] . '/include/vtour.inc.php';
                 $vtour = new vtours();
                 $data = $vtour->show_vtour($_GET['listingID']);
             } else {
                 $data = 'No Listing ID';
             }
             break;
         case 'contact_friend':
             require_once $config['basepath'] . '/include/contact.inc.php';
             $contact = new contact();
             if (isset($_GET['listing_id'])) {
                 $data = $contact->ContactFriendForm($_GET['listing_id']);
             }
             break;
         case 'contact_agent':
             require_once $config['basepath'] . '/include/contact.inc.php';
             $contact = new contact();
             if (isset($_GET['listing_id']) && isset($_GET['agent_id'])) {
                 $data = $contact->ContactAgentForm($_GET['listing_id'], $_GET['agent_id']);
             } elseif (isset($_GET['listing_id'])) {
                 $data = $contact->ContactAgentForm($_GET['listing_id'], 0);
             } elseif (isset($_GET['agent_id'])) {
                 $data = $contact->ContactAgentForm(0, $_GET['agent_id']);
             } else {
                 $data = '';
             }
             break;
         case 'create_vcard':
             require_once $config['basepath'] . '/include/user.inc.php';
             $user = new user();
             if (isset($_GET['user'])) {
                 $data = $user->create_vcard($_GET['user']);
             }
             break;
         case 'create_download':
             require_once $config['basepath'] . '/include/files.inc.php';
             $files = new file_handler();
             if (isset($_GET['ID']) && isset($_GET['file_id']) && isset($_GET['type'])) {
                 $data = $files->create_download($_GET['ID'], $_GET['file_id'], $_GET['type']);
             } elseif (isset($_POST['ID']) && isset($_POST['file_id']) && isset($_POST['type'])) {
                 $data = $files->create_download($_POST['ID'], $_POST['file_id'], $_POST['type']);
             }
             break;
         case 'blog_index':
             require_once $config['basepath'] . '/include/blog_display.inc.php';
             $blog = new blog_display();
             $data = $blog->disply_blog_index();
             break;
         case 'blog_view_article':
             require_once $config['basepath'] . '/include/blog_display.inc.php';
             $blog = new blog_display();
             $data = $blog->display();
             break;
         case 'verify_email':
             require_once $config['basepath'] . '/include/user_manager.inc.php';
             $user_manager = new user_managment();
             $data = $user_manager->verify_email();
             break;
         default:
             $addon_name = array();
             if (preg_match("/^addon_(.\\S*?)_.*/", $_GET['action'], $addon_name)) {
                 $file = $config['basepath'] . '/addons/' . $addon_name[1] . '/addon.inc.php';
                 if (file_exists($file)) {
                     include_once $file;
                     $function_name = $addon_name[1] . '_run_action_user_template';
                     $data = $function_name();
                 } else {
                     $data = $lang['addon_doesnt_exist'];
                 }
             } else {
                 $data = '';
             }
             break;
     }
     // End switch ($_GET['action'])
     return $data;
 }
 function view_favorites()
 {
     global $config, $lang, $conn;
     require_once $config['basepath'] . '/include/misc.inc.php';
     $misc = new misc();
     $security = login::loginCheck('Member');
     if ($security === true) {
         $display = '';
         $display .= '<h3>' . $lang['favorite_listings'] . '</h3>';
         $userID = $misc->make_db_safe($_SESSION['userID']);
         $sql = "SELECT listingsdb_id FROM " . $config['table_prefix'] . "userfavoritelistings WHERE userdb_id = {$userID}";
         $recordSet = $conn->Execute($sql);
         if ($recordSet == false) {
             log_error($sql);
         }
         $num_columns = $recordSet->RecordCount();
         if ($num_columns == 0) {
             $display .= $lang['no_listing_in_favorites'] . '<br /><br />';
         } else {
             $recordNum = 0;
             $listings = '';
             while (!$recordSet->EOF) {
                 if ($recordNum == 0) {
                     $listings .= $recordSet->fields['listingsdb_id'];
                 } else {
                     $listings .= "," . $recordSet->fields['listingsdb_id'];
                 }
                 $recordNum++;
                 $recordSet->MoveNext();
             }
             $_GET['listing_id'] = $listings;
             require_once $config['basepath'] . '/include/search.inc.php';
             $search = new search_page();
             $display .= $search->search_results();
         }
         // End else
         return $display;
     } else {
         return $security;
     }
 }
 function NotifyUsersOfAllNewListings()
 {
     global $conn, $lang, $config;
     $display = '';
     require_once $config['basepath'] . '/include/misc.inc.php';
     $misc = new misc();
     require_once $config['basepath'] . '/include/search.inc.php';
     //Get Last Notification Timestamp
     $sql = 'SELECT controlpanel_notification_last_timestamp FROM ' . $config['table_prefix_no_lang'] . 'controlpanel';
     $recordSet = $conn->Execute($sql);
     if ($recordSet === false) {
         $misc->log_error($sql);
     }
     $last_timestamp = $conn->UnixTimeStamp($recordSet->fields['controlpanel_notification_last_timestamp']);
     //echo 'Timestamp'.$last_timestamp;
     $display .= 'Sending New Listing Notifications since ' . date(DATE_RFC822, $last_timestamp) . "<br />\r\n";
     $current_timestamp = time();
     $notify_count = 0;
     $sql = "SELECT " . $config['table_prefix'] . "usersavedsearches.userdb_id, usersavedsearches_title, usersavedsearches_query_string, usersavedsearches_notify, userdb_user_name, userdb_emailaddress\n\t\t\t\tFROM " . $config['table_prefix'] . "userdb , " . $config['table_prefix'] . "usersavedsearches\n\t\t\t\tWHERE " . $config['table_prefix'] . "userdb.userdb_id = " . $config['table_prefix'] . "usersavedsearches.userdb_id AND usersavedsearches_notify = 'yes'";
     $recordSet = $conn->Execute($sql);
     if ($recordSet === false) {
         $misc->log_error($sql);
     }
     while (!$recordSet->EOF) {
         $query_string = $misc->make_db_unsafe($recordSet->fields['usersavedsearches_query_string']);
         $user_id = $recordSet->fields['userdb_id'];
         $search_title = $misc->make_db_unsafe($recordSet->fields['usersavedsearches_title']);
         $email = $misc->make_db_unsafe($recordSet->fields['userdb_emailaddress']);
         $user_name = $misc->make_db_unsafe($recordSet->fields['userdb_user_name']);
         $display .= 'Checking Notifications for Saved Search "' . $search_title . '" for ' . $user_name . "<br />\r\n";
         // Break Quesry String up into $_GET variables.
         unset($_GET);
         $query_string = urldecode($query_string);
         $criteria = explode('&', $query_string);
         foreach ($criteria as $crit) {
             if ($crit != '') {
                 $pieces = explode('=', $crit);
                 $pos = strpos($pieces[0], '[]');
                 if ($pos !== false) {
                     $name = substr($pieces[0], 0, -2);
                     $_GET[$name][] = $pieces[1];
                 } else {
                     $_GET[$pieces[0]] = $pieces[1];
                 }
             }
         }
         if (!isset($_GET)) {
             $_GET[] = '';
         }
         $_GET['listing_last_modified_greater'] = $last_timestamp;
         $matched_listing_ids = search_page::search_results(true);
         if (count($matched_listing_ids) >= 1) {
             //print_r($matched_listing_ids);
             //Get User Details
             //Now that we have a list of the listings, render the template
             $template = $this->renderNotifyListings($matched_listing_ids, $search_title, $user_name, $email);
             $display .= '<span class=redtext">Sent Listing Notification to ' . $user_name . '&lt;' . $email . '&gt; for listings ' . implode(',', $matched_listing_ids) . "</span><br />\r\n";
             // Send Mail
             if (isset($config['site_email']) && $config['site_email'] != '') {
                 $sender_email = $config['site_email'];
             } else {
                 $sender_email = $config['admin_email'];
             }
             $subject = $lang['new_listing_notify'] . $search_title;
             $sent = $misc->send_email($config['admin_name'], $sender_email, $email, $template, $subject, TRUE, TRUE);
         }
         $recordSet->MoveNext();
     }
     // while
     //Swt Last Notification Timestamp
     $db_timestamp = $conn->DBTimeStamp($current_timestamp);
     $sql = 'UPDATE ' . $config['table_prefix_no_lang'] . 'controlpanel SET controlpanel_notification_last_timestamp = ' . $db_timestamp;
     $recordSet = $conn->Execute($sql);
     if ($recordSet === false) {
         $misc->log_error($sql);
     }
     $display .= "Finish Sending Notifications<br />\r\n";
     return $display;
 }