|
|
@@ -10,6 +10,8 @@
|
|
|
* @var string[] $template_keys
|
|
|
*/
|
|
|
|
|
|
+use Carbon\CarbonImmutable;
|
|
|
+
|
|
|
Core::$show_footer_content = false;
|
|
|
|
|
|
if((int) Core::$user->getId() !== $test->getTesterId()) throw new Exception(__("You do not have permission to view this page."));
|
|
|
@@ -30,13 +32,10 @@ if($submit) {
|
|
|
|
|
|
$previous_timezone = date_default_timezone_get();
|
|
|
|
|
|
- $unix_start = null;
|
|
|
- $unix_end = null;
|
|
|
-
|
|
|
try {
|
|
|
Core::validateCSRFToken($submit);
|
|
|
|
|
|
- $form_exception = new FormException;
|
|
|
+ $form_exception = new FormException();
|
|
|
|
|
|
// Parse before the test form
|
|
|
if($test->isConfirmed()) {
|
|
|
@@ -56,18 +55,18 @@ if($submit) {
|
|
|
$end_override = HTTP::value("end_override");
|
|
|
|
|
|
if($start_override && $end_override) {
|
|
|
- $dt_start = new DateTime($start_override, new DateTimeZone(TIMEZONE));
|
|
|
- $dt_end = new DateTime($end_override, new DateTimeZone(TIMEZONE));
|
|
|
+ $dt_start = CarbonImmutable::parse($start_override, TIMEZONE);
|
|
|
+ $dt_end = CarbonImmutable::parse($end_override, TIMEZONE);
|
|
|
|
|
|
- $unix_start = $dt_start->format("U");
|
|
|
- $unix_end = $dt_end->format("U");
|
|
|
-
|
|
|
- if($unix_start > $unix_end) $form_exception->addError(__("Entry Time must not be after Exit Time."));
|
|
|
- if($unix_start === $unix_end) $form_exception->addError(__("Entry Time must not equal the Exit Time."));
|
|
|
- if(!$unix_start && $unix_end && $test->dts_start) {
|
|
|
- $recorded_start_unix = Util::getUnixTimeFromUTC($test->dts_start);
|
|
|
- if($unix_end < $recorded_start_unix) $form_exception->addError(__("Exit Time cannot be later than the recorded Entry Time."));
|
|
|
+ if($dt_start > $dt_end) {
|
|
|
+ $form_exception->addError(__("Entry Time must not be after Exit Time."));
|
|
|
+ }
|
|
|
+ if($dt_start === $dt_end) {
|
|
|
+ $form_exception->addError(__("Entry Time must not equal the Exit Time."));
|
|
|
}
|
|
|
+
|
|
|
+ $test->dts_start = $dt_start->utc()->toDateTimeString();
|
|
|
+ $test->dts_end = $dt_end->utc()->toDateTimeString();
|
|
|
}
|
|
|
else {
|
|
|
$form_exception->addError(__("Entry Time and Exit Time must be filled in."));
|
|
|
@@ -75,7 +74,9 @@ if($submit) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(empty($fields)) throw new LogicException(__("No fields can be shown."));
|
|
|
+ if(empty($fields)) {
|
|
|
+ throw new LogicException(__("No fields can be shown."));
|
|
|
+ }
|
|
|
|
|
|
foreach($fields as $field) {
|
|
|
$name = $field->name ?? false;
|
|
|
@@ -164,7 +165,14 @@ if($submit) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if($form_exception->hasErrors()) throw $form_exception;
|
|
|
+ $validate_file = $template->getProcessingDirectoryPath() . "/test_validate.php";
|
|
|
+ if(file_exists($validate_file)) {
|
|
|
+ require $validate_file;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($form_exception->hasErrors()) {
|
|
|
+ throw $form_exception;
|
|
|
+ }
|
|
|
|
|
|
date_default_timezone_set("UTC");
|
|
|
|
|
|
@@ -187,22 +195,6 @@ if($submit) {
|
|
|
|
|
|
$test->status = Test::STATUS_PENDING_VERIFICATION;
|
|
|
|
|
|
- if($has_started) {
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int $unix_start
|
|
|
- * @var int $unix_end
|
|
|
- */
|
|
|
-
|
|
|
- if($unix_start && $unix_end) {
|
|
|
- $test->dts_start = date("Y-m-d H:i:s", $unix_start);
|
|
|
- $test->dts_end = date("Y-m-d H:i:s", $unix_end);
|
|
|
- }
|
|
|
- else if($unix_end) {
|
|
|
- $test->dts_end = date("Y-m-d H:i:s", $unix_end);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
$test->pass = 1;
|
|
|
if($template->hasPassFail()) {
|
|
|
$test->pass = ($test->challenge_stage <= $template->getPassStage()) ? 1 : 0; // Pass = Challenged during browsing or before
|