$id, "status" => Test::STATUS_UNASSIGNED, ]); try { if(!$test) throw new Exception(__("Test no longer available.")); $project = $test->getProject(); // Set due date $date_due = date("Y-m-d", strtotime("+7 DAYS")); $unix_due = strtotime("$date_due 23:59:59"); $user = Core::$user; if($user->level == User::LEVEL_BANNED) throw new Exception(__("You are a banned tester.")); if($user->level == User::LEVEL_REGISTERED) throw new Exception(__("Your account is not verified.")); if($user->level == User::LEVEL_UNVERIFIED) throw new Exception(__("Your account is not verified.")); if($user->level == User::LEVEL_DEACTIVATED) throw new Exception(__("Your account is deactivated.")); if($user->level != User::LEVEL_TESTER) throw new Exception(__("You are not a tester.")); $test->status = Test::STATUS_CONFIRMED; $test->tester_id = $user->id; $test->dts_assigned = Util::getDateTime(); $test->dts_rejected = null; $test->dts_updated = Util::getDateTime(); if($unix_due) { $test->dts_due = "$date_due 23:59:59"; if(strcmp($test->dts_due, $project->dts_start) < 0) throw new Exception(__("Too early.")); } $success = $test->commit(); if(!$success) throw new Exception(__("Test cannot be claimed, please try again later.")); $test->sendClaimedEmail(); } catch(Exception $e) { JSON::fail($e->getMessage()); } JSON::success(); break; case "get-tests": $output = []; foreach($tests as $test) { $location = $test->getLocation(); $output[] = (object) [ "id" => (int) $test->id, "location" => (object) [ "id" => (int) $location->id, "name" => $location->name, "address" => $location->getDisplayAddress(), "geolocation" => $location->getGeolocation(), ], ]; } $response["tests"] = $output; break; default: throw new Exception(__("Invalid action.")); } JSON::success($response); ?>