Joomla-Export für Monatsvorschau ergänzen

This commit is contained in:
2026-08-31 10:59:54 +02:00
parent 0427e3cf2c
commit 559844bfab
2 changed files with 321 additions and 0 deletions
+54
View File
@@ -3,6 +3,12 @@ declare(strict_types=1);
session_start();
require_once __DIR__ . '/auth_helpers.php';
if (isLocalDevelopmentRequest()) {
set_time_limit(180);
}
$loggedIn = isset($_SESSION['user_id']);
$pageTitle = 'Monatsvorhersage - AstroTools';
$bodyClass = 'admin-page monatsvorhersage-page';
@@ -19,6 +25,10 @@ if (!isset($_SESSION['observation_tip_insert_token']) || !is_string($_SESSION['o
$_SESSION['observation_tip_insert_token'] = bin2hex(random_bytes(16));
}
$observationTipInsertToken = $_SESSION['observation_tip_insert_token'];
if (!isset($_SESSION['joomla_monthly_preview_token']) || !is_string($_SESSION['joomla_monthly_preview_token'])) {
$_SESSION['joomla_monthly_preview_token'] = bin2hex(random_bytes(16));
}
$joomlaMonthlyPreviewToken = $_SESSION['joomla_monthly_preview_token'];
// -------------------------------------------------------------------------
// Bereits berechnete Bausteine der Monatsvorschau
@@ -264,6 +274,7 @@ $observationTipInsertSql = '';
$observationTipCalendarIcs = '';
$observationTipInsertPayloadJson = '[]';
$observationTipInsertEndpoint = $publicBasePath . 'ajax/insert_observationtips.php';
$joomlaMonthlyPreviewEndpoint = $publicBasePath . 'ajax/save_monthly_preview_to_joomla.php';
$chartConfig = null;
$chartConfigJson = 'null';
$starDataJson = '[]';
@@ -2903,6 +2914,11 @@ $observationTipCalendarFilenameJson = json_encode(sprintf('astrotools-monatserei
<button type="button" class="monatskarte-export-button" id="copyMonatsueberblickHtml">
HTML in Zwischenablage kopieren
</button>
<?php if (currentUserIsAdminLike()): ?>
<button type="button" class="monatskarte-export-button" id="saveMonatsueberblickToJoomla">
In Joomla speichern
</button>
<?php endif; ?>
<p id="monatsueberblickZipStatus" role="status" aria-live="polite"></p>
</div>
@@ -3389,6 +3405,8 @@ const MONTH_EVENT_LIST = <?= $monthEventListJson ?: '[]' ?>;
const MONTH_CHART_ERROR = <?= $starDataErrorJson ?: 'null' ?>;
const OBSERVATION_TIP_ICAL = <?= $observationTipCalendarIcsJson ?: '""' ?>;
const OBSERVATION_TIP_ICAL_FILENAME = <?= $observationTipCalendarFilenameJson ?: '"astrotools-monatsereignisse.ics"' ?>;
const JOOMLA_MONTHLY_PREVIEW_ENDPOINT = <?= json_encode($joomlaMonthlyPreviewEndpoint, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) ?>;
const JOOMLA_MONTHLY_PREVIEW_TOKEN = <?= json_encode($joomlaMonthlyPreviewToken, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) ?>;
const MONTH_CHART_EXPORT_LOGO_SRC = <?= json_encode($publicBasePath . 'images/logoAM_ws.png', JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) ?>;
const MONTH_CHART_COMET_K = 0.01720209895;
@@ -6160,6 +6178,7 @@ function monthChartCometRaDec(comet, date) {
(function () {
const downloadButton = document.getElementById('downloadMonatsueberblickZip');
const copyButton = document.getElementById('copyMonatsueberblickHtml');
const saveToJoomlaButton = document.getElementById('saveMonatsueberblickToJoomla');
const statusEl = document.getElementById('monatsueberblickZipStatus');
const overviewEl = document.getElementById('monatsueberblick');
const polarCanvas = document.getElementById('monatskarteCanvas');
@@ -6455,6 +6474,41 @@ function monthChartCometRaDec(comet, date) {
copyButton.disabled = false;
}
});
if (saveToJoomlaButton) {
saveToJoomlaButton.addEventListener('click', async function () {
const year = Number(MONTH_CHART_CONFIG.year || 0);
const month = Number(MONTH_CHART_CONFIG.monthNumber || MONTH_CHART_CONFIG.month || 0);
if (!Number.isInteger(year) || !Number.isInteger(month)) {
statusEl.textContent = 'Monat für den Joomla-Export konnte nicht bestimmt werden.';
return;
}
try {
statusEl.textContent = 'Monatsvorschau wird für Joomla erstellt...';
saveToJoomlaButton.disabled = true;
const formData = new FormData();
formData.append('joomla_monthly_preview_token', JOOMLA_MONTHLY_PREVIEW_TOKEN);
formData.append('year', String(year));
formData.append('month', String(month));
formData.append('html', await overviewHtml(await createOverviewImages()));
const response = await fetch(JOOMLA_MONTHLY_PREVIEW_ENDPOINT, {
method: 'POST',
body: formData,
headers: { 'X-Requested-With': 'fetch' },
});
const payload = await response.json();
statusEl.textContent = payload && payload.message
? payload.message
: 'Die Monatsvorschau konnte nicht in Joomla gespeichert werden.';
} catch (error) {
statusEl.textContent = 'Die Monatsvorschau konnte nicht in Joomla gespeichert werden.';
} finally {
saveToJoomlaButton.disabled = false;
}
});
}
})();
</script>