This repository was archived by the owner on May 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvote.php
More file actions
240 lines (219 loc) · 8.57 KB
/
Copy pathvote.php
File metadata and controls
240 lines (219 loc) · 8.57 KB
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('max_execution_time', 120);
error_reporting(E_ALL);
require './login.php';
require_once './assets/config.php';
if (empty($_SESSION['access_token'])) {
header('Location: error.php?eCode=auth_err&eDesc=Not Authenticated');
die();
} else if ($_SESSION['api_user']->hasMember === false) {
header('Location: error.php?eCode=no_role');
die();
}
echo "<script>console.log('User Info retrieved from Verifier API:')</script>";
echo "<script>console.log('" . json_encode($_SESSION['api_user']) . "')</script>";
echo "<script>console.log('User info retrieved from Discord OAuth2 grant:')</script>";
echo "<script>console.log('" . json_encode($_SESSION['oauth_user']) . "')</script>";
$psql = pg_connect("$db->host $db->port $db->name $db->credentials");
$already_voted = voteStatus($psql, $_SESSION['api_user']->id);
if (empty($already_voted)) {
echo "<script>console.log('User has not voted yet!');</script>";
} else {
header('Location: error.php?eCode=already_voted');
die();
}
if ($duedate < date('Y-m-d')) {
header('Location: error.php?eCode=concluded');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ASE | Rösta på representanter</title>
</head>
<body>
<div class="fullscreen-bg">
<video loop muted autoplay class="fullscreen-bg__video">
<source src="./assets/videos/background.mp4" type="video/mp4">
</video>
</div>
<div id="content">
<nav class="header">
<h1>Arma Sweden</h1>
</nav>
<section id="userinfo">
<div class="user-container">
<div class="userimg">
<img src="<?=$_SESSION['api_user']->avatar?>" alt="Din profilbild på Discord">
</div>
<div class="usercreds">
<h1 class="username"><?=$_SESSION['api_user']->user?></h1>
<p>Discord status: <?=$_SESSION['api_user']->presence?></p>
<p>Discord ID: <?=$_SESSION['api_user']->id?></p>
</div>
</div>
<div id="logout">
<a href="./login.php?action=logout" id="confirm-btn">Logga ut</a>
</div>
</section>
<section id="choices">
<h1>Rösta</h1>
<form action="sendVote.php" id="votes" method="post">
<p>Notera att fler val kan göras!<br><br></p>
<div id="nomineeList">
<?php
$ret = pg_query($psql, "SELECT COUNT(*), nominee FROM votes GROUP BY nominee;");
if (!$ret) {
header('Location: error.php?eCode=db_err&eStack='.pg_last_error($psql));
}
while ($row = pg_fetch_row($ret)) {
$nominee = apiRequest('http://verifier.obliv1on.space/v1/user/find/id/'. $row[1] . '/185178535059521537');
if ($row[0] > 1) {
$txt = "röster";
} else {
$txt = "röst";
}
echo "<input type='checkbox' id='{$row[1]}' name='{$row[1]}' value='{$row[1]}' class='toggle' onclick='checkVoteLimit(\"$row[1]\")'>";
if (empty($nominee->nickname)) {
echo "<label for='{$row[1]}' >{$nominee->username} ({$nominee->user})</label><br><br>";
} else {
echo "<label for='{$row[1]}' >{$nominee->nickname} ({$nominee->user})</label><br><br>";
}
}
?>
</div>
<p class="center"> Jag har dubbelkollat mina val</p>
<input type="checkbox" class="toggle toggle-center" id="confirm" onclick="showBtn()">
<input type="submit" id="voteSend" value="Skicka in" style="margin: 0 auto; display: none">
<br>
</form>
<div>
<p style="font-weight: bold">Saknas medlemmen du vill nominera?</p>
<p>Du kan lägga till en eller fler medlemmar i denna lista genom att föra in deras Discord-id i fältet nedan.<br><br></p>
<div class="add-nominee">
<input type="text" id="customId" name="customId" class="field" placeholder="Användar-id">
<button type="button" id="addNominee" onclick="addNominee()">Lägg till</button>
</div>
<p><a href="https://www.youtube.com/watch?v=1T0L4c9hWTo" target="_blank">Mer information om hur du kan få ut användar-id</a></p><br><br>
</div>
</section>
<nav class="footer">
<p>Denna sida har skapats för <a href="https://armasweden.se">Arma Sweden</a></p>
</nav>
</div>
</body>
</html>
<script>
var nomineesChecked = 0;
var nomineeLimit = 3;
var currentL = [
'231144147291996161',
'213279544927322112',
'157628163365666816',
'0'
];
function showBtn() {
var cb = document.getElementById('confirm');
var btn = document.getElementById('voteSend');
if (cb.checked == true) {
btn.style.display = "block";
} else {
btn.style.display = "none";
}
}
function addNominee() {
var btn = document.getElementById('addNominee');
var idField = document.getElementById('customId');
var nl = document.getElementById('nomineeList');
var check = document.getElementById(idField.value);
console.log(nl);
console.log(idField.value);
if (idField.value == "" || idField.value == null) {
alert('Fältet för att lägga till fler medlemmar kan ej vara tomt!');
return
} else if (check) {
alert('Medlemmen finns redan i listan!');
idField.value = "";
return;
} else if (idField.value == currentL[0] || idField.value == currentL[1] || idField.value == currentL[2] || idField.value == currentL[3]) {
alert('Du kan ej rösta på medlemmar som redan är en del av ledningen!');
idField.value = "";
return;
} else if (idField.value == "<?=$_SESSION['api_user']->id?>") {
alert('Du kan ej rösta på dig själv!');
idField.value = "";
return;
}
if (nomineesChecked >= nomineeLimit) {
alert('du får ej lägga till eller rösta på mer än tre nya kandidater.');
idField.value = "";
return;
}
fetch('http://verifier.obliv1on.space/v1/user/find/id/' + idField.value + '/185178535059521537')
.then(response => response.json())
.then(userObj => {
if (userObj.error == null || userObj.error == undefined) {
let name = "";
if (userObj.nickname == null || userObj.nickname == undefined) {
name = userObj.username;
} else {
name = userObj.nickname;
}
if (confirm(`Vill du verkligen lägga till ${name} (${userObj.user})? \nMedlemmen kommer ej att stanna kvar i listan om du ej röstar på dem.`)) {
console.log('confirmed!')
let inp = document.createElement('input');
inp.type = 'checkbox';
inp.id = userObj.id;
inp.name = userObj.id;
inp.value = userObj.id;
inp.className = 'toggle';
let lbl = document.createElement('label');
lbl.for = userObj.id;
lbl.innerHTML = `${name} (${userObj.user})`;
inp.checked = true;
// inp.addEventListener('click', checkVoteLimit(userObj.id));
nl.appendChild(inp);
nl.appendChild(lbl);
nl.appendChild(document.createElement('br'));
nl.appendChild(document.createElement('br'));
nomineesChecked++;
document.getElementById(idField.value).setAttribute('onclick', `checkVoteLimit("${idField.value}")`);
idField.value = "";
} else {
idField.value = "";
}
}
}).catch(error => {
console.log(error);
alert(`Användare med ID "${idField.value}" kunde ej hittas`);
})
}
function checkVoteLimit(id) {
console.log(`checking status of checkbox (${id})`);
console.log(`Current checked: ${nomineesChecked}, limit: ${nomineeLimit}`)
let cbox = document.getElementById(id);
if (cbox.checked) {
console.log('is checked');
if (nomineesChecked >= nomineeLimit) {
alert("Maximalt antal röster (" + nomineeLimit + ") har redan uppnåtts.");
console.log('MaxNomineesChecked');
cbox.checked = false;
} else {
console.log('up counter');
nomineesChecked++;
console.log(`now checked: ${nomineesChecked}`)
}
} else {
console.log('is unchecked');
console.log(`down counter`);
nomineesChecked--;
console.log(`now checked: ${nomineesChecked}`)
}
}
</script>
<link rel="stylesheet" href="./assets/css/style.css">