mirror of https://github.com/itflow-org/itflow
Add Setting option to enable or disable ticket autotimer
This commit is contained in:
parent
dba3e895da
commit
9c096d1f65
|
|
@ -53,6 +53,13 @@ require_once "includes/inc_all_admin.php";
|
|||
</div>
|
||||
<?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">
|
||||
<label>Number of hours to auto close resolved tickets</label>
|
||||
<div class="input-group">
|
||||
|
|
|
|||
|
|
@ -3464,12 +3464,15 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
|
|||
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.4') {
|
||||
// // Insert queries here required to update to DB version 2.1.5
|
||||
// if (CURRENT_DATABASE_VERSION == '2.1.5') {
|
||||
// // Insert queries here required to update to DB version 2.1.6
|
||||
// // 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 {
|
||||
|
|
|
|||
3
db.sql
3
db.sql
|
|
@ -1812,6 +1812,7 @@ CREATE TABLE `settings` (
|
|||
`config_ticket_autoclose_hours` int(5) NOT NULL DEFAULT 72,
|
||||
`config_ticket_new_ticket_notification_email` varchar(200) DEFAULT NULL,
|
||||
`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_recurring_auto_send_invoice` 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 */;
|
||||
/*!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
|
||||
|
|
|
|||
|
|
@ -5,4 +5,4 @@
|
|||
* It is used in conjunction with database_updates.php
|
||||
*/
|
||||
|
||||
DEFINE("LATEST_DATABASE_VERSION", "2.1.4");
|
||||
DEFINE("LATEST_DATABASE_VERSION", "2.1.5");
|
||||
|
|
|
|||
|
|
@ -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_moving_columns = intval($row['config_ticket_moving_columns']);
|
||||
$config_ticket_ordering = intval($row['config_ticket_ordering']);
|
||||
$config_ticket_timer_autostart = intval($row['config_ticket_timer_autostart']);
|
||||
|
||||
// Cron
|
||||
$config_enable_cron = intval($row['config_enable_cron']);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
// Description: This file contains the JavaScript for the ticket time tracking feature
|
||||
|
||||
(function() {
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
// Initialize variables
|
||||
var timerInterval = null;
|
||||
var isPaused = false;
|
||||
var ticketID = getCurrentTicketID();
|
||||
var elapsedSecs = getElapsedSeconds();
|
||||
|
||||
|
|
@ -51,10 +48,8 @@
|
|||
localStorage.setItem(getLocalStorageKey("startTime"), Date.now().toString());
|
||||
}
|
||||
timerInterval = setInterval(countTime, 1000);
|
||||
isPaused = false;
|
||||
document.getElementById("startStopTimer").innerHTML = "<i class='fas fa-pause'></i>";
|
||||
localStorage.setItem("ticket-timer-running-" + ticketID, "true");
|
||||
|
||||
}
|
||||
|
||||
function pauseTimer() {
|
||||
|
|
@ -65,10 +60,8 @@
|
|||
let currentElapsed = getElapsedSeconds();
|
||||
localStorage.setItem(getLocalStorageKey("pausedTime"), currentElapsed.toString());
|
||||
localStorage.removeItem(getLocalStorageKey("startTime"));
|
||||
isPaused = true;
|
||||
document.getElementById("startStopTimer").innerHTML = "<i class='fas fa-play'></i>";
|
||||
localStorage.setItem("ticket-timer-running-" + ticketID, "false");
|
||||
|
||||
}
|
||||
|
||||
function clearTimeStorage() {
|
||||
|
|
@ -99,9 +92,7 @@
|
|||
}
|
||||
|
||||
function handleInputFocus() {
|
||||
if (!isPaused) {
|
||||
pauseTimer();
|
||||
}
|
||||
pauseTimer();
|
||||
}
|
||||
|
||||
function updateTimeFromInput() {
|
||||
|
|
@ -110,7 +101,6 @@
|
|||
const seconds = parseInt(document.getElementById("seconds").value, 10) || 0;
|
||||
elapsedSecs = (hours * 3600) + (minutes * 60) + seconds;
|
||||
|
||||
// Update local storage so the manually entered time is retained even if the page is reloaded.
|
||||
if (!timerInterval) {
|
||||
localStorage.setItem(getLocalStorageKey("pausedTime"), elapsedSecs.toString());
|
||||
} else {
|
||||
|
|
@ -120,7 +110,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
// Function to check status and pause timer
|
||||
function checkStatusAndPauseTimer() {
|
||||
var status = document.querySelector('select[name="status"]').value;
|
||||
if (status.includes("Pending") || status.includes("Close")) {
|
||||
|
|
@ -128,6 +117,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
// Attach input listeners
|
||||
document.getElementById("hours").addEventListener('change', updateTimeFromInput);
|
||||
document.getElementById("minutes").addEventListener('change', updateTimeFromInput);
|
||||
document.getElementById("seconds").addEventListener('change', updateTimeFromInput);
|
||||
|
|
@ -151,25 +141,33 @@
|
|||
});
|
||||
|
||||
document.getElementById("ticket_add_reply").addEventListener('click', function() {
|
||||
// Wait for other synchronous actions (if any) to complete before resetting the timer.
|
||||
setTimeout(forceResetTimer, 100); // 100ms delay should suffice, but you can adjust as needed.
|
||||
setTimeout(forceResetTimer, 100);
|
||||
});
|
||||
|
||||
document.getElementById("ticket_close").addEventListener('click', function() {
|
||||
// Wait for other synchronous actions (if any) to complete before resetting the timer.
|
||||
setTimeout(clearTimeStorage, 100); // 100ms delay should suffice, but you can adjust as needed.
|
||||
setTimeout(clearTimeStorage, 100);
|
||||
});
|
||||
|
||||
// Final initialization logic
|
||||
try {
|
||||
displayTime();
|
||||
|
||||
// If no timer state, respect ticketAutoStart
|
||||
if (!localStorage.getItem(getLocalStorageKey("startTime")) && !localStorage.getItem(getLocalStorageKey("pausedTime"))) {
|
||||
startTimer();
|
||||
} else if (localStorage.getItem(getLocalStorageKey("startTime"))) {
|
||||
if (ticketAutoStart === 1) {
|
||||
startTimer();
|
||||
} else {
|
||||
pauseTimer();
|
||||
}
|
||||
}
|
||||
// If timer already running, resume it
|
||||
else if (localStorage.getItem(getLocalStorageKey("startTime"))) {
|
||||
startTimer();
|
||||
}
|
||||
|
||||
// Check and pause timer if status is pending
|
||||
checkStatusAndPauseTimer();
|
||||
|
||||
} catch (error) {
|
||||
console.error("There was an issue initializing the timer:", error);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,9 @@ if (isset($_POST['edit_ticket_settings'])) {
|
|||
$config_ticket_default_view = intval($_POST['config_ticket_default_view']);
|
||||
$config_ticket_moving_columns = intval($_POST['config_ticket_moving_columns']);
|
||||
$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
|
||||
logAction("Settings", "Edit", "$session_name edited ticket settings");
|
||||
|
|
|
|||
|
|
@ -1252,6 +1252,11 @@ require_once "includes/footer.php";
|
|||
<script src="js/show_modals.js"></script>
|
||||
|
||||
<?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 -->
|
||||
<script src="js/ticket_time_tracking.js"></script>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue