-
Notifications
You must be signed in to change notification settings - Fork 0
/
send.php
149 lines (124 loc) · 7.01 KB
/
send.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
<?php
if (isset($_GET["event"], $_POST)) {
verify_and_exit_csrf_form_token($_POST["csrf_token"], "event_registration");
$template_data_events = array("errors" => []);
$max_event_participants = $db->get_max_participants($_GET["event"]);
$event_participants = $db->get_participants($_GET["event"]);
$registered_participants = 1; // TODO Möglichkeit für mehrere Anmeldungen implementieren.
if ($event_participants >= $max_event_participants) {
array_push($template_data_events["errors"], array("msg" => "Es gibt für diese Veranstaltung keine freien Anmeldeplätze mehr."));
}
$db_data = array(
"nachname" => htmlspecialchars($_POST["lastname"]),
"vorname" => htmlspecialchars($_POST["firstname"]),
"strasse" => htmlspecialchars($_POST["street"] . " " . $_POST["house_nr"]),
"ort" => htmlspecialchars($_POST["postal_code"] . " " . $_POST["city"]),
"email" => htmlspecialchars($_POST["email"]),
"telefon" => htmlspecialchars($_POST["phone"]),
"anzahl" => htmlspecialchars($registered_participants),
"zeitfensterID" => htmlspecialchars($_POST["selected_timewindow"]),
"anmeldestation" => null,
);
$query_event_timewindows = $db->get_timewindows($_GET["event"]);
$ids_event_timewindows = $query_event_timewindows->fetchAll(PDO::FETCH_COLUMN, 0);
$already_registered_data = array(
"event_ids" => implode(",", $ids_event_timewindows),
"nachname" => $db_data["nachname"],
"vorname" => $db_data["vorname"],
"ort" => $db_data["ort"],
"strasse" => $db_data["strasse"],
);
$sql_already_registered = "SELECT id FROM teilnehmer WHERE vorname = :vorname AND nachname = :nachname AND strasse = :strasse AND ort = :ort AND FIND_IN_SET(zeitfensterID, :event_ids)";
$query_already_registered = $db->query($sql_already_registered, $already_registered_data);
if ($query_already_registered->rowCount() > 0) {
array_push($template_data_events["errors"], array("msg" => "Sie haben sich bereits für diese Veranstaltung registriert."));
}
$data_event = get_event_data($_GET["event"], $db);
if (isset($data_event["error"]) and $data_event["error"] === "closed") {
$template_data_events["errors"] = [];
array_push($template_data_events["errors"], array("msg" => "Das Anmeldefenster für diese Veranstaltung ist geschlossen."));
}
if (!($template_data_events["errors"] === [])) {
$_SESSION["messages"] = add_type_to_msgs($template_data_events["errors"], "danger");
redirect(".");
}
$captcha = htmlspecialchars($_POST["captcha"]);
$template_data_event = array("errors" => []);
if (!(isset($_POST["captcha"]) and $captcha == $_SESSION['digit'])) {
$template_data_event["errors"]["captcha"] = "wrong";
}
$post_keys = ["selected_day", "selected_timewindow", "lastname", "firstname", "email", "street", "house_nr", "postal_code", "city", "phone"];
$template_data_event["errors"] = array_merge($template_data_event["errors"], check_if_empty($_POST, $post_keys));
if (isset($_POST["selected_day"], $_POST["selected_timewindow"])) {
$sql_timewindow_count = "SELECT COUNT(zeitfensterID) FROM zeitfenster WHERE tagID = ? AND zeitfensterID = ?";
$query_timewindow_count = $db->query($sql_timewindow_count, array($_POST["selected_day"], $_POST["selected_timewindow"]));
if ($query_timewindow_count->rowCount() === 0 or ((int) $query_timewindow_count->fetch()[0]) !== 1) {
$template_data_event["errors"]["selected_day"] = "wrong_window";
$template_data_event["errors"]["selected_timewindow"] = "wrong_window";
} else {
$timewindow_max_participants = $db->get_max_participants(null, array($_POST["selected_timewindow"]));
$timewindow_participants = $db->get_participants(null, array($_POST["selected_timewindow"]));
if ($timewindow_participants >= $timewindow_max_participants) {
$template_data_event["errors"]["selected_timewindow"] = "already_full";
} elseif ($timewindow_participants + $registered_participants > $timewindow_max_participants) {
$template_data_event["errors"]["selected_timewindow"] = "too_many_registered";
}
}
}
if (isset($_POST["email"])) {
if (!(filter_var($_POST["email"], FILTER_VALIDATE_EMAIL))) {
$template_data_event["errors"]["email"] = "invalid";
}
}
if (!($template_data_event["errors"] === [])) {
foreach ($post_keys as $key) {
if (isset($_POST[$key])) {
$template_data_event["values"][$key] = htmlspecialchars($_POST[$key]);
}
}
$template_data_event = array_merge($template_data_event, $data_event);
echo render_registration($templates, $template_data_event);
exit;
}
// Code after validation
if (!empty($data_event["stations"])) {
try {
$sql_stations = "SELECT teilnehmer.Anmeldestation
FROM zeitfenster, teilnehmer, tage, veranstaltungen
WHERE zeitfenster.ZeitfensterID = ?
AND teilnehmer.ZeitfensterID = zeitfenster.ZeitfensterID
AND tage.tagID = zeitfenster.tagID
AND veranstaltungen.id = tage.veranstaltungsId
GROUP BY teilnehmer.Anmeldestation
ORDER BY COUNT(*) ASC";
$query_stations = $db->query($sql_stations, [$db_data["zeitfensterID"]]);
$data_stations = $query_stations->fetchAll(PDO::FETCH_COLUMN, 0);
$missing_stations = array_values(array_diff(range(1, (int) $data_event["stations"]), $data_stations));
if (count($missing_stations) == 0) {
$db_data["anmeldestation"] = $data_stations[0];
} else {
$db_data["anmeldestation"] = $missing_stations[0];
}
} catch (Exception $exception) {
exit_with_code(500);
}
}
// Insert Data into database
try {
$db->insert("teilnehmer", $db_data);
} catch (Exception $exception) {
$_SESSION["messages"] = add_type_to_msgs(["Es gab ein Problem mit ihren Angaben. Bitte melden sie sich bei " + CONFIG_DATA["mail"]["support_email"] + " falls dieses Problem weiterhin besteht."], "danger");
redirect(".");
}
// Send confirmation E-Mail
$participant_id = $db->mysql->lastInsertID();
include("inc/classes/Mailer.php");
$mailer = new Atlasfreak\Eventmanager\Mailer($db);
if (!$mailer->send_confirmation_mail($participant_id, $_GET["event"])) {
$_SESSION["messages"] = add_type_to_msgs(["Es gab ein Problem beim versenden der Bestätigungs E-Mail, ihre Daten wurden bereits gespeichert! Bitte melden sie sich bei " + CONFIG_DATA["mail"]["support_email"] + "."], "danger");
redirect(".");
}
$_SESSION["messages"] = add_type_to_msgs(["Die Anmeldung war erfolgreich. Sie sollten in kürze eine E-Mail erhalten. Schauen sie ggf. im Spamordner nach."], "success");
redirect(".");
}
?>