Skip to content

Commit 50980b9

Browse files
authoredMay 21, 2021
Add files via upload
1 parent 1aa1e22 commit 50980b9

File tree

5 files changed

+944
-0
lines changed

5 files changed

+944
-0
lines changed
 

‎config.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
$host = 'localhost';
3+
$db = 'dbname';
4+
$user = 'user_with_rights_to_the_db';
5+
$password = 'password';
6+
$dbc = "mysql:host=$host;dbname=$db";
7+
$pdo = new PDO($dbc, $user, $password);
8+
?>

‎delete.php

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Perfection Tracker Delete Game</title>
5+
<link rel="stylesheet" href="style.css" />
6+
</head>
7+
<body>
8+
9+
<?php
10+
include "config.php";
11+
12+
$sqlselectgamedata = "select pk,gamename from gamelist where active=1 order by gamename";
13+
$sqlgamedata = $pdo->query($sqlselectgamedata);
14+
unset($sqlselectgamedata);
15+
if (!$sqlgamedata)
16+
{
17+
$error = "<p>Error retrieving table key. Can\'t add the game.</p><p>".$dbc->errorInfo()."</p>";
18+
die($error);
19+
}
20+
else
21+
{
22+
$listofoptions = "";
23+
while ($row = $sqlgamedata->fetch())
24+
{
25+
$listofoptions = $listofoptions."<option value=\"".$row['pk']."\">".ucwords($row['gamename'])."</option>\n";
26+
}
27+
}
28+
29+
?>
30+
<form action="index.php" method="post">
31+
<h2>Delete a game</h2>
32+
<div>Select a game to delete:
33+
<select name="gametodelete" id="deletedropdown">
34+
<option value="" selected disabled>Select the game</option>
35+
36+
<?php
37+
echo $listofoptions;
38+
unset($listofoptions);
39+
?>
40+
</select>
41+
</div>
42+
<p id="submitdiv"><input type="submit" id="submitbutton" name="deletionrequest" value="Submit" /></p>
43+
</form>
44+
<div class="navigation">
45+
<p class="navlink"><a href="index.php">Go back without deleting</a></p>
46+
</div> <!-- navigation -->
47+
48+
49+
</body>
50+
</html>
51+
<?php
52+
unset($row);
53+
$dbc=null;
54+
?>

‎index.php

+301
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Perfection Tracker Landing</title>
5+
<link rel="stylesheet" href="style.css" />
6+
</head>
7+
<body>
8+
9+
<?php
10+
include "config.php";
11+
$nametaken=null;
12+
$statusmessage=null;
13+
14+
//********************* CHECK FOR DELETIONS
15+
16+
if (isset($_POST['deletionrequest']))
17+
{
18+
$pkofgametodelete = $_POST['gametodelete'];
19+
$sqlgamenamelookup = "select gamename from gamelist where pk=".$_POST['gametodelete'];
20+
$sqlgamenamelookupresult = $pdo->query($sqlgamenamelookup);
21+
unset($sqlgamenamelookup);
22+
if (!$sqlgamenamelookupresult)
23+
{
24+
$error = $error."<p>Unable to find the right game. Something is VERY wrong. ".$dbc->errorInfo()."</p><p><a id=\"navlink\" href=\"index.php\">Back to the landing page...</a></p>";
25+
die($error);
26+
}
27+
else
28+
{
29+
$nameofgametodelete = $sqlgamenamelookupresult->fetchColumn();
30+
}
31+
32+
if (!$pkofgametodelete)
33+
{
34+
$statusmessage = "No game specified for deletion (did you pick a game?).";
35+
}
36+
else
37+
{
38+
$tablename = "gamedata".$_POST['gametodelete'].$nameofgametodelete;
39+
$sqldeletefromgamelist = "delete from gamelist where pk=".$pkofgametodelete;
40+
$sqldeletegametable = "drop table ".$tablename;
41+
// $sqldeletesequence = "drop sequence ".$tablename."_pk_seq";
42+
unset($pkofgametodelete);
43+
unset($tablename);
44+
$error = "";
45+
$sqldeletefromgamelistresult = $pdo->query($sqldeletefromgamelist);
46+
if (!$sqldeletefromgamelistresult)
47+
{
48+
$error = $error."<p>Unable to delete game. Not the end of the world, but thought you should know. ".$dbc->errorInfo()."</p>";
49+
}
50+
51+
$sqldeletegametableresult = $pdo->query($sqldeletegametable);
52+
if (!$sqldeletegametableresult)
53+
{
54+
$error = $error."<p>Unable to delete game table. Oh well, just means some manual cleanup. ".$dbc->errorInfo()."</p>";
55+
}
56+
/* $sqldeletesequenceresult = $pdo->query($sqldeletesequence);
57+
if (!$sqldeletesequenceresult)
58+
{
59+
$error = $error."<p>Unable to delete game pk sequence. No biggie, just needs to be done manually. ".$dbc->errorInfo()."</p>";
60+
}
61+
*/
62+
if ($error)
63+
{
64+
echo "<p><a id=\"navlink\" href=\"index.php\">Back to the landing page...</a></p>";
65+
die($error);
66+
}
67+
else
68+
{
69+
$statusmessage = "Game deleted successfully!";
70+
}
71+
}
72+
}
73+
74+
75+
76+
//********************* BUILD INITIAL LIST OF GAMES
77+
78+
$sqlselectgamelist = "select pk,gamename from gamelist where active=1 order by gamename";
79+
$sqllistofgamesresult = $pdo->query($sqlselectgamelist);
80+
if (!$sqllistofgamesresult)
81+
{
82+
$error = "<p>Error loading game list. Something's very broken.</p><p><a href=\"index.php\">Try again?</a></p>";
83+
die($dbc->errorInfo());
84+
}
85+
if($sqllistofgamesresult->rowCount() > 0) //if there are no items left in this group for this season
86+
{
87+
$listofgames = "<h2>List of Games</h2><ul>";
88+
while ($row = $sqllistofgamesresult->fetch())
89+
{
90+
$listofgames = $listofgames."<li><form action=\"tracker.php\" method=\"get\"><input type=\"submit\" class=\"gamelistbutton\" name=\"gamename\" value=\"".ucwords($row['gamename'])."\" /><input type=\"hidden\" name=\"gamepk\" value=\"".$row['pk']."\"></form></li>\n";
91+
}
92+
$listofgames=$listofgames."</ul>";
93+
}
94+
unset($row);
95+
96+
97+
//********************* UPDATE GAME TABLES
98+
99+
if (isset($_POST['updaterequest']))
100+
{
101+
$sqlselectgamepks = "select pk,gamename from gamelist";
102+
$sqlselectgamepksresult = $pdo->query($sqlselectgamepks);
103+
unset($sqlselectgamepks);
104+
if (!$sqlselectgamepksresult)
105+
{
106+
$error = "<p>Error updating tables. Can't query the list of games.</p><p><a href=\"index.php\">Try again?</a></p>";
107+
die($dbc->errorInfo());
108+
}
109+
$sqllistofgamesresult2 = $pdo->query($sqlselectgamelist);
110+
while ($row = $sqllistofgamesresult2->fetch())
111+
{
112+
$tablename = "gamedata".$row['pk'].$row['gamename'];
113+
$sqlupdategametable = "insert into ".$tablename." (trackable_id) select items.item_id from items where items.trackable=1 except select ".$tablename.".trackable_id from ".$tablename;
114+
$sqlupdategametableresult = $pdo->query($sqlupdategametable);
115+
116+
if (!$sqlupdategametableresult)
117+
{
118+
$error="<p>Error updating \"".$row['gamename']."\".</p><p><a href=\"index.php\">Try again?</a></p>";
119+
die($error);
120+
}
121+
$sqlupdategametable2 = "delete from ".$tablename." where ".$tablename.".trackable_id in (select items.item_id from items where items.trackable=0)";
122+
$sqlupdategametableresult2 = $pdo->query($sqlupdategametable2);
123+
if (!$sqlupdategametableresult2)
124+
{
125+
$error="<p>Error removing excess data from \"".$row['gamename']."\".</p><p><a href=\"index.php\">Try again?</a></p>";
126+
die($error);
127+
}
128+
}
129+
$statusmessage="<p>Tables updated successfully!</p>";
130+
unset($sqlupdategametable);
131+
unset($sqlupdategametable2);
132+
unset($row);
133+
unset($tablename);
134+
}
135+
136+
137+
//********************* ADD A NEW GAME
138+
139+
if (isset($_POST['posted']))
140+
{
141+
$newgamename = preg_replace("/[^a-zA-Z0-9]+/", "", $_POST['newgamename']); //remove any non-alphanumerics,
142+
$newgamename = strtolower($newgamename); //make it lower case,
143+
$newgamename = substr($newgamename,0,40); //and truncate it to 40 characters
144+
unset($_POST);
145+
if (!$newgamename) //if there's nothing left after the sanitization
146+
{
147+
$statusmessage="Invalid name. Only use a-z and/or 0-9 in the name.";
148+
}
149+
else
150+
{
151+
while ($row = $sqllistofgamesresult->fetch()) //check for duplicate names
152+
{
153+
if ($row['gamename'] == $newgamename)
154+
{
155+
$nametaken=TRUE;
156+
$statusmessage="Name already in use. Choose a different name.";
157+
break;
158+
}
159+
else
160+
{
161+
$nametaken=FALSE;
162+
}
163+
}
164+
unset($row);
165+
if (!$nametaken) //add new game name to gamelist table
166+
{
167+
$sqlinsertgamename = "insert into gamelist (gamename) values ('".$newgamename."')";
168+
$sqlinsertgamenameresult = $pdo->query($sqlinsertgamename);
169+
unset($sqlinsertgamename);
170+
if (!$sqlinsertgamenameresult)
171+
{
172+
$error = "<p>Error adding name to database. Something\'s broken.</p><p><a id=\"navlink\" href=\"index.php\">Try again?</a></p>";
173+
die($dbc->errorInfo());
174+
}
175+
else //rebuild list of games with new game name
176+
{
177+
$sqllistofgamesresult = $pdo->query($sqlselectgamelist);
178+
$listofgames = "<h2>List of Games</h2><ul>";
179+
while ($row = $sqllistofgamesresult->fetch())
180+
{
181+
$listofgames = $listofgames."<li><form action=\"tracker.php\" method=\"get\"><input type=\"submit\" class=\"gamelistbutton\" name=\"gamename\" value=\"".ucwords($row['gamename'])."\" /><input type=\"hidden\" name=\"gamepk\" value=\"".$row['pk']."\"></form></li>\n";
182+
}
183+
$listofgames=$listofgames."</ul>";
184+
185+
unset($row);
186+
unset($sqlselectgamelist);
187+
188+
//get the primary key value of the new game (we use it to name the db seq and data table)
189+
$sqlretrievegamepk = "select pk from gamelist where gamename='" . $newgamename . "' and active!=0";
190+
$sqlretrievegamepkresult = $pdo->query($sqlretrievegamepk);
191+
unset($sqlretrievegamepk);
192+
if (!$sqlretrievegamepkresult)
193+
{
194+
$error = "<p>Error retrieving table key. Can\'t add the game. ".$dbc->errorInfo()."</p><p><a id=\"navlink\" href=\"index.php\">Back to the landing page...</a></p>";
195+
die($error);
196+
}
197+
else
198+
{
199+
$pk = $sqlretrievegamepkresult->fetchColumn();
200+
$sqltablename = "gamedata".$pk.$newgamename;
201+
unset($newgamename);
202+
/* $sqlsequencename = $sqltablename."_pk_seq";
203+
$sqlcreatesequence = "create sequence ".$sqlsequencename." start 1";
204+
$sqlcreatesequenceresult = $pdo->query($sqlcreatesequence);
205+
unset($sqlcreatesequence);
206+
if (!$sqlcreatesequenceresult)
207+
{
208+
$error = "<p>Error creating sequence. Unable to setup new game.: ".$dbc->errorInfo()."</p><p><a id=\"navlink\" href=\"index.php\">Back to the landing page...</a></p>";
209+
die($error);
210+
}
211+
212+
*/
213+
//create the game data table
214+
$sqlcreatetable = "create table ".$sqltablename." (pk integer not null auto_increment primary key, trackable_id integer, made int default 0)";
215+
$sqlcreatetableresult = $pdo->query($sqlcreatetable);
216+
unset($sqlcreatetable);
217+
if (!$sqlcreatetableresult)
218+
{
219+
echo "<p>Error adding table to database. Unable to setup new game.: ".$dbc->errorInfo()."</p>";
220+
echo "<p>Cleaning up...</p>";
221+
/* $sqldeletesequence = "drop sequence ".$sqlsequencename;
222+
$sqldeletesequenceresult = $pdo->query($sqldeletesequence);
223+
unset($sqldeletesequence);
224+
if (!$sqldeletesequenceresult)
225+
{
226+
$error = "<p>Error deleting sequence. Something\'s very broken.: ".$dbc->errorInfo()."</p><p><a id=\"navlink\" href=\"index.php\">Back to the landing page...</a></p>";
227+
die($error);
228+
}*/
229+
die('<p>Cleanup complete. Exiting.</p>');
230+
}
231+
232+
//populate the initial values in the game data table
233+
$sqltableinit = "insert into ".$sqltablename." (trackable_id) select items.item_id from items where items.trackable=1";
234+
$sqltableinitresult = $pdo->query($sqltableinit);
235+
unset($sqltableinit);
236+
if (!$sqltableinitresult)
237+
{
238+
echo "<p>Error populating game table. Could try it again, but something's probably broken.: ".$dbc->errorInfo()."</p>";
239+
echo "<p>Cleaning up...</p>";
240+
$sqldeletetable = "drop table ".$sqltablename;
241+
$sqldeletetableresult = $pdo->query($sqldeletetable);
242+
unset($sqldeletetable);
243+
if (!$sqldeletetableresult)
244+
{
245+
$error = "<p>Error deleting table. Something\'s very broken.: ".$dbc->errorInfo()."</p><p><a id=\"navlink\" href=\"index.php\">Back to the landing page...</a></p>";
246+
die($error);
247+
}
248+
/* $sqldeletesequence = "drop sequence ".$sqlsequencename;
249+
$sqldeletesequenceresult = $pdo->query($sqldeletesequence);
250+
unset($sqldeletesequence);
251+
if (!$sqldeletesequenceresult)
252+
{
253+
$error = "<p>Error deleting sequence. Something\'s very broken.: ".$dbc->errorInfo()."</p><p><a id=\"navlink\" href=\"index.php\">Back to the landing page...</a></p>";
254+
die($error);
255+
}*/
256+
die('<p>Cleanup complete.</p><p><a id=\"navlink\" href=\"index.php\">Back to the landing page...</a></p>');
257+
}
258+
}
259+
// unset($sqldeletesequence);
260+
unset($sqltablename);
261+
// unset($sqlsequencename);
262+
}
263+
}
264+
unset($nametaken);
265+
}
266+
}
267+
268+
?>
269+
270+
<h1>Perfection Item Tracker</h1>
271+
<div class="statusmessage"><p><?php echo $statusmessage ?></p></div>
272+
<div id="listofgamesdiv">
273+
<?php echo $listofgames; ?>
274+
</div>
275+
276+
<div id="createnewgamediv">
277+
<form action="<?=$_SERVER['PHP_SELF']; ?>" method="post">
278+
<h2>Create a new game</h2>
279+
<p>
280+
New Game Name (alphanumeric): <input type="text" id="newgameinputbox" name="newgamename" maxlength="40" /><br />
281+
<input type="submit" id="submitbutton" name="posted" value="Add Game" />
282+
</p>
283+
</form>
284+
</div>
285+
286+
<div id="deletegamediv">
287+
<p class="navlink"><a href="delete.php">Click here to delete a game</a></p>
288+
<form action="<?=$_SERVER['PHP_SELF']; ?>" method="post">
289+
<input type="hidden" name="updaterequest" value="updaterequest">
290+
<input type="submit" class="submitbutton" name="submitupdate" value="Click here to update game tables" />
291+
</form>
292+
</p>
293+
</div>
294+
295+
</body>
296+
</html>
297+
<?php
298+
unset($listofgames);
299+
unset($statusmessage);
300+
$dbc=null;
301+
?>

‎reset.php

+199
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Perfection Tracker Reset</title>
5+
<link rel="stylesheet" href="style.css" />
6+
</head>
7+
<body>
8+
9+
<?php
10+
include "config.php";
11+
12+
$yesvalues=null;
13+
$novalues=null;
14+
$gamepk = $_POST['gamepk'];
15+
$gamename = $_POST['gamename'];
16+
$seasonselection = $_POST['season'];
17+
$gametable = "gamedata".$gamepk.$gamename;
18+
19+
if (!($gamepk || $gamename || $seasonselection))
20+
{
21+
echo "<p>Game meta data did not load properly.</p><p class=\"navlink\"><a href=\"index.php\">Try again?</a></p>";
22+
die();
23+
}
24+
25+
if (isset($_POST['submitted'])) //with submitted updates
26+
{
27+
unset($_POST['submitted']);
28+
foreach($_POST as $key => $value) //build the sql "IN" lists, one each for yes and no
29+
{
30+
switch ($value)
31+
{
32+
case "yes":
33+
$yesvalues = $yesvalues.$key.", ";
34+
break;
35+
case "no":
36+
$novalues = $novalues.$key.", ";
37+
break;
38+
}
39+
}
40+
41+
$yesvalues = rtrim($yesvalues, ', ');
42+
$novalues = rtrim($novalues, ', ');
43+
44+
//prime the sqlresult vars so the error check will pass
45+
$sqlresultyes = 1;
46+
$sqlresultno = 1;
47+
48+
if ($yesvalues)
49+
{
50+
$sqlinsertyes = "update ".$gametable." set made=1 where pk in (".$yesvalues.")";
51+
$sqlresultyes = $pdo->query($sqlinsertyes);
52+
}
53+
if ($novalues)
54+
{
55+
$sqlinsertno = "update ".$gametable." set made=0 where pk in (".$novalues.")";
56+
$sqlresultno = $pdo->query($sqlinsertno);
57+
}
58+
unset($yesvalues);
59+
unset($novalues);
60+
61+
if (!$sqlresultyes OR !$sqlresultno)
62+
{
63+
$error = "<p>Error updating tracker: ".$dbc->errorInfo()."</p>";
64+
die($error);
65+
}
66+
unset($sqlinsertyes);
67+
unset($sqlinsertno);
68+
unset($sqlresultyes);
69+
unset($sqlresultno);
70+
}
71+
72+
?>
73+
<h1>Tracker Reset Page for <?php echo $gamename; ?></h1>
74+
<div class="navigation">
75+
<form action="tracker.php" method="post">
76+
<p><input type="submit" class="submitbutton" name="submittoreset" value="Back to tracker" /></p>
77+
<input type="hidden" name="gamepk" value="<?php echo $gamepk; ?>">
78+
<input type="hidden" name="gamename" value="<?php echo $gamename; ?>">
79+
<input type="hidden" name="season" value="<?php echo $seasonselection; ?>">
80+
</form>
81+
</div> <!-- navigation -->
82+
83+
<form action="<?=$_SERVER['PHP_SELF']; ?>" method="post">
84+
<input type="hidden" name="gamepk" value="<?php echo $gamepk; ?>">
85+
<input type="hidden" name="gamename" value="<?php echo $gamename; ?>">
86+
<input type="hidden" name="season" value="<?php echo $seasonselection; ?>">
87+
88+
<div class="trackablesresetcontainer">
89+
<h3>Marked as done</h3>
90+
<table class="resettable">
91+
<tr><th>Trackable</th><th>Done?</th></tr>
92+
93+
<?php
94+
95+
$sqlselect = "select i1.item_name as name, t1.made, t1.pk from ".$gametable." t1 left join items i1 on i1.item_id=t1.trackable_id where t1.made=1 order by i1.item_name";
96+
97+
$sqlresult = $pdo->query($sqlselect);
98+
if (!$sqlresult)
99+
{
100+
die("Error loading trackables: " . $dbc->errorInfo());
101+
}
102+
unset($sqlselect);
103+
104+
while ($row = $sqlresult->fetch())
105+
{
106+
$nameurl = $row['name'];
107+
$nameurl = str_replace(' ', '_', $row['name']);
108+
109+
echo "<tr class=\"alternatingcolours\">\n";
110+
echo "<td class=\"item\"><a target=\"_blank\" class=\"itemlink\" href=\"https://stardewvalleywiki.com/".$nameurl."\">".$row['name']."</a></td>\n";
111+
switch ($row['made'])
112+
{
113+
case true:
114+
$checkno = "";
115+
$checkyes =" checked=\"checked\"";
116+
break;
117+
case false:
118+
$checkyes = "";
119+
$checkno = " checked=\"checked\"";
120+
break;
121+
}
122+
123+
echo "<td class=\"item\">";
124+
echo "<input type=\"radio\" name=\"".$row['pk']."\" id=\"yes".$row['pk']."\" value=\"yes\"".$checkyes.">";
125+
echo "<label class=\"radiolabel\" for=\"yes".$row['pk']."\">Yes</label>";
126+
echo "&nbsp;";
127+
echo "<input type=\"radio\" name=\"".$row['pk']."\" id=\"no".$row['pk']."\" value=\"no\"".$checkno.">";
128+
echo "<label class=\"radiolabel\" for=\"no".$row['pk']."\">No</label>";
129+
echo "</td>";
130+
echo "</tr>\n";
131+
}
132+
?>
133+
134+
</table>
135+
</div> <!-- trackablesresetcontainer -->
136+
137+
<div class="trackablesresetcontainer">
138+
<h3>Not marked as done</h3>
139+
<table class="resettable">
140+
<tr><th>Trackable</th><th>Done?</th></tr>
141+
142+
<?php
143+
144+
$sqlselect = "select i1.item_name as name, t1.made, t1.pk from ".$gametable." t1 left join items i1 on i1.item_id=t1.trackable_id where t1.made=0 order by i1.item_name";
145+
146+
$sqlresult = $pdo->query($sqlselect);
147+
if (!$sqlresult)
148+
{
149+
die("Error loading trackables: " . $dbc->errorInfo());
150+
}
151+
unset($sqlselect);
152+
153+
while ($row = $sqlresult->fetch())
154+
{
155+
$nameurl = $row['name'];
156+
$nameurl = str_replace(' ', '_', $row['name']);
157+
158+
echo "<tr class=\"alternatingcolours\">\n";
159+
echo "<td class=\"item\"><a target=\"_blank\" class=\"itemlink\" href=\"https://stardewvalleywiki.com/".$nameurl."\">".$row['name']."</a></td>\n";
160+
switch ($row['made'])
161+
{
162+
case true:
163+
$checkno = "";
164+
$checkyes =" checked=\"checked\"";
165+
break;
166+
case false:
167+
$checkyes = "";
168+
$checkno = " checked=\"checked\"";
169+
break;
170+
}
171+
172+
echo "<td class=\"item\">";
173+
echo "<input type=\"radio\" name=\"".$row['pk']."\" id=\"yes".$row['pk']."\" value=\"yes\"".$checkyes.">";
174+
echo "<label class=\"radiolabel\" for=\"yes".$row['pk']."\">Yes</label>";
175+
echo "&nbsp;";
176+
echo "<input type=\"radio\" name=\"".$row['pk']."\" id=\"no".$row['pk']."\" value=\"no\"".$checkno.">";
177+
echo "<label class=\"radiolabel\" for=\"no".$row['pk']."\">No</label>";
178+
echo "</td>";
179+
echo "</tr>\n";
180+
}
181+
?>
182+
183+
</table>
184+
</div> <!-- trackablesresetcontainer -->
185+
<p><input type="submit" name="submitted" value="Submit Changes" /></p>
186+
</form>
187+
188+
</body>
189+
</html>
190+
191+
<?php
192+
unset($sqlresult);
193+
unset($row);
194+
unset($nameurl);
195+
unset($checkyes);
196+
unset($checkno);
197+
unset($gametable);
198+
$dbc=null;
199+
?>

‎tracker.php

+382
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,382 @@
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

Comments
 (0)
Please sign in to comment.