mirror of
https://github.com/itflow-org/itflow
synced 2026-11-22 04:17:24 +00:00
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:
@@ -923,49 +923,6 @@ if (isset($_POST['bulk_delete_assets'])) {
|
||||
|
||||
// Licenses are linked in post/link.php (link_software_to_asset)
|
||||
|
||||
// Right now 1 login and have many assets but not many to many
|
||||
if (isset($_POST['link_asset_to_credential'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
// It changes the credential, so it takes credential edit rights too
|
||||
enforceUserPermission('module_credential', 2);
|
||||
|
||||
$credential_id = intval($_POST['credential_id']);
|
||||
$asset_id = intval($_POST['asset_id']);
|
||||
|
||||
// Get credential Name and Client ID for logging
|
||||
$sql_credential = mysqli_query($mysqli,"SELECT credential_name, credential_client_id FROM credentials WHERE credential_id = $credential_id");
|
||||
$row = mysqli_fetch_assoc($sql_credential);
|
||||
if (!$row) {
|
||||
flashAlert("That credential no longer exists", 'error');
|
||||
redirect();
|
||||
}
|
||||
$credential_name = escapeSql($row['credential_name']);
|
||||
$client_id = intval($row['credential_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// Only to one of the same client's assets
|
||||
if (!assetClientOwnedId('asset', $asset_id, $client_id)) {
|
||||
flashAlert("That asset isn't one of this client's", 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
// Get Asset Name for logging
|
||||
$asset_name = escapeSql(getFieldById('assets', $asset_id, 'asset_name'));
|
||||
|
||||
mysqli_query($mysqli,"UPDATE credentials SET credential_asset_id = $asset_id WHERE credential_id = $credential_id");
|
||||
|
||||
logAudit("Credential", "Link", "$session_name linked credential $credential_name to asset $asset_name", $client_id, $credential_id);
|
||||
|
||||
flashAlert("Asset <strong>" . stripslashes($asset_name) . "</strong> linked with credential <strong>" . stripslashes($credential_name) . "</strong>");
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['unlink_credential_from_asset'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
@@ -1104,46 +1104,6 @@ if (isset($_GET['delete_contact'])) {
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['link_contact_to_asset'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_client', 2);
|
||||
|
||||
$asset_id = intval($_POST['asset_id']);
|
||||
$contact_id = intval($_POST['contact_id']);
|
||||
|
||||
// Get Asset Name and Client ID for logging
|
||||
$sql_asset = mysqli_query($mysqli,"SELECT asset_name, asset_client_id FROM assets WHERE asset_id = $asset_id");
|
||||
$row = mysqli_fetch_assoc($sql_asset);
|
||||
if (!$row) {
|
||||
flashAlert('Pick an asset to link.', 'error');
|
||||
redirect();
|
||||
}
|
||||
$asset_name = escapeSql($row['asset_name']);
|
||||
$client_id = intval($row['asset_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// Only one of the same client's people - another client's contact would show on this client's asset
|
||||
if (!assetClientOwnedId('contact', $contact_id, $client_id)) {
|
||||
flashAlert("That contact isn't one of this client's", 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
// Get Contact Name for logging
|
||||
$contact_name = escapeSql(getFieldById('contacts', $contact_id, 'contact_name'));
|
||||
|
||||
mysqli_query($mysqli,"UPDATE assets SET asset_contact_id = $contact_id WHERE asset_id = $asset_id");
|
||||
|
||||
logAudit("Asset", "Link", "$session_name linked asset $asset_name to contact $contact_name", $client_id, $asset_id);
|
||||
|
||||
flashAlert("Contact <strong>" . stripslashes($contact_name) . "</strong> linked with asset <strong>" . stripslashes($asset_name) . "</strong>");
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['unlink_asset_from_contact'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
@@ -1181,48 +1141,6 @@ if (isset($_GET['unlink_asset_from_contact'])) {
|
||||
|
||||
// Licenses are linked in post/link.php (link_software_to_contact)
|
||||
|
||||
if (isset($_POST['link_contact_to_credential'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_client', 2);
|
||||
// It changes the credential, so it takes credential edit rights too
|
||||
enforceUserPermission('module_credential', 2);
|
||||
|
||||
$credential_id = intval($_POST['credential_id']);
|
||||
$contact_id = intval($_POST['contact_id']);
|
||||
|
||||
// Get credential Name and Client ID for logging
|
||||
$sql_credential = mysqli_query($mysqli,"SELECT credential_name, credential_client_id FROM credentials WHERE credential_id = $credential_id");
|
||||
$row = mysqli_fetch_assoc($sql_credential);
|
||||
if (!$row) {
|
||||
flashAlert("That credential no longer exists", 'error');
|
||||
redirect();
|
||||
}
|
||||
$credential_name = escapeSql($row['credential_name']);
|
||||
$client_id = intval($row['credential_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// Only to one of the same client's people
|
||||
if (!assetClientOwnedId('contact', $contact_id, $client_id)) {
|
||||
flashAlert("That contact isn't one of this client's", 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
// Get Contact Name for logging
|
||||
$contact_name = escapeSql(getFieldById('contacts', $contact_id, 'contact_name'));
|
||||
|
||||
mysqli_query($mysqli,"UPDATE credentials SET credential_contact_id = $contact_id WHERE credential_id = $credential_id");
|
||||
|
||||
logAudit("Credential", "Link", "$session_name linked credential $credential_name to contact $contact_name", $client_id, $credential_id);
|
||||
|
||||
flashAlert("Contact <strong>" . stripslashes($contact_name) . "</strong> linked with credential <strong>" . stripslashes($credential_name) . "</strong>");
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['unlink_credential_from_contact'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* files about a location, and what a service depends on.
|
||||
*
|
||||
* One handler for every pair LINK_RELATIONS knows (functions/links.php):
|
||||
* link_items links any number of records at once, unlink_item drops one.
|
||||
* unlink_item drops one. Linking is the Link picker's (functions/link_picker.php).
|
||||
* The older one-pair-each names (link_asset_to_document, unlink_contact_from_file
|
||||
* and so on) are still answered here, so a link built by any page or older
|
||||
* modal keeps working - and gets the same checks: the same client, nothing
|
||||
@@ -63,11 +63,6 @@ function linkHandle($action, $from, $id, $to, $ids) {
|
||||
redirect();
|
||||
}
|
||||
|
||||
if (isset($_POST['link_items'])) {
|
||||
$ids = $_POST['ids'] ?? [];
|
||||
linkHandle('link', (string) ($_POST['from'] ?? ''), intval($_POST['id'] ?? 0), (string) ($_POST['to'] ?? ''), is_array($ids) ? $ids : [$ids]);
|
||||
}
|
||||
|
||||
if (isset($_GET['unlink_item'])) {
|
||||
linkHandle('unlink', (string) ($_GET['from'] ?? ''), intval($_GET['id'] ?? 0), (string) ($_GET['to'] ?? ''), [intval($_GET['other'] ?? 0)]);
|
||||
}
|
||||
|
||||
@@ -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'])) {
|
||||
|
||||
|
||||
@@ -189,62 +189,6 @@ if (isset($_GET['delete_service'])) {
|
||||
|
||||
}
|
||||
|
||||
// Tickets raised about a service - from its page, or from the ticket
|
||||
if (isset($_POST['link_service_tickets'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$row = serviceForRequest($_POST['service_id'] ?? 0, 2);
|
||||
|
||||
$added = serviceLinkTickets($row['service_id'], $client_id, (array) ($_POST['ticket_ids'] ?? []));
|
||||
if ($added) {
|
||||
logAudit("Service", "Link", "$session_name linked $added ticket(s) to service " . escapeSql($row['service_name']), $client_id, intval($row['service_id']));
|
||||
flashAlert("Linked <strong>$added</strong> ticket" . ($added === 1 ? '' : 's') . " to <strong>" . escapeHtml($row['service_name']) . "</strong>");
|
||||
} else {
|
||||
flashAlert("Nothing new to link to <strong>" . escapeHtml($row['service_name']) . "</strong>.", 'warning');
|
||||
}
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['link_ticket_services'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$ticket_id = intval($_POST['ticket_id'] ?? 0);
|
||||
$ticket = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT ticket_id, ticket_prefix, ticket_number, ticket_client_id FROM tickets WHERE ticket_id = $ticket_id"));
|
||||
if (!$ticket || !intval($ticket['ticket_client_id'])) {
|
||||
flashAlert('That ticket no longer exists.', 'error');
|
||||
redirect();
|
||||
}
|
||||
$client_id = intval($ticket['ticket_client_id']);
|
||||
enforceClientAccess();
|
||||
|
||||
$names = [];
|
||||
foreach (array_unique(array_map('intval', (array) ($_POST['service_ids'] ?? []))) as $service_id) {
|
||||
$row = serviceRow($service_id);
|
||||
if (!$row || intval($row['service_client_id']) !== $client_id || $row['service_archived_at']) {
|
||||
continue;
|
||||
}
|
||||
if (serviceLinkTickets($service_id, $client_id, [$ticket_id])) {
|
||||
$names[] = $row['service_name'];
|
||||
logAudit("Service", "Link", "$session_name linked ticket " . escapeSql($ticket['ticket_prefix'] . $ticket['ticket_number']) . " to service " . escapeSql($row['service_name']), $client_id, $service_id);
|
||||
}
|
||||
}
|
||||
|
||||
if ($names) {
|
||||
flashAlert("Ticket linked to <strong>" . escapeHtml(implode(', ', $names)) . "</strong>");
|
||||
} else {
|
||||
flashAlert('Nothing new to link.', 'warning');
|
||||
}
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['unlink_service_ticket'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
@@ -1,45 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - POST handlers for related tickets (functions/ticket_link.php): the ticket page's
|
||||
* Link window and the x on each related ticket, and Link together on the tickets list.
|
||||
* ITFlow - POST handlers for related tickets (functions/ticket_link.php): the x on each related
|
||||
* ticket, and Link together on the tickets list. Linking from a ticket is its Link picker
|
||||
* (functions/link_picker.php).
|
||||
*/
|
||||
|
||||
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
|
||||
|
||||
// From a ticket's Link window: this ticket and the ones picked, each a ticket of a client the agent can open
|
||||
if (isset($_POST['link_tickets'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$row = ticketForRequest($_POST['ticket_id'] ?? 0, 2);
|
||||
$ticket_id = intval($row['ticket_id']);
|
||||
|
||||
$ids = [$ticket_id];
|
||||
foreach (array_unique(array_map('intval', (array) ($_POST['related_ticket_ids'] ?? []))) as $related_id) {
|
||||
$related = $related_id ? ticketRow($related_id) : null;
|
||||
if ($related && (!intval($related['ticket_client_id']) || hasClientAccess($related['ticket_client_id']))) {
|
||||
$ids[] = $related_id;
|
||||
}
|
||||
}
|
||||
if (count($ids) < 2) {
|
||||
flashAlert('Pick the tickets to link it with.', 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
$joined = ticketLinkTogether($ids);
|
||||
$related_count = count(ticketRelated($ticket_id));
|
||||
|
||||
logAudit("Ticket", "Link", "$session_name linked ticket " . escapeSql(ticketReference($row)) . " with " . (count($ids) - 1) . " other ticket(s)", intval($row['ticket_client_id']), $ticket_id);
|
||||
|
||||
flashAlert($joined
|
||||
? "<strong>" . escapeHtml(ticketReference($row)) . "</strong> is related to <strong>$related_count</strong> ticket" . ($related_count === 1 ? '' : 's') . " now"
|
||||
: 'They were already related.');
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
// The x on a related ticket - it comes out of the group, the rest stay related
|
||||
if (isset($_GET['unlink_ticket'])) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user