From b8db50adfa53c237cb452febf6ba86c5b44c20ac Mon Sep 17 00:00:00 2001 From: johnnyq Date: Mon, 30 Nov 2026 14:01:11 -0500 Subject: [PATCH] Rename watchers to CCs in the database and code: database 4.2.8 renames ticket_watchers to ticket_ccs with its columns and index, functions, settings, form and post names, the Add CC modal file, JavaScript IDs, the email preview key and the To line group follow; the ticket email parser waits while a database update is pending instead of flagging email it cannot take; 26.12.3 changelog updated --- CHANGELOG.md | 16 ++-- admin/database_updates/4.2.8.php | 55 +++++++++++++ admin/mail_preview.php | 2 +- admin/post/demo_data_model.php | 14 ++-- agent/ajax.php | 2 +- agent/js/tickets_add_modal.js | 12 +-- agent/modals/ticket/ticket_add.php | 2 +- ...cket_add_watcher.php => ticket_add_cc.php} | 8 +- .../ticket/ticket_resolve_no_response.php | 8 +- agent/post/client.php | 2 +- agent/post/ticket.php | 58 +++++++------- agent/ticket.php | 28 +++---- api/v1/ticket_replies/create.php | 4 +- api/v1/tickets/create.php | 2 +- cron/ticket_email_parser.php | 57 +++++++------ db.sql | 34 ++++---- functions/dispatch.php | 2 +- functions/email.php | 2 +- functions/email_preview.php | 6 +- functions/ticket.php | 80 +++++++++---------- functions/ticket_mail_thread.php | 12 +-- functions/ticket_mail_try.php | 14 ++-- functions/ticket_reply_recipients.php | 16 ++-- functions/ticket_status.php | 2 +- guest/guest_post.php | 2 +- guest/guest_view_ticket.php | 2 +- 26 files changed, 253 insertions(+), 189 deletions(-) create mode 100644 admin/database_updates/4.2.8.php rename agent/modals/ticket/{ticket_add_watcher.php => ticket_add_cc.php} (92%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40cb49e16..c3a2495ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This file documents all notable changes made to ITFlow. ### Upgrading to 26.12.3 -Update from Maintenance > Update as usual - this release has six database changes: 4.2.2 adds a table for passkeys and a setting to turn them on or off, 4.2.3 lets a document keep the Markdown it was written in, 4.2.4 lets a ticket keep its pictures as files, 4.2.5 adds identity providers, 4.2.6 keeps each ticket's email conversation together, and 4.2.7 lets a reply from a CC say who sent it. The client portal's Microsoft 365 single sign-on becomes the first identity provider, for client contacts, and keeps its redirect address, so nothing changes in Microsoft Entra. Nothing else is required: passkeys are on, and no one has one until they add it. Pictures already inside tickets move to files in the background afterwards - the new Ticket Pictures job in Maintenance > Cron does a batch a minute, so an install with years of emailed screenshots may take a while, and tickets work as usual meanwhile. A passkey is made for your ITFlow's address (the one in config.php) and only works there, over HTTPS - if you move ITFlow to a new address, everyone adds theirs again. Watchers are called CCs now. Emails about a ticket go to its contact with the CCs copied in, rather than one each - Admin > Settings > Tickets has the switch, under Emails about a ticket. +Update from Maintenance > Update as usual - this release has seven database changes: 4.2.2 adds a table for passkeys and a setting to turn them on or off, 4.2.3 lets a document keep the Markdown it was written in, 4.2.4 lets a ticket keep its pictures as files, 4.2.5 adds identity providers, 4.2.6 keeps each ticket's email conversation together, 4.2.7 lets a reply from a CC say who sent it, and 4.2.8 renames the watchers table for CCs. The client portal's Microsoft 365 single sign-on becomes the first identity provider, for client contacts, and keeps its redirect address, so nothing changes in Microsoft Entra. Nothing else is required: passkeys are on, and no one has one until they add it. Pictures already inside tickets move to files in the background afterwards - the new Ticket Pictures job in Maintenance > Cron does a batch a minute, so an install with years of emailed screenshots may take a while, and tickets work as usual meanwhile. A passkey is made for your ITFlow's address (the one in config.php) and only works there, over HTTPS - if you move ITFlow to a new address, everyone adds theirs again. Watchers are called CCs now. Emails about a ticket go to its contact with the CCs copied in, rather than one each - Admin > Settings > Tickets has the switch, under Emails about a ticket. ### New Features & Updates @@ -73,6 +73,7 @@ Update from Maintenance > Update as usual - this release has six database change - A client who CCs your support mailbox no longer adds it to the ticket's CCs. As one, every email about the ticket went back into the mailbox, came back in as a note and reopened the ticket - a resolved ticket reopened a minute later. Mail from ITFlow's own addresses is now set aside in the ITFlow folder without a ticket, and nothing about a ticket is emailed to them, so a support mailbox already on a ticket's CCs stops getting copies too. - Email new tickets to (Admin > Settings > Tickets) can't be the mailbox ITFlow reads tickets from any more: each notice could come back in as a new email and raise another ticket, whose notice raised another, every minute. One saved before isn't emailed. - Email someone opened before ITFlow got to it - Outlook marks an email read as soon as it shows it - is made a ticket now, when it came in the last hour. It used to stay in the mailbox for good. Read email older than that, such as what was there when the mailbox was connected, is left alone. +- Emails to the ticket mailbox wait there while a database update is waiting to run, and come in once it has. Before, an email that came in during an update could fail and stay in the mailbox for good. - An email to a domain whose mail server couldn't be found is tried again like any other failed email, and a domain with no MX record that takes mail at its own address is found. One failed lookup used to fail the email for good. - After the ticket prefix was changed (Admin > Settings > Tickets), a reply to an older ticket - its number with the old prefix - became a new ticket. It finds its ticket now, and so does a number written with zeros in front. - A reply to an email of a ticket that was merged into another goes on the ticket it was merged into, rather than being turned away as a reply to a closed ticket. @@ -112,18 +113,19 @@ Update from Maintenance > Update as usual - this release has six database change - agent/includes/inc_all_client.php: without a client_id, or with one that isn't there, it draws That client isn't here in the agent layout and exits, before anything queries with no client - it was an SQL error (or a tagPills() TypeError) and a blank page. admin/modules.php and its commented-out menu entry are removed. - Tabs in agent/modals/product/product_form.php, service/service_form.php, calendar/calendar_event_form.php, expense/expense_form.php and ticket/ticket_add.php, and in admin/modals/payment_provider/payment_provider_edit.php, rmm/rmm_provider_edit.php, identity_provider/identity_provider_edit.php and ticket_status/ticket_status_form.php - the same field names, so the posts and their handlers are unchanged. js/app.js has window.itflowRevealTab(field), used by the invalid-field handler and by the provider windows' server-check errors, to open the tab a field is on. - admin/modals/role/role_form.php draws a module as a list-group row with data-role-allows (its levels' text as JSON); js/role_form.js writes what the level picked allows into [data-role-can]. agent/modals/ticket/ticket_edit.php takes ?tab=planning. ticket_invoice_add.php posts scope as a hidden field, so add_invoice_from_ticket is unchanged. .itflow-tag-icons is three rows high (6.6rem), and js/app.js scrolls its .active icon into the box on shown.bs.modal and shown.bs.tab. -- Mail loop: emailOwnAddresses() (functions/email.php - the From mailboxes and config_imap_username) is skipped by cron/ticket_email_parser.php before anything else (moved to the ITFlow folder, App Logs info), left out of CC watchers there and in ticketAddWatchers(), filtered out of ticketMailSend()'s recipients and ticketColleagueRecipients(), and not offered in the reply To line (ticketReplyRecipients()). emailReadMailbox() - the Receiving username or the ticket mailbox, while email-to-ticket is on - is refused for config_ticket_new_ticket_notification_email and skipped by ticketMailNewTicketAddress(). Try an Email (functions/ticket_mail_try.php) asks the same first. +- Mail loop: emailOwnAddresses() (functions/email.php - the From mailboxes and config_imap_username) is skipped by cron/ticket_email_parser.php before anything else (moved to the ITFlow folder, App Logs info), left out of CCs there and in ticketAddCcs(), filtered out of ticketMailSend()'s recipients and ticketColleagueRecipients(), and not offered in the reply To line (ticketReplyRecipients()). emailReadMailbox() - the Receiving username or the ticket mailbox, while email-to-ticket is on - is refused for config_ticket_new_ticket_notification_email and skipped by ticketMailNewTicketAddress(). Try an Email (functions/ticket_mail_try.php) asks the same first. - Read mail: the parser's unseen query is followed, when it has room, by seen() unflagged() since(yesterday) newest(), kept when the Date header is within $read_mail_minutes (60). MailGraphMessageQuery (functions/mail_graph_mailbox.php) now honours seen(), unseen(), since() and newest() - isRead eq true, receivedDateTime desc. - cron/mail_queue.php: mailQueueDomainProblem() (functions/mail_queue.php - MX, else A or AAAA, once a domain a run) is a normal failed try in the send path (attempts 1, not 99) and is asked again in the retry path before each send; --no-mx-validation still skips it. - functions/ticket_mail_thread.php, database 4.2.6: ticket_mail_threads keeps each Message-ID of a ticket's emails - the client's, and ITFlow's (mail_thread_ours 1, itflow..@). ticketMailHeaders() gives a queued email its Message-ID, In-Reply-To (the latest kept) and References (the first and the latest, 10 at most). In cron/ticket_email_parser.php, ticketMailHeaderTicket() matches In-Reply-To, then References latest first, before the subject; ticketMailSubjectTicket() matches [] against each ticket's own ticket_prefix, trying each split of the trailing digits, in place of the config prefix regex there, in the bounce path and in Try an Email; ticketMailIdTicket() skips an email whose Message-ID is kept already. ticketMergeInto() moves the merged ticket's rows; deleting a ticket deletes them (ON DELETE CASCADE). 4.2.6 also indexes tickets.ticket_number, which every email with a number in brackets is looked up by. - emailQueue() takes together (one email to the first recipient, the rest in email_queue.email_cc as JSON, with together_footnote) and thread (a ticket id, with answering). addToMailQueue() writes email_cc and email_headers as JSON with mysqli_real_escape_string(), as escapeSql() strips <...>. sendQueueEmail() in cron/mail_queue.php takes them: addCC(), MessageID, and addCustomHeader() for MAIL_QUEUE_HEADERS only (mailQueueHeaders() - Message-ID, In-Reply-To, References, each a list of ). Development mode names the Cc in the subject. A large Microsoft Graph email sent as a draft (mailGraphSendLarge()) goes without In-Reply-To and References. -- ticketMailSend($ticket_id, $email, $opts) no longer takes a subject: ticketEmailSubject() is the subject of every client email about a ticket, ticketMailWatchersAdded(), ticketMailColleaguesNew() and ticketMailClosedReply($ticket_id, $from_email, $answering) included - not the task approval email. ticketMailCreated() lost its $subject_prefix argument. Its recipients carry a group, and the contact goes first. ticketReplyEmailed() and ticketReplyEmailStates() count email_cc; ticketReplyRecipientsPick() takes $remember (false keeps nothing in ticket_mail_choices) and returns each one's group. -- ticketMailRelayClientReply() (client/post.php, functions/sms.php, and the parser for a reply matched by its headers) sends ticketEmailContent()'s client_reply kind to the To line's people (ticketReplyRecipients() send) less the author, the email's From, To and Cc, and agents. ticketMailCopiedWatchers() (the parser's addTicket(), and addReply() unless from a stranger or an agent) adds To and Cc less ITFlow's own addresses, emailOwnDomain() (functions/email.php - their domains, not EMAIL_PUBLIC_DOMAINS), agents and no-reply addresses. addReply() takes a ticket id and $email (message_id, copied, had, threaded). settings.config_ticket_email_copy and config_ticket_email_relay, both 1 (ticketMailSettings()). +- ticketMailSend($ticket_id, $email, $opts) no longer takes a subject: ticketEmailSubject() is the subject of every client email about a ticket, ticketMailCcsAdded(), ticketMailColleaguesNew() and ticketMailClosedReply($ticket_id, $from_email, $answering) included - not the task approval email. ticketMailCreated() lost its $subject_prefix argument. Its recipients carry a group, and the contact goes first. ticketReplyEmailed() and ticketReplyEmailStates() count email_cc; ticketReplyRecipientsPick() takes $remember (false keeps nothing in ticket_mail_choices) and returns each one's group. +- ticketMailRelayClientReply() (client/post.php, functions/sms.php, and the parser for a reply matched by its headers) sends ticketEmailContent()'s client_reply kind to the To line's people (ticketReplyRecipients() send) less the author, the email's From, To and Cc, and agents. ticketMailCopiedCcs() (the parser's addTicket(), and addReply() unless from a stranger or an agent) adds To and Cc less ITFlow's own addresses, emailOwnDomain() (functions/email.php - their domains, not EMAIL_PUBLIC_DOMAINS), agents and no-reply addresses. addReply() takes a ticket id and $email (message_id, copied, had, threaded). settings.config_ticket_email_copy and config_ticket_email_relay, both 1 (ticketMailSettings()). - Admin > Mail Queue shows and searches email_cc, the email's window has a Cc line, and Admin > Mail previews show one (admin/mail_preview.php cc) and have a Client's reply, passed on. - functions/ticket_mail_auto.php: ticketMailHeaderMap() (lower-case name => raw value), ticketMailIsBounce() (multipart/report with report-type=delivery-status, X-Failed-Recipients, or a TICKET_MAIL_BOUNCE_SENDERS local part - replacing the /daemon|postmaster|bounce|mta/i pattern), ticketMailAutomaticKind() (auto-reply: Auto-Submitted auto-replied, Precedence auto_reply, X-Autoreply, X-Autorespond, or an "Automatic reply:"/"Out of Office:" subject with X-Auto-Response-Suppress or a [ticket number]; automated: any other Auto-Submitted but no, Precedence bulk/list/junk, List-Id, List-Unsubscribe), ticketMailBounceRead() (each message/delivery-status block's Final-Recipient, Action, Status and Diagnostic-Code, the returned message/rfc822 or text/rfc822-headers Message-ID and Subject, X-Failed-Recipients as a fallback), ticketMailAutoHeaders() and ticketMailAnswersLeft() (TICKET_MAIL_ANSWERS_AN_HOUR, counted from email_headers like auto-replied). -- cron/ticket_email_parser.php: bounces go to addBounce() right after the own-address check, and step 6 is now only unknown senders. addReply() sorts the sender into contact (the ticket's or the client's), agent, watcher or stranger, takes $email from_name and automatic, keeps a closed ticket's or an automatic reply's email as an Internal note (ticket_reply_by 0), and answers only a contact or watcher, never anything automatic, within ticketMailAnswersLeft(). addTicket() returns the ticket id, takes $automatic and acknowledges only a person's email; the fuzzy step replies only for the ticket's contact or a watcher and otherwise links the new ticket with linkSimilarTicket() (ticketLinkTogether(), as The email parser). emailQueue() and ticketMailSend() take auto (replied or generated); MAIL_QUEUE_HEADERS is now name => pattern and allows Auto-Submitted and X-Auto-Response-Suppress. The ack ("how" email), ticketMailClosedReply(), ticketMailColleaguesNew() and ticketMailRelayClientReply() send them. -- Database 4.2.7: ticket_replies.ticket_reply_from_name and ticket_reply_from_email, set on a client reply from a watcher (ticketReplyFromReady()). ticketReplyAuthorSql() selects COALESCE(contact_name, ticket_reply_from_name, ticket_reply_from_email) AS contact_name in every reply query that names a client reply - the ticket page, quick look, split, pulse, project and email history, AI summaries, the portal and the guest page. Try an Email (functions/ticket_mail_try.php) follows: a bounce address first, automatic replies as a note or set aside, watchers as client replies, closed tickets as notes, and near-same subjects from someone else linked. -- Watchers are CCs in every page, email, ticket history line, log and message. The code, the ticket_watchers table and the API keep the watcher names for now. +- cron/ticket_email_parser.php: bounces go to addBounce() right after the own-address check, and step 6 is now only unknown senders. addReply() sorts the sender into contact (the ticket's or the client's), agent, cc or stranger, takes $email from_name and automatic, keeps a closed ticket's or an automatic reply's email as an Internal note (ticket_reply_by 0), and answers only a contact or CC, never anything automatic, within ticketMailAnswersLeft(). addTicket() returns the ticket id, takes $automatic and acknowledges only a person's email; the fuzzy step replies only for the ticket's contact or a CC and otherwise links the new ticket with linkSimilarTicket() (ticketLinkTogether(), as The email parser). emailQueue() and ticketMailSend() take auto (replied or generated); MAIL_QUEUE_HEADERS is now name => pattern and allows Auto-Submitted and X-Auto-Response-Suppress. The ack ("how" email), ticketMailClosedReply(), ticketMailColleaguesNew() and ticketMailRelayClientReply() send them. +- Database 4.2.7: ticket_replies.ticket_reply_from_name and ticket_reply_from_email, set on a client reply from a CC (ticketReplyFromReady()). ticketReplyAuthorSql() selects COALESCE(contact_name, ticket_reply_from_name, ticket_reply_from_email) AS contact_name in every reply query that names a client reply - the ticket page, quick look, split, pulse, project and email history, AI summaries, the portal and the guest page. Try an Email (functions/ticket_mail_try.php) follows: a bounce address first, automatic replies as a note or set aside, CCs as client replies, closed tickets as notes, and near-same subjects from someone else linked. +- Watchers are CCs in every page, email, ticket history line, log and message, and in the code. Database 4.2.8 renames ticket_watchers to ticket_ccs and its watcher_id, watcher_name, watcher_email and watcher_ticket_id to ticket_cc_id, ticket_cc_name, ticket_cc_email and ticket_cc_ticket_id, with its index. ticketWatcherEmails(), ticketAddWatchers(), ticketMailWatchersAdded() and ticketMailCopiedWatchers() are ticketCcEmails(), ticketAddCcs(), ticketMailCcsAdded() and ticketMailCopiedCcs(); ticketMailSend()'s to_watchers and ticketMailCreated()'s $to_watchers are to_ccs; the watcher group, email kind and sender are cc; the posts add_ticket_watcher (watcher_email, watcher_notify), delete_ticket_watcher and New Ticket's watchers[] are add_ticket_cc (cc_email, cc_notify), delete_ticket_cc and ccs[]; agent/modals/ticket/ticket_add_watcher.php is ticket_add_cc.php; the email preview ticket_watcher is ticket_cc. +- The ticket email parser waits while a database update is pending, rather than flag email it can't take - a flagged email is left in the mailbox for good. ## [26.12.2] diff --git a/admin/database_updates/4.2.8.php b/admin/database_updates/4.2.8.php new file mode 100644 index 000000000..90d13c08b --- /dev/null +++ b/admin/database_updates/4.2.8.php @@ -0,0 +1,55 @@ + ticket_ccs + * watcher_id -> ticket_cc_id + * watcher_name -> ticket_cc_name + * watcher_email -> ticket_cc_email + * watcher_ticket_id -> ticket_cc_ticket_id, its index with it + * + * Re-runnable: the table is renamed only while ticket_watchers is there and ticket_ccs isn't, and + * each column and the index only while it has its old name. + */ + +defined('FROM_DB_UPDATER') || die("Direct file access is not allowed"); + + $itflow_table_exists = function ($table) use ($mysqli) { + $result = mysqli_query($mysqli, "SELECT 1 FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = '$table' LIMIT 1"); + return $result && mysqli_num_rows($result) > 0; + }; + if ($itflow_table_exists('ticket_watchers') && !$itflow_table_exists('ticket_ccs')) { + mysqli_query($mysqli, "RENAME TABLE `ticket_watchers` TO `ticket_ccs`"); + } + + if ($itflow_table_exists('ticket_ccs')) { + $itflow_cc_columns = [ + 'watcher_id' => "`ticket_cc_id` int(11) NOT NULL AUTO_INCREMENT", + 'watcher_name' => "`ticket_cc_name` varchar(255) DEFAULT NULL", + 'watcher_email' => "`ticket_cc_email` varchar(255) NOT NULL", + 'watcher_ticket_id' => "`ticket_cc_ticket_id` int(11) NOT NULL", + ]; + foreach ($itflow_cc_columns as $itflow_old_column => $itflow_definition) { + $itflow_column_exists = mysqli_query($mysqli, "SELECT 1 FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'ticket_ccs' AND COLUMN_NAME = '$itflow_old_column' LIMIT 1"); + if ($itflow_column_exists && mysqli_num_rows($itflow_column_exists) > 0) { + mysqli_query($mysqli, "ALTER TABLE `ticket_ccs` CHANGE `$itflow_old_column` $itflow_definition"); + } + } + + // The index on the ticket, under its new name + $itflow_index = function ($name) use ($mysqli) { + $result = mysqli_query($mysqli, "SELECT 1 FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'ticket_ccs' AND INDEX_NAME = '$name' LIMIT 1"); + return $result && mysqli_num_rows($result) > 0; + }; + if ($itflow_index('watcher_ticket_id')) { + mysqli_query($mysqli, "ALTER TABLE `ticket_ccs` DROP INDEX `watcher_ticket_id`"); + } + if (!$itflow_index('ticket_cc_ticket_id')) { + mysqli_query($mysqli, "ALTER TABLE `ticket_ccs` ADD KEY `ticket_cc_ticket_id` (`ticket_cc_ticket_id`)"); + } + } diff --git a/admin/mail_preview.php b/admin/mail_preview.php index 239fbeed8..d0bd4327d 100644 --- a/admin/mail_preview.php +++ b/admin/mail_preview.php @@ -41,7 +41,7 @@ echo json_encode([ 'subject' => $email['subject'] ?? '', 'from' => $email ? ($email['from'] !== '' ? $person($email['from_name'], $email['from']) : 'No address yet - set it under From Addresses') : '', 'to' => $email ? $person($email['to_name'], $email['to']) : '', - // Copied in on it - a ticket's watchers, on one email with its contact (emailQueue()'s together) + // Copied in on it - a ticket's CCs, on one email with its contact (emailQueue()'s together) 'cc' => $email ? array_map(function ($copied) use ($person) { return $person($copied['name'], $copied['email']); }, $email['cc'] ?? []) : [], 'also' => array_values(array_unique($others)), 'calendar' => !empty($email['cal_str']), diff --git a/admin/post/demo_data_model.php b/admin/post/demo_data_model.php index 271d2ee8e..9932a8c23 100644 --- a/admin/post/demo_data_model.php +++ b/admin/post/demo_data_model.php @@ -827,7 +827,7 @@ function demoDataRemove($mysqli) { mysqli_query($mysqli, "DELETE FROM ticket_replies WHERE ticket_reply_ticket_id IN ($ticket_ids)"); mysqli_query($mysqli, "DELETE FROM ticket_history WHERE ticket_history_ticket_id IN ($ticket_ids)"); mysqli_query($mysqli, "DELETE FROM ticket_assets WHERE ticket_id IN ($ticket_ids)"); - mysqli_query($mysqli, "DELETE FROM ticket_watchers WHERE watcher_ticket_id IN ($ticket_ids)"); + mysqli_query($mysqli, "DELETE FROM ticket_ccs WHERE ticket_cc_ticket_id IN ($ticket_ids)"); mysqli_query($mysqli, "DELETE FROM ticket_views WHERE view_ticket_id IN ($ticket_ids)"); mysqli_query($mysqli, "DELETE FROM ticket_reads WHERE ticket_id IN ($ticket_ids)"); mysqli_query($mysqli, "DELETE FROM ticket_attachments WHERE ticket_attachment_ticket_id IN ($ticket_ids)"); @@ -2602,11 +2602,11 @@ function demoSeedTicket($mysqli, $fields, $trail, $context, &$counts) { } - // A watcher, where somebody else wanted to be kept in the loop - if (!empty($trail['watcher'])) { - starterInsert($mysqli, 'ticket_watchers', [ - 'watcher_email' => $trail['watcher'], - 'watcher_ticket_id' => $ticket_id, + // A CC, where somebody else wanted to be kept in the loop + if (!empty($trail['cc'])) { + starterInsert($mysqli, 'ticket_ccs', [ + 'ticket_cc_email' => $trail['cc'], + 'ticket_cc_ticket_id' => $ticket_id, ]); } @@ -2937,7 +2937,7 @@ function demoBuildTickets($mysqli, $profile, $index, $client_id, $contact_ids, $ 'sla_paused_at' => $on_hold ? demoDateTime(max(0, $stage['created'] - 1), 11, 30) : '', 'replies' => $replies, 'tasks' => !$stage['closed'] ? ($ticket['tasks'] ?? []) : [], - 'watcher' => $slot === 3 && $contact_ids ? demoContactEmail($profile['people'][0][0], $profile['domain']) : '', + 'cc' => $slot === 3 && $contact_ids ? demoContactEmail($profile['people'][0][0], $profile['domain']) : '', ], $context, $counts); } diff --git a/agent/ajax.php b/agent/ajax.php index 66937d547..321b793ed 100644 --- a/agent/ajax.php +++ b/agent/ajax.php @@ -3166,7 +3166,7 @@ if (isset($_GET['calendar_items'])) { * Something dragged on the calendar: a scheduled ticket to a new time, a * ticket from To schedule onto the calendar, or an event that does not repeat * to a new day or length. A ticket is booked exactly as from the ticket - the - * agent, contact and watchers are emailed - and an event moved with notify + * agent, contact and CCs are emailed - and an event moved with notify * sends the update to the people who have it in their calendar. */ if (isset($_POST['calendar_move'])) { diff --git a/agent/js/tickets_add_modal.js b/agent/js/tickets_add_modal.js index 81d9ec4ab..d7464fe9f 100644 --- a/agent/js/tickets_add_modal.js +++ b/agent/js/tickets_add_modal.js @@ -266,10 +266,10 @@ } // Populate client contacts - one request feeds both the contact picker and the - // watchers list, as both are built from the same set of people + // CCs list, as both are built from the same set of people function populateContactsDropdown(client_id) { - if (!document.getElementById("contactSelect") && !document.getElementById("watchersSelect")) { + if (!document.getElementById("contactSelect") && !document.getElementById("ccsSelect")) { return; } @@ -290,8 +290,8 @@ // Contacts dropdown const contactSelectDropdown = resetDropdown("contactSelect", '- No One -', '0'); - // Watchers is a tags field - any address can be typed in, these are just the handy ones - const watchersDropdown = resetDropdown("watchersSelect", null, null); + // CCs is a tags field - any address can be typed in, these are just the handy ones + const ccsDropdown = resetDropdown("ccsSelect", null, null); // Populate dropdown - the name, with title and role on the line under it contacts.forEach(contact => { @@ -319,8 +319,8 @@ contactSelectDropdown[contactSelectDropdown.length] = option; } - if (watchersDropdown && contact.contact_email) { - watchersDropdown[watchersDropdown.length] = new Option(contact.contact_email, contact.contact_email); + if (ccsDropdown && contact.contact_email) { + ccsDropdown[ccsDropdown.length] = new Option(contact.contact_email, contact.contact_email); } }); diff --git a/agent/modals/ticket/ticket_add.php b/agent/modals/ticket/ticket_add.php index d60abb8f0..a8f8b92cc 100644 --- a/agent/modals/ticket/ticket_add.php +++ b/agent/modals/ticket/ticket_add.php @@ -423,7 +423,7 @@ ob_start();
-
diff --git a/agent/modals/ticket/ticket_add_watcher.php b/agent/modals/ticket/ticket_add_cc.php similarity index 92% rename from agent/modals/ticket/ticket_add_watcher.php rename to agent/modals/ticket/ticket_add_cc.php index be1eeb2cb..b8da5968c 100644 --- a/agent/modals/ticket/ticket_add_watcher.php +++ b/agent/modals/ticket/ticket_add_cc.php @@ -27,7 +27,7 @@ ob_start();
-
- -
@@ -60,7 +60,7 @@ ob_start();
diff --git a/agent/modals/ticket/ticket_resolve_no_response.php b/agent/modals/ticket/ticket_resolve_no_response.php index 3bcc8396f..838ca2212 100644 --- a/agent/modals/ticket/ticket_resolve_no_response.php +++ b/agent/modals/ticket/ticket_resolve_no_response.php @@ -4,7 +4,7 @@ * Resolve - no response: for a client who hasn't answered after several * tries. The message from Admin > Settings > Tickets, filled in for this * ticket, to change before it goes - it goes on the ticket as a public note - * and, with client emails on, to the contact and watchers in place of the + * and, with client emails on, to the contact and CCs in place of the * usual "resolved" words. Closing it later asks them nothing. * resolve_ticket_no_response (agent/post/ticket.php). ?ticket_id= */ @@ -17,14 +17,14 @@ $row = ticketForModal($_GET['ticket_id'] ?? 0, 2, true); $ticket_id = intval($row['ticket_id']); // Who it goes to - as the Resolve button's own email -$watcher_count = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM ticket_watchers WHERE watcher_ticket_id = $ticket_id"))[0] ?? 0); +$cc_count = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM ticket_ccs WHERE ticket_cc_ticket_id = $ticket_id"))[0] ?? 0); $contact_email = trim((string) ($row['contact_email'] ?? '')); $emailed_to = []; if ($contact_email !== '') { $emailed_to[] = trim((string) $row['contact_name']) !== '' ? (string) $row['contact_name'] : $contact_email; } -if ($watcher_count) { - $emailed_to[] = $watcher_count . ' CC' . ($watcher_count === 1 ? '' : 's'); +if ($cc_count) { + $emailed_to[] = $cc_count . ' CC' . ($cc_count === 1 ? '' : 's'); } if (!emailReady()) { $why_not = 'mail isn\'t set up'; diff --git a/agent/post/client.php b/agent/post/client.php index 16e0642c8..aa6763337 100644 --- a/agent/post/client.php +++ b/agent/post/client.php @@ -445,7 +445,7 @@ if (isset($_GET['delete_client'])) { mysqli_query($mysqli, "DELETE FROM software WHERE software_client_id = $client_id"); // Delete tickets and everything that is only theirs - attachments and the pictures in their text, files and all, - // tasks, watchers and history too (functions/ticket.php) + // tasks, CCs and history too (functions/ticket.php) $sql = mysqli_query($mysqli, "SELECT ticket_id FROM tickets WHERE ticket_client_id = $client_id"); while($row = mysqli_fetch_assoc($sql)) { ticketDeleteForGood(intval($row['ticket_id'])); diff --git a/agent/post/ticket.php b/agent/post/ticket.php index 8ef6152d8..63f1375e3 100644 --- a/agent/post/ticket.php +++ b/agent/post/ticket.php @@ -127,7 +127,7 @@ if (isset($_POST['add_ticket'])) { // Store any attached files against the ticket itself $emailable_attachments = filterEmailableAttachments(saveTicketAttachments($ticket_id, null)); - ticketAddWatchers($ticket_id, ticketWatcherEmails($_POST['watchers'] ?? [])); + ticketAddCcs($ticket_id, ticketCcEmails($_POST['ccs'] ?? [])); ticketSetOtherAssets($ticket_id, $other_asset_ids); tagSetForRecord('ticket', $ticket_id, (array) ($_POST['tags'] ?? [])); @@ -164,7 +164,7 @@ if (isset($_POST['add_ticket'])) { phonePopTicketMade($phone_pop_call, $ticket_id); } - // E-mail the client and the watchers - a quick ticket's contact only when its setting says so + // E-mail the client and the CCs - a quick ticket's contact only when its setting says so if (intval($config_ticket_client_general_notifications) === 1) { if (!$quick_ticket || quickTicketSettings()['email_client']) { ticketMailCreated($ticket_id, $emailable_attachments['send']); @@ -485,25 +485,25 @@ if (isset($_POST['edit_ticket_project'])) { } -if (isset($_POST['add_ticket_watcher'])) { +if (isset($_POST['add_ticket_cc'])) { validateCSRFToken(); $row = ticketForRequest($_POST['ticket_id'] ?? 0, 2); $ticket_id = intval($row['ticket_id']); - $notify = intval($_POST['watcher_notify'] ?? 0); + $notify = intval($_POST['cc_notify'] ?? 0); $reference = escapeSql(ticketReference($row)); - $added = ticketAddWatchers($ticket_id, ticketWatcherEmails($_POST['watcher_email'] ?? '')); + $added = ticketAddCcs($ticket_id, ticketCcEmails($_POST['cc_email'] ?? '')); - // Let each new watcher know, when asked + // Let each new CC know, when asked if ($added && $notify) { - ticketMailWatchersAdded($ticket_id, $added, stripslashes($session_name)); + ticketMailCcsAdded($ticket_id, $added, stripslashes($session_name)); } - foreach ($added as $watcher_email) { - logTicketHistory($ticket_id, "$session_name added " . escapeSql($watcher_email) . " as a CC"); - logAudit("Ticket", "Edit", "$session_name added " . escapeSql($watcher_email) . " as a CC on ticket $reference", $client_id, $ticket_id); + foreach ($added as $cc_email) { + logTicketHistory($ticket_id, "$session_name added " . escapeSql($cc_email) . " as a CC"); + logAudit("Ticket", "Edit", "$session_name added " . escapeSql($cc_email) . " as a CC on ticket $reference", $client_id, $ticket_id); } $count = count($added); @@ -513,27 +513,27 @@ if (isset($_POST['add_ticket_watcher'])) { } -if (isset($_GET['delete_ticket_watcher'])) { +if (isset($_GET['delete_ticket_cc'])) { validateCSRFToken(); - $watcher_id = intval($_GET['delete_ticket_watcher']); - $watcher = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT watcher_email, watcher_ticket_id FROM ticket_watchers WHERE watcher_id = $watcher_id")); - if (!$watcher) { + $cc_id = intval($_GET['delete_ticket_cc']); + $cc = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT ticket_cc_email, ticket_cc_ticket_id FROM ticket_ccs WHERE ticket_cc_id = $cc_id")); + if (!$cc) { flashAlert('That CC was already removed.', 'error'); redirect(); } - $row = ticketForRequest($watcher['watcher_ticket_id'], 2); + $row = ticketForRequest($cc['ticket_cc_ticket_id'], 2); $ticket_id = intval($row['ticket_id']); - $watcher_email = escapeSql($watcher['watcher_email']); + $cc_email = escapeSql($cc['ticket_cc_email']); - mysqli_query($mysqli, "DELETE FROM ticket_watchers WHERE watcher_id = $watcher_id"); + mysqli_query($mysqli, "DELETE FROM ticket_ccs WHERE ticket_cc_id = $cc_id"); - logTicketHistory($ticket_id, "$session_name removed $watcher_email as a CC"); + logTicketHistory($ticket_id, "$session_name removed $cc_email as a CC"); - logAudit("Ticket", "Edit", "$session_name removed $watcher_email as a CC on ticket " . escapeSql(ticketReference($row)), $client_id, $ticket_id); + logAudit("Ticket", "Edit", "$session_name removed $cc_email as a CC on ticket " . escapeSql(ticketReference($row)), $client_id, $ticket_id); - flashAlert("Removed CC " . escapeHtml($watcher['watcher_email']) . "", 'error'); + flashAlert("Removed CC " . escapeHtml($cc['ticket_cc_email']) . "", 'error'); redirect(); @@ -965,7 +965,7 @@ if (isset($_POST['bulk_ticket_reply'])) { triggerCustomAction('ticket_resolve', $ticket_id); } - // Email the client and watchers about a public update - the reply keeps who it went to + // Email the client and CCs about a public update - the reply keeps who it went to if (!$private_note) { ticketMailReply($ticket_id, $reply_text, stripslashes($session_name), false, $bulk_attachments['send'], $bulk_reply_id); } else { @@ -1217,7 +1217,7 @@ if (isset($_POST['add_ticket_reply'])) { } } - // Email the client and the watchers - the reply keeps who it went to, for the conversation + // Email the client and the CCs - the reply keeps who it went to, for the conversation $emailed_to = 0; $email_to = null; if ($send_email) { @@ -1701,12 +1701,12 @@ if (isset($_POST['change_client_ticket'])) { if ($client_id !== $old_client_id) { ticketNewGuestKeys($ticket_id); } - // Nobody at the old client hears about it any more: its watchers come off - all but our own + // Nobody at the old client hears about it any more: its CCs come off - all but our own // agents and the new client's contacts - and its email replies' To line starts again - mysqli_query($mysqli, "DELETE FROM ticket_watchers WHERE watcher_ticket_id = $ticket_id - AND watcher_email NOT IN (SELECT user_email FROM users WHERE user_type = 1 AND user_archived_at IS NULL AND user_email IS NOT NULL) - AND watcher_email NOT IN (SELECT contact_email FROM contacts WHERE contact_client_id = $client_id AND contact_archived_at IS NULL AND contact_email IS NOT NULL)"); - $watchers_off = max(0, mysqli_affected_rows($mysqli)); + mysqli_query($mysqli, "DELETE FROM ticket_ccs WHERE ticket_cc_ticket_id = $ticket_id + AND ticket_cc_email NOT IN (SELECT user_email FROM users WHERE user_type = 1 AND user_archived_at IS NULL AND user_email IS NOT NULL) + AND ticket_cc_email NOT IN (SELECT contact_email FROM contacts WHERE contact_client_id = $client_id AND contact_archived_at IS NULL AND contact_email IS NOT NULL)"); + $ccs_off = max(0, mysqli_affected_rows($mysqli)); ticketReplyRecipientsForget($ticket_id); // The driving for it goes with it - not to the old client's site mysqli_query($mysqli, "UPDATE trips SET trip_client_id = $client_id, trip_location_id = 0 WHERE trip_ticket_id = $ticket_id"); @@ -1716,14 +1716,14 @@ if (isset($_POST['change_client_ticket'])) { $new_client_name = (string) getFieldById('clients', $client_id, 'client_name'); logTicketHistory($ticket_id, "$session_name moved the ticket from " . escapeSql($old_client_name) . " to " . escapeSql($new_client_name) - . ($watchers_off ? " - $watchers_off CC" . ($watchers_off === 1 ? '' : 's') . " of the old client taken off" : '')); + . ($ccs_off ? " - $ccs_off CC" . ($ccs_off === 1 ? '' : 's') . " of the old client taken off" : '')); logAudit("Ticket", "Change", "$session_name moved ticket " . escapeSql(ticketReference($row)) . " from " . escapeSql($old_client_name) . " to " . escapeSql($new_client_name), $client_id, $ticket_id); triggerCustomAction('ticket_update', $ticket_id); flashAlert("Ticket " . escapeHtml(ticketReference($row)) . " moved to " . escapeHtml($new_client_name) . "" - . ($watchers_off ? " - $watchers_off CC" . ($watchers_off === 1 ? '' : 's') . " of the old client taken off" : '')); + . ($ccs_off ? " - $ccs_off CC" . ($ccs_off === 1 ? '' : 's') . " of the old client taken off" : '')); redirect(ticketUrl($ticket_id, $client_id)); diff --git a/agent/ticket.php b/agent/ticket.php index 57f5a6a2f..93adcf484 100644 --- a/agent/ticket.php +++ b/agent/ticket.php @@ -311,9 +311,9 @@ if (isset($_GET['ticket_id'])) { } } - // Get Watchers - $sql_ticket_watchers = mysqli_query($mysqli, "SELECT watcher_email, watcher_id FROM ticket_watchers WHERE watcher_ticket_id = $ticket_id ORDER BY watcher_email DESC"); - $watcher_count = mysqli_num_rows($sql_ticket_watchers); + // Get CCs + $sql_ticket_ccs = mysqli_query($mysqli, "SELECT ticket_cc_email, ticket_cc_id FROM ticket_ccs WHERE ticket_cc_ticket_id = $ticket_id ORDER BY ticket_cc_email DESC"); + $cc_count = mysqli_num_rows($sql_ticket_ccs); // Get Additional Assets $sql_additional_assets = mysqli_query($mysqli, "SELECT assets.asset_id, asset_name, asset_type FROM assets, ticket_assets @@ -362,7 +362,7 @@ if (isset($_GET['ticket_id'])) { /* * Ticket history. agent/post/ticket.php has been writing priority, SLA, - * contact, watcher and asset changes here all along - the page fetched + * contact, CC and asset changes here all along - the page fetched * the rows and then never rendered them. */ $sql_ticket_history = mysqli_query($mysqli, "SELECT ticket_history_description, ticket_history_created_at @@ -910,7 +910,7 @@ if (isset($_GET['ticket_id'])) {
@@ -924,7 +924,7 @@ if (isset($_GET['ticket_id'])) { @@ -1865,7 +1865,7 @@ if (isset($_GET['ticket_id'])) { $can_link = $can_edit_ticket && !$ticket_is_closed; // The services it is about - raised for them, or through its assets $ticket_services = $client_id ? ticketServices($ticket_id) : []; - $has_links = $asset_id || $vendor_id || $project_id || $watcher_count || $ticket_services; + $has_links = $asset_id || $vendor_id || $project_id || $cc_count || $ticket_services; if ($has_links || $can_link) { ?>
@@ -1890,7 +1890,7 @@ if (isset($_GET['ticket_id'])) { - + Add CC
@@ -2005,18 +2005,18 @@ if (isset($_GET['ticket_id'])) { - + -
- + - + diff --git a/api/v1/ticket_replies/create.php b/api/v1/ticket_replies/create.php index 9feaed183..7647cdcf2 100644 --- a/api/v1/ticket_replies/create.php +++ b/api/v1/ticket_replies/create.php @@ -13,7 +13,7 @@ * ticket_id required - Ticket to reply to * ticket_reply required - Reply body (HTML allowed, same as the UI) * ticket_reply_type optional - 'Internal' (default) or 'Public'. - * Public emails the contact and any watchers + * Public emails the contact and any CCs * and counts as the ticket's first response. * ticket_reply_time_worked optional - HH:MM:SS, default 00:00:00 * ticket_status optional - Also set the ticket status. Status 4 resolves @@ -144,7 +144,7 @@ if (!empty($ticket_id) && !empty($reply)) { triggerCustomAction('reply_reply_agent_public', $ticket_id); } - // Email the contact and watchers on a public reply, as the agent reply handler does - + // Email the contact and CCs on a public reply, as the agent reply handler does - // the reply keeps who it went to if ($reply_type == 'Public') { ticketMailReply($ticket_id, (string) getFieldById('ticket_replies', $insert_id, 'ticket_reply'), stripslashes($session_name), false, [], $insert_id); diff --git a/api/v1/tickets/create.php b/api/v1/tickets/create.php index 2dc95e05c..50156b465 100644 --- a/api/v1/tickets/create.php +++ b/api/v1/tickets/create.php @@ -6,7 +6,7 @@ * sent, its category, priority, billing and agent for those not sent, its * tags, due time and tasks, and its fill-ins answered from ticket_fill_ins * ({"Name": "answer"}). ticket_notify = 1 tells people as a ticket raised in - * ITFlow does - the contact and watchers (when ticket emails to clients are + * ITFlow does - the contact and CCs (when ticket emails to clients are * on), the new-ticket address and the agent it is assigned to; "agents" tells * only your team, the new-ticket address and the agent. ticket_status * starts it in an open status of your choosing - On Hold, say - and diff --git a/cron/ticket_email_parser.php b/cron/ticket_email_parser.php index a6a350872..96a71f043 100644 --- a/cron/ticket_email_parser.php +++ b/cron/ticket_email_parser.php @@ -58,6 +58,13 @@ if (devModeOn()) { cronJobStop("Development mode - the ticket mailbox isn't read"); } +// Not while a database update is waiting - newer files than database. An email this can't take is flagged and left in +// the mailbox for good, so it is left unread until the update has run (Maintenance > Update) +require_once "../includes/database_version.php"; +if (version_compare(LATEST_DATABASE_VERSION, CURRENT_DATABASE_VERSION, '>')) { + cronJobStop("Waiting for the database update to " . LATEST_DATABASE_VERSION . " - the ticket mailbox is read once it has run"); +} + // Overlapping runs are prevented by cron/includes/cron_lock.php. This script used to keep a // lock file of its own alongside that one, which needed a five minute age heuristic to // recover from a killed run and could only end itself with exit() - fatal to a dispatched @@ -76,8 +83,8 @@ $read_mail_minutes = 60; // Mail someone opened before this got to it * Ticket / Reply helpers (unchanged) * ------------------------------------------------------------------ */ /* - * A new ticket from an email. $copied - the people it was also to or copied to, made its watchers - * (ticketMailCopiedWatchers()); $message_id its Message-ID, kept with the ticket so a reply to it - + * A new ticket from an email. $copied - the people it was also to or copied to, made its CCs + * (ticketMailCopiedCcs()); $message_id its Message-ID, kept with the ticket so a reply to it - * or to all on it, before the ticket's number was ever sent - finds it (functions/ticket_mail_thread.php); * $automatic 'automated' for one sent by a system or a list, which isn't answered (functions/ticket_mail_auto.php). * The new ticket's id. @@ -163,13 +170,13 @@ function addTicket($contact_id, $contact_name, $contact_email, $client_id, $date } } - // Add unknown guests as ticket watcher + // The person whose email raised a ticket with no client is its CC, so its emails reach them if ($client_id == 0 && !preg_match($bad_pattern, $contact_email_esc)) { - mysqli_query($mysqli, "INSERT INTO ticket_watchers SET watcher_email = '$contact_email_esc', watcher_ticket_id = $id"); + mysqli_query($mysqli, "INSERT INTO ticket_ccs SET ticket_cc_email = '$contact_email_esc', ticket_cc_ticket_id = $id"); } - // The people it was also to or copied to are its watchers - not your own addresses or agents (ticketMailCopiedWatchers()) - ticketMailCopiedWatchers($id, $copied, stripslashes($contact_email)); + // The people it was also to or copied to are its CCs - not your own addresses or agents (ticketMailCopiedCcs()) + ticketMailCopiedCcs($id, $copied, stripslashes($contact_email)); // The sender is told it is a ticket now - unless they asked for replies only (Your account in the client portal), it was // sent by a system or a list, whose answer could be answered back, or they have had a few answers this hour already @@ -241,7 +248,7 @@ function addBounce($message, array $headers, $from_email, $subject) { /* * A new ticket whose subject is almost that of $similar_id - an open ticket of the client's from the last week - raised by - * someone who isn't its contact or watching it: kept as a ticket of its own, linked to that one as related + * someone who isn't its contact or a CC on it: kept as a ticket of its own, linked to that one as related * (functions/ticket_link.php), so an agent sees both and can merge them. */ function linkSimilarTicket($new_id, $similar_id) { @@ -259,14 +266,14 @@ function linkSimilarTicket($new_id, $similar_id) { * An email on ticket $ticket_id. $email, about the email: * message_id its Message-ID, kept with the ticket (functions/ticket_mail_thread.php) * from_name the name in its From line - * copied the people it was also to or copied to, made watchers when it is from the client or a watcher + * copied the people it was also to or copied to, made CCs when it is from the client or a CC * had everyone it was from, to and copied to - a client's reply goes on to the rest (ticketMailRelayClientReply()) * threaded it answers one of the ticket's emails (its In-Reply-To or References) - only then is a client's * reply passed on, as anyone can put a ticket number in a subject * automatic auto-reply (an out-of-office) or automated (a system, a list) - never answered or passed on * (functions/ticket_mail_auto.php) * - * Who it is from decides what it is: the ticket's contact, another of the client's contacts, or one of its watchers + * Who it is from decides what it is: the ticket's contact, another of the client's contacts, or one of its CCs * (the person whose email raised a ticket with no client is one) - a client reply, which reopens the ticket; one * of your agents - their own internal note; anyone else - an internal note with a warning, which reopens nothing * and takes no attachments. An automatic reply is a note that reopens nothing, and an email to a closed ticket is @@ -313,7 +320,7 @@ function addReply($from_email, $date, $subject, $ticket_id, $message, $attachmen $client_id = intval($row['ticket_client_id']); $client_uri = $client_id ? "&client_id=$client_id" : ''; - // Who wrote it - contact (the ticket's, or another of the client's), watcher, agent or stranger + // Who wrote it - contact (the ticket's, or another of the client's), CC, agent or stranger $who = 'stranger'; $reply_by = 0; if (trim((string) $row['contact_email']) !== '' && strcasecmp(trim((string) $row['contact_email']), stripslashes($from_email)) === 0) { @@ -325,16 +332,16 @@ function addReply($from_email, $date, $subject, $ticket_id, $message, $attachmen } elseif ($agent_row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT user_id FROM users WHERE user_email = '$from_email_esc' AND user_type = 1 AND user_status = 1 AND user_archived_at IS NULL LIMIT 1"))) { $who = 'agent'; $reply_by = intval($agent_row[0]); // an internal note is by an agent, as on the ticket page - } elseif (mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM ticket_watchers WHERE watcher_ticket_id = $ticket_id AND watcher_email = '$from_email_esc' LIMIT 1"))) { - $who = 'watcher'; + } elseif (mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM ticket_ccs WHERE ticket_cc_ticket_id = $ticket_id AND ticket_cc_email = '$from_email_esc' LIMIT 1"))) { + $who = 'cc'; } $stranger = $who === 'stranger'; $closed = $ticket_status === TICKET_STATUS_CLOSED; $by_name = $who === 'contact' ? (string) getFieldById('contacts', $reply_by, 'contact_name') : ($from_name !== '' ? $from_name : stripslashes($from_email)); - // What it is on the ticket: a client reply from the client or a watcher; a note from an agent, a stranger, an automatic + // What it is on the ticket: a client reply from the client or a CC; a note from an agent, a stranger, an automatic // reply, or anything on a closed ticket - $type = in_array($who, ['contact', 'watcher'], true) && $automatic !== 'auto-reply' && !$closed ? 'Client' : 'Internal'; + $type = in_array($who, ['contact', 'cc'], true) && $automatic !== 'auto-reply' && !$closed ? 'Client' : 'Internal'; $notes = []; if ($automatic === 'auto-reply') { $notes[] = 'An automatic reply - the ticket was not reopened'; @@ -355,7 +362,7 @@ function addReply($from_email, $date, $subject, $ticket_id, $message, $attachmen // Who a client reply from someone who isn't a contact came from - there is no contact to name (4.2.7) $from_sql = ''; - if ($type === 'Client' && $who === 'watcher' && ticketReplyFromReady()) { + if ($type === 'Client' && $who === 'cc' && ticketReplyFromReady()) { $from_sql = ", ticket_reply_from_name = " . ($from_name !== '' ? "'" . mysqli_real_escape_string($mysqli, mb_substr($from_name, 0, 200)) . "'" : 'NULL') . ", ticket_reply_from_email = '" . mysqli_real_escape_string($mysqli, mb_substr(stripslashes($from_email), 0, 255)) . "'"; } @@ -405,13 +412,13 @@ function addReply($from_email, $date, $subject, $ticket_id, $message, $attachmen return true; } - // A closed ticket isn't reopened. Agents are told it is on it, and the client or watcher that nobody will act on it - + // A closed ticket isn't reopened. Agents are told it is on it, and the client or CC that nobody will act on it - // not a stranger (a guessed number would tell them the ticket's subject), an agent, or anything automatic, whose // answer would only be answered, and not more than a few times an hour (functions/ticket_mail_auto.php) if ($closed) { appNotify("Ticket", "Email parser: $from_email replied to closed ticket $ticket_reference_esc - it is on the ticket as a note, and the ticket was not reopened", "/agent/ticket.php?ticket_id=$ticket_id$client_uri", $client_id, $ticket_id); logTicketHistory($ticket_id, "$from_email_esc replied after it was closed - kept as a note"); - if (in_array($who, ['contact', 'watcher'], true) && $automatic === '' && ticketMailAnswersLeft(stripslashes($from_email))) { + if (in_array($who, ['contact', 'cc'], true) && $automatic === '' && ticketMailAnswersLeft(stripslashes($from_email))) { ticketMailClosedReply($ticket_id, stripslashes($from_email), (string) ($email['message_id'] ?? '')); } return true; @@ -423,10 +430,10 @@ function addReply($from_email, $date, $subject, $ticket_id, $message, $attachmen return true; } - // The people the client or a watcher also wrote to, or copied in, follow the ticket from now on - as + // The people the client or a CC also wrote to, or copied in, follow the ticket from now on - as // they would have in a conversation by email. Not a stranger's: anyone can put a number in a subject - if (!$stranger && ($watching = ticketMailCopiedWatchers($ticket_id, (array) ($email['copied'] ?? []), stripslashes($from_email)))) { - logTicketHistory($ticket_id, escapeSql(implode(', ', $watching)) . " added as " . (count($watching) === 1 ? 'a CC' : 'CCs') . " - copied in on an email from $from_email_esc"); + if (!$stranger && ($added_ccs = ticketMailCopiedCcs($ticket_id, (array) ($email['copied'] ?? []), stripslashes($from_email)))) { + logTicketHistory($ticket_id, escapeSql(implode(', ', $added_ccs)) . " added as " . (count($added_ccs) === 1 ? 'a CC' : 'CCs') . " - copied in on an email from $from_email_esc"); } // The agent it is assigned to, with what they wrote - a stranger's as plain text @@ -464,7 +471,7 @@ function addReply($from_email, $date, $subject, $ticket_id, $message, $attachmen logTicketHistory($ticket_id, "$from_email_esc replied by email, reopening the ticket"); } - logAudit("Ticket", "Edit", "Email parser: " . ($who === 'watcher' ? 'CC' : 'Client contact') . " $from_email_esc updated ticket $ticket_reference_esc ($subject)", $client_id, $ticket_id); + logAudit("Ticket", "Edit", "Email parser: " . ($who === 'cc' ? 'CC' : 'Client contact') . " $from_email_esc updated ticket $ticket_reference_esc ($subject)", $client_id, $ticket_id); triggerCustomAction('ticket_reply_client', $ticket_id); return true; } @@ -815,7 +822,7 @@ foreach ($messages as $message) { // ticket_subject holds 500 characters - a longer one failed the insert and the email was tried again every run $subject = escapeSql(mb_substr((string)$message->subject() ?: 'No Subject', 0, 500)); - // ITFlow's own email come back - a copy to a watcher that is this mailbox, a notice sent to it. Taken, it would + // ITFlow's own email come back - a copy to a CC that is this mailbox, a notice sent to it. Taken, it would // go on the ticket as a note and reopen it, or raise a ticket that sends another, round and round if (in_array(strtolower(stripslashes($from_email)), $own_addresses, true)) { logApp("Cron-Email-Parser", "info", "Email parser skipped an email from ITFlow's own address $from_email ($subject) - mail it sent came back to this mailbox"); @@ -857,7 +864,7 @@ foreach ($messages as $message) { file_put_contents("../uploads/tmp/{$original_message_file}", $raw_message); // Who else it was to or copied to (deduplicated, excluding the sender) - and not ITFlow's own addresses: this - // mailbox CC'd beside a tech made a watcher would get every email about the ticket, each come back as a note + // mailbox CC'd beside a tech, added as one of the ticket's CCs, would get every email about it, each come back as a note $copied = array(); $had = [strtolower(stripslashes($from_email))]; foreach (array_merge($message->to(), $message->cc()) as $copied_addr) { @@ -942,7 +949,7 @@ foreach ($messages as $message) { } // 3. Almost the same subject as an open ticket of the sender's client from the last week - a reply on it when they are - // its contact or watching it. From anyone else at the client it is a ticket of its own, linked to that one as related + // its contact or a CC on it. From anyone else at the client it is a ticket of its own, linked to that one as related // (linkSimilarTicket()): two people with "Printer not working" in a week used to land on one ticket $similar_ticket_id = 0; if (!$email_processed && strlen(trim($subject)) > 10) { @@ -986,7 +993,7 @@ foreach ($messages as $message) { if ($percent >= 95) { $similar_id = intval($rowt['ticket_id']); $theirs = ($contact_id && $contact_id === intval($rowt['ticket_contact_id'])) - || mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM ticket_watchers WHERE watcher_ticket_id = $similar_id AND watcher_email = '$from_email_esc' LIMIT 1")); + || mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM ticket_ccs WHERE ticket_cc_ticket_id = $similar_id AND ticket_cc_email = '$from_email_esc' LIMIT 1")); if ($theirs) { $email_processed = addReply($from_email, $date, $subject, $similar_id, $message_body, $attachments, $original_message_file, $email); } else { diff --git a/db.sql b/db.sql index 6e3fca767..ebcefa453 100644 --- a/db.sql +++ b/db.sql @@ -4805,6 +4805,23 @@ CREATE TABLE `ticket_attachments` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `ticket_ccs` +-- + +DROP TABLE IF EXISTS `ticket_ccs`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8mb4 */; +CREATE TABLE `ticket_ccs` ( + `ticket_cc_id` int(11) NOT NULL AUTO_INCREMENT, + `ticket_cc_name` varchar(255) DEFAULT NULL, + `ticket_cc_email` varchar(255) NOT NULL, + `ticket_cc_ticket_id` int(11) NOT NULL, + PRIMARY KEY (`ticket_cc_id`), + KEY `ticket_cc_ticket_id` (`ticket_cc_ticket_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `ticket_fill_ins` -- @@ -5147,23 +5164,6 @@ CREATE TABLE `ticket_views` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `ticket_watchers` --- - -DROP TABLE IF EXISTS `ticket_watchers`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8mb4 */; -CREATE TABLE `ticket_watchers` ( - `watcher_id` int(11) NOT NULL AUTO_INCREMENT, - `watcher_name` varchar(255) DEFAULT NULL, - `watcher_email` varchar(255) NOT NULL, - `watcher_ticket_id` int(11) NOT NULL, - PRIMARY KEY (`watcher_id`), - KEY `watcher_ticket_id` (`watcher_ticket_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `tickets` -- diff --git a/functions/dispatch.php b/functions/dispatch.php index 9028dfee1..5d8bdfe56 100644 --- a/functions/dispatch.php +++ b/functions/dispatch.php @@ -249,7 +249,7 @@ function dispatchItems($from, $to, array $agent_ids) { /* * Give a ticket to an agent (when it's someone new) and book it for $start (on * the company's clock) for $minutes, onsite or remote. $tell_client false keeps - * the contact and watchers out of it - the agent is always told. + * the contact and CCs out of it - the agent is always told. * [ok, message, conflicts]. */ function dispatchBook($ticket_id, $agent_id, $start, $minutes, $onsite, $tell_client = true) { diff --git a/functions/email.php b/functions/email.php index bdf5404ba..29723f06e 100644 --- a/functions/email.php +++ b/functions/email.php @@ -277,7 +277,7 @@ function emailMailboxes() { /** * ITFlow's own addresses, lower case - the mailboxes it sends from (emailMailboxes()) and the one * it reads (Admin > Mail > Receiving). Mail from one of them is ITFlow's own come back - a copy to a - * watcher that is the ticket mailbox, say - so the ticket mailbox reader skips it, and nothing about + * CC that is the ticket mailbox, say - so the ticket mailbox reader skips it, and nothing about * a ticket is sent to one (emailOwnAddress()). */ function emailOwnAddresses() { diff --git a/functions/email_preview.php b/functions/email_preview.php index 4dadc25b1..ab7f304ff 100644 --- a/functions/email_preview.php +++ b/functions/email_preview.php @@ -84,7 +84,7 @@ function emailPreviewSample() { $insert("INSERT INTO ticket_replies SET ticket_reply = '" . $e($reply) . "', ticket_reply_type = 'Public', ticket_reply_time_worked = '00:10:00', ticket_reply_by = $me, ticket_reply_ticket_id = $ticket"); $client_reply = '

The test page came out fine - thank you!

'; $insert("INSERT INTO ticket_replies SET ticket_reply = '" . $e($client_reply) . "', ticket_reply_type = 'Client', ticket_reply_time_worked = '00:00:00', ticket_reply_by = $alex, ticket_reply_ticket_id = $ticket"); - $insert("INSERT INTO ticket_watchers SET watcher_email = '" . $e($jamie_email) . "', watcher_ticket_id = $ticket"); + $insert("INSERT INTO ticket_ccs SET ticket_cc_email = '" . $e($jamie_email) . "', ticket_cc_ticket_id = $ticket"); $recurring = $insert("INSERT INTO recurring_tickets SET recurring_ticket_subject = 'Monthly backup check', recurring_ticket_details = '

Check last month''s backups ran, and test a restore.

', recurring_ticket_priority = 'Low', recurring_ticket_frequency = 'Monthly', recurring_ticket_billable = 0, recurring_ticket_start_date = CURDATE(), recurring_ticket_next_run = CURDATE(), recurring_ticket_created_by = $me, recurring_ticket_assigned_to = $agent, recurring_ticket_client_id = $client_id, recurring_ticket_contact_id = $alex"); @@ -201,9 +201,9 @@ function emailPreviewCatalog() { AND ticket_reply_type = 'Client' ORDER BY ticket_reply_id DESC LIMIT 1"))[0] ?? 0); ticketMailRelayClientReply($s['ticket'], $reply_id, $s['alex_name'], $s['alex_email']); }], - 'ticket_watcher' => ['group' => 'Tickets - to clients', 'label' => 'Added as a CC', 'to' => 'The new CC', 'when' => 'An agent adds a CC and asks to tell them', + 'ticket_cc' => ['group' => 'Tickets - to clients', 'label' => 'Added as a CC', 'to' => 'The new CC', 'when' => 'An agent adds a CC and asks to tell them', 'run' => function ($s) { - ticketMailWatchersAdded($s['ticket'], [$s['jamie_email']], $s['by']); + ticketMailCcsAdded($s['ticket'], [$s['jamie_email']], $s['by']); }], 'ticket_colleague_new' => ['group' => 'Tickets - to clients', 'label' => 'New ticket at their company', 'to' => 'Primary and technical contacts who asked', 'when' => 'Anyone raises a ticket for their company', 'run' => function ($s) { diff --git a/functions/ticket.php b/functions/ticket.php index 0b6810957..8237ceec1 100644 --- a/functions/ticket.php +++ b/functions/ticket.php @@ -234,8 +234,8 @@ function ticketDueSql($input) { return 'NULL'; } -/** The watchers posted - valid email addresses only, each once, lower-cased. */ -function ticketWatcherEmails($input) { +/** The CCs posted - valid email addresses only, each once, lower-cased. */ +function ticketCcEmails($input) { $list = is_array($input) ? $input : preg_split('/[\s,;]+/', (string) $input); $emails = []; foreach ($list as $email) { @@ -247,8 +247,8 @@ function ticketWatcherEmails($input) { return array_keys($emails); } -/** Add watchers a ticket doesn't have already - the ones added. Never one of ITFlow's own addresses (emailOwnAddresses()). */ -function ticketAddWatchers($ticket_id, array $emails) { +/** Add CCs a ticket doesn't have already - the ones added. Never one of ITFlow's own addresses (emailOwnAddresses()). */ +function ticketAddCcs($ticket_id, array $emails) { global $mysqli; $ticket_id = intval($ticket_id); $added = []; @@ -257,17 +257,17 @@ function ticketAddWatchers($ticket_id, array $emails) { continue; } $email_sql = escapeSql($email); - if (mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM ticket_watchers WHERE watcher_ticket_id = $ticket_id AND watcher_email = '$email_sql' LIMIT 1"))) { + if (mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM ticket_ccs WHERE ticket_cc_ticket_id = $ticket_id AND ticket_cc_email = '$email_sql' LIMIT 1"))) { continue; } - mysqli_query($mysqli, "INSERT INTO ticket_watchers SET watcher_email = '$email_sql', watcher_ticket_id = $ticket_id"); + mysqli_query($mysqli, "INSERT INTO ticket_ccs SET ticket_cc_email = '$email_sql', ticket_cc_ticket_id = $ticket_id"); $added[] = $email; } return $added; } /** - * Delete a ticket and everything that is only its: replies, views, watchers, + * Delete a ticket and everything that is only its: replies, views, CCs, * attachments (and their files), tasks and their approvals, history and SLA * history. Its other-asset links go with it (ON DELETE CASCADE). */ @@ -281,7 +281,7 @@ function ticketDeleteForGood($ticket_id) { mysqli_query($mysqli, "DELETE FROM tasks WHERE task_ticket_id = $ticket_id"); mysqli_query($mysqli, "DELETE FROM ticket_replies WHERE ticket_reply_ticket_id = $ticket_id"); mysqli_query($mysqli, "DELETE FROM ticket_views WHERE view_ticket_id = $ticket_id"); - mysqli_query($mysqli, "DELETE FROM ticket_watchers WHERE watcher_ticket_id = $ticket_id"); + mysqli_query($mysqli, "DELETE FROM ticket_ccs WHERE ticket_cc_ticket_id = $ticket_id"); mysqli_query($mysqli, "DELETE FROM ticket_attachments WHERE ticket_attachment_ticket_id = $ticket_id"); mysqli_query($mysqli, "DELETE FROM ticket_history WHERE ticket_history_ticket_id = $ticket_id"); mysqli_query($mysqli, "DELETE FROM sla_history WHERE sla_history_ticket_id = $ticket_id"); @@ -302,7 +302,7 @@ function ticketEmailFrom() { return emailFrom('ticket'); } -/** Where a contact or watcher opens a ticket - its guest link, no sign-in needed, or the portal when it has none. */ +/** Where a contact or CC opens a ticket - its guest link, no sign-in needed, or the portal when it has none. */ function ticketEmailUrl(array $row) { global $config_base_url; $ticket_id = intval($row['ticket_id']); @@ -545,7 +545,7 @@ function ticketEmailExcerpt($html, $limit = 700) { * resolved marked resolved, pending closure - message (the agent's note, HTML, or ''), by, * no_response (true: the message is the email - Resolve - no response) * closed closed - asking how we did - * watcher they were made a watcher - by (who added them) + * cc they were added as a CC - by (who added them) * assigned an agent picked it up - message (the "ticket assigned" words, HTML), agent (who has it, or '') * scheduled the work was booked - when (words), where (the site's address), or cancelled: true */ @@ -646,7 +646,7 @@ function ticketEmailContent(array $row, $kind, array $opts = []) { $email['content'] = (string) ($opts['message'] ?? ''); $email['summary'] = $summary + ($agent !== '' ? ['Assigned to' => $agent] : []); $email['history'] = ticketEmailHistory($row, ['limit' => 2, 'label' => 'What it is about', 'skip' => $email['content']]); - } elseif ($kind === 'watcher') { + } elseif ($kind === 'cc') { $email['kind'] = 'Copied in'; $email['title'] = 'You were added to a ticket'; $email['intro'] = ["$by added you to ticket $reference" . (!empty($row['client_name']) ? ' for ' . $row['client_name'] : '') . ", so you will get its updates. To add anything, just reply to this email."]; @@ -675,7 +675,7 @@ function ticketEmailPreview(array $email) { /* * Queue an email about a ticket (ticketEmailContent()) to its contact, when - * $to_contact and the address is good, and to every watcher, each told why + * $to_contact and the address is good, and to every CC, each told why * they get it. Nothing is queued without a mail provider. Its subject is the * ticket's (ticketEmailSubject()), and it goes in the ticket's conversation * (functions/ticket_mail_thread.php). One email, the contact's, with everyone @@ -683,7 +683,7 @@ function ticketEmailPreview(array $email) { * How many it went to. $opts: * attachments files to send with it ([['path', 'name'], ...]) * to_contact false leaves the contact out - * to_watchers false is the contact alone - no watchers, no colleagues + * to_ccs false is the contact alone - no CCs, no colleagues * to [['email', 'name'], ...] in place of the contact - the sender of an emailed ticket * recipients emailQueue()'s list in place of everyone - the To line's people * (ticketReplyRecipientsPick()), each with its group @@ -691,7 +691,7 @@ function ticketEmailPreview(array $email) { * for replies only gets no created or closed email * (ticketContactWantsEmail()), and the client's primary and * technical contacts who asked for every update on their - * company's tickets get the rest, as a watcher does + * company's tickets get the rest, as a CC does * (ticketColleagueRecipients()) * ticket_reply_id the agent's reply it carries - each email is kept with it * (emailQueue()), for ticketReplyEmailed() @@ -705,7 +705,7 @@ function ticketMailSend($ticket_id, array $email, array $opts = []) { } $ticket_id = intval($ticket_id); $kind = (string) ($opts['kind'] ?? 'update'); - $to_watchers = $opts['to_watchers'] ?? true; + $to_ccs = $opts['to_ccs'] ?? true; $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT ticket_prefix, ticket_number, ticket_subject, contact_name, contact_email, contact_ticket_emails FROM tickets LEFT JOIN contacts ON contact_id = ticket_contact_id WHERE ticket_id = $ticket_id")); if (!$row) { @@ -716,7 +716,7 @@ function ticketMailSend($ticket_id, array $email, array $opts = []) { $recipients = []; if (isset($opts['recipients'])) { $recipients = (array) $opts['recipients']; - $to_watchers = false; + $to_ccs = false; } elseif (isset($opts['to'])) { foreach ((array) $opts['to'] as $to) { $recipients[] = ['email' => $to['email'], 'name' => (string) ($to['name'] ?? ''), 'group' => 'contact', 'footnote' => "You get this because you emailed $company_name."]; @@ -724,10 +724,10 @@ function ticketMailSend($ticket_id, array $email, array $opts = []) { } elseif (($opts['to_contact'] ?? true) && ticketContactWantsEmail($row['contact_ticket_emails'] ?? 'all', $kind)) { $recipients[] = ['email' => (string) $row['contact_email'], 'name' => (string) $row['contact_name'], 'group' => 'contact', 'footnote' => "You get this as the contact on ticket $reference with $company_name."]; } - if ($to_watchers) { - $sql = mysqli_query($mysqli, "SELECT watcher_email FROM ticket_watchers WHERE watcher_ticket_id = $ticket_id"); - while ($watcher = mysqli_fetch_assoc($sql)) { - $recipients[] = ['email' => trim((string) $watcher['watcher_email']), 'greet' => '', 'group' => 'watcher', 'footnote' => "You get this because you are copied in on ticket $reference - ask $company_name if you would like to stop."]; + if ($to_ccs) { + $sql = mysqli_query($mysqli, "SELECT ticket_cc_email FROM ticket_ccs WHERE ticket_cc_ticket_id = $ticket_id"); + while ($cc = mysqli_fetch_assoc($sql)) { + $recipients[] = ['email' => trim((string) $cc['ticket_cc_email']), 'greet' => '', 'group' => 'cc', 'footnote' => "You get this because you are copied in on ticket $reference - ask $company_name if you would like to stop."]; } // A new ticket reaches them by ticketMailColleaguesNew(), in an email of its own if ($kind !== 'created') { @@ -736,7 +736,7 @@ function ticketMailSend($ticket_id, array $email, array $opts = []) { } } } - // Never to one of ITFlow's own addresses - a watcher that is the ticket mailbox would read it back in (emailOwnAddresses()) - and + // Never to one of ITFlow's own addresses - a CC that is the ticket mailbox would read it back in (emailOwnAddresses()) - and // only to an address $recipients = array_values(array_filter($recipients, function ($recipient) { return filter_var(trim((string) ($recipient['email'] ?? '')), FILTER_VALIDATE_EMAIL) && !emailOwnAddress($recipient['email']); @@ -832,22 +832,22 @@ function ticketMailColleaguesNew($ticket_id) { } /* - * The "a ticket was created for you" email - to its contact, and its watchers - * unless $to_watchers is false; or to $to (ticketMailSend()'s) in their + * The "a ticket was created for you" email - to its contact, and its CCs + * unless $to_ccs is false; or to $to (ticketMailSend()'s) in their * place. $how agent, email or scheduled (ticketEmailContent()). */ -function ticketMailCreated($ticket_id, $attachments = [], $to_watchers = true, $how = 'agent', ?array $to = null) { +function ticketMailCreated($ticket_id, $attachments = [], $to_ccs = true, $how = 'agent', ?array $to = null) { $row = ticketRow($ticket_id); if (!$row) { return 0; } // Emailed in, it is an automatic answer to that email - which says so, so the other side doesn't answer it (functions/ticket_mail_auto.php) return ticketMailSend($row['ticket_id'], ticketEmailContent($row, 'created', ['how' => $how]), - ['attachments' => $attachments, 'to_watchers' => $to_watchers, 'kind' => 'created'] + ($to !== null ? ['to' => $to] : []) + ($how === 'email' ? ['auto' => 'replied'] : [])); + ['attachments' => $attachments, 'to_ccs' => $to_ccs, 'kind' => 'created'] + ($to !== null ? ['to' => $to] : []) + ($how === 'email' ? ['auto' => 'replied'] : [])); } /* - * A public reply on a ticket, to its contact and watchers - or the people in + * A public reply on a ticket, to its contact and CCs - or the people in * its To line, $to (ticketReplyRecipientsPick()) - $reply_html as saved (with * the signature), $by who wrote it (raw). $resolved when the reply resolved * it. $reply_id, the reply in ticket_replies, has who it went to kept with it @@ -883,7 +883,7 @@ function ticketReplyFromReady() { /* * Who wrote a reply, for a SELECT joined to contacts on its ticket_reply_by - as contact_name: the - * contact, or for a client reply from someone who isn't one - a watcher, the person whose email + * contact, or for a client reply from someone who isn't one - a CC, the person whose email * raised a ticket with no client - the name and then the address it came from (4.2.7). */ function ticketReplyAuthorSql() { @@ -999,16 +999,16 @@ function ticketReplyEmailStates(array $rows) { return $states; } -/** Tell people just made watchers of a ticket - $emails, by $by (raw), each an email of their own in its conversation. How many it went to. */ -function ticketMailWatchersAdded($ticket_id, array $emails, $by) { +/** Tell people just added as a ticket's CCs - $emails, by $by (raw), each an email of their own in its conversation. How many it went to. */ +function ticketMailCcsAdded($ticket_id, array $emails, $by) { $row = ticketRow($ticket_id); if (!$row || !$emails) { return 0; } $company_name = (string) (billingCompany()['company_name'] ?? 'us'); - return count(emailQueue(array_map(function ($watcher_email) use ($row, $company_name) { - return ['email' => $watcher_email, 'greet' => '', 'footnote' => "You get this because you are copied in on ticket " . ticketReference($row) . " - ask $company_name if you would like to stop."]; - }, $emails), ticketEmailSubject($row), ticketEmailContent($row, 'watcher', ['by' => (string) $by]), ['from' => ticketEmailFrom(), 'thread' => intval($row['ticket_id'])])); + return count(emailQueue(array_map(function ($cc_email) use ($row, $company_name) { + return ['email' => $cc_email, 'greet' => '', 'footnote' => "You get this because you are copied in on ticket " . ticketReference($row) . " - ask $company_name if you would like to stop."]; + }, $emails), ticketEmailSubject($row), ticketEmailContent($row, 'cc', ['by' => (string) $by]), ['from' => ticketEmailFrom(), 'thread' => intval($row['ticket_id'])])); } /* ------------------------------------------------------------ Emails about a ticket, to agents */ @@ -1637,7 +1637,7 @@ function ticketIsNoResponse(array $row) { * Resolve $row (ticketForRequest()) as "no response": $message - plain text, * as the agent left it - as a public note, the ticket resolved * (ticketResolve()), and when client notifications are on the resolved - * email to the contact and watchers saying it in place of its usual words. + * email to the contact and CCs saying it in place of its usual words. * The caller has checked it may be resolved. How many were emailed. */ function ticketResolveNoResponse(array $row, $message) { @@ -1677,7 +1677,7 @@ function ticketReopen($row, $status_id = TICKET_STATUS_OPEN, $how = '') { triggerCustomAction('ticket_update', $ticket_id); } -/** The "your ticket is closed" email - to its contact and watchers, asking how we did. Not for one resolved as "no response". */ +/** The "your ticket is closed" email - to its contact and CCs, asking how we did. Not for one resolved as "no response". */ function ticketMailClosed($ticket_id) { $row = ticketRow($ticket_id); if (!$row || ticketIsNoResponse($row)) { @@ -1750,7 +1750,7 @@ function ticketReplyEmailHtml($reply_id, array $state, $queue_url = '') { /* * The "your ticket is resolved, pending closure" email - to its contact and - * watchers. $note is the agent's words as HTML, raw, or ''; $reply_id the + * CCs. $note is the agent's words as HTML, raw, or ''; $reply_id the * reply they were saved as, which keeps who it went to (ticketReplyEmailed()). */ function ticketMailResolved($ticket_id, $note = '', $reply_id = 0) { @@ -2202,7 +2202,7 @@ function recurringTicketRaise($recurring_ticket_id, $by = 'Cron') { // The client is told (when general notifications are on) - the contact alone $new = ticketRow($ticket_id); if (intval($config_ticket_client_general_notifications) === 1 && $new) { - ticketMailSend($ticket_id, ticketEmailContent($new, 'created', ['how' => 'scheduled']), ['kind' => 'created', 'to_watchers' => false]); + ticketMailSend($ticket_id, ticketEmailContent($new, 'created', ['how' => 'scheduled']), ['kind' => 'created', 'to_ccs' => false]); } // The new-ticket address (Admin > Ticket), when there is one @@ -2443,10 +2443,10 @@ function ticketScheduleValue($input) { /* * The scheduled-work emails, each with the calendar file - the invite, or its * cancellation: to the agent doing the work, and when client notifications - * are on (Admin > Ticket) to the contact and the watchers. $row has the + * are on (Admin > Ticket) to the contact and the CCs. $row has the * ticket's id and, for a booking, location_address. With the booking's $start * and $end, the agent's email has the time on their own clock. $tell_client - * false leaves the contact and watchers out of it (Dispatch). + * false leaves the contact and CCs out of it (Dispatch). */ function ticketMailSchedule($row, $cal_str, $cancelled, $when_text, $start = null, $end = null, $tell_client = true) { global $config_ticket_client_general_notifications; @@ -2651,10 +2651,10 @@ function ticketScheduleIcs(array $row, $schedule, $end = null) { /** * Book the work on a ticket for $schedule ('Y-m-d H:i:s') to $end (the usual - * length when none), onsite or remote: the agent, the contact and the watchers + * length when none), onsite or remote: the agent, the contact and the CCs * are emailed with the calendar file, and it is noted on the ticket. Helpers * who follow the lead are sent the new time. $tell_client false leaves the - * contact and watchers out of it. Returns ['when_text' => ..., 'conflicts' => + * contact and CCs out of it. Returns ['when_text' => ..., 'conflicts' => * the same agent's - and those helpers' - other work at that time, as plain * text (ticketScheduleConflicts())]. */ diff --git a/functions/ticket_mail_thread.php b/functions/ticket_mail_thread.php index 5f650cd4d..79f2b5340 100644 --- a/functions/ticket_mail_thread.php +++ b/functions/ticket_mail_thread.php @@ -45,8 +45,8 @@ function ticketEmailSubject(array $row) { } /* - * The ticket settings for its emails, read once - copy: one email, the watchers copied in (else - * one each); relay: a client's reply goes on to the watchers who didn't have it. Both on until + * The ticket settings for its emails, read once - copy: one email, the CCs copied in (else + * one each); relay: a client's reply goes on to the CCs who didn't have it. Both on until * the 4.2.6 update has made them, as they are by default after it. */ function ticketMailSettings() { @@ -227,18 +227,18 @@ function ticketMailSubjectTicket($subject) { /* * The people an email to a ticket was also to or copied to ($addresses, its To and Cc) made the - * ticket's watchers, so the rest of the conversation reaches them as it reaches whoever wrote it. + * ticket's CCs, so the rest of the conversation reaches them as it reaches whoever wrote it. * Never whoever sent it ($sender), the ticket's contact, an agent, one of ITFlow's own addresses or * another address at your own domain (emailOwnDomain()), nor a no-reply address. The ones added. */ -function ticketMailCopiedWatchers($ticket_id, array $addresses, $sender) { +function ticketMailCopiedCcs($ticket_id, array $addresses, $sender) { global $mysqli; $ticket_id = intval($ticket_id); $contact_email = strtolower(trim((string) (mysqli_fetch_row(mysqli_query($mysqli, "SELECT contact_email FROM tickets JOIN contacts ON contact_id = ticket_contact_id WHERE ticket_id = $ticket_id"))[0] ?? ''))); $sender = strtolower(trim((string) $sender)); $emails = []; - foreach (ticketWatcherEmails($addresses) as $email) { + foreach (ticketCcEmails($addresses) as $email) { if ($email === $sender || $email === $contact_email || emailOwnAddress($email) || emailOwnDomain($email) || preg_match('/do[\W_]*not[\W_]*reply|no[\W_]*reply/i', $email)) { continue; @@ -248,7 +248,7 @@ function ticketMailCopiedWatchers($ticket_id, array $addresses, $sender) { } $emails[] = $email; } - return ticketAddWatchers($ticket_id, array_slice($emails, 0, 20)); + return ticketAddCcs($ticket_id, array_slice($emails, 0, 20)); } /* diff --git a/functions/ticket_mail_try.php b/functions/ticket_mail_try.php index 6845af148..9da330be2 100644 --- a/functions/ticket_mail_try.php +++ b/functions/ticket_mail_try.php @@ -16,9 +16,9 @@ * 2. a ticket number in [brackets] in the subject, with the prefix that * ticket was given (ticketMailSubjectTicket()) - a reply on that ticket, * as whoever sent it is to the ticket (its contact or another of the - * client's, an agent, a watcher, or a stranger), or a closed one turned away; + * client's, an agent, a CC, or a stranger), or a closed one turned away; * 3. a subject almost the same as an open ticket of the sender's client from - * the last 7 days - a reply on that ticket from its contact or a watcher, and + * the last 7 days - a reply on that ticket from its contact or a CC, and * from anyone else at the client a new ticket linked to it as related; * 4. a contact's address - a new ticket for their client; * 5. an address at a client's domain - a new contact, and a ticket; @@ -98,7 +98,7 @@ function ticketMailTry($from_email, $subject, $auto_reply = false) { $domain_row = null; } - // 3. Almost the same subject as an open ticket of theirs from the last week - a reply from its contact or a watcher; from + // 3. Almost the same subject as an open ticket of theirs from the last week - a reply from its contact or a CC; from // anyone else at the client, a ticket of its own linked to it $client_id = $contact ? intval($contact['contact_client_id']) : ($domain_row ? intval($domain_row['domain_client_id']) : 0); $similar = null; @@ -116,7 +116,7 @@ function ticketMailTry($from_email, $subject, $auto_reply = false) { $linked = ''; if ($similar) { $theirs = ($contact && intval($contact['contact_id']) === intval($similar['ticket_contact_id'])) - || mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM ticket_watchers WHERE watcher_ticket_id = " . intval($similar['ticket_id']) . " AND watcher_email = '$from_sql' LIMIT 1")); + || mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM ticket_ccs WHERE ticket_cc_ticket_id = " . intval($similar['ticket_id']) . " AND ticket_cc_email = '$from_sql' LIMIT 1")); if ($theirs && ($reply = ticketMailTryReply($from_email, intval($similar['ticket_id'])))) { $steps[] = ['The same subject as an open ticket of theirs from the last week?', 'Yes - ' . ticketReference($similar)]; return ['steps' => $steps, 'outcome' => $reply]; @@ -172,7 +172,7 @@ function ticketMailTryReply($from_email, $ticket_id) { $client_id = intval($ticket['ticket_client_id']); $known = (strtolower((string) $ticket['contact_email']) === $from_email && $from_email !== '') || ($client_id && mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM contacts WHERE contact_email = '$from_sql' AND contact_client_id = $client_id AND contact_archived_at IS NULL LIMIT 1"))) - || mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM ticket_watchers WHERE watcher_ticket_id = " . intval($ticket['ticket_id']) . " AND watcher_email = '$from_sql' LIMIT 1")); + || mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM ticket_ccs WHERE ticket_cc_ticket_id = " . intval($ticket['ticket_id']) . " AND ticket_cc_email = '$from_sql' LIMIT 1")); if (intval($ticket['ticket_status']) === TICKET_STATUS_CLOSED) { return ['fa-ban', 'warning', "A note on $reference - it is closed", 'Closed tickets aren\'t reopened by email: it is kept on the ticket as an internal note, and agents get a notice' @@ -190,8 +190,8 @@ function ticketMailTryReply($from_email, $ticket_id) { if ($agent) { return ['fa-sticky-note', 'info', "An internal note on $on", 'From ' . $agent['user_name'] . ', one of your agents - as their own note. Nothing is reopened.']; } - $watcher = mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM ticket_watchers WHERE watcher_ticket_id = " . intval($ticket['ticket_id']) . " AND watcher_email = '$from_sql' LIMIT 1")); - if ($watcher) { + $cc = mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM ticket_ccs WHERE ticket_cc_ticket_id = " . intval($ticket['ticket_id']) . " AND ticket_cc_email = '$from_sql' LIMIT 1")); + if ($cc) { return ['fa-reply', 'success', "A reply on $on", 'From one of its CCs, as the client\'s reply. ' . $reopens]; } return ['fa-user-secret', 'warning', "An internal note on $on, with a warning", diff --git a/functions/ticket_reply_recipients.php b/functions/ticket_reply_recipients.php index cbb84886b..cbf460a08 100644 --- a/functions/ticket_reply_recipients.php +++ b/functions/ticket_reply_recipients.php @@ -4,7 +4,7 @@ * Who an email reply on a ticket goes to - the To line in its reply box * (agent/ticket.php), sent by add_ticket_reply (agent/post/ticket.php). * - * An email reply has always gone to the contact, the watchers and the client's + * An email reply has always gone to the contact, the CCs and the client's * colleagues who asked for every update (ticketMailSend()). The To line starts * with those same people; the agent it's assigned to, the client's other * contacts and any address typed in can be added, and anyone taken out. Whoever @@ -26,7 +26,7 @@ const TICKET_REPLY_TO_MOST = 50; /** What each kind of person in the To line is - shown under their name. */ const TICKET_REPLY_TO_GROUPS = [ 'contact' => 'Contact on the ticket', - 'watcher' => 'CC', + 'cc' => 'CC', 'colleague' => 'Asked for every update', 'agent' => 'Assigned agent', 'client' => 'Contact at the client', @@ -52,8 +52,8 @@ function ticketReplyRecipientsReady() { /** * Everyone the To line offers on a ticket, in order: [email (lower case) => [ * 'name' their name, or '' - * 'group' contact, watcher, colleague, agent, client or added (TICKET_REPLY_TO_GROUPS) - * 'default' in To unless someone changed it - the contact, watchers and colleagues + * 'group' contact, CC, colleague, agent, client or added (TICKET_REPLY_TO_GROUPS) + * 'default' in To unless someone changed it - the contact, CCs and colleagues * 'send' in To now - the default, or what was kept for the ticket * 'look' their picture or initials, as picker option attributes (selectOptionData()) * ]]. Each address once, under the first thing it is. @@ -95,9 +95,9 @@ function ticketReplyRecipients($ticket_id) { $add($email, $contact['contact_name'], 'contact', true, $contact['look']); } } - $sql = mysqli_query($mysqli, "SELECT watcher_name, watcher_email FROM ticket_watchers WHERE watcher_ticket_id = $ticket_id ORDER BY watcher_id"); + $sql = mysqli_query($mysqli, "SELECT ticket_cc_name, ticket_cc_email FROM ticket_ccs WHERE ticket_cc_ticket_id = $ticket_id ORDER BY ticket_cc_id"); while ($row = mysqli_fetch_assoc($sql)) { - $contact_named($row['watcher_email'], (string) $row['watcher_name'], 'watcher', true); + $contact_named($row['ticket_cc_email'], (string) $row['ticket_cc_name'], 'cc', true); } foreach (ticketColleagueRecipients($ticket_id, 'update') as $email => $colleague) { $contact_named($email, $colleague['name'], 'colleague', true); @@ -179,7 +179,7 @@ function ticketReplyRecipientsPick($ticket_id, array $posted, $remember = true) $company_name = (string) (billingCompany()['company_name'] ?? 'us'); $why = [ 'contact' => "You get this as the contact on ticket $reference with $company_name.", - 'watcher' => "You get this because you are copied in on ticket $reference - ask $company_name if you would like to stop.", + 'cc' => "You get this because you are copied in on ticket $reference - ask $company_name if you would like to stop.", 'colleague' => "You get this because you asked for every update on $client_name's tickets - change that under Your account in the client portal.", 'agent' => "You get this because ticket $reference is assigned to you.", ]; @@ -189,7 +189,7 @@ function ticketReplyRecipientsPick($ticket_id, array $posted, $remember = true) $recipients[] = [ 'email' => $email, 'name' => $person['name'], - 'greet' => in_array($person['group'], ['watcher', 'added'], true) ? '' : $person['name'], + 'greet' => in_array($person['group'], ['cc', 'added'], true) ? '' : $person['name'], 'footnote' => $why[$person['group']] ?? "You get this because $company_name copied you in on ticket $reference.", 'group' => $person['group'], ]; diff --git a/functions/ticket_status.php b/functions/ticket_status.php index 321961317..7d09d9f38 100644 --- a/functions/ticket_status.php +++ b/functions/ticket_status.php @@ -522,7 +522,7 @@ function ticketStatusMovedByAgent($ticket_id, $from_status, $to_status) { $status_name = escapeSql((string) $ticket['ticket_status_name']); if ($mode === 2) { - // The message as a public note - from whoever moved it - then to the contact and watchers + // The message as a public note - from whoever moved it - then to the contact and CCs $agent_name = intval($ticket['ticket_assigned_to']) ? stripslashes((string) $ticket['user_name']) : ''; $html = cannedResponsePlaceholders(nl2br(escapeHtml(trim(ticketAssignedMessage()))), $ticket_id, $agent_name !== '' ? $agent_name : 'our team'); $by = intval($session_user_id ?? 0) ?: intval($ticket['ticket_assigned_to']); diff --git a/guest/guest_post.php b/guest/guest_post.php index 9ac24d097..21286b15a 100644 --- a/guest/guest_post.php +++ b/guest/guest_post.php @@ -98,7 +98,7 @@ if (isset($_GET['export_contract_pdf'])) { * resolved ticket, rate a closed one. Posted, never links - mail scanners and * link previews open links, and must not close a ticket. The ticket's link * key is the only proof, matched exactly (ticketByGuestKey()). Who pressed - * it isn't known - the link goes to watchers too - so it is noted as from + * it isn't known - the link goes to CCs too - so it is noted as from * the guest link, never as the contact. Each happens once: a second press, * or a ticket an agent has moved on since, just goes back to the page. */ diff --git a/guest/guest_view_ticket.php b/guest/guest_view_ticket.php index 720e28dc2..7fa199e73 100644 --- a/guest/guest_view_ticket.php +++ b/guest/guest_view_ticket.php @@ -1,7 +1,7 @@