diff --git a/CHANGELOG.md b/CHANGELOG.md index d38e71e8c..3b3090894 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This file documents all notable changes made to ITFlow. ### Upgrading to 26.12 -Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's thirty-eight database changes (3.6.6 to 4.0.5) in the same pass. They add four tables for RMM providers and their alerts, a setting 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, three columns on agents' settings for their calendar color, what their calendar shows and their own time zone, a table for the agents helping on a ticket, three columns on quote lines with three settings for what a quote line costs and how it is priced, a column each on quote lines and products with a setting for their pictures, two settings and a column on tickets for keeping project tickets apart, a table for your other offices with a column each on agents and invites for which one they work from, three settings for the emails and notices your agents get about their tickets, three settings for sending and reading Microsoft 365 mail through Microsoft Graph, five tables, four settings and a role permission for purchase orders, five settings for switching Dispatch, Bookkeeping, Purchasing, Trips and the calendar on and off, and eight tables, three columns and two settings for the Knowledge Base, who can read its articles, what its readers think of them and their files, a column on documents for how often each is reviewed, a column on agents' settings for compact rows, a table for reply drafts, a table for which tickets each agent has opened, two columns on contacts for an email that bounces, a table for credentials' earlier passwords, a column on recurring invoices for a pause with an end, and change nothing that is there. Nothing else is required, but it is a big release, so take a backup before you update. Purchasing starts off - switch it on in Admin > Settings > Modules - and so does the Knowledge Base's public help center, in Admin > Settings > Knowledge Base. This release has thirteen 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 thirty-nine database changes (3.6.6 to 4.0.6) in the same pass. They add four tables for RMM providers and their alerts, a setting 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, three columns on agents' settings for their calendar color, what their calendar shows and their own time zone, a table for the agents helping on a ticket, three columns on quote lines with three settings for what a quote line costs and how it is priced, a column each on quote lines and products with a setting for their pictures, two settings and a column on tickets for keeping project tickets apart, a table for your other offices with a column each on agents and invites for which one they work from, three settings for the emails and notices your agents get about their tickets, three settings for sending and reading Microsoft 365 mail through Microsoft Graph, five tables, four settings and a role permission for purchase orders, five settings for switching Dispatch, Bookkeeping, Purchasing, Trips and the calendar on and off, and eight tables, three columns and two settings for the Knowledge Base, who can read its articles, what its readers think of them and their files, a column on documents for how often each is reviewed, a column on agents' settings for compact rows, a table for reply drafts, a table for which tickets each agent has opened, two columns on contacts for an email that bounces, a table for credentials' earlier passwords, a column on recurring invoices for a pause with an end, a column on calendar events, two columns on agents' settings and a table for reminders, and change nothing that is there. Nothing else is required, but it is a big release, so take a backup before you update. Purchasing starts off - switch it on in Admin > Settings > Modules - and so does the Knowledge Base's public help center, in Admin > Settings > Knowledge Base. This release has thirteen 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 @@ -182,6 +182,10 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Invoices and quotes: Send has Also send to, for an address that isn't one of the client's contacts - their accountant, say. It's for this once and isn't saved. A client with no contact to send to can now be sent one this way. - Quotes: three days before a sent quote runs out with no answer, the people who can see quotes get a notification to follow it up. - Expenses: on a phone or tablet, the picture window has Take a photo, which opens the camera straight away - for a receipt, and for every other picture and photo in ITFlow. +- Timers: the stopwatch in the top bar is always there now, and starts a timer before there is a ticket - for a call that may or may not need one. New ticket opens Quick ticket with the timer carrying on from where it is, and Add to a ticket finds one (your own open tickets until you type) and adds the time to its timer. Picking one of the contact's open tickets in Quick ticket adds it there too. +- Timers: the timers panel says how much time you logged on tickets today and this week - the week starting on the day your calendar does. +- Calendar: an event can remind you - when it starts, or from five minutes to two days before. The agents it's assigned to get a notification, or whoever made it when nobody is, and each time a repeating event comes round. Your account > Preferences has Remind me before work booked for me, for tickets booked with you, and Email me reminders too. Reminders need cron, and go within a minute. +- Projects: a project has a Timeline - its booked tickets as bars in time, from its start to its due date, with now marked. A booking that is past and still open shows in amber, and two of the same agent's at the same time are flagged. Its open tickets with no booking are listed under it, with Book. - Tickets: a ticket shows what its client owes on invoices past their due date, beside the client's name, to agents who can see invoices - with how many and how late the oldest is. It opens their overdue invoices. - Invoices: a draft left more than a week says so on the invoices list, under its status, and Drafts left a week picks them out - In drafts counts them too. The nightly notice about drafts says how many have been left that long, and opens them. - Contacts and assets: an email already on another contact - now when changing a contact too - and a serial number or MAC address already on another asset are named as they're typed, with who or which, and where. @@ -378,6 +382,9 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Credentials: database 4.0.4 adds `password_history` (the encrypted `password_history_password` as it was on the credential, `_set_at`, `_replaced_at`, `_user_id`, and `_credential_id` with an `ON DELETE CASCADE` key to `credentials`). `credentialPasswordKeep()` in `functions/credential.php` copies the current password there and keeps the newest `CREDENTIAL_PASSWORD_HISTORY_KEEP` (10); `edit_credential`, `rotate_credential`, the API's `credentials/update` and the credential import call it before a password that wasn't empty changes. `credentialPasswordHistory()`, `credentialPasswordHistoryRow()` and `credentialPasswordHistoryReady()`. `get_credential_via_id` takes `history_id`, logged once in 5 minutes as a View; `credentialPasswordHtml()` takes the history id as `data-credential-history`, which `js/credentials.js` sends. `restore_credential_password` (Credential edit) and `delete_credential_password_history` (Credential delete) in `agent/post/credential.php`. `credentialReusedPasswords($where)` decrypts the passwords in `$where` and groups them by client and SHA-256 in memory; `credentialReusedPill()`, and the `reused` pill on `agent/credentials.php`. - Recurring invoices: database 4.0.5 adds `recurring_invoices.recurring_invoice_paused_until` (`recurringPauseReady()`). `recurringInvoiceResumePaused()` (nightly, before the run that bills) sets status 1 and clears it once the day has come, moving the next date on with `recurringInvoiceCatchUp()`; `recurring_invoice_set_status` and `edit_recurring_invoice` clear it on a resume. `bulk_recurring_invoices` in `agent/post/billing.php` takes `bulk_action` (`pause` with `paused_until`, `resume`, `next_date`, `frequency`) and `recurring_invoice_ids[]`, from the list's bulk menu and `agent/modals/recurring_invoice/recurring_invoice_bulk.php` - also the single Pause on the list and the page. `copy_recurring_invoice` (`agent/post/recurring_invoice.php`, `recurring_invoice_copy.php`) copies the row and its lines, `item_seat_*` kept except for `license` seat lines, then runs `recurringInvoiceRefresh()`. - Billing: `billingEmailExtraRecipients()`, `billingEmailMergeRecipients()` and `billingEmailExtraField()` in `functions/billing_email.php` - `email_invoice` and `email_quote` take `extra_emails` beside `contacts[]`, recipients with id 0. `billingClientOverdue()` for the ticket page (Sales read). `invoiceDraftAgePill()` and `INVOICE_DRAFT_STALE_DAYS` (7) - the `StaleDraft` status on `agent/invoices.php`. `QUOTE_EXPIRY_NUDGE_DAYS` (3) - the nightly `Quote Expiring` notification, a Sales type in `notificationTypeModules()`. `js/picture_field.js` adds a `capture="environment"` input behind Take a photo where the pointer is coarse. +- Reminders: database 4.0.6 adds `calendar_events.event_reminder` (minutes before, `NULL` for none), `user_settings.user_config_booking_reminder` and `user_config_reminder_email`, and `calendar_reminders` (`reminder_kind` `event` or `ticket`, `reminder_item_id`, `reminder_for`, `reminder_user_id` as the primary key, so each occurrence goes once). `functions/calendar_reminders.php`: `calendarRemindersReady()`, `CALENDAR_REMINDER_CHOICES`, `calendarReminderOptions()`, `calendarReminderFromInput()` and `calendarRemindersRun()`, which sends what came due in the last `CALENDAR_REMINDER_GRACE_MINUTES` (10) - repeating events through `expandRecurringEvent()` - as `Calendar Reminder` and `Booking Reminder` notifications to one agent each, and by `emailQueue()` to those who asked. `cron/calendar_reminders.php` runs it every minute (`includes/cron_jobs.php`, `calendar_reminders`), and nightly clears rows older than 60 days. `agent/calendar.php?event=ID` opens the event's quick look. +- Timers: `js/ticket_timers.js` keeps the timer without a ticket in `call-startTime` / `call-pausedTime`, and exposes `window.itflowTicketTimers.giveCall(ticketId)`. `ticket_quick.php?call=1` posts `quick_ticket_timer` or `quick_ticket_paused` with `quick_ticket_call`; `quickTicketAfterCreate()` keeps either whatever the Quick ticket timer setting, and `quickTicketTimerScript()` sets the ticket's timer and removes the call keys. `agent/ajax.php` adds `ticket_timer_search` (open tickets, scoped, 8) and `my_time_logged` (seconds today and this week from the agent's replies, by `ticket_reply_work_start` when there is one). +- Projects: `projectTimeline($project, $tickets, $first_day)` in `functions/project.php` - bars, ticks by day, week or month, the now / start / due markers and same-agent clashes - for the Timeline tab on `agent/project.php`. ## [26.11.8] diff --git a/admin/database_updates/4.0.6.php b/admin/database_updates/4.0.6.php new file mode 100644 index 000000000..7da07b89d --- /dev/null +++ b/admin/database_updates/4.0.6.php @@ -0,0 +1,44 @@ + 0; + }; + + if (!$itflow_column('calendar_events', 'event_reminder')) { + mysqli_query($mysqli, "ALTER TABLE `calendar_events` ADD `event_reminder` int(11) DEFAULT NULL AFTER `event_sequence`"); + } + if (!$itflow_column('user_settings', 'user_config_booking_reminder')) { + mysqli_query($mysqli, "ALTER TABLE `user_settings` ADD `user_config_booking_reminder` int(11) DEFAULT NULL AFTER `user_config_compact_rows`"); + } + if (!$itflow_column('user_settings', 'user_config_reminder_email')) { + mysqli_query($mysqli, "ALTER TABLE `user_settings` ADD `user_config_reminder_email` tinyint(1) NOT NULL DEFAULT 0 AFTER `user_config_booking_reminder`"); + } + + mysqli_query($mysqli, "CREATE TABLE IF NOT EXISTS `calendar_reminders` ( + `reminder_kind` varchar(10) NOT NULL, + `reminder_item_id` int(11) NOT NULL, + `reminder_for` datetime NOT NULL, + `reminder_user_id` int(11) NOT NULL, + `reminder_sent_at` datetime NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`reminder_kind`, `reminder_item_id`, `reminder_for`, `reminder_user_id`), + KEY `reminder_sent_at` (`reminder_sent_at`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci"); diff --git a/agent/ajax.php b/agent/ajax.php index 5403cac43..b26a582a2 100644 --- a/agent/ajax.php +++ b/agent/ajax.php @@ -1741,6 +1741,64 @@ if (isset($_GET['ticket_timer_tickets'])) { exit; } +/* + * The top bar's timers panel (js/ticket_timers.js): open tickets to put a timer + * started before there was a ticket on - by number, subject or client, or with + * nothing typed the agent's own, latest first. Only tickets the agent can open. + */ +if (isset($_GET['ticket_timer_search'])) { + header('Content-Type: application/json'); + + $found = []; + if (lookupUserPermission('module_support') >= 1) { + $search = trim((string) ($_GET['q'] ?? '')); + $where = "ticket_archived_at IS NULL AND " . TICKET_OPEN_SQL . clientScopeSql('ticket_client_id'); + if ($search === '') { + $where .= " AND ticket_assigned_to = " . intval($session_user_id); + } else { + $like = escapeSql(str_replace(['%', '_'], ['\\%', '\\_'], mb_substr($search, 0, 100))); + $number = intval(preg_replace('/\D/', '', $search)); + $where .= " AND (ticket_subject LIKE '%$like%' OR client_name LIKE '%$like%'" . ($number ? " OR ticket_number = $number" : '') . ")"; + } + $sql = mysqli_query($mysqli, "SELECT ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_client_id, client_name + FROM tickets LEFT JOIN clients ON client_id = ticket_client_id + WHERE $where + ORDER BY ticket_updated_at DESC, ticket_id DESC LIMIT 8"); + while ($row = mysqli_fetch_assoc($sql)) { + $found[] = [ + 'id' => intval($row['ticket_id']), + 'reference' => ticketReference($row), + 'subject' => html_entity_decode((string) $row['ticket_subject'], ENT_QUOTES, 'UTF-8'), + 'client' => html_entity_decode((string) $row['client_name'], ENT_QUOTES, 'UTF-8'), + 'client_id' => intval($row['ticket_client_id']), + ]; + } + } + echo json_encode($found); + exit; +} + +/* + * The agent's own time logged on tickets today and this week - the week starting on the + * day their calendars do - for the top bar's timers panel (js/ticket_timers.js). In seconds. + */ +if (isset($_GET['my_time_logged'])) { + header('Content-Type: application/json'); + + $first_day = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT user_config_calendar_first_day FROM user_settings WHERE user_id = " . intval($session_user_id)))[0] ?? 0) === 1 ? 1 : 0; + $today = date('Y-m-d'); + $week_start = date('Y-m-d', strtotime($today . ' -' . ((intval(date('w')) - $first_day + 7) % 7) . ' days')); + $day_sql = function_exists('ticketWorkTimesReady') && ticketWorkTimesReady() ? 'DATE(COALESCE(ticket_reply_work_start, ticket_reply_created_at))' : 'DATE(ticket_reply_created_at)'; + $row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT + COALESCE(SUM(CASE WHEN $day_sql = '$today' THEN TIME_TO_SEC(ticket_reply_time_worked) END), 0), + COALESCE(SUM(TIME_TO_SEC(ticket_reply_time_worked)), 0) + FROM ticket_replies + WHERE ticket_reply_by = " . intval($session_user_id) . " AND ticket_reply_archived_at IS NULL AND ticket_reply_time_worked IS NOT NULL + AND ticket_reply_type != 'Client' AND ticket_reply_created_at >= '$week_start' - INTERVAL 1 DAY AND $day_sql BETWEEN '$week_start' AND '$today'")); + echo json_encode(['today' => intval($row[0]), 'week' => intval($row[1]), 'week_start' => $week_start]); + exit; +} + /* * Returns ordered list of active assets for a specified client */ diff --git a/agent/calendar.php b/agent/calendar.php index e6aca9e17..9092a8def 100644 --- a/agent/calendar.php +++ b/agent/calendar.php @@ -209,3 +209,18 @@ foreach ($sources as $key => $source) { + + + diff --git a/agent/js/ticket_quick.js b/agent/js/ticket_quick.js index 1cd5227fc..90c21af73 100644 --- a/agent/js/ticket_quick.js +++ b/agent/js/ticket_quick.js @@ -4,7 +4,10 @@ * says so - and the contact's tickets still open, with Work on this one to go * to one instead. Make ticket sends when the new ticket's timer counts from, * by this browser's clock, as the ticket page's timer is this browser's - * (agent/js/ticket_time_tracking.js). Run again each time the window opens. + * (agent/js/ticket_time_tracking.js). Opened from the top bar's timer that + * was started before there was a ticket (?call=1, js/ticket_timers.js), the + * new ticket's timer carries on from it - running or paused - and that timer + * is cleared once the ticket is made. Run again each time the window opens. */ (function () { 'use strict'; @@ -24,7 +27,29 @@ let contactRequest = 0; let openRequest = 0; + // The timer started before there was a ticket - its seconds, and whether it is counting + const fromCall = form.dataset.call === '1'; + function callTimer() { + try { + const start = parseInt(localStorage.getItem('call-startTime') || '0', 10); + const paused = parseInt(localStorage.getItem('call-pausedTime') || '0', 10); + return { running: !!start, seconds: paused + (start ? Math.max(0, Math.floor((Date.now() - start) / 1000)) : 0) }; + } catch (e) { + return { running: false, seconds: 0 }; + } + } + if (fromCall) { + const shown = form.querySelector('[data-call-time]'); + const seconds = callTimer().seconds; + if (shown && seconds) { + shown.textContent = ' - ' + Math.floor(seconds / 3600) + ':' + String(Math.floor(seconds % 3600 / 60)).padStart(2, '0') + ' so far'; + } + } + function timerStart() { + if (fromCall) { + return Date.now() - callTimer().seconds * 1000; + } return timerMode === 'open' ? openedAt : Date.now(); } @@ -124,13 +149,22 @@ if (!button) { return; } - if (timerMode !== 'off') { + if (fromCall && window.itflowTicketTimers && window.itflowTicketTimers.giveCall) { + // The time without a ticket goes onto this one + window.itflowTicketTimers.giveCall(button.dataset.ticketWork); + } else if (timerMode !== 'off') { startTimer(button.dataset.ticketWork, timerStart()); } window.location.href = button.dataset.url; }); form.addEventListener('submit', function () { + if (fromCall) { + const call = callTimer(); + document.getElementById('quickTicketTimer').value = call.running ? String(Date.now() - call.seconds * 1000) : ''; + document.getElementById('quickTicketPaused').value = call.running ? '' : String(call.seconds); + return; + } document.getElementById('quickTicketTimer').value = timerMode === 'off' ? '' : String(timerStart()); }); diff --git a/agent/modals/calendar/calendar_event.php b/agent/modals/calendar/calendar_event.php index 9d5a2100f..103e7b031 100644 --- a/agent/modals/calendar/calendar_event.php +++ b/agent/modals/calendar/calendar_event.php @@ -87,6 +87,9 @@ ob_start(); }, calendarSkippedDates($event)))) ?> + +