|
@@ -38,8 +38,6 @@ if($submit) {
|
|
|
|
|
|
|
|
$form_exception = new FormException;
|
|
$form_exception = new FormException;
|
|
|
|
|
|
|
|
- $void = HTTP::value("void", "int");
|
|
|
|
|
-
|
|
|
|
|
// Parse before the test form
|
|
// Parse before the test form
|
|
|
if($test->isConfirmed()) {
|
|
if($test->isConfirmed()) {
|
|
|
$fields = $json->beforeTest;
|
|
$fields = $json->beforeTest;
|
|
@@ -53,11 +51,7 @@ if($submit) {
|
|
|
|
|
|
|
|
// Start/End times
|
|
// Start/End times
|
|
|
|
|
|
|
|
- if($void) {
|
|
|
|
|
- $unix_start = time();
|
|
|
|
|
- $unix_end = time();
|
|
|
|
|
- }
|
|
|
|
|
- else if($has_started) {
|
|
|
|
|
|
|
+ if($has_started) {
|
|
|
$start_override = HTTP::value("start_override");
|
|
$start_override = HTTP::value("start_override");
|
|
|
$end_override = HTTP::value("end_override");
|
|
$end_override = HTTP::value("end_override");
|
|
|
|
|
|
|
@@ -83,75 +77,73 @@ if($submit) {
|
|
|
|
|
|
|
|
if(empty($fields)) throw new LogicException(__("No fields can be shown."));
|
|
if(empty($fields)) throw new LogicException(__("No fields can be shown."));
|
|
|
|
|
|
|
|
- if(!$void) {
|
|
|
|
|
- foreach($fields as $field) {
|
|
|
|
|
- $name = $field->name ?? false;
|
|
|
|
|
- if(empty($name)) continue; // Not a field
|
|
|
|
|
|
|
+ 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, true)) continue;
|
|
|
|
|
|
|
+ $required_key = $field->requiredKey ?? null;
|
|
|
|
|
+ if($required_key && !in_array($required_key, $template_keys, true)) 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));
|
|
|
|
|
|
|
+ // 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));
|
|
|
|
|
|
|
+ [$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";
|
|
|
|
|
|
|
|
- $success = imagejpeg($output_image, $output_path, 60);
|
|
|
|
|
- imagedestroy($output_image);
|
|
|
|
|
|
|
+ $success = imagejpeg($output_image, $output_path, 60);
|
|
|
|
|
+ imagedestroy($output_image);
|
|
|
|
|
|
|
|
- if(!$success) throw new Exception(__("Failed to save %s.", $label));
|
|
|
|
|
- if(!file_exists($output_path)) throw new Exception(__("Failed to save %s."));
|
|
|
|
|
- }
|
|
|
|
|
- catch(Exception $e) {
|
|
|
|
|
- $form_exception->addError($e->getMessage());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if(!$success) throw new Exception(__("Failed to save %s.", $label));
|
|
|
|
|
+ if(!file_exists($output_path)) throw new Exception(__("Failed to save %s."));
|
|
|
}
|
|
}
|
|
|
- else {
|
|
|
|
|
- $value = http::value($name, "trim");
|
|
|
|
|
- if($value === "") $value = null;
|
|
|
|
|
|
|
+ catch(Exception $e) {
|
|
|
|
|
+ $form_exception->addError($e->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ $value = http::value($name, "trim");
|
|
|
|
|
+ if($value === "") $value = null;
|
|
|
|
|
|
|
|
- if($required && $value === null) $form_exception->addError(sprintf(__("%s is required."), $label));
|
|
|
|
|
- if($values && !in_array($value, $values, false)) $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, false)) $form_exception->addError(sprintf(__("Value for %s is invalid."), $label));
|
|
|
|
|
|
|
|
- if(in_array($name, Test::TEST_FIELDS, true)) {
|
|
|
|
|
- $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));
|
|
|
|
|
|
|
+ if(in_array($name, Test::TEST_FIELDS, true)) {
|
|
|
|
|
+ $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));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -195,16 +187,9 @@ if($submit) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if($void) {
|
|
|
|
|
- $test->void = 1;
|
|
|
|
|
- $test->void_notes = HTTP::value("void_notes", "trim");
|
|
|
|
|
- if(empty($test->void_notes)) throw new Exception(__("Venue Closed Notes is required."));
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- $test->pass = 1;
|
|
|
|
|
- if($template->hasPassFail()) {
|
|
|
|
|
- $test->pass = ($test->challenge_stage <= $template->getPassStage()) ? 1 : 0; // Pass = Challenged during browsing or before
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $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();
|
|
$test->dts_updated = Util::getDateTime();
|