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

@@ -1,70 +0,0 @@
<?php
/*
* Link one of the client's credentials to an asset. A credential sits on one
* asset, so picking one that is on another asset moves it here - the picker
* says where each one is now. Ones whose asset was deleted count as free.
*/
require_once '../../../includes/modal_header.php';
enforceUserPermission('module_support', 2);
enforceUserPermission('module_credential', 2);
$asset_id = intval($_GET['id'] ?? 0);
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT asset_client_id, asset_name FROM assets WHERE asset_id = $asset_id LIMIT 1"));
if (!$row) {
echo json_encode(['error' => 'That asset no longer exists.']);
exit;
}
$asset_name = escapeHtml($row['asset_name']);
$client_id = intval($row['asset_client_id']);
enforceClientAccess();
$choices = credentialRows("credential_client_id = $client_id AND credential_asset_id <> $asset_id");
// Free ones first, then the ones that would move from another asset
uasort($choices, function ($a, $b) {
return [empty($a['asset_id']) ? 0 : 1, strtolower($a['credential_name'])] <=> [empty($b['asset_id']) ? 0 : 1, strtolower($b['credential_name'])];
});
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title text-truncate"><i class="fa fa-fw fa-key me-2"></i>Link a credential to <strong><?= $asset_name ?></strong></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="asset_id" value="<?= $asset_id ?>">
<div class="modal-body">
<?php if ($choices) { ?>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-key"></i></span>
<select class="form-select select2" name="credential_id" required data-placeholder="Pick a credential">
<option value=""></option>
<?php foreach ($choices as $credential_id => $choice) {
$where_now = !empty($choice['asset_id']) ? 'On ' . $choice['asset_name'] . ' - moves here' : ($choice['credential_description'] ?: $choice['credential_uri']); ?>
<option value="<?= $credential_id ?>"<?= selectOptionCredential($choice, $where_now) ?>><?= escapeHtml($choice['credential_name']) ?></option>
<?php } ?>
</select>
</div>
<div class="form-text">A credential belongs to one asset - one already on another asset moves here.</div>
<?php } else { ?>
<p class="text-body-secondary mb-0">This client has no other credentials to link - make a new one instead.</p>
<?php } ?>
</div>
<div class="modal-footer">
<?php if ($choices) { ?>
<button type="submit" name="link_asset_to_credential" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Link</button>
<?php } ?>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -1,12 +0,0 @@
<?php
/*
* Kept so existing links keep working. Every pair is linked in
* agent/modals/link/link.php, here opened on its Documents tab.
*/
$_GET['from'] = 'asset';
$_GET['id'] = intval($_GET['id'] ?? 0);
$_GET['to'] = 'document';
require __DIR__ . '/../link/link.php';

View File

@@ -1,12 +0,0 @@
<?php
/*
* Kept so existing links keep working. Every pair is linked in
* agent/modals/link/link.php, here opened on its Files tab.
*/
$_GET['from'] = 'asset';
$_GET['id'] = intval($_GET['id'] ?? 0);
$_GET['to'] = 'file';
require __DIR__ . '/../link/link.php';

View File

@@ -1,12 +0,0 @@
<?php
/*
* Kept so existing links keep working. Every pair is linked in
* agent/modals/link/link.php, here opened on its Services tab.
*/
$_GET['from'] = 'asset';
$_GET['id'] = intval($_GET['id'] ?? 0);
$_GET['to'] = 'service';
require __DIR__ . '/../link/link.php';

View File

@@ -1,13 +0,0 @@
<?php
/*
* Kept so existing links keep working. Every pair is linked in
* agent/modals/link/link.php, here opened on its Licenses tab - every license
* the client has, with how many seats each has left.
*/
$_GET['from'] = 'asset';
$_GET['id'] = intval($_GET['id'] ?? 0);
$_GET['to'] = 'software';
require __DIR__ . '/../link/link.php';

View File

@@ -176,7 +176,7 @@ ob_start();
<div class="d-flex align-items-center mt-1 mb-1">
<span class="small text-body-secondary fw-semibold text-uppercase me-auto">Services that use it</span>
<?php if ($can_edit) { ?>
<a class="small ajax-modal" href="#" data-modal-url="modals/link/link.php?from=certificate&id=<?= $certificate_id ?>&to=service"><i class="fas fa-link me-1"></i>Link a service</a>
<?= linkPickerButton('certificate', $certificate_id, 'service', 'Link a service', 'small', 'fas fa-link me-1') ?>
<?php } ?>
</div>
<?php if ($services) { ?>

View File

@@ -1,65 +0,0 @@
<?php
require_once '../../../includes/modal_header.php';
$contact_id = intval($_GET['id']);
$sql = mysqli_query($mysqli, "SELECT contact_client_id, contact_name FROM contacts
WHERE contact_id = $contact_id
LIMIT 1
");
$row = mysqli_fetch_assoc($sql);
$contact_name = escapeHtml($row['contact_name']);
$client_id = intval($row['contact_client_id']);
enforceClientAccess();
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fa fa-fw fa-desktop me-2"></i>Link Asset to <strong><?= $contact_name ?></strong></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="contact_id" value="<?= $contact_id ?>">
<div class="modal-body">
<div class="mb-3">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-desktop"></i></span>
<select class="form-select select2" name="asset_id">
<option value="">- Select an Asset -</option>
<?php
$sql_assets_select = mysqli_query($mysqli, "
SELECT asset_id, asset_name, asset_type, asset_make, asset_model
FROM assets
WHERE asset_client_id = $client_id
AND asset_contact_id = 0
AND asset_archived_at IS NULL
ORDER BY asset_name ASC
");
while ($row = mysqli_fetch_assoc($sql_assets_select)) {
$asset_id = intval($row['asset_id']);
$asset_name = escapeHtml($row['asset_name']);
?>
<option value="<?= $asset_id ?>"<?= selectOptionAsset($row['asset_type'] ?? '', trim(($row['asset_make'] ?? '') . ' ' . ($row['asset_model'] ?? ''))) ?>><?= $asset_name ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="link_contact_to_asset" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Link</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';
?>

View File

@@ -1,70 +0,0 @@
<?php
/*
* Link one of the client's credentials to a contact - whose login it is. A
* credential belongs to one contact, so picking one that is someone else's
* moves it - the picker says whose each one is now.
*/
require_once '../../../includes/modal_header.php';
enforceUserPermission('module_client', 2);
enforceUserPermission('module_credential', 2);
$contact_id = intval($_GET['id'] ?? 0);
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT contact_client_id, contact_name FROM contacts WHERE contact_id = $contact_id LIMIT 1"));
if (!$row) {
echo json_encode(['error' => 'That contact no longer exists.']);
exit;
}
$contact_name = escapeHtml($row['contact_name']);
$client_id = intval($row['contact_client_id']);
enforceClientAccess();
$choices = credentialRows("credential_client_id = $client_id AND credential_contact_id <> $contact_id");
// Nobody's first, then the ones that would move from someone else
uasort($choices, function ($a, $b) {
return [empty($a['contact_id']) ? 0 : 1, strtolower($a['credential_name'])] <=> [empty($b['contact_id']) ? 0 : 1, strtolower($b['credential_name'])];
});
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title text-truncate"><i class="fa fa-fw fa-key me-2"></i>Link a credential to <strong><?= $contact_name ?></strong></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="contact_id" value="<?= $contact_id ?>">
<div class="modal-body">
<?php if ($choices) { ?>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-key"></i></span>
<select class="form-select select2" name="credential_id" required data-placeholder="Pick a credential">
<option value=""></option>
<?php foreach ($choices as $credential_id => $choice) {
$whose_now = !empty($choice['contact_id']) ? $choice['contact_name'] . "'s - moves to " . html_entity_decode($contact_name, ENT_QUOTES, 'UTF-8') : ($choice['credential_description'] ?: $choice['credential_uri']); ?>
<option value="<?= $credential_id ?>"<?= selectOptionCredential($choice, $whose_now) ?>><?= escapeHtml($choice['credential_name']) ?></option>
<?php } ?>
</select>
</div>
<div class="form-text">A credential belongs to one person - one that is someone else's moves to <?= $contact_name ?>.</div>
<?php } else { ?>
<p class="text-body-secondary mb-0">This client has no other credentials to link - make a new one instead.</p>
<?php } ?>
</div>
<div class="modal-footer">
<?php if ($choices) { ?>
<button type="submit" name="link_contact_to_credential" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Link</button>
<?php } ?>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -1,12 +0,0 @@
<?php
/*
* Kept so existing links keep working. Every pair is linked in
* agent/modals/link/link.php, here opened on its Documents tab.
*/
$_GET['from'] = 'contact';
$_GET['id'] = intval($_GET['id'] ?? 0);
$_GET['to'] = 'document';
require __DIR__ . '/../link/link.php';

View File

@@ -1,12 +0,0 @@
<?php
/*
* Kept so existing links keep working. Every pair is linked in
* agent/modals/link/link.php, here opened on its Files tab.
*/
$_GET['from'] = 'contact';
$_GET['id'] = intval($_GET['id'] ?? 0);
$_GET['to'] = 'file';
require __DIR__ . '/../link/link.php';

View File

@@ -1,12 +0,0 @@
<?php
/*
* Kept so existing links keep working. Every pair is linked in
* agent/modals/link/link.php, here opened on its Services tab.
*/
$_GET['from'] = 'contact';
$_GET['id'] = intval($_GET['id'] ?? 0);
$_GET['to'] = 'service';
require __DIR__ . '/../link/link.php';

View File

@@ -1,13 +0,0 @@
<?php
/*
* Kept so existing links keep working. Every pair is linked in
* agent/modals/link/link.php, here opened on its Licenses tab - every license
* the client has, with how many seats each has left.
*/
$_GET['from'] = 'contact';
$_GET['id'] = intval($_GET['id'] ?? 0);
$_GET['to'] = 'software';
require __DIR__ . '/../link/link.php';

View File

@@ -113,7 +113,7 @@ ob_start();
<div class="d-flex align-items-center mt-3 mb-1">
<span class="small text-body-secondary fw-semibold text-uppercase me-auto">For</span>
<?php if ($can_edit && $link_types) { ?>
<a class="small ajax-modal" href="#" data-modal-url="modals/link/link.php?from=credential&id=<?= $credential_id ?>&to=vendor"><i class="fas fa-link me-1"></i>Link a vendor, license or service</a>
<?= linkPickerButton('credential', $credential_id, '', 'Link a vendor, license or service', 'small', 'fas fa-link me-1') ?>
<?php } ?>
</div>
<ul class="list-unstyled mb-0 itflow-links">

View File

@@ -1,12 +0,0 @@
<?php
/*
* Kept so existing links keep working. Every pair is linked in
* agent/modals/link/link.php, here opened on its Assets tab.
*/
$_GET['from'] = 'document';
$_GET['id'] = intval($_GET['document_id'] ?? 0);
$_GET['to'] = 'asset';
require __DIR__ . '/../link/link.php';

View File

@@ -1,12 +0,0 @@
<?php
/*
* Kept so existing links keep working. Every pair is linked in
* agent/modals/link/link.php, here opened on its Contacts tab.
*/
$_GET['from'] = 'document';
$_GET['id'] = intval($_GET['document_id'] ?? 0);
$_GET['to'] = 'contact';
require __DIR__ . '/../link/link.php';

View File

@@ -1,12 +0,0 @@
<?php
/*
* Kept so existing links keep working. Every pair is linked in
* agent/modals/link/link.php, here opened on its Files tab.
*/
$_GET['from'] = 'document';
$_GET['id'] = intval($_GET['document_id'] ?? 0);
$_GET['to'] = 'file';
require __DIR__ . '/../link/link.php';

View File

@@ -1,12 +0,0 @@
<?php
/*
* Kept so existing links keep working. Every pair is linked in
* agent/modals/link/link.php, here opened on its Licenses tab.
*/
$_GET['from'] = 'document';
$_GET['id'] = intval($_GET['document_id'] ?? 0);
$_GET['to'] = 'software';
require __DIR__ . '/../link/link.php';

View File

@@ -1,12 +0,0 @@
<?php
/*
* Kept so existing links keep working. Every pair is linked in
* agent/modals/link/link.php, here opened on its Vendors tab.
*/
$_GET['from'] = 'document';
$_GET['id'] = intval($_GET['document_id'] ?? 0);
$_GET['to'] = 'vendor';
require __DIR__ . '/../link/link.php';

View File

@@ -165,7 +165,7 @@ ob_start();
<div class="d-flex align-items-center mt-3 mb-1">
<span class="small text-body-secondary fw-semibold text-uppercase me-auto">Services that use it</span>
<?php if ($can_edit) { ?>
<a class="small ajax-modal" href="#" data-modal-url="modals/link/link.php?from=domain&id=<?= $domain_id ?>&to=service"><i class="fas fa-link me-1"></i>Link a service</a>
<?= linkPickerButton('domain', $domain_id, 'service', 'Link a service', 'small', 'fas fa-link me-1') ?>
<?php } ?>
</div>
<?php if ($services) { ?>

View File

@@ -1,12 +0,0 @@
<?php
/*
* Kept so existing links keep working. Every pair is linked in
* agent/modals/link/link.php, here opened on its Assets tab.
*/
$_GET['from'] = 'file';
$_GET['id'] = intval($_GET['id'] ?? 0);
$_GET['to'] = 'asset';
require __DIR__ . '/../link/link.php';

View File

@@ -1,140 +0,0 @@
<?php
/*
* Link things to a document or a file - or a document or file to an asset or
* contact, devices, users and credentials to a license, what a service
* depends on to the service. One modal for every
* pair in LINK_RELATIONS (functions/links.php):
* ?from=document&id=81&to=asset opens on Assets; the pills along the top
* switch to anything else this record can be linked to. Pick as many as you
* like; only the client's own, unarchived, not-yet-linked records are offered.
*
* The old one-pair modals (document_link_asset.php, asset_link_file.php...)
* are thin wrappers that set from/id/to and include this.
*/
require_once '../../../includes/modal_header.php';
$link_from = (string) ($_GET['from'] ?? '');
$link_id = intval($_GET['id'] ?? 0);
$link_source = linkRecord($link_from, $link_id);
if (!$link_source) {
echo json_encode(['error' => 'That record no longer exists.']);
exit;
}
$client_id = intval($link_source['client_id']);
enforceClientAccess();
// Only the kinds this agent may change
$link_types = array_values(array_filter(linkTypesFor($link_from), function ($to) use ($link_from) {
return linkCanEdit($link_from, $to);
}));
if (!$link_types) {
echo json_encode(['error' => 'You do not have permission to change these links.']);
exit;
}
$link_to = in_array($_GET['to'] ?? '', $link_types, true) ? $_GET['to'] : $link_types[0];
$from_entity = LINK_ENTITIES[$link_from];
$link_name = escapeHtml($link_source['name']);
$panes = [];
foreach ($link_types as $to) {
$panes[$to] = [
'entity' => LINK_ENTITIES[$to],
'linked' => count(linkedRecords($link_from, $link_id, $to)),
'candidates' => linkCandidates($link_from, $link_id, $to, $client_id),
];
}
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-link me-2"></i>Link to <strong><?= $link_name ?></strong></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off" data-link-form>
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="from" value="<?= escapeHtml($link_from) ?>">
<input type="hidden" name="id" value="<?= $link_id ?>">
<input type="hidden" name="to" value="<?= escapeHtml($link_to) ?>" data-link-to>
<div class="modal-body">
<?php if (count($panes) > 1) { ?>
<nav class="nav nav-pills itflow-asset-pills itflow-link-types mb-3" role="tablist">
<?php foreach ($panes as $to => $pane) { ?>
<button type="button" class="nav-link <?= $to === $link_to ? 'active' : '' ?>" data-bs-toggle="pill" data-bs-target="#linkPane-<?= $to ?>" data-link-type="<?= $to ?>" role="tab">
<i class="fas fa-fw <?= $pane['entity']['icon'] ?> me-1"></i><?= $pane['entity']['plural'] ?>
<?php if ($pane['linked']) { ?><span class="badge rounded-pill ms-1" title="Already linked"><?= $pane['linked'] ?></span><?php } ?>
</button>
<?php } ?>
</nav>
<?php } ?>
<div class="tab-content">
<?php foreach ($panes as $to => $pane) {
$entity = $pane['entity']; ?>
<div class="tab-pane fade <?= $to === $link_to ? 'show active' : '' ?>" id="linkPane-<?= $to ?>" role="tabpanel">
<?php if ($pane['candidates']) { ?>
<label class="form-label">Which <?= strtolower($entity['plural']) ?>?</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw <?= $entity['icon'] ?>"></i></span>
<select class="form-select select2" name="ids[]" multiple data-placeholder="Pick one or more <?= strtolower($entity['plural']) ?>" <?= $to === $link_to ? '' : 'disabled' ?> data-link-select="<?= $to ?>">
<?php foreach ($pane['candidates'] as $row) { ?>
<option value="<?= intval($row['id']) ?>"<?= linkOptionData($to, $row, $client_id) ?>><?= escapeHtml($row['name']) ?></option>
<?php } ?>
</select>
</div>
<div class="form-text"><?= count($pane['candidates']) ?> <?= count($pane['candidates']) === 1 ? $entity['label'] : strtolower($entity['plural']) ?> not linked yet<?= $pane['linked'] ? ', ' . $pane['linked'] . ' already linked' : '' ?>.</div>
<?php } else { ?>
<div class="itflow-asset-empty py-4">
<i class="fas <?= $entity['icon'] ?> fa-2x mb-2"></i>
<div><?= $pane['linked'] ? 'Every ' . $entity['label'] . ' this client has is already linked.' : 'This client has no ' . strtolower($entity['plural']) . ' to link.' ?></div>
</div>
<?php } ?>
</div>
<?php } ?>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="link_items" class="btn btn-primary text-bold"><i class="fas fa-link me-2"></i>Link</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<script>
(function () {
// Only the pane on show posts its picks
var form = document.querySelector('form[data-link-form]:not([data-wired])');
if (!form) {
return;
}
form.dataset.wired = '1';
var to = form.querySelector('[data-link-to]');
form.querySelectorAll('[data-link-type]').forEach(function (pill) {
pill.addEventListener('shown.bs.tab', function () {
to.value = pill.dataset.linkType;
form.querySelectorAll('[data-link-select]').forEach(function (select) {
select.disabled = select.dataset.linkSelect !== to.value;
});
});
});
form.addEventListener('submit', function (e) {
var select = form.querySelector('[data-link-select="' + to.value + '"]');
if (!select || !select.selectedOptions.length) {
e.preventDefault();
if (select && select.itflowSelect) {
select.itflowSelect.open();
}
}
});
})();
</script>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -1,90 +0,0 @@
<?php
/*
* Add tickets to a project - picked from its client's tickets (any client's
* for an internal project), open ones first, then the ones closed in the
* last 90 days; older ones by number. A ticket on another project moves.
*/
require_once '../../../includes/modal_header.php';
$project = projectForModal($_GET['project_id'] ?? 0, 2, true);
$project_id = intval($project['project_id']);
$project_client_id = intval($project['project_client_id']);
$client_sql = $project_client_id ? "AND ticket_client_id = $project_client_id" : clientScopeSql('ticket_client_id');
$sql = mysqli_query($mysqli, "SELECT ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_client_id, ticket_resolved_at, ticket_closed_at,
ticket_status_name, client_name, project_id, project_prefix, project_number, project_name
FROM tickets
LEFT JOIN ticket_statuses ON ticket_status_id = ticket_status
LEFT JOIN clients ON client_id = ticket_client_id
LEFT JOIN projects ON project_id = ticket_project_id AND ticket_project_id > 0
WHERE ticket_project_id <> $project_id AND ticket_archived_at IS NULL $client_sql
AND (" . TICKET_OPEN_SQL . " OR COALESCE(ticket_closed_at, ticket_resolved_at) > NOW() - INTERVAL 90 DAY)
ORDER BY " . TICKET_OPEN_SQL . " DESC, ticket_number DESC
LIMIT 500");
$open = [];
$done = [];
while ($row = mysqli_fetch_assoc($sql)) {
if (ticketIsOpen($row)) {
$open[] = $row;
} else {
$done[] = $row;
}
}
$option = function ($row) use ($project_client_id) {
$description = array_filter([
$row['ticket_status_name'],
!$project_client_id ? ($row['client_name'] ?? 'Internal') : '',
$row['project_id'] ? 'now on ' . $row['project_prefix'] . $row['project_number'] . ' - ' . $row['project_name'] : '',
]);
return '<option value="' . intval($row['ticket_id']) . '" data-icon="fas fa-life-ring" data-description="' . escapeHtml(implode(' · ', $description)) . '">'
. escapeHtml(ticketReference($row) . ' - ' . $row['ticket_subject']) . '</option>';
};
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-link me-2"></i>Add tickets <small class="ms-1 opacity-75"><?= escapeHtml(projectReference($project) . ' - ' . $project['project_name']) ?></small></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="project_id" value="<?= $project_id ?>">
<div class="modal-body">
<div class="mb-3">
<label class="form-label">Tickets</label>
<select class="form-select select2" data-placeholder="Pick tickets..." multiple name="tickets[]">
<?php if ($open) { ?>
<optgroup label="Open">
<?php foreach ($open as $row) { echo $option($row); } ?>
</optgroup>
<?php } ?>
<?php if ($done) { ?>
<optgroup label="Resolved or closed in the last 90 days">
<?php foreach ($done as $row) { echo $option($row); } ?>
</optgroup>
<?php } ?>
</select>
<div class="form-text"><?= $project_client_id ? escapeHtml($project['client_name']) . "'s tickets" : "Any client's tickets - this is an internal project" ?>. One on another project moves to this one.</div>
</div>
<div class="mb-0">
<label class="form-label">Or by number</label>
<input type="text" class="form-control" name="ticket_numbers" placeholder="<?= escapeHtml($config_ticket_prefix) ?>1042, <?= escapeHtml($config_ticket_prefix) ?>1043">
<div class="form-text">For older tickets - separate them with commas or spaces.</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="link_ticket_to_project" class="btn btn-primary text-bold"><i class="fas fa-check me-2"></i>Add</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fas fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -1,66 +0,0 @@
<?php
/*
* Link tickets already raised to a service - the outage reported before
* anyone said which service it was. The client's tickets from the last year,
* open ones first, not already on the service.
*/
require_once '../../../includes/modal_header.php';
$service = serviceForModal($_GET['id'] ?? 0, 2, true);
$service_id = intval($service['service_id']);
$sql = mysqli_query($mysqli, "SELECT ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_created_at, ticket_resolved_at, ticket_closed_at FROM tickets
WHERE ticket_client_id = $client_id AND ticket_archived_at IS NULL
AND ticket_id NOT IN (SELECT ticket_id FROM service_tickets WHERE service_id = $service_id)
AND (" . TICKET_OPEN_SQL . " OR ticket_created_at > NOW() - INTERVAL 1 YEAR)
ORDER BY " . TICKET_OPEN_SQL . " DESC, ticket_number DESC LIMIT 300");
$candidates = [];
while ($row = mysqli_fetch_assoc($sql)) {
$candidates[] = $row;
}
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-life-ring me-2"></i>Tickets about <strong><?= escapeHtml($service['service_name']) ?></strong></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="service_id" value="<?= $service_id ?>">
<div class="modal-body">
<?php if ($candidates) { ?>
<label class="form-label">Which tickets?</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw fa-life-ring"></i></span>
<select class="form-select select2" name="ticket_ids[]" multiple required data-placeholder="Search by number or subject">
<?php foreach ($candidates as $row) {
$is_open = ticketIsOpen($row); ?>
<option value="<?= intval($row['ticket_id']) ?>" data-icon="fas fa-<?= $is_open ? 'life-ring' : 'check-circle' ?>"
data-description="<?= escapeHtml($row['ticket_prefix'] . $row['ticket_number'] . ' · ' . ($is_open ? 'Open' : 'Closed') . ' · ' . date('M j, Y', strtotime($row['ticket_created_at']))) ?>"
data-keywords="<?= escapeHtml($row['ticket_prefix'] . $row['ticket_number']) ?>"><?= escapeHtml($row['ticket_subject']) ?></option>
<?php } ?>
</select>
</div>
<div class="form-text">Tickets on its assets show on the service already - this is for the rest.</div>
<?php } else { ?>
<div class="itflow-asset-empty py-4">
<i class="fas fa-life-ring fa-2x mb-2"></i>
<div>No other tickets for this client in the last year.</div>
</div>
<?php } ?>
</div>
<div class="modal-footer">
<?php if ($candidates) { ?>
<button type="submit" name="link_service_tickets" class="btn btn-primary text-bold"><i class="fas fa-link me-2"></i>Link</button>
<?php } ?>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -1,67 +0,0 @@
<?php
/*
* Link related tickets (functions/ticket_link.php) - pick the tickets this one is about the same
* thing as, of any client the agent can open. Posts link_tickets (agent/post/ticket_link.php).
*/
require_once '../../../includes/modal_header.php';
enforceUserPermission('module_support', 2);
// The ticket, after the module and client checks - or the modal's error
$row = ticketForModal($_GET['ticket_id'] ?? 0, 2);
$ticket_id = intval($row['ticket_id']);
$reference = escapeHtml(ticketReference($row));
$candidates = ticketLinksReady() ? ticketLinkCandidates($ticket_id) : [];
$related_count = count(ticketRelated($ticket_id));
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fas fa-fw fa-link me-2"></i>Link related tickets <small class="ms-1 opacity-75"><?= $reference ?></small></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="ticket_id" value="<?= $ticket_id ?>">
<div class="modal-body">
<p class="small text-body-secondary">
Tickets about the same thing - one outage at several clients, or a problem that keeps coming back. Each shows the others, and one update or resolve can go to them all.
<?php if ($related_count) { ?>
<strong><?= $reference ?></strong> is related to <?= $related_count ?> already - the ones you pick join them.
<?php } ?>
</p>
<div class="mb-3">
<label class="form-label">Related to <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-life-ring"></i></span>
<select class="form-select select2" name="related_ticket_ids[]" data-placeholder="- Pick tickets -" multiple required>
<?php foreach ($candidates as $candidate) {
$is_open = ticketIsOpen($candidate);
$client = $candidate['client_name'] !== null ? $candidate['client_name'] : 'Internal'; ?>
<option value="<?= intval($candidate['ticket_id']) ?>"<?= selectOptionData([
'icon' => 'fas fa-life-ring',
'description' => $client . ' · ' . ($candidate['ticket_status_name'] ?? '') . ($is_open ? '' : ' - ' . timeAgo($candidate['ticket_closed_at'] ?: $candidate['ticket_resolved_at'])),
'keywords' => $client,
]) ?>><?= escapeHtml(ticketReference($candidate) . ' ' . $candidate['ticket_subject']) ?></option>
<?php } ?>
</select>
</div>
<div class="form-text">Open tickets, and those closed in the last 90 days. Search by number, subject or client.</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="link_tickets" class="btn btn-primary text-bold"><i class="fas fa-link me-2"></i>Link</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -1,76 +0,0 @@
<?php
/*
* Link a service to a ticket - an outage of email, a change to the backups.
* The ticket then shows on the service's page with the tickets on its assets.
*/
require_once '../../../includes/modal_header.php';
enforceUserPermission('module_support', 2);
// The ticket, after the module and client checks - or the modal's error
$row = ticketForModal($_GET['id'] ?? 0, 2, true);
$ticket_id = intval($row['ticket_id']);
$client_id = intval($row['ticket_client_id']);
$reference = escapeHtml($row['ticket_prefix'] . $row['ticket_number']);
if (!$client_id) {
echo json_encode(['error' => 'A ticket with no client has no services to link.']);
exit;
}
$linked = ticketServices($ticket_id);
$sql = mysqli_query($mysqli, "SELECT service_id, service_name, service_description, service_category, service_importance FROM services
WHERE service_client_id = $client_id AND service_archived_at IS NULL
AND service_id NOT IN (SELECT service_id FROM service_tickets WHERE ticket_id = $ticket_id)
ORDER BY FIELD(service_importance, 'High', 'Medium', 'Low'), service_name");
$candidates = [];
while ($candidate = mysqli_fetch_assoc($sql)) {
$candidates[] = $candidate;
}
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fas fa-fw fa-stream me-2"></i>Link a service <small class="ms-1 opacity-75"><?= $reference ?></small></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="ticket_id" value="<?= $ticket_id ?>">
<div class="modal-body">
<?php if ($candidates) { ?>
<label class="form-label">Which service is this ticket about?</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw fa-stream"></i></span>
<select class="form-select select2" name="service_ids[]" multiple required data-placeholder="Pick one or more services">
<?php foreach ($candidates as $candidate) {
$via_asset = isset($linked[intval($candidate['service_id'])]); ?>
<option value="<?= intval($candidate['service_id']) ?>"<?= selectOptionService($candidate) ?>><?= escapeHtml($candidate['service_name']) ?><?= $via_asset ? ' (through its asset)' : '' ?></option>
<?php } ?>
</select>
</div>
<div class="form-text">The ticket shows on the service's page, in its Tickets tab.</div>
<?php } else { ?>
<div class="itflow-asset-empty py-4">
<i class="fas fa-stream fa-2x mb-2"></i>
<div><?= $linked ? 'Every service this client has is already linked.' : 'This client has no services yet.' ?></div>
</div>
<?php } ?>
</div>
<div class="modal-footer">
<?php if ($candidates) { ?>
<button type="submit" name="link_ticket_services" class="btn btn-primary text-bold"><i class="fas fa-link me-2"></i>Link</button>
<?php } ?>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';