false, 'message' => 'Keine valide Programm-ID']); exit; } require $baseDir . '/../scripts/db/db-functions.php'; require $baseDir . '/../scripts/db/db-tables.php'; $type = 'wkl'; $dbconnection = require $baseDir . '/../scripts/db/db-verbindung-script.php'; if ($dbconnection['success'] !== true){ echo 'Critical DB Error.'; exit; } $programm_name = db_get_var($mysqli, "SELECT `programm` FROM $tableProgramme WHERE id = ? LIMIT 1", [$programm_id]) ?: null; if ($programm_name === null) { echo json_encode(['success' => true, 'message' => 'Dieses Programm existiert nicht.']); http_response_code(400); exit; } $personen = db_select($mysqli, $tableTeilnehmende, "id", '`programm` = ?', [$programm_name]); if (count($personen) < 1) { echo json_encode(['success' => true, 'message' => 'Es existieren keine Personen mit diesem Programm.']); http_response_code(400); exit; } $personen_id_array = array_column($personen, 'id'); $parram_array = array_fill(0, count($personen_id_array), "?"); $parram_string = implode(', ', $parram_array); $year = date('n') > 6 ? intval(date('Y')) + 1 : intval(date('Y')); $value_array = array_merge($personen_id_array, [$year]); $stmt = $mysqli->prepare("DELETE FROM $tableNoten WHERE `person_id` IN ($parram_string) AND `jahr` = ?"); $types_string = str_repeat("i", count($personen_id_array)) . "i"; $stmt->bind_param($types_string, ...$value_array); $stmt->execute(); $stmt->close(); $stmt = $mysqli->prepare("DELETE FROM $tableNotenChanges WHERE `person_id` IN ($parram_string) AND `jahr` = ?"); $stmt->bind_param($types_string, ...$value_array); $stmt->execute(); $stmt->close(); echo json_encode(['success' => true, 'message' => 'Noten gelöscht']); http_response_code(200);