|
|
@@ -10,17 +10,17 @@
|
|
|
* @var string[] $template_keys
|
|
|
*/
|
|
|
|
|
|
-$is_confirmed = $test->status == Test::STATUS_CONFIRMED;
|
|
|
-$is_started = $test->status == Test::STATUS_STARTED;
|
|
|
-$is_unverified = $test->status == Test::STATUS_PENDING_VERIFICATION;
|
|
|
+$is_confirmed = $test->isConfirmed();
|
|
|
+$is_started = $test->hasStarted();
|
|
|
+$is_unverified = $test->isPendingVerification();
|
|
|
|
|
|
Core::$show_footer_content = false;
|
|
|
|
|
|
-if(Core::$user->id != $test->tester_id) throw new Exception(__("You do not have permission to view this page."));
|
|
|
-if($test->status == Test::STATUS_ASSIGNED) throw new Exception(__("You do not have permission to view this page as you have not accepted the test yet."));
|
|
|
+if(Core::$user->getId() != $test->getTesterId()) throw new Exception(__("You do not have permission to view this page."));
|
|
|
+if($test->getStatus() === Test::STATUS_ASSIGNED) throw new Exception(__("You do not have permission to view this page as you have not accepted the test yet."));
|
|
|
|
|
|
// Show completed message
|
|
|
-if($test->status > Test::STATUS_PENDING_VERIFICATION) {
|
|
|
+if($test->getStatus() > Test::STATUS_PENDING_VERIFICATION) {
|
|
|
View::includeOnce("header", compact("page_title"));
|
|
|
View::include("test_form", compact("test", "location", "project", "template"));
|
|
|
View::includeOnce("footer");
|
|
|
@@ -39,110 +39,117 @@ if($submit) {
|
|
|
|
|
|
$form_exception = new FormException;
|
|
|
|
|
|
+ $void = HTTP::value("void", "int");
|
|
|
+
|
|
|
+ // Parse before the test form
|
|
|
if($is_confirmed) {
|
|
|
- // Parse before the test form
|
|
|
$fields = $json->beforeTest;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+ // Parse after the test form
|
|
|
if($is_started || $is_unverified) {
|
|
|
- // Parse after the test form
|
|
|
$fields = $json->duringTest;
|
|
|
|
|
|
// Start/End times
|
|
|
- if($is_started) {
|
|
|
- $start_override = http::getDateTimeFromFields("start_override");
|
|
|
- $end_override = http::getDateTimeFromFields("end_override");
|
|
|
-
|
|
|
- $start_unix = null;
|
|
|
- $end_unix = null;
|
|
|
|
|
|
- if($start_override && $end_override) {
|
|
|
- $start_unix = strtotime($start_override);
|
|
|
- $end_unix = strtotime($end_override);
|
|
|
-
|
|
|
- if($start_unix > $end_unix) $form_exception->addError(__("Entry Time must not be after Exit Time."));
|
|
|
- if(!$start_unix && $end_unix && $test->dts_start) {
|
|
|
- $recorded_start_unix = Util::getUnixTimeFromUTC($test->dts_start);
|
|
|
- if($end_unix < $recorded_start_unix) $form_exception->addError(__("Exit Time cannot be later than the recorded Entry Time."));
|
|
|
+ if($void) {
|
|
|
+ $start_unix = time();
|
|
|
+ $end_unix = time();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if($is_started) {
|
|
|
+ $start_override = http::getDateTimeFromFields("start_override");
|
|
|
+ $end_override = http::getDateTimeFromFields("end_override");
|
|
|
+
|
|
|
+ $start_unix = null;
|
|
|
+ $end_unix = null;
|
|
|
+
|
|
|
+ if($start_override && $end_override) {
|
|
|
+ $start_unix = strtotime($start_override);
|
|
|
+ $end_unix = strtotime($end_override);
|
|
|
+
|
|
|
+ if($start_unix > $end_unix) $form_exception->addError(__("Entry Time must not be after Exit Time."));
|
|
|
+ if(!$start_unix && $end_unix && $test->dts_start) {
|
|
|
+ $recorded_start_unix = Util::getUnixTimeFromUTC($test->dts_start);
|
|
|
+ if($end_unix < $recorded_start_unix) $form_exception->addError(__("Exit Time cannot be later than the recorded Entry Time."));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $form_exception->addError(__("Entry Time and Exit Time must be filled in."));
|
|
|
}
|
|
|
- }
|
|
|
- else {
|
|
|
- $form_exception->addError(__("Entry Time and Exit Time must be filled in."));
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
if(empty($fields)) throw new LogicException(__("No fields can be shown."));
|
|
|
|
|
|
- foreach($fields as $field) {
|
|
|
-
|
|
|
- $name = $field->name ?? false;
|
|
|
- if(empty($name)) continue; // Not a field
|
|
|
+ if(!$void) {
|
|
|
+ foreach($fields as $field) {
|
|
|
+ $name = $field->name ?? false;
|
|
|
+ if(empty($name)) continue; // Not a field
|
|
|
|
|
|
- $required_key = $field->requiredKey ?? null;
|
|
|
- if($required_key && !in_array($required_key, $template_keys)) continue;
|
|
|
+ $required_key = $field->requiredKey ?? null;
|
|
|
+ if($required_key && !in_array($required_key, $template_keys)) continue;
|
|
|
|
|
|
- $label = $field->label ?? "";
|
|
|
- $type = $field->type;
|
|
|
- $required = $field->required ?? false;
|
|
|
- $values = $field->values ?? [];
|
|
|
+ $label = $field->label ?? "";
|
|
|
+ $type = $field->type;
|
|
|
+ $required = $field->required ?? false;
|
|
|
+ $values = $field->values ?? [];
|
|
|
|
|
|
- if($type == "file") {
|
|
|
- $file = (object) $_FILES[$name];
|
|
|
+ if($type === "file") {
|
|
|
+ $file = (object) $_FILES[$name];
|
|
|
|
|
|
- try {
|
|
|
- if(!$required && $file->error == UPLOAD_ERR_NO_FILE) continue;
|
|
|
- if($required && $file->error == UPLOAD_ERR_NO_FILE) {
|
|
|
- throw new Exception("$label is required.");
|
|
|
- }
|
|
|
+ try {
|
|
|
+ if(!$required && $file->error === UPLOAD_ERR_NO_FILE) continue;
|
|
|
+ if($required && $file->error === UPLOAD_ERR_NO_FILE) {
|
|
|
+ throw new Exception("$label is required.");
|
|
|
+ }
|
|
|
|
|
|
- // Detect upload error
|
|
|
- if($file->error != UPLOAD_ERR_OK) throw new Exception(HTTP::getUploadErrorString($file->error));
|
|
|
+ // Detect upload error
|
|
|
+ if($file->error !== UPLOAD_ERR_OK) throw new Exception(HTTP::getUploadErrorString($file->error));
|
|
|
|
|
|
- // Get image details
|
|
|
- $size = @getimagesize($file->tmp_name);
|
|
|
- if(!$size) throw new Exception(sprintf(__("The uploaded file for %s is not an image."), $label));
|
|
|
- [$width, $height, $type] = $size;
|
|
|
- if($type != IMAGETYPE_JPEG) throw new Exception(sprintf(__("The uploaded file for %s is not a JPEG."), $label));
|
|
|
+ // Get image details
|
|
|
+ $size = @getimagesize($file->tmp_name);
|
|
|
+ if(!$size) throw new Exception(sprintf(__("The uploaded file for %s is not an image."), $label));
|
|
|
+ [$width, $height, $type] = $size;
|
|
|
+ if($type !== IMAGETYPE_JPEG) throw new Exception(sprintf(__("The uploaded file for %s is not a JPEG."), $label));
|
|
|
|
|
|
- // Resize image
|
|
|
- $output_image = Image::normalise($file->tmp_name);
|
|
|
+ // Resize image
|
|
|
+ $output_image = Image::normalise($file->tmp_name);
|
|
|
|
|
|
- // Write image to disk
|
|
|
- $output_path = $test->getDirectory() . "/" . $name . ".jpg";
|
|
|
+ // Write image to disk
|
|
|
+ $output_path = $test->getDirectory() . "/" . $name . ".jpg";
|
|
|
|
|
|
- imagejpeg($output_image, $output_path, 60);
|
|
|
- imagedestroy($output_image);
|
|
|
- }
|
|
|
- catch(Exception $e) {
|
|
|
- $form_exception->addError($e->getMessage());
|
|
|
+ imagejpeg($output_image, $output_path, 60);
|
|
|
+ imagedestroy($output_image);
|
|
|
+ }
|
|
|
+ catch(Exception $e) {
|
|
|
+ $form_exception->addError($e->getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- else {
|
|
|
- $value = http::value($name, "trim");
|
|
|
+ else {
|
|
|
+ $value = http::value($name, "trim");
|
|
|
|
|
|
- if($required && $value === null) $form_exception->addError(sprintf(__("%s is required."), $label));
|
|
|
- if($values && !in_array($value, $values)) $form_exception->addError(sprintf(__("Value for %s is invalid."), $label));
|
|
|
+ if($required && $value === null) $form_exception->addError(sprintf(__("%s is required."), $label));
|
|
|
+ if($values && !in_array($value, $values)) $form_exception->addError(sprintf(__("Value for %s is invalid."), $label));
|
|
|
|
|
|
- if(in_array($name, Test::TEST_FIELDS)) {
|
|
|
- $test->$name = $value;
|
|
|
- }
|
|
|
- else {
|
|
|
- $test_value = TestValue::get($test->id, $name);
|
|
|
- if(!$test_value) {
|
|
|
- $test_value = new TestValue;
|
|
|
- $test_value->test_id = $test->id;
|
|
|
- $test_value->name = $name;
|
|
|
+ if(in_array($name, Test::TEST_FIELDS)) {
|
|
|
+ $test->$name = $value;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $test_value = TestValue::get($test->id, $name);
|
|
|
+ if(!$test_value) {
|
|
|
+ $test_value = new TestValue;
|
|
|
+ $test_value->test_id = $test->id;
|
|
|
+ $test_value->name = $name;
|
|
|
+ }
|
|
|
+ $test_value->value = $value;
|
|
|
+ $success = $test_value->commit();
|
|
|
+ if(!$success) $form_exception->addError(sprintf(__("Failed to save value for %s."), $label));
|
|
|
}
|
|
|
- $test_value->value = $value;
|
|
|
- $success = $test_value->commit();
|
|
|
- if(!$success) $form_exception->addError(sprintf(__("Failed to save value for %s."), $label));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
if($form_exception->hasErrors()) throw $form_exception;
|
|
|
@@ -164,7 +171,9 @@ if($submit) {
|
|
|
}
|
|
|
|
|
|
// During the test
|
|
|
+
|
|
|
if($is_started || $is_unverified) {
|
|
|
+
|
|
|
$test->status = Test::STATUS_PENDING_VERIFICATION;
|
|
|
|
|
|
if($is_started) {
|
|
|
@@ -183,9 +192,14 @@ if($submit) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $test->pass = 1;
|
|
|
- if($template->hasPassFail()) {
|
|
|
- $test->pass = ($test->challenge_stage <= $template->getPassStage()) ? 1 : 0; // Pass = Challenged during browsing or before
|
|
|
+ if($void) {
|
|
|
+ $test->void = 1;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $test->pass = 1;
|
|
|
+ if($template->hasPassFail()) {
|
|
|
+ $test->pass = ($test->challenge_stage <= $template->getPassStage()) ? 1 : 0; // Pass = Challenged during browsing or before
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
$test->dts_updated = Util::getDateTime();
|