mirror of
https://github.com/itflow-org/itflow
synced 2026-11-21 03:47:25 +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:
@@ -22,6 +22,8 @@
|
||||
* event_repeat optional - Day, Week, Month or Year
|
||||
* event_repeat_interval optional - Every so many, 1 to 99
|
||||
* event_repeat_until optional - Its last day, Y-m-d
|
||||
* event_repeat_by_day optional - Month and Year: the weekday it repeats on, as it starts -
|
||||
* "3WE" the third Wednesday, "-1FR" the last Friday; empty for the same date
|
||||
* attendee_user_ids, attendee_contact_ids, attendee_emails optional - Who is on it
|
||||
* send_invites optional - 1 emails them the invitation
|
||||
*
|
||||
|
||||
@@ -57,6 +57,13 @@ if ($location_id && (!$client_id || !assetClientOwnedId('location', $location_id
|
||||
$event_refuse("event_location_id isn't one of the client's locations.");
|
||||
}
|
||||
|
||||
// The weekday a monthly or yearly one repeats on - one it has follows a moved start when none is sent
|
||||
$by_day_sent = array_key_exists('event_repeat_by_day', $_POST) ? trim($sent('event_repeat_by_day', '')) : null;
|
||||
if (byDayReady() && $by_day_sent !== null && $by_day_sent !== '' && (!in_array($repeat, ['Month', 'Year'], true) || byDayForDate($by_day_sent, $start_date) === '')) {
|
||||
$options = in_array($repeat, ['Month', 'Year'], true) ? array_keys(byDayOptions($start_date)) : [];
|
||||
$event_refuse('event_repeat_by_day is the weekday a Month or Year one repeats on, from its ' . $start_date . ' start' . ($options ? ': ' . implode(' or ', $options) : ' - none for this one') . ', or empty for the same date.');
|
||||
}
|
||||
|
||||
$error = '';
|
||||
$event_set = calendarEventFormSet([
|
||||
'title' => $sent('event_title', $event_row['event_title'] ?? ''),
|
||||
@@ -72,7 +79,8 @@ $event_set = calendarEventFormSet([
|
||||
'location' => $sent('event_location', $event_row['event_location'] ?? ''),
|
||||
'location_id' => $location_id,
|
||||
'description' => $sent('event_description', $event_row['event_description'] ?? ''),
|
||||
], $client_id, $error);
|
||||
'repeat_on_current' => $event_row['event_repeat_by_day'] ?? '',
|
||||
] + ($by_day_sent !== null ? ['repeat_on' => $by_day_sent] : []), $client_id, $error);
|
||||
if ($event_set === '') {
|
||||
$event_refuse($error);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ if ($event_row) {
|
||||
// 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) $event_row[$field] !== (string) $event[$field]) {
|
||||
$changed = true;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
* subject required, unless the template has one
|
||||
* frequency required - Three Days, Weekly, Biweekly, Monthly, Quarterly, Biannually or Annually
|
||||
* start_date optional - Its first run, Y-m-d, today or later; today if left out
|
||||
* repeat_on optional - Monthly to yearly ones: the weekday it repeats on, as its first
|
||||
* run falls - "3WE" the third Wednesday, "-1FR" the last Friday; left out,
|
||||
* the same date each time
|
||||
* details optional - HTML
|
||||
* priority optional - Low, Medium (the default), High or Urgent
|
||||
* billable optional - 1 or 0; needs Modify on Sales
|
||||
@@ -94,6 +97,9 @@ $rt_set += [
|
||||
];
|
||||
$rt_set['recurring_ticket_start_date'] = "'$start_date'";
|
||||
$rt_set['recurring_ticket_next_run'] = "'$start_date'";
|
||||
if (byDayReady()) {
|
||||
$rt_set['recurring_ticket_by_day'] = $rt_by_day(trim($rt_set['recurring_ticket_frequency'], "'"), $start_date);
|
||||
}
|
||||
$rt_set['recurring_ticket_created_by'] = intval($session_user_id);
|
||||
$rt_set['recurring_ticket_client_id'] = $client_id;
|
||||
|
||||
|
||||
@@ -36,6 +36,17 @@ $rt_refuse = function ($message) use (&$return_arr) {
|
||||
$rt_text = function ($field) {
|
||||
return trim((string) (is_scalar($_POST[$field] ?? '') ? ($_POST[$field] ?? '') : ''));
|
||||
};
|
||||
// The weekday it repeats on (repeat_on, "3WE") for a run on $date, as SQL - checked like the form
|
||||
// checks it; not sent, the rule it had ($current) follows the run. Needs the 3.8.3 update.
|
||||
$rt_by_day = function ($frequency, $date, $current = '') use ($rt_refuse, $rt_text) {
|
||||
if (array_key_exists('repeat_on', $_POST) && $rt_text('repeat_on') !== '') {
|
||||
if (!recurringTicketMonthBased($frequency) || byDayForDate($rt_text('repeat_on'), $date) === '') {
|
||||
$options = recurringTicketMonthBased($frequency) ? array_keys(byDayOptions($date)) : [];
|
||||
$rt_refuse('repeat_on is the weekday a monthly to yearly one repeats on, from its ' . $date . ' run' . ($options ? ': ' . implode(' or ', $options) : ' - none for this one') . ', or empty for the same date each time.');
|
||||
}
|
||||
}
|
||||
return recurringTicketByDaySql($frequency, $date, array_key_exists('repeat_on', $_POST) ? $rt_text('repeat_on') : null, $current);
|
||||
};
|
||||
|
||||
if (array_key_exists('subject', $_POST)) {
|
||||
if ($rt_text('subject') === '') {
|
||||
|
||||
@@ -30,7 +30,7 @@ if ($rt_row && isset($_POST['status'])) {
|
||||
mysqli_query($mysqli, "UPDATE recurring_tickets SET recurring_ticket_paused_at = COALESCE(recurring_ticket_paused_at, NOW()) WHERE recurring_ticket_id = $recurring_ticket_id");
|
||||
} else {
|
||||
if ($next_run < date('Y-m-d')) {
|
||||
$next_run = recurringTicketNextRun($next_run, $rt_row['recurring_ticket_frequency'], $rt_row['recurring_ticket_start_date'], date('Y-m-d', strtotime('-1 day')));
|
||||
$next_run = recurringTicketNextRun($next_run, $rt_row['recurring_ticket_frequency'], $rt_row['recurring_ticket_start_date'], date('Y-m-d', strtotime('-1 day')), $rt_row['recurring_ticket_by_day'] ?? '');
|
||||
}
|
||||
mysqli_query($mysqli, "UPDATE recurring_tickets SET recurring_ticket_paused_at = NULL, recurring_ticket_next_run = '" . escapeSql($next_run) . "' WHERE recurring_ticket_id = $recurring_ticket_id");
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
* recurring_ticket_id required - The recurring ticket
|
||||
* client_id its client - needed when the key's user is limited to certain clients
|
||||
* next_date optional - Its next run, Y-m-d
|
||||
* repeat_on optional - As for create, from its next run; one it has follows a moved
|
||||
* next_date
|
||||
* subject, details, priority, frequency, billable, assigned_to, contact_id, asset_id,
|
||||
* asset_ids, category_id, ticket_template_id, fill_ins, tasks
|
||||
* optional - as for recurring_tickets/create.php
|
||||
@@ -44,8 +46,17 @@ if ($rt_row) {
|
||||
}
|
||||
}
|
||||
|
||||
// The weekday it repeats on - as sent, or the one it had following its run, going with a repeat that isn't month-based
|
||||
if (byDayReady() && (array_key_exists('repeat_on', $_POST) || isset($rt_set['recurring_ticket_frequency']) || isset($rt_set['recurring_ticket_next_run']))) {
|
||||
$rt_set['recurring_ticket_by_day'] = $rt_by_day(
|
||||
isset($rt_set['recurring_ticket_frequency']) ? trim($rt_set['recurring_ticket_frequency'], "'") : $rt_row['recurring_ticket_frequency'],
|
||||
isset($rt_set['recurring_ticket_next_run']) ? trim($rt_set['recurring_ticket_next_run'], "'") : substr((string) $rt_row['recurring_ticket_next_run'], 0, 10),
|
||||
$rt_row['recurring_ticket_by_day'] ?? ''
|
||||
);
|
||||
}
|
||||
|
||||
if (!$rt_set && $rt_assets === null && $rt_tasks === null && $rt_fill_ins === null && !array_key_exists('next_date', $_POST)) {
|
||||
$rt_refuse('Send at least one of subject, details, priority, frequency, next_date, billable, assigned_to, contact_id, asset_id, asset_ids, category_id, ticket_template_id, fill_ins or tasks.');
|
||||
$rt_refuse('Send at least one of subject, details, priority, frequency, next_date, repeat_on, billable, assigned_to, contact_id, asset_id, asset_ids, category_id, ticket_template_id, fill_ins or tasks.');
|
||||
}
|
||||
|
||||
$update_sql = $rt_set ? mysqli_query($mysqli, "UPDATE recurring_tickets SET " . implode(', ', array_map(function ($column, $value) {
|
||||
|
||||
Reference in New Issue
Block a user