function nextMonth(currentMonth, currentYear) { let nextMonth = currentMonth + 1; let nextYear = currentYear; if (nextMonth > 12) { nextMonth = 1; nextYear += 1; } window.location.href = `calendar.php?month=${nextMonth}&year=${nextYear}`; } function prevMonth(currentMonth, currentYear) { let prevMonth = currentMonth - 1; let prevYear = currentYear; if (prevMonth < 1) { prevMonth = 12; prevYear -= 1; } window.location.href = `calendar.php?month=${prevMonth}&year=${prevYear}`; } function currentMoth() { window.location.href = `calendar.php`; } function closeSubscriptionModal() { const modal = document.getElementById('subscriptionModal'); modal.classList.remove('is-open'); } function openSubscriptionModal(subscriptionId) { const modal = document.getElementById('subscriptionModal'); const modalContent = document.getElementById('subscriptionModalContent'); modalContent.innerHTML = ''; fetch('endpoints/subscription/getcalendar.php', { method: 'POST', body: JSON.stringify({id: subscriptionId}), headers: { 'Content-Type': 'application/json' } }) .then(response => response.json()) .then(data => { if (data.success && data.data) { const subscription = data.data; const html = ` `; modalContent.innerHTML = html; modal.classList.add('is-open'); } else { console.error(data.message); } }) .catch(error => console.error('Error:', error)); } function exportCalendar(subscriptionId) { fetch('endpoints/subscription/exportcalendar.php', { method: 'POST', body: JSON.stringify({id: subscriptionId}), headers: { 'Content-Type': 'application/json' } }) .then(response => response.json()) .then(data => { if (data.success && data.ics) { const blob = new Blob([data.ics], {type: 'text/calendar'}); const url = window.URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; // Use the subscription name for the file name, replacing any characters that are invalid in file names a.download = `${data.name.replace(/[\/\\:*?"<>|]/g, '_').toLowerCase()}.ics`; document.body.appendChild(a); a.click(); window.URL.revokeObjectURL(url); } else { console.error('Failed to download the calendar file.'); } }) .catch(error => console.error('Error:', error)); }