-
-Kaffeeliste";
- echo "Hallo " . getUserName($conn,$mailadress) . "!
";
-
-
-// Beispiel: falls $conn nicht global ist, musst du es wie in deiner Seite erzeugen.
-if (!isset($conn)) {
- die("DB Verbindung (\$conn) fehlt.");
-}
-
-function h($s) { return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); }
-
-$errors = [];
-$success = false;
-
-$emailNorm = function_exists('mb_strtolower')
- ? mb_strtolower(trim((string)$mailadress), 'UTF-8')
- : strtolower(trim((string)$mailadress));
-if ($emailNorm === '' || !filter_var($emailNorm, FILTER_VALIDATE_EMAIL)) {
- $errors[] = "Keine gültige E-Mail im System gefunden (Variable \$mailadress).";
-}
-
-// Options
-$drinks = [
- 'espresso' => 'Espresso',
- 'crema' => 'Café Crema',
- 'cappuccino' => 'Cappuccino',
- 'latte' => 'Latte Macchiato',
- 'americano' => 'Americano',
- 'decaf' => 'Entkoffeiniert',
- 'other' => 'Andere',
-];
-
-$problems = [
- 'forget' => 'Vergesse Eintrag',
- 'empty' => 'Kaffee leer',
- 'water' => 'Wasser auffüllen',
- 'too_little' => 'zu wenig Kaffeeausgabe',
- 'too_much' => 'zu viel Kaffeeausgabe',
- 'none' => 'Kein Problem',
- 'other' => 'Sonstiges',
-];
-
-$improvements = [
- 'easier_entry' => 'Einfacherer Eintrag',
- 'overview' => 'Übersicht über Kosten/Verbrauch',
- 'more_mails' => 'Mehr Info-Mails',
- 'adjust_amount' => 'Menge der Kaffeeausgabe anpassen',
- 'other' => 'Sonstiges',
-];
-
-function post($k, $def='') { return $_POST[$k] ?? $def; }
-function postArr($k) { $v = $_POST[$k] ?? []; return is_array($v) ? $v : []; }
-
-// Schon abgestimmt?
-$alreadyVoted = true;
-if (!$errors) {
- $sqlChk = "SELECT 1 FROM dbo.CoffeeSurveyVotedEmails WHERE EmailNorm = ?";
- $stmtChk = sqlsrv_query($conn, $sqlChk, [$emailNorm]);
- if ($stmtChk === false) {
- $errors[] = "DB-Fehler (Vote-Check): " . print_r(sqlsrv_errors(), true);
- } else {
- $alreadyVoted = (sqlsrv_fetch_array($stmtChk, SQLSRV_FETCH_NUMERIC) !== null);
- }
-}
-
-// POST Handling
-if ($_SERVER['REQUEST_METHOD'] === 'POST' && !$errors) {
- if ($alreadyVoted) {
- $errors[] = "Du hast bereits abgestimmt.";
- } else {
-
- $q1 = (int)post('q1_listease', 0); // 1 sehr einfach .. 5 sehr schwierig
- $q2 = (int)post('q2_listsat', 0); // 1 sehr zufrieden .. 5 sehr unzufrieden
- $q3 = (int)post('q3_quality', 0);
- $q4 = (int)post('q4_websat', 0);
-
- $q5 = postArr('q5_drinks'); // array
- $q5_other = trim((string)post('q5_drinks_other',''));
-
- $q6 = trim((string)post('q6_newvarieties',''));
-
- $q7 = (string)post('q7_problem','');
- $q7_other = trim((string)post('q7_problem_other',''));
-
- $q8 = postArr('q8_improvements');
- $q8_other = trim((string)post('q8_improvements_other',''));
-
- $q9 = trim((string)post('q9_betterideas',''));
-
- // Validate scales
- foreach ([1=>$q1,2=>$q2,3=>$q3,4=>$q4] as $idx=>$val) {
- if ($val < 1 || $val > 5) $errors[] = "Bitte bei Frage {$idx} einen Wert von 1 bis 5 wählen.";
- }
-
- // Validate drinks
- $allowedDrinks = array_keys($drinks);
- $q5 = array_values(array_unique(array_filter($q5, fn($v)=>in_array($v,$allowedDrinks,true))));
- if (count($q5) === 0) $errors[] = "Bitte bei Frage 5 mindestens eine Kaffeesorte auswählen.";
- if (in_array('other',$q5,true) && $q5_other === '') $errors[] = "Bitte bei Frage 5 'Andere' kurz beschreiben.";
-
- // Validate problem
- if (!array_key_exists($q7, $problems)) $errors[] = "Bitte bei Frage 7 eine Option wählen.";
- if ($q7 === 'other' && $q7_other === '') $errors[] = "Bitte bei Frage 7 'Sonstiges' kurz beschreiben.";
-
- // Validate improvements
- $allowedImp = array_keys($improvements);
- $q8 = array_values(array_unique(array_filter($q8, fn($v)=>in_array($v,$allowedImp,true))));
- if (count($q8) === 0) $errors[] = "Bitte bei Frage 8 mindestens eine Verbesserung auswählen.";
- if (in_array('other',$q8,true) && $q8_other === '') $errors[] = "Bitte bei Frage 8 'Sonstiges' kurz beschreiben.";
-
- if (!$errors) {
- $q5_csv = implode(',', $q5);
- $q8_csv = implode(',', $q8);
-
- // Transaction (sqlsrv)
- sqlsrv_begin_transaction($conn);
-
- // 1) Sperre (E-Mail) eintragen
- $sqlEmail = "INSERT INTO dbo.CoffeeSurveyVotedEmails (EmailNorm) VALUES (?)";
- $stmtEmail = sqlsrv_query($conn, $sqlEmail, [$emailNorm]);
-
- if ($stmtEmail === false) {
- sqlsrv_rollback($conn);
- $errors[] = "Speichern fehlgeschlagen (E-Mail-Sperre). " . print_r(sqlsrv_errors(), true);
- } else {
- // 2) Antworten speichern (ohne E-Mail)
- $sqlIns = "
- INSERT INTO dbo.CoffeeSurveyResponses
- (Q1_ListEase, Q2_ListSatisfaction, Q3_CoffeeQuality, Q4_WebsiteSatisfaction,
- Q5_Drinks, Q5_DrinksOther, Q6_NewVarieties,
- Q7_ListProblem, Q7_ListProblemOther,
- Q8_Improvements, Q8_ImprovementsOther,
- Q9_BetterIdeas)
- VALUES (?,?,?,?,?,?,?,?,?,?,?,?)
- ";
- $params = [
- $q1, $q2, $q3, $q4,
- $q5_csv, ($q5_other !== '' ? $q5_other : null), ($q6 !== '' ? $q6 : null),
- $q7, ($q7_other !== '' ? $q7_other : null),
- $q8_csv, ($q8_other !== '' ? $q8_other : null),
- ($q9 !== '' ? $q9 : null),
- ];
-
- $stmtIns = sqlsrv_query($conn, $sqlIns, $params);
-
- if ($stmtIns === false) {
- sqlsrv_rollback($conn);
- $errors[] = "Speichern fehlgeschlagen (Antworten). " . print_r(sqlsrv_errors(), true);
- } else {
- sqlsrv_commit($conn);
- $success = true;
- $alreadyVoted = true;
- }
- }
- }
- }
-}
-?>
-
-
-
Danke! Deine Antwort wurde gespeichert.
-
-
-
-
Hinweis: Du hast bereits abgestimmt.
-
-
-
-
-
-
-
Danke! Umfrage abgeschlossen.";
-
- else:
-?>
-
-
-
-Sie haben keine Zugang zu dieser Webseite";
-}
-?>
-
-
-