Add Setting option to enable or disable ticket autotimer

This commit is contained in:
johnnyq
2025-06-12 13:44:21 -04:00
parent dba3e895da
commit 9c096d1f65
8 changed files with 41 additions and 25 deletions

View File

@@ -53,6 +53,13 @@ require_once "includes/inc_all_admin.php";
</div> </div>
<?php } ?> <?php } ?>
<div class="form-group">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" name="config_ticket_timer_autostart" <?php if ($config_ticket_timer_autostart == 1) { echo "checked"; } ?> value="1" id="ticketTimerSwitch">
<label class="custom-control-label" for="ticketTimerSwitch">Autostart Ticket Timer <small class="text-secondary">(This option will control if the timer starts automatically or manually)</small></label>
</div>
</div>
<div class="form-group"> <div class="form-group">
<label>Number of hours to auto close resolved tickets</label> <label>Number of hours to auto close resolved tickets</label>
<div class="input-group"> <div class="input-group">

View File

@@ -3464,12 +3464,15 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.1.4'"); mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.1.4'");
} }
if (CURRENT_DATABASE_VERSION == '2.1.4') {
mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_ticket_timer_autostart` TINYINT(1) NOT NULL DEFAULT '1' AFTER `config_ticket_default_billable`");
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.1.5'");
}
// if (CURRENT_DATABASE_VERSION == '2.1.5') {
// if (CURRENT_DATABASE_VERSION == '2.1.4') { // // Insert queries here required to update to DB version 2.1.6
// // Insert queries here required to update to DB version 2.1.5
// // Then, update the database to the next sequential version // // Then, update the database to the next sequential version
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.1.5'"); // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.1.6'");
// } // }
} else { } else {

3
db.sql
View File

@@ -1812,6 +1812,7 @@ CREATE TABLE `settings` (
`config_ticket_autoclose_hours` int(5) NOT NULL DEFAULT 72, `config_ticket_autoclose_hours` int(5) NOT NULL DEFAULT 72,
`config_ticket_new_ticket_notification_email` varchar(200) DEFAULT NULL, `config_ticket_new_ticket_notification_email` varchar(200) DEFAULT NULL,
`config_ticket_default_billable` tinyint(1) NOT NULL DEFAULT 0, `config_ticket_default_billable` tinyint(1) NOT NULL DEFAULT 0,
`config_ticket_timer_autostart` tinyint(1) NOT NULL DEFAULT 1,
`config_enable_cron` tinyint(1) NOT NULL DEFAULT 0, `config_enable_cron` tinyint(1) NOT NULL DEFAULT 0,
`config_recurring_auto_send_invoice` tinyint(1) NOT NULL DEFAULT 1, `config_recurring_auto_send_invoice` tinyint(1) NOT NULL DEFAULT 1,
`config_enable_alert_domain_expire` tinyint(1) NOT NULL DEFAULT 1, `config_enable_alert_domain_expire` tinyint(1) NOT NULL DEFAULT 1,
@@ -2500,4 +2501,4 @@ CREATE TABLE `vendors` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2025-05-24 13:23:21 -- Dump completed on 2025-06-12 13:43:40

View File

@@ -5,4 +5,4 @@
* It is used in conjunction with database_updates.php * It is used in conjunction with database_updates.php
*/ */
DEFINE("LATEST_DATABASE_VERSION", "2.1.4"); DEFINE("LATEST_DATABASE_VERSION", "2.1.5");

View File

@@ -78,6 +78,7 @@ $config_ticket_default_billable = intval($row['config_ticket_default_billable'])
$config_ticket_default_view = intval($row['config_ticket_default_view']); $config_ticket_default_view = intval($row['config_ticket_default_view']);
$config_ticket_moving_columns = intval($row['config_ticket_moving_columns']); $config_ticket_moving_columns = intval($row['config_ticket_moving_columns']);
$config_ticket_ordering = intval($row['config_ticket_ordering']); $config_ticket_ordering = intval($row['config_ticket_ordering']);
$config_ticket_timer_autostart = intval($row['config_ticket_timer_autostart']);
// Cron // Cron
$config_enable_cron = intval($row['config_enable_cron']); $config_enable_cron = intval($row['config_enable_cron']);

View File

@@ -1,10 +1,7 @@
// Description: This file contains the JavaScript for the ticket time tracking feature
(function() { (function() {
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function() {
// Initialize variables // Initialize variables
var timerInterval = null; var timerInterval = null;
var isPaused = false;
var ticketID = getCurrentTicketID(); var ticketID = getCurrentTicketID();
var elapsedSecs = getElapsedSeconds(); var elapsedSecs = getElapsedSeconds();
@@ -51,10 +48,8 @@
localStorage.setItem(getLocalStorageKey("startTime"), Date.now().toString()); localStorage.setItem(getLocalStorageKey("startTime"), Date.now().toString());
} }
timerInterval = setInterval(countTime, 1000); timerInterval = setInterval(countTime, 1000);
isPaused = false;
document.getElementById("startStopTimer").innerHTML = "<i class='fas fa-pause'></i>"; document.getElementById("startStopTimer").innerHTML = "<i class='fas fa-pause'></i>";
localStorage.setItem("ticket-timer-running-" + ticketID, "true"); localStorage.setItem("ticket-timer-running-" + ticketID, "true");
} }
function pauseTimer() { function pauseTimer() {
@@ -65,10 +60,8 @@
let currentElapsed = getElapsedSeconds(); let currentElapsed = getElapsedSeconds();
localStorage.setItem(getLocalStorageKey("pausedTime"), currentElapsed.toString()); localStorage.setItem(getLocalStorageKey("pausedTime"), currentElapsed.toString());
localStorage.removeItem(getLocalStorageKey("startTime")); localStorage.removeItem(getLocalStorageKey("startTime"));
isPaused = true;
document.getElementById("startStopTimer").innerHTML = "<i class='fas fa-play'></i>"; document.getElementById("startStopTimer").innerHTML = "<i class='fas fa-play'></i>";
localStorage.setItem("ticket-timer-running-" + ticketID, "false"); localStorage.setItem("ticket-timer-running-" + ticketID, "false");
} }
function clearTimeStorage() { function clearTimeStorage() {
@@ -99,9 +92,7 @@
} }
function handleInputFocus() { function handleInputFocus() {
if (!isPaused) { pauseTimer();
pauseTimer();
}
} }
function updateTimeFromInput() { function updateTimeFromInput() {
@@ -110,7 +101,6 @@
const seconds = parseInt(document.getElementById("seconds").value, 10) || 0; const seconds = parseInt(document.getElementById("seconds").value, 10) || 0;
elapsedSecs = (hours * 3600) + (minutes * 60) + seconds; elapsedSecs = (hours * 3600) + (minutes * 60) + seconds;
// Update local storage so the manually entered time is retained even if the page is reloaded.
if (!timerInterval) { if (!timerInterval) {
localStorage.setItem(getLocalStorageKey("pausedTime"), elapsedSecs.toString()); localStorage.setItem(getLocalStorageKey("pausedTime"), elapsedSecs.toString());
} else { } else {
@@ -120,7 +110,6 @@
} }
} }
// Function to check status and pause timer
function checkStatusAndPauseTimer() { function checkStatusAndPauseTimer() {
var status = document.querySelector('select[name="status"]').value; var status = document.querySelector('select[name="status"]').value;
if (status.includes("Pending") || status.includes("Close")) { if (status.includes("Pending") || status.includes("Close")) {
@@ -128,6 +117,7 @@
} }
} }
// Attach input listeners
document.getElementById("hours").addEventListener('change', updateTimeFromInput); document.getElementById("hours").addEventListener('change', updateTimeFromInput);
document.getElementById("minutes").addEventListener('change', updateTimeFromInput); document.getElementById("minutes").addEventListener('change', updateTimeFromInput);
document.getElementById("seconds").addEventListener('change', updateTimeFromInput); document.getElementById("seconds").addEventListener('change', updateTimeFromInput);
@@ -151,25 +141,33 @@
}); });
document.getElementById("ticket_add_reply").addEventListener('click', function() { document.getElementById("ticket_add_reply").addEventListener('click', function() {
// Wait for other synchronous actions (if any) to complete before resetting the timer. setTimeout(forceResetTimer, 100);
setTimeout(forceResetTimer, 100); // 100ms delay should suffice, but you can adjust as needed.
}); });
document.getElementById("ticket_close").addEventListener('click', function() { document.getElementById("ticket_close").addEventListener('click', function() {
// Wait for other synchronous actions (if any) to complete before resetting the timer. setTimeout(clearTimeStorage, 100);
setTimeout(clearTimeStorage, 100); // 100ms delay should suffice, but you can adjust as needed.
}); });
// Final initialization logic
try { try {
displayTime(); displayTime();
// If no timer state, respect ticketAutoStart
if (!localStorage.getItem(getLocalStorageKey("startTime")) && !localStorage.getItem(getLocalStorageKey("pausedTime"))) { if (!localStorage.getItem(getLocalStorageKey("startTime")) && !localStorage.getItem(getLocalStorageKey("pausedTime"))) {
startTimer(); if (ticketAutoStart === 1) {
} else if (localStorage.getItem(getLocalStorageKey("startTime"))) { startTimer();
} else {
pauseTimer();
}
}
// If timer already running, resume it
else if (localStorage.getItem(getLocalStorageKey("startTime"))) {
startTimer(); startTimer();
} }
// Check and pause timer if status is pending // Check and pause timer if status is pending
checkStatusAndPauseTimer(); checkStatusAndPauseTimer();
} catch (error) { } catch (error) {
console.error("There was an issue initializing the timer:", error); console.error("There was an issue initializing the timer:", error);
} }

View File

@@ -17,8 +17,9 @@ if (isset($_POST['edit_ticket_settings'])) {
$config_ticket_default_view = intval($_POST['config_ticket_default_view']); $config_ticket_default_view = intval($_POST['config_ticket_default_view']);
$config_ticket_moving_columns = intval($_POST['config_ticket_moving_columns']); $config_ticket_moving_columns = intval($_POST['config_ticket_moving_columns']);
$config_ticket_ordering = intval($_POST['config_ticket_ordering']); $config_ticket_ordering = intval($_POST['config_ticket_ordering']);
$config_ticket_timer_autostart = intval($_POST['config_ticket_timer_autostart']);
mysqli_query($mysqli,"UPDATE settings SET config_ticket_prefix = '$config_ticket_prefix', config_ticket_next_number = $config_ticket_next_number, config_ticket_email_parse = $config_ticket_email_parse, config_ticket_email_parse_unknown_senders = $config_ticket_email_parse_unknown_senders, config_ticket_autoclose_hours = $config_ticket_autoclose_hours, config_ticket_new_ticket_notification_email = '$config_ticket_new_ticket_notification_email', config_ticket_default_billable = $config_ticket_default_billable, config_ticket_default_view = $config_ticket_default_view, config_ticket_moving_columns = $config_ticket_moving_columns, config_ticket_ordering = $config_ticket_ordering WHERE company_id = 1"); mysqli_query($mysqli,"UPDATE settings SET config_ticket_prefix = '$config_ticket_prefix', config_ticket_next_number = $config_ticket_next_number, config_ticket_email_parse = $config_ticket_email_parse, config_ticket_email_parse_unknown_senders = $config_ticket_email_parse_unknown_senders, config_ticket_autoclose_hours = $config_ticket_autoclose_hours, config_ticket_new_ticket_notification_email = '$config_ticket_new_ticket_notification_email', config_ticket_default_billable = $config_ticket_default_billable, config_ticket_default_view = $config_ticket_default_view, config_ticket_moving_columns = $config_ticket_moving_columns, config_ticket_ordering = $config_ticket_ordering, config_ticket_timer_autostart = $config_ticket_timer_autostart WHERE company_id = 1");
// Logging // Logging
logAction("Settings", "Edit", "$session_name edited ticket settings"); logAction("Settings", "Edit", "$session_name edited ticket settings");

View File

@@ -1252,6 +1252,11 @@ require_once "includes/footer.php";
<script src="js/show_modals.js"></script> <script src="js/show_modals.js"></script>
<?php if (empty($ticket_closed_at)) { ?> <?php if (empty($ticket_closed_at)) { ?>
<!-- create js variable related to ticket timer setting -->
<script type="text/javascript">
var ticketAutoStart = <?php echo json_encode($config_ticket_timer_autostart); ?>;
</script>
<!-- Ticket Time Tracking JS --> <!-- Ticket Time Tracking JS -->
<script src="js/ticket_time_tracking.js"></script> <script src="js/ticket_time_tracking.js"></script>