-
Notifications
You must be signed in to change notification settings - Fork 0
/
wahl.php
201 lines (175 loc) · 6.69 KB
/
wahl.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
200
201
<?php
/**
* Project: WeidigWahl
* Author: AlexanderKaschta
* License: MIT License
*/
include_once "core/config.php";
require "core/Database.php";
session_start();
$pageTitle = "Wahl";
if (isset($_SESSION['loggedin']) && isset($_GET['id']) && isset($_GET['nr']) && is_int((int)$_GET['id']) && is_int((int)$_GET['nr'])){
if ($_SESSION['loggedin'] == 1 && isset($_SESSION['benutzer'])){
$db = new Database();
$pdo = $db->connect();
if (is_null($pdo)){
session_destroy();
header("Location: index.php?errorCode=1 ");
exit();
}
//Kontrolliere ob der Nutzer an der Wahl teilnehmen darf
$check = $pdo->prepare("SELECT * FROM tbl_teilnehmer WHERE wahl_id = :wahl AND benutzer = :id;");
$check->bindParam(":wahl", $_GET['id']);
$check->bindParam(":id", $_SESSION['id']);
$check->execute();
$check_row = $check->rowCount();
if ($check_row != 1){
header("Location: main.php?errorCode=1 ");
exit();
}
$check2 = $pdo->prepare("SELECT * FROM tbl_sportwahl WHERE id = :id AND ist_aktiv=1;");
$check2->bindParam(":id", $_GET['id']);
$check2->execute();
$check2_rows = $check2->rowCount();
if ($check2_rows != 1){
header("Location: main.php?errorCode=1 ");
exit();
}
$check2_row =$check2->fetch();
if ($check2_row['ist_aktiv'] == 0){
header("Location: main.php?errorCode=1 ");
exit();
}
//Besorge das aktuelle Datum
try {
$aktuell = new DateTime(date('Y-m-d'));
$date2 = new DateTime($check2_row['datum_ende']);
} catch (Exception $e) {
session_destroy();
header("Location: index.php?errorCode=1 ");
exit();
}
//Wenn date2 kleiner als aktuell ist,
if ($date2 < $aktuell){
//dann ist die Wahl abgelaufen
header("Location: main.php?errorCode=4 ");
exit();
}
} else{
session_destroy();
header("Location: index.php?errorCode=1 ");
exit();
}
} else{
session_destroy();
header("Location: index.php?errorCode=1 ");
exit();
}
?>
<!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, shrink-to-fit=no">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/dashboard.css">
<link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png">
<meta name="theme-color" content="#212529">
<title><?php echo PROJECT_NAME . " | " . $pageTitle; ?></title>
</head>
<body class="d-flex flex-column min-vh-100">
<header>
<div class="navbar navbar-dark bg-dark shadow-sm">
<div class="container d-flex justify-content-between">
<a href="main.php" class="navbar-brand d-flex align-items-center">
<strong><?php echo PROJECT_NAME;?></strong>
</a>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</header>
<div class="container">
<?php
if (isset($_GET['errorCode'])) {
$errorMessage = htmlspecialchars($_GET['errorCode']);
if ($errorMessage == 1) {
$errorMessage = '<div class="alert alert-danger alert-dismissible">
<button type="button" class="close" data-dismiss="alert">×</button>
Eingabe konnten nicht gespeichert werden.
</div>';
echo $errorMessage;
} else if($errorMessage == 2){
$errorMessage = '<div class="alert alert-success alert-dismissible">
<button type="button" class="close" data-dismiss="alert">×</button>
Eingabe wurde erfolgreich gespeichert.
</div>';
echo $errorMessage;
}
}
?>
<h1 class="title_style">Wähle deine Kurse</h1>
<h2><?php echo $_GET['nr'].". Stimme"; ?></h2>
<form method="post" action="core/insert_wahl.php?<?php echo "id=".$_GET['id']."&nr=".$_GET['nr']; ?>" class="login-form">
<div class="form-group">
<label for="kurs">Kurs:</label>
<select id="kurs" name="kurs" class="form-control" required>
<option value="-1">Bitte wählen...</option>
<?php
$kurs_query = $pdo->prepare("SELECT * FROM tbl_kurse WHERE sportwahl=:id; ");
$kurs_query->bindParam(":id", $_GET['id']);
$kurs_query->execute();
$kursanzahl = $kurs_query->rowCount();
if ($kursanzahl == 0){
header("Location: main.php?errorCode=1 ");
exit();
} else{
while ($kurs_row = $kurs_query->fetch()){
echo '<option value="'.$kurs_row["id"].'">'.$kurs_row['name'].'</option>';
}
}
?>
</select>
</div>
<?php
$sportwahl_query = $pdo->prepare("SELECT * FROM tbl_sportwahl WHERE id = :id;");
$sportwahl_query->bindParam(":id", $_GET['id']);
$sportwahl_query->execute();
$sportwahl_lines = $sportwahl_query->rowCount();
if ($sportwahl_lines != 1){
session_destroy();
header("Location: index.php?errorCode=1 ");
exit();
} else{
$sportwahl_row = $sportwahl_query->fetch();
$angaben_anzahl = $sportwahl_row['anzahl_wahl'];
if ((int)$_GET['nr'] == $angaben_anzahl){
echo '<input type="submit" value="Fertigstellen" name="submit" class="btn btn-primary">';
} else if ((int)$_GET['nr'] < $angaben_anzahl){
echo '<input type="submit" value="Weiter" name="submit" class="btn btn-primary">';
} else{
//Throw an error
session_destroy();
header("Location: index.php?errorCode=1 ");
exit();
}
}
?>
</form>
</div>
<div class="mt-auto">
<?php include "core/include/footer.php"; ?>
</div>
<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="js/popper.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript">
$('.alert').alert()
</script>
</body>
</html>