Skip to content
Permalink
Browse files

added coordinate history to cache logs display; updates #922

  • Loading branch information...
following5 committed Mar 6, 2016
1 parent c8b7d41 commit d11f1e490a115e26adb99141c147b375ceb91efc
@@ -776,6 +776,11 @@ function dbv_148() // add log contents modification date
}
}
function dbv_149() // add editcache flag to protect old coordinates
{
if (!sql_field_exists('caches', 'protect_old_coords'))
sql("ALTER TABLE `caches` ADD COLUMN `protect_old_coords` tinyint(1) NOT NULL default '0' AFTER `show_cachelists`");
}
// When adding new mutations, take care that they behave well if run multiple
// times. This improves robustness of database versioning.
@@ -2850,6 +2850,11 @@ INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2563', 'You may
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2564', 'Important:', '2015-06-17 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2565', 'The geocache description at Opencaching must be kept up to date! Description changes on other websites must be applied to the Opencaching listing timely.', '2015-06-17 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2566', 'last modified on', '2015-06-17 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2567', 'Original coordinates:', '2015-06-17 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2568', 'New coordinates:', '2015-06-17 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2569', 'moved by %1 meters', '2015-06-17 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2570', 'moved by %1 km', '2015-06-17 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2571', 'Protect old coordinates', '2015-06-17 10:09:14');

-- Table sys_trans_ref
SET NAMES 'utf8';
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2564', 'DE', 'Wichtig:', '2015-06-17 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2565', 'DE', 'Die Cachebeschreibung bei Opencaching muss aktuell gehalten werden! Änderungen auf anderen Websites müssen zeitnah in die Opencaching-Beschreibung übernommen werden.', '2015-06-17 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2566', 'DE', 'zuletzt geändert am', '2015-06-17 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2567', 'DE', 'Ursprüngliche Koordinaten:', '2015-06-17 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2568', 'DE', 'Neue Koordinaten:', '2015-06-17 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2569', 'DE', 'verlegt um %1 Meter', '2015-06-17 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2570', 'DE', 'verlegt um %1 km', '2015-06-17 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2571', 'DE', 'Altkoordinaten schützen', '2015-06-17 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('1', 'EN', 'Reorder IDs', '2010-09-02 00:15:30');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2', 'EN', 'The database could not be reconnected.', '2010-08-28 11:48:07');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('3', 'EN', 'Testing – please do not login', '2010-08-28 11:48:07');
@@ -32,6 +32,7 @@ CREATE TABLE `caches` (
`date_activate` datetime default NULL,
`need_npa_recalc` tinyint(1) NOT NULL,
`show_cachelists` tinyint(1) NOT NULL default '1',
`protect_old_coords` tinyint(1) NOT NULL default '0',
`needs_maintenance` tinyint(1) NOT NULL default '0',
`listing_outdated` tinyint(1) NOT NULL default '0',
`flags_last_modified` datetime NOT NULL COMMENT 'via Trigger (caches)',
@@ -85,7 +85,37 @@ function getWaypoints($cacheid)
}
else
{
$cache_rs = sql("SELECT `caches`.`uuid`, `caches`.`user_id`, `caches`.`name`, `stat_caches`.`picture`, `caches`.`type`, `caches`.`size`, `caches`.`date_hidden`, `caches`.`date_activate`, `caches`.`longitude`, `caches`.`latitude`, `caches`.`country`, `caches`.`terrain`, `caches`.`difficulty`, `caches`.`desc_languages`, `caches`.`status`, `caches`.`search_time`, `caches`.`way_length`, `caches`.`logpw`, `caches`.`wp_oc`, `caches`.`wp_gc`, `caches`.`show_cachelists`, `caches`.`node`, `user`.`username` FROM `caches` INNER JOIN `user` ON `caches`.`user_id`=`user`.`user_id` LEFT JOIN `stat_caches` ON `caches`.`cache_id`=`stat_caches`.`cache_id` WHERE `caches`.`cache_id`='&1'", $cache_id);
$cache_rs = sql("
SELECT
`caches`.`uuid`,
`caches`.`user_id`,
`caches`.`name`,
`caches`.`type`,
`caches`.`size`,
`caches`.`date_hidden`,
`caches`.`date_activate`,
`caches`.`longitude`,
`caches`.`latitude`,
`caches`.`country`,
`caches`.`terrain`,
`caches`.`difficulty`,
`caches`.`desc_languages`,
`caches`.`status`,
`caches`.`search_time`,
`caches`.`way_length`,
`caches`.`logpw`,
`caches`.`wp_oc`,
`caches`.`wp_gc`,
`caches`.`show_cachelists`,
`caches`.`protect_old_coords`,
`caches`.`node`,
`user`.`username`,
`stat_caches`.`picture`
FROM `caches`
INNER JOIN `user` ON `caches`.`user_id`=`user`.`user_id`
LEFT JOIN `stat_caches` ON `caches`.`cache_id`=`stat_caches`.`cache_id`
WHERE `caches`.`cache_id`='&1'",
$cache_id);
$cache_record = sql_fetch_array($cache_rs);
sql_free_result($cache_rs);
@@ -222,6 +252,7 @@ function getWaypoints($cacheid)
// fix #4356: gc waypoints are frequently copy&pasted with leading spaces
$wp_gc = isset($_POST['wp_gc']) ? strtoupper(trim($_POST['wp_gc'])) : $cache_record['wp_gc']; // Ocprop
$showlists = isset($_POST['showlists']) ? 1 : $cache_record['show_cachelists'] + 0;
$protect_old_coords = isset($_POST['protect_old_coords']) ? 1 : $cache_record['protect_old_coords'] + 0;
// name
$name_not_ok = false;
@@ -485,13 +516,14 @@ function getWaypoints($cacheid)
// fix showlists setting
if (!isset($_POST['showlists'])) $showlists = 0;
if (!isset($_POST['protect_old_coords'])) $protect_old_coords = 0;
// save to DB
// Status update will trigger touching the last_modified date of all depending records.
// Status change via editcache.php is no longer available via the user interface,
// but still used by Ocprop and maybe other tools.
sql("SET @STATUS_CHANGE_USER_ID='&1'", $usr['userid']);
sql("UPDATE `caches` SET `name`='&1', `longitude`='&2', `latitude`='&3', `type`='&4', `date_hidden`='&5', `country`='&6', `size`='&7', `difficulty`='&8', `terrain`='&9', `status`='&10', `search_time`='&11', `way_length`='&12', `logpw`='&13', `wp_gc`='&14', `show_cachelists`='&15', `date_activate` = $activation_date WHERE `cache_id`='&16'", $cache_name, $cache_lon, $cache_lat, $cache_type, date('Y-m-d', mktime(0, 0, 0, $cache_hidden_month, $cache_hidden_day, $cache_hidden_year)), $cache_country, $sel_size, $cache_difficulty, $cache_terrain, $status, $search_time, $way_length, $log_pw, $wp_gc, $showlists, $cache_id);
sql("UPDATE `caches` SET `name`='&1', `longitude`='&2', `latitude`='&3', `type`='&4', `date_hidden`='&5', `country`='&6', `size`='&7', `difficulty`='&8', `terrain`='&9', `status`='&10', `search_time`='&11', `way_length`='&12', `logpw`='&13', `wp_gc`='&14', `show_cachelists`='&15', `protect_old_coords`='&16', `date_activate` = $activation_date WHERE `cache_id`='&17'", $cache_name, $cache_lon, $cache_lat, $cache_type, date('Y-m-d', mktime(0, 0, 0, $cache_hidden_month, $cache_hidden_day, $cache_hidden_year)), $cache_country, $sel_size, $cache_difficulty, $cache_terrain, $status, $search_time, $way_length, $log_pw, $wp_gc, $showlists, $protect_old_coords, $cache_id);
// send notification on admin intervention
if ($cache_record['user_id'] != $usr['userid'] &&
@@ -928,6 +960,7 @@ function getWaypoints($cacheid)
tpl_set_var('log_pw', htmlspecialchars($log_pw, ENT_COMPAT, 'UTF-8'));
tpl_set_var('wp_gc', htmlspecialchars($wp_gc, ENT_COMPAT, 'UTF-8'));
tpl_set_var('showlists_checked', $showlists ? 'checked="checked"' : '');
tpl_set_var('protectcoords_checked', $protect_old_coords ? 'checked="checked"' : '');
tpl_set_var('reset', $reset); // obsolete
tpl_set_var('submit', $submit);
@@ -347,10 +347,15 @@ function toggleAttr(id)
{t}Please note the <a href="articles.php?page=cacheinfo#logpw" target="_blank">description</a>{/t}
</td>
</tr>
<tr><td class="spacer" colspan="2"></td></tr>
<tr>
<td><nobr><label for="showlists">{t}Show all cache lists{/t}</label></nobr></td>
<td><input type="checkbox" id="showlists" name="showlists" value="1" {showlists_checked} /></td>
</tr>
<tr>
<td><nobr><label for="protect_old_coords">{t}Protect old coordinates{/t}</label></nobr></td>
<td><input type="checkbox" id="protect_old_coords" name="protect_old_coords" value="1" {protectcoords_checked} /></td>
</tr>

<tr><td class="spacer" colspan="2"></td></tr>
<tr><td class="spacer" colspan="2"></td></tr>
@@ -98,6 +98,7 @@ function __construct($nNewCacheId=ID_NEW)
$this->reCache->addDate('date_activate', null, true);
$this->reCache->addInt('need_npa_recalc', 1, false, RE_INSERT_IGNORE);
$this->reCache->addInt('show_cachelists', 1, false);
$this->reCache->addInt('protect_old_coords', 0, false);
$this->reCache->addInt('needs_maintenance', 0, false);
$this->reCache->addInt('listing_outdated', 0, false);
$this->reCache->addDate('flags_last_modified', '0000-00-00 00:00:00', false);
@@ -212,6 +213,15 @@ function getDefaultDescLanguage()
return $this->reCache->getValue('default_desclang');
}
function getProtectOldCoords()
{
return $this->reCache->getValue('protect_old_coords');
}
function setProtectOldCoords($value)
{
return $this->reCache->setValue('protect_old_coords', $value);
}
// cache condition flags
function getNeedsMaintenance()
{
@@ -318,15 +328,31 @@ static function getLogsCount($cacheid)
}
static function getLogsArray($cacheid, $start, $count, $deleted=false)
static function getLogsArray($cacheid, $start, $count, $deleted=false, $protect_old_coords=false)
{
global $login;
// negative or abornally high numbers like 1.0E+15 can crash the LIMIT selection
// negative or abornally high numbers like 1.0E+15 can crash the LIMIT statement
if ($count <= 0 || $count > 10000)
return array();
//prepare the logs
$rsCoords = sql("
SELECT `date_created` `date`, `latitude`, `longitude`
FROM `cache_coordinates`
WHERE `cache_id`='&1'
ORDER BY `date_created` DESC",
$cacheid);
$coords = sql_fetch_assoc_table($rsCoords);
if ($coords)
{
$coords[] = array(
'date' => '0000-00-00',
'latitude' => $coords[count($coords)-1]['latitude'],
'longitude' => $coords[count($coords)-1]['longitude']);
$current_coord = new coordinate($coords[0]['latitude'], $coords[0]['longitude']);
}
if ($deleted && ($login->admin && ADMIN_USER)>0)
{
// admins may view owner-deleted logs
@@ -368,6 +394,9 @@ static function getLogsArray($cacheid, $start, $count, $deleted=false)
LIMIT &2, &3", $cacheid, $start+0, $count+0);
$logs = array();
$coordpos = 0;
$coord_changes = false;
while ($rLog = sql_fetch_assoc($rsLogs))
{
$pictures = array();
@@ -378,10 +407,37 @@ static function getLogsArray($cacheid, $start, $count, $deleted=false)
$rLog['pictures'] = $pictures;
$rLog['text'] = use_current_protocol_in_html($rLog['text']);
$newcoord = false;
while ($coordpos < count($coords) && $coords[$coordpos]['date'] > $rLog['date']) {
if (!$newcoord) $newcoord = $coords[$coordpos];
++$coordpos;
}
if ($newcoord) {
$distance = geomath::calcDistance(
$newcoord['latitude'], $newcoord['longitude'],
$coords[$coordpos]['latitude'], $coords[$coordpos]['longitude']);
if (abs($distance) > 0.005) {
$new = new coordinate($newcoord['latitude'], $newcoord['longitude']);
$rLog['newcoord'] = $new->getDecimalMinutes($protect_old_coords && $new != $current_coord);
if ($distance <= 1)
$rLog['movedbym'] = floor($distance*1000);
else if ($distance < 10)
$rLog['movedbykm'] = sprintf('%1.1f', $distance);
else
$rLog['movedbykm'] = round($distance);
$coord_changes = true;
}
}
$logs[] = $rLog;
}
sql_free_result($rsLogs);
if ($coord_changes) {
$coord = new coordinate($coords[count($coords)-1]['latitude'], $coords[count($coords)-1]['longitude']);
$logs[] = array('newcoord' => $coord->getDecimalMinutes($protect_old_coords), 'movedby' => false);
}
return $logs;
}
@@ -41,18 +41,20 @@ function getDecimal()
}
// d° mm.mmm
function getDecimalMinutes()
function getDecimalMinutes($hideMinutFractions=false)
{
$minute_format = ($hideMinutFractions ? '%02.0f.***' : '%06.3f');
// Ocprop: ([N|S].*?)&#039;
$nLat = $this->nLat;
$bLatN = ($nLat < 0) ? false : true;
if (!$bLatN) $nLat = -$nLat;
$nLatDeg = floor($nLat);
$nLatMin = ($nLat - $nLatDeg) * 60;
if ($bLatN)
$sLat = 'N ' . sprintf("%02d", $nLatDeg) . '° ' . sprintf("%06.3f", $nLatMin) . '\'';
$sLat = 'N ' . sprintf("%02d", $nLatDeg) . '° ' . sprintf($minute_format, $nLatMin) . '\'';
else
$sLat = 'S ' . sprintf("%02d", $nLatDeg) . '° ' . sprintf("%06.3f", $nLatMin) . '\'';
$sLat = 'S ' . sprintf("%02d", $nLatDeg) . '° ' . sprintf($minute_format, $nLatMin) . '\'';
// Ocprop: ([E|W].*?)&#039;
$nLon = $this->nLon;
@@ -61,9 +63,9 @@ function getDecimalMinutes()
$nLonDeg = floor($nLon);
$nLonMin = ($nLon - $nLonDeg) * 60;
if ($bLonE)
$sLon = 'E ' . sprintf("%03d", $nLonDeg) . '° ' . sprintf("%06.3f", $nLonMin) . '\'';
$sLon = 'E ' . sprintf("%03d", $nLonDeg) . '° ' . sprintf($minute_format, $nLonMin) . '\'';
else
$sLon = 'W ' . sprintf("%03d", $nLonDeg) . '° ' . sprintf("%06.3f", $nLonMin) . '\'';
$sLon = 'W ' . sprintf("%03d", $nLonDeg) . '° ' . sprintf($minute_format, $nLonMin) . '\'';
return array('lat' => $sLat, 'lon' => $sLon);
}
Binary file not shown.
@@ -4,6 +4,16 @@
* Unicode Reminder メモ
***************************************************************************}
<div id="log{$logItem.id}" style="clear:both">
{if isset($logItem.newcoord)}
<p>
&nbsp;<img src="resource2/{$opt.template.style}/images/log/16x16-moved.png" width="16" height="16" />
{if $logItem.type}{t}New coordinates:{/t}{else}{t}Original coordinates:{/t}{/if}&nbsp;
<strong>{$logItem.newcoord.lat} {$logItem.newcoord.lon}</strong>{if $logItem.movedbym},
{t 1=$logItem.movedbym}moved by %1 meters{/t}{elseif $logItem.movedbykm},
{t 1=$logItem.movedbykm}moved by %1 km{/t}{/if}
</p>
{/if}
{if $logItem.type}
<div class="content-txtbox-noshade"> {* Ocprop: <div class="content-txtbox-noshade">(.*?)<\/div> *}
<div class="logs">
<p class="content-title-noshade-size1 {if $print}printlogheader{/if}" style="display:inline; margin-right:0">
@@ -104,5 +114,6 @@
<div style="clear:both"></div>
</div>
</div>
{/if}
</div>

@@ -107,7 +107,8 @@ function getChildWaypoints($cacheid)
`caches`.`is_publishdate` AS `is_publishdate`,
`caches`.`difficulty` AS `difficulty`,
`caches`.`terrain` AS `terrain`,
`caches`.`show_cachelists` AS `show_cachelists`,
`caches`.`show_cachelists`,
`caches`.`protect_old_coords`,
`caches`.`needs_maintenance`,
`caches`.`listing_outdated`,
`cache_desc`.`language` AS `desclanguage`,
@@ -255,7 +256,7 @@ function getChildWaypoints($cacheid)
$rscount = $_REQUEST['log'] + 0;
}
$logs = cache::getLogsArray($cacheid, 0, $rscount+1);
$logs = cache::getLogsArray($cacheid, 0, $rscount+1, false, $rCache['protect_old_coords']);
if (isset($logs[$rscount]))
{
@@ -54,6 +54,7 @@
`caches`.`user_id` AS `userid`, `caches`.`name`,
`caches`.`status` AS `status`,
`caches`.`type` AS `type`,
`caches`.`protect_old_coords`,
IFNULL(`stat_caches`.`found`, 0) AS `found`,
IFNULL(`stat_caches`.`notfound`, 0) AS `notfound`,
IFNULL(`stat_caches`.`will_attend`, 0) AS `willattend`,
@@ -80,7 +81,7 @@
$rCache['adminlog'] = ($login->admin & ADMIN_USER);
$tpl->assign('cache', $rCache);
$tpl->assign('logs', cache::getLogsArray($cache_id, $start, $count, $deleted));
$tpl->assign('logs', cache::getLogsArray($cache_id, $start, $count, $deleted, $rCache['protect_old_coords']));
$tpl->assign('tagloadlogs', $tagloadlogs);

0 comments on commit d11f1e4

Please sign in to comment.
You can’t perform that action at this time.