mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 09:09:01 +00:00
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
This commit is contained in:
@@ -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())].
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user