Fix #54 - fixed time checking

This commit is contained in:
Vojtěch Sajdl 2018-08-23 20:37:45 +02:00
parent 9488343f9b
commit 93565fc014
No known key found for this signature in database
GPG Key ID: 5D4EB1361A272390
2 changed files with 14 additions and 6 deletions

View File

@ -117,9 +117,9 @@ class Incident implements JsonSerializable
$services = $_POST['services']; $services = $_POST['services'];
} }
if (!empty($_POST['time'])){ if (!empty($_POST['time']) && $type == 2){
$input_time = (isset($_POST['time_js'])?$_POST['time_js']: $_POST['time']); $input_time = (!empty($_POST['time_js'])?$_POST['time_js']: $_POST['time']);
$input_end_time = (isset($_POST['end_time_js'])?$_POST['end_time_js']: $_POST['end_time']); $input_end_time = (!empty($_POST['end_time_js'])?$_POST['end_time_js']: $_POST['end_time']);
$time = strtotime($input_time); $time = strtotime($input_time);
$end_time = strtotime($input_end_time); $end_time = strtotime($input_end_time);
if (!$time) if (!$time)
@ -133,6 +133,12 @@ class Incident implements JsonSerializable
$message = _("End date format is not recognized. Please use ISO 8601 format."); $message = _("End date format is not recognized. Please use ISO 8601 format.");
return; return;
} }
if ($time >= $end_time)
{
$message = _("End time is either the same or earlier than start time!");
return;
}
}else{ }else{
$time = time(); $time = time();
$end_time = ''; $end_time = '';

View File

@ -15,6 +15,8 @@
$("#new-incident .panel.new .panel-heading i").get(0).className = icons[val]; $("#new-incident .panel.new .panel-heading i").get(0).className = icons[val];
$("#new-incident .panel.new").get(0).className = classes[val] + " new"; $("#new-incident .panel.new").get(0).className = classes[val] + " new";
$('#time_input').val('');
$('#end_time').val('');
}); });
$("#new-incident select").trigger("change"); $("#new-incident select").trigger("change");
@ -24,7 +26,7 @@
var end_time = Date.parse($('#end_time').val()); var end_time = Date.parse($('#end_time').val());
var type = $("#type").val() || 0; var type = $("#type").val() || 0;
if (type === 2 &&(isNaN(time) || isNaN(end_time))) if (type == 2 &&(isNaN(time) || isNaN(end_time)))
{ {
if (isNaN(end_time)) if (isNaN(end_time))
{ {
@ -39,7 +41,7 @@
} }
return false; return false;
} }
else if (type === 2 && time >= end_time) else if (type == 2 && time >= end_time)
{ {
$.growl.error({ message: "End time is either the same or earlier than start time!" }); $.growl.error({ message: "End time is either the same or earlier than start time!" });
$('#time').addClass("error"); $('#time').addClass("error");
@ -47,7 +49,7 @@
return false; return false;
} }
if($('#status-container :checkbox:checked').length === 0) if($('#status-container :checkbox:checked').length == 0)
{ {
$.growl.error({ message: "Please check at least one service!" }); $.growl.error({ message: "Please check at least one service!" });
$('#status-container').addClass("error"); $('#status-container').addClass("error");