Recurring tickets and events can repeat on a weekday, such as the third Wednesday or the last Friday, instead of the same date: monthly, quarterly, twice-yearly and yearly recurring tickets and monthly and yearly events get Repeats on once a date is picked, moving the next run or an event's start keeps the same kind of weekday, the recurring tickets list, events and invitations say which, and subscribed calendars get it as an RRULE BYDAY; the API takes repeat_on and event_repeat_by_day; database 3.8.3 adds recurring_tickets.recurring_ticket_by_day and calendar_events.event_repeat_by_day; 26.11.9 changelog entries

This commit is contained in:
johnnyq
2026-11-17 20:51:53 -05:00
parent 512ac75c73
commit d69015e2c7
23 changed files with 413 additions and 26 deletions

View File

@@ -113,6 +113,7 @@ $form_can_email = calendarCanEmail();
<input type="date" class="form-control" name="repeat_until" id="eventRepeatUntil" value="<?= escapeHtml($form['event_repeat_until'] ?? '') ?>">
</div>
</div>
<?= byDayField('[name=start_date]', '[name=repeat]', ['Month', 'Year'], ['Year'], $form['event_repeat_by_day'] ?? '', 'col-md-8', 'form-label small text-body-secondary mb-1') ?>
</div>
<?php if (calendarSkippedDates($form)) { ?>
<div class="small text-body-secondary mt-2"><i class="fas fa-fw fa-forward me-1"></i>Skipped: <?= escapeHtml(implode(', ', array_map(function ($date) {

View File

@@ -213,6 +213,8 @@ ob_start();
<div class="form-text">The nightly cron raises a ticket on this day, then again each time it comes round. Monthly ones keep to this day of the month - the last day, in a shorter month.</div>
</div>
<?= byDayField('[name=start_date]', '[name=frequency]', ['Monthly', 'Quarterly', 'Biannually', 'Annually'], ['Annually'], '') ?>
<?php $ahead_row = null; require __DIR__ . '/../../includes/inc_recurring_ticket_ahead.php'; ?>
</div>

View File

@@ -210,6 +210,8 @@ ob_start();
</div>
</div>
<?= byDayField('[name=next_date]', '[name=frequency]', ['Monthly', 'Quarterly', 'Biannually', 'Annually'], ['Annually'], $recurring['recurring_ticket_by_day'] ?? '') ?>
<?php $ahead_row = $recurring; require __DIR__ . '/../../includes/inc_recurring_ticket_ahead.php'; ?>
<div class="small text-body-secondary">

View File

@@ -256,7 +256,7 @@ if (isset($_POST['edit_event'])) {
enforceCalendarEvent(['event_client_id' => $client_id], 'edit');
}
$set = calendarEventFormSet($_POST, $client_id, $error);
$set = calendarEventFormSet($_POST + ['repeat_on_current' => $old['event_repeat_by_day'] ?? ''], $client_id, $error);
if ($set === '') {
flashAlert($error, 'error');
redirect();
@@ -267,7 +267,7 @@ if (isset($_POST['edit_event'])) {
// A change a calendar that already has it needs to know about moves it on a version
$event = calendarEventRow($event_id);
$changed = false;
foreach (['event_title', 'event_start', 'event_end', 'event_all_day', 'event_location', 'event_location_id', 'event_description', 'event_repeat', 'event_repeat_interval', 'event_repeat_until'] as $field) {
foreach (array_merge(['event_title', 'event_start', 'event_end', 'event_all_day', 'event_location', 'event_location_id', 'event_description', 'event_repeat', 'event_repeat_interval', 'event_repeat_until'], byDayReady() ? ['event_repeat_by_day'] : []) as $field) {
if ((string) $old[$field] !== (string) $event[$field]) {
$changed = true;
}

View File

@@ -135,11 +135,14 @@ if (isset($_POST['add_recurring_ticket'])) {
$f = recurringTicketFromPost($client_id);
// The weekday it repeats on - the third Wednesday - when the first run falls on it
$by_day_sql = byDayReady() ? ", recurring_ticket_by_day = " . recurringTicketByDaySql($f['frequency'], $start_date, $_POST['repeat_on'] ?? '') : '';
mysqli_query($mysqli, "INSERT INTO recurring_tickets SET recurring_ticket_subject = '{$f['subject']}', recurring_ticket_details = '{$f['details']}',
recurring_ticket_priority = '{$f['priority']}', recurring_ticket_frequency = '{$f['frequency']}', recurring_ticket_billable = {$f['billable']},
recurring_ticket_start_date = '$start_date', recurring_ticket_next_run = '$start_date', recurring_ticket_assigned_to = {$f['assigned_to']},
recurring_ticket_created_by = $session_user_id, recurring_ticket_client_id = $client_id, recurring_ticket_contact_id = {$f['contact_id']},
recurring_ticket_asset_id = {$f['asset_id']}, recurring_ticket_category = {$f['category_id']}, recurring_ticket_ticket_template_id = {$f['template_id']} {$f['ahead']}");
recurring_ticket_asset_id = {$f['asset_id']}, recurring_ticket_category = {$f['category_id']}, recurring_ticket_ticket_template_id = {$f['template_id']} {$f['ahead']} $by_day_sql");
$recurring_ticket_id = mysqli_insert_id($mysqli);
@@ -181,10 +184,13 @@ if (isset($_POST['edit_recurring_ticket'])) {
// A run moved by hand is the new anchor - monthly ones keep to its day of the month from here
$anchor_sql = $next_run !== $current_next_run ? ", recurring_ticket_start_date = '$next_run'" : '';
// The weekday it repeats on, as picked - or, from a form without the field, the one it had, following a moved run
$by_day_sql = byDayReady() ? ", recurring_ticket_by_day = " . recurringTicketByDaySql($f['frequency'], $next_run, isset($_POST['repeat_on_field']) ? ($_POST['repeat_on'] ?? '') : null, $row['recurring_ticket_by_day'] ?? '') : '';
mysqli_query($mysqli, "UPDATE recurring_tickets SET recurring_ticket_subject = '{$f['subject']}', recurring_ticket_details = '{$f['details']}',
recurring_ticket_priority = '{$f['priority']}', recurring_ticket_frequency = '{$f['frequency']}', recurring_ticket_billable = {$f['billable']},
recurring_ticket_next_run = '$next_run' $anchor_sql, recurring_ticket_assigned_to = {$f['assigned_to']}, recurring_ticket_asset_id = {$f['asset_id']},
recurring_ticket_contact_id = {$f['contact_id']}, recurring_ticket_category = {$f['category_id']}, recurring_ticket_ticket_template_id = {$f['template_id']} {$f['ahead']}
recurring_ticket_contact_id = {$f['contact_id']}, recurring_ticket_category = {$f['category_id']}, recurring_ticket_ticket_template_id = {$f['template_id']} {$f['ahead']} $by_day_sql
WHERE recurring_ticket_id = $recurring_ticket_id");
// The other assets go with the asset field - an empty multi-select posts nothing
@@ -264,7 +270,7 @@ if (isset($_GET['pause_recurring_ticket']) || isset($_GET['resume_recurring_tick
// Runs it missed while paused are not raised now - it picks up from today
$next_run = substr((string) $row['recurring_ticket_next_run'], 0, 10);
if ($next_run < date('Y-m-d')) {
$next_run = recurringTicketNextRun($next_run, $row['recurring_ticket_frequency'], $row['recurring_ticket_start_date'], date('Y-m-d', strtotime('-1 day')));
$next_run = recurringTicketNextRun($next_run, $row['recurring_ticket_frequency'], $row['recurring_ticket_start_date'], date('Y-m-d', strtotime('-1 day')), $row['recurring_ticket_by_day'] ?? '');
}
mysqli_query($mysqli, "UPDATE recurring_tickets SET recurring_ticket_paused_at = NULL, recurring_ticket_next_run = '$next_run' WHERE recurring_ticket_id = $recurring_ticket_id");
}
@@ -292,7 +298,7 @@ if (isset($_POST['bulk_pause_recurring_tickets']) || isset($_POST['bulk_resume_r
} else {
$next_run = substr((string) $row['recurring_ticket_next_run'], 0, 10);
if ($next_run < date('Y-m-d')) {
$next_run = recurringTicketNextRun($next_run, $row['recurring_ticket_frequency'], $row['recurring_ticket_start_date'], date('Y-m-d', strtotime('-1 day')));
$next_run = recurringTicketNextRun($next_run, $row['recurring_ticket_frequency'], $row['recurring_ticket_start_date'], date('Y-m-d', strtotime('-1 day')), $row['recurring_ticket_by_day'] ?? '');
}
mysqli_query($mysqli, "UPDATE recurring_tickets SET recurring_ticket_paused_at = NULL, recurring_ticket_next_run = '$next_run' WHERE recurring_ticket_id = $recurring_ticket_id");
}
@@ -455,8 +461,9 @@ if (isset($_POST['bulk_edit_recurring_ticket_next_run_date'])) {
$count = 0;
foreach (recurringTicketsForBulk(2) as $recurring_ticket_id => $row) {
// A run moved by hand is the new anchor for the day of the month
mysqli_query($mysqli, "UPDATE recurring_tickets SET recurring_ticket_next_run = '$next_run', recurring_ticket_start_date = '$next_run' WHERE recurring_ticket_id = $recurring_ticket_id");
// A run moved by hand is the new anchor for the day of the month - and a weekday rule follows it
$by_day_sql = byDayReady() ? ", recurring_ticket_by_day = " . recurringTicketByDaySql($row['recurring_ticket_frequency'], $next_run, null, $row['recurring_ticket_by_day'] ?? '') : '';
mysqli_query($mysqli, "UPDATE recurring_tickets SET recurring_ticket_next_run = '$next_run', recurring_ticket_start_date = '$next_run' $by_day_sql WHERE recurring_ticket_id = $recurring_ticket_id");
logAudit("Recurring Ticket", "Edit", "$session_name moved the next run of recurring ticket " . escapeSql($row['recurring_ticket_subject']) . " from " . escapeSql($row['recurring_ticket_next_run']) . " to $next_run", intval($row['recurring_ticket_client_id']), $recurring_ticket_id);
triggerCustomAction('recurring_ticket_update', $recurring_ticket_id);
$count++;