All pastes #468292 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-05-03 00:30 UTC
rendered paste body
<?php
include ('../version.php');
require ('../config.php');
checkLoggedIn("yes");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
<title>Administration Panel - Maps2us PRO - Version: <?php echo $thisversion; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="../css/base.css" media="screen" rel="stylesheet" type="text/css" />
<link href="../css/iono.css" media="screen" rel="stylesheet" type="text/css" />
<!--[if IE]><link href="../css/hacks/iepc.css" media="screen" rel="Stylesheet" type="text/css" /><![endif]-->
</head>
<body>
<div id="wrapper">

<div id="header">
	<a href="index.php" id="logo">blue badge route</a>
	<ul>			
		<li>Version: <?php echo $thisversion; ?>&nbsp;&nbsp;</li>
		<li>Product: <a href="http://www.bluebadgeroute.biz" title="<?php echo $productname; ?>"><?php echo $productname; ?></a></li>
		<li><?php print("Logged in as: <b>".$_SESSION["login"]."</b></li>\n");
print("<li><a href=\"logout.php?".session_name()."=".session_id()."\" title=\"Logout\">Logout</a>"); ?></li>
	</ul>
</div>
<h1>Administration</h1>
<?php
function after ($this, $inthat)
   {
       if (!is_bool(strpos($inthat, $this)))
       return substr($inthat, strpos($inthat,$this)+strlen($this));
   };

function after_last ($this, $inthat)
   {
       if (!is_bool(strrevpos($inthat, $this)))
       return substr($inthat, strrevpos($inthat, $this)+strlen($this));
   };

function before ($this, $inthat)
   {
       return substr($inthat, 0, strpos($inthat, $this));
   };

function before_last ($this, $inthat)
   {
       return substr($inthat, 0, strrevpos($inthat, $this));
   };

function between ($this, $that, $inthat)
   {
     return before($that, after($this, $inthat));
   };

function between_last ($this, $that, $inthat)
   {
     return after_last($this, before_last($that, $inthat));
   };

function strrevpos($instr, $needle)
{
 $rev_pos = strpos (strrev($instr), strrev($needle));
 if ($rev_pos===false) return false;
 else return strlen($instr) - $rev_pos - strlen($needle);
};

if (isset($_POST['submit']))
{
    $name         = mysql_escape_string($_POST['name']);          
    $desc            = mysql_escape_string($_POST['desc']);
    $address           = mysql_escape_string($_POST['address']);             
    $town             = mysql_escape_string($_POST['town']);
    $county         = mysql_escape_string($_POST['county']);
    $postcode       = mysql_escape_string($_POST['postcode']);     
    $country           = mysql_escape_string($_POST['country']);
    $phone             = mysql_escape_string($_POST['phone']); 
	$lat             = mysql_escape_string($_POST['lat']);
	$long             = mysql_escape_string($_POST['long']);                     

    if ($name == '')
    {
        $msg .= "<div id=\"fail\"><p><strong>Error:</strong> You must enter a name for this location</p>
</div>";
        $error = 1;
    }
	
	if ($address == '')
    {
        $msg .= "<div id=\"fail\"><p><strong>Error:</strong> You must enter an address / state</p>
</div>";
        $error = 1;
    }
	if ($county == '')
    {
        $msg .= "<div id=\"fail\"><p><strong>Error:</strong> You must enter a county / state</p>
</div>";
        $error = 1;
    }

######################################Main Geocoders##################################### 

   ###############################United States of America##################################
   if ($country == 'us')
   {
      //Google
      $apiURL = "http://maps.google.com/maps/geo?q=$address,$town,$county,$postcode,$country&key=$gkey&output=xml";
      $addressData = file_get_contents($apiURL);
      $coordinates = split('[,]',between("<coordinates>", "</coordinates>", $addressData));
      $lat = $coordinates[1];
      $long = $coordinates[0];
      
      //Backup (Yahoo)
      if (!$lat && !$long)
      {
      //Yahoo chokes if it encounters 2 , symbols in a row, so we have to hand feed it the address.
      if ($street)   {$addr .= "$street";}
      if ($town)     {$addr .= ",$town";}
      if ($county)    {$addr .= ",$county";}
      if ($postcode)  {$addr .= ",$postcode";}
      if ($country)  {$addr .= ",$country";}
      $apiURL = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=YahooDemo&location=$addr";
      $addressData = file_get_contents($apiURL);
      $lat = between("<Latitude>", "</Latitude>", $addressData);
      $long = between("<Longitude>", "</Longitude>", $addressData);
      }

      //Backup (LocalSearchMaps)
      if (!$lat && !$long)
      {
      $apiURL = "http://geo.localsearchmaps.com/?street=$address&city=$town&state=$county&zip=$postcode&country=$country&cb=coordinates";
      $addressData = file_get_contents($apiURL);
      $coordinates = between('coordinates(', ');', $addressData);
      $coordinates = split('[,]', $coordinates);
      $lat = $coordinates[0];
      $long = $coordinates[1];

      }

      //Backup (geocoder.us)  Just zipcodes OR addresses, not both.  Also quite slow.
      if (!$lat && !$long)
      {
         if ($postcode)
         {
         $apiURL = "http://rpc.geocoder.us/service/csv?postcode=$postcode";
         }
         else
         {
         $apiURL = "http://rpc.geocoder.us/service/csv?address=$address,$town,$county";
         }
      $addressData = file_get_contents($apiURL);
      $coordinates = split('[,]', $addressData);
      $lat = $coordinates[0];
      $long = $coordinates[1];
      }
   }
    
   #######################################Canada############################################
   elseif ($country == 'ca')
   {

      //geocoder.ca
      $address = "$street,$town,$county,$postcode,$country";
      $address = trim(str_replace(' ', '+', $address));
      $apiURL = "http://geocoder.ca/?locate=$address&town=$town&prov=$county&postal=$postcode&geoit=XML";
      $addressData = file_get_contents($apiURL);
      $lat = between("<latt>", "</latt>", $addressData);
      $long = between("<longt>", "</longt>", $addressData);

     //Backup (LocalSearchMaps)
     if (!$lat && !$long)
     {
     $apiURL = "http://geo.localsearchmaps.com/?street=$address&city=$town&state=$county&country=$country&zip=$postcode&cb=coordinates";
     $addressData = file_get_contents($apiURL);
     $coordinates = between('coordinates(', ');', $addressData);
     $coordinates = split('[,]', $coordinates);
     $lat = $coordinates[0];
     $long = $coordinates[1];
     }

     //Backup (Google) It is not very good with canada believe it or not.
      if (!$lat && !$long)
      {
      $apiURL = "http://maps.google.com/maps/geo?q=$address,$town,$county,$postcode,$country&key=$gkey&output=xml";
      $addressData = file_get_contents($apiURL);
      $coordinates = split('[,]',between("<coordinates>", "</coordinates>", $addressData));
      $lat = $coordinates[1];
      $long = $coordinates[0];
      }

      //Backup (Yahoo)
      if (!$lat && !$long)
      {
      //Yahoo chokes if it encounters 2 , symbols in a row, so we have to hand feed it the address.
      if ($street)   {$addr .= "$street";}
      if ($town)     {$addr .= ",$town";}
      if ($county)    {$addr .= ",$county";}
      if ($postcode)  {$addr .= ",$postcode";}
      if ($country)  {$addr .= ",$country";}
      $apiURL = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=YahooDemo&location=$addr";
      echo $addressData = file_get_contents($apiURL);
      $lat = between("<Latitude>", "</Latitude>", $addressData);
      $long = between("<Longitude>", "</Longitude>", $addressData);
      }
   }

   ####################################United Kingdom#######################################

// {{{ class LongLat

/**
* Longitude-Latitude utilities
*
* This function will include the static functions (collection of methods)
* that are going to be used to help with the longitude and latitude coords.
*
* @version 0.1.0
* @license LGPL-CC
* @copyright 1line
*
*/

// {{{ class LongLat
/**
 * Longitude-Latitude utilities
 * 
 * This function will include the static functions (collection of methods)
 * that are going to be used to help with the longitude and latitude coords.
 * 
 * @version 0.1.0
 * @license LGPL-CC
 * @copyright 1line
 *
 */
class Util_LongLat
{
    // {{{ public static function getCoord
    /**
     * Get Coords
     * 
     * This function retrieves the coords of a givent url.
     *
     * @param  string $type    The type, either longitude or latitude
     * @param  string $content The content of the page to parse.
     * @return string The value of the parsed content.
     */
    function getCoord($type = 'latitude', $content)
    {
        switch (strtolower($type)) {
            case 'longitude':
            case 'latitude':
                $type = (string)$type;
        }
        
        preg_match("/<dd class=\"$type\">(.*[^>])<\/dd>/", $content, $values,  PREG_OFFSET_CAPTURE);
        
        if (is_array($values) && isset($values[1][0])) {
            preg_match("/\((.*[^\)])\)/", $values[1][0], $lastvalues, PREG_OFFSET_CAPTURE);
            if (is_array($lastvalues) && isset($lastvalues[1][0])) {
                return (string)$lastvalues[1][0];
            }
        }
        return 'none';
    }
    // }}}
}
// }}}

$lat  =  '';
$long =  '';


if (strtolower((string)$county) == 'uk') {

    $content = file_get_contents("http://www.multimap.com/map/browse.cgi?client=public&search_result=&db=pc&keepicon=true&lang=&pc=$postcode&advanced=&client[equal%20tongue]ublic&addr2=&quicksearch=$postcode&addr3=&addr1=");

    $lat  = Util_LongLat::getCoord('latitude', $content);
    $long = Util_LongLat::getCoord('longitude', $content);

}

   ####################################Australia############################################
   if ($country == 'au')
   {
    //Google
    if (!$lat && !$long)
      {
      $apiURL = "http://maps.google.com/maps/geo?q=$address,$town,$county,$postcode,$country&key=$gkey&output=xml";
      $addressData = file_get_contents($apiURL);
      $coordinates = split('[,]',between("<coordinates>", "</coordinates>", $addressData));
      $lat = $coordinates[1];
      $long = $coordinates[0];
      }
   }
   
   ####################################New Zealand##########################################
   if ($country == 'nz')
   {
    //Google
    if (!$lat && !$long)
      {
      $apiURL = "http://maps.google.com/maps/geo?q=$address,$town,$county,$postcode,$country&key=$gkey&output=xml";
      $addressData = file_get_contents($apiURL);
      $coordinates = split('[,]',between("<coordinates>", "</coordinates>", $addressData));
      $lat = $coordinates[1];
      $long = $coordinates[0];
      }
   }

   ####################################International########################################

   //If there is no long/lat yet, we assume it's international and attempt to find it based on just the
   //town and country.

   //Yahoo
    if (!$lat && !$long)
      {
      //Yahoo chokes if it encounters 2 , symbols in a row, so we have to hand feed it the address.
      if ($town)     {$addr .= "$town";}
      if ($country)  {$addr .= ",$country";}
      $apiURL = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=YahooDemo&location=$addr";
      $addressData = file_get_contents($apiURL);
      $lat = between("<Latitude>", "</Latitude>", $addressData);
      $long = between("<Longitude>", "</Longitude>", $addressData);
      }

      //LocalSearchMaps (Backup)
      if (!$long && !$lat)
      {
      $apiURL = "http://geo.localsearchmaps.com/?street=$address&city=$town&state=$county&country=$country&zip=$postcode&cb=coordinates";
      //$addressData = file_get_contents($apiURL);
      $coordinates = between('coordinates(', ');', $addressData);
      $coordinates = split('[,]', $coordinates);
      $lat = $coordinates[0];
      $long = $coordinates[1];
      }
    if (!$error)
    {

        insert_location($name, $desc, $address, $town, $county, $postcode, $country, $phone, $lat, $long, $link); 

	echo "<div id=\"success\"><p><strong>Complete:</strong> Location has been successfully added to the database.</p>
</div>";
    echo "<script language='javascript'>\n";
    echo "setTimeout(\"location='control.php'\", 5000);\n";
    echo "</script>\n";
	}

if ($error) { echo "$msg"; }
}
if($messages) { displayErrors($messages); }

$filename = '../config.php';
$dir = "../install"; 
if (is_writable($filename)) {
   echo '<div id="fail"><p><strong>Attention:</strong> config.php is writable, for security reasons please set file permissions to 0644 or <a href="../secure.php" title="Secure Configuration File">click here</a></p>
</div>';
} else {
echo "";
}
if (file_exists($dir)) {
echo '<div id="fail"><p><strong>Attention:</strong> install directory still exsists, please DELETE this directory as this is a security risk.</p>
</div>';
} else {
  echo "";
}
?>
<div id="navigation">
	<p id="submenu"><strong>Menu:</strong> <a href="control.php" title="Return to control panel">Main</a> | <a href="license.php" title="View license information">License Information </a> | <a href="locations.php" title="Add locations">Add Locations </a> | <a href="settings.php" title="Manage system settings">Settings</a> | <a href="http://www.bluebadgeroute.biz/billing" title="Billing">Billing </a> | <a href="support.php" title="Support">Support </a></p>
    <p id="breadcrumbs">&nbsp;</p>
</div>

<div id="content">
  <table width="100%" border="0">
    <tr>
      <td>
        <h3>Add Locations </h3>
	    <p>To add a new office, shop or whatever address you want on the maping system simply enter the details below. <span class="small"></span></p>
		<form method=POST action="<?php echo $_SERVER['PHP_SELF'];?>">
	    <table width="100%" border="0">
          <tr>
            <td>Name:</td>
            <td>
                <input name="name" type="text" id="name" />
            </td>
          </tr>
          <tr>
            <td>Description:</td>
            <td><textarea name="desc" cols="30" rows="4" id="desc" type="text"><? 
$desc = str_replace("<br />", "\r\n", $desc);
echo $desc; ?></textarea></td>
          </tr>
          <tr>
            <td>Address:</td>
            <td><input name="address" type="text" id="address" /></td>
          </tr>
          <tr>
            <td>Town / City: </td>
            <td><input name="town" type="text" id="town" /></td>
          </tr>
          <tr>
            <td>County / State: </td>
            <td><input name="county" type="text" id="county" /></td>
          </tr>
          <tr>
            <td>Post Code / Zip:</td>
            <td><input name="postcode" type="text" id="postcode" /></td>
          </tr>
          <tr>
            <td>Phone:</td>
            <td><input name="phone" type="text" id="phone" /></td>
          </tr>
          <tr>
            <td>Country:</td>
            <td><? echo show_country_codes(); ?></td>
          </tr>
        </table>
		<p><input name="use_coordinate" type="hidden" id="use_coordinate" checked="checked" />
          <input type="submit" name="submit" value="Add Location" /></form>
        </p></td>
      </tr>
  </table>
  </div>
<div id="footer">Powered by <a href="http://www.bluebadgeroute.biz" title="Powered By: Blue Badge Route Business Solutions"><?php echo $productname; ?> </a> <?php echo $thisversion; ?></div>
</div>
</body>
</html>