Fix issue with roundToNearest15 Function would break php if the time worked was empty
This commit is contained in:
+10
-8
@@ -746,8 +746,13 @@ function shortenClient($client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function roundToNearest15($time) {
|
function roundToNearest15($time) {
|
||||||
// Extract hours, minutes, and seconds from the time string
|
// Validate the input time format
|
||||||
list($hours, $minutes, $seconds) = explode(':', $time);
|
if (!preg_match('/^(\d{2}):(\d{2}):(\d{2})$/', $time, $matches)) {
|
||||||
|
return false; // or throw an exception
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract hours, minutes, and seconds from the matched time string
|
||||||
|
list(, $hours, $minutes, $seconds) = $matches;
|
||||||
|
|
||||||
// Convert everything to seconds for easier calculation
|
// Convert everything to seconds for easier calculation
|
||||||
$totalSeconds = ($hours * 3600) + ($minutes * 60) + $seconds;
|
$totalSeconds = ($hours * 3600) + ($minutes * 60) + $seconds;
|
||||||
@@ -755,18 +760,15 @@ function roundToNearest15($time) {
|
|||||||
// Calculate the remainder when divided by 900 seconds (15 minutes)
|
// Calculate the remainder when divided by 900 seconds (15 minutes)
|
||||||
$remainder = $totalSeconds % 900;
|
$remainder = $totalSeconds % 900;
|
||||||
|
|
||||||
// If the total seconds is less than 15 minutes, round up to 15 minutes
|
if ($remainder > 450) { // If remainder is more than 7.5 minutes (450 seconds), round up
|
||||||
if ($totalSeconds < 900) {
|
|
||||||
$totalSeconds = 900;
|
|
||||||
} else if ($remainder > 450) { // If remainder is more than 7.5 minutes (450 seconds), round up
|
|
||||||
$totalSeconds += (900 - $remainder);
|
$totalSeconds += (900 - $remainder);
|
||||||
} else { // Else round down
|
} else { // Else round down
|
||||||
$totalSeconds -= $remainder;
|
$totalSeconds -= $remainder;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert total seconds to the decimal format
|
// Convert total seconds to decimal hours
|
||||||
$decimalHours = $totalSeconds / 3600;
|
$decimalHours = $totalSeconds / 3600;
|
||||||
|
|
||||||
// Return the formatted string
|
// Return the decimal hours
|
||||||
return number_format($decimalHours, 2);
|
return number_format($decimalHours, 2);
|
||||||
}
|
}
|
||||||
+3
-3
@@ -525,8 +525,8 @@ if (isset($_GET['ticket_id'])) {
|
|||||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, $sql_prev_ticket));
|
$row = mysqli_fetch_assoc(mysqli_query($mysqli, $sql_prev_ticket));
|
||||||
|
|
||||||
$prev_ticket_id = intval($row['ticket_id']);
|
$prev_ticket_id = intval($row['ticket_id']);
|
||||||
$prev_ticket_subject = htmlentities($row['ticket_subject']);
|
$prev_ticket_subject = nullable_htmlentities($row['ticket_subject']);
|
||||||
$prev_ticket_status = htmlentities($row['ticket_status']);
|
$prev_ticket_status = nullable_htmlentities($row['ticket_status']);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
@@ -564,7 +564,7 @@ if (isset($_GET['ticket_id'])) {
|
|||||||
// Get Watchers
|
// Get Watchers
|
||||||
$sql_ticket_watchers = mysqli_query($mysqli, "SELECT * FROM ticket_watchers WHERE watcher_ticket_id = $ticket_id ORDER BY watcher_email DESC");
|
$sql_ticket_watchers = mysqli_query($mysqli, "SELECT * FROM ticket_watchers WHERE watcher_ticket_id = $ticket_id ORDER BY watcher_email DESC");
|
||||||
while ($ticket_watcher_row = mysqli_fetch_array($sql_ticket_watchers)) {
|
while ($ticket_watcher_row = mysqli_fetch_array($sql_ticket_watchers)) {
|
||||||
$ticket_watcher_email = $ticket_watcher_row['watcher_email'];
|
$ticket_watcher_email = nullable_htmlentities($ticket_watcher_row['watcher_email']);
|
||||||
?>
|
?>
|
||||||
<div class='mt-1'>
|
<div class='mt-1'>
|
||||||
<i class="fa fa-fw fa-eye text-secondary ml-1 mr-2"></i><?php echo $ticket_watcher_email; ?>
|
<i class="fa fa-fw fa-eye text-secondary ml-1 mr-2"></i><?php echo $ticket_watcher_email; ?>
|
||||||
|
|||||||
Reference in New Issue
Block a user