Ejemplo n.º 1
0
 public static function edit_listing_link($url_only = 'no')
 {
     global $lang, $config, $current_ID;
     $display = '';
     //Get the listing ID
     if ($current_ID != '') {
         $_GET['listingID'] = $current_ID;
     }
     if (isset($_GET['listingID'])) {
         $listingID = intval($_GET['listingID']);
         $listingagentid = listing_pages::getListingAgentID($listingID);
         if (isset($_SESSION['userID'])) {
             $userid = $_SESSION['userID'];
             if ($_SESSION['edit_all_listings'] == 'yes' || $_SESSION['admin_privs'] == 'yes') {
                 $edit_link = $config['baseurl'] . '/admin/index.php?action=edit_listings&edit=' . $listingID;
             } elseif ($_SESSION['isAgent'] == 'yes' && $listingagentid == $userid) {
                 $edit_link = $config['baseurl'] . '/admin/index.php?action=edit_my_listings&edit=' . $listingID;
             } else {
                 return;
             }
             if ($url_only == 'yes') {
                 $display = $edit_link;
             } else {
                 $display = '<a href="' . $edit_link . '">' . $lang['edit_listing'] . '</a>';
             }
         }
     }
     return $display;
 }
Ejemplo n.º 2
0
 function replace_listing_field_tags($listing_id, $tempate_section = '', $utf8HTML = false)
 {
     global $lang;
     if (is_numeric($listing_id)) {
         global $config, $conn, $or_replace_listing_id, $or_replace_listing_owner;
         $or_replace_listing_id = $listing_id;
         require_once $config['basepath'] . '/include/listing.inc.php';
         require_once $config['basepath'] . '/include/vtour.inc.php';
         require_once $config['basepath'] . '/include/misc.inc.php';
         $misc = new misc();
         if ($tempate_section != '') {
             $tsection = true;
         } else {
             $tempate_section = $this->page;
             $tsection = false;
         }
         if ($utf8HTML) {
             //Deal with listing field blocks
             $lf_blocks = array();
             preg_match_all('/{listing_field_([^{}]*?)_block}/', $tempate_section, $lf_blocks);
             require_once $config['basepath'] . '/include/user.inc.php';
             global $or_replace_listing_owner;
             if (count($lf_blocks) > 1) {
                 foreach ($lf_blocks[1] as $block) {
                     require_once $config['basepath'] . '/include/listing.inc.php';
                     $value = listing_pages::renderSingleListingItem($or_replace_listing_id, $block, 'rawvalue');
                     if ($value == '') {
                         $tempate_section = preg_replace('/{listing_field_' . $block . '_block}(.*?){\\/listing_field_' . $block . '_block}/is', '', $tempate_section);
                     } else {
                         $tempate_section = str_replace('{listing_field_' . $block . '_block}', '', $tempate_section);
                         $tempate_section = str_replace('{/listing_field_' . $block . '_block}', '', $tempate_section);
                     }
                 }
             }
             // Handle Caption Only
             $tempate_section = preg_replace_callback('/{listing_field_([^{}]*?)_caption}/', create_function('$matches', 'global $config,$or_replace_listing_id,$lang;require_once($config[\'basepath\'].\'/include/listing.inc.php\'); return htmlentities(utf8_encode(listing_pages::renderSingleListingItem($or_replace_listing_id, $matches[1],\'caption\')), ENT_QUOTES, \'UTF-8\');'), $tempate_section);
             // Hanle Value Only
             $tempate_section = preg_replace_callback('/{listing_field_([^{}]*?)_value}/', create_function('$matches', 'global $config,$or_replace_listing_id,$lang;require_once($config[\'basepath\'].\'/include/listing.inc.php\'); return htmlentities(utf8_encode(listing_pages::renderSingleListingItem($or_replace_listing_id, $matches[1],\'value\')), ENT_QUOTES, \'UTF-8\');'), $tempate_section);
             // Handle Raw Value
             $tempate_section = preg_replace_callback('/{listing_field_([^{}]*?)_rawvalue}/', create_function('$matches', 'global $config,$or_replace_listing_id,$lang;require_once($config[\'basepath\'].\'/include/listing.inc.php\'); return htmlentities(utf8_encode(listing_pages::renderSingleListingItem($or_replace_listing_id, $matches[1],\'rawvalue\')), ENT_QUOTES, \'UTF-8\');'), $tempate_section);
             // Handle Both Caption and Value
             $tempate_section = preg_replace_callback('/{listing_field_([^{}]*?)}/', create_function('$matches', 'global $config,$or_replace_listing_id,$lang;require_once($config[\'basepath\'].\'/include/listing.inc.php\'); return htmlentities(utf8_encode(listing_pages::renderSingleListingItem($or_replace_listing_id, $matches[1])), ENT_QUOTES, \'UTF-8\');'), $tempate_section);
             $value = htmlentities(utf8_encode(listing_pages::get_title($listing_id)), ENT_QUOTES, 'UTF-8');
             $tempate_section = str_replace('{listing_title}', $value, $tempate_section);
             $value = listing_pages::get_title($listing_id);
             if ($config["controlpanel_mbstring_enabled"] == 1) {
                 if (mb_detect_encoding($value) != 'UTF-8') {
                     $value = utf8_encode($value);
                 }
             }
             $tempate_section = str_replace('{rss_listing_title}', $value, $tempate_section);
             $value = htmlentities(utf8_encode(listing_pages::getListingAgent($listing_id)), ENT_QUOTES, 'UTF-8');
             $tempate_section = str_replace('{listing_agent_name}', $value, $tempate_section);
             $value = htmlentities(utf8_encode(listing_pages::getListingAgentFirstName($listing_id)), ENT_QUOTES, 'UTF-8');
             $tempate_section = str_replace('{listing_agent_first_name}', $value, $tempate_section);
             $value = htmlentities(utf8_encode(listing_pages::getListingAgentLastName($listing_id)), ENT_QUOTES, 'UTF-8');
             $tempate_section = str_replace('{listing_agent_last_name}', $value, $tempate_section);
             $value = htmlentities(utf8_encode(listing_pages::getListingAgentLink($listing_id)), ENT_QUOTES, 'UTF-8');
             $tempate_section = str_replace('{listing_agent_link}', $value, $tempate_section);
             $value = htmlentities(utf8_encode(listing_pages::get_pclass($listing_id)), ENT_QUOTES, 'UTF-8');
             $tempate_section = str_replace('{listing_pclass}', $value, $tempate_section);
             $value = htmlentities(utf8_encode(listing_pages::getAgentListingsLink($listing_id)), ENT_QUOTES, 'UTF-8');
             $tempate_section = str_replace('{listing_agent_listings}', $value, $tempate_section);
             $value = htmlentities(utf8_encode(listing_pages::getListingAgentID($listing_id)), ENT_QUOTES, 'UTF-8');
             $tempate_section = str_replace('{listing_agent_id}', $value, $tempate_section);
             // Get listing owner
             $owner_sql = 'SELECT userdb_id FROM ' . $config['table_prefix'] . 'listingsdb WHERE (listingsdb_id = ' . $or_replace_listing_id . ')';
             $recordSet = $conn->execute($owner_sql);
             $or_replace_listing_owner = $recordSet->fields['userdb_id'];
             //New listing_agent_field_****_block tag handler for 2.4.1
             $laf_blocks = array();
             preg_match_all('/{listing_agent_field_([^{}]*?)_block}/', $tempate_section, $laf_blocks);
             require_once $config['basepath'] . '/include/user.inc.php';
             global $or_replace_listing_owner;
             if (count($laf_blocks) > 1) {
                 foreach ($laf_blocks[1] as $block) {
                     $value = user::renderSingleListingItem($or_replace_listing_owner, $block, 'rawvalue');
                     if ($value == '') {
                         $tempate_section = preg_replace('/{listing_agent_field_' . $block . '_block}(.*?){\\/listing_agent_field_' . $block . '_block}/is', '', $tempate_section);
                     } else {
                         $tempate_section = str_replace('{listing_agent_field_' . $block . '_block}', '', $tempate_section);
                         $tempate_section = str_replace('{/listing_agent_field_' . $block . '_block}', '', $tempate_section);
                     }
                 }
             }
             // Replace listing_agent tags
             // Handle Caption Only
             $tempate_section = preg_replace_callback('/{listing_agent_field_([^{}]*?)_caption}/', create_function('$matches', 'global $config,$or_replace_listing_owner,$lang;require_once($config[\'basepath\'].\'/include/user.inc.php\'); return htmlentities(utf8_encode(user::renderSingleListingItem($or_replace_listing_owner, $matches[1],\'caption\')), ENT_QUOTES, \'UTF-8\');'), $tempate_section);
             // Hanle Value Only
             $tempate_section = preg_replace_callback('/{listing_agent_field_([^{}]*?)_value}/', create_function('$matches', 'global $config,$or_replace_listing_owner,$lang;require_once($config[\'basepath\'].\'/include/user.inc.php\'); return htmlentities(utf8_encode(user::renderSingleListingItem($or_replace_listing_owner, $matches[1],\'value\')), ENT_QUOTES, \'UTF-8\');'), $tempate_section);
             // Handle Raw Value
             $tempate_section = preg_replace_callback('/{listing_agent_field_([^{}]*?)_rawvalue}/', create_function('$matches', 'global $config,$or_replace_listing_owner,$lang;require_once($config[\'basepath\'].\'/include/user.inc.php\'); return htmlentities(utf8_encode(user::renderSingleListingItem($or_replace_listing_owner, $matches[1],\'rawvalue\')), ENT_QUOTES, \'UTF-8\');'), $tempate_section);
             // Handle Both Caption and Value
             $tempate_section = preg_replace_callback('/{listing_agent_field_([^{}]*?)}/', create_function('$matches', 'global $config,$or_replace_listing_owner,$lang;require_once($config[\'basepath\'].\'/include/user.inc.php\'); return htmlentities(utf8_encode(user::renderSingleListingItem($or_replace_listing_owner, $matches[1])), ENT_QUOTES, \'UTF-8\');'), $tempate_section);
         } else {
             //Deal with listing field blocks
             $lf_blocks = array();
             preg_match_all('/{listing_field_([^{}]*?)_block}/', $tempate_section, $lf_blocks);
             require_once $config['basepath'] . '/include/user.inc.php';
             global $or_replace_listing_owner;
             if (count($lf_blocks) > 1) {
                 foreach ($lf_blocks[1] as $block) {
                     require_once $config['basepath'] . '/include/listing.inc.php';
                     $value = listing_pages::renderSingleListingItem($or_replace_listing_id, $block, 'rawvalue');
                     if ($value == '') {
                         $tempate_section = preg_replace('/{listing_field_' . $block . '_block}(.*?){\\/listing_field_' . $block . '_block}/is', '', $tempate_section);
                     } else {
                         $tempate_section = str_replace('{listing_field_' . $block . '_block}', '', $tempate_section);
                         $tempate_section = str_replace('{/listing_field_' . $block . '_block}', '', $tempate_section);
                     }
                 }
             }
             // Handle Caption Only
             $tempate_section = preg_replace_callback('/{listing_field_([^{}]*?)_caption}/', create_function('$matches', 'global $config,$or_replace_listing_id,$lang;require_once($config[\'basepath\'].\'/include/listing.inc.php\'); return listing_pages::renderSingleListingItem($or_replace_listing_id, $matches[1],\'caption\');'), $tempate_section);
             // Hanle Value Only
             $tempate_section = preg_replace_callback('/{listing_field_([^{}]*?)_value}/', create_function('$matches', 'global $config,$or_replace_listing_id,$lang;require_once($config[\'basepath\'].\'/include/listing.inc.php\'); return listing_pages::renderSingleListingItem($or_replace_listing_id, $matches[1],\'value\');'), $tempate_section);
             // Handle Raw Value
             $tempate_section = preg_replace_callback('/{listing_field_([^{}]*?)_rawvalue}/', create_function('$matches', 'global $config,$or_replace_listing_id,$lang;require_once($config[\'basepath\'].\'/include/listing.inc.php\'); return listing_pages::renderSingleListingItem($or_replace_listing_id, $matches[1],\'rawvalue\');'), $tempate_section);
             // Handle Both Caption and Value
             $tempate_section = preg_replace_callback('/{listing_field_([^{}]*?)}/', create_function('$matches', 'global $config,$or_replace_listing_id,$lang;require_once($config[\'basepath\'].\'/include/listing.inc.php\'); return listing_pages::renderSingleListingItem($or_replace_listing_id, $matches[1]);'), $tempate_section);
             $value = listing_pages::get_title($listing_id);
             $tempate_section = str_replace('{listing_title}', $value, $tempate_section);
             $value = listing_pages::getListingAgent($listing_id);
             $tempate_section = str_replace('{listing_agent_name}', $value, $tempate_section);
             $value = listing_pages::getListingAgentFirstName($listing_id);
             $tempate_section = str_replace('{listing_agent_first_name}', $value, $tempate_section);
             $value = listing_pages::getListingAgentLastName($listing_id);
             $tempate_section = str_replace('{listing_agent_last_name}', $value, $tempate_section);
             $value = listing_pages::getListingAgentLink($listing_id);
             $tempate_section = str_replace('{listing_agent_link}', $value, $tempate_section);
             $value = listing_pages::get_pclass($listing_id);
             $tempate_section = str_replace('{listing_pclass}', $value, $tempate_section);
             $value = listing_pages::getAgentListingsLink($listing_id);
             $tempate_section = str_replace('{listing_agent_listings}', $value, $tempate_section);
             $value = listing_pages::getListingAgentID($listing_id);
             $tempate_section = str_replace('{listing_agent_id}', $value, $tempate_section);
             // Get listing owner
             $owner_sql = 'SELECT userdb_id FROM ' . $config['table_prefix'] . 'listingsdb WHERE (listingsdb_id = ' . $or_replace_listing_id . ')';
             $recordSet = $conn->execute($owner_sql);
             $or_replace_listing_owner = $recordSet->fields['userdb_id'];
             $laf_blocks = array();
             preg_match_all('/{listing_agent_field_([^{}]*?)_block}/', $tempate_section, $laf_blocks);
             require_once $config['basepath'] . '/include/user.inc.php';
             global $or_replace_listing_owner;
             if (count($laf_blocks) > 1) {
                 foreach ($laf_blocks[1] as $block) {
                     $value = user::renderSingleListingItem($or_replace_listing_owner, $block, 'rawvalue');
                     if ($value == '') {
                         $tempate_section = preg_replace('/{listing_agent_field_' . $block . '_block}(.*?){\\/listing_agent_field_' . $block . '_block}/is', '', $tempate_section);
                     } else {
                         $tempate_section = str_replace('{listing_agent_field_' . $block . '_block}', '', $tempate_section);
                         $tempate_section = str_replace('{/listing_agent_field_' . $block . '_block}', '', $tempate_section);
                     }
                 }
             }
             // Replace listing_agent tags
             // Handle Caption Only
             $tempate_section = preg_replace_callback('/{listing_agent_field_([^{}]*?)_caption}/', create_function('$matches', 'global $config,$or_replace_listing_owner,$lang;require_once($config[\'basepath\'].\'/include/user.inc.php\'); return user::renderSingleListingItem($or_replace_listing_owner, $matches[1],\'caption\');'), $tempate_section);
             // Hanle Value Only
             $tempate_section = preg_replace_callback('/{listing_agent_field_([^{}]*?)_value}/', create_function('$matches', 'global $config,$or_replace_listing_owner,$lang;require_once($config[\'basepath\'].\'/include/user.inc.php\'); return user::renderSingleListingItem($or_replace_listing_owner, $matches[1],\'value\');'), $tempate_section);
             // Handle Raw Value
             $tempate_section = preg_replace_callback('/{listing_agent_field_([^{}]*?)_rawvalue}/', create_function('$matches', 'global $config,$or_replace_listing_owner,$lang;require_once($config[\'basepath\'].\'/include/user.inc.php\'); return user::renderSingleListingItem($or_replace_listing_owner, $matches[1],\'rawvalue\');'), $tempate_section);
             // Handle Both Caption and Value
             $tempate_section = preg_replace_callback('/{listing_agent_field_([^{}]*?)}/', create_function('$matches', 'global $config,$or_replace_listing_owner,$lang;require_once($config[\'basepath\'].\'/include/user.inc.php\'); return user::renderSingleListingItem($or_replace_listing_owner, $matches[1]);'), $tempate_section);
         }
         // Listing Images
         $sql2 = "SELECT listingsdb_title FROM " . $config['table_prefix'] . "listingsdb WHERE listingsdb_id = {$listing_id}";
         $recordSet2 = $conn->Execute($sql2);
         if (!$recordSet2) {
             $misc->log_error($sql2);
         }
         $Title = $misc->make_db_unsafe($recordSet2->fields['listingsdb_title']);
         if ($config['url_style'] == '1') {
             $url = '<a href="index.php?action=listingview&amp;listingID=' . $listing_id . '">';
             $fullurl = '<a href="' . $config["baseurl"] . '/index.php?action=listingview&amp;listingID=' . $listing_id . '">';
             // Listing Link
             $tempate_section = str_replace('{link_to_listing}', 'index.php?action=listingview&amp;listingID=' . $listing_id, $tempate_section);
             $tempate_section = str_replace('{fulllink_to_listing}', $config['baseurl'] . '/index.php?action=listingview&amp;listingID=' . $listing_id, $tempate_section);
         } else {
             $url_title = str_replace("/", "", $Title);
             $url_title = strtolower(str_replace(" ", $config['seo_url_seperator'], $url_title));
             $url = '<a href="listing-' . misc::urlencode_to_sef($url_title) . '-' . $listing_id . '.html">';
             $fullurl = '<a href="' . $config["baseurl"] . '/listing-' . misc::urlencode_to_sef($url_title) . '-' . $listing_id . '.html">';
             // Listing Link
             $tempate_section = str_replace('{link_to_listing}', 'listing-' . misc::urlencode_to_sef($url_title) . '-' . $listing_id . '.html', $tempate_section);
             $tempate_section = str_replace('{fulllink_to_listing}', '' . $config["baseurl"] . '/listing-' . misc::urlencode_to_sef($url_title) . '-' . $listing_id . '.html', $tempate_section);
         }
         // grab the listing's image
         $sql2 = "SELECT listingsimages_id, listingsimages_caption, listingsimages_thumb_file_name, listingsimages_file_name FROM " . $config['table_prefix'] . "listingsimages WHERE listingsdb_id = {$listing_id} ORDER BY listingsimages_rank";
         $recordSet2 = $conn->Execute($sql2);
         if (!$recordSet2) {
             $misc->log_error($sql2);
         }
         $num_images = $recordSet2->RecordCount();
         if ($num_images == 0) {
             if ($config['show_no_photo'] == 1) {
                 $listing_image = $url . '<img src="' . $config["baseurl"] . '/images/nophoto.gif" alt="' . $lang['no_photo'] . '" /></a>';
                 $listing_image_full = $fullurl . '<img src="' . $config["baseurl"] . '/images/nophoto.gif" alt="' . $lang['no_photo'] . '" /></a>';
                 if ($_GET['action'] == 'listingview') {
                     $listing_image = '<img src="' . $config["baseurl"] . '/images/nophoto.gif" alt="' . $lang['no_photo'] . '" />';
                     $listing_image_full = '<img src="' . $config["baseurl"] . '/images/nophoto.gif" alt="' . $lang['no_photo'] . '" />';
                 }
                 $tempate_section = str_replace('{raw_image_thumb_1}', $config['baseurl'] . '/images/nophoto.gif', $tempate_section);
             } else {
                 $listing_image = '';
                 $tempate_section = str_replace('{raw_image_thumb_1}', '', $tempate_section);
             }
             $tempate_section = str_replace('{image_thumb_1}', $listing_image, $tempate_section);
             $tempate_section = str_replace('{image_thumb_fullurl_1}', $listing_image, $tempate_section);
         }
         $x = 1;
         while (!$recordSet2->EOF) {
             //if we're already on the listing then make the urls goto the view image
             $listingsimages_id = $misc->make_db_unsafe($recordSet2->fields['listingsimages_id']);
             $image_caption = $misc->make_db_unsafe($recordSet2->fields['listingsimages_caption']);
             $thumb_file_name = $misc->make_db_unsafe($recordSet2->fields['listingsimages_thumb_file_name']);
             $full_file_name = $misc->make_db_unsafe($recordSet2->fields['listingsimages_file_name']);
             if ($_GET['action'] == 'listingview') {
                 if ($config['url_style'] == '1') {
                     $url = '<a href="index.php?action=view_listing_image&amp;image_id=' . $listingsimages_id . '">';
                     $fullurl = '<a href="' . $config["baseurl"] . '/index.php?action=view_listing_image&amp;image_id=' . $listingsimages_id . '">';
                 } else {
                     $url = '<a href="listing_image_' . $listingsimages_id . '.html">';
                     $fullurl = '<a href="' . $config["baseurl"] . '/listing_image_' . $listingsimages_id . '.html">';
                 }
             }
             if ($thumb_file_name != "" && file_exists("{$config['listings_upload_path']}/{$thumb_file_name}")) {
                 // Full Image Sizes
                 $imagedata = GetImageSize("{$config['listings_upload_path']}/{$full_file_name}");
                 $imagewidth = $imagedata[0];
                 $imageheight = $imagedata[1];
                 $max_width = $config['main_image_width'];
                 $max_height = $config['main_image_height'];
                 $resize_by = $config['resize_by'];
                 $shrinkage = 1;
                 if ($max_width == $imagewidth || $max_height == $imageheight) {
                     $display_width = $imagewidth;
                     $display_height = $imageheight;
                 } else {
                     if ($resize_by == 'width') {
                         $shrinkage = $imagewidth / $max_width;
                         $display_width = $max_width;
                         $display_height = round($imageheight / $shrinkage);
                     } elseif ($resize_by == 'height') {
                         $shrinkage = $imageheight / $max_height;
                         $display_height = $max_height;
                         $display_width = round($imagewidth / $shrinkage);
                     } elseif ($resize_by == 'both') {
                         $display_width = $max_width;
                         $display_height = $max_height;
                     } elseif ($resize_by == 'bestfit') {
                         $shrinkage_width = $imagewidth / $max_width;
                         $shrinkage_height = $imageheight / $max_height;
                         $shrinkage = max($shrinkage_width, $shrinkage_height);
                         $display_height = round($imageheight / $shrinkage);
                         $display_width = round($imagewidth / $shrinkage);
                     }
                 }
                 // Thumbnail Image Sizes
                 $thumb_imagedata = GetImageSize("{$config['listings_upload_path']}/{$thumb_file_name}");
                 $thumb_imagewidth = $thumb_imagedata[0];
                 $thumb_imageheight = $thumb_imagedata[1];
                 $thumb_max_width = $config['thumbnail_width'];
                 $thumb_max_height = $config['thumbnail_height'];
                 $resize_thumb_by = $config['resize_thumb_by'];
                 $shrinkage = 1;
                 if ($thumb_max_width == $thumb_imagewidth || $thumb_max_height == $thumb_imageheight) {
                     $thumb_displaywidth = $thumb_imagewidth;
                     $thumb_displayheight = $thumb_imageheight;
                 } else {
                     if ($resize_thumb_by == 'width') {
                         $shrinkage = $thumb_imagewidth / $thumb_max_width;
                         $thumb_displaywidth = $thumb_max_width;
                         $thumb_displayheight = round($thumb_imageheight / $shrinkage);
                     } elseif ($resize_thumb_by == 'height') {
                         $shrinkage = $thumb_imageheight / $thumb_max_height;
                         $thumb_displayheight = $thumb_max_height;
                         $thumb_displaywidth = round($thumb_imagewidth / $shrinkage);
                     } elseif ($resize_thumb_by == 'both') {
                         $thumb_displayheight = $thumb_max_height;
                         $thumb_displaywidth = $thumb_max_width;
                     }
                 }
                 $listing_image = $url . '<img src="' . $config['listings_view_images_path'] . '/' . $thumb_file_name . '" height="' . $thumb_displayheight . '" width="' . $thumb_displaywidth . '" alt="' . $image_caption . '" /></a>';
                 $listing_image_full = $url . '<img src="' . $config['listings_view_images_path'] . '/' . $full_file_name . '" height="' . $display_height . '" width="' . $display_width . '" alt="' . $image_caption . '" /></a>';
                 $listing_image_fullurl = $fullurl . '<img src="' . $config['listings_view_images_path'] . '/' . $thumb_file_name . '" height="' . $thumb_displayheight . '" width="' . $thumb_displaywidth . '" alt="' . $image_caption . '" /></a>';
                 $listing_image_full_fullurl = $fullurl . '<img src="' . $config['listings_view_images_path'] . '/' . $full_file_name . '" height="' . $display_height . '" width="' . $display_width . '" alt="' . $image_caption . '" /></a>';
                 $tempate_section = str_replace('{image_thumb_' . $x . '}', $listing_image, $tempate_section);
                 $tempate_section = str_replace('{raw_image_thumb_' . $x . '}', $config['listings_view_images_path'] . '/' . $thumb_file_name, $tempate_section);
                 $tempate_section = str_replace('{image_thumb_fullurl_' . $x . '}', $listing_image_fullurl, $tempate_section);
                 //Full Image tags
                 $tempate_section = str_replace('{image_full_' . $x . '}', $listing_image_full, $tempate_section);
                 $tempate_section = str_replace('{raw_image_full_' . $x . '}', $config['listings_view_images_path'] . '/' . $full_file_name, $tempate_section);
                 $tempate_section = str_replace('{image_full_fullurl_' . $x . '}', $listing_image_full_fullurl, $tempate_section);
             } else {
                 if ($config['show_no_photo'] == 1) {
                     $listing_image = $url . '<img src="' . $config["baseurl"] . '/images/nophoto.gif" alt="' . $lang['no_photo'] . '" /></a>';
                     $listing_image_fullurl = $fullurl . '<img src="' . $config["baseurl"] . '/images/nophoto.gif" alt="' . $lang['no_photo'] . '" /></a>';
                     $tempate_section = str_replace('{raw_image_thumb_' . $x . '}', $config['baseurl'] . '/images/nophoto.gif', $tempate_section);
                 } else {
                     $listing_image = '';
                     $tempate_section = str_replace('{raw_image_thumb_' . $x . '}', '', $tempate_section);
                 }
                 $tempate_section = str_replace('{image_thumb_' . $x . '}', $listing_image, $tempate_section);
                 $tempate_section = str_replace('{image_thumb_fullurl_' . $x . '}', $listing_image_fullurl, $tempate_section);
                 $tempate_section = str_replace('{image_full_' . $x . '}', '', $tempate_section);
                 $tempate_section = str_replace('{raw_image_full_' . $x . '}', '', $tempate_section);
                 $tempate_section = str_replace('{image_full_fullurl_' . $x . '}', '', $tempate_section);
             }
             // We have the image so insert it into the section.
             $x++;
             $recordSet2->MoveNext();
         }
         // end while
         // End Listing Images
         $value = array();
         $value = listing_pages::getListingAgentThumbnail($listing_id);
         $x = 0;
         foreach ($value as $y) {
             $tempate_section = str_replace('{listing_agent_thumbnail_' . $x . '}', $y, $tempate_section);
             $x++;
         }
         $tempate_section = preg_replace('/{listing_agent_thumbnail_([^{}]*?)}/', '', $tempate_section);
         // End of Listing Tag Replacement
         if ($tsection === true) {
             return $tempate_section;
         } else {
             $this->page = $tempate_section;
         }
     }
 }
 function update_listing($verify_user = true)
 {
     global $conn, $lang, $config;
     require_once $config['basepath'] . '/include/misc.inc.php';
     $misc = new misc();
     require_once $config['basepath'] . '/include/forms.inc.php';
     $forms = new forms();
     require_once $config['basepath'] . '/include/listing.inc.php';
     $listing_pages = new listing_pages();
     $display = '';
     // update the listing
     if ($verify_user) {
         $sql_edit = intval($_POST['edit']);
         $listing_ownerID = $listing_pages->getListingAgentID($sql_edit);
         if (intval($_SESSION['userID']) != $listing_ownerID) {
             $display = $lang['listing_editor_permission_denied'] . '<br />';
             return $display;
         }
     }
     if ($_POST['title'] == "") {
         // if the title is blank
         $display .= "{$lang['admin_new_listing_enter_a_title']}<br />";
     } else {
         $pass_the_form = $forms->validateForm('listingsformelements', $_POST['pclass']);
         if ($pass_the_form !== "Yes") {
             // if we're not going to pass it, tell that they forgot to fill in one of the fields
             foreach ($pass_the_form as $k => $v) {
                 if ($v == 'REQUIRED') {
                     $display .= "<p class=\"redtext\">{$k}: {$lang['required_fields_not_filled']}</p>";
                 }
                 if ($v == 'TYPE') {
                     $display .= "<p class=\"redtext\">{$k}: {$lang['field_type_does_not_match']}</p>";
                 }
             }
             // $display .= "<p>$lang[required_fields_not_filled]</p>";
         }
         if ($pass_the_form == "Yes") {
             $sql_title = $misc->make_db_safe($_POST['title']);
             $sql_notes = $misc->make_db_safe($_POST['notes']);
             $sql_edit = $misc->make_db_safe($_POST['edit']);
             if (!isset($_POST['mlsexport'])) {
                 $_POST['mlsexport'] = "no";
             }
             $sql_mlsexport = $misc->make_db_safe($_POST['mlsexport']);
             $sql = "UPDATE " . $config['table_prefix'] . "listingsdb SET ";
             if (!$verify_user) {
                 $sql_or_owner = $misc->make_db_safe($_POST['or_owner']);
                 // update the listing data
                 $sql .= "userdb_ID = {$sql_or_owner}, ";
             }
             $sql .= "listingsdb_title = {$sql_title}, ";
             if ($_SESSION['admin_privs'] == "yes" || $_SESSION['featureListings'] == "yes") {
                 // Check Number of Featured Listings User has
                 if (isset($_POST['or_owner'])) {
                     $or_owner = $misc->make_db_safe($_POST['or_owner']);
                     $featuredsql = 'SELECT count(listingsdb_id) as listing_count FROM ' . $config['table_prefix'] . 'listingsdb WHERE listingsdb_featured = \'yes\' AND userdb_id = ' . $or_owner;
                 } else {
                     $featuredsql = 'SELECT count(listingsdb_id) as listing_count FROM ' . $config['table_prefix'] . 'listingsdb WHERE listingsdb_featured = \'yes\' AND userdb_id = ' . $_SESSION['userID'];
                 }
                 $recordSet = $conn->Execute($featuredsql);
                 if ($recordSet === false) {
                     $misc->log_error($featuredsql);
                 }
                 $featuredlisting_count = $recordSet->fields['listing_count'];
                 // Get User Featured Listing Limit
                 if (isset($_POST['or_owner'])) {
                     $or_owner = $misc->make_db_safe($_POST['or_owner']);
                     $featuredsql = 'SELECT userdb_featuredlistinglimit FROM ' . $config['table_prefix'] . 'userdb WHERE userdb_id = ' . $or_owner;
                 } else {
                     $featuredsql = 'SELECT userdb_featuredlistinglimit FROM ' . $config['table_prefix'] . 'userdb WHERE userdb_id = ' . $_SESSION['userID'];
                 }
                 $recordSet = $conn->Execute($featuredsql);
                 if ($recordSet === false) {
                     $misc->log_error($featuredsql);
                 }
                 $featuredlisting_limit = $recordSet->fields['userdb_featuredlistinglimit'];
                 $featuredLimitError = FALSE;
                 if ($_POST['featured'] == 'yes') {
                     if ($featuredlisting_limit > $featuredlisting_count || $featuredlisting_limit == '-1') {
                         // if the user can feature properties
                         $sql_featured = $misc->make_db_safe($_POST['featured']);
                         $sql .= "listingsdb_featured = {$sql_featured}, ";
                     } else {
                         //See if we are already featured..
                         $featuredcheckSql = 'SELECT listingsdb_featured FROM ' . $config['table_prefix'] . 'listingsdb WHERE listingsdb_id = ' . $sql_edit;
                         $recordSetFeatured = $conn->Execute($featuredcheckSql);
                         if ($recordSetFeatured === false) {
                             $misc->log_error($featuredcheckSql);
                         }
                         $current_status = $recordSetFeatured->fields['listingsdb_featured'];
                         if ($current_status == 'yes') {
                             $sql_featured = $misc->make_db_safe($_POST['featured']);
                             $sql .= "listingsdb_featured = {$sql_featured}, ";
                         } else {
                             $featuredLimitError = TRUE;
                         }
                     }
                 } else {
                     //Not Feautred Save no matter what
                     $sql_featured = $misc->make_db_safe($_POST['featured']);
                     $sql .= "listingsdb_featured = {$sql_featured}, ";
                 }
             }
             // end if ($featureListings == "yes")
             if ($_SESSION['admin_privs'] == "yes" || $_SESSION['moderator'] == "yes") {
                 // if the user is an administrtor
                 $sql_active = $misc->make_db_safe($_POST['edit_active']);
                 $sql .= "listingsdb_active = {$sql_active}, ";
             }
             // end if ($admin_privs == "yes")
             if (($_SESSION['admin_privs'] == "yes" || $_SESSION['edit_expiration'] == "yes") && $config['use_expiration'] == "1") {
                 $expiration_date = $misc->or_date_format($_POST['edit_expiration']);
                 $sql .= "listingsdb_expiration = " . $expiration_date . ",";
             }
             if ($verify_user) {
                 $sql .= "listingsdb_notes = {$sql_notes}, listingsdb_mlsexport = {$sql_mlsexport}, listingsdb_last_modified = " . $conn->DBTimeStamp(time()) . " WHERE ((listingsdb_id = {$sql_edit}) AND (userdb_id = {$_SESSION['userID']}))";
             } else {
                 $sql .= "listingsdb_notes = {$sql_notes}, listingsdb_mlsexport = {$sql_mlsexport}, listingsdb_last_modified = " . $conn->DBTimeStamp(time()) . " WHERE listingsdb_id = {$sql_edit}";
             }
             $recordSet = $conn->Execute($sql);
             if ($recordSet === false) {
                 $misc->log_error($sql);
             }
             if ($verify_user) {
                 $message = listing_editor::updateListingsData($_POST['edit'], $_SESSION['userID']);
             } else {
                 // update the image data (in case the or_owner has changed)
                 $sql = "UPDATE " . $config['table_prefix'] . "listingsimages SET userdb_id = {$sql_or_owner} WHERE listingsdb_id = {$sql_edit}";
                 $recordSet = $conn->Execute($sql);
                 if ($recordSet === false) {
                     $misc->log_error($sql);
                 }
                 $message = listing_editor::updateListingsData($_POST['edit'], $_POST['or_owner']);
             }
             // Ok Now Handle Any property class changes that all the data is saved.
             // First Get a list of all the currently assing property classes.
             $sql2 = 'SELECT class_id FROM ' . $config['table_prefix_no_lang'] . 'classlistingsdb WHERE listingsdb_id =' . $sql_edit;
             $recordSet2 = $conn->execute($sql2);
             if ($recordSet2 === false) {
                 $misc->log_error($sql2);
             }
             $current_class_id = array();
             while (!$recordSet2->EOF) {
                 $current_class_id[] = $recordSet2->fields['class_id'];
                 $recordSet2->MoveNext();
             }
             // Get List of edited pclasses
             $new_class_assigned_sql = implode(',', $_POST['pclass']);
             // Now if teh property class is no longer assigned remove this listin from the class and remove any listing fields tha belogn only to this class
             foreach ($current_class_id as $c_class_id) {
                 if (!in_array($c_class_id, $_POST['pclass'])) {
                     // Delete listing from class
                     $sql = 'DELETE FROM ' . $config['table_prefix_no_lang'] . 'classlistingsdb WHERE class_id = ' . $c_class_id . ' AND listingsdb_id = ' . $sql_edit;
                     $recordSet = $conn->execute($sql);
                     if ($recordSet === false) {
                         $misc->log_error($sql);
                     }
                     // Get a list of form element ids for the new selected property classes
                     $sql = 'SELECT listingsformelements_id FROM ' . $config['table_prefix_no_lang'] . 'classformelements WHERE class_id IN (' . $new_class_assigned_sql . ')';
                     $recordSet = $conn->execute($sql);
                     if ($recordSet === false) {
                         $misc->log_error($sql);
                     }
                     $formelement_ids = array();
                     while (!$recordSet->EOF) {
                         $formelement_ids[] = $recordSet->fields['listingsformelements_id'];
                         $recordSet->Movenext();
                     }
                     $new_listingsformelements_id_sql = implode(',', $formelement_ids);
                     $sql = 'SELECT DISTINCT(listingsformelements_field_name) FROM ' . $config['table_prefix_no_lang'] . 'classformelements as c,' . $config['table_prefix'] . 'listingsformelements as f WHERE class_id = ' . $c_class_id . ' AND c.listingsformelements_id NOT IN (' . $new_listingsformelements_id_sql . ') AND c.listingsformelements_id = f.listingsformelements_id';
                     if ($recordSet === false) {
                         $misc->log_error($sql);
                     }
                     while (!$recordSet->EOF) {
                         $sql2 = 'DELETE FROM ' . $config['table_prefix'] . 'listingsdbelements WHERE listingsdbelements_field_name = ' . $recordSet->fields['listingsformelements_field_name'] . ' AND listingsdb_id = ' . $sql_edit;
                         $recordSet2 = $conn->execute($sql2);
                         if ($recordSet2 === false) {
                             $misc->log_error($sql2);
                         }
                     }
                 }
             }
             // If this is a new class add the listing to the class
             foreach ($_POST['pclass'] as $class_id) {
                 if (!in_array($class_id, $current_class_id)) {
                     $sql2 = 'INSERT INTO ' . $config['table_prefix_no_lang'] . 'classlistingsdb (class_id,listingsdb_id) VALUES (' . $class_id . ',' . $sql_edit . ')';
                     $recordSet2 = $conn->execute($sql2);
                     if ($recordSet2 === false) {
                         $misc->log_error($sql2);
                     }
                 }
             }
             if ($message == "success") {
                 $display .= "<p>{$lang['admin_listings_editor_listing_number']} {$_POST['edit']} {$lang['has_been_updated']} </p>";
                 if ($featuredLimitError == TRUE) {
                     $display .= "<p style=\"error\">{$lang['admin_listings_editor_featuredlistingerror']} </p>";
                 }
                 $misc->log_action("{$lang['log_updated_listing']} {$_POST['edit']}");
             } else {
                 $display .= "<p>{$lang['alert_site_admin']}</p>";
             }
             // end else
         }
         // end if $pass_the_form == "Yes"
     }
     // end else
     return $display;
 }