mirror of
https://github.com/itflow-org/itflow
synced 2026-08-05 07:07:14 +00:00
Feature: Calendars are now exportable shareable so Third Party Calendar services can read them, also added recoccurence to calendar, and all day along with sperating the time fields and click in a box to add calendar event is possible
This commit is contained in:
@@ -43,9 +43,13 @@ if (isset($_GET['calendar_id'])) {
|
||||
$calendar_id = intval($row['calendar_id']);
|
||||
$calendar_name = escapeHtml($row['calendar_name']);
|
||||
$calendar_color = escapeHtml($row['calendar_color']);
|
||||
$calendar_feed_key = escapeHtml($row['calendar_feed_key'] ?? null);
|
||||
?>
|
||||
<div class="form-group d-flex align-items-center">
|
||||
<i class="fas fa-fw fa-circle mr-2" style="color:<?= $calendar_color ?>;"></i><?= $calendar_name ?>
|
||||
<?php if (!empty($calendar_feed_key)) { ?>
|
||||
<i class="fas fa-fw fa-share-alt text-info ml-2" title="Published as a subscription link"></i>
|
||||
<?php } ?>
|
||||
|
||||
<div class="dropdown dropright ml-auto">
|
||||
<button class="btn btn-tool" type="button" data-toggle="dropdown">
|
||||
@@ -56,6 +60,12 @@ if (isset($_GET['calendar_id'])) {
|
||||
data-modal-url="modals/calendar/calendar_edit.php?id=<?= $calendar_id ?>">
|
||||
<i class="fas fa-fw fa-pencil-alt mr-2"></i>Rename
|
||||
</a>
|
||||
<?php if ($session_is_admin) { ?>
|
||||
<a class="dropdown-item ajax-modal" href="#"
|
||||
data-modal-url="modals/calendar/calendar_share.php?id=<?= $calendar_id ?>">
|
||||
<i class="fas fa-fw fa-share-alt mr-2"></i><?= empty($calendar_feed_key) ? 'Share' : 'Manage sharing' ?>
|
||||
</a>
|
||||
<?php } ?>
|
||||
<?php if ($session_user_role == 3) { ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_calendar=<?= $calendar_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
@@ -153,6 +163,19 @@ while ($row = mysqli_fetch_assoc($sql)) {
|
||||
<script src='/libs/fullcalendar/themes/classic/global.js'></script>
|
||||
|
||||
<script>
|
||||
// Local-time formatters for the date and datetime-local inputs.
|
||||
// Date.toISOString() would convert to UTC and silently shift the event by the
|
||||
// browser's offset.
|
||||
function formatLocalDate(date) {
|
||||
const pad = (n) => String(n).padStart(2, "0");
|
||||
return date.getFullYear() + "-" + pad(date.getMonth() + 1) + "-" + pad(date.getDate());
|
||||
}
|
||||
|
||||
function formatLocalTime(date) {
|
||||
const pad = (n) => String(n).padStart(2, "0");
|
||||
return pad(date.getHours()) + ":" + pad(date.getMinutes());
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
var calendarEl = document.getElementById('calendar');
|
||||
|
||||
@@ -163,6 +186,13 @@ while ($row = mysqli_fetch_assoc($sql)) {
|
||||
text: 'New Event',
|
||||
iconClass: 'fas fa-plus',
|
||||
click: function() {
|
||||
// Reset to the all-day default; without this the modal keeps
|
||||
// whatever state the last calendar selection left it in
|
||||
const allDayToggle = document.getElementById("event_add_all_day");
|
||||
if (allDayToggle) {
|
||||
allDayToggle.checked = true;
|
||||
$(allDayToggle).trigger("change");
|
||||
}
|
||||
$("#addCalendarEventModal").modal();
|
||||
}
|
||||
}
|
||||
@@ -185,6 +215,65 @@ while ($row = mysqli_fetch_assoc($sql)) {
|
||||
eventDidMount: function(info) {
|
||||
// Always show full title when hovering
|
||||
info.el.setAttribute('title', info.event.title);
|
||||
|
||||
// Mark occurrences of a repeating event, so a series is recognisable
|
||||
// without opening it. Every occurrence carries the parent event id, so
|
||||
// this is the only cue that a click will edit the whole series.
|
||||
const repeat = info.event.extendedProps.repeat;
|
||||
if (repeat) {
|
||||
info.el.setAttribute('title', info.event.title + ' (repeats every ' + repeat.toLowerCase() + ')');
|
||||
|
||||
const titleEl = info.el.querySelector('.fc-event-title') || info.el.querySelector('.fc-list-event-title');
|
||||
if (titleEl) {
|
||||
const icon = document.createElement('i');
|
||||
icon.className = 'fas fa-redo fa-xs mr-1';
|
||||
titleEl.prepend(icon);
|
||||
}
|
||||
}
|
||||
},
|
||||
// Clicking - or dragging across - empty calendar space opens the New Event
|
||||
// modal prefilled with whatever was selected. Month view yields an all-day
|
||||
// range; the time grid views yield a slot range.
|
||||
select: function(selectionInfo) {
|
||||
|
||||
const allDayToggle = document.getElementById("event_add_all_day");
|
||||
const startDate = document.getElementById("event_add_start_date");
|
||||
const endDate = document.getElementById("event_add_end_date");
|
||||
const startTime = document.getElementById("event_add_start_time");
|
||||
const endTime = document.getElementById("event_add_end_time");
|
||||
|
||||
if (!startDate || !endDate) {
|
||||
return;
|
||||
}
|
||||
|
||||
// FullCalendar reports an exclusive end for an all-day range, but the form
|
||||
// asks for the last day the event covers - step back a day so a single-day
|
||||
// click does not come back as a two-day event. A time-grid selection is not
|
||||
// exclusive in the same way, so its end date is used as-is (a slot running
|
||||
// to midnight legitimately ends on the next day).
|
||||
const lastDay = new Date(selectionInfo.end.getTime());
|
||||
if (selectionInfo.allDay) {
|
||||
lastDay.setDate(lastDay.getDate() - 1);
|
||||
}
|
||||
|
||||
startDate.value = formatLocalDate(selectionInfo.start);
|
||||
endDate.value = formatLocalDate(lastDay);
|
||||
|
||||
// A time-grid selection carries a real time; a month-view click does not,
|
||||
// so its time fields are left for the user to fill in if they uncheck
|
||||
if (!selectionInfo.allDay && startTime && endTime) {
|
||||
startTime.value = formatLocalTime(selectionInfo.start);
|
||||
endTime.value = formatLocalTime(selectionInfo.end);
|
||||
}
|
||||
|
||||
// Last, so the handler in app.js shows or hides the time row to match
|
||||
if (allDayToggle) {
|
||||
allDayToggle.checked = selectionInfo.allDay;
|
||||
$(allDayToggle).trigger("change");
|
||||
}
|
||||
|
||||
calendar.unselect();
|
||||
$("#addCalendarEventModal").modal();
|
||||
},
|
||||
eventClick: function(editEvent) {
|
||||
var eventId = editEvent.event.id;
|
||||
@@ -215,16 +304,40 @@ while ($row = mysqli_fetch_assoc($sql)) {
|
||||
events: [
|
||||
<?php
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM calendar_events LEFT JOIN calendars ON event_calendar_id = calendar_id $client_event_query");
|
||||
|
||||
// Repeating events are stored as a single row, so the occurrences have to
|
||||
// be materialised here - the bundled FullCalendar build has no rrule
|
||||
// plugin. Every occurrence keeps the parent event_id, so clicking any of
|
||||
// them opens the series in the edit modal.
|
||||
$recur_window_start = date('Y-m-d H:i:s', strtotime('-6 months'));
|
||||
$recur_window_end = date('Y-m-d H:i:s', strtotime('+18 months'));
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$event_id = intval($row['event_id']);
|
||||
$event_title = json_encode($row['event_title']);
|
||||
$event_start = json_encode($row['event_start']);
|
||||
$event_end = json_encode($row['event_end']);
|
||||
$calendar_id = intval($row['calendar_id']);
|
||||
$calendar_name = json_encode($row['calendar_name']);
|
||||
$calendar_color = json_encode($row['calendar_color']);
|
||||
$event_is_all_day = !empty($row['event_all_day'] ?? 0);
|
||||
$event_all_day = $event_is_all_day ? 'true' : 'false';
|
||||
$event_repeat = json_encode($row['event_repeat'] ?? '');
|
||||
|
||||
echo "{ id: $event_id, title: $event_title, start: $event_start, end: $event_end, color: $calendar_color },";
|
||||
foreach (expandRecurringEvent($row, $recur_window_start, $recur_window_end) as $occurrence) {
|
||||
|
||||
$occurrence_end = $occurrence['end'];
|
||||
|
||||
// event_end holds the last day an all-day event covers, but
|
||||
// FullCalendar's all-day end is exclusive - without this the final
|
||||
// day of a multi-day event is not drawn
|
||||
if ($event_is_all_day && !empty($occurrence_end)) {
|
||||
$occurrence_end = date('Y-m-d H:i:s', strtotime($occurrence_end . ' +1 day'));
|
||||
}
|
||||
|
||||
$event_start = json_encode($occurrence['start']);
|
||||
$event_end = json_encode($occurrence_end);
|
||||
|
||||
echo "{ id: $event_id, title: $event_title, start: $event_start, end: $event_end, allDay: $event_all_day, color: $calendar_color, extendedProps: { repeat: $event_repeat } },";
|
||||
}
|
||||
}
|
||||
|
||||
// Invoices Created
|
||||
@@ -384,31 +497,3 @@ while ($row = mysqli_fetch_assoc($sql)) {
|
||||
calendar.render();
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- Automatically set new event end date to 1 hr after start date -->
|
||||
<script>
|
||||
// Function - called when user leaves field (onblur)
|
||||
function updateIncrementEndTime() {
|
||||
|
||||
// Get the start date
|
||||
let start = document.getElementById("event_add_start").value;
|
||||
|
||||
// Create a date object
|
||||
let new_end = new Date(start);
|
||||
|
||||
// Get the time zone offset in minutes, convert it to milliseconds
|
||||
let offsetInMilliseconds = new_end.getTimezoneOffset() * 60 * 1000;
|
||||
|
||||
// Adjust the date by the time zone offset before adding an hour
|
||||
new_end = new Date(new_end.getTime() - offsetInMilliseconds);
|
||||
|
||||
// Set the end date to 1 hr in the future
|
||||
new_end.setHours(new_end.getHours() + 1);
|
||||
|
||||
// Get the date back as a string, with the milliseconds trimmed off
|
||||
new_end = new_end.toISOString().replace(/.\d+Z$/g, "");
|
||||
|
||||
// Update the end date field
|
||||
document.getElementById("event_add_end").value = new_end;
|
||||
}
|
||||
</script>
|
||||
@@ -62,22 +62,56 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label>Start / End <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-calendar-check"></i></span>
|
||||
</div>
|
||||
<input type="datetime-local" class="form-control" id="event_add_start" name="start" required onblur="updateIncrementEndTime()">
|
||||
<div class="custom-control custom-switch">
|
||||
<input type="checkbox" class="custom-control-input event-all-day-toggle" id="event_add_all_day" name="all_day" value="1" checked>
|
||||
<label class="custom-control-label" for="event_add_all_day">All day</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-6">
|
||||
<label>Date from <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-calendar-check"></i></span>
|
||||
</div>
|
||||
<input type="date" class="form-control event-start-date" id="event_add_start_date" name="start_date" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label>Date to <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
|
||||
</div>
|
||||
<input type="date" class="form-control" id="event_add_end_date" name="end_date" required>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Hidden while All day is on. The toggle handler in app.js also
|
||||
adds and removes required, because a hidden required field
|
||||
blocks submission with an unfocusable-element error. -->
|
||||
<div class="form-row d-none" id="event_add_time_fields">
|
||||
<div class="form-group col-md-6">
|
||||
<label>Time from <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-clock"></i></span>
|
||||
</div>
|
||||
<input type="time" class="form-control event-start-time" id="event_add_start_time" name="start_time">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label>Time to <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-clock"></i></span>
|
||||
</div>
|
||||
<input type="time" class="form-control" id="event_add_end_time" name="end_time">
|
||||
</div>
|
||||
<input type="datetime-local" class="form-control" id="event_add_end" name="end" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -87,7 +121,7 @@
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-recycle"></i></span>
|
||||
</div>
|
||||
<select class="form-control select2" name="repeat" disabled>
|
||||
<select class="form-control select2" name="repeat">
|
||||
<option value="">Never</option>
|
||||
<option>Day</option>
|
||||
<option>Week</option>
|
||||
|
||||
@@ -13,6 +13,18 @@ $event_location = escapeHtml($row['event_location']);
|
||||
$event_start = escapeHtml($row['event_start']);
|
||||
$event_end = escapeHtml($row['event_end']);
|
||||
$event_repeat = escapeHtml($row['event_repeat']);
|
||||
$event_all_day = intval($row['event_all_day'] ?? 0);
|
||||
|
||||
// Split the stored datetimes into the four fields the form now uses. An empty
|
||||
// event_end previously fed strtotime('') and rendered as 1970 - fall back to the
|
||||
// start instead.
|
||||
$event_start_ts = strtotime($event_start) ?: time();
|
||||
$event_end_ts = !empty($row['event_end']) ? (strtotime($event_end) ?: $event_start_ts) : $event_start_ts;
|
||||
|
||||
$event_start_date = date('Y-m-d', $event_start_ts);
|
||||
$event_start_time = date('H:i', $event_start_ts);
|
||||
$event_end_date = date('Y-m-d', $event_end_ts);
|
||||
$event_end_time = date('H:i', $event_end_ts);
|
||||
$calendar_id = intval($row['calendar_id']);
|
||||
$calendar_name = escapeHtml($row['calendar_name']);
|
||||
$calendar_color = escapeHtml($row['calendar_color']);
|
||||
@@ -89,22 +101,61 @@ ob_start();
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($event_repeat)) { ?>
|
||||
<div class="alert alert-info">
|
||||
<i class="fas fa-fw fa-redo mr-2"></i>
|
||||
This event repeats <strong>every <?= strtolower($event_repeat) ?></strong>.
|
||||
Saving or deleting affects <strong>every occurrence</strong> — a single
|
||||
occurrence cannot be moved or cancelled on its own.
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Start / End <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-calendar-check"></i></span>
|
||||
</div>
|
||||
<input type="datetime-local" class="form-control" name="start" value="<?= date('Y-m-d\TH:i:s', strtotime($event_start)) ?>" required>
|
||||
<div class="custom-control custom-switch">
|
||||
<input type="checkbox" class="custom-control-input event-all-day-toggle" id="event_edit_all_day" name="all_day" value="1" <?php if ($event_all_day) { echo "checked"; } ?>>
|
||||
<label class="custom-control-label" for="event_edit_all_day">All day</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-calendar-day"></i></span>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-6">
|
||||
<label>Date from <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-calendar-check"></i></span>
|
||||
</div>
|
||||
<input type="date" class="form-control event-start-date" id="event_edit_start_date" name="start_date" value="<?= $event_start_date ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label>Date to <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-calendar-day"></i></span>
|
||||
</div>
|
||||
<input type="date" class="form-control" id="event_edit_end_date" name="end_date" value="<?= $event_end_date ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row<?= $event_all_day ? ' d-none' : '' ?>" id="event_edit_time_fields">
|
||||
<div class="form-group col-md-6">
|
||||
<label>Time from <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-clock"></i></span>
|
||||
</div>
|
||||
<input type="time" class="form-control event-start-time" id="event_edit_start_time" name="start_time" value="<?= $event_start_time ?>"<?= $event_all_day ? '' : ' required' ?>>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label>Time to <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-clock"></i></span>
|
||||
</div>
|
||||
<input type="time" class="form-control" id="event_edit_end_time" name="end_time" value="<?= $event_end_time ?>"<?= $event_all_day ? '' : ' required' ?>>
|
||||
</div>
|
||||
<input type="datetime-local" class="form-control" name="end" value="<?= date('Y-m-d\TH:i:s', strtotime($event_end)) ?>"required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -114,7 +165,7 @@ ob_start();
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-recycle"></i></span>
|
||||
</div>
|
||||
<select class="form-control select2" name="repeat" disabled>
|
||||
<select class="form-control select2" name="repeat">
|
||||
<option <?php if (empty($event_repeat)) { echo "selected"; } ?> value="">Never</option>
|
||||
<option <?php if ($event_repeat == "Day") { echo "selected"; } ?>>Day</option>
|
||||
<option <?php if ($event_repeat == "Week") { echo "selected"; } ?>>Week</option>
|
||||
@@ -190,7 +241,7 @@ ob_start();
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a class="btn btn-default text-danger mr-auto" href="post.php?delete_event=<?= $event_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>"><i class="fa fa-calendar-times mr-2"></i>Delete</a>
|
||||
<a class="btn btn-default text-danger mr-auto confirm-link" href="post.php?delete_event=<?= $event_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>"><i class="fa fa-calendar-times mr-2"></i><?= empty($event_repeat) ? 'Delete' : 'Delete series' ?></a>
|
||||
<button type="submit" name="edit_event" class="btn btn-primary text-bold"><i class="fa fa-check mr-2"></i>Save</button>
|
||||
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fa fa-times mr-2"></i>Cancel</button>
|
||||
</div>
|
||||
|
||||
189
agent/modals/calendar/calendar_share.php
Normal file
189
agent/modals/calendar/calendar_share.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
$calendar_id = intval($_GET['id']);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM calendars WHERE calendar_id = $calendar_id LIMIT 1");
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$calendar_name = escapeHtml($row['calendar_name']);
|
||||
$calendar_color = escapeHtml($row['calendar_color']);
|
||||
$calendar_feed_key = escapeHtml($row['calendar_feed_key']);
|
||||
$calendar_feed_busy_only = intval($row['calendar_feed_busy_only']);
|
||||
$calendar_feed_created_at = escapeHtml($row['calendar_feed_created_at']);
|
||||
$calendar_feed_accessed_at = escapeHtml($row['calendar_feed_accessed_at']);
|
||||
|
||||
// $config_base_url lives in config.php (written at setup from HTTP_HOST, or from
|
||||
// the --base_url argument to setup_cli.php) and is expected to be a bare host.
|
||||
// Tolerate a scheme having been saved into it rather than emitting https://https://
|
||||
$base_url = rtrim(preg_replace('#^[a-z]+://#i', '', (string) $config_base_url), '/');
|
||||
$feed_path = "/guest/guest_calendar_feed.php?key=$calendar_feed_key";
|
||||
$feed_url_https = "https://$base_url$feed_path";
|
||||
$feed_url_webcal = "webcal://$base_url$feed_path";
|
||||
|
||||
// Generate the HTML form content using output buffering.
|
||||
ob_start();
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fas fa-fw fa-share-alt mr-2"></i>Share <?= $calendar_name ?></h5>
|
||||
<button type="button" class="close text-white" data-dismiss="modal">
|
||||
<span>×</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<?php if (empty($base_url)) { ?>
|
||||
|
||||
<div class="modal-body">
|
||||
<div class="alert alert-danger mb-0">
|
||||
<i class="fas fa-fw fa-exclamation-triangle mr-2"></i>
|
||||
<strong>$config_base_url is not set in config.php.</strong>
|
||||
Without it there is no hostname to build a subscription link from. Set it
|
||||
to the hostname this install is reached on and reopen this dialog.
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-light" data-dismiss="modal">
|
||||
<i class="fas fa-fw fa-times mr-2"></i>Close
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<?php } elseif (empty($calendar_feed_key)) { ?>
|
||||
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="calendar_id" value="<?= $calendar_id ?>">
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<p>
|
||||
Publishing <strong><?= $calendar_name ?></strong> creates a secret link that
|
||||
Google Calendar, Nextcloud, Apple Calendar or Thunderbird can subscribe to.
|
||||
</p>
|
||||
|
||||
<div class="alert alert-warning">
|
||||
<i class="fas fa-fw fa-exclamation-triangle mr-2"></i>
|
||||
Anyone with the link can read this calendar without logging in. Share it
|
||||
like a password, and revoke it here if it gets out.
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="custom-control custom-switch">
|
||||
<input type="checkbox" class="custom-control-input" id="feedBusyOnly" name="busy_only" value="1">
|
||||
<label class="custom-control-label" for="feedBusyOnly">
|
||||
Busy only — publish time blocks without titles, descriptions or locations
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="share_calendar" class="btn btn-primary">
|
||||
<i class="fas fa-fw fa-link mr-2"></i>Create link
|
||||
</button>
|
||||
<button type="button" class="btn btn-light" data-dismiss="modal">
|
||||
<i class="fas fa-fw fa-times mr-2"></i>Cancel
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php } else { ?>
|
||||
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="calendar_id" value="<?= $calendar_id ?>">
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="form-group">
|
||||
<label>Subscription link</label>
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" value="<?= $feed_url_https ?>" readonly onclick="this.select();">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-secondary clipboardjs" type="button" data-clipboard-text="<?= $feed_url_https ?>" title="Copy link">
|
||||
<i class="far fa-fw fa-copy"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<small class="form-text text-muted">
|
||||
Paste this into <strong>Google Calendar</strong> → Other calendars → From URL,
|
||||
or <strong>Nextcloud Calendar</strong> → New calendar → New subscription.
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Or open directly in a desktop calendar app</label>
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" value="<?= $feed_url_webcal ?>" readonly onclick="this.select();">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-secondary clipboardjs" type="button" data-clipboard-text="<?= $feed_url_webcal ?>" title="Copy link">
|
||||
<i class="far fa-fw fa-copy"></i>
|
||||
</button>
|
||||
<a class="btn btn-secondary" href="<?= $feed_url_webcal ?>" title="Open">
|
||||
<i class="fas fa-fw fa-external-link-alt"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="custom-control custom-switch">
|
||||
<input type="checkbox" class="custom-control-input" id="feedBusyOnly" name="busy_only" value="1" <?php if ($calendar_feed_busy_only == 1) { echo "checked"; } ?>>
|
||||
<label class="custom-control-label" for="feedBusyOnly">
|
||||
Busy only — publish time blocks without titles, descriptions or locations
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<dl class="row mb-0 text-muted">
|
||||
<dt class="col-5">Link created</dt>
|
||||
<dd class="col-7"><?= $calendar_feed_created_at ?: 'Unknown' ?></dd>
|
||||
<dt class="col-5">Last fetched</dt>
|
||||
<dd class="col-7"><?= $calendar_feed_accessed_at ?: 'Never' ?></dd>
|
||||
</dl>
|
||||
|
||||
<div class="alert alert-secondary mt-3 mb-0">
|
||||
<i class="fas fa-fw fa-info-circle mr-2"></i>
|
||||
Subscriptions are read-only, and clients decide how often to refresh.
|
||||
Google refreshes on its own schedule (often 12–24 hours) and cannot be
|
||||
forced. Nextcloud defaults to once a week unless
|
||||
<code>calendarSubscriptionRefreshRate</code> is lowered, and refuses
|
||||
subscriptions pointing at a private IP address.
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer justify-content-between">
|
||||
<div>
|
||||
<button type="submit" name="share_calendar" class="btn btn-primary">
|
||||
<i class="fas fa-fw fa-check mr-2"></i>Save
|
||||
</button>
|
||||
<button type="button" class="btn btn-light" data-dismiss="modal">
|
||||
<i class="fas fa-fw fa-times mr-2"></i>Close
|
||||
</button>
|
||||
</div>
|
||||
<div class="dropdown dropup">
|
||||
<button class="btn btn-light" type="button" data-toggle="dropdown">
|
||||
<i class="fas fa-fw fa-ellipsis-v"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu dropdown-menu-right">
|
||||
<a class="dropdown-item confirm-link" href="post.php?regenerate_calendar_feed=<?= $calendar_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-sync mr-2"></i>Regenerate link
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?unshare_calendar=<?= $calendar_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-unlink mr-2"></i>Stop sharing
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<?php
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
@@ -68,6 +68,103 @@ if (isset($_GET['delete_calendar'])) {
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['share_calendar'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
// Publishing a calendar mints an unauthenticated public URL, so keep it to
|
||||
// admins. This is a deliberately narrow check using $session_is_admin rather
|
||||
// than the module permission system - calendars are not owned by a module.
|
||||
enforceAdminPermission();
|
||||
|
||||
$calendar_id = intval($_POST['calendar_id']);
|
||||
$busy_only = isset($_POST['busy_only']) ? 1 : 0;
|
||||
|
||||
$calendar_name = escapeSql(getFieldById('calendars', $calendar_id, 'calendar_name'));
|
||||
$existing_key = getFieldById('calendars', $calendar_id, 'calendar_feed_key');
|
||||
|
||||
if (empty($existing_key)) {
|
||||
|
||||
// 32 URL-safe base64 chars (~192 bits). Stored in cleartext, like
|
||||
// invoice_url_key, so the link stays re-copyable for a second device.
|
||||
$feed_key = escapeSql(randomString(32));
|
||||
|
||||
mysqli_query($mysqli, "UPDATE calendars SET
|
||||
calendar_feed_key = '$feed_key',
|
||||
calendar_feed_busy_only = $busy_only,
|
||||
calendar_feed_created_at = NOW()
|
||||
WHERE calendar_id = $calendar_id");
|
||||
|
||||
logAudit("Calendar", "Share", "$session_name published calendar $calendar_name as a read-only feed", 0, $calendar_id);
|
||||
|
||||
flashAlert("Calendar <strong>$calendar_name</strong> published - copy the subscription link from the share dialog");
|
||||
|
||||
} else {
|
||||
|
||||
mysqli_query($mysqli, "UPDATE calendars SET
|
||||
calendar_feed_busy_only = $busy_only
|
||||
WHERE calendar_id = $calendar_id");
|
||||
|
||||
logAudit("Calendar", "Edit", "$session_name updated feed settings for calendar $calendar_name", 0, $calendar_id);
|
||||
|
||||
flashAlert("Feed settings for <strong>$calendar_name</strong> updated");
|
||||
}
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['regenerate_calendar_feed'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceAdminPermission();
|
||||
|
||||
$calendar_id = intval($_GET['regenerate_calendar_feed']);
|
||||
|
||||
$calendar_name = escapeSql(getFieldById('calendars', $calendar_id, 'calendar_name'));
|
||||
|
||||
$feed_key = escapeSql(randomString(32));
|
||||
|
||||
mysqli_query($mysqli, "UPDATE calendars SET
|
||||
calendar_feed_key = '$feed_key',
|
||||
calendar_feed_created_at = NOW(),
|
||||
calendar_feed_accessed_at = NULL
|
||||
WHERE calendar_id = $calendar_id");
|
||||
|
||||
logAudit("Calendar", "Share", "$session_name regenerated the feed link for calendar $calendar_name", 0, $calendar_id);
|
||||
|
||||
flashAlert("Feed link for <strong>$calendar_name</strong> regenerated - existing subscribers will stop updating and must re-subscribe", 'error');
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['unshare_calendar'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceAdminPermission();
|
||||
|
||||
$calendar_id = intval($_GET['unshare_calendar']);
|
||||
|
||||
$calendar_name = escapeSql(getFieldById('calendars', $calendar_id, 'calendar_name'));
|
||||
|
||||
mysqli_query($mysqli, "UPDATE calendars SET
|
||||
calendar_feed_key = NULL,
|
||||
calendar_feed_busy_only = 0,
|
||||
calendar_feed_created_at = NULL,
|
||||
calendar_feed_accessed_at = NULL
|
||||
WHERE calendar_id = $calendar_id");
|
||||
|
||||
logAudit("Calendar", "Share", "$session_name stopped sharing calendar $calendar_name", 0, $calendar_id);
|
||||
|
||||
flashAlert("Calendar <strong>$calendar_name</strong> is no longer shared", 'error');
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['add_event'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
@@ -79,7 +176,7 @@ if (isset($_POST['add_event'])) {
|
||||
enforceClientAccess();
|
||||
}
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO calendar_events SET event_title = '$title', event_location = '$location', event_description = '$description', event_start = '$start', event_end = '$end', event_repeat = '$repeat', event_calendar_id = $calendar_id, event_client_id = $client_id");
|
||||
mysqli_query($mysqli,"INSERT INTO calendar_events SET event_title = '$title', event_location = '$location', event_description = '$description', event_start = '$start', event_end = '$end', event_all_day = $all_day, event_repeat = '$repeat', event_calendar_id = $calendar_id, event_client_id = $client_id");
|
||||
|
||||
$event_id = mysqli_insert_id($mysqli);
|
||||
|
||||
@@ -158,7 +255,7 @@ if (isset($_POST['edit_event'])) {
|
||||
|
||||
$event_id = intval($_POST['event_id']);
|
||||
|
||||
mysqli_query($mysqli,"UPDATE calendar_events SET event_title = '$title', event_location = '$location', event_description = '$description', event_start = '$start', event_end = '$end', event_repeat = '$repeat', event_calendar_id = $calendar_id, event_client_id = $client_id WHERE event_id = $event_id");
|
||||
mysqli_query($mysqli,"UPDATE calendar_events SET event_title = '$title', event_location = '$location', event_description = '$description', event_start = '$start', event_end = '$end', event_all_day = $all_day, event_repeat = '$repeat', event_calendar_id = $calendar_id, event_client_id = $client_id WHERE event_id = $event_id");
|
||||
|
||||
//If email is checked
|
||||
if ($email_event == 1) {
|
||||
|
||||
@@ -5,8 +5,37 @@ $calendar_id = intval($_POST['calendar']);
|
||||
$title = escapeSql($_POST['title']);
|
||||
$location = escapeSql($_POST['location']);
|
||||
$description = escapeSql($_POST['description']);
|
||||
$start = escapeSql($_POST['start']);
|
||||
$end = escapeSql($_POST['end']);
|
||||
$all_day = isset($_POST['all_day']) ? 1 : 0;
|
||||
|
||||
/*
|
||||
* The form posts the date and the time as separate fields, so recombine them into
|
||||
* the DATETIME columns.
|
||||
*
|
||||
* All-day events are pinned to midnight at both ends, and event_end holds the LAST
|
||||
* DAY the event covers - the same thing the form asks for. Both FullCalendar and
|
||||
* iCalendar treat an all-day end as exclusive, so the render and feed paths add a
|
||||
* day; do not add one here as well.
|
||||
*/
|
||||
$start_date = $_POST['start_date'] ?? '';
|
||||
$end_date = !empty($_POST['end_date']) ? $_POST['end_date'] : $start_date;
|
||||
|
||||
if ($all_day) {
|
||||
$start_raw = "$start_date 00:00:00";
|
||||
$end_raw = "$end_date 00:00:00";
|
||||
} else {
|
||||
$start_time = !empty($_POST['start_time']) ? $_POST['start_time'] : '00:00';
|
||||
$end_time = !empty($_POST['end_time']) ? $_POST['end_time'] : $start_time;
|
||||
$start_raw = "$start_date $start_time";
|
||||
$end_raw = "$end_date $end_time";
|
||||
}
|
||||
|
||||
// A malformed value would otherwise land in 1970 via strtotime() returning false
|
||||
$start_ts = strtotime($start_raw) ?: time();
|
||||
$end_ts = strtotime($end_raw) ?: $start_ts;
|
||||
|
||||
$start = escapeSql(date('Y-m-d H:i:s', $start_ts));
|
||||
$end = escapeSql(date('Y-m-d H:i:s', $end_ts));
|
||||
|
||||
$repeat = escapeSql($_POST['repeat'] ?? 0);
|
||||
$client_id = intval($_POST['client_id']);
|
||||
$email_event = intval($_POST['email_event'] ?? 0);
|
||||
|
||||
Reference in New Issue
Block a user