|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | +<title>Stardew Perfection Tracker</title> |
| 5 | +<link rel="stylesheet" href="style.css" /> |
| 6 | +</head> |
| 7 | +<body> |
| 8 | + |
| 9 | +<?php |
| 10 | +include "config.php"; |
| 11 | + |
| 12 | +$invalues=null; |
| 13 | +$statusmessage=null; |
| 14 | + |
| 15 | +//********************* GET SCROLL POSITION FOR AUTOSCROLL |
| 16 | + |
| 17 | +if ($_POST['scrollposname']) |
| 18 | +{ |
| 19 | + $scrollpos = $_POST['scrollposname']; |
| 20 | + echo "<script>"; |
| 21 | + echo "function scrolltopos() {"; |
| 22 | + echo "window.scrollTo(0, ".$scrollpos.");"; |
| 23 | + echo "}"; |
| 24 | + echo "window.onload = scrolltopos;"; |
| 25 | + echo "</script>"; |
| 26 | +} |
| 27 | + |
| 28 | + |
| 29 | +//********************* CHECK FOR GAME PK VALUE |
| 30 | + |
| 31 | +if (!isset($_GET['gamepk']) && !isset($_POST['gamepk'])) |
| 32 | +{ |
| 33 | + echo "<p>No game name detected. Go back and try again.</p>"; |
| 34 | + echo "<p class=\"navlink\"><a href=\"index.php\">Back to landing page</a></p>"; |
| 35 | + die(); |
| 36 | +} |
| 37 | + |
| 38 | + |
| 39 | +//********************* BUILD VARS FOR PASSING BETWEEN PAGES |
| 40 | +if($_POST) |
| 41 | +{ |
| 42 | + $gamepk = $_POST['gamepk']; |
| 43 | + strtolower($gamename = $_POST['gamename']); |
| 44 | +} |
| 45 | +else |
| 46 | +{ |
| 47 | + $gamepk = $_GET['gamepk']; |
| 48 | + strtolower($gamename = $_GET['gamename']); |
| 49 | +} |
| 50 | +$gametable = "gamedata".$gamepk.$gamename; |
| 51 | + |
| 52 | + |
| 53 | +//********************* PROCESS THE SEASON SELECTION |
| 54 | +$seasonselection = "all"; |
| 55 | +if ($_POST['season']) |
| 56 | +{ |
| 57 | + $seasonselection = $_POST['season']; |
| 58 | + unset($_POST['season']); |
| 59 | +} |
| 60 | + |
| 61 | + |
| 62 | +//********************* DEAL WITH CHANGES TO TRACKED STUFF |
| 63 | +//it's setup to "easily" switch to a multi-select thing |
| 64 | + |
| 65 | +//step 1, get the value(s) |
| 66 | +if (isset($_POST['trackerchange'])) |
| 67 | +{ |
| 68 | + foreach($_POST as $key => $value) |
| 69 | + { |
| 70 | + if($key=='trackerchange') |
| 71 | + { |
| 72 | + $invalues = $invalues.$value.", "; |
| 73 | + $invalues = rtrim($invalues, ', '); |
| 74 | + } |
| 75 | + } |
| 76 | + unset($_POST['trackerchange']); |
| 77 | + $sqlupdatetracker = "update ".$gametable." set made=1 where pk in (".$invalues.")"; |
| 78 | + unset($invalues); |
| 79 | + |
| 80 | +//step 2, pass the value(s) to the db for updating |
| 81 | + $sqlupdatetrackerresult = $pdo->query($sqlupdatetracker); |
| 82 | + if (!$sqlupdatetrackerresult) |
| 83 | + { |
| 84 | + $error = "<p>Error updating tracker. Kinda defeats the purpose of this whole thing, if I'm honest.</p><p id=\"navlinkdiv\"><a href=\"index.php\">Go back and try again?</a></p><p>".$dbc->errorInfo()."</p>"; |
| 85 | + die($error); |
| 86 | + } |
| 87 | + unset($sqlupdatetracker); |
| 88 | + unset($_POST['trackerchange']); |
| 89 | +} |
| 90 | + |
| 91 | +?> |
| 92 | + |
| 93 | +<h1>Perfection Tracker for <?php echo $gamename; ?></h1> |
| 94 | + |
| 95 | +<!-- |
| 96 | +//********************* SEASON SELECTOR |
| 97 | +// --> |
| 98 | +<form action="<?=$_SERVER['PHP_SELF']; ?>" method="post"> |
| 99 | +<input type="hidden" name="gamepk" value="<?php echo $gamepk; ?>"> |
| 100 | +<input type="hidden" name="gamename" value="<?php echo $gamename; ?>"> |
| 101 | +<div id="radiobuttoncontainer"> |
| 102 | +<input type="radio" onChange="this.form.submit();" name="season" class="theradiobuttonitself" id="spring" value="spring" <?php if ($seasonselection == 'spring') { echo "checked=\"checked\""; } ?>> |
| 103 | +<label for="spring">Spring</label> |
| 104 | + |
| 105 | +<input type="radio" onChange="this.form.submit();" name="season" class="theradiobuttonitself" id="summer" value="summer" <?php if ($seasonselection == 'summer') { echo "checked=\"checked\""; } ?>> |
| 106 | +<label for="summer">Summer</label> |
| 107 | + |
| 108 | +<input type="radio" onChange="this.form.submit();" name="season" class="theradiobuttonitself" id="fall" value="fall" <?php if ($seasonselection == 'fall') { echo "checked=\"checked\""; } ?>> |
| 109 | +<label for="fall">Fall</label> |
| 110 | + |
| 111 | +<input type="radio" onChange="this.form.submit();" name="season" class="theradiobuttonitself" id="winter" value="winter" <?php if ($seasonselection == 'winter') { echo "checked=\"checked\""; } ?>> |
| 112 | +<label for="winter">Winter</label> |
| 113 | + |
| 114 | +<input type="radio" onChange="this.form.submit();" name="season" class="theradiobuttonitself" id="all" value="all" <?php if ($seasonselection == 'all') { echo "checked=\"checked\""; } ?>> |
| 115 | +<label for="all">All</label> |
| 116 | + |
| 117 | +</div> |
| 118 | +</form> |
| 119 | + |
| 120 | + |
| 121 | +<!-- |
| 122 | +//********************* GENERATE LISTS OF REQUIRED ITEMS |
| 123 | +//--> |
| 124 | +<div class="itemcontainer"> |
| 125 | +<h2>Items</h2> |
| 126 | + |
| 127 | +<?php |
| 128 | + |
| 129 | +switch ($seasonselection) |
| 130 | +{ |
| 131 | + case "spring": |
| 132 | + $sqlseason="and i1.spring=1 "; |
| 133 | + break; |
| 134 | + case "summer": |
| 135 | + $sqlseason="and i1.summer=1 "; |
| 136 | + break; |
| 137 | + case "fall": |
| 138 | + $sqlseason="and i1.fall=1 "; |
| 139 | + break; |
| 140 | + case "winter": |
| 141 | + $sqlseason="and i1.winter=1 "; |
| 142 | + break; |
| 143 | + case "all": |
| 144 | + $sqlseason=""; |
| 145 | + break; |
| 146 | +} |
| 147 | + |
| 148 | +$itemtype = array(0=>"crop", 1=>"forage", 2=>"fish"); |
| 149 | + |
| 150 | +foreach($itemtype as $key => $value) |
| 151 | +{ |
| 152 | + $itemheader = ucwords($value); |
| 153 | + $sqlselectitemsbygroups = "select i1.item_name as name, sum(r1.item_quantity) as quantity |
| 154 | + from recipes r1 |
| 155 | + left join items i1 on r1.item_id=i1.item_id |
| 156 | + left join ".$gametable." t1 on r1.trackable_id=t1.trackable_id |
| 157 | + where t1.made=0 and i1.".$value."=1 ".$sqlseason."group by i1.item_name |
| 158 | + order by i1.item_name"; |
| 159 | + |
| 160 | + $sqlitemsbygroupsresult = $pdo->query($sqlselectitemsbygroups); |
| 161 | + unset($sqlselectitemsbygroups); |
| 162 | +/* if (!$sqlitemsbygroupsresult) |
| 163 | + { |
| 164 | + echo "Error requesting \"".$value."\" and \"".$seasonselection."\". Something's broken.: " . $dbc->errorInfo(); |
| 165 | + echo "<p class=\"navlink\"><a href=\"index.php\">Back to landing page</a></p>"; |
| 166 | + die($error); |
| 167 | + }*/ |
| 168 | + |
| 169 | + //need to see if there are any items of the group left for this season |
| 170 | + //prime the $row, and reset the pointer back to 0 for the loop later |
| 171 | +// $row = $sqlitemsbygroupsresult->fetch(); |
| 172 | +// pg_result_seek($sqlitemsbygroupsresult, 0); |
| 173 | + |
| 174 | + if($sqlitemsbygroupsresult->rowCount() > 0) //if there are no items left in this group for this season |
| 175 | + { |
| 176 | + echo "<div class=\"itemgroupcontainer\">\n"; //itemsgroupedbytype |
| 177 | + echo "<h3 class=\"itemgroupheader\">".ucwords($itemheader)."</h3>\n"; |
| 178 | + echo "<table class=\"itemtable\">\n"; |
| 179 | + echo "<tr class=\"alternatingcolours\">"; |
| 180 | + echo "<th class=\"leftalign\">Item</th>"; |
| 181 | + echo "<th class=\"centered\">Quantity</th>"; |
| 182 | + echo "</tr>\n"; |
| 183 | + while ($row = $sqlitemsbygroupsresult->fetch()) |
| 184 | + { |
| 185 | + $nameurl = str_replace(' ', '_', $row['name']); |
| 186 | + echo "<tr class=\"alternatingcolours\">"; |
| 187 | + echo "<td class=\"item\"><a target=\"_blank\" class=\"itemlink\" href=\"https://stardewvalleywiki.com/".$nameurl."\">".$row['name']."</a></td>"; |
| 188 | + echo "<td class=\"item centered quantities\">".$row['quantity']."</td>"; |
| 189 | + echo "</tr>\n"; |
| 190 | + } |
| 191 | + echo "</table>\n"; |
| 192 | + echo "</div>\n"; //itemsgroupedbytype |
| 193 | + } |
| 194 | +} //foreach |
| 195 | +unset($itemheader); |
| 196 | +unset($itemtype); |
| 197 | +unset($sqlseason); |
| 198 | + |
| 199 | + |
| 200 | +//********************* EVERYTHING ELSE TABLE */ |
| 201 | + |
| 202 | +$sqlselecteverythingelse = "select i1.item_name as name, sum(r1.item_quantity) as quantity |
| 203 | + from recipes r1 |
| 204 | + left join items i1 on r1.item_id=i1.item_id |
| 205 | + left join ".$gametable." t1 on r1.trackable_id=t1.trackable_id |
| 206 | + where t1.made=0 and (i1.crop=0 and i1.fish=0 and i1.forage=0) |
| 207 | + group by i1.item_name |
| 208 | + order by i1.item_name"; |
| 209 | + |
| 210 | +$sqleverythingelseresult = $pdo->query($sqlselecteverythingelse); |
| 211 | +unset($sqlselecteverythingelse); |
| 212 | + |
| 213 | +if ($sqleverythingelseresult->rowCount() > 0) |
| 214 | +{ |
| 215 | + echo "<div class=\"itemgroupcontainer\">\n"; //itemsgroupedbytype |
| 216 | + echo "<h3 class=\"itemgroupheader\">Everything Else</h3>\n"; |
| 217 | + echo "<table class=\"itemtable\">\n"; |
| 218 | + echo "<tr class=\"alternatingcolours\">"; |
| 219 | + echo "<th class=\"leftalign\">Item</th>"; |
| 220 | + echo "<th class=\"centered\">Quantity</th>"; |
| 221 | + echo "</tr>\n"; |
| 222 | + |
| 223 | + while ($row = $sqleverythingelseresult->fetch()) |
| 224 | + { |
| 225 | + $nameurl = str_replace(' ', '_', $row['name']); |
| 226 | + echo "<tr class=\"alternatingcolours\">"; |
| 227 | + echo "<td class=\"item\"><a target=\"_blank\" class=\"itemlink\" href=\"https://stardewvalleywiki.com/".$nameurl."\">".$row['name']."</a></td>"; |
| 228 | + echo "<td class=\"item centered quantities\">".$row['quantity']."</td>"; |
| 229 | + echo "</tr>\n"; |
| 230 | + } |
| 231 | + unset($nameurl); |
| 232 | + echo "</table>\n"; |
| 233 | + echo "</div>\n"; //itemsgroupedbytype |
| 234 | +} |
| 235 | +?> |
| 236 | + |
| 237 | +</div> <!-- itemcontainer --> |
| 238 | + |
| 239 | +<div class="trackingcontainer"> |
| 240 | +<h2>Tracking</h2> |
| 241 | +<form action="<?=$_SERVER['PHP_SELF']; ?>" method="post"> |
| 242 | +<input type="hidden" name="gamepk" value="<?php echo $gamepk; ?>"> |
| 243 | +<input type="hidden" name="gamename" value="<?php echo $gamename; ?>"> |
| 244 | +<input type="hidden" name="season" value="<?php echo $seasonselection; ?>"> |
| 245 | + |
| 246 | + |
| 247 | + |
| 248 | +<?php |
| 249 | +//********************* TRACKABLES, GROUPED BY TYPE, WITH CHECKBOXES */ |
| 250 | + |
| 251 | +switch ($seasonselection) |
| 252 | +{ |
| 253 | + case "spring": |
| 254 | + $sqltrackableseason="and (i1.spring=1 or (i1.spring=0 and i1.summer=0 and i1.fall=0 and i1.winter=0)) "; |
| 255 | + break; |
| 256 | + case "summer": |
| 257 | + $sqltrackableseason="and (i1.summer=1 or (i1.spring=0 and i1.summer=0 and i1.fall=0 and i1.winter=0)) "; |
| 258 | + break; |
| 259 | + case "fall": |
| 260 | + $sqltrackableseason="and (i1.fall=1 or (i1.spring=0 and i1.summer=0 and i1.fall=0 and i1.winter=0)) "; |
| 261 | + break; |
| 262 | + case "winter": |
| 263 | + $sqltrackableseason="and (i1.winter=1 or (i1.spring=0 and i1.summer=0 and i1.fall=0 and i1.winter=0)) "; |
| 264 | + break; |
| 265 | + case "all": |
| 266 | + $sqltrackableseason=""; |
| 267 | + break; |
| 268 | +} |
| 269 | + |
| 270 | +$trackabletype = array(0=>"bundle", 1=>"fish", 2=>"quest", 3=>"shipping", 4=>"crafting", 5=>"cooking"); |
| 271 | + |
| 272 | +foreach($trackabletype as $key => $value) |
| 273 | +{ |
| 274 | + switch ($value) |
| 275 | + { |
| 276 | + case "bundle": |
| 277 | + $sqltrackabletype="and i1.bundle=1 "; |
| 278 | + break; |
| 279 | + case "cooking": |
| 280 | + $sqltrackabletype="and i1.cooking=1 "; |
| 281 | + break; |
| 282 | + case "crafting": |
| 283 | + $sqltrackabletype="and i1.crafting=1 "; |
| 284 | + break; |
| 285 | + case "fish": |
| 286 | + $sqltrackabletype="and i1.fish=1 "; |
| 287 | + break; |
| 288 | + case "shipping": |
| 289 | + $sqltrackabletype="and i1.shipping=1 "; |
| 290 | + break; |
| 291 | + case "quest": |
| 292 | + $sqltrackabletype="and i1.quest=1 "; |
| 293 | + break; |
| 294 | + } |
| 295 | + |
| 296 | + $sqlselecttrackables = "select i1.item_name as name, t1.pk, t1.made |
| 297 | + from items i1 |
| 298 | + right join ".$gametable." t1 on i1.item_id=t1.trackable_id |
| 299 | + where i1.trackable=1 and t1.made=0 ".$sqltrackabletype." ".$sqltrackableseason." |
| 300 | + order by i1.item_name"; |
| 301 | + unset($sqltrackabletype); |
| 302 | + $sqltrackablesresult = $pdo->query($sqlselecttrackables); |
| 303 | + unset($sqlselecttrackables); |
| 304 | + if ($sqltrackablesresult->rowCount() > 0) //if there are no items left in this group for this season |
| 305 | + { |
| 306 | + echo "<div class=\"trackinggroupcontainers\">\n"; //trackablesgroupedbytype |
| 307 | + echo "<h3 class=\"trackinggroupheader\">".ucwords($value)."</h3>\n"; |
| 308 | + echo "<table class=\"trackingtable\">\n"; |
| 309 | + echo "<tr class=\"alternatingcolours\">"; |
| 310 | + echo "<th class=\"leftalign\">Trackable</th>"; |
| 311 | + echo "<th class=\"centered\">Done?</th>"; |
| 312 | + echo "</tr>\n"; |
| 313 | + |
| 314 | + while ($row = $sqltrackablesresult->fetch()) |
| 315 | + { |
| 316 | + $nameurl = str_replace(' ', '_', $row['name']); |
| 317 | + echo "<tr class=\"alternatingcolours\">"; |
| 318 | + echo "<td class=\"item\"><a target=\"_blank\" class=\"itemlink\" href=\"https://stardewvalleywiki.com/".$nameurl."\">".$row['name']."</a></td>"; |
| 319 | + |
| 320 | + //items will only show up on this list if t1.made=0, but in case you want to view what has been |
| 321 | + //made in the lists, change the sql, and use this stuff to check the boxes |
| 322 | + /* |
| 323 | + if ($row['made'] == 't') |
| 324 | + { |
| 325 | + $checkboxvar=" checked"; |
| 326 | + } |
| 327 | + else |
| 328 | + { |
| 329 | + $checkboxvar=""; |
| 330 | + } |
| 331 | + */ |
| 332 | + echo "<td class=\"item centered\"><input type=\"checkbox\" onChange=\"this.form.submit();\" name=\"trackerchange\" value=\"".$row['pk']."\""; |
| 333 | +// echo $checkboxvar; |
| 334 | + echo "></td></tr>\n"; |
| 335 | + } |
| 336 | +// unset($checkboxvar); |
| 337 | + unset($nameurl); |
| 338 | + echo "</table>\n"; |
| 339 | + echo "</div>\n"; //trackablesgroupedbytype |
| 340 | + } |
| 341 | +} //foreach |
| 342 | +unset($trackabletype); |
| 343 | + |
| 344 | + |
| 345 | +?> |
| 346 | +<input type="hidden" id="scrollposid" name="scrollposname" value="" /> |
| 347 | +</form> |
| 348 | +</div> <!--trackingcontainer --> |
| 349 | + |
| 350 | +<div class="navigation"> |
| 351 | +<form action="reset.php" method="post"> |
| 352 | +<input type="hidden" name="gamepk" value="<?php echo $gamepk; ?>"> |
| 353 | +<input type="hidden" name="gamename" value="<?php echo $gamename; ?>"> |
| 354 | +<input type="hidden" name="season" value="<?php echo $seasonselection; ?>"> |
| 355 | +<p><input type="submit" class="submitbutton" name="fromtracker" value="Reset trackables" /></p> |
| 356 | +</form> |
| 357 | +<p id="navlink"><a href="index.php">Back to landing page</a></p> |
| 358 | +</div> <!-- navigation --> |
| 359 | + |
| 360 | + |
| 361 | +<!-- ********************* GET SCROLL POSITION --> |
| 362 | +<script> |
| 363 | +window.addEventListener("scroll", (event) => { |
| 364 | + let scroll = this.scrollY; |
| 365 | + document.getElementById("scrollposid").value = scroll; |
| 366 | +}); |
| 367 | +</script> |
| 368 | + |
| 369 | +</body> |
| 370 | +</html> |
| 371 | +<?php |
| 372 | +unset($gamepk); |
| 373 | +unset($gamename); |
| 374 | +unset($gametable); |
| 375 | +unset($seasonselection); |
| 376 | +unset($sqltrackableseason); |
| 377 | +unset($row); |
| 378 | +unset($key); |
| 379 | +unset($value); |
| 380 | + |
| 381 | +$dbc = null; |
| 382 | +?> |
0 commit comments