forked from michael-dev/polling-station
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauszaehlungadmin.html
More file actions
265 lines (254 loc) · 10.8 KB
/
auszaehlungadmin.html
File metadata and controls
265 lines (254 loc) · 10.8 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<html>
<head>
<title>Administration Stimmauszählung</title>
<link type="text/css" href="css/smoothness/jquery-ui-1.8.12.custom.css" rel="stylesheet" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.12.custom.min.js"></script>
<script type="text/javascript" src="js/jquery.timers-1.2.js"></script>
<script type="text/javascript">
$(function() {
$( "#tabs" ).tabs({
show: function (event, ui) {
if (ui.panel.id == "Wahlen") {
loadWahl();
}
if (ui.panel.id == "Stapel") {
loadStapel();
}
if (ui.panel.id == "Ergebnis") {
loadErgebnis();
}
}
});
checkAuth();
$(document).everyTime("10s", function() { checkAuth(); });
});
/* header */
function checkAuth() {
$.post("action/checkauth.php").success(function(r) {
$('#loginbar').text('Sie sind als ' + r + ' authentifiziert.');
$('#loginbar').append(' <a href="./action/relogin.php?nouser=' + escape(r) + '">Logout</a>');
} ).error(function() {
$('#loginbar').text('Sie sind nicht authentifiziert.');
});
}
/* Wahlen */
function loadWahl() {
wahlId = $('#mgmWahlSelect').val();
$('.wahlSelect option').remove();
$('#mgmWahlSelect').append(new Option('Neue Wahl','-1',true,true));
$('#stapelWahlSelect').append(new Option('alle','-1',true,true));
$('#ergWahlSelect').append(new Option('** Bitte auswählen **','-1',false,false));
$.post("action/wahl.php", {}, function(r, textStatus, jqXHR) {
jQuery.each(r, function(i, val) {
$('.wahlSelect').each( function(j, element) {
$(element).append(new Option(val.name, val.id,false,false));
});
});
$('#mgmWahlSelect').val(wahlId);
selectWahl('mgmWahlSelect');
}).error(function(r) { alert("Die Wahlen konnten nicht geladen werden.\n"+r.responseText); });
}
var suppressSelectWahlRecursion = false;
function selectWahl(elementId) {
if (suppressSelectWahlRecursion) return;
suppressSelectWahlRecursion = true;
var wahlId = $('#'+elementId).val();
$('.wahlSelect').each(function(i, element) {
$(element).val(wahlId);
});
$('#wahlName').val($('#mgmWahlSelect option:selected').text());
loadKandidat(wahlId, '#WahlenKandidaten');
loadErgKandidat(wahlId, '#ErgWahlenKandidaten');
suppressSelectWahlRecursion = false;
}
function loadKandidat(wahlId, base) {
$(base + ' .Kandidat').remove();
$.post("action/kandidat.php", {wahl: wahlId}, function(r, textStatus, jqXHR) {
jQuery.each(r, function(i, val) {
var elem = $('<tr/>');
elem.attr("class","Kandidat");
elem.appendTo($(base));
var elem2 = $('<input type="text">');
elem2.attr("name","name[]");
elem2.attr("value",val.name);
$('<td/>').append(elem2).appendTo(elem);
var elem3 = $('<input type="text">');
elem3.attr("name","kid[]");
elem3.attr("value",val.kid);
$('<td/>').append(elem3).appendTo(elem);
});
appendNewKandidat();
}).error(function(r) { alert("Die Kandidaten konnten nicht geladen werden.\n"+r.responseText); });
}
function appendNewKandidat() {
$('#WahlenKandidaten').append('<tr class="Kandidat"><td><input name="name[]" onFocus="appendNewKandidat(); $(this).removeAttr(\'onFocus\');"></td><td><input name="kid[]"></td></tr>');
}
function saveWahl() {
var kandidatenName = Array();
var kandidatenKid = Array();
var data = new FormData();
var useUpload = false;
if (document.getElementById('kandidatfile').files.length > 0) {
useUpload = confirm("Sollen wirklich die Daten aus der Datei verwendet werden?");
}
if (useUpload) {
data.append( 'file' , document.getElementById('kandidatfile').files[0] );
} else {
jQuery.each($('#WahlenKandidaten .Kandidat'), function(i, elem) {
var name = $(elem).find('input[name="name[]"]').val();
var kid = $(elem).find('input[name="kid[]"]').val();
if (name != "") {
data.append( 'kandidatenName[]', name);
data.append( 'kandidatenKid[]', kid);
}
});
}
data.append('wahl', $('#mgmWahlSelect').val());
data.append('name', $('#wahlName').val());
$.ajax({
url: 'action/savewahl.php',
data: data,
cache: false,
contentType: false,
processData: false,
type: 'POST'
}).success(function() {
alert("Die Wahl wurde erfolgreich gespeichert.");
loadWahl();
}).error(function(r) { alert("Die Wahl konnte nicht gespeichert werden.\n"+r.responseText); });
}
function deleteWahl() {
var id = $('#mgmWahlSelect').val();
if (id == "" || id == -1) {
alert("Nur gespeicherte Wahlen können gelöscht werden.");
return;
}
$.post("action/deletewahl.php", {wahl: id}, function(r, textStatus, jqXHR) {
alert("Die Wahl wurde erfolgreich gelöscht.");
loadWahl();
}).error(function(r) { alert("Die Wahl konnte nicht gelöscht werden.\n"+r.responseText); });
}
/* Stapel */
function loadStapel() {
$('#stapelTable tr.dataRow').remove();
$.post("action/allstapel.php", {wahlId: $('#stapelWahlSelect').val(), filter:$('#filterMaxVerify').val()}, function(r, textStatus, jqXHR) {
jQuery.each(r, function(i, val) {
if (parseInt(val.numBallot) == 0) {
val.minVerify = "n/a";
}
$('#stapelTable tr:last').after('<tr class="dataRow" onClick="handleStapel('+val.wahl+','+val.id+','+val.numVotes+');"><td>'+val.wahlname+'</td><td>'+val.wahl+"/"+val.id+'</td><td>'+val.numVotes+'</td><td>'+val.numBallot+'</td><td>'+val.minVerify+'</td><td>'+val.todoBallot+'</td><td>'+val.doneBallot+'</td></tr>');
});
if (r.length == 0) {
alert("Es liegen keine Stapel vor.");
}
}).error(function(r) { alert("Die Stapel konnten nicht geladen werden.\n"+r.responseText); });
loadWahl();
}
function handleStapel(wahl, id, numVotes) {
if (confirm("Stapel "+wahl+"/"+id+" löschen?")) {
$.post("action/deletestapel.php", {wahl: wahl, id: id}).success(function() {
alert("Der Stapel wurde gelöscht.");
loadStapel();
}).error(function(r) {
alert("Der Stapel konnte nicht entfernt werden.\n"+r.responseText);
});
} else {
var newNumVotes = prompt("Geben sie bitte die neue Stimmanzahl für Stapel "+wahl+"/"+id+" ein.", numVotes);
if (newNumVotes != null) {
$.post("action/updatestapel.php", {wahl: wahl, id: id, numVotes: newNumVotes}).success(function() {
alert("Der Stapel wurde aktualisiert.");
loadStapel();
}).error(function(r) {
alert("Der Stapel konnte nicht aktualisiert werden.\n"+r.responseText);
});
}
}
}
/* Ergebnis */
function loadErgebnis() {
loadWahl();
}
function loadErgKandidat(wahlId, base) {
$(base+' tr.dataRow').remove();
$.post("action/statwahl.php", {wahl: wahlId}, function(r, textStatus, jqXHR) {
jQuery.each(r, function(i, val) {
$(base+' tr:last').after('<tr class="dataRow"><td>'+val.kandidatname+'</td><td>'+val.numVotes+'</td></tr>');
});
}).error(function(r) { alert("Die Ergebnisse konnten nicht geladen werden.\n"+r.responseText); });
}
function ergWahlPDF() {
var wahlId = $('#ergWahlSelect').val();
self.location.href="action/statwahlpdf.php?wahl="+wahlId+"&nonce="+(new Date()).getTime();
}
function ergWahlDownload() {
var wahlId = $('#ergWahlSelect').val();
self.location.href="action/statwahldownload.php?wahl="+wahlId+"&nonce="+(new Date()).getTime();
}
/* Nutzerverwaltung */
function saveUser() {
var data = {name: $('#username').val(),
pass: $('#password').val()};
$.post("action/nutzeranlegenauszaehlung.php",data).success(function() { alert("Der Nutzer "+$('#username').val()+" wurde erstellt."); $('#username').val(""); $('#password').val("");}).error(function(r) { alert("Der Nutzer wurde nicht angelegt.\n"+r.responseText); });
}
</script>
<style type="text/css">
#tabs > div { min-height: 600px; }
#stapelTable { text-align: center; }
#stapelTable tr:nth-child(odd) { background-color:#eee; }
#stapelTable tr:nth-child(even) { background-color:#fff; }
#stapelTable tr:hover { background-color:#ccc; }
</style>
</head>
<body>
<div id="loginbar"> </div>
<div id="tabs">
<ul>
<li><a href="#Benutzer"><span>Wahlhelfer anlegen</span></a></li>
<li><a href="#Wahlen"><span>Wahlen verwalten</span></a></li>
<li><a href="#Stapel"><span>Stapel verwalten</span></a></li>
<li><a href="#Ergebnis"><span>Wahlergebnis anzeigen</span></a></li>
</ul>
<div id="Benutzer">
<table border="0" style="width: 100%;">
<tr>
<th>Name</th>
<td><input type="text" name="name" id="username"/></td>
</tr>
<tr>
<th>Passwort</th>
<td><input type="password" name="password" id="password"/></td>
</tr>
<tr>
<td colspan="2"><button type="button" onClick="saveUser();" accesskey="s"><u>S</u>peichern</button></td>
</tr>
</table>
</div>
<div id="Wahlen">
<form onSubmit="return false;"><select id="mgmWahlSelect" class="wahlSelect" onChange="selectWahl('mgmWahlSelect');"></select> <input type="text" name="wahlname" id="wahlName"/></form>
<table id="WahlenKandidaten">
<tr><th>Name</th><th>KID</th></tr>
</table>
<div><label for="file">Kandidatenliste ersetzen durch Upload:</label><input id="kandidatfile" type="file" name="file"> (GZIP-komprimierte CSV Datei mit Kopfzeile und (kid,name))</div>
<button onClick="saveWahl();">Speichern</button> <button onClick="deleteWahl();">Löschen</button>
</div>
<div id="Stapel">
<form onSubmit="return false;">
<button onClick="loadStapel()">Stapel neuladen</button>
Filter: Wahl = <select id="stapelWahlSelect" class="wahlSelect" onChange="selectWahl('stapelWahlSelect');"></select>, Überprüfungen ≤<input type="text" name="filterMaxVerify" id="filterMaxVerify" value="-1" style="width: 50px;" title="-1 für beliebig"/>
</form>
<table border="0" id="stapelTable">
<tr><th>Wahl</th><th>Stapel-Nr</th><th>Anzahl der Stimmen<br/>(SOLL je Zettel)</th><th>Anzahl der Stimmzettel</th><th>Anzahl der Überprüfungen</th><th>Zahl der zu prüfenden Stimmzettel</th><th>Zahl der fertig geprüften Stimmzettel</th></tr>
</table>
</div>
<div id="Ergebnis">
<form onSubmit="return false;"><select id="ergWahlSelect" class="wahlSelect" onChange="selectWahl('ergWahlSelect');"></select></form>
<table id="ErgWahlenKandidaten" border="0">
<tr><th>Kandidat</th><th>Anzahl der Stimmen</th></tr>
</table>
<button onClick="ergWahlPDF();">PDF</button>
<button onClick="ergWahlDownload();">Export für Wahlenwebseite</button>
</div>
</body>
</html>