-
Notifications
You must be signed in to change notification settings - Fork 4
/
gyms.php
190 lines (152 loc) · 5.43 KB
/
gyms.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
include "./core/bootstrap.php";
//connect to database
include 'dbconnect.php';
//check that user has a valid cookie, redirect if no valid cookie
include 'php_common/cookiecheck.php';
//get user's country
$userService = new UserService();
$countryCode = $userService->getUserCountryCode($userid);
//for each country, extract the number of gyms
$stmt = $db->prepare("SELECT * FROM gyms");
$stmt->execute();
$gym_country_num = array();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$gym_country_num[strtolower($row['countryCode'])]++;
}
include 'php_dataquery/getCountryNameFromCode.php';
$countryName = country_code_to_country($countryCode);
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Climbing Tracker</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Latest compiled and minified CSS -->
<link rel="icon" href="images/favicon.ico" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="style.php/mycss.scss">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>
<script src="bower_components/jqvmap/jqvmap/jquery.vmap.js"></script>
<script src="bower_components/jqvmap/jqvmap/maps/jquery.vmap.world.js"></script>
<script>
var gym_country_num = <?php echo json_encode($gym_country_num)?>;
</script>
<script src="js/sitePath.js"></script>
<script src="js/uservoice.js"></script>
<link rel="stylesheet" type="text/css" href="bower_components/jqvmap/jqvmap/jqvmap.css">
<link rel="stylesheet" type="text/css" href="style.php/mycss.scss">
</head>
<body>
<div id="wrap">
<div id="main">
<?php include_once("php_common/analyticstracking.php") ?>
<?php require("navigation.php"); ?>
<div class="container">
<div class="page-header"><h1>Climbing Areas</h1></div>
<p>Click on a country to see its climbing areas</p>
<div class="container-fluid" style="height:450px;">
<div id="vmap" style="width: 700px; height: 500px; margin: 0 auto;"></div>
</div>
<script src="js/writeGymList.js"></script>
<script>
var countryCode = '<?php echo $countryCode ?>';
var region = '<?php echo $countryName ?>';
countryCode = countryCode.toLowerCase();
url2 = sitePath()+"/php_dataquery/getGymsByCountry.php?countryCode="+countryCode+"&indoor=1";
listID = "gymList";
$.ajax({
url: url2,
dataType: 'json',
success: function(data) {
//Note: inner functions have access to variables in outer function
writeGymList(data,region,listID);
},
error: function(){
alert('Error in AJAX call');
}
});
url4 = sitePath()+"/php_dataquery/getGymsByCountry.php?countryCode="+countryCode+"&indoor=0";
listID2 = "cragList";
$.ajax({
url: url4,
dataType: 'json',
success: function(data) {
//Note: inner functions have access to variables in outer function
writeGymList(data,region,listID2);
},
error: function(){
alert('Error in AJAX call');
}
});
</script>
<script>
$('#vmap').vectorMap({
map: 'world_en',
backgroundColor: null,
color: '#ffffff',
hoverOpacity: 0.7,
selectedColor: '#666666',
enableZoom: true,
showTooltip: true,
values: gym_country_num,
scaleColors: ['#C8EEFF', '#006491'],
normalizeFunction: 'polynomial',
onRegionClick: function(element,code,region)
{
var clickedCountry = code.toUpperCase();
//create an ajax request to populate a list of gyms
//call PHP function with these parameters to get data
$.ajaxSetup({cache:false});
url1 = sitePath()+"/php_dataquery/getGymsByCountry.php?countryCode="+clickedCountry+"&indoor=1";
listID = "gymList";
$.ajax({
url: url1,
dataType: 'json',
success: function(data) {
//Note: inner functions have access to variables in outer function
writeGymList(data,region,listID);
},
error: function(){
alert('Error in AJAX call');
}
});
url3 = sitePath()+"/php_dataquery/getGymsByCountry.php?countryCode="+clickedCountry+"&indoor=0";
listID2 = "cragList";
$.ajax({
url: url3,
dataType: 'json',
success: function(data) {
//Note: inner functions have access to variables in outer function
writeGymList(data,region,listID2);
},
error: function(){
alert('Error in AJAX call');
}
});
}
});
</script>
<div class="row">
<h2 id="countryHeader"><?php echo $countryName ?></h2><hr>
<div class="col-sm-6">
<h3>Indoor Gyms</h3>
<div id="gymList">
</div>
</div>
<div class="col-sm-6">
<h3>Outdoor Crags</h3>
<div id="cragList">
</div>
</div>
</div>
<div id="scroll-padding">
</div>
</div>
</div>
</div>
<?php require("php_common/footer.php"); ?>
</body>
</html>