forked from sgezel/pronostiek
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
176 lines (135 loc) · 5.31 KB
/
admin.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
<?php
session_set_cookie_params(604800);
session_start();
if(!isset($_SESSION["data"]["admin"]) && $_SESSION["data"]["admin"]!=true)
header("location: /");
?>
<?php include("header.php"); ?>
<?php if ($logged_in): ?>
<!-- Page Content -->
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h1 class="mt-5">Pr(emed)onostiek Admin</h1>
<form method="post" action="saveadmin.php">
<table border=1 id="pronostiek">
<?php
$data = file_get_contents("data/data.json");
$json = json_decode($data, true);
?>
<?php foreach($json as $group): ?>
<tr>
<td colspan="6" class="header"><?= $group["naam"]; ?></td>
</tr>
<tr>
<td class="subheader">datum + tijd</td>
<td class="subheader" colspan=5>Score</td>
</tr>
<?php foreach($group["matches"] as $match): ?>
<?php
$thuis = $group["naam"].'_'.str_replace(" ", "_",$match['thuis']).'_' . str_replace(" ", "_",$match['uit']).'_t';
$uit = $group["naam"].'_'.str_replace(" ", "_",$match['thuis']).'_' . str_replace(" ", "_",$match['uit']).'_u';
$vlag_thuis = file_exists("vlaggen/" . $match["thuis"] . ".png") ? "vlaggen/" . $match["thuis"] . ".png" : "vlaggen/default.png";
$vlag_uit = file_exists("vlaggen/" . $match["uit"] . ".png") ? "vlaggen/" . $match["uit"] . ".png" : "vlaggen/default.png";
?>
<tr class="vraag">
<td> <?= $match["datum"]; ?></td>
<td class="nowrap"><?= $match["thuis"]; ?></td>
<td> <img class="" src="<?= $vlag_thuis; ?>"/></td>
<td class="nowrap">
<input type="number" name="<?= $thuis ?>" value="<?= $match["thuis_goals"]; ?>"/>
-
<input type="number" name="<?= $uit ?>" value="<?= $match["uit_goals"]; ?>"/>
</td>
<td> <img class="" src="<?= $vlag_uit; ?>"/></td>
<td class="nowrap"><?= $match["uit"]; ?> </td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
<tr>
<td colspan="6"><input type="submit" value="Opslaan" class="btn btn-success" /></td>
</tr>
</table>
<?php
$files = scandir('data/user/');
$vragen = [];
$bonusvragenjuist = [];
$contestants = "";
foreach($files as $file) {
if ($file !== "." && $file !== ".." && file_exists("data/user/" . $file))
{
$filename = "data/user/" . $file;
$userdata = json_decode(file_get_contents($filename), true);
$contestants .= str_replace(".json", ";",$file);
if(array_key_exists("vragen", $userdata))
{
$vragen[$userdata["name"]]["username"] = $userdata["username"];
foreach ($userdata["vragen"] as $vraag => $antwoord) {
$vragen[$userdata["name"]]["vragen"][$vraag] = $antwoord;
}
}
if(array_key_exists("bonus", $userdata))
{
foreach($userdata["bonus"] as $id => $punten)
{
$bonusvragenjuist[$userdata["username"]][$id] = true;
}
}
}
}
$data = file_get_contents("data/vragen.json");
$vraagdata = json_decode($data, true);
$vraagzinnen = [];
foreach($vraagdata as $vraaggroep)
{
foreach($vraaggroep["vragen"] as $vrdata)
{
$vraagzinnen["vraag_" .$vrdata["id"]] = $vrdata["Vraag"];
}
}
ksort($vragen);
?>
<table border=1>
<?php foreach($vragen as $user => $data): ?>
<tr>
<td class="header" colspan="3"><?= $user; ?></td>
</tr>
<tr>
<td class="subheader">Vraag</td>
<td class="subheader">Antwoord</td>
<td class="subheader">Correct?</td>
</tr>
<?php foreach($data["vragen"] as $vraagid => $antwoord): ?>
<tr>
<td><?= $vraagzinnen[$vraagid]; ?></td>
<td><?= $antwoord; ?></td>
<td><input type="checkbox" name="antwoorden[<?= $data["username"]; ?>][<?= $vraagid; ?>]" <?= isset($bonusvragenjuist[$data["username"]][$vraagid]) ? "checked" : "" ?> /></td>
</tr>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>
</form>
</div>
</div>
<div class="row">
<div class="col-lg-12 text-center">
<p class="wit">
<a href="mailto:<?= $contestants; ?>?subject=Pr(emed)onostiek Update" class="btn btn-warning">Alle deelnemers mailen</a>
</p>
</div>
</div>
<div class="row">
<div class="col-lg-12 text-center">
<form method="post" action="saveadmin.php">
<p class="wit">
<input type="submit" onclick="function(){ var ver = document.getElementById('verification'); return ver.value.toLowerCase() === "reset";}" value="Reset ALLE speler data" class="btn btn-danger" name="reset_all_data" />
Typ "reset" in het volgende vak: <input type="text" id="verification" name="verification" required />
</p>
</form>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php include("footer.php"); ?>