mirror of https://github.com/itflow-org/itflow
Added Linking and unlinking services in contact details
This commit is contained in:
parent
5e8a6bfcd6
commit
bbed55a8ff
|
|
@ -98,6 +98,16 @@ if (isset($_GET['contact_id'])) {
|
|||
$sql_related_notes = mysqli_query($mysqli, "SELECT * FROM contact_notes LEFT JOIN users ON contact_note_created_by = user_id WHERE contact_note_contact_id = $contact_id AND contact_note_archived_at IS NULL ORDER BY contact_note_created_at DESC");
|
||||
$note_count = mysqli_num_rows($sql_related_notes);
|
||||
|
||||
// Linked Services
|
||||
$sql_linked_services = mysqli_query($mysqli, "SELECT * FROM service_contacts, services
|
||||
WHERE service_contacts.contact_id = $contact_id
|
||||
AND service_contacts.service_id = services.service_id
|
||||
ORDER BY service_name ASC"
|
||||
);
|
||||
$service_count = mysqli_num_rows($sql_linked_services);
|
||||
|
||||
$linked_services = array();
|
||||
|
||||
// Linked Documents
|
||||
$sql_linked_documents = mysqli_query($mysqli, "SELECT * FROM contact_documents, documents
|
||||
LEFT JOIN users ON document_created_by = user_id
|
||||
|
|
@ -240,7 +250,7 @@ if (isset($_GET['contact_id'])) {
|
|||
<i class="fa fa-fw fa-key mr-2"></i>Credential
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-dark" href="#" data-toggle="modal" data-target="#createContactNoteModal<?php echo $contact_id; ?>">
|
||||
<a class="dropdown-item text-dark" href="#" data-toggle="modal" data-target="#linkServiceModal">
|
||||
<i class="fa fa-fw fa-stream mr-2"></i>Service
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
|
|
@ -696,6 +706,64 @@ if (isset($_GET['contact_id'])) {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card card-dark <?php if ($service_count == 0) { echo "d-none"; } ?>">
|
||||
<div class="card-header py-2">
|
||||
<h3 class="card-title mt-2"><i class="fa fa-fw fa-stream mr-2"></i>Linked Services</h3>
|
||||
<div class="card-tools">
|
||||
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#linkServiceModal">
|
||||
<i class="fas fa-link mr-2"></i>Link Service
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive-sm">
|
||||
<table class="table table-striped table-borderless table-hover dataTables" style="width:100%">
|
||||
<thead class="text-dark">
|
||||
<tr>
|
||||
<th>Service</th>
|
||||
<th>Category</th>
|
||||
<th>Importance</th>
|
||||
<th class="text-center">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
|
||||
while ($row = mysqli_fetch_array($sql_linked_services)) {
|
||||
$service_id = intval($row['service_id']);
|
||||
$service_name = nullable_htmlentities($row['service_name']);
|
||||
$service_description = nullable_htmlentities($row['service_description']);
|
||||
$service_category = nullable_htmlentities($row['service_category']);
|
||||
$service_importance = nullable_htmlentities($row['service_importance']);
|
||||
|
||||
$linked_services[] = $service_id;
|
||||
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<div><?php echo $service_name; ?></div>
|
||||
<div class="text-secondary"><?php echo $service_description; ?></div>
|
||||
</td>
|
||||
<td><?php echo $service_category; ?></td>
|
||||
<td><?php echo $service_importance; ?></td>
|
||||
<td class="text-center">
|
||||
<a href="post.php?unlink_service_from_contact&contact_id=<?php echo $contact_id; ?>&service_id=<?php echo $service_id; ?>" class="btn btn-secondary btn-sm" title="Unlink"><i class="fas fa-fw fa-unlink"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card card-dark <?php if ($document_count == 0) { echo "d-none"; } ?>">
|
||||
<div class="card-header py-2">
|
||||
<h3 class="card-title mt-2"><i class="fa fa-fw fa-folder mr-2"></i>Linked Documents</h3>
|
||||
|
|
@ -963,6 +1031,7 @@ require_once "client_contact_create_note_modal.php";
|
|||
require_once "ticket_add_modal.php";
|
||||
require_once "client_contact_link_asset_modal.php";
|
||||
require_once "client_contact_link_credential_modal.php";
|
||||
require_once "client_contact_link_service_modal.php";
|
||||
require_once "client_contact_link_document_modal.php";
|
||||
require_once "client_contact_link_file_modal.php";
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
<div class="modal" id="linkServiceModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content bg-dark">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-stream mr-2"></i>Link Service to <strong><?php echo $contact_name; ?></strong></h5>
|
||||
<button type="button" class="close text-white" data-dismiss="modal">
|
||||
<span>×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="contact_id" value="<?php echo $contact_id; ?>">
|
||||
<div class="modal-body bg-white">
|
||||
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-stream"></i></span>
|
||||
</div>
|
||||
<select class="form-control select2" name="service_id">
|
||||
<option value="">- Select a Service -</option>
|
||||
<?php
|
||||
// Check if there are any associated services
|
||||
if (!empty($linked_services)) {
|
||||
$excluded_service_ids = implode(",", $linked_services);
|
||||
$exclude_condition = "AND service_id NOT IN ($excluded_service_ids)";
|
||||
} else {
|
||||
$exclude_condition = ""; // No condition if there are no displayed services
|
||||
}
|
||||
|
||||
$sql_services_select = mysqli_query($mysqli, "SELECT * FROM services
|
||||
WHERE service_client_id = $client_id
|
||||
$exclude_condition
|
||||
ORDER BY service_name ASC"
|
||||
);
|
||||
while ($row = mysqli_fetch_array($sql_services_select)) {
|
||||
$service_id = intval($row['service_id']);
|
||||
$service_name = nullable_htmlentities($row['service_name']);
|
||||
|
||||
?>
|
||||
<option value="<?php echo $service_id ?>"><?php echo $service_name; ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer bg-white">
|
||||
<button type="submit" name="link_service_to_contact" class="btn btn-primary text-bold"><i class="fa fa-check mr-2"></i>Link</button>
|
||||
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fa fa-times mr-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -997,6 +997,65 @@ if (isset($_GET['unlink_credential_from_contact'])) {
|
|||
|
||||
}
|
||||
|
||||
if (isset($_POST['link_service_to_contact'])) {
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$service_id = intval($_POST['service_id']);
|
||||
$contact_id = intval($_POST['contact_id']);
|
||||
|
||||
// Get service Name and Client ID for logging
|
||||
$sql_service = mysqli_query($mysqli,"SELECT service_name, service_client_id FROM services WHERE service_id = $service_id");
|
||||
$row = mysqli_fetch_array($sql_service);
|
||||
$service_name = sanitizeInput($row['service_name']);
|
||||
$client_id = intval($row['service_client_id']);
|
||||
|
||||
// Get Contact Name for logging
|
||||
$sql_contact = mysqli_query($mysqli,"SELECT contact_name FROM contacts WHERE contact_id = $contact_id");
|
||||
$row = mysqli_fetch_array($sql_contact);
|
||||
$contact_name = sanitizeInput($row['contact_name']);
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO service_contacts SET contact_id = $contact_id, service_id = $service_id");
|
||||
|
||||
// Logging
|
||||
logAction("Service", "Link", "$session_name linked contact $contact_name to service $service_name", $client_id, $service_id);
|
||||
|
||||
$_SESSION['alert_message'] = "service <strong>$service_name</strong> linked with contact <strong>$contact_name</strong>";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['unlink_service_from_contact'])) {
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$contact_id = intval($_GET['contact_id']);
|
||||
$service_id = intval($_GET['service_id']);
|
||||
|
||||
// Get service Name and Client ID for logging
|
||||
$sql_service = mysqli_query($mysqli,"SELECT service_name, service_client_id FROM services WHERE service_id = $service_id");
|
||||
$row = mysqli_fetch_array($sql_service);
|
||||
$service_name = sanitizeInput($row['service_name']);
|
||||
$client_id = intval($row['service_client_id']);
|
||||
|
||||
// Get Contact Name for logging
|
||||
$sql_contact = mysqli_query($mysqli,"SELECT contact_name FROM contacts WHERE contact_id = $contact_id");
|
||||
$row = mysqli_fetch_array($sql_contact);
|
||||
$contact_name = sanitizeInput($row['contact_name']);
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM service_contacts WHERE contact_id = $contact_id AND service_id = $service_id");
|
||||
|
||||
//Logging
|
||||
logAction("service", "Unlink", "$session_name unlinked contact $contact_name from service $service_name", $client_id, $service_id);
|
||||
|
||||
$_SESSION['alert_type'] = "error";
|
||||
$_SESSION['alert_message'] = "Contact <strong>$contact_name</strong> unlinked from service <strong>$service_name</strong>";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['link_contact_to_file'])) {
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
|
@ -1019,7 +1078,7 @@ if (isset($_POST['link_contact_to_file'])) {
|
|||
mysqli_query($mysqli,"INSERT INTO contact_files SET contact_id = $contact_id, file_id = $file_id");
|
||||
|
||||
// Logging
|
||||
logAction("Document", "Link", "$session_name linked contact $contact_name to document $file_name", $client_id, $file_id);
|
||||
logAction("File", "Link", "$session_name linked contact $contact_name to file $file_name", $client_id, $file_id);
|
||||
|
||||
$_SESSION['alert_message'] = "Contact <strong>$contact_name</strong> linked with File <strong>$file_name</strong>";
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue