Dateien nach "/" hochladen

This commit is contained in:
2026-03-05 15:31:22 +01:00
parent ecbb565e2b
commit 4de35c7d58
5 changed files with 841 additions and 0 deletions
+342
View File
@@ -0,0 +1,342 @@
<?php
declare(strict_types=1);
include "functions.php";
include "header.php";
include "headerline.php";
include "nav.php";
?>
<!-- Banner -->
<section id="banner">
<div class="content">
<style>
/* Hartes Reset für Inputs nur im Umfrage-Formular */
html body form#coffeeSurvey input[type="checkbox"],
html body form#coffeeSurvey input[type="radio"]{
all: revert !important; /* setzt ALLES zurück */
appearance: auto !important;
-webkit-appearance: auto !important;
display: inline-block !important;
position: static !important;
opacity: 1 !important;
visibility: visible !important;
width: 16px !important;
height: 16px !important;
margin: 0 6px 0 0 !important;
transform: none !important;
}
html body form#coffeeSurvey label{
display: inline-block;
cursor: pointer;
}
</style>
<?php
$geschlossen = true;
if(checkKaffeelisteAccess($conn, $mailadress)){
echo "<h2>Kaffeeliste</h2>";
echo "Hallo " . getUserName($conn,$mailadress) . "!<br><br>";
// 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 = mb_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;
}
}
}
}
}
?>
<?php if ($success): ?>
<p><b>Danke!</b> Deine Antwort wurde gespeichert.</p>
<?php endif; ?>
<?php if ($alreadyVoted && !$success && !$errors): ?>
<p><h2><b>Hinweis:</b> Du hast bereits abgestimmt.</h2></p>
<?php endif; ?>
<?php if ($errors): ?>
<div style="border:1px solid #cc0000; padding:10px; margin:10px 0;">
<b>Bitte korrigieren:</b>
<ul>
<?php foreach ($errors as $e): ?>
<li><?php echo h($e); ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif;?>
<?php if ($geschlossen):
echo "<p><b>Danke!</b> Umfrage abgeschlossen.</p>";
else:
?>
<form id="coffeeSurvey" method="post" action="<?php echo h($_SERVER["PHP_SELF"]); ?>">
<label for="q1_listease">Wie einfach ist die Kaffeeliste für dich zu benutzen?</label><br>
<select name="q1_listease" id="q1_listease" required>
<option value="">Bitte wählen</option>
<?php for ($i=1;$i<=5;$i++): ?>
<?php
$text = ($i===1) ? "1 (sehr einfach)" : (($i===5) ? "5 (sehr schwierig)" : (string)$i);
$sel = ((string)post('q1_listease','') === (string)$i) ? "selected" : "";
?>
<option value="<?php echo $i; ?>" <?php echo $sel; ?>><?php echo h($text); ?></option>
<?php endfor; ?>
</select>
<br><br>
<label for="q2_listsat">Wie zufrieden bist du mit der Kaffeeliste insgesamt?</label><br>
<select name="q2_listsat" id="q2_listsat" required>
<option value="">Bitte wählen</option>
<?php for ($i=1;$i<=5;$i++): ?>
<?php
$text = ($i===1) ? "1 (sehr zufrieden)" : (($i===5) ? "5 (sehr unzufrieden)" : (string)$i);
$sel = ((string)post('q2_listsat','') === (string)$i) ? "selected" : "";
?>
<option value="<?php echo $i; ?>" <?php echo $sel; ?>><?php echo h($text); ?></option>
<?php endfor; ?>
</select>
<br><br>
<label for="q3_quality">Wie zufrieden bist du mit der Kaffeequalität insgesamt?</label><br>
<select name="q3_quality" id="q3_quality" required>
<option value="">Bitte wählen</option>
<?php for ($i=1;$i<=5;$i++): ?>
<?php
$text = ($i===1) ? "1 (sehr zufrieden)" : (($i===5) ? "5 (sehr unzufrieden)" : (string)$i);
$sel = ((string)post('q3_quality','') === (string)$i) ? "selected" : "";
?>
<option value="<?php echo $i; ?>" <?php echo $sel; ?>><?php echo h($text); ?></option>
<?php endfor; ?>
</select>
<br><br>
<label for="q4_websat">Wie zufrieden bist du mit der Webseite der Kaffeeliste insgesamt?</label><br>
<select name="q4_websat" id="q4_websat" required>
<option value="">Bitte wählen</option>
<?php for ($i=1;$i<=5;$i++): ?>
<?php
$text = ($i===1) ? "1 (sehr zufrieden)" : (($i===5) ? "5 (sehr unzufrieden)" : (string)$i);
$sel = ((string)post('q4_websat','') === (string)$i) ? "selected" : "";
?>
<option value="<?php echo $i; ?>" <?php echo $sel; ?>><?php echo h($text); ?></option>
<?php endfor; ?>
</select>
<br><br>
<label>Welche Kaffeearten/Sorten trinkst du am häufigsten? (Mehrfachauswahl)</label><br>
<?php foreach ($drinks as $val => $label): ?>
<?php $checked = in_array($val, postArr('q5_drinks'), true) ? "checked" : ""; ?>
<input type="checkbox" name="q5_drinks[]" value="<?php echo h($val); ?>" <?php echo $checked; ?>>
<?php echo h($label); ?><br>
<?php endforeach; ?>
<br>
<label for="q5_drinks_other">Andere (Text):</label><br>
<input type="text" name="q5_drinks_other" id="q5_drinks_other" value="<?php echo h((string)post('q5_drinks_other','')); ?>">
<br><br>
<label for="q6_newvarieties">Welche zusätzlichen Sorten würdest du dir wünschen? (Freitext)</label><br>
<textarea name="q6_newvarieties" id="q6_newvarieties" rows="3"><?php echo h((string)post('q6_newvarieties','')); ?></textarea>
<br><br>
<label for="q7_problem">Was ist dein häufigstes Problem mit der Kaffeeliste?</label><br>
<select name="q7_problem" id="q7_problem" required>
<option value="">Bitte wählen</option>
<?php foreach ($problems as $val => $label): ?>
<?php $sel = ((string)post('q7_problem','') === (string)$val) ? "selected" : ""; ?>
<option value="<?php echo h($val); ?>" <?php echo $sel; ?>><?php echo h($label); ?></option>
<?php endforeach; ?>
</select>
<br><br>
<label for="q7_problem_other">Sonstiges (Text):</label><br>
<input type="text" name="q7_problem_other" id="q7_problem_other" value="<?php echo h((string)post('q7_problem_other','')); ?>">
<br><br>
<label>Welche Verbesserungen wünschst du dir für die Kaffeeliste? (Mehrfachauswahl)</label><br>
<?php foreach ($improvements as $val => $label): ?>
<?php $checked = in_array($val, postArr('q8_improvements'), true) ? "checked" : ""; ?>
<input type="checkbox" name="q8_improvements[]" value="<?php echo h($val); ?>" <?php echo $checked; ?>>
<?php echo h($label); ?><br>
<?php endforeach; ?>
<br>
<label for="q8_improvements_other">Sonstiges (Text):</label><br>
<input type="text" name="q8_improvements_other" id="q8_improvements_other" value="<?php echo h((string)post('q8_improvements_other','')); ?>">
<br><br>
<label for="q9_betterideas">Was kann die Kaffeeliste noch besser machen? (Freitext)</label><br>
<textarea name="q9_betterideas" id="q9_betterideas" rows="4"><?php echo h((string)post('q9_betterideas','')); ?></textarea>
<br><br>
<input type="hidden" name="aktion" value="umfrage_absenden">
<button type="submit" <?php echo $alreadyVoted ? 'disabled' : ''; ?>>Umfrage absenden</button>
</form>
<?php
endif;?>
<?php
}else{
echo "<h2>Sie haben keine Zugang zu dieser Webseite</h2>";
}
?>
</div>
</section>
<?php include "footer.php";
?>