@@ -210,9 +209,9 @@ if ($session_contact_primary == 1 || $session_contact_is_billing_contact) { ?>
-
diff --git a/client/post.php b/client/post.php
index 03ec1773..59381157 100644
--- a/client/post.php
+++ b/client/post.php
@@ -15,6 +15,7 @@ if (isset($_POST['add_ticket'])) {
$subject = sanitizeInput($_POST['subject']);
$details = mysqli_real_escape_string($mysqli, ($_POST['details']));
$category = intval($_POST['category']);
+ $asset = intval($_POST['asset']);
// Get settings from get_settings.php
$config_ticket_prefix = sanitizeInput($config_ticket_prefix);
@@ -38,7 +39,7 @@ if (isset($_POST['add_ticket'])) {
$new_config_ticket_next_number = $config_ticket_next_number + 1;
mysqli_query($mysqli, "UPDATE settings SET config_ticket_next_number = $new_config_ticket_next_number WHERE company_id = 1");
- mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_source = 'Portal', ticket_category = $category, ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_status = 1, ticket_billable = $config_ticket_default_billable, ticket_created_by = $session_user_id, ticket_contact_id = $session_contact_id, ticket_url_key = '$url_key', ticket_client_id = $session_client_id");
+ mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_source = 'Portal', ticket_category = $category, ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_status = 1, ticket_billable = $config_ticket_default_billable, ticket_created_by = $session_user_id, ticket_contact_id = $session_contact_id, ticket_asset_id = $asset, ticket_url_key = '$url_key', ticket_client_id = $session_client_id");
$ticket_id = mysqli_insert_id($mysqli);
// Notify agent DL of the new ticket, if populated with a valid email
diff --git a/client/ticket_add.php b/client/ticket_add.php
index ceffca1c..6037f5b1 100644
--- a/client/ticket_add.php
+++ b/client/ticket_add.php
@@ -6,6 +6,9 @@
require_once 'includes/inc_all.php';
+// Allow clients to select a related asset when raising a ticket
+$sql_assets = mysqli_query($mysqli, "SELECT asset_id, asset_name, asset_type FROM assets WHERE asset_contact_id = $session_contact_id AND asset_client_id = $session_client_id AND asset_archived_at IS NULL ORDER BY asset_name ASC");
+
?>
@@ -75,6 +78,30 @@ require_once 'includes/inc_all.php';
+ 0) { ?>
+
+
diff --git a/js/recurring_tickets_add_modal.js b/js/recurring_tickets_add_modal.js
deleted file mode 100644
index 433fb5fe..00000000
--- a/js/recurring_tickets_add_modal.js
+++ /dev/null
@@ -1,63 +0,0 @@
-// Client selected listener
-// We seem to have to use jQuery to listen for events, as the client input is a select2 component?
-
-const clientSelectDropdown = document.getElementById("changeClientSelect"); // Define client selector
-
-// // If the client selector is disabled, we must be on client_recurring_tickets.php instead. Trigger the contact list update.
-if (clientSelectDropdown.disabled) {
-
- let client_id = $(clientSelectDropdown).find(':selected').val();
-
- // Update the contacts dropdown list
- populateContactsDropdown(client_id);
-}
-
-// Listener for client selection. Populate contact select when a client is selected
-$(clientSelectDropdown).on('select2:select', function (e) {
- let client_id = $(this).find(':selected').val();
-
- // Update the contacts dropdown list
- populateContactsDropdown(client_id);
-
- // TODO: Update the assets dropdown list
-
-});
-
-// Populate client contact function (after a client is selected)
-function populateContactsDropdown(client_id) {
- // Send a GET request to ajax.php as ajax.php?get_client_contacts=true&client_id=NUM
- jQuery.get(
- "ajax.php",
- {get_client_contacts: 'true', client_id: client_id},
- function(data) {
-
- // If we get a response from ajax.php, parse it as JSON
- const response = JSON.parse(data);
-
- // Access the data for contacts (multiple)
- const contacts = response.contacts;
-
- // Contacts dropdown
- const contactSelectDropdown = document.getElementById("contactSelect");
-
- // Clear Category dropdown
- let i, L = contactSelectDropdown.options.length - 1;
- for (i = L; i >= 0; i--) {
- contactSelectDropdown.remove(i);
- }
- contactSelectDropdown[contactSelectDropdown.length] = new Option('- Contact -', '0');
-
- // Populate dropdown
- contacts.forEach(contact => {
- var appendText = "";
- if (contact.contact_primary == "1") {
- appendText = " (Primary)";
- } else if (contact.contact_technical == "1") {
- appendText = " (Technical)";
- }
- contactSelectDropdown[contactSelectDropdown.length] = new Option(contact.contact_name + appendText, contact.contact_id);
- });
-
- }
- );
-}
diff --git a/js/tickets_add_modal.js b/js/tickets_add_modal.js
new file mode 100644
index 00000000..154e29f3
--- /dev/null
+++ b/js/tickets_add_modal.js
@@ -0,0 +1,176 @@
+// Used to populate dynamic content in recurring_ticket_add_modal and ticket_add_modal_v2 based on selected client
+
+// Client selected listener
+// We seem to have to use jQuery to listen for events, as the client input is a select2 component?
+
+const clientSelectDropdown = document.getElementById("changeClientSelect"); // Define client selector
+
+// // If the client selector is disabled, we must be on a client-specific page instead. Trigger the lists to update.
+if (clientSelectDropdown.disabled) {
+
+ let client_id = $(clientSelectDropdown).find(':selected').val();
+
+ populateLists(client_id);
+}
+
+// Listener for client selection. Populate select lists when a client is selected
+$(clientSelectDropdown).on('select2:select', function (e) {
+ let client_id = $(this).find(':selected').val();
+
+ // Update the contacts dropdown list
+ populateLists(client_id);
+
+});
+
+// Populates dropdowns with dynamic content based on the client ID
+// Called the client select dropdown is used or if the client select is disabled
+function populateLists(client_id) {
+
+ populateContactsDropdown(client_id);
+
+ populateAssetsDropdown(client_id);
+
+ populateLocationsDropdown(client_id);
+
+ populateVendorsDropdown(client_id);
+}
+
+// Populate client contacts
+function populateContactsDropdown(client_id) {
+ // Send a GET request to ajax.php as ajax.php?get_client_contacts=true&client_id=NUM
+ jQuery.get(
+ "ajax.php",
+ {get_client_contacts: 'true', client_id: client_id},
+ function(data) {
+
+ // If we get a response from ajax.php, parse it as JSON
+ const response = JSON.parse(data);
+
+ // Access the data for contacts (multiple)
+ const contacts = response.contacts;
+
+ // Contacts dropdown
+ const contactSelectDropdown = document.getElementById("contactSelect");
+
+ // Clear dropdown
+ let i, L = contactSelectDropdown.options.length - 1;
+ for (i = L; i >= 0; i--) {
+ contactSelectDropdown.remove(i);
+ }
+ contactSelectDropdown[contactSelectDropdown.length] = new Option('- Contact -', '0');
+
+ // Populate dropdown
+ contacts.forEach(contact => {
+ var appendText = "";
+ if (contact.contact_primary == "1") {
+ appendText = " (Primary)";
+ } else if (contact.contact_technical == "1") {
+ appendText = " (Technical)";
+ }
+ contactSelectDropdown[contactSelectDropdown.length] = new Option(contact.contact_name + appendText, contact.contact_id);
+ });
+
+ }
+ );
+}
+
+// Populate client assets
+function populateAssetsDropdown(client_id) {
+ jQuery.get(
+ "ajax.php",
+ {get_client_assets: 'true', client_id: client_id},
+ function(data) {
+
+ // If we get a response from ajax.php, parse it as JSON
+ const response = JSON.parse(data);
+
+ // Access the data for assets (multiple)
+ const assets = response.assets;
+
+ // Assets dropdown
+ const assetSelectDropdown = document.getElementById("assetSelect");
+
+ // Clear dropdown
+ let i, L = assetSelectDropdown.options.length - 1;
+ for (i = L; i >= 0; i--) {
+ assetSelectDropdown.remove(i);
+ }
+ assetSelectDropdown[assetSelectDropdown.length] = new Option('- Asset -', '0');
+
+ // Populate dropdown with asset name (and contact, if set)
+ assets.forEach(asset => {
+ let displayText = asset.asset_name;
+ if (asset.contact_name !== null) {
+ displayText = asset.asset_name + " - " + asset.contact_name;
+ }
+
+ assetSelectDropdown[assetSelectDropdown.length] = new Option(displayText, asset.asset_id);
+ });
+
+ }
+ );
+}
+
+// Populate client locations
+function populateLocationsDropdown(client_id) {
+ jQuery.get(
+ "ajax.php",
+ {get_client_locations: 'true', client_id: client_id},
+ function(data) {
+
+ // If we get a response from ajax.php, parse it as JSON
+ const response = JSON.parse(data);
+
+ // Access the data for locations (multiple)
+ const locations = response.locations;
+
+ // Locations dropdown
+ const locationSelectDropdown = document.getElementById("locationSelect");
+
+ // Clear dropdown
+ let i, L = locationSelectDropdown.options.length - 1;
+ for (i = L; i >= 0; i--) {
+ locationSelectDropdown.remove(i);
+ }
+ locationSelectDropdown[locationSelectDropdown.length] = new Option('- Location -', '0');
+
+ // Populate dropdown
+ locations.forEach(location => {
+ locationSelectDropdown[locationSelectDropdown.length] = new Option(location.location_name, location.location_id);
+ });
+
+ }
+ );
+}
+
+// Populate client vendors
+function populateVendorsDropdown(client_id) {
+ jQuery.get(
+ "ajax.php",
+ {get_client_vendors: 'true', client_id: client_id},
+ function(data) {
+
+ // If we get a response from ajax.php, parse it as JSON
+ const response = JSON.parse(data);
+
+ // Access the data for locations (multiple)
+ const vendors = response.vendors;
+
+ // Locations dropdown
+ const vendorSelectDropdown = document.getElementById("vendorSelect");
+
+ // Clear dropdown
+ let i, L = vendorSelectDropdown.options.length - 1;
+ for (i = L; i >= 0; i--) {
+ vendorSelectDropdown.remove(i);
+ }
+ vendorSelectDropdown[vendorSelectDropdown.length] = new Option('- Vendor -', '0');
+
+ // Populate dropdown
+ vendors.forEach(vendor => {
+ vendorSelectDropdown[vendorSelectDropdown.length] = new Option(vendor.vendor_name, vendor.vendor_id);
+ });
+
+ }
+ );
+}
diff --git a/modals/recurring_ticket_add_modal.php b/modals/recurring_ticket_add_modal.php
index 891c978c..73117579 100644
--- a/modals/recurring_ticket_add_modal.php
+++ b/modals/recurring_ticket_add_modal.php
@@ -51,7 +51,7 @@