mirror of
https://github.com/Deutscher-Tischfussballbund/com_sportsmanager.git
synced 2026-09-11 18:41:50 +00:00
Export von kompletten Ligen im json-Format
This commit is contained in:
@@ -166,6 +166,32 @@ function exportCSV(array $rows, string $dateiname): void
|
||||
exit;
|
||||
}
|
||||
|
||||
function exportJSON(array $rows, string $dateiname): void
|
||||
{
|
||||
if (empty($rows)) {
|
||||
// Keine Daten → nichts exportieren
|
||||
return;
|
||||
}
|
||||
|
||||
// Dateiname absichern
|
||||
$dateiname = bereinigterDateiname($dateiname);
|
||||
|
||||
// Output Buffer nur beenden, wenn aktiv
|
||||
if (ob_get_level() > 0) {
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
// JSON-Header für Browser
|
||||
header('Content-Type: application/json; charset=UTF-8');
|
||||
header('Content-Disposition: attachment; filename="' . $dateiname . '"; filename*=UTF-8\'\'' . rawurlencode($dateiname));
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Pragma: no-cache');
|
||||
header('Expires: 0');
|
||||
|
||||
echo json_encode($rows, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
exit;
|
||||
}
|
||||
|
||||
function adminUebersicht(): void
|
||||
{
|
||||
$db = getDatabase();
|
||||
@@ -12969,34 +12995,90 @@ function adminBegegnungenExportForm(): void
|
||||
HTML_sportsmanager_admin::adminBegegnungenExport($veranstaltung,$saison);
|
||||
}
|
||||
|
||||
#[NoReturn] function adminBegegnungenExport(): void
|
||||
function sportsmanagerExportErmittleTeams($db, int $veranstaltungId): array
|
||||
{
|
||||
$db = getDatabase();
|
||||
$jInput = Factory::getContainer()->get(SiteApplication::class)->input;
|
||||
|
||||
$veranstaltungId = $jInput->get('veranstaltungId', 0, 'INT');
|
||||
$export = $jInput->get('export', '', 'RAW');
|
||||
|
||||
if ($veranstaltungId == 0) die("Missing id!");
|
||||
|
||||
if (!benutzerZugriff("mannschaftswettbewerb_aendern") && !benutzerVeranstaltungModerator($veranstaltungId))
|
||||
keinZugriff();
|
||||
|
||||
// Veranstaltung ermitteln
|
||||
$query = "SELECT * FROM #__sportsmanager_veranstaltung WHERE veranstaltung_id = $veranstaltungId";
|
||||
$query = "SELECT t2.verein_id, t2.vereinsname AS Verein, t2.vereinssitz AS Vereinssitz,"
|
||||
. "\n t2.vereinssitz_ortsteil AS Vereinssitz_Ortsteil, t2.url AS Vereinswebseite,"
|
||||
. "\n t1.team_id, t1.teamname AS Team, t3.bezeichnung AS Liga, t1.tischtyp AS Tisch,"
|
||||
. "\n t4.name AS Spielort, t4.strasse AS Spielort_Strasse, t4.plz AS Spielort_PLZ,"
|
||||
. "\n t4.ortsname AS Spielort_Ort, t4.ortsteil AS Spielort_Ortsteil, t4.telefon AS Spielort_Telefon,"
|
||||
. "\n t4.url AS Spielort_Url, t1.trainingstage AS Trainingstage, t4.ruhetage AS Spielort_Ruhetage"
|
||||
. "\n FROM #__sportsmanager_team AS t1"
|
||||
. "\n LEFT JOIN #__sportsmanager_verein AS t2 ON t1.verein_id = t2.verein_id"
|
||||
. "\n LEFT JOIN #__sportsmanager_veranstaltung AS t3 ON t1.veranstaltung_id = t3.veranstaltung_id"
|
||||
. "\n LEFT JOIN #__sportsmanager_spielort AS t4 ON t1.heimspielort_id = t4.spielort_id"
|
||||
. "\n WHERE t1.veranstaltung_id = " . $veranstaltungId . ";";
|
||||
|
||||
$rows = loadObjectList($db, $query);
|
||||
if (count($rows) < 1) die("Wrong id!");
|
||||
$veranstaltung = $rows[0];
|
||||
|
||||
if ($jInput->get('cancel', false, 'BOOL')) {
|
||||
redirectSportsManagerURL('&task=admin_begegnungen&veranstaltungid=' . $veranstaltungId);
|
||||
foreach ($rows AS $value)
|
||||
{
|
||||
$query = "SELECT * FROM #__sportsmanager_vereinsansprechpartner"
|
||||
. "\n WHERE verein_id = ".$value->verein_id." ORDER BY vereinsansprechpartner_id;";
|
||||
$ansprechpartner = loadObjectList($db, $query);
|
||||
for ($i = 0; $i <= 2; $i++){
|
||||
$index = $i + 1;
|
||||
if (isset($ansprechpartner[$i])){
|
||||
$property = "VAP{$index}_Nachname";
|
||||
$value->$property = $ansprechpartner[$i]->nachname;
|
||||
$property = "VAP{$index}_Vorname";
|
||||
$value->$property = $ansprechpartner[$i]->vorname;
|
||||
$property = "VAP{$index}_Telefon";
|
||||
$value->$property = $ansprechpartner[$i]->telefon;
|
||||
$property = "VAP{$index}_Mobil";
|
||||
$value->$property = $ansprechpartner[$i]->mobil;
|
||||
$property = "VAP{$index}_EMail";
|
||||
$value->$property = $ansprechpartner[$i]->email;
|
||||
} else {
|
||||
$property = "VAP{$index}_Nachname";
|
||||
$value->$property = "";
|
||||
$property = "VAP{$index}_Vorname";
|
||||
$value->$property = "";
|
||||
$property = "VAP{$index}_Telefon";
|
||||
$value->$property = "";
|
||||
$property = "VAP{$index}_Mobil";
|
||||
$value->$property = "";
|
||||
$property = "VAP{$index}_EMail";
|
||||
$value->$property = "";
|
||||
}
|
||||
}
|
||||
|
||||
unset($rows);
|
||||
$query = "SELECT * FROM #__sportsmanager_teamansprechpartner"
|
||||
. "\n WHERE team_id = ".$value->team_id." ORDER BY kontaktperson_id;";
|
||||
$ansprechpartner = loadObjectList($db, $query);
|
||||
for ($i = 0; $i <= 1; $i++){
|
||||
$index = $i + 1;
|
||||
if (isset($ansprechpartner[$i])){
|
||||
$property = "TAP{$index}_Nachname";
|
||||
$value->$property = $ansprechpartner[$i]->nachname;
|
||||
$property = "TAP{$index}_Vorname";
|
||||
$value->$property = $ansprechpartner[$i]->vorname;
|
||||
$property = "TAP{$index}_Telefon";
|
||||
$value->$property = $ansprechpartner[$i]->telefon;
|
||||
$property = "TAP{$index}_Mobil";
|
||||
$value->$property = $ansprechpartner[$i]->mobil;
|
||||
$property = "TAP{$index}_EMail";
|
||||
$value->$property = $ansprechpartner[$i]->email;
|
||||
} else {
|
||||
$property = "TAP{$index}_Nachname";
|
||||
$value->$property = "";
|
||||
$property = "TAP{$index}_Vorname";
|
||||
$value->$property = "";
|
||||
$property = "TAP{$index}_Telefon";
|
||||
$value->$property = "";
|
||||
$property = "TAP{$index}_Mobil";
|
||||
$value->$property = "";
|
||||
$property = "TAP{$index}_EMail";
|
||||
$value->$property = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$dateiname = "";
|
||||
if ($export == "spieler") {
|
||||
return $rows;
|
||||
}
|
||||
|
||||
function sportsmanagerExportErmittleSpieler($db, int $veranstaltungId): array
|
||||
{
|
||||
$query = "
|
||||
SELECT t5.bezeichnung AS Veranstaltung, t2.vereinsname AS Verein, t1.teamname AS Team, t4.spielernr AS Passnummer,
|
||||
t4.nachname AS Nachname, t4.vorname AS Vorname, t4.geburtsjahr AS Geburtsjahr, LOWER(LEFT(geschlecht, 1)) AS Geschlecht,
|
||||
@@ -13010,14 +13092,11 @@ function adminBegegnungenExportForm(): void
|
||||
WHERE t1.veranstaltung_id = " . $veranstaltungId . ";
|
||||
";
|
||||
|
||||
$rows = loadObjectList($db, $query);
|
||||
if (!isset($rows) or count($rows) == 0) {
|
||||
redirectSportsManagerURL('&task=admin_begegnungen&veranstaltungid=1', "Zu dieser Auswahl sind keine Daten vorhanden!");
|
||||
}
|
||||
$dateiname = "Spieler " . $veranstaltung->bezeichnung;
|
||||
}
|
||||
return loadObjectList($db, $query);
|
||||
}
|
||||
|
||||
if ($export == "spielplan" or $export == "spielberichte") {
|
||||
function sportsmanagerExportErmittleSpielplan($db, int $veranstaltungId): array
|
||||
{
|
||||
$query = "
|
||||
SELECT t1.begegnung_id AS ID, ";
|
||||
if (einstellungswert("verbands_kuerzel") == "STFV"){
|
||||
@@ -13070,14 +13149,12 @@ function adminBegegnungenExportForm(): void
|
||||
if (!empty($genehmigt))
|
||||
$value->verlegt_auf = $genehmigt[0]->Termin_neu;
|
||||
}
|
||||
$dateiname = "Spielplan " . $veranstaltung->bezeichnung;
|
||||
|
||||
if (!isset($rows) or count($rows) == 0) {
|
||||
redirectSportsManagerURL('&task=admin_begegnungen&veranstaltungid=1', "Zu dieser Auswahl sind keine Daten vorhanden!");
|
||||
}
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
if ($export == "spielberichte") {
|
||||
function sportsmanagerExportErgaenzeSpielberichte($db, int $veranstaltungId, array $rows): array
|
||||
{
|
||||
// Modus ermitteln
|
||||
$query = "
|
||||
SELECT t2.* FROM #__sportsmanager_veranstaltung AS t1
|
||||
@@ -13202,89 +13279,84 @@ function adminBegegnungenExportForm(): void
|
||||
$value->$variable = $spielbericht[$i - 1]->Gast_Punkte;
|
||||
}
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
#[NoReturn] function adminBegegnungenExport(): void
|
||||
{
|
||||
$db = getDatabase();
|
||||
$jInput = Factory::getContainer()->get(SiteApplication::class)->input;
|
||||
|
||||
$veranstaltungId = $jInput->get('veranstaltungId', 0, 'INT');
|
||||
$export = $jInput->get('export', '', 'RAW');
|
||||
$exportformat = $jInput->get('exportformat', 'csvdatei', 'RAW');
|
||||
|
||||
if ($veranstaltungId == 0) die("Missing id!");
|
||||
|
||||
if (!benutzerZugriff("mannschaftswettbewerb_aendern") && !benutzerVeranstaltungModerator($veranstaltungId))
|
||||
keinZugriff();
|
||||
|
||||
// Veranstaltung ermitteln
|
||||
$query = "SELECT * FROM #__sportsmanager_veranstaltung WHERE veranstaltung_id = $veranstaltungId";
|
||||
|
||||
$rows = loadObjectList($db, $query);
|
||||
if (count($rows) < 1) die("Wrong id!");
|
||||
$veranstaltung = $rows[0];
|
||||
|
||||
if ($jInput->get('cancel', false, 'BOOL')) {
|
||||
redirectSportsManagerURL('&task=admin_begegnungen&veranstaltungid=' . $veranstaltungId);
|
||||
}
|
||||
|
||||
unset($rows);
|
||||
|
||||
// JSON-Export: Teams, Spieler und Spielberichte gemeinsam in dieser Reihenfolge exportieren
|
||||
if ($exportformat == "jsondatei") {
|
||||
$teams = sportsmanagerExportErmittleTeams($db, $veranstaltungId);
|
||||
$spieler = sportsmanagerExportErmittleSpieler($db, $veranstaltungId);
|
||||
$spielberichte = sportsmanagerExportErgaenzeSpielberichte($db, $veranstaltungId, sportsmanagerExportErmittleSpielplan($db, $veranstaltungId));
|
||||
|
||||
if (empty($teams) && empty($spieler) && empty($spielberichte)) {
|
||||
redirectSportsManagerURL('&task=admin_begegnungen&veranstaltungid=1', "Zu dieser Auswahl sind keine Daten vorhanden!");
|
||||
}
|
||||
|
||||
$daten = [
|
||||
'teams' => $teams,
|
||||
'spieler' => $spieler,
|
||||
'spielberichte' => $spielberichte,
|
||||
];
|
||||
|
||||
exportJSON($daten, "Export " . $veranstaltung->bezeichnung . ".json");
|
||||
}
|
||||
|
||||
$dateiname = "";
|
||||
if ($export == "spieler") {
|
||||
$rows = sportsmanagerExportErmittleSpieler($db, $veranstaltungId);
|
||||
if (!isset($rows) or count($rows) == 0) {
|
||||
redirectSportsManagerURL('&task=admin_begegnungen&veranstaltungid=1', "Zu dieser Auswahl sind keine Daten vorhanden!");
|
||||
}
|
||||
$dateiname = "Spieler " . $veranstaltung->bezeichnung;
|
||||
}
|
||||
|
||||
if ($export == "spielplan" or $export == "spielberichte") {
|
||||
$rows = sportsmanagerExportErmittleSpielplan($db, $veranstaltungId);
|
||||
$dateiname = "Spielplan " . $veranstaltung->bezeichnung;
|
||||
|
||||
if (!isset($rows) or count($rows) == 0) {
|
||||
redirectSportsManagerURL('&task=admin_begegnungen&veranstaltungid=1', "Zu dieser Auswahl sind keine Daten vorhanden!");
|
||||
}
|
||||
}
|
||||
|
||||
if ($export == "spielberichte") {
|
||||
$rows = sportsmanagerExportErgaenzeSpielberichte($db, $veranstaltungId, $rows);
|
||||
$dateiname = "Spielberichte " . $veranstaltung->bezeichnung;
|
||||
}
|
||||
|
||||
if ($export == "teams") {
|
||||
$query = "SELECT t2.verein_id, t2.vereinsname AS Verein, t2.vereinssitz AS Vereinssitz,"
|
||||
. "\n t2.vereinssitz_ortsteil AS Vereinssitz_Ortsteil, t2.url AS Vereinswebseite,"
|
||||
. "\n t1.team_id, t1.teamname AS Team, t3.bezeichnung AS Liga, t1.tischtyp AS Tisch,"
|
||||
. "\n t4.name AS Spielort, t4.strasse AS Spielort_Strasse, t4.plz AS Spielort_PLZ,"
|
||||
. "\n t4.ortsname AS Spielort_Ort, t4.ortsteil AS Spielort_Ortsteil, t4.telefon AS Spielort_Telefon,"
|
||||
. "\n t4.url AS Spielort_Url, t1.trainingstage AS Trainingstage, t4.ruhetage AS Spielort_Ruhetage"
|
||||
. "\n FROM #__sportsmanager_team AS t1"
|
||||
. "\n LEFT JOIN #__sportsmanager_verein AS t2 ON t1.verein_id = t2.verein_id"
|
||||
. "\n LEFT JOIN #__sportsmanager_veranstaltung AS t3 ON t1.veranstaltung_id = t3.veranstaltung_id"
|
||||
. "\n LEFT JOIN #__sportsmanager_spielort AS t4 ON t1.heimspielort_id = t4.spielort_id"
|
||||
. "\n WHERE t1.veranstaltung_id = " . $veranstaltungId . ";";
|
||||
|
||||
$rows = loadObjectList($db, $query);
|
||||
$rows = sportsmanagerExportErmittleTeams($db, $veranstaltungId);
|
||||
if (!isset($rows) or count($rows) == 0) {
|
||||
redirectSportsManagerURL('&task=admin_begegnungen&veranstaltungid=1', "Zu dieser Auswahl sind keine Daten vorhanden!");
|
||||
}
|
||||
|
||||
foreach ($rows AS $value)
|
||||
{
|
||||
$query = "SELECT * FROM #__sportsmanager_vereinsansprechpartner"
|
||||
. "\n WHERE verein_id = ".$value->verein_id." ORDER BY vereinsansprechpartner_id;";
|
||||
$ansprechpartner = loadObjectList($db, $query);
|
||||
for ($i = 0; $i <= 2; $i++){
|
||||
$index = $i + 1;
|
||||
if (isset($ansprechpartner[$i])){
|
||||
$property = "VAP{$index}_Nachname";
|
||||
$value->$property = $ansprechpartner[$i]->nachname;
|
||||
$property = "VAP{$index}_Vorname";
|
||||
$value->$property = $ansprechpartner[$i]->vorname;
|
||||
$property = "VAP{$index}_Telefon";
|
||||
$value->$property = $ansprechpartner[$i]->telefon;
|
||||
$property = "VAP{$index}_Mobil";
|
||||
$value->$property = $ansprechpartner[$i]->mobil;
|
||||
$property = "VAP{$index}_EMail";
|
||||
$value->$property = $ansprechpartner[$i]->email;
|
||||
} else {
|
||||
$property = "VAP{$index}_Nachname";
|
||||
$value->$property = "";
|
||||
$property = "VAP{$index}_Vorname";
|
||||
$value->$property = "";
|
||||
$property = "VAP{$index}_Telefon";
|
||||
$value->$property = "";
|
||||
$property = "VAP{$index}_Mobil";
|
||||
$value->$property = "";
|
||||
$property = "VAP{$index}_EMail";
|
||||
$value->$property = "";
|
||||
}
|
||||
}
|
||||
|
||||
$query = "SELECT * FROM #__sportsmanager_teamansprechpartner"
|
||||
. "\n WHERE team_id = ".$value->team_id." ORDER BY kontaktperson_id;";
|
||||
$ansprechpartner = loadObjectList($db, $query);
|
||||
for ($i = 0; $i <= 1; $i++){
|
||||
$index = $i + 1;
|
||||
if (isset($ansprechpartner[$i])){
|
||||
$property = "TAP{$index}_Nachname";
|
||||
$value->$property = $ansprechpartner[$i]->nachname;
|
||||
$property = "TAP{$index}_Vorname";
|
||||
$value->$property = $ansprechpartner[$i]->vorname;
|
||||
$property = "TAP{$index}_Telefon";
|
||||
$value->$property = $ansprechpartner[$i]->telefon;
|
||||
$property = "TAP{$index}_Mobil";
|
||||
$value->$property = $ansprechpartner[$i]->mobil;
|
||||
$property = "TAP{$index}_EMail";
|
||||
$value->$property = $ansprechpartner[$i]->email;
|
||||
} else {
|
||||
$property = "TAP{$index}_Nachname";
|
||||
$value->$property = "";
|
||||
$property = "TAP{$index}_Vorname";
|
||||
$value->$property = "";
|
||||
$property = "TAP{$index}_Telefon";
|
||||
$value->$property = "";
|
||||
$property = "TAP{$index}_Mobil";
|
||||
$value->$property = "";
|
||||
$property = "TAP{$index}_EMail";
|
||||
$value->$property = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
$dateiname = "Teams " . $veranstaltung->bezeichnung;
|
||||
}
|
||||
|
||||
|
||||
@@ -12843,6 +12843,11 @@ static function adminVerbandsorganMitglieder($rows,$verbandsorgan): void
|
||||
{
|
||||
global $params;
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
function anzeige_aktualisieren() {
|
||||
document.getElementById("export_row").style.display = document.adminForm.exportformat.value !== "jsondatei" ? '' : 'none';
|
||||
}
|
||||
</script>
|
||||
<form action="<?php echo SportsManagerURL(); ?>" method="post" name="adminForm" id="adminForm">
|
||||
<div class="uk-overflow-auto">
|
||||
<table style="width: 500px">
|
||||
@@ -12862,7 +12867,7 @@ static function adminVerbandsorganMitglieder($rows,$verbandsorgan): void
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr id="export_row">
|
||||
<td nowrap style="text-align: right">
|
||||
<label for="export">Exportieren</label>
|
||||
</td>
|
||||
@@ -12880,8 +12885,9 @@ static function adminVerbandsorganMitglieder($rows,$verbandsorgan): void
|
||||
<label for="exportformat">Exportformat</label>
|
||||
</td>
|
||||
<td nowrap>
|
||||
<select class="uk-select uk-form-width-large" style='width: 320px;' name="exportformat" id="exportformat" size="1">
|
||||
<select class="uk-select uk-form-width-large" style='width: 320px;' name="exportformat" id="exportformat" size="1" onchange="anzeige_aktualisieren();">
|
||||
<option value='csvdatei'>CSV-Datei</option>
|
||||
<option value='jsondatei'>JSON-Datei</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user