-
Notifications
You must be signed in to change notification settings - Fork 0
/
subareas.php
224 lines (144 loc) · 6.38 KB
/
subareas.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
include("inc/data.php");
if(isset($_GET['page'])){$page = $_GET['page'];} else {$page = 1;}
$area = null;
$area = $_GET["area"];
$subarea = $_GET["subarea"];
$section = $_GET["section"];
$all = null;
$all = $_GET['all'];
include("inc/header.php");
include("inc/topostyle.php");
// STEP 4 - function takes IDs and returns corresponding values from data.php
function get_area($id,$item,$problem,$i){
$problems = 0;
foreach ($problem as $key => $value):
if ($problem[$key - ($key % 100)]['area'] == $problem[$id]['area']){
$problems +=1;
}
endforeach;
$star = 0;
foreach ($problem as $key => $value):
if ($problem[$key - ($key % 100)]['area'] == $problem[$id]['area'] && $value['star'] == "y"){
$star +=1;
}
endforeach;
$heart = 0;
foreach ($problem as $key => $value):
if ($problem[$key - ($key % 100)]['area'] == $problem[$id]['area'] && $value['best'] == "y"){
$heart +=1;
}
endforeach;
$bench = 0;
foreach ($problem as $key => $value):
if ($problem[$key - ($key % 100)]['area'] == $problem[$id]['area'] && $value['bench'] == "y"){
$bench +=1;
}
endforeach;
if ($area == null){$areaphoto = $problem[$id]['area'];}
if ($area == null){$areadescription = $problem[$id]['adescription'];}
if ($area == null){$astar = $problem[$id]['adescription'];}
if ($area == null){$aheart = $problem[$id]['adescription'];}
if ($area == null){$abench = $problem[$id]['adescription'];}
if ($area == null){$areaapproach = $problem[$id]['aapproach'];}
if ($area == null){$areadrive = $problem[$id]['adrive'];}
if ($area == null){$areagrade = $problem[$id]['agrades'];}
if ($area == null){$link = "areas.php?all=y&area=".$problem[$id]['area'];}
$sorterarea = $problem[$id]['areatitle'];
$sortersubarea = $problem[$id]['subareatitle'];
if (is_int($i/3)){$linebreak = "</div><div class='w3-light-grey w3-row-padding w3-center' id='food' style='margin-top:0px;''>";}
$output =
"<div class='w3-third w3-container w3-margin-bottom'><a href='".$link."'><img src='img/are/".$areaphoto.".jpg' alt='Chebucto' style='width:100%' class='w3-hover-opacity'></a><div class='w3-container w3-white w3-card'><h4>".$sorterarea."<b></h4>Problems: ".$problems." <img src='/img/ico/star.png' alt='star'> ".$star. " <img src='/img/ico/best.png' alt='star'> ".$heart." <img src='/img/ico/bench.png' alt='star'> ".$bench." <p></b>".$areadescription."<br><br><b>Drive "
.$areadrive." min <br>Approach ".$areaapproach." mins <br>Grades ".$areagrade."</p></b></div></div>".$linebreak;
return $output;
}
// STEP 2 - Search function - outputs an array of IDs based on parameters of a foreach loop, and specified input value $grade
function search_array($problem,$area,$subarea,$section){
$output = array();
foreach ($problem as $id => $item){
if ($area == null && $subarea == null && isset($item["area"])){
$sort = $item['area'];
$output[$id] = $sort;
$output = array_unique($output);
}
else if (isset($area) && $area == $item["area"] && $item["subarea"] == ""){
$sort = $item['area'];
$output[$id] = $sort;
}
else if (isset($area) && $area == $item["area"] && $item["subarea"] != ""){
$sort = $item['subarea'];
$output[$id] = $sort;
$output = array_unique($output);
}
else if (isset($subarea) && $subarea == $item["subarea"]){
$sort = $item['section'];
$output[$id] = $sort;
}
}
asort($output);
return array_keys($output);
}
// STEP 1 - creates an variable containing an array of IDs generated by the array_category function. Specify the input to pass to the search function
$areasearch = search_array($problem,$area,$subarea,$section);
$resultstotal = count($areasearch);
// STEP 3 - takes an array of IDs from the search and returns valuses from get_grade function
// foreach (associateive array AS array key => array key's value) {code to execute}
//functions are named containers for code snippets to be executed with passed variables
//function function_name(variables to pass to function){code to execute using passed variables}
?>
<!-- Problem Sorter Controls -->
<!-- Display area -->
<?php
print_r($areasearch);
function addOrUpdateUrlParam($name, $value) // function to create links adding new html parameters while keeping the old ones
{
$params = $_GET;
unset($params[$name]);
$params[$name] = $value;
return basename($_SERVER['PHP_SELF']).'?'.http_build_query($params);
}
// code to create pagination
$urlnext = addOrUpdateUrlParam("page", $page+1);
$urlprevious = addOrUpdateUrlParam("page", $page-1);
$itemsperpage = 20;
$pagestotal = ceil(count($areasearch)/$itemsperpage);
?>
<!-- First Row -->
<div class="w3-light-grey w3-row-padding w3-center" id="food" style="margin-top:0px;">
<?php
// STEP 4 code the calls the results of the sorted and formatted search array and inserts results into the page
if ($all == null){$areasearch = array_slice($areasearch,0,3);}else if ($all == "y"){$areasearch = $areasearch;}
$arrayslice2 = array_slice($areasearch,(0+($itemsperpage*($page -1))),$itemsperpage);
$i = 1;
foreach ($arrayslice2 as $id){
echo get_area($id,$problem[$id],$problem,$i);
$i +=1;
}
// Pagination links
?>
</div>
<div class="w3-center">
<button class="w3-button w3-black w3-padding-large w3-margin-bottom <?php if ($all == "y") { echo "w3-hide"; } ?>" onclick="updateURL();"><i class="fa fa-arrow-down w3-margin-right"></i>Show More</button>
</div>
<div class="w3-center">
<?php if ($page > 1){echo "<a href='".$urlprevious."'>";} ?><button class="w3-button w3-large <?php if ($page > 1){echo "w3-black";} else {echo "w3-lightgrey";} ?>">‹</button><?php if ($page > 1){echo "</a>";} ?>
<?php if ($page < $pagestotal){echo "<a href='".$urlnext."'>";} ?><button class="w3-button w3-large <?php if ($page < $pagestotal){echo "w3-black";} else {echo "w3-lightgrey";} ?>">›</button><?php if ($page < $pagestotal){echo "</a>";} ?>
</div>
<?php include("inc/footer.php");?>
<script>
var slideCol = document.getElementById("id1");
var y = document.getElementById("f");
y.innerHTML = slideCol.value;
slideCol.oninput = function() {
y.innerHTML = this.value;
}
</script>
<script>
var slideCol2 = document.getElementById("id2");
var y2 = document.getElementById("g");
y2.innerHTML = slideCol2.value;
slideCol2.oninput = function() {
y2.innerHTML = this.value;
}
</script>
</html>