diff --git a/CHANGELOG.md b/CHANGELOG.md
index b5a6bcb6f..247ed2066 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,7 +6,7 @@ This file documents all notable changes made to ITFlow.
### Upgrading
-Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's seventeen database changes (3.6.6 to 3.8.3) in the same pass. They add four tables for RMM providers and their alerts, a setting for device actions and one for API keys in the address, a column marking the emails the mail queue clears once sent, a column and a table for agent banners, two columns for ticket statuses with a setting for the "ticket assigned" message, a column on tickets with a setting for the "no response" message, a table for who a ticket's email replies go to, the settings for Quick tickets, columns on recurring tickets and recurring invoices for booking and making them ahead, two columns on ticket replies for when their time was worked, the settings for cron alerts, a table and a setting for labor costs, a column on users for API / service accounts, columns on tickets and recurring tickets for how long booked work takes, and a column each on recurring tickets and calendar events for repeating on a weekday, and change nothing that is there. Nothing else is required. This release has eleven security fixes - see Security. On Apache, ITFlow's own .htaccess now sends security headers: if you show ITFlow inside a frame on another website, it will now refuse to load there. On nginx, add the same headers to your server block if you want them - see Developer Updates.
+Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's eighteen database changes (3.6.6 to 3.8.4) in the same pass. They add four tables for RMM providers and their alerts, a setting for device actions and one for API keys in the address, a column marking the emails the mail queue clears once sent, a column and a table for agent banners, two columns for ticket statuses with a setting for the "ticket assigned" message, a column on tickets with a setting for the "no response" message, a table for who a ticket's email replies go to, the settings for Quick tickets, columns on recurring tickets and recurring invoices for booking and making them ahead, two columns on ticket replies for when their time was worked, the settings for cron alerts, a table and a setting for labor costs, a column on users for API / service accounts, columns on tickets and recurring tickets for how long booked work takes, a column each on recurring tickets and calendar events for repeating on a weekday, and two columns on agents' settings for their calendar color and what their calendar shows, and change nothing that is there. Nothing else is required. This release has eleven security fixes - see Security. On Apache, ITFlow's own .htaccess now sends security headers: if you show ITFlow inside a frame on another website, it will now refuse to load there. On nginx, add the same headers to your server block if you want them - see Developer Updates.
### Security
@@ -99,6 +99,12 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u
- Tickets: booked work has an end. The Schedule window has How long - 15 minutes to a day, an hour unless picked - and an Agent picker, so booking someone else's ticket gives it to them and takes it off the old agent's calendar. New Ticket's Schedule and a recurring ticket's Book the work for take a length too. The calendar draws each booking at its length, and dragging its bottom edge changes how long it takes, after asking. The booking email, the calendar file, the ticket and the guest page say when it ends. From Mountaineer IT's build of ITFlow.
- Tickets: the warning when an agent is booked twice now means it - it lists their tickets and timed events that overlap the booking, at their lengths, instead of anything within two hours. From Mountaineer IT's build of ITFlow.
- Recurring tickets and events: a monthly, quarterly, twice-yearly or yearly recurring ticket, and a monthly or yearly event, can repeat on a weekday - the third Wednesday, or the last Friday - instead of the same date. Pick its date, then Repeats on offers what that date is: On the 16th, or On the third Wednesday. Moving the next run, or an event's start, keeps it on the same kind of weekday. The recurring tickets list, the event and its calendar invitations say which, and Google, Outlook and phone calendars that subscribe show it on the right days. From Mountaineer IT's build of ITFlow.
+- Calendar: every agent has a color, and their booked tickets and the events assigned to them are drawn in it - so whose work is whose shows at a glance. Each has one from the start; pick your own under Account > Preferences > Calendar color, or an admin picks one in Admin > Users. In the week, 7 days, day and list views the agent's first name sits beside the time. From Mountaineer IT's build of ITFlow.
+- Calendar: events are assigned to agents. New Event and Edit have Assigned to beside the title, and the client's contacts and anyone else by email go under Invite. Calendar is only asked for when you have more than one. An event added from someone's calendar - Whose set to them - starts assigned to them, and it shows on their calendar rather than yours. The event's quick look changes who it's assigned to without opening Edit, sending the cancellation to anyone taken off who had the invitation, and the invitation to anyone added when others have it. From Mountaineer IT's build of ITFlow.
+- Calendar: Left behind, under the calendar, lists open tickets booked on a day that has gone - the work wasn't done and nobody moved it on - longest left first, with how many days ago. Drag one onto the calendar to book it again, for as long as before, or click it for the quick look. Its old booking on the calendar has a dashed red outline. It follows Whose, so Everyone shows everyone's. From Mountaineer IT's build of ITFlow.
+- Calendar: a 7 days view shows seven days from any day, and its arrows move a day at a time, so a booking can be dragged across a weekend without leaving the view. Bookings at the same time now sit side by side instead of on top of each other. From Mountaineer IT's build of ITFlow.
+- Calendar: Holidays, under From ITFlow, shows the closure days from Admin > SLA, and is on to start with. From Mountaineer IT's build of ITFlow.
+- Calendar: what you have shown - calendars, sources, Whose and the view - is kept to your account, so the calendar opens the same way on every computer and phone. The first time, it opens on your own calendar. With Whose set to Everyone, To schedule lists everyone's open tickets that aren't booked, with who has each. From Mountaineer IT's build of ITFlow.
### Bug Fixes
@@ -223,6 +229,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u
- Database 3.8.1: `users.user_service_account` - `serviceAccountsReady()`, `serviceAccountIs()`, `serviceAccountSave()` (`functions/service_account.php`). `serviceAccountsOutSql($column)` adds ` AND user_service_account = 0` to the agent lists and pickers (tickets, recurring tickets, projects, contracts, calendar and events, ticket templates, bulk assign, exports, reports, client onboarding, Quick ticket, mentions, trips, expenses, labor costs, Getting Started's team, user archive's hand-over, incident response) and to `appNotify()`, `signInAdmins()`, `cronHealthRecipients()` and the last-admin checks (`userActiveAdminCount()` in `functions/user.php`, `roles.php`). Not to `apiKeyAgents()`, the API's own checks (`api/v1/enforce_api_rbac.php`) or `getActiveAgentUserCount()`. `login.php` matches agents with `user_service_account = 0`, and `includes/load_user_session.php` ends a service account's session. The switch is `service_account` with `service_account_present` on `admin/modals/user/user_form.php`'s Sign in tab, saved by `add_user` (an invite with it is refused) and `edit_user`. `admin/users.php` adds the `service` view and excludes them from the others but `archived`. From Mountaineer IT's build of ITFlow.
- Database 3.8.2: `tickets.ticket_schedule_end` (NULL is `CALENDAR_TICKET_MINUTES` after the start) and `recurring_tickets.recurring_ticket_schedule_minutes` (default 60) - `ticketScheduleEndReady()`. `ticketSetSchedule($row, $schedule, $onsite, $end = null)` keeps the end (cancelling clears it) and `ticketScheduleIcs()` and `createiCalStr(..., $uid, $end)` write it as DTEND. `ticketScheduleEnd()`, `ticketScheduleMinutes()`, `ticketScheduleMinutesValue()` (15 to 1440), `ticketScheduleLengths()`, `ticketScheduleLengthText()`, `ticketScheduleWhenText()` and `ticketScheduleShortText()` word it; `ticketScheduleOverlapSql($from, $to)` finds bookings running into a range, used by the calendar's tickets source, the agent feed and `ticketScheduleConflicts()` (overlapping tickets and timed calendar events of the agent). `edit_ticket_schedule` takes `schedule_tech` (one of `ticketMentionAgents()`, given the ticket with `ticketChangeAssignee()`, the old agent sent `ticketMailScheduleAgentCancelled()`) and `schedule_minutes`; `add_ticket` and the recurring ticket handlers take `schedule_minutes`, and `recurringTicketBook()` books that long. `calendar_move` (`agent/ajax.php`) takes an `end` from a resize, or keeps the length on a move; ticket items are `durationEditable`. From Mountaineer IT's build of ITFlow.
- Database 3.8.3: `recurring_tickets.recurring_ticket_by_day` and `calendar_events.event_repeat_by_day`, an RFC 5545 BYDAY value (`3WE`, `-1FR`; NULL is the same date) - `byDayReady()` and the helpers in `functions/by_day.php`: `byDayRule()`, `byDayDate($year, $month, $rule)`, `byDayText()`, `byDayOptions($date)` (the rules a date can take), `byDayForDate()` (a posted rule, kept when the date takes it), `byDayFollow()` (a rule carried to a moved date) and `byDayField()`, the Repeats on picker filled by `js/repeat_on.js`, which posts `repeat_on` with `repeat_on_field`. `recurringTicketNextRun()` takes `$by_day` for month-based frequencies, passed by every caller, and `recurringTicketByDaySql()` saves it for `add_recurring_ticket`, `edit_recurring_ticket`, the bulk next run and `recurring_tickets/create` and `update` (`repeat_on`). `calendarEventFormSet()` saves `event_repeat_by_day` from `repeat_on`, or follows `repeat_on_current`; `expandRecurringEvent()`, `calendarRepeatText()` and `icsRepeatToRrule($repeat, $interval, $until, $all_day, $timezone, $by_day, $start)` (BYDAY, with BYMONTH for yearly) use it, through `calendarEventByDay()`. `events/create` and `update` take `event_repeat_by_day`. From Mountaineer IT's build of ITFlow.
+- Database 3.8.4: `user_settings.user_config_calendar_color` (NULL is `calendarAgentDefaultColor()`, one of `CALENDAR_AGENT_COLORS` by user id) and `user_config_calendar_state` (JSON, `all` and `client`) - `calendarAgentSettingsReady()`. `calendarAgentColor()`, `calendarAgentColors()`, `calendarFirstName()`; `calendarAgentColorField()` (Account > Preferences, Admin > Users' Edit) posts `calendar_color` and `calendar_color_auto`, saved by `calendarAgentColorSave()` in `edit_your_user_preferences` and `edit_user`. The tickets source colors each booking by `ticket_assigned_to` and adds `agent_name` and `agent_full` (the name leaves `detail`); `calendarEventItems()` ends with `calendarEventItemsAgents()`, which colors an event by its attendee agents and leaves out of one agent's calendar an event assigned only to others. `calendarEventAgents()`, `calendarEventAgentChoices()`, `calendarEventDefaultAgents()` (New Event's `agent_id`), `calendarEventSetAgents()` and `calendarEventAgentsText()`; `assign_event` (`agent/post/event.php`) is the quick look's. `calendarLeftBehindSql()` and `calendarLeftBehindTickets()` behind `ajax.php?calendar_left_behind`, and items left behind get `itflow-cal-left-behind`. `ajax.php` `calendar_state` saves through `calendarUserStateSave()` and `calendarCleanState()` (`CALENDAR_VIEWS`); `agent/calendar.php` reads `calendarUserState()` into `data-saved-state`, which `agent/js/calendar.js` prefers to `localStorage`. `calendar_unscheduled` takes `user_id` 0 as everyone's, with `agent`. The `holidays` source reads `business_holidays`. The `timeGridSevenDays` view and `slotEventOverlap: false`. From Mountaineer IT's build of ITFlow.
## [26.11.8]
diff --git a/admin/database_updates/3.8.4.php b/admin/database_updates/3.8.4.php
new file mode 100644
index 000000000..1e994e220
--- /dev/null
+++ b/admin/database_updates/3.8.4.php
@@ -0,0 +1,30 @@
+ 0;
+ };
+
+ if (!$itflow_column('user_settings', 'user_config_calendar_color')) {
+ mysqli_query($mysqli, "ALTER TABLE `user_settings` ADD `user_config_calendar_color` varchar(7) DEFAULT NULL AFTER `user_config_calendar_first_day`");
+ }
+
+ if (!$itflow_column('user_settings', 'user_config_calendar_state')) {
+ mysqli_query($mysqli, "ALTER TABLE `user_settings` ADD `user_config_calendar_state` text DEFAULT NULL AFTER `user_config_calendar_color`");
+ }
diff --git a/admin/modals/user/user_form.php b/admin/modals/user/user_form.php
index 55f8f2452..34228b284 100644
--- a/admin/modals/user/user_form.php
+++ b/admin/modals/user/user_form.php
@@ -109,6 +109,9 @@ $value = function ($key) use ($form) {
} ?>
+
+ = calendarAgentColorField($form_user_id, 'col-12') ?>
+
diff --git a/admin/post/users.php b/admin/post/users.php
index 498095dc0..ecbcd0e62 100644
--- a/admin/post/users.php
+++ b/admin/post/users.php
@@ -205,6 +205,7 @@ if (isset($_POST['edit_user'])) {
mysqli_query($mysqli, "UPDATE users SET user_name = '" . escapeSql($name) . "', user_email = '" . escapeSql($email) . "', user_role_id = " . intval($role['role_id']) . " WHERE user_id = $user_id");
$force_mfa = !empty($_POST['force_mfa']) ? 1 : 0;
mysqli_query($mysqli, "INSERT INTO user_settings SET user_id = $user_id, user_config_force_mfa = $force_mfa ON DUPLICATE KEY UPDATE user_config_force_mfa = $force_mfa");
+ calendarAgentColorSave($user_id, $_POST);
// An admin sees every client - their rules are left as they were, in case the role changes back
if (!intval($role['role_is_admin']) && isset($_POST['client_permission_shown'])) {
diff --git a/agent/ajax.php b/agent/ajax.php
index 318c722ba..9c0b3ed43 100644
--- a/agent/ajax.php
+++ b/agent/ajax.php
@@ -2678,6 +2678,7 @@ if (isset($_POST['calendar_move'])) {
/*
* The calendar's To schedule list: an agent's open tickets with no work booked
* (most urgent first), to drag onto the calendar - in one client, or all.
+ * user_id 0 is everyone's: the open tickets assigned to anyone.
*/
if (isset($_GET['calendar_unscheduled'])) {
@@ -2687,22 +2688,23 @@ if (isset($_GET['calendar_unscheduled'])) {
echo json_encode(['tickets' => []]);
exit;
}
- $user_id = intval($_GET['user_id'] ?? 0) ?: $session_user_id;
+ $user_id = intval($_GET['user_id'] ?? $session_user_id);
$client_id = intval($_GET['client_id'] ?? 0);
if ($client_id && !hasClientAccess($client_id)) {
echo json_encode(['tickets' => []]);
exit;
}
- $sql = mysqli_query($mysqli, "SELECT tickets.ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_priority, ticket_onsite, ticket_client_id, client_name
+ $sql = mysqli_query($mysqli, "SELECT tickets.ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_priority, ticket_onsite, ticket_client_id, client_name, user_name
FROM tickets
LEFT JOIN clients ON client_id = ticket_client_id
+ LEFT JOIN users ON user_id = ticket_assigned_to
WHERE ticket_schedule IS NULL AND ticket_resolved_at IS NULL AND ticket_closed_at IS NULL AND ticket_archived_at IS NULL
- AND ticket_assigned_to = $user_id
+ AND " . ($user_id ? "ticket_assigned_to = $user_id" : 'ticket_assigned_to > 0') . "
" . ($client_id ? "AND ticket_client_id = $client_id" : '') . "
" . clientScopeSql('ticket_client_id') . "
ORDER BY FIELD(ticket_priority, 'Urgent', 'High', 'Medium', 'Low'), ticket_created_at ASC
- LIMIT 25");
+ LIMIT " . ($user_id ? 25 : 50));
$tickets = [];
while ($row = mysqli_fetch_assoc($sql)) {
$tickets[] = [
@@ -2712,6 +2714,7 @@ if (isset($_GET['calendar_unscheduled'])) {
'client' => $row['client_name'] ?: 'Internal',
'priority' => $row['ticket_priority'],
'onsite' => intval($row['ticket_onsite']),
+ 'agent' => (string) ($row['user_name'] ?? ''),
];
}
@@ -2719,6 +2722,45 @@ if (isset($_GET['calendar_unscheduled'])) {
exit;
}
+/*
+ * The calendar's Left behind list: open tickets booked on a day gone by
+ * (calendarLeftBehindTickets()) - one agent's or everyone's, in one client or all.
+ */
+if (isset($_GET['calendar_left_behind'])) {
+
+ header('Content-Type: application/json');
+
+ $client_id = intval($_GET['client_id'] ?? 0);
+ if (!calendarCanScheduleTickets() || ($client_id && !hasClientAccess($client_id))) {
+ echo json_encode(['tickets' => []]);
+ exit;
+ }
+
+ echo json_encode(['tickets' => calendarLeftBehindTickets($_GET['user_id'] ?? 0, $client_id)]);
+ exit;
+}
+
+/*
+ * What the calendar page shows - calendars, sources, whose, the view - kept to
+ * the agent's account, so every device opens the same way.
+ */
+if (isset($_POST['calendar_state'])) {
+
+ validateCSRFToken();
+
+ header('Content-Type: application/json');
+ $raw = (string) ($_POST['state'] ?? '');
+ $state = strlen($raw) <= 8192 ? json_decode($raw, true) : null;
+ if (!is_array($state)) {
+ http_response_code(400);
+ echo json_encode(['error' => 'That is not the calendar\'s settings.']);
+ exit;
+ }
+
+ echo json_encode(['ok' => calendarUserStateSave($session_user_id, ($_POST['page'] ?? '') === 'client' ? 'client' : 'all', $state)]);
+ exit;
+}
+
/*
* One agent's day - their scheduled tickets and the events they are on - for
* the ticket's Schedule dialog, so a visit is not booked on top of another.
diff --git a/agent/calendar.php b/agent/calendar.php
index 52137bb2a..3d066935e 100644
--- a/agent/calendar.php
+++ b/agent/calendar.php
@@ -7,11 +7,14 @@
* agent can reach, or one client (opened inside it).
*
* Each calendar and each source can be shown or hidden, and the whole thing
- * narrowed to one agent's work. Picking a day or a time range adds an event;
- * scheduled tickets and events that do not repeat can be dragged to a new
- * time, and the agent's open unscheduled tickets dragged onto the calendar to
- * book them. Items are fetched for the range on screen (ajax.php
- * ?calendar_items) - agent/js/calendar.js. ?date=Y-m-d opens on that day.
+ * narrowed to one agent's work - what is shown is kept to the agent's account
+ * (calendarUserState()), so every device opens the same way. Picking a day or
+ * a time range adds an event; scheduled tickets and events that do not repeat
+ * can be dragged to a new time, and open unscheduled tickets - and those left
+ * behind, booked on a day gone by - dragged onto the calendar to book them.
+ * Booked work and events are drawn in their agent's colour. Items are fetched
+ * for the range on screen (ajax.php ?calendar_items) - agent/js/calendar.js.
+ * ?date=Y-m-d opens on that day.
*/
if (isset($_GET['client_id'])) {
@@ -41,6 +44,9 @@ while ($row = mysqli_fetch_assoc($sql)) {
$my_feed = calendarUserFeed($session_user_id);
+// What the page showed last, on any device
+$saved_state = calendarUserState($session_user_id, $page_client_id ? 'client' : 'all');
+
// What the page script needs to know
$page_sources = [];
foreach ($sources as $key => $source) {
@@ -58,7 +64,8 @@ foreach ($sources as $key => $source) {
data-can-add="= $can_add_event ? 1 : 0 ?>"
data-mobile="= !empty($session_mobile) ? 1 : 0 ?>"
data-initial-date="= calendarIsDate($_GET['date'] ?? '') ? escapeHtml($_GET['date']) : '' ?>"
- data-sources="= escapeHtml(json_encode($page_sources)) ?>">
+ data-sources="= escapeHtml(json_encode($page_sources)) ?>"
+ data-saved-state="= escapeHtml(json_encode($saved_state ?: new stdClass())) ?>">
+ Left behind
+ Open tickets booked on a day that has gone - drag one onto the calendar to book it again.
+
+
+
+
+
+
+
diff --git a/agent/js/calendar.js b/agent/js/calendar.js
index 3b3208a7e..93553658e 100644
--- a/agent/js/calendar.js
+++ b/agent/js/calendar.js
@@ -3,12 +3,14 @@
// Items are fetched for the range on screen from ajax.php?calendar_items -
// the events on the calendars ticked, and the built-in sources ticked - for
// one client or all, everyone's or one agent's. What is ticked, whose, and
-// the view are remembered in this browser.
+// the view are remembered in this browser and kept to the agent's account
+// (ajax.php?calendar_state), so every device opens the same way.
//
-// Picking a day or a time range opens New Event for it. A click opens the
-// item's quick look. Scheduled tickets and events that do not repeat can be
-// dragged to a new time (ajax.php?calendar_move), and the open tickets in To
-// schedule dragged onto the calendar to book them - a ticket is booked exactly
+// Picking a day or a time range opens New Event for it - assigned to the
+// agent whose calendar it is. A click opens the item's quick look. Scheduled
+// tickets and events that do not repeat can be dragged to a new time
+// (ajax.php?calendar_move), and the open tickets in To schedule and Left
+// behind dragged onto the calendar to book them - a ticket is booked exactly
// as from the ticket, so the agent and contact are emailed the time.
(function () {
@@ -29,6 +31,7 @@
const sourceDefaults = JSON.parse(root.dataset.sources || '{}');
const agentSelect = document.getElementById('calendarAgent');
const unscheduledList = document.getElementById('calendarUnscheduled');
+ const leftBehindList = document.getElementById('calendarLeftBehind');
// ---------- what this browser remembers ----------
@@ -39,16 +42,42 @@
} catch (e) {
state = {};
}
+ // What is kept to the account wins, so every device opens the same way
+ try {
+ const kept = JSON.parse(root.dataset.savedState || '{}');
+ if (kept && typeof kept === 'object' && Object.keys(kept).length) {
+ state = kept;
+ }
+ } catch (e) {
+ // Nothing kept yet - this browser's copy, or the defaults
+ }
+ let saveTimer = null;
function save() {
try {
window.localStorage.setItem(storeKey, JSON.stringify(state));
} catch (e) {
- // Private window or storage blocked - it just won't be remembered
+ // Private window or storage blocked - the account's copy still keeps it
}
+ // And to the account, a moment after the last change
+ clearTimeout(saveTimer);
+ saveTimer = setTimeout(function () {
+ fetch('ajax.php', {
+ method: 'POST',
+ headers: {'Content-Type': 'application/x-www-form-urlencoded'},
+ credentials: 'same-origin',
+ body: new URLSearchParams({calendar_state: 1, csrf_token: csrf, page: clientId ? 'client' : 'all', state: JSON.stringify(state)}).toString()
+ }).catch(function () {
+ // Offline - this browser still remembers it
+ });
+ }, 800);
}
+ const views = ['dayGridMonth', 'timeGridWeek', 'timeGridSevenDays', 'timeGridDay', 'listWeek'];
state.hidden = Array.isArray(state.hidden) ? state.hidden : [];
- state.sources = state.sources && typeof state.sources === 'object' ? state.sources : {};
+ state.sources = state.sources && typeof state.sources === 'object' && !Array.isArray(state.sources) ? state.sources : {};
+ if (state.view && views.indexOf(state.view) === -1) {
+ delete state.view;
+ }
root.querySelectorAll('.itflow-cal-check[data-calendar]').forEach(function (box) {
box.checked = state.hidden.indexOf(box.dataset.calendar) === -1;
@@ -59,6 +88,9 @@
});
if (agentSelect && state.agent && agentSelect.querySelector('option[value="' + Number(state.agent) + '"]')) {
agentSelect.value = String(Number(state.agent));
+ } else if (agentSelect && !('agent' in state) && agentSelect.querySelector('option[value="' + myId + '"]')) {
+ // The first time, your own calendar
+ agentSelect.value = String(myId);
}
function shownCalendars() {
@@ -115,6 +147,10 @@
query.set('client_id', clientId);
query.set('lock_client', '1');
}
+ // From someone's calendar, it is theirs
+ if (agentId()) {
+ query.set('agent_id', agentId());
+ }
openModal('modals/calendar/calendar_event_add.php?' + query.toString(), 'lg');
}
@@ -175,7 +211,7 @@
initialDate: root.dataset.initialDate || undefined,
headerToolbar: mobile
? {left: 'prev,next', center: 'title', right: 'today'}
- : {left: 'prev,next today', center: 'title', right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'},
+ : {left: 'prev,next today', center: 'title', right: 'dayGridMonth,timeGridWeek,timeGridSevenDays,timeGridDay,listWeek'},
footerToolbar: mobile ? {center: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'} : false,
noEventsText: 'Nothing on the calendar for these days',
firstDay: Number(root.dataset.firstDay) || 0,
@@ -190,10 +226,16 @@
scrollTime: '07:30:00',
businessHours: {daysOfWeek: [1, 2, 3, 4, 5], startTime: '08:00', endTime: '18:00'},
eventOrder: 'allDay,start,-duration,title',
+ // Bookings at the same time sit side by side, never on top of each other
+ slotEventOverlap: false,
views: {
// Side by side past three, the rest go behind "+N more"
- timeGrid: {eventMaxStack: 3}
+ timeGrid: {eventMaxStack: 3},
+ // Seven days from any day - the arrows move a day at a time, so a booking can be
+ // dragged across a weekend without leaving the view
+ timeGridSevenDays: {type: 'timeGrid', duration: {days: 7}, dateIncrement: {days: 1}}
},
+ buttons: {timeGridSevenDays: {text: '7 days', hint: 'Seven days from any day - the arrows move a day at a time'}},
events: function (info, success, failure) {
const end = new Date(info.end.getTime());
@@ -234,11 +276,25 @@
const view = arg.view.type;
const wrap = document.createElement('div');
wrap.className = 'itflow-cal-event ' + (view.indexOf('list') === 0 ? 'is-list' : (view.indexOf('timeGrid') === 0 && !arg.event.allDay ? 'is-timegrid' : 'is-daygrid'));
+ let agentShown = false;
if ((arg.timeText && !arg.event.allDay) || (arg.event.allDay && view.indexOf('list') === 0)) {
const time = document.createElement('span');
time.className = 'itflow-cal-time';
time.textContent = arg.event.allDay ? 'All day' : arg.timeText;
- wrap.appendChild(time);
+ // Who it is for, on the time's line - not on the month's one-line items, where it
+ // would push the title out (the colour and the tooltip say who)
+ if (props.agent_name && view.indexOf('dayGrid') !== 0) {
+ const when = document.createElement('span');
+ when.className = 'itflow-cal-when';
+ const agent = document.createElement('span');
+ agent.className = 'itflow-cal-agent';
+ agent.textContent = props.agent_name;
+ when.append(time, agent);
+ wrap.appendChild(when);
+ agentShown = true;
+ } else {
+ wrap.appendChild(time);
+ }
}
if (props.icon) {
const icon = document.createElement('i');
@@ -249,10 +305,12 @@
title.className = 'itflow-cal-title';
title.textContent = arg.event.title;
wrap.appendChild(title);
- if (props.detail && (view.indexOf('timeGrid') === 0 || view.indexOf('list') === 0)) {
+ // With no time line to put the agent on, they go at the front of the detail
+ const detailText = [agentShown ? '' : (props.agent_name || ''), props.detail || ''].filter(Boolean).join(' · ');
+ if (detailText && (view.indexOf('timeGrid') === 0 || view.indexOf('list') === 0)) {
const detail = document.createElement('div');
detail.className = 'itflow-cal-detail';
- detail.textContent = props.detail;
+ detail.textContent = detailText;
wrap.appendChild(detail);
}
return {domNodes: [wrap]};
@@ -260,7 +318,8 @@
eventDidMount: function (info) {
const props = info.event.extendedProps || {};
- info.el.setAttribute('title', info.event.title + (props.detail ? '\n' + props.detail : ''));
+ const who = [props.agent_full || props.agent_name || '', props.detail || ''].filter(Boolean).join(' · ');
+ info.el.setAttribute('title', info.event.title + (who ? '\n' + who : ''));
info.el.dataset.kind = props.kind || '';
},
@@ -396,6 +455,7 @@
saved(json);
item.remove();
countUnscheduled();
+ countLeftBehind();
calendar.refetchEvents();
}, function (error) {
itflowToast(error, 'error');
@@ -428,6 +488,7 @@
save();
calendar.refetchEvents();
loadUnscheduled();
+ loadLeftBehind();
});
}
@@ -452,7 +513,7 @@
if (hint) {
hint.textContent = n
? 'Open tickets with no time booked - drag one onto the calendar to book it.'
- : 'Nothing waiting - every open ticket ' + (agentId() && agentId() !== myId ? 'they have' : 'you have') + ' is booked or needs no visit.';
+ : 'Nothing waiting - every open ticket ' + (!agentId() ? 'anyone has' : (agentId() !== myId ? 'they have' : 'you have')) + ' is booked or needs no visit.';
}
}
@@ -460,7 +521,8 @@
if (!unscheduledList) {
return;
}
- itflowGet('ajax.php', {calendar_unscheduled: 1, user_id: agentId() || myId, client_id: clientId}, function (text) {
+ // Everyone: the open tickets assigned to anyone
+ itflowGet('ajax.php', {calendar_unscheduled: 1, user_id: agentId(), client_id: clientId}, function (text) {
let tickets = [];
try {
tickets = JSON.parse(text).tickets || [];
@@ -489,7 +551,7 @@
line.textContent = ticket.reference + ' ' + ticket.subject;
const sub = document.createElement('div');
sub.className = 'text-truncate small text-body-secondary';
- sub.textContent = (clientId ? '' : ticket.client + ' · ') + ticket.priority + (ticket.onsite ? ' · Onsite' : '');
+ sub.textContent = (clientId ? '' : ticket.client + ' · ') + (!agentId() && ticket.agent ? ticket.agent + ' · ' : '') + ticket.priority + (ticket.onsite ? ' · Onsite' : '');
text.appendChild(line);
text.appendChild(sub);
item.appendChild(text);
@@ -513,4 +575,95 @@
loadUnscheduled();
}
+ // ---------- Left behind ----------
+
+ // Open tickets booked on a day gone by. Each row carries what a To schedule row does, so
+ // dropping one books it again (keeping its length); a click opens the quick look.
+ const leftBehindCard = document.getElementById('calendarLeftBehindCard');
+
+ function countLeftBehind() {
+ if (!leftBehindList) {
+ return;
+ }
+ const n = leftBehindList.children.length;
+ const count = document.getElementById('calendarLeftBehindCount');
+ const hint = document.getElementById('calendarLeftBehindHint');
+ count.textContent = n ? String(n) : 'None';
+ count.className = 'badge rounded-pill ms-auto ' + (n ? 'text-bg-danger' : 'bg-body-secondary text-body-secondary');
+ hint.textContent = n
+ ? 'Open tickets booked on a day that has gone - drag one onto the calendar to book it again.'
+ : 'Nothing left behind - every open ticket booked before today has been moved on or done.';
+ // With some, the calendar makes room for a row of them under it
+ const was = leftBehindCard.classList.contains('is-empty');
+ leftBehindCard.classList.toggle('is-empty', n === 0);
+ if (!mobile && was !== (n === 0)) {
+ calendar.setOption('height', n ? 'calc(100vh - 19rem)' : 'calc(100vh - 11rem)');
+ }
+ }
+
+ function loadLeftBehind() {
+ if (!leftBehindList) {
+ return;
+ }
+ itflowGet('ajax.php', {calendar_left_behind: 1, user_id: agentId(), client_id: clientId}, function (text) {
+ let tickets = [];
+ try {
+ tickets = JSON.parse(text).tickets || [];
+ } catch (e) {
+ tickets = [];
+ }
+ leftBehindList.innerHTML = '';
+ tickets.forEach(function (ticket) {
+ const item = document.createElement('div');
+ item.className = 'itflow-cal-unscheduled';
+ item.dataset.ticket = ticket.id;
+ item.dataset.reference = ticket.reference;
+ item.dataset.title = ticket.reference + ' ' + ticket.subject;
+ item.dataset.onsite = ticket.onsite;
+ item.title = 'Booked ' + ticket.booked + ' - drag onto the calendar to book it again, click for a quick look';
+
+ const dot = document.createElement('span');
+ dot.className = 'itflow-cal-priority bg-' + (priorityTones[ticket.priority] || 'secondary');
+ dot.title = ticket.priority;
+ item.appendChild(dot);
+
+ const text = document.createElement('div');
+ text.className = 'min-w-0 flex-grow-1';
+ const line = document.createElement('div');
+ line.className = 'text-truncate small fw-semibold';
+ line.textContent = ticket.reference + ' ' + ticket.subject;
+ const sub = document.createElement('div');
+ sub.className = 'text-truncate small text-body-secondary';
+ sub.textContent = [clientId ? '' : ticket.client, agentId() ? '' : ticket.agent, 'booked ' + ticket.booked].filter(Boolean).join(' · ');
+ text.appendChild(line);
+ text.appendChild(sub);
+ item.appendChild(text);
+
+ const days = document.createElement('span');
+ days.className = 'badge text-bg-danger flex-shrink-0';
+ days.textContent = ticket.days + 'd';
+ days.title = ticket.days + ' day' + (ticket.days === 1 ? '' : 's') + ' since it was booked for';
+ item.appendChild(days);
+
+ item.addEventListener('click', function () {
+ openModal('modals/ticket/ticket.php?id=' + ticket.id, 'lg');
+ });
+ leftBehindList.appendChild(item);
+ });
+ countLeftBehind();
+ });
+ }
+
+ if (leftBehindList && canSchedule && FullCalendar.Interaction && FullCalendar.Interaction.Draggable) {
+ new FullCalendar.Interaction.Draggable(leftBehindList, {
+ itemSelector: '.itflow-cal-unscheduled',
+ eventData: function (item) {
+ return {title: item.dataset.title, duration: '01:00', create: false, color: '#dc3545'};
+ }
+ });
+ loadLeftBehind();
+ // The ticket's quick look can resolve it or book it again
+ document.addEventListener('hidden.bs.modal', loadLeftBehind);
+ }
+
})();
diff --git a/agent/modals/calendar/calendar_event.php b/agent/modals/calendar/calendar_event.php
index a01066d90..c08937db7 100644
--- a/agent/modals/calendar/calendar_event.php
+++ b/agent/modals/calendar/calendar_event.php
@@ -4,7 +4,8 @@
* Event quick look - opened from the calendar, the dashboard and a client's
* overview. When and where (with the map and the meeting link), who is on it
* and whether they have been sent it, and what it is for. From here: edit,
- * send the invitation, skip this one occurrence, download it, delete it.
+ * change who it is assigned to, send the invitation, skip this one
+ * occurrence, download it, delete it.
* GET: id, occurrence (Y-m-d, for one of a repeating event's days).
*/
@@ -42,6 +43,13 @@ $csrf = $_SESSION['csrf_token'];
// What the role allows with it (calendarEventCan())
$can_edit = calendarEventCan($event, 'edit');
$can_delete = calendarEventCan($event, 'delete');
+// Its agents are who it is assigned to; the rest are invited
+$agents = array_values(array_filter($attendees, function ($attendee) {
+ return $attendee['kind'] === 'agent';
+}));
+$others = array_values(array_filter($attendees, function ($attendee) {
+ return $attendee['kind'] !== 'agent';
+}));
ob_start();
@@ -105,12 +113,50 @@ ob_start();
+
+ Nobody else
+
+ $form_client_id ? intval(assetClientOwnedId('location', $_GET['location_id'] ?? 0, $form_client_id)) : 0,
];
$form_attendees = [
- 'agents' => [intval($session_user_id)],
+ // Assigned to the agent whose calendar it was added from, or the one adding it
+ 'agents' => calendarEventDefaultAgents($_GET['agent_id'] ?? 0),
'contacts' => $form_client_id && intval(assetClientOwnedId('contact', $_GET['contact_id'] ?? 0, $form_client_id)) ? [intval($_GET['contact_id'])] : [],
'emails' => [],
];
diff --git a/agent/modals/calendar/calendar_event_form.php b/agent/modals/calendar/calendar_event_form.php
index 5ec703ea0..12da1cf20 100644
--- a/agent/modals/calendar/calendar_event_form.php
+++ b/agent/modals/calendar/calendar_event_form.php
@@ -8,6 +8,9 @@
* (['agents' => ids, 'contacts' => ids, 'emails' => [...]]) and $form_invited
* (whether anyone has been sent it already). The client's sites and contacts
* follow the client picked (agent/js/calendar_event_modal.js).
+ *
+ * The agents on it are who it is assigned to - Assigned to, beside the title;
+ * the calendar it is kept on is picked only when there is more than one.
*/
isset($mysqli) || die("Direct file access is not allowed");
@@ -23,28 +26,46 @@ if (!isset($form_calendars[$form_calendar_id])) {
$form_calendar_id = isset($form_calendars[intval($config_default_calendar ?? 0)]) ? intval($config_default_calendar) : intval(array_key_first($form_calendars) ?? 0);
}
$form_can_email = calendarCanEmail();
+$form_agents = calendarEventAgentChoices($form_attendees['agents']);
?>
diff --git a/agent/post/event.php b/agent/post/event.php
index 6f44831d9..9a8007947 100644
--- a/agent/post/event.php
+++ b/agent/post/event.php
@@ -9,7 +9,8 @@
* Attendees are agents, the client's contacts and anyone by email; ticking
* "Email the invitation" sends each of them an iCalendar invitation, and from
* then on a change, a skipped occurrence or the deletion goes to the people
- * who have it in their calendar.
+ * who have it in their calendar. An event's agents are who it is assigned to,
+ * changed from its form or its quick look (assign_event).
*/
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
@@ -312,6 +313,25 @@ if (isset($_POST['edit_event'])) {
}
+// Who it is assigned to, from its quick look - its contacts and others by email stay as they are
+if (isset($_POST['assign_event'])) {
+
+ validateCSRFToken();
+
+ $event = calendarEventForRequest($_POST['event_id'] ?? 0, 'edit');
+ [$added, $removed, $sent] = calendarEventSetAgents($event, (array) ($_POST['agents'] ?? []));
+ $words = calendarEventAgentsText($added, $removed);
+
+ if ($words !== '') {
+ logAudit("Calendar Event", "Edit", "$session_name " . escapeSql($words) . " - the event " . escapeSql($event['event_title']), intval($event['event_client_id']), intval($event['event_id']));
+ }
+
+ flashAlert("" . escapeHtml($event['event_title']) . " " . ($words !== '' ? escapeHtml($words) : 'unchanged') . calendarSentText($sent, ''));
+
+ redirect();
+
+}
+
if (isset($_POST['send_event_invites'])) {
validateCSRFToken();
diff --git a/agent/user/post/profile.php b/agent/user/post/profile.php
index aeb9dea51..429d329d2 100644
--- a/agent/user/post/profile.php
+++ b/agent/user/post/profile.php
@@ -123,6 +123,7 @@ if (isset($_POST['edit_your_user_preferences'])) {
mysqli_query($mysqli, "INSERT INTO user_settings SET user_id = $session_user_id, user_config_calendar_first_day = $calendar_first_day, user_config_theme_dark = $dark_mode, user_config_records_per_page = $per_page
ON DUPLICATE KEY UPDATE user_config_calendar_first_day = $calendar_first_day, user_config_theme_dark = $dark_mode, user_config_records_per_page = $per_page");
+ calendarAgentColorSave($session_user_id, $_POST);
logAudit("User Account", "Edit", "$session_name updated their preferences");
diff --git a/agent/user/user_preferences.php b/agent/user/user_preferences.php
index 3a2ff1807..db19e61ef 100644
--- a/agent/user/user_preferences.php
+++ b/agent/user/user_preferences.php
@@ -2,7 +2,8 @@
/*
* Your account > Preferences - how ITFlow looks and behaves for you: light
- * or dark, the day calendars start on, and how many rows a list shows.
+ * or dark, the day calendars start on, your colour on the calendar, and how
+ * many rows a list shows.
*/
require_once "includes/inc_all_user.php";
@@ -59,6 +60,8 @@ $per_page = intval($me['user_config_records_per_page']) ?: 10;