diff --git a/client_contact_details.php b/client_contact_details.php index 2685a3a3..95706c34 100644 --- a/client_contact_details.php +++ b/client_contact_details.php @@ -43,6 +43,17 @@ if (isset($_GET['contact_id'])) { $sql_related_assets = mysqli_query($mysqli, "SELECT * FROM assets LEFT JOIN asset_interfaces ON interface_asset_id = asset_id AND interface_primary = 1 WHERE asset_contact_id = $contact_id ORDER BY asset_name DESC"); $asset_count = mysqli_num_rows($sql_related_assets); + // Linked Software Licenses + $sql_linked_software = mysqli_query($mysqli, "SELECT * FROM software_contacts, software + WHERE software_contacts.contact_id = $contact_id + AND software_contacts.software_id = software.software_id + AND software_archived_at IS NULL + ORDER BY software_name ASC" + ); + $software_count = mysqli_num_rows($sql_linked_software); + + $linked_software = array(); + // Related Logins Query 1 to 1 relationship $sql_related_logins = mysqli_query($mysqli, "SELECT * FROM logins LEFT JOIN login_tags ON login_tags.login_id = logins.login_id @@ -53,18 +64,6 @@ if (isset($_GET['contact_id'])) { "); $login_count = mysqli_num_rows($sql_related_logins); - // Related Software Query - many to many relationship - //$sql_related_software = mysqli_query($mysqli, "SELECT * FROM software, software_contacts WHERE software.software_id = software_contacts.software_id AND software_contacts.contact_id = $contact_id ORDER BY software.software_id DESC"); - $sql_related_software = mysqli_query( - $mysqli, - "SELECT * FROM software_contacts - LEFT JOIN software ON software_contacts.software_id = software.software_id - WHERE software_contacts.contact_id = $contact_id - ORDER BY software.software_id DESC" - ); - - $software_count = mysqli_num_rows($sql_related_software); - // Related Tickets Query - 1 to 1 relationship $sql_related_tickets = mysqli_query($mysqli, "SELECT * FROM tickets LEFT JOIN users ON ticket_assigned_to = user_id @@ -242,7 +241,7 @@ if (isset($_GET['contact_id'])) { Asset - + License @@ -545,8 +544,13 @@ if (isset($_GET['contact_id'])) {
"> -
-

Related Licenses

+
+

Related Licenses

+
+ +
@@ -557,12 +561,13 @@ if (isset($_GET['contact_id'])) { Type License Type Seats + Action - $software_version"; ?> + + + + + +
diff --git a/post/user/contact.php b/post/user/contact.php index 6f3cdfcc..f1c4ce2f 100644 --- a/post/user/contact.php +++ b/post/user/contact.php @@ -938,6 +938,65 @@ if (isset($_GET['unlink_asset_from_contact'])) { } +if (isset($_POST['link_software_to_contact'])) { + + enforceUserPermission('module_support', 2); + + $software_id = intval($_POST['software_id']); + $contact_id = intval($_POST['contact_id']); + + // Get software Name and Client ID for logging + $sql_software = mysqli_query($mysqli,"SELECT software_name, software_client_id FROM software WHERE software_id = $software_id"); + $row = mysqli_fetch_array($sql_software); + $software_name = sanitizeInput($row['software_name']); + $client_id = intval($row['software_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 software_contacts SET contact_id = $contact_id, software_id = $software_id"); + + // Logging + logAction("Software", "Link", "$session_name added software license $software_name to contact $contact_name", $client_id, $software_id); + + $_SESSION['alert_message'] = "Software $software_name licensed for contact $contact_name"; + + header("Location: " . $_SERVER["HTTP_REFERER"]); + +} + +if (isset($_GET['unlink_software_from_contact'])) { + + enforceUserPermission('module_support', 2); + + $contact_id = intval($_GET['contact_id']); + $software_id = intval($_GET['software_id']); + + // Get software Name and Client ID for logging + $sql_software = mysqli_query($mysqli,"SELECT software_name, software_client_id FROM software WHERE software_id = $software_id"); + $row = mysqli_fetch_array($sql_software); + $software_name = sanitizeInput($row['software_name']); + $client_id = intval($row['software_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 software_contacts WHERE contact_id = $contact_id AND software_id = $software_id"); + + //Logging + logAction("software", "Unlink", "$session_name removed software license $software_name from contact $contact_name", $client_id, $software_id); + + $_SESSION['alert_type'] = "error"; + $_SESSION['alert_message'] = "Removed Software License $software_name for Contact $contact_name"; + + header("Location: " . $_SERVER["HTTP_REFERER"]); + +} + if (isset($_POST['link_contact_to_credential'])) { enforceUserPermission('module_support', 2);