diff --git a/ajax.php b/ajax.php
index 8875fb597..41467ac59 100644
--- a/ajax.php
+++ b/ajax.php
@@ -359,6 +359,7 @@
$client_id = intval($_GET['client_id']);
$ticket_id = intval($_GET['ticket_id']);
+ // Get all contacts, to allow tickets to be raised under a specific contact
$contact_sql = mysqli_query($mysqli, "SELECT contact_id, contact_name FROM contacts
WHERE contact_client_id = $client_id
AND contact_archived_at IS NULL
@@ -368,7 +369,7 @@
$response['contacts'][] = $row;
}
-
+ // Get ticket details
$ticket_sql = mysqli_query($mysqli, "SELECT * FROM scheduled_tickets
WHERE scheduled_ticket_id = $ticket_id
AND scheduled_ticket_client_id = $client_id LIMIT 1");
@@ -376,11 +377,26 @@
$response['ticket'][] = $row;
}
+ // Get assets
$asset_sql = mysqli_query($mysqli, "SELECT asset_id, asset_name FROM assets WHERE asset_client_id = $client_id AND asset_archived_at IS NULL");
while ($row = mysqli_fetch_array($asset_sql)) {
$response['assets'][] = $row;
}
+ // Get technicians to auto assign the ticket to
+ $sql_agents = mysqli_query(
+ $mysqli,
+ "SELECT users.user_id, user_name FROM users
+ LEFT JOIN user_settings on users.user_id = user_settings.user_id
+ WHERE user_role > 1
+ AND user_status = 1
+ AND user_archived_at IS NULL
+ ORDER BY user_name ASC"
+ );
+ while ($row = mysqli_fetch_array($sql_agents)) {
+ $response['agents'][] = $row;
+ }
+
echo json_encode($response);
}
@@ -448,9 +464,9 @@
$contact_sql = mysqli_query(
$mysqli,
- "SELECT contact_id, contact_name FROM contacts
+ "SELECT contact_id, contact_name, contact_primary, contact_important, contact_technical FROM contacts
WHERE contacts.contact_archived_at IS NULL AND contact_client_id = $client_id
- ORDER BY contact_important DESC, contact_name"
+ ORDER BY contact_primary DESC, contact_technical DESC, contact_important DESC, contact_name"
);
while ($row = mysqli_fetch_array($contact_sql)) {
diff --git a/cron.php b/cron.php
index 06decb6c7..f0290f0e0 100644
--- a/cron.php
+++ b/cron.php
@@ -249,10 +249,16 @@
$priority = sanitizeInput($row['scheduled_ticket_priority']);
$frequency = sanitizeInput(strtolower($row['scheduled_ticket_frequency']));
$created_id = intval($row['scheduled_ticket_created_by']);
+ $assigned_id = intval($row['scheduled_ticket_assigned_to']);
$client_id = intval($row['scheduled_ticket_client_id']);
$contact_id = intval($row['scheduled_ticket_contact_id']);
$asset_id = intval($row['scheduled_ticket_asset_id']);
+ $ticket_status = 'New'; // Default
+ if ($assigned_id > 0) {
+ $ticket_status = 'Open'; // Set to open if we've auto-assigned an agent
+ }
+
// Assign this new ticket the next ticket number
$ticket_number_sql = mysqli_fetch_array(mysqli_query($mysqli, "SELECT config_ticket_next_number FROM settings WHERE company_id = 1"));
$ticket_number = intval($ticket_number_sql['config_ticket_next_number']);
@@ -262,7 +268,7 @@
mysqli_query($mysqli, "UPDATE settings SET config_ticket_next_number = $new_config_ticket_next_number WHERE company_id = 1");
// Raise the ticket
- mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_status = 'New', ticket_created_by = $created_id, ticket_contact_id = $contact_id, ticket_client_id = $client_id, ticket_asset_id = $asset_id");
+ mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_status = '$ticket_status', ticket_created_by = $created_id, ticket_assigned_to = $assigned_id, ticket_contact_id = $contact_id, ticket_client_id = $client_id, ticket_asset_id = $asset_id");
$id = mysqli_insert_id($mysqli);
// Logging
@@ -316,7 +322,7 @@
if (filter_var($config_ticket_new_ticket_notification_email, FILTER_VALIDATE_EMAIL)) {
$email_subject = "ITFlow - New Recurring Ticket - $client_name: $ticket_subject";
- $email_body = "Hello,
This is a notification that a recurring scheduled ticket has been raised in ITFlow.
Ticket: $ticket_prefix$ticket_number
Client: $client_name
Priority: $priority
Link: https://$config_base_url/ticket.php?ticket_id=$id
--------------------------------
$ticket_subject
$ticket_details";
+ $email_body = "Hello,
This is a notification that a recurring (scheduled) ticket has been raised in ITFlow.
Ticket: $ticket_prefix$ticket_number
Client: $client_name
Priority: $priority
Link: https://$config_base_url/ticket.php?ticket_id=$id
--------------------------------
$ticket_subject
$ticket_details";
$email = [
'from' => $config_ticket_from_email,
diff --git a/database_updates.php b/database_updates.php
index 74f606911..61572a66b 100644
--- a/database_updates.php
+++ b/database_updates.php
@@ -1560,7 +1560,7 @@
}
-
+
if (CURRENT_DATABASE_VERSION == '1.0.2') {
//Insert queries here required to update to DB version 1.0.3
mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_stripe_expense_vendor` INT(11) NOT NULL DEFAULT 0 AFTER `config_stripe_account`");
@@ -1610,14 +1610,14 @@
if (CURRENT_DATABASE_VERSION == '1.0.6') {
// Insert queries here required to update to DB version 1.0.7
mysqli_query($mysqli, "CREATE TABLE `remember_tokens` (`remember_token_id` int(11) NOT NULL AUTO_INCREMENT,`remember_token_token` varchar(255) NOT NULL,`remember_token_user_id` int(11) NOT NULL,`remember_token_created_at` datetime NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`remember_token_id`))");
-
+
// Then, update the database to the next sequential version
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.0.7'");
}
if (CURRENT_DATABASE_VERSION == '1.0.7') {
mysqli_query($mysqli, "ALTER TABLE `user_settings` DROP `user_config_remember_me_token`");
-
+
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.0.8'");
}
@@ -1626,13 +1626,13 @@
mysqli_query($mysqli, "ALTER TABLE `assets` DROP `asset_login_id`");
// Dropped this unused Table as we don't need many to many relationship between assets and logins
mysqli_query($mysqli, "DROP TABLE asset_logins");
-
+
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.0.9'");
}
if (CURRENT_DATABASE_VERSION == '1.0.9') {
mysqli_query($mysqli, "ALTER TABLE `transfers` ADD `transfer_method` VARCHAR(200) DEFAULT NULL AFTER `transfer_id`");
-
+
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.1.0'");
}
@@ -1647,10 +1647,16 @@
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.1.1'");
}
- // if (CURRENT_DATABASE_VERSION == '1.1.1') {
- // // Insert queries here required to update to DB version 1.1.2
+ if (CURRENT_DATABASE_VERSION == '1.1.1') {
+ mysqli_query($mysqli, "ALTER TABLE `scheduled_tickets` ADD `scheduled_ticket_assigned_to` INT(11) NOT NULL DEFAULT '0' AFTER `scheduled_ticket_created_by`");
+
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.1.2'");
+ }
+
+ // if (CURRENT_DATABASE_VERSION == '1.1.2') {
+ // // Insert queries here required to update to DB version 1.1.3
// // Then, update the database to the next sequential version
- // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.1.2'");
+ // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.1.3'");
// }
} else {
diff --git a/database_version.php b/database_version.php
index 04a479379..7a9af70dd 100644
--- a/database_version.php
+++ b/database_version.php
@@ -5,5 +5,5 @@
* It is used in conjunction with database_updates.php
*/
-DEFINE("LATEST_DATABASE_VERSION", "1.1.1");
+DEFINE("LATEST_DATABASE_VERSION", "1.1.2");
diff --git a/db.sql b/db.sql
index 4f1d619fe..f401f2650 100644
--- a/db.sql
+++ b/db.sql
@@ -1090,6 +1090,7 @@ CREATE TABLE `scheduled_tickets` (
`scheduled_ticket_created_at` datetime NOT NULL DEFAULT current_timestamp(),
`scheduled_ticket_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(),
`scheduled_ticket_created_by` int(11) NOT NULL DEFAULT 0,
+ `scheduled_ticket_assigned_to` int(11) NOT NULL DEFAULT 0,
`scheduled_ticket_client_id` int(11) NOT NULL DEFAULT 0,
`scheduled_ticket_contact_id` int(11) NOT NULL DEFAULT 0,
`scheduled_ticket_asset_id` int(11) NOT NULL DEFAULT 0,
diff --git a/js/recurring_tickets_add_modal.js b/js/recurring_tickets_add_modal.js
new file mode 100644
index 000000000..1d4d75a07
--- /dev/null
+++ b/js/recurring_tickets_add_modal.js
@@ -0,0 +1,64 @@
+// 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/recurring_tickets_edit_modal.js b/js/recurring_tickets_edit_modal.js
index 07de7c6b9..2ce3e2c08 100644
--- a/js/recurring_tickets_edit_modal.js
+++ b/js/recurring_tickets_edit_modal.js
@@ -13,6 +13,7 @@ function populateRecurringTicketEditModal(client_id, ticket_id) {
const contacts = response.contacts;
const ticket = response.ticket[0];
const assets = response.assets;
+ const agents = response.agents;
// Populate the scheduled ticket modal fields
document.getElementById("editHeader").innerText = " Edit Recurring ticket: " + ticket.scheduled_ticket_subject;
@@ -80,6 +81,29 @@ function populateRecurringTicketEditModal(client_id, ticket_id) {
assetDropdown[assetDropdown.length] = new Option(asset.asset_name, asset.asset_id);
}
});
+
+
+ // Agent dropdown
+ var agentDropdown = document.getElementById("editTicketAgent");
+
+ // Clear agent dropdown
+ var i, L = agentDropdown.options.length -1;
+ for(i = L; i >= 0; i--) {
+ agentDropdown.remove(i);
+ }
+ agentDropdown[agentDropdown.length] = new Option('- Agent -', '0');
+
+
+ // Populate dropdown
+ agents.forEach(agent => {
+ if(parseInt(agent.user_id) == parseInt(ticket.scheduled_ticket_assigned_to)){
+ // Selected agent
+ agentDropdown[agentDropdown.length] = new Option(agent.user_name, agent.user_id, true, true);
+ }
+ else{
+ agentDropdown[agentDropdown.length] = new Option(agent.user_name, agent.user_id);
+ }
+ });
}
);
}
diff --git a/post/recurring_ticket_model.php b/post/recurring_ticket_model.php
index 88a445941..ae42ccb96 100644
--- a/post/recurring_ticket_model.php
+++ b/post/recurring_ticket_model.php
@@ -15,3 +15,8 @@
if (isset($_POST['contact'])) {
$contact_id = intval($_POST['contact']);
}
+
+$assigned_to = "0";
+if (isset($_POST['assigned_to'])) {
+ $assigned_to = intval($_POST['assigned_to']);
+}
diff --git a/post/ticket.php b/post/ticket.php
index d0cdd1834..e24168bf8 100644
--- a/post/ticket.php
+++ b/post/ticket.php
@@ -1318,7 +1318,7 @@
exit;
}
-if (isset($_POST['add_scheduled_ticket']) || isset($_POST['add_recurring_ticket'])) {
+if (isset($_POST['add_recurring_ticket'])) {
validateTechRole();
@@ -1334,7 +1334,7 @@
}
// Add scheduled ticket
- mysqli_query($mysqli, "INSERT INTO scheduled_tickets SET scheduled_ticket_subject = '$subject', scheduled_ticket_details = '$details', scheduled_ticket_priority = '$priority', scheduled_ticket_frequency = '$frequency', scheduled_ticket_start_date = '$start_date', scheduled_ticket_next_run = '$start_date', scheduled_ticket_created_by = $session_user_id, scheduled_ticket_client_id = $client_id, scheduled_ticket_contact_id = $contact_id, scheduled_ticket_asset_id = $asset_id");
+ mysqli_query($mysqli, "INSERT INTO scheduled_tickets SET scheduled_ticket_subject = '$subject', scheduled_ticket_details = '$details', scheduled_ticket_priority = '$priority', scheduled_ticket_frequency = '$frequency', scheduled_ticket_start_date = '$start_date', scheduled_ticket_next_run = '$start_date', scheduled_ticket_assigned_to = $assigned_to, scheduled_ticket_created_by = $session_user_id, scheduled_ticket_client_id = $client_id, scheduled_ticket_contact_id = $contact_id, scheduled_ticket_asset_id = $asset_id");
$scheduled_ticket_id = mysqli_insert_id($mysqli);
@@ -1346,7 +1346,7 @@
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
-if (isset($_POST['edit_scheduled_ticket']) || isset($_POST['edit_recurring_ticket'])) {
+if (isset($_POST['edit_recurring_ticket'])) {
validateTechRole();
@@ -1363,7 +1363,7 @@
}
// Edit scheduled ticket
- mysqli_query($mysqli, "UPDATE scheduled_tickets SET scheduled_ticket_subject = '$subject', scheduled_ticket_details = '$details', scheduled_ticket_priority = '$priority', scheduled_ticket_frequency = '$frequency', scheduled_ticket_next_run = '$next_run_date', scheduled_ticket_asset_id = $asset_id, scheduled_ticket_contact_id = $contact_id WHERE scheduled_ticket_id = $scheduled_ticket_id");
+ mysqli_query($mysqli, "UPDATE scheduled_tickets SET scheduled_ticket_subject = '$subject', scheduled_ticket_details = '$details', scheduled_ticket_priority = '$priority', scheduled_ticket_frequency = '$frequency', scheduled_ticket_next_run = '$next_run_date', scheduled_ticket_assigned_to = $assigned_to, scheduled_ticket_asset_id = $asset_id, scheduled_ticket_contact_id = $contact_id WHERE scheduled_ticket_id = $scheduled_ticket_id");
// Logging
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Recurring Ticket', log_action = 'Modify', log_description = '$session_name modified recurring ticket for $subject - $frequency', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $scheduled_ticket_id");
diff --git a/post/user.php b/post/user.php
index 0b900cfbd..36f870ef0 100644
--- a/post/user.php
+++ b/post/user.php
@@ -207,6 +207,10 @@
mysqli_query($mysqli, "UPDATE users SET user_status = 0 WHERE user_id = $user_id");
+ // Un-assign tickets
+ mysqli_query($mysqli, "UPDATE tickets SET ticket_assigned_to = 0 WHERE ticket_assigned_to = $user_id AND ticket_closed_at IS NULL");
+ mysqli_query($mysqli, "UPDATE scheduled_tickets SET scheduled_ticket_assigned_to = 0 WHERE scheduled_ticket_assigned_to = $user_id");
+
//Logging
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'User', log_action = 'Modify', log_description = '$session_name disabled user $user_name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, log_entity_id = $user_id");
diff --git a/recurring_ticket_add_modal.php b/recurring_ticket_add_modal.php
index adb787705..56a289b7c 100644
--- a/recurring_ticket_add_modal.php
+++ b/recurring_ticket_add_modal.php
@@ -9,150 +9,184 @@