if ($longitude == NULL || $longitude == 0) {
     $longitude = 21.00442;
 }
 $distance = $db->multiVariableQueryValue("SELECT `notify_radius` FROM user WHERE user_id=:1", 0, $applicationContainer->getLoggedUser()->getUserId());
 if ($distance == 0) {
     $distance = 50;
 }
 $distance_unit = 'km';
 $radius = $distance;
 tpl_set_var('distance', $distance);
 //get the users home coords
 $lat = $latitude;
 $lon = $longitude;
 $lon_rad = $lon * 3.14159 / 180;
 $lat_rad = $lat * 3.14159 / 180;
 localCachesInc::createLocalCaches($db, $lon, $lat, $distance, $user_id);
 // Read coordinates of the newest caches
 $markerpositions = get_marker_positions($latitude, $longitude, $radius, $user_id);
 // Generate include file for map with new caches
 tpl_set_var('local_cache_map', '<img src="' . create_map_url($markerpositions, -1, $latitude, $longitude) . '" basesrc="' . create_map_url($markerpositions, -1, $latitude, $longitude) . '" id="main-cachemap" name="main-cachemap" alt="mapa" />');
 /* ===================================================================================== */
 /*                          Najnowsze skrzynki                                           */
 /* ===================================================================================== */
 //start_newcaches.include
 $query = "SELECT    `user`.`user_id`            AS `user_id`,\n                            `user`.`username`           AS `username`,\n                            `caches`.`cache_id`         AS `cache_id`,\n                            `caches`.`name`             AS `name`,\n                            `caches`.`longitude`        AS `longitude`,\n                            `caches`.`latitude`         AS `latitude`,\n                            `caches`.`date_hidden`      AS `date_hidden`,\n                            `caches`.`date_created`     AS `date_created`,\n                            IF((`caches`.`date_hidden`>`caches`.`date_created`), `caches`.`date_hidden`, `caches`.`date_created`) AS `date`,\n                            `caches`.`country`          AS `country`,\n                            `caches`.`difficulty`       AS `difficulty`,\n                            `caches`.`distance`         AS `distance`,\n                            `caches`.`terrain`          AS `terrain`,\n                            `cache_type`.`icon_large`   AS `icon_large`,\n                            `caches`.`type`             AS `cache_type`\n                 FROM local_caches `caches` INNER JOIN `user` ON (`caches`.`user_id`=`user`.`user_id`), `cache_type`\n                 WHERE     `caches`.`type`!=6\n                    AND `caches`.`status`=1\n                    AND `caches`.`type`=`cache_type`.`id`\n                    AND `caches`.`date_created` <= NOW()\n                    AND     `caches`.`date_hidden` <= NOW()\n                 ORDER BY `date` DESC, `caches`.`cache_id` DESC\n                 LIMIT 0 , 11";
 $rs = $db->simpleQuery($query);
 if ($db->rowCount($rs) > 10) {
     tpl_set_var('more_caches', '<a class="links" href="myn_newcaches.php">[' . tr("show_more") . '...]</a>');
     $limit = 10;
 } else {
     $limit = $db->rowCount($rs);
<?php

global $dateFormat;
require_once './lib/common.inc.php';
$tplname = 'cache_titled';
$usrid = -1;
if ($usr != false) {
    $usrid = $usr['userid'];
}
$dbcLocCache = new dataBase();
$query = "SELECT \n    caches.type cache_type, caches.name cacheName, caches.cache_id cache_id, \n    user.username userName, user.user_id user_id, \n    cache_location.adm3 cacheRegion, cache_titled.date_alg dateAlg\n        \n    FROM cache_titled \n    JOIN caches on caches.cache_id = cache_titled.cache_id\n    JOIN user on user.user_id = caches.user_id\n    JOIN cache_location ON cache_location.cache_id = cache_titled.cache_id";
if (isset($_REQUEST['type'])) {
    $latitude = sqlValue("SELECT `latitude` FROM user WHERE user_id='" . sql_escape($usr['userid']) . "'", 0);
    $longitude = sqlValue("SELECT `longitude` FROM user WHERE user_id='" . sql_escape($usr['userid']) . "'", 0);
    $distance = sqlValue("SELECT `notify_radius` FROM user WHERE user_id='" . sql_escape($usr['userid']) . "'", 0);
    localCachesInc::createLocalCaches($dbcLocCache, $longitude, $latitude, $distance, $usrid);
    $query .= " JOIN local_caches on cache_titled.cache_id = local_caches.cache_id ";
}
$dbcLocCache->simpleQuery($query);
$content = "";
for ($i = 0; $i < $dbcLocCache->rowCount(); $i++) {
    $record = $dbcLocCache->dbResultFetch();
    $cacheId = $record['cache_id'];
    $cacheName = str_replace("'", "-", $record['cacheName']);
    $cacheName = str_replace("\"", " ", $cacheName);
    $cacheNameRef = '<a href="viewcache.php?cacheid={cacheId}">{cacheName}<a>';
    $cacheNameRef = str_replace('{cacheId}', $cacheId, $cacheNameRef);
    $cacheNameRef = str_replace('{cacheName}', $cacheName, $cacheNameRef);
    $cacheRegion = $record['cacheRegion'];
    $ownId = $record['user_id'];
    $userName = str_replace("'", "-", $record['userName']);