Skip to content

Commit

Permalink
issue #628 save_user_coords
Browse files Browse the repository at this point in the history
  • Loading branch information
hxdimpf committed Dec 9, 2023
1 parent 2ce5c31 commit 5194518
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 42 deletions.
118 changes: 77 additions & 41 deletions okapi/services/caches/save_user_coords/WebService.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,58 +51,94 @@ public static function call(OkapiRequest $request)
);
$cache_id = $geocache['internal_id'];

self::update_notes($cache_id, $request->token->user_id, $latitude, $longitude);

$ret_value = 'ok';
self::update_coordinates($cache_id, $request->token->user_id, $latitude, $longitude);

$result = array(
'status' => $ret_value
'success' => true
);
return Okapi::formatted_response($request, $result);
}

private static function update_notes($cache_id, $user_id, $latitude, $longitude)
private static function update_coordinates($cache_id, $user_id, $latitude, $longitude)
{
/* See:
*
* - https://github.com/OpencachingDeutschland/oc-server3/tree/development/htdocs/src/Oc/Libse/CacheNote
* - https://www.opencaching.de/okapi/devel/dbstruct
*/
if (Settings::get('OC_BRANCH') == 'oc.de')
{

$rs = Db::query("
select max(id) as id
from coordinates
where
type = 2 -- personal note
and cache_id = '".Db::escape_string($cache_id)."'
and user_id = '".Db::escape_string($user_id)."'
");
$id = null;
if($row = Db::fetch_assoc($rs)) {
$id = $row['id'];
}
if ($id == null) {
Db::query("
insert into coordinates (
type, latitude, longitude, cache_id, user_id
) values (
2,
'".Db::escape_string($latitude)."',
'".Db::escape_string($longitude)."',
'".Db::escape_string($cache_id)."',
'".Db::escape_string($user_id)."'
)
/* See:
*
* - https://github.com/OpencachingDeutschland/oc-server3/tree/development/htdocs/src/Oc/Libse/CacheNote
* - https://www.opencaching.de/okapi/devel/dbstruct
*/

$rs = Db::query("
select max(id) as id
from coordinates
where
type = 2 -- personal note
and cache_id = '".Db::escape_string($cache_id)."'
and user_id = '".Db::escape_string($user_id)."'
");
} else {
Db::query("
update coordinates
set latitude = '".Db::escape_string($latitude)."',
longitude = '".Db::escape_string($longitude)."',
$id = null;
if($row = Db::fetch_assoc($rs)) {
$id = $row['id'];
}
if ($id == null) {
Db::query("
insert into coordinates (
type, latitude, longitude, cache_id, user_id, description
) values (
2,
'".Db::escape_string($latitude)."',
'".Db::escape_string($longitude)."',
'".Db::escape_string($cache_id)."',
'".Db::escape_string($user_id)."',
'".Db::escape_string("")."'
)
");
} else {
Db::query("
update coordinates
set latitude = '".Db::escape_string($latitude)."',
longitude = '".Db::escape_string($longitude)."'
where
id = '".Db::escape_string($id)."'
and type = 2
");
}
}
else # oc.pl branch
{
$rs = Db::query("
select max(id) as id
from cache_mod_cords
where
id = '".Db::escape_string($id)."'
and type = 2
cache_id = '".Db::escape_string($cache_id)."'
and user_id = '".Db::escape_string($user_id)."'
");
$id = null;
if($row = Db::fetch_assoc($rs)) {
$id = $row['id'];
}
if ($id == null) {
Db::query("
insert into cache_mod_cords (
cache_id, user_id, latitude, longitude
) values (
'".Db::escape_string($cache_id)."',
'".Db::escape_string($user_id)."',
'".Db::escape_string($latitude)."',
'".Db::escape_string($longitude)."'
)
");
} else {
Db::query("
update cache_mod_cords
set latitude = '".Db::escape_string($latitude)."',
longitude = '".Db::escape_string($longitude)."'
where
id = '".Db::escape_string($id)."'
");
}
}
}

}
2 changes: 1 addition & 1 deletion okapi/services/caches/save_user_coords/docs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<returns>
<p>A dictionary of the following structure:</p>
<ul>
<li>status - ok</li>
<li>success - true</li>
</ul>
</returns>
</xml>

0 comments on commit 5194518

Please sign in to comment.