public static function buildWaypointsForGeocache(GeoCache $geoCache)
 {
     $db = OcDb::instance();
     $stmt = $db->multiVariableQuery("SELECT `wp_id`, `type`, `longitude`, `latitude`,  `desc`, `status`, `stage` FROM `waypoints` WHERE `cache_id`=:1 ORDER BY `stage`,`wp_id`", $geoCache->getCacheId());
     foreach ($db->dbResultFetchAll($stmt) as $wpRecord) {
         $waypoint = new Waypoint();
         $waypoint->setCoordinates(new Coordinates(array('dbRow' => $wpRecord)))->setDescription($wpRecord['desc'])->setId((int) $wpRecord['wp_id'])->setStage((int) $wpRecord['stage'])->setStatus((int) $wpRecord['status'])->setType((int) $wpRecord['type'])->setGeocache($geoCache);
         $geoCache->getWaypoints()->append($waypoint);
     }
 }
Beispiel #2
0
 /**
  * Call OKAPI, parse response and display the results
  * @param array $params - params of the cache to search and display
  */
 private function htmlFormat(array $params)
 {
     //call OKAPI
     $okapi_resp = \okapi\Facade::service_call('services/caches/shortcuts/search_and_retrieve', $this->user_id, $params);
     if (!is_a($okapi_resp, "ArrayObject")) {
         // strange OKAPI return !?
         error_log(__METHOD__ . ": ERROR: strange OKAPI response - not an ArrayObject");
         exit(0);
     }
     \okapi\OkapiErrorHandler::disable();
     if ($okapi_resp->count() == 0) {
         // no caches found
         exit(0);
     }
     // get the first object from the list
     $arrayCopy = $okapi_resp->getArrayCopy();
     $geoCache = new \lib\Objects\GeoCache\GeoCache(array('okapiRow' => array_pop($arrayCopy)));
     //generate the results
     if ($this->screenWidth < 400) {
         tpl_set_tplname('map/map_cacheinfo_small');
     } else {
         tpl_set_tplname('map/map_cacheinfo');
     }
     tpl_set_var('cache_lat', $geoCache->getCoordinates()->getLatitude());
     tpl_set_var('cache_lon', $geoCache->getCoordinates()->getLongitude());
     tpl_set_var('cache_name', $geoCache->getCacheName());
     tpl_set_var('cache_icon', $geoCache->getCacheIcon());
     $is_event = $geoCache->getCacheType() == $geoCache::TYPE_EVENT ? '1' : '0';
     // be aware: booleans not working here
     tpl_set_var('is_event', $is_event, false);
     $is_scored = $geoCache->getRatingId() != 0 && $geoCache->getRatingVotes() > 2 ? '1' : '0';
     tpl_set_var('is_scored', $is_scored, false);
     tpl_set_var('rating_desc', tr($geoCache->getRatingDesc()));
     $is_recommended = $geoCache->getRecommendations() > 0 ? '1' : '0';
     tpl_set_var('is_recommended', $is_recommended, false);
     tpl_set_var('cache_recommendations', $geoCache->getRecommendations(), false);
     tpl_set_var('cache_code', $geoCache->getWaypointId());
     tpl_set_var('cache_founds', $geoCache->getFounds());
     tpl_set_var('cache_not_founds', $geoCache->getNotFounds());
     tpl_set_var('cache_rating_votes', $geoCache->getRatingVotes());
     tpl_set_var('cache_willattends', $geoCache->getWillattends());
     tpl_set_var('cache_url', $geoCache->getCacheUrl());
     tpl_set_var('user_name', $geoCache->getOwner()->getUserName());
     tpl_set_var('user_profile', $geoCache->getOwner()->getProfileUrl());
     tpl_set_var('cache_size_desc', tr($geoCache->getSizeDesc()));
     $is_powertrail_part = $geoCache->isPowerTrailPart() ? '1' : '0';
     tpl_set_var('is_powertrail_part', $is_powertrail_part, false);
     if ($geoCache->isPowerTrailPart()) {
         tpl_set_var('pt_name', $geoCache->getPowerTrail()->getName());
         tpl_set_var('pt_image', $geoCache->getPowerTrail()->getImage());
         tpl_set_var('pt_icon', $geoCache->getPowerTrail()->getFootIcon());
         tpl_set_var('pt_url', $geoCache->getPowerTrail()->getPowerTrailUrl());
     }
     $is_titled = $geoCache->isTitled() ? 'true' : 'false';
     tpl_set_var('is_titled', $is_titled, false);
     //tpl_set_var('is_titled', $geoCache->isTitled(), false);
     // make the template and send it out
     tpl_BuildTemplate(false, false, true);
 }
Beispiel #3
0
     tpl_redirect('login.php?target=' . $target);
 } else {
     $cache_rs = XDb::xSql("SELECT `user_id`, `name` FROM `caches` WHERE `cache_id`= ? LIMIT 1", $cache_id);
     if ($cache_record = XDb::xFetchArray($cache_rs)) {
         if ($cache_record['user_id'] == $usr['userid'] || $usr['admin']) {
             $desc_rs = XDb::xSql("SELECT `id`, `uuid` FROM `cache_desc` WHERE `cache_id`= ? AND `language`= ? LIMIT 1", $cache_id, $desclang);
             if ($desc_record = XDb::xFetchArray($desc_rs)) {
                 XDb::xFreeResults($desc_rs);
                 require $stylepath . '/removedesc.inc.php';
                 if ($remove_commit == 1) {
                     //add to removed_objects
                     XDb::xSql("INSERT INTO `removed_objects` (`id`, `localID`, `uuid`, `type`, `removed_date`, `node`)\n                            VALUES ('', ?, ?, '3', NOW(), ?)", $desc_record['id'], $desc_record['uuid'], $oc_nodeid);
                     //remove it from cache_desc
                     XDb::xSql("DELETE FROM `cache_desc` WHERE `cache_id`= ? AND `language`= ? LIMIT 1", $cache_id, $desclang);
                     // update cache-record, including last modification date
                     GeoCache::setCacheDefaultDescLang($cache_id);
                     tpl_redirect('editcache.php?cacheid=' . urlencode($cache_id));
                     exit;
                 } else {
                     //commit the removement
                     $tplname = 'removedesc';
                     tpl_set_var('desclang_name', db_LanguageFromShort($desclang));
                     tpl_set_var('cachename', htmlspecialchars($cache_record['name'], ENT_COMPAT, 'UTF-8'));
                     tpl_set_var('cacheid_urlencode', htmlspecialchars(urlencode($cache_id), ENT_COMPAT, 'UTF-8'));
                     tpl_set_var('desclang_urlencode', htmlspecialchars(urlencode($desclang), ENT_COMPAT, 'UTF-8'));
                 }
             } else {
                 //TODO: desc not exist
             }
         } else {
             //TODO: not the owner
Beispiel #4
0
<?php

/**
 * This script publishes the cache if its activation_date was set
 */
use Utils\Database\XDb;
use lib\Objects\GeoCache\GeoCache;
$rootpath = '../../';
require_once $rootpath . 'lib/ClassPathDictionary.php';
require_once $rootpath . 'lib/eventhandler.inc.php';
require_once $rootpath . 'lib/consts.inc.php';
require_once $rootpath . 'lib/settings.inc.php';
$rsPublish = XDb::xSql("SELECT `cache_id`, `user_id`\n                FROM `caches`\n                WHERE `status` = 5\n                  AND `date_activate` != 0\n                  AND `date_activate` <= NOW()");
while ($rPublish = XDb::xFetchArray($rsPublish)) {
    $userid = $rPublish['user_id'];
    $cacheid = $rPublish['cache_id'];
    // update cache status to active
    XDb::xSql("UPDATE `caches` SET `status`=1, `date_activate`=NULL, `last_modified`=NOW() WHERE `cache_id`= ? ", $cacheid);
    // send events
    GeoCache::touchCache($cacheid);
    event_new_cache($userid);
    event_notify_new_cache($cacheid);
}
XDb::xFreeResults($rsPublish);
/**
 * if coordinates were changed, update altitude
 * @param array $oldCacheRecord
 * @param integer $cacheId
 * @param integer $altitude
 */
function updateAltitudeIfNeeded($oldCacheRecord, $cacheId, $altitude = NULL)
{
    /* add cache altitude altitude */
    $geoCache = new GeoCache(array('cacheId' => $cacheId));
    if ($geoCache->getCoordinates()->getLatitude() != $oldCacheRecord['latitude'] || $geoCache->getCoordinates()->getLongitude() != $oldCacheRecord['longitude']) {
        $geoCache->getAltitude()->pickAndStoreAltitude($altitude);
    }
}
function geocacheStatusCheck($cacheId)
{
    $geocache = new GeoCache(array('cacheId' => $cacheId));
    $forbidenCacheStatuses = array(GeoCache::STATUS_BLOCKED, GeoCache::STATUS_ARCHIVED, GeoCache::STATUS_WAITAPPROVERS);
    if (in_array($geocache->getStatus(), $forbidenCacheStatuses)) {
        print 'geocache of this status cannot be added';
        return false;
    }
    return true;
}
Beispiel #7
0
 public function getGeocaches()
 {
     if ($this->geocaches === null) {
         $this->geocaches = new \ArrayObject();
         $db = OcDb::instance();
         $stmt = $db->multiVariableQuery("SELECT * FROM `caches` where `user_id` = :1 ", $this->userId);
         foreach ($db->dbResultFetchAll($stmt) as $geocacheRow) {
             $geocache = new GeoCache();
             $geocache->loadFromRow($geocacheRow);
             $this->geocaches->append($geocache);
             if ($geocache->getStatus() === GeoCache::STATUS_NOTYETAVAILABLE) {
                 $this->appendNotPublishedGeocache($geocache);
             }
             if ($geocache->getStatus() === GeoCache::STATUS_WAITAPPROVERS) {
                 $this->appendWaitAprooveGeocache($geocache);
             }
             if ($geocache->getStatus() === GeoCache::STATUS_BLOCKED) {
                 $this->appendBlockedGeocache($geocache);
             }
         }
     }
     return $this->geocaches;
 }
 } else {
     $lang_db = "en";
 }
 $thatquery = "SELECT `caches`.`cache_id` `cache_id`,\n                              `caches`.`user_id` `user_id`,\n                              `caches`.`status` `status`,\n                              `caches`.`latitude` `latitude`,\n                              `caches`.`longitude` `longitude`,\n                              `caches`.`name` `name`,\n                              `caches`.`type` `type`,\n                              `caches`.`size` `size`,\n                              `caches`.`search_time` `search_time`,\n                              `caches`.`way_length` `way_length`,\n                              `caches`.`country` `country`,\n                              `caches`.`logpw` `logpw`,\n                              `caches`.`date_hidden` `date_hidden`,\n                              `caches`.`wp_oc` `wp_oc`,\n                              `caches`.`wp_gc` `wp_gc`,\n                              `caches`.`wp_ge` `wp_ge`,\n                              `caches`.`wp_tc` `wp_tc`,\n                              `caches`.`wp_nc` `wp_nc`,\n                              `caches`.`wp_qc` `wp_qc`,\n                              `caches`.`date_created` `date_created`,\n                              `caches`.`difficulty` `difficulty`,\n                              `caches`.`terrain` `terrain`,\n                              `caches`.`founds` `founds`,\n                              `caches`.`notfounds` `notfounds`,\n                              `caches`.`notes` `notes`,\n                              `caches`.`watcher` `watcher`,\n                              `caches`.`votes` `votes`,\n                              `caches`.`score` `score`,\n                              `caches`.`picturescount` `picturescount`,\n                              `caches`.`mp3count` `mp3count`,\n                              `caches`.`desc_languages` `desc_languages`,\n                              `caches`.`topratings` `topratings`,\n                              `caches`.`ignorer_count` `ignorer_count`,\n                              `caches`.`votes` `votes_count`,\n                              `cache_type`.`icon_large` `icon_large`,\n                              `user`.`username` `username`,\n                              `countries`.`short` AS `country_short`,\n                            IFNULL(`cache_location`.`code1`, '') AS `code1`,\n                            IFNULL(`cache_location`.`adm1`, '') AS `adm1`,\n                            IFNULL(`cache_location`.`adm2`, '') AS `adm2`,\n                            IFNULL(`cache_location`.`adm3`, '') AS `adm3`,\n                            IFNULL(`cache_location`.`code3`, '') AS `code3`,\n                            IFNULL(`cache_location`.`adm4`, '') AS `adm4`,\n                            caches.org_user_id,\n                            org_user.username as org_username,\n                            cache_titled.date_alg date_alg\n                          FROM (`caches`\n                                    JOIN user ON `caches`.`user_id` = `user`.`user_id`\n                                    JOIN cache_type ON `cache_type`.`id`=`caches`.`type`\n                                    LEFT JOIN `cache_location` ON `caches`.`cache_id` = `cache_location`.`cache_id`\n                                    LEFT OUTER JOIN user org_user ON org_user.user_id = caches.org_user_id\n                                    LEFT JOIN `cache_titled` ON `caches`.`cache_id` = `cache_titled`.`cache_id`\n                                )\n                                INNER JOIN countries ON (caches.country = countries.short)\n                          WHERE `caches`.`cache_id`= :v1";
 // $params['v1']['value'] = (string) $lang_db;; //TODO: be check if to replace with translation throuhgh languages
 // $params['v1']['data_type'] = 'string';
 $params['v1']['value'] = (int) $cache_id;
 $params['v1']['data_type'] = 'integer';
 $dbc->paramQuery($thatquery, $params);
 unset($params);
 //clear to avoid overlaping on next paramQuery (if any))
 if ($dbc->rowCount() == 0) {
     $cache_id = 0;
 } else {
     $cache_record = $dbc->dbResultFetch();
     $geocache = new GeoCache(array('cacheId' => $cache_id));
 }
 // detailed cache access logging
 if (@$enable_cache_access_logs && $cache_id > 0) {
     $user_id = $usr !== false ? $usr['userid'] : null;
     $access_log = @$_SESSION['CACHE_ACCESS_LOG_VC_' . $user_id];
     if ($access_log === null) {
         $_SESSION['CACHE_ACCESS_LOG_VC_' . $user_id] = array();
         $access_log = $_SESSION['CACHE_ACCESS_LOG_VC_' . $user_id];
     }
     if (@$access_log[$cache_id] !== true) {
         $dbc->multiVariableQuery('INSERT INTO CACHE_ACCESS_LOGS
                     (event_date, cache_id, user_id, source, event, ip_addr, user_agent, forwarded_for)
                  VALUES
                     (NOW(), :1, :2, \'B\', \'view_cache\', :3, :4, :5)', $cache_id, $user_id, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'], $_SERVER['HTTP_X_FORWARDED_FOR']);
         $access_log[$cache_id] = true;
Beispiel #9
0
 }
 if ($usr == false) {
     tpl_set_var('hidesearchdownloadsection_start', '<!--');
     tpl_set_var('hidesearchdownloadsection_end', '-->');
 } else {
     tpl_set_var('hidesearchdownloadsection_start', '');
     tpl_set_var('hidesearchdownloadsection_end', '');
     tpl_set_var('uType', $usr['admin']);
 }
 $no_crypt = 0;
 if (isset($_REQUEST['nocrypt'])) {
     $no_crypt = $_REQUEST['nocrypt'];
 }
 if ($cache_id != 0) {
     //get cache record
     $geocache = new GeoCache(array('cacheId' => $cache_id));
     // detailed cache access logging
     if (@$enable_cache_access_logs && $cache_id > 0) {
         $user_id = $usr !== false ? $usr['userid'] : null;
         $access_log = @$_SESSION['CACHE_ACCESS_LOG_VC_' . $user_id];
         if ($access_log === null) {
             $_SESSION['CACHE_ACCESS_LOG_VC_' . $user_id] = array();
             $access_log = $_SESSION['CACHE_ACCESS_LOG_VC_' . $user_id];
         }
         if (@$access_log[$cache_id] !== true) {
             $dbc->multiVariableQuery('INSERT INTO CACHE_ACCESS_LOGS
                         (event_date, cache_id, user_id, source, event, ip_addr, user_agent, forwarded_for)
                      VALUES
                         (NOW(), :1, :2, \'B\', \'view_cache\', :3, :4, :5)', $cache_id, $user_id, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'], $_SERVER['HTTP_X_FORWARDED_FOR']);
             $access_log[$cache_id] = true;
             $_SESSION['CACHE_ACCESS_LOG_VC_' . $user_id] = $access_log;
Beispiel #10
0
 /**
  * @return  Collection
  */
 public function getGeocaches()
 {
     if (!$this->geocaches->isReady()) {
         $db = OcDb::instance();
         $query = 'SELECT powerTrail_caches.isFinal, caches . * , user.username FROM  `caches` , user, powerTrail_caches WHERE cache_id IN ( SELECT  `cacheId` FROM  `powerTrail_caches` WHERE  `PowerTrailId` =:1) AND user.user_id = caches.user_id AND powerTrail_caches.cacheId = caches.cache_id ORDER BY caches.name';
         $s = $db->multiVariableQuery($query, $this->id);
         $geoCachesDbResult = $db->dbResultFetchAll($s);
         $geocachesIdArray = array();
         foreach ($geoCachesDbResult as $geoCacheDbRow) {
             $geocache = new GeoCache();
             $geocache->loadFromRow($geoCacheDbRow)->setIsPowerTrailPart(true);
             $geocache->setPowerTrail($this);
             if ($geoCacheDbRow['isFinal'] == 1) {
                 $geocache->setIsPowerTrailFinalGeocache(true);
             }
             $this->geocaches[] = $geocache;
             $geocachesIdArray[] = $geocache->getCacheId();
         }
         $this->geocaches->setIsReady(true);
         $this->geocaches->setGeocachesIdArray($geocachesIdArray);
         $this->caculateGeocachesCountByStatus();
     }
     return $this->geocaches;
 }
Beispiel #11
0
     $desc = userInputFilter::purifyHtmlString($desc);
     $hints = htmlspecialchars($hints, ENT_COMPAT, 'UTF-8');
     if (isset($_POST['submitform'])) {
         // consider whether language does not already exist
         $cacheLang = XDb::xMultiVariableQueryValue("SELECT COUNT(*) `count` FROM `cache_desc`\n                            WHERE `cache_id`= :1 AND `id` != :2 AND `language`= :3 ", 0, $desc_record['cache_id'], $descid, $desclang);
         if ($cacheLang > 0) {
             tpl_errorMsg('editdesc', $error_desc_exists);
         }
         /* Prevent binary data in cache descriptions, e.g. <img src='data:...'> tags. */
         if (strlen($desc) > 300000) {
             tpl_errorMsg('editdesc', tr('error3KCharsExcedeed'));
         }
         XDb::xSql("UPDATE `cache_desc` SET\n                                `last_modified`=NOW(), `desc_html`= '2', `desc_htmledit`= '1',\n                                `desc`= ?, `short_desc`= ?, `hint`= ?, `language`= ?\n                            WHERE `id`= ? ", $desc, $short_desc, nl2br($hints), $desclang, $descid);
         // update description languages in the cache record;
         // this also updates the modification date
         GeoCache::setCacheDefaultDescLang($desc_record['cache_id']);
         // redirect to cachepage
         tpl_redirect('editcache.php?cacheid=' . urlencode($desc_record['cache_id']));
         exit;
     } else {
         if (isset($_POST['show_all_langs'])) {
             $show_all_langs = true;
         }
     }
 } else {
     //here we read all used information from the DB
     $short_desc = strip_tags($desc_record['short_desc']);
     $hints = strip_tags($desc_record['hint']);
     $desc_lang = $desc_record['language'];
     $desc = $desc_record['desc'];
 }