mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 09:09:01 +00:00
Ticket CCs in the API: ticket_ccs read, create and delete endpoints scoped through the ticket's client, adding one address or several with an optional email to each new CC, removing by id or by address at Modify as on the ticket page, closed tickets left as they are, ticket history and audit lines; tickets/create takes ticket_ccs before its first email goes out and tickets/read returns each ticket's CCs; 26.12.3 changelog
This commit is contained in:
@@ -247,6 +247,46 @@ function ticketCcEmails($input) {
|
||||
return array_keys($emails);
|
||||
}
|
||||
|
||||
/**
|
||||
* ticketCcEmails() for the API, where an address that is wrong is said so rather than left out - the list, or null
|
||||
* with $bad the first entry that isn't an email address. $input is a list, or one string separated by commas,
|
||||
* semicolons or spaces.
|
||||
*/
|
||||
function ticketCcEmailsValid($input, &$bad = '') {
|
||||
$list = is_array($input) ? $input : preg_split('/[\s,;]+/', is_scalar($input) ? (string) $input : '');
|
||||
foreach ($list as $email) {
|
||||
if (!is_scalar($email) && $email !== null) {
|
||||
$bad = 'a list inside the list';
|
||||
return null;
|
||||
}
|
||||
$email = trim((string) $email);
|
||||
if ($email !== '' && !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$bad = $email;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return ticketCcEmails($list);
|
||||
}
|
||||
|
||||
/** Each ticket's CCs on its row, as ticket_ccs - their ticket_cc_id, ticket_cc_name and ticket_cc_email, as they were added. For the API's ticket read (api/v1/read_output.php). */
|
||||
function ticketCcsApiAttach(array $rows) {
|
||||
global $mysqli;
|
||||
$ids = array_unique(array_filter(array_map('intval', array_column($rows, 'ticket_id'))));
|
||||
$ccs = [];
|
||||
if ($ids) {
|
||||
$sql = mysqli_query($mysqli, "SELECT ticket_cc_id, ticket_cc_name, ticket_cc_email, ticket_cc_ticket_id FROM ticket_ccs
|
||||
WHERE ticket_cc_ticket_id IN (" . implode(',', $ids) . ") ORDER BY ticket_cc_id");
|
||||
while ($sql && ($cc = mysqli_fetch_assoc($sql))) {
|
||||
$ccs[intval($cc['ticket_cc_ticket_id'])][] = ['ticket_cc_id' => intval($cc['ticket_cc_id']), 'ticket_cc_name' => $cc['ticket_cc_name'], 'ticket_cc_email' => $cc['ticket_cc_email']];
|
||||
}
|
||||
}
|
||||
foreach ($rows as &$row) {
|
||||
$row['ticket_ccs'] = $ccs[intval($row['ticket_id'] ?? 0)] ?? [];
|
||||
}
|
||||
unset($row);
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/** 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;
|
||||
|
||||
Reference in New Issue
Block a user