forked from opencaching/opencaching-pl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openchecker.php
141 lines (115 loc) · 4.74 KB
/
openchecker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* openchecker.php
* ------------------------------------------------------------------------------------------------
* Puzzle Final Cache coordinate checker
* ------------------------------------------------------------------------------------------------
* @author: Andrzej 'Łza' Woźniak [[email protected]]
*
*
*
* ================================================================================================
* TODO:
* 1.) validation data from post (should be numeric, but this is not a must - if data is not numeric
* we just get result that puzzle solution is incorrect)
* 2.) convert section 2 to OOP.
* 3.) after successful check, provide (.gpx) download with final stage coords, downloadable for
* GPS devices.
* 4.) store checks in database rather then session (logging out resets your attempts count)
* 5.) rename database tables and fields according to https://github.com/opencaching/opencaching-pl/issues/649
* 6.) remove / rewrite LIMIT 0,1000 ?
* ================================================================================================
*/
use OpenChecker\OpenCheckerCore;
use OpenChecker\OpenCheckerSetup;
use src\Models\ApplicationContainer;
use src\Models\GeoCache\Waypoint;
use src\Utils\Database\XDb;
use src\Utils\View\View;
//prepare the templates and include all necessary
require_once(__DIR__ . '/lib/common.inc.php');
$loggedUser = ApplicationContainer::GetAuthorizedUser();
if (!$loggedUser) {
// not logged in, go to login page
$target = urlencode(tpl_get_current_page());
tpl_redirect('login.php?target=' . $target);
exit;
}
if ($config['module']['openchecker']['enabled'] == false) {
tpl_redirect('index.php');
exit;
}
/** @var View */
$view->setTemplate('openchecker');
$view->loadJQuery();
$OpenCheckerSetup = new OpenCheckerSetup();
tpl_set_var('openchecker_script', $OpenCheckerSetup->scriptname);
tpl_set_var("section_5_start", '<!--');
tpl_set_var("section_5_stop", '-->');
$OpenChecker = new OpenCheckerCore();
/*
* if isset $_POST['guessedCoordsFinalLatitude'] means that user entered coords to check.
* - Checking for bruteforce (and prevent if detected)
* - Checking if coordinates are correct, then display result
*/
if (isset($_POST['guessedCoordsFinalLatitude'])) {
$OpenChecker->BruteForceCheck($OpenCheckerSetup);
$OpenChecker->CoordsComparing($OpenCheckerSetup);
}
$OpenChecker->DisplayAllOpenCheckerCaches($OpenCheckerSetup);
// section 2 (display cache data and coordinate entry form)
// TODO: rewrite code using OOP and database queries with PDO
$rs = XDb::xSql("SELECT `caches`.`name`,
`caches`.`cache_id`,
`caches`.`type`,
`caches`.`user_id`,
`cache_type`.`icon_large`,
`user`.`username`
FROM `caches`, `user`, `cache_type`
WHERE `caches`.`user_id` = `user`.`user_id`
AND `caches`.`type` = `cache_type`.`id`
AND `caches`.`wp_oc` = ? ", $OpenChecker->cache_wp);
// prepare sections
tpl_set_var("section_1_start", '<!--');
tpl_set_var("section_1_stop", '-->');
tpl_set_var("section_2_start", '');
tpl_set_var("section_2_stop", '');
tpl_set_var("section_3_start", '<!--');
tpl_set_var("section_3_stop", '-->');
tpl_set_var("section_4_start", '<!--');
tpl_set_var("section_4_stop", '-->');
if (!$record = Xdb::xFetchArray($rs)) {
tpl_set_var("openchecker_wrong_cache", tr('openchecker_wrong_cache'));
tpl_set_var("section_2_start", '<!--');
tpl_set_var("section_2_stop", '-->');
tpl_set_var("section_5_start", '');
tpl_set_var("section_5_stop", '');
$OpenChecker->Finalize();
}
$cache_id = $record['cache_id'];
tpl_set_var("wp_oc", $OpenChecker->cache_wp);
tpl_set_var("cache_icon", '<img src="/images/' . $record['icon_large'] . '" />');
tpl_set_var("cacheid", $record['cache_id']);
tpl_set_var("user_name", htmlspecialchars($record['username']));
tpl_set_var("cachename", htmlspecialchars($record['name']));
tpl_set_var("user_id", $record['user_id']);
Xdb::xFreeResults($rs);
$wp_rs = XDb::xSql("SELECT `waypoints`.`wp_id`,
`waypoints`.`type`,
`waypoints`.`longitude`,
`waypoints`.`latitude`,
`waypoints`.`status`,
`waypoints`.`type`,
`waypoints`.`opensprawdzacz`
FROM `waypoints`
WHERE `cache_id`= ? AND `type` = " . Waypoint::TYPE_FINAL, $cache_id);
$wp_record = XDb::xFetchArray($wp_rs);
if ($wp_record !== false && ($wp_record['type'] == Waypoint::TYPE_FINAL) && ($wp_record['opensprawdzacz'] == 1)) {
$view->setVar('displayOpencheckerForm', true);
tpl_set_var("openchecker_not_enabled", '');
} else {
tpl_set_var("openchecker_not_enabled", tr('openchecker_not_enabled'));
$view->setVar('displayOpencheckerForm', false);
}
// assemble template and display HTML page
$OpenChecker->Finalize();