<?php
/*
#****************************************************************************#
# Ultimate Locator                                                              #
# Professional Zip Code Locator Systems          support@ultimatelocator.com #
# Copyright 2004 PageSkills.com Internet Services    www.ultimatelocator.com #
# Release Date: 2/01/2004                                                    #
#                                                                            #
#   Ultimate Locator is protected by the copyright                           #
#   laws and international copyright treaties, as well as other              #
#   intellectual property laws and treaties.                                 #
#   Distribution without approved license is illegal and is                  #
#   punishable by law.                                                       #
#                                                                            #
#   A license is good toward one domain only.  You must purchase             #
#   additional licenses if you wish to install this software on              #
#   additional domains (websites). We do offer Reseller Packages.            #
#****************************************************************************#
*/

require_once("admin/config.php");
$fp5=fopen("$user_path/results_details.htm","r");
$str5=fread($fp5,filesize("$user_path/results_details.htm"));

$ts=explode("{#}",$str5);

$fp=fopen("$user_path/results_details_format.htm","r");
$str=fread($fp,filesize("$user_path/results_details_format.htm"));

$query="Select * from location where id='$id'";
$data=mysql_query($query,$zip_connection);

$query="Select hide as h1 from setfield";
$data1=mysql_query($query,$zip_connection);


        if(mysql_result($data1,0,"h1")==0)
        {
        $str=str_replace("{name}",mysql_result($data,0,"name"),$str);
        }
        else
        {
        $str=str_replace("{name}","",$str);
        }

        if(mysql_result($data1,1,"h1")==0)
        {
        $str=str_replace("{address1}",mysql_result($data,0,"address1"),$str);
        }
        else
        {
        $str=str_replace("{address1}","",$str);
        }

        if(mysql_result($data1,1,"h1")==0)
        {
        $str=str_replace("{address2}",mysql_result($data,0,"address2"),$str);
        }
        else
        {
        $str=str_replace("{address2}","",$str);
        }

        if(mysql_result($data1,2,"h1")==0)
        {
        $str=str_replace("{city}",mysql_result($data,0,"city"),$str);
        }
        else
        {
        $str=str_replace("{city}","",$str);
        }

        if(mysql_result($data1,3,"h1")==0)
        {
        $str=str_replace("{state}",mysql_result($data,0,"state"),$str);
        }
        else
        {
        $str=str_replace("{state}","",$str);
        }

        if(mysql_result($data1,4,"h1")==0)
        {
        $str=str_replace("{country}",mysql_result($data,0,"country"),$str);
        }
        else
        {
        $str=str_replace("{country}","",$str);
        }

        if(mysql_result($data1,5,"h1")==0)
        {
        $str=str_replace("{zip}",mysql_result($data,0,"zip"),$str);
        }
        else
        {
        $str=str_replace("{zip}","",$str);
        }

        if(mysql_result($data1,6,"h1")==0)
        {
        $str=str_replace("{telephone}",mysql_result($data,0,"telephone"),$str);
        }
        else
        {
        $str=str_replace("{telephone}","",$str);
        }

        if(mysql_result($data1,7,"h1")==0)
        {
        $str=str_replace("{fax}",mysql_result($data,0,"fax"),$str);
        }
        else
        {
        $str=str_replace("{fax}","",$str);
        }

        if(mysql_result($data1,8,"h1")==0)
        {
        $str=str_replace("{email}",mysql_result($data,0,"email"),$str);
        }
        else
        {
        $str=str_replace("{email}","",$str);
        }

        if(mysql_result($data1,9,"h1")==0)
        {
                if($website_link_target==0)
                {
                $target="";
                }
                if($website_link_target==1)
                {
                $target="_blank";
                }

                if (mysql_result($data,0,"website") !="") {
                $str=str_replace("{website}","<a class=\"websiteLink\" href=\"http://".mysql_result($data,0,"website")."\" target=\"$target\">"."http://".mysql_result($data,0,"website")."</a>",$str);
                }
                else
                {
                $str=str_replace("{website}","",$str);
                }

        }
        else
        {
        $str=str_replace("{website}","",$str);
        }

        if ($dist != "") {
           $str=str_replace("{distance}","Distance: ".$dist,$str); }
        else {
           $str=str_replace("{distance}"," ",$str); }



        if (mysql_result($data,0,"zip") != "-") {
         if($map_link_text!="")
         {

           if ($show_map_link == 1) {
            if ($map_target==1) {$target="_blank";}
             if ($map_target==0){$target="";}

        $streetY = mysql_result($data,0,"address1");
        $cityY = mysql_result($data,0,"city");
        $stateY = mysql_result($data,0,"state");
        $zipY = mysql_result($data,0,"zip");
        $countryY = mysql_result($data,0,"country");
        $streetMQ = str_replace(" ","+",mysql_result($data,0,"address1"));
        $cityMQ = str_replace(" ","+",mysql_result($data,0,"city"));
        $stateMQ = str_replace(" ","+",mysql_result($data,0,"state"));
        $zipMQ = str_replace(" ","+",mysql_result($data,0,"zip"));
        $countryMQ = str_replace(" ","+",mysql_result($data,0,"country"));

        if ($map_service == "mapquest")
            {
              $stn="<a class=\"mapLink\" target=\"$target\" href=\"http://$mapquest_link?city=$cityMQ&state=$stateMQ&address=$streetMQ&zip=$zipMQ&zoom=5\">$map_link_text</a>";
              $str=str_replace("{maptext}",$stn,$str);
            }
        elseif ($map_service == "yahoo")
            {
              $stn="<a class=\"mapLink\" target=\"$target\" href=\"http://$yahoo_link?addr=$streetMQ&csz=$cityY+$stateY+$zipY&country=$countryY\">$map_link_text</a>";
              $str=str_replace("{maptext}",$stn,$str);
            }
        else { $str=str_replace("{maptext}"," ",$str); }

        }
        }
        }
        else { $str=str_replace("{maptext}"," ",$str); }

$user1=mysql_result($data,0,"user1");
$user2=mysql_result($data,0,"user2");
$user3=mysql_result($data,0,"user3");
$user4=mysql_result($data,0,"user4");
$user5=mysql_result($data,0,"user5");

        if(mysql_result($data1,10,"h1")==0)
        {
        $str=str_replace("{user1label}",$users1,$str);
        $str=str_replace("{user1}",mysql_result($data,0,"user1"),$str);
        }
        else
        {
        $str=str_replace("{user1label}","",$str);
        $str=str_replace("{user1}","",$str);
        }

        if(mysql_result($data1,11,"h1")==0)
        {
        $str=str_replace("{user2label}",$users2,$str);
        $str=str_replace("{user2}",mysql_result($data,0,"user2"),$str);
        }
        else
        {
        $str=str_replace("{user2label}","",$str);
        $str=str_replace("{user2}","",$str);
        }

        if(mysql_result($data1,12,"h1")==0)
        {
        $str=str_replace("{user3label}",$users3,$str);
        $str=str_replace("{user3}",mysql_result($data,0,"user3"),$str);
        }
        else
        {
        $str=str_replace("{user3label}","",$str);
        $str=str_replace("{user3}","",$str);
        }

        if(mysql_result($data1,13,"h1")==0)
        {
        $str=str_replace("{user4label}",$users4,$str);
        $str=str_replace("{user4}",mysql_result($data,0,"user4"),$str);
        }
        else
        {
        $str=str_replace("{user4label}","",$str);
        $str=str_replace("{user4}","",$str);
        }

        if(mysql_result($data1,14,"h1")==0)
        {
        $str=str_replace("{user5label}",$users5,$str);
        $str=str_replace("{user5}",mysql_result($data,0,"user5"),$str);
        }
        else
        {
        $str=str_replace("{user5label}","",$str);
        $str=str_replace("{user5}","",$str);
        }

$hits=mysql_result($data,0,"hits");
$hits=$hits+1;
$qry="Update location set hits='$hits' where id='$id'";
$dat=mysql_query($qry,$zip_connection);

$str7=str_replace("{results}",$str,$ts[1]);

$str=$ts[0].$str7.$ts[2];

if($headerfooter==1)
{
// Print Header
   $hdr=fopen("$user_path/header.htm","r");
   $stx=fread($hdr,filesize("$user_path/header.htm"));
   $str=str_replace("{header}",$stx,$str);
   fclose($hdr);
// Print Footer
   $ftr=fopen("$user_path/footer.htm","r");
   $stx=fread($ftr,filesize("$user_path/footer.htm"));
   $str=str_replace("{footer}",$stx,$str);
   fclose($ftr);
}
else 
{
$str=str_replace("{header}","",$str);
$str=str_replace("{footer}","",$str);
}

$str=str_replace("{images}",$image_path,$str);
$str=str_replace("{site}",$site,$str);
$str=str_replace("{headtext}",$headtext,$str);

$str=str_replace("{idf}",$id,$str);

echo $str;
?>