Location: PHPKode > projects > photolibrary > ajax.geotag.xml.php
<?PHP
/*
   [Start: Program Information Header]

    Name    : Photolibrary: Geotags
    Purpose : Load geotags for a given view / update geotag coordinates of given category
    Syntax  :

   [End: Program Information Header]

   [Start: Author Information Header]

    Name    : James D. Forrester
    E-mail  : hide@address.com

    Name    : Ed Sanders
    E-mail  : hide@address.com

   [End: Author Information Header]
*/
header('Content-Type: application/xml');

$non_html = true;
require('include.initialise.php');

$mode = getString('mode');
$category = getInt('category');

echo '<?xml version="1.0" encoding="iso-8859-1"?>
<data>
';
//<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

if($mode == 'set' or $mode == 'delete')
{
  $_SESSION['PL_admin'] or die();

  $lat_min = getFloat('latMin');
  $lng_min = getFloat('lngMin');
  $lat_max = getFloat('latMax');
  $lng_max = getFloat('lngMax');

  if($mode == 'set')
  {
    mysql_query("
      UPDATE categories
      SET lat_min = '$lat_min', lng_min = '$lng_min', lat_max = '$lat_max', lng_max = '$lng_max', located = 1 WHERE category = '$category'") or trigger_error(mysql_error(), E_USER_ERROR);
    children_located($category, 1);
  }

  if($mode == 'delete')
  {
    mysql_query("UPDATE categories SET lat_min = NULL, lng_min = NULL, lat_max = NULL, lng_max = NULL WHERE category = '$category'") or trigger_error(mysql_error(), E_USER_ERROR);
    $located = locate($category) ? 1 : 0;
    mysql_query("UPDATE categories SET located = '$located' WHERE category = '$category'") or trigger_error(mysql_error(), E_USER_ERROR);
    children_located($category, $located);
  }
}

if($mode == 'find')
{
  list($lat_min, $lng_min, $lat_max, $lng_max, $category, $name) = locate($category);

  if($lat_min)
    echo '<markers><marker latMin="'.$lat_min.'" lngMin="'.$lng_min.'" latMax="'.$lat_max.'" lngMax="'.$lng_max.'" category="'.$category.'" catName="'.htmlentities($name, ENT_QUOTES).'" /></markers>';
}

if($mode == 'load')
{

  if($category)
  {
    $query_handle = mysql_query("
      SELECT category, name, lat_min, lng_min, lat_max, lng_max, 0 AS lat_ratio, 0 AS lng_ratio
      FROM categories
      WHERE category = '$category'") or trigger_error(mysql_error(), E_USER_ERROR);
  }
  else
  {
    $width = getInt('width');
    $height = getInt('height');

    $b_lat_min = getFloat('latMin');
    $b_lat_max = getFloat('latMax');
    $b_lng_min = getFloat('lngMin');
    $b_lng_max = getFloat('lngMax');

    $b_lat_diff = abs($b_lat_max - $b_lat_min);
    $b_lng_diff = abs($b_lng_max - $b_lng_min);

    $query_handle = mysql_query("
      SELECT category, name, lat_min, lng_min, lat_max, lng_max,
             2*ABS((lat_max-lat_min)/$b_lat_diff) AS lat_ratio,
             2*ABS((lng_max-lng_min)/$b_lng_diff) AS lng_ratio
      FROM categories
      WHERE NOT ISNULL(lat_min)
            AND lat_min < $b_lat_max AND lat_max > $b_lat_min
            AND lng_min < $b_lng_max AND lng_max > $b_lng_min
      HAVING (lat_ratio > 30/$width OR lng_ratio > 30/$height)
             AND lat_ratio < 1 AND lng_ratio < 1
      ORDER BY lat_ratio DESC") or trigger_error(mysql_error(), E_USER_ERROR);
  }
  echo '<markers>';
  while($array = mysql_fetch_assoc($query_handle))
  {
    extract($array);
    echo '<marker lr="'.$lat_ratio.'" latMin="'.$lat_min.'" lngMin="'.$lng_min.'" latMax="'.$lat_max.'" lngMax="'.$lng_max.'" category="'.$category.'" catName="'.htmlentities($name, ENT_QUOTES).'" />';
  }
  echo '</markers>';
}
echo '</data>';

include('include.footer.php');
?>
Return current item: photolibrary