-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset.php
199 lines (171 loc) · 5.44 KB
/
reset.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Perfection Tracker Reset</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<?php
include "config.php";
$yesvalues=null;
$novalues=null;
$gamepk = $_POST['gamepk'];
$gamename = $_POST['gamename'];
$seasonselection = $_POST['season'];
$gametable = "gamedata".$gamepk.$gamename;
if (!($gamepk || $gamename || $seasonselection))
{
echo "<p>Game meta data did not load properly.</p><p class=\"navlink\"><a href=\"index.php\">Try again?</a></p>";
die();
}
if (isset($_POST['submitted'])) //with submitted updates
{
unset($_POST['submitted']);
foreach($_POST as $key => $value) //build the sql "IN" lists, one each for yes and no
{
switch ($value)
{
case "yes":
$yesvalues = $yesvalues.$key.", ";
break;
case "no":
$novalues = $novalues.$key.", ";
break;
}
}
$yesvalues = rtrim($yesvalues, ', ');
$novalues = rtrim($novalues, ', ');
//prime the sqlresult vars so the error check will pass
$sqlresultyes = 1;
$sqlresultno = 1;
if ($yesvalues)
{
$sqlinsertyes = "update ".$gametable." set made=1 where pk in (".$yesvalues.")";
$sqlresultyes = $pdo->query($sqlinsertyes);
}
if ($novalues)
{
$sqlinsertno = "update ".$gametable." set made=0 where pk in (".$novalues.")";
$sqlresultno = $pdo->query($sqlinsertno);
}
unset($yesvalues);
unset($novalues);
if (!$sqlresultyes OR !$sqlresultno)
{
$error = "<p>Error updating tracker: ".$dbc->errorInfo()."</p>";
die($error);
}
unset($sqlinsertyes);
unset($sqlinsertno);
unset($sqlresultyes);
unset($sqlresultno);
}
?>
<h1>Tracker Reset Page for <?php echo $gamename; ?></h1>
<div class="navigation">
<form action="tracker.php" method="post">
<p><input type="submit" class="submitbutton" name="submittoreset" value="Back to tracker" /></p>
<input type="hidden" name="gamepk" value="<?php echo $gamepk; ?>">
<input type="hidden" name="gamename" value="<?php echo $gamename; ?>">
<input type="hidden" name="season" value="<?php echo $seasonselection; ?>">
</form>
</div> <!-- navigation -->
<form action="<?=$_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="gamepk" value="<?php echo $gamepk; ?>">
<input type="hidden" name="gamename" value="<?php echo $gamename; ?>">
<input type="hidden" name="season" value="<?php echo $seasonselection; ?>">
<div class="trackablesresetcontainer">
<h3>Marked as done</h3>
<table class="resettable">
<tr><th>Trackable</th><th>Done?</th></tr>
<?php
$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";
$sqlresult = $pdo->query($sqlselect);
if (!$sqlresult)
{
die("Error loading trackables: " . $dbc->errorInfo());
}
unset($sqlselect);
while ($row = $sqlresult->fetch())
{
$nameurl = $row['name'];
$nameurl = str_replace(' ', '_', $row['name']);
echo "<tr class=\"alternatingcolours\">\n";
echo "<td class=\"item\"><a target=\"_blank\" class=\"itemlink\" href=\"https://stardewvalleywiki.com/".$nameurl."\">".$row['name']."</a></td>\n";
switch ($row['made'])
{
case true:
$checkno = "";
$checkyes =" checked=\"checked\"";
break;
case false:
$checkyes = "";
$checkno = " checked=\"checked\"";
break;
}
echo "<td class=\"item\">";
echo "<input type=\"radio\" name=\"".$row['pk']."\" id=\"yes".$row['pk']."\" value=\"yes\"".$checkyes.">";
echo "<label class=\"radiolabel\" for=\"yes".$row['pk']."\">Yes</label>";
echo " ";
echo "<input type=\"radio\" name=\"".$row['pk']."\" id=\"no".$row['pk']."\" value=\"no\"".$checkno.">";
echo "<label class=\"radiolabel\" for=\"no".$row['pk']."\">No</label>";
echo "</td>";
echo "</tr>\n";
}
?>
</table>
</div> <!-- trackablesresetcontainer -->
<div class="trackablesresetcontainer">
<h3>Not marked as done</h3>
<table class="resettable">
<tr><th>Trackable</th><th>Done?</th></tr>
<?php
$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";
$sqlresult = $pdo->query($sqlselect);
if (!$sqlresult)
{
die("Error loading trackables: " . $dbc->errorInfo());
}
unset($sqlselect);
while ($row = $sqlresult->fetch())
{
$nameurl = $row['name'];
$nameurl = str_replace(' ', '_', $row['name']);
echo "<tr class=\"alternatingcolours\">\n";
echo "<td class=\"item\"><a target=\"_blank\" class=\"itemlink\" href=\"https://stardewvalleywiki.com/".$nameurl."\">".$row['name']."</a></td>\n";
switch ($row['made'])
{
case true:
$checkno = "";
$checkyes =" checked=\"checked\"";
break;
case false:
$checkyes = "";
$checkno = " checked=\"checked\"";
break;
}
echo "<td class=\"item\">";
echo "<input type=\"radio\" name=\"".$row['pk']."\" id=\"yes".$row['pk']."\" value=\"yes\"".$checkyes.">";
echo "<label class=\"radiolabel\" for=\"yes".$row['pk']."\">Yes</label>";
echo " ";
echo "<input type=\"radio\" name=\"".$row['pk']."\" id=\"no".$row['pk']."\" value=\"no\"".$checkno.">";
echo "<label class=\"radiolabel\" for=\"no".$row['pk']."\">No</label>";
echo "</td>";
echo "</tr>\n";
}
?>
</table>
</div> <!-- trackablesresetcontainer -->
<p><input type="submit" name="submitted" value="Submit Changes" /></p>
</form>
</body>
</html>
<?php
unset($sqlresult);
unset($row);
unset($nameurl);
unset($checkyes);
unset($checkno);
unset($gametable);
$dbc=null;
?>