test_confirm.php 859 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. $test = Test::get($id);
  3. if(!$test) throw new Exception("Test not found.");
  4. if($test->tester_id != Core::$user->id) throw new Exception("You do not have permission to view this page.");
  5. if($test->status > Test::STATUS_ASSIGNED) throw new Exception("The test has already been accepted or declined.");
  6. switch($action) {
  7. case "accept":
  8. $test->status = Test::STATUS_CONFIRMED;
  9. $test->commit();
  10. // TODO: Email/notification?
  11. Core::addAlert("success", "Test accepted successfully.");
  12. HTTP::redirect("/account/tests");
  13. break;
  14. case "decline":
  15. $test->tester_id = null;
  16. $test->dts_due = null;
  17. $test->dts_assigned = null;
  18. $test->commit();
  19. // TODO: Email/notification?
  20. Core::addAlert("success", "Test declined successfully.");
  21. HTTP::redirect("/account/tests");
  22. break;
  23. default:
  24. throw new Exception("Invalid action.");
  25. }
  26. ?>