Files
itflow/api/v1/ticket_ccs/delete.php

59 lines
2.4 KiB
PHP

<?php
/*
* API - Ticket CCs - Delete
* POST /api/v1/ticket_ccs/delete.php
*
* Take a CC off a ticket, as the x beside them on its page does - they get no
* more of its emails. Needs Modify on Support, as on the page, not Full. Not on
* a closed ticket.
*
* Parameters (POST, JSON body):
* api_key required - Your API key
* ticket_cc_id The CC - this, or ticket_id and ticket_cc_email
* ticket_id, ticket_cc_email The ticket, and the CC's email address
* client_id the ticket's client - needed when the key's user is limited to
* certain clients
*/
require_once '../validate_api_key.php';
require_once '../require_post_method.php';
$delete_count = false;
require_once 'ticket_cc_find.php';
// By the ticket and the address, without the CC's id
if ($ticket && !$cc_row && empty($_POST['ticket_cc_id'])) {
$cc_email = strtolower(trim(is_scalar($_POST['ticket_cc_email'] ?? '') ? (string) ($_POST['ticket_cc_email'] ?? '') : ''));
if ($cc_email === '') {
apiFormRefuse('ticket_cc_id is needed, or ticket_id and ticket_cc_email');
}
$cc_row = mysqli_fetch_assoc(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 = " . intval($ticket['ticket_id']) . " AND ticket_cc_email = '" . escapeSql($cc_email) . "' LIMIT 1"));
if (!$cc_row) {
apiFormRefuse("$cc_email isn't a CC on ticket " . ticketReference($ticket));
}
}
if ($ticket && $cc_row) {
if ($cc_locked) {
apiFormRefuse($cc_locked);
}
$ticket_id = intval($ticket['ticket_id']);
mysqli_query($mysqli, "DELETE FROM ticket_ccs WHERE ticket_cc_id = " . intval($cc_row['ticket_cc_id']));
$delete_count = mysqli_affected_rows($mysqli);
if ($delete_count > 0) {
$cc_email_sql = escapeSql($cc_row['ticket_cc_email']);
$reference_sql = escapeSql(ticketReference($ticket));
logTicketHistory($ticket_id, "$session_name removed $cc_email_sql as a CC via the API ($api_key_name)");
logAudit("Ticket", "Edit", "Removed $cc_email_sql as a CC on ticket $reference_sql via API ($api_key_name)", $client_id, $ticket_id);
logAudit("API", "Success", "Removed $cc_email_sql as a CC on ticket $reference_sql via API ($api_key_name)", $client_id);
}
}
// Output
require_once '../delete_output.php';