mirror of
https://github.com/itflow-org/itflow
synced 2026-11-27 22:59:00 +00:00
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:
134
functions/by_day.php
Normal file
134
functions/by_day.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - Repeats by weekday: "the third Wednesday" or "the last Friday" of the month, for
|
||||
* recurring tickets and repeating calendar events (database 3.8.3).
|
||||
*
|
||||
* A rule is kept the way calendars write it (RFC 5545 BYDAY): an ordinal and a weekday - 1 to 4
|
||||
* for the first to fourth, -1 for the last - so "3WE" is the third Wednesday and "-1FR" the last
|
||||
* Friday. No rule is the same date each month, as before. The choices offered come from the date
|
||||
* picked (byDayOptions()), so a rule always matches its first run, and a rule moves with its date
|
||||
* when that's changed (byDayFollow()). js/repeat_on.js draws the Repeats on field from the date.
|
||||
* recurring_tickets.recurring_ticket_by_day - monthly, quarterly, twice-yearly and yearly ones
|
||||
* calendar_events.event_repeat_by_day - monthly and yearly events
|
||||
*/
|
||||
|
||||
const BY_DAY_WEEKDAYS = ['MO' => 'Monday', 'TU' => 'Tuesday', 'WE' => 'Wednesday', 'TH' => 'Thursday', 'FR' => 'Friday', 'SA' => 'Saturday', 'SU' => 'Sunday'];
|
||||
const BY_DAY_ORDINALS = [1 => 'first', 2 => 'second', 3 => 'third', 4 => 'fourth', -1 => 'last'];
|
||||
|
||||
/** Whether the 3.8.3 update has run. */
|
||||
function byDayReady() {
|
||||
global $mysqli;
|
||||
static $ready = null;
|
||||
if ($ready === null) {
|
||||
if (defined('CURRENT_DATABASE_VERSION')) {
|
||||
$version = CURRENT_DATABASE_VERSION;
|
||||
} else {
|
||||
$result = mysqli_query($mysqli, "SELECT config_current_database_version FROM settings WHERE company_id = 1");
|
||||
$version = $result && ($row = mysqli_fetch_row($result)) ? (string) $row[0] : '0';
|
||||
}
|
||||
$ready = version_compare($version, '3.8.3', '>=');
|
||||
}
|
||||
return $ready;
|
||||
}
|
||||
|
||||
/** The rule tidied ("3WE", "-1FR"), or '' when it isn't one. */
|
||||
function byDayRule($rule) {
|
||||
$rule = strtoupper(trim((string) $rule));
|
||||
return preg_match('/^(-1|[1-4])(MO|TU|WE|TH|FR|SA|SU)$/', $rule) ? $rule : '';
|
||||
}
|
||||
|
||||
/** [ordinal, weekday code] of a rule - [0, ''] for none. */
|
||||
function byDayParts($rule) {
|
||||
$rule = byDayRule($rule);
|
||||
return $rule === '' ? [0, ''] : [intval(substr($rule, 0, -2)), substr($rule, -2)];
|
||||
}
|
||||
|
||||
/** The date ('Y-m-d') a rule falls on in a month - the first to fourth and the last of a weekday are in every month. */
|
||||
function byDayDate($year, $month, $rule) {
|
||||
[$ordinal, $code] = byDayParts($rule);
|
||||
if (!$ordinal) {
|
||||
return null;
|
||||
}
|
||||
$weekday = array_search($code, array_keys(BY_DAY_WEEKDAYS)) + 1; // ISO, 1 (Monday) to 7 (Sunday)
|
||||
$days = intval(date('t', mktime(0, 0, 0, $month, 1, $year)));
|
||||
if ($ordinal > 0) {
|
||||
$first = intval(date('N', mktime(0, 0, 0, $month, 1, $year)));
|
||||
$day = 1 + (($weekday - $first + 7) % 7) + ($ordinal - 1) * 7;
|
||||
} else {
|
||||
$last = intval(date('N', mktime(0, 0, 0, $month, $days, $year)));
|
||||
$day = $days - (($last - $weekday + 7) % 7);
|
||||
}
|
||||
return sprintf('%04d-%02d-%02d', $year, $month, $day);
|
||||
}
|
||||
|
||||
/** "the third Wednesday", "the last Friday" - '' for no rule. */
|
||||
function byDayText($rule) {
|
||||
[$ordinal, $code] = byDayParts($rule);
|
||||
return $ordinal ? 'the ' . BY_DAY_ORDINALS[$ordinal] . ' ' . BY_DAY_WEEKDAYS[$code] : '';
|
||||
}
|
||||
|
||||
/*
|
||||
* The weekday rules a date can repeat on: its weekday of the month when that's the first to
|
||||
* fourth, and the last when it's in the month's last seven days - [rule => "the third Wednesday"].
|
||||
*/
|
||||
function byDayOptions($date) {
|
||||
$ts = strtotime(substr((string) $date, 0, 10));
|
||||
if (!$ts) {
|
||||
return [];
|
||||
}
|
||||
$code = array_keys(BY_DAY_WEEKDAYS)[intval(date('N', $ts)) - 1];
|
||||
$day = intval(date('j', $ts));
|
||||
$options = [];
|
||||
$nth = intdiv($day - 1, 7) + 1;
|
||||
if ($nth <= 4) {
|
||||
$options[$nth . $code] = byDayText($nth . $code);
|
||||
}
|
||||
if ($day + 7 > intval(date('t', $ts))) {
|
||||
$options['-1' . $code] = byDayText('-1' . $code);
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
/** A posted rule, kept only when the date can repeat on it - else ''. */
|
||||
function byDayForDate($rule, $date) {
|
||||
$rule = byDayRule($rule);
|
||||
return $rule !== '' && isset(byDayOptions($date)[$rule]) ? $rule : '';
|
||||
}
|
||||
|
||||
/*
|
||||
* A rule carried to a new date - a run or an event moved by hand: kept while the new date still
|
||||
* fits it, otherwise the same kind of rule for the new date, the last staying the last when it can.
|
||||
*/
|
||||
function byDayFollow($rule, $date) {
|
||||
$rule = byDayRule($rule);
|
||||
if ($rule === '' || byDayForDate($rule, $date) !== '') {
|
||||
return $rule;
|
||||
}
|
||||
$options = array_keys(byDayOptions($date));
|
||||
$last = array_values(array_filter($options, function ($option) { return strpos($option, '-1') === 0; }));
|
||||
$nth = array_values(array_filter($options, function ($option) { return strpos($option, '-1') !== 0; }));
|
||||
if (strpos($rule, '-1') === 0) {
|
||||
return $last[0] ?? ($nth[0] ?? '');
|
||||
}
|
||||
return $nth[0] ?? ($last[0] ?? '');
|
||||
}
|
||||
|
||||
/*
|
||||
* The Repeats on field (js/repeat_on.js fills it from the date): $date and $frequency are
|
||||
* selectors for those fields in the same form, $months the frequency values it's for, $yearly
|
||||
* those worded "of October". Posts repeat_on - nothing while hidden, so repeat_on_field says the
|
||||
* form had it. Nothing before the update.
|
||||
*/
|
||||
function byDayField($date, $frequency, array $months, array $yearly, $current, $wrap_class = 'mb-3', $label_class = '') {
|
||||
if (!byDayReady()) {
|
||||
return '';
|
||||
}
|
||||
return '<input type="hidden" name="repeat_on_field" value="1"><div class="' . escapeHtml($wrap_class) . '" data-repeat-on-wrap hidden>'
|
||||
. '<label' . ($label_class !== '' ? ' class="' . escapeHtml($label_class) . '"' : '') . '>Repeats on</label>'
|
||||
. '<div class="input-group"><span class="input-group-text"><i class="fas fa-fw fa-calendar-week"></i></span>'
|
||||
. '<select class="form-select select2" name="repeat_on" data-repeat-on data-date="' . escapeHtml($date) . '" data-frequency="' . escapeHtml($frequency) . '"'
|
||||
. ' data-months="' . escapeHtml(implode(',', $months)) . '" data-yearly="' . escapeHtml(implode(',', $yearly)) . '" data-current="' . escapeHtml(byDayRule($current)) . '" disabled></select></div>'
|
||||
. '<div class="form-text">The same date each time, or the same weekday - the third Wednesday, or the last Friday.</div>'
|
||||
. '</div><script src="' . staticFileUrl('/js/repeat_on.js') . '"></script>';
|
||||
}
|
||||
@@ -257,7 +257,7 @@ function calendarEventRepeats($row) {
|
||||
return isset(CALENDAR_REPEATS[(string) ($row['event_repeat'] ?? '')]);
|
||||
}
|
||||
|
||||
/** "Every week", "Every 2 weeks until Mar 3, 2027", or '' for an event that does not repeat. */
|
||||
/** "Every week", "Every month on the third Wednesday", "Every 2 weeks until Mar 3, 2027", or '' for an event that does not repeat. */
|
||||
function calendarRepeatText($row) {
|
||||
if (!calendarEventRepeats($row)) {
|
||||
return '';
|
||||
@@ -265,12 +265,21 @@ function calendarRepeatText($row) {
|
||||
$interval = max(1, intval($row['event_repeat_interval'] ?? 1));
|
||||
[, $one, $many] = CALENDAR_REPEATS[(string) $row['event_repeat']];
|
||||
$text = $interval === 1 ? "Every $one" : "Every $interval $many";
|
||||
$by_day = calendarEventByDay($row);
|
||||
if ($by_day !== '') {
|
||||
$text .= ' on ' . byDayText($by_day) . ($row['event_repeat'] === 'Year' ? ' of ' . date('F', strtotime($row['event_start'])) : '');
|
||||
}
|
||||
if (!empty($row['event_repeat_until'])) {
|
||||
$text .= ' until ' . date('M j, Y', strtotime($row['event_repeat_until']));
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
/** The weekday a monthly or yearly event repeats on ("3WE", functions/by_day.php) - '' for the same date each time. */
|
||||
function calendarEventByDay($row) {
|
||||
return in_array($row['event_repeat'] ?? '', ['Month', 'Year'], true) ? byDayRule($row['event_repeat_by_day'] ?? '') : '';
|
||||
}
|
||||
|
||||
/** The dates of occurrences that have been skipped - ['Y-m-d', ...]. */
|
||||
function calendarSkippedDates($row) {
|
||||
$skip = trim((string) ($row['event_repeat_skip'] ?? ''));
|
||||
@@ -291,6 +300,7 @@ function calendarSkippedDates($row) {
|
||||
* running date, so a long series cannot drift and a 9:00 meeting stays at 9:00
|
||||
* either side of a DST change. Monthly on the 31st and yearly on Feb 29 skip the
|
||||
* months without that day, as RFC 5545 does, rather than rolling into the next.
|
||||
* One on a weekday of the month (event_repeat_by_day) is on that day of each one.
|
||||
*
|
||||
* An occurrence still under way at the start of the window is included. The
|
||||
* bundled FullCalendar build has no rrule plugin, so the page gets the
|
||||
@@ -326,12 +336,18 @@ function expandRecurringEvent(array $event, $window_start, $window_end, $limit =
|
||||
$skip = array_flip(calendarSkippedDates($event));
|
||||
$step = ['Day' => 'day', 'Week' => 'week', 'Month' => 'month', 'Year' => 'year'][$repeat];
|
||||
$base_day = (int) $base->format('j');
|
||||
$by_day = calendarEventByDay($event);
|
||||
|
||||
$occurrences = [];
|
||||
for ($i = 0; count($occurrences) < $limit && $i < 50000; $i++) {
|
||||
|
||||
$candidate = clone $base;
|
||||
if ($i > 0) {
|
||||
if ($i > 0 && $by_day !== '') {
|
||||
// Stepped from the 1st, so no month is passed over, then put on the rule's day - at the same time
|
||||
$candidate->setDate((int) $base->format('Y'), (int) $base->format('n'), 1);
|
||||
$candidate->modify('+' . ($i * $interval) . " $step");
|
||||
$candidate->setDate((int) $candidate->format('Y'), (int) $candidate->format('n'), (int) substr(byDayDate((int) $candidate->format('Y'), (int) $candidate->format('n'), $by_day), 8, 2));
|
||||
} elseif ($i > 0) {
|
||||
$candidate->modify('+' . ($i * $interval) . " $step");
|
||||
if (($step === 'month' || $step === 'year') && (int) $candidate->format('j') !== $base_day) {
|
||||
if ($candidate > $to) {
|
||||
@@ -546,11 +562,24 @@ function calendarEventFormSet($post, $client_id, &$error = '') {
|
||||
$location_id = intval(assetClientOwnedId('location', $post['location_id'], $client_id));
|
||||
}
|
||||
|
||||
// The weekday a monthly or yearly one repeats on (functions/by_day.php) - the one picked, when the
|
||||
// start falls on it; from a form without the field, the one it had ('repeat_on_current') follows the start
|
||||
$by_day_sql = '';
|
||||
if (byDayReady()) {
|
||||
$by_day = '';
|
||||
if ($repeat === 'Month' || $repeat === 'Year') {
|
||||
$by_day = isset($post['repeat_on_field']) || array_key_exists('repeat_on', $post)
|
||||
? byDayForDate($post['repeat_on'] ?? '', $start_date)
|
||||
: byDayFollow($post['repeat_on_current'] ?? '', $start_date);
|
||||
}
|
||||
$by_day_sql = ", event_repeat_by_day = " . ($by_day !== '' ? "'$by_day'" : 'NULL');
|
||||
}
|
||||
|
||||
return "event_title = '" . escapeSql(mb_substr($title, 0, 200)) . "',
|
||||
event_location = '" . escapeSql(mb_substr(trim((string) ($post['location'] ?? '')), 0, 500)) . "',
|
||||
event_description = '" . escapeSql(trim((string) ($post['description'] ?? ''))) . "',
|
||||
event_start = '$start', event_end = '$end', event_all_day = $all_day,
|
||||
event_repeat = '$repeat', event_repeat_interval = $interval, event_repeat_until = " . ($until !== '' ? "'$until'" : 'NULL') . ",
|
||||
event_repeat = '$repeat', event_repeat_interval = $interval, event_repeat_until = " . ($until !== '' ? "'$until'" : 'NULL') . "$by_day_sql,
|
||||
event_calendar_id = $calendar_id, event_client_id = " . intval($client_id) . ", event_location_id = $location_id";
|
||||
}
|
||||
|
||||
@@ -767,7 +796,7 @@ function calendarEventItems(array $calendar_ids, $from, $to, array $opts = []) {
|
||||
$user_id = intval($opts['user_id'] ?? 0);
|
||||
$user_query = $user_id ? "AND (event_created_by = $user_id OR EXISTS (SELECT 1 FROM calendar_event_attendees a WHERE a.attendee_event_id = event_id AND a.attendee_user_id = $user_id))" : '';
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT event_id, event_title, event_start, event_end, event_all_day, event_repeat, event_repeat_interval, event_repeat_until, event_repeat_skip,
|
||||
$sql = mysqli_query($mysqli, "SELECT event_id, event_title, event_start, event_end, event_all_day, event_repeat, event_repeat_interval, event_repeat_until, event_repeat_skip," . (byDayReady() ? " event_repeat_by_day," : "") . "
|
||||
event_location, event_client_id, event_calendar_id, event_created_by, calendar_color, client_name, location_name,
|
||||
(SELECT COUNT(*) FROM calendar_event_attendees a WHERE a.attendee_event_id = event_id) AS attendee_count,
|
||||
(SELECT COUNT(*) FROM calendar_event_attendees a WHERE a.attendee_event_id = event_id AND a.attendee_invited_at IS NOT NULL) AS invited_count
|
||||
@@ -971,7 +1000,7 @@ function icsVtimezone($timezone, $from, $to) {
|
||||
* UTC (RFC 5545 requires UTC when DTSTART carries a TZID); an all-day event's
|
||||
* is the date itself.
|
||||
*/
|
||||
function icsRepeatToRrule($repeat, $interval = 1, $until = null, $all_day = false, $timezone = 'UTC') {
|
||||
function icsRepeatToRrule($repeat, $interval = 1, $until = null, $all_day = false, $timezone = 'UTC', $by_day = '', $start = null) {
|
||||
|
||||
if (!isset(CALENDAR_REPEATS[(string) $repeat])) {
|
||||
return null;
|
||||
@@ -981,6 +1010,11 @@ function icsRepeatToRrule($repeat, $interval = 1, $until = null, $all_day = fals
|
||||
if (intval($interval) > 1) {
|
||||
$rule .= ';INTERVAL=' . intval($interval);
|
||||
}
|
||||
// On a weekday of the month - yearly ones in the month they start in
|
||||
$by_day = in_array($repeat, ['Month', 'Year'], true) ? byDayRule($by_day) : '';
|
||||
if ($by_day !== '') {
|
||||
$rule .= ';BYDAY=' . $by_day . ($repeat === 'Year' && $start ? ';BYMONTH=' . date('n', strtotime($start)) : '');
|
||||
}
|
||||
if (!empty($until)) {
|
||||
$rule .= ';UNTIL=' . ($all_day ? date('Ymd', strtotime($until)) : icsFormatUtc(substr($until, 0, 10) . ' 23:59:59', $timezone));
|
||||
}
|
||||
@@ -1044,7 +1078,7 @@ function icsEventLines(array $item, $timezone, $tzid) {
|
||||
}
|
||||
}
|
||||
|
||||
$rrule = icsRepeatToRrule($item['repeat'] ?? '', $item['repeat_interval'] ?? 1, $item['repeat_until'] ?? null, $all_day, $timezone);
|
||||
$rrule = icsRepeatToRrule($item['repeat'] ?? '', $item['repeat_interval'] ?? 1, $item['repeat_until'] ?? null, $all_day, $timezone, $item['repeat_by_day'] ?? '', $item['start'] ?? null);
|
||||
if ($rrule) {
|
||||
$lines[] = "RRULE:$rrule";
|
||||
foreach ($item['skip'] ?? [] as $date) {
|
||||
@@ -1191,6 +1225,7 @@ function calendarEventIcsItem(array $event, $busy = false) {
|
||||
'repeat' => $event['event_repeat'] ?? '',
|
||||
'repeat_interval' => $event['event_repeat_interval'] ?? 1,
|
||||
'repeat_until' => $event['event_repeat_until'] ?? null,
|
||||
'repeat_by_day' => calendarEventByDay($event),
|
||||
'skip' => calendarSkippedDates($event),
|
||||
'busy' => $busy,
|
||||
];
|
||||
|
||||
@@ -400,7 +400,7 @@ function clientOverviewUpcoming($client_id, $access, $days = 14) {
|
||||
}
|
||||
}
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT event_id, event_title, event_start, event_end, event_all_day, event_repeat, event_repeat_interval, event_repeat_until, event_repeat_skip,
|
||||
$sql = mysqli_query($mysqli, "SELECT event_id, event_title, event_start, event_end, event_all_day, event_repeat, event_repeat_interval, event_repeat_until, event_repeat_skip," . (byDayReady() ? " event_repeat_by_day," : "") . "
|
||||
event_location, location_name
|
||||
FROM calendar_events
|
||||
JOIN calendars ON calendar_id = event_calendar_id AND calendar_archived_at IS NULL
|
||||
|
||||
@@ -492,7 +492,7 @@ function dashboardSchedule($days = 7, $limit = 30) {
|
||||
// Events I am on or added - and the ones nobody owns (made before events had
|
||||
// attendees, or with no agent on them), which are everyone's
|
||||
$sql = mysqli_query($mysqli, "
|
||||
SELECT event_id, event_title, event_start, event_end, event_all_day, event_repeat, event_repeat_interval, event_repeat_until, event_repeat_skip,
|
||||
SELECT event_id, event_title, event_start, event_end, event_all_day, event_repeat, event_repeat_interval, event_repeat_until, event_repeat_skip," . (byDayReady() ? " event_repeat_by_day," : "") . "
|
||||
event_location, client_name, calendar_color, location_name
|
||||
FROM calendar_events
|
||||
JOIN calendars ON event_calendar_id = calendar_id AND calendar_archived_at IS NULL
|
||||
|
||||
@@ -1806,13 +1806,15 @@ function recurringTicketFrequency($frequency) {
|
||||
* was due fell on - except when that was a shorter month's last day standing
|
||||
* in for a later one: one that started ($anchor) on the 31st runs on the last
|
||||
* day of shorter months and back on the 31st after, rather than drifting.
|
||||
* Missed runs are stepped over, not raised one by one.
|
||||
* Missed runs are stepped over, not raised one by one. With a weekday rule
|
||||
* ($by_day, "3WE") month-based ones land on that weekday of the month instead.
|
||||
*/
|
||||
function recurringTicketNextRun($due, $frequency, $anchor = '', $after = '') {
|
||||
function recurringTicketNextRun($due, $frequency, $anchor = '', $after = '', $by_day = '') {
|
||||
$frequency = recurringTicketFrequency($frequency) ?: 'Monthly';
|
||||
$step = RECURRING_TICKET_FREQUENCIES[$frequency];
|
||||
$after = $after !== '' ? $after : date('Y-m-d');
|
||||
$date = DateTime::createFromFormat('!Y-m-d', substr((string) $due, 0, 10)) ?: new DateTime('today');
|
||||
$by_day = isset($step['months']) ? byDayRule($by_day) : '';
|
||||
$anchor_date = DateTime::createFromFormat('!Y-m-d', substr((string) $anchor, 0, 10));
|
||||
$anchor_day = intval($date->format('j'));
|
||||
if ($anchor_date && intval($anchor_date->format('j')) > $anchor_day && $anchor_day === intval($date->format('t'))) {
|
||||
@@ -1827,6 +1829,10 @@ function recurringTicketNextRun($due, $frequency, $anchor = '', $after = '') {
|
||||
$month = intval($date->format('n')) + $step['months'];
|
||||
$year += intdiv($month - 1, 12);
|
||||
$month = ($month - 1) % 12 + 1;
|
||||
if ($by_day !== '') {
|
||||
$date = DateTime::createFromFormat('!Y-m-d', byDayDate($year, $month, $by_day));
|
||||
continue;
|
||||
}
|
||||
$days_in_month = intval(date('t', mktime(0, 0, 0, $month, 1, $year)));
|
||||
$date->setDate($year, $month, min($anchor_day, $days_in_month));
|
||||
}
|
||||
@@ -1845,6 +1851,10 @@ function recurringTicketCadenceText($row) {
|
||||
if (isset($step['days'])) {
|
||||
return $step['days'] === 7 ? 'on ' . $next->format('l') . 's' : ($step['days'] === 14 ? 'every other ' . $next->format('l') : 'every three days');
|
||||
}
|
||||
$by_day = byDayText($row['recurring_ticket_by_day'] ?? '');
|
||||
if ($by_day !== '') {
|
||||
return 'on ' . $by_day . ($frequency === 'Annually' ? ' of ' . $next->format('F') : '');
|
||||
}
|
||||
$day = intval($next->format('j'));
|
||||
$start = DateTime::createFromFormat('!Y-m-d', substr((string) ($row['recurring_ticket_start_date'] ?? ''), 0, 10));
|
||||
if ($start && intval($start->format('j')) > $day && $day === intval($next->format('t'))) {
|
||||
@@ -1997,7 +2007,7 @@ function recurringTicketRunNow($row, $by) {
|
||||
$due = (string) $row['recurring_ticket_next_run'];
|
||||
// Booked for the day of the run it is for, at its time - when it has one
|
||||
recurringTicketBook($ticket_id, $recurring_ticket_id, $due);
|
||||
$next_run = recurringTicketNextRun($due, $row['recurring_ticket_frequency'], $row['recurring_ticket_start_date'], max(date('Y-m-d'), substr($due, 0, 10)));
|
||||
$next_run = recurringTicketNextRun($due, $row['recurring_ticket_frequency'], $row['recurring_ticket_start_date'], max(date('Y-m-d'), substr($due, 0, 10)), $row['recurring_ticket_by_day'] ?? '');
|
||||
mysqli_query($mysqli, "UPDATE recurring_tickets SET recurring_ticket_next_run = '$next_run' WHERE recurring_ticket_id = $recurring_ticket_id");
|
||||
}
|
||||
return $ticket_id;
|
||||
@@ -2034,6 +2044,20 @@ function recurringTicketMonthBased($frequency) {
|
||||
return isset(RECURRING_TICKET_FREQUENCIES[recurringTicketFrequency($frequency)]['months']);
|
||||
}
|
||||
|
||||
/*
|
||||
* The weekday it repeats on (functions/by_day.php), as SQL for recurring_ticket_by_day - NULL is the
|
||||
* same date each time. $posted is the Repeats on choice when one was sent (null when not), kept only
|
||||
* when $date - the first or next run - falls on it; without one the rule it had ($current) follows the
|
||||
* run to $date. Only month-based repeats have one.
|
||||
*/
|
||||
function recurringTicketByDaySql($frequency, $date, $posted, $current = '') {
|
||||
if (!recurringTicketMonthBased($frequency)) {
|
||||
return 'NULL';
|
||||
}
|
||||
$rule = $posted !== null ? byDayForDate($posted, $date) : byDayFollow($current, $date);
|
||||
return $rule !== '' ? "'$rule'" : 'NULL';
|
||||
}
|
||||
|
||||
/*
|
||||
* Days ahead as kept: up to 90, and short of one step of the repeat (a month
|
||||
* counts as 28 days), so the next run is never due before this one is made -
|
||||
@@ -2159,7 +2183,7 @@ function recurringTicketUpcoming($row, $count = 3) {
|
||||
}
|
||||
$runs[] = $date;
|
||||
while (count($runs) < $count) {
|
||||
$date = recurringTicketNextRun($date, $row['recurring_ticket_frequency'], $row['recurring_ticket_start_date'], $date);
|
||||
$date = recurringTicketNextRun($date, $row['recurring_ticket_frequency'], $row['recurring_ticket_start_date'], $date, $row['recurring_ticket_by_day'] ?? '');
|
||||
$runs[] = $date;
|
||||
}
|
||||
return $runs;
|
||||
|
||||
Reference in New Issue
Block a user