Link opens the standard picker under the button instead of a window - linked records ticked, tick to link and untick to unlink, saved when the picker closes with one message - for every record link, contact and asset credentials, a contact's assets, project and service tickets, a ticket's services and related tickets, with a document's or file's Link grouped by kind and quick looks reloading in place; the old link windows and the handlers only they used are removed

This commit is contained in:
johnnyq
2026-11-20 18:23:48 -05:00
parent c1bdc99c14
commit 8ac88a48fd
54 changed files with 837 additions and 1252 deletions

View File

@@ -207,70 +207,6 @@ if (isset($_GET['delete_project'])) {
}
/*
* Tickets onto a project - picked from its client's tickets, or typed by
* number for older ones. Moving a ticket off another project is fine; one
* the agent can't reach, or another client's, is skipped.
*/
if (isset($_POST['link_ticket_to_project'])) {
validateCSRFToken();
$row = projectForRequest($_POST['project_id'] ?? 0, 2);
if (!projectIsOpen($row)) {
flashAlert("Project <strong>" . escapeHtml(projectReference($row)) . "</strong> isn't open - reopen it to add tickets.", 'error');
redirect();
}
$ticket_ids = array_map('intval', (array) ($_POST['tickets'] ?? []));
// Numbers typed in, with or without the prefix
$not_found = [];
foreach (preg_split('/[\s,;]+/', (string) ($_POST['ticket_numbers'] ?? ''), -1, PREG_SPLIT_NO_EMPTY) as $typed) {
$number = intval(preg_replace('/^\D+/', '', $typed));
$found = $number ? mysqli_fetch_row(mysqli_query($mysqli, "SELECT ticket_id FROM tickets WHERE ticket_number = $number ORDER BY ticket_id DESC LIMIT 1")) : null;
if ($found) {
$ticket_ids[] = intval($found[0]);
} else {
$not_found[] = escapeHtml($typed);
}
}
$added = 0;
$skipped = [];
foreach (array_unique(array_filter($ticket_ids)) as $ticket_id) {
$ticket = ticketRow($ticket_id);
if (!$ticket) {
continue;
}
if (intval($ticket['ticket_project_id']) === intval($row['project_id'])) {
continue;
}
$why_not = projectAddTicket($row, $ticket);
if ($why_not === '') {
$added++;
} else {
$skipped[] = escapeHtml(ticketReference($ticket)) . " ($why_not)";
}
}
if ($added) {
logAudit("Project", "Edit", "$session_name added $added ticket" . ($added === 1 ? '' : 's') . " to project " . escapeSql(projectReference($row) . ' - ' . $row['project_name']), $client_id, intval($row['project_id']));
}
// One message - a second flashAlert() would replace the first
$message = array_filter([
$added ? "<strong>$added</strong> ticket" . ($added === 1 ? '' : 's') . " added to <strong>" . escapeHtml($row['project_name']) . "</strong>" : '',
$skipped ? 'Skipped ' . implode(', ', $skipped) : '',
$not_found ? 'No ticket numbered ' . implode(', ', $not_found) : '',
]);
flashAlert($message ? implode('. ', $message) : 'Nothing to add - those tickets are on the project already.', $added ? 'success' : 'error');
redirect();
}
/** Tickets off a project - from its page, ticked. Only ones on this project, and the agent may reach. */
if (isset($_POST['remove_tickets_from_project'])) {