test_confirm.php 990 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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->dts_updated = Util::getDateTime();
  10. $test->commit();
  11. // TODO: Email/notification?
  12. Core::addAlert("success", "Test accepted successfully.");
  13. HTTP::redirect("/account/tests");
  14. break;
  15. case "decline":
  16. $test->status = Test::STATUS_UNASSIGNED;
  17. $test->tester_id = null;
  18. $test->dts_due = null;
  19. $test->dts_assigned = null;
  20. $test->dts_updated = Util::getDateTime();
  21. $test->commit();
  22. // TODO: Email/notification?
  23. Core::addAlert("success", "Test declined successfully.");
  24. HTTP::redirect("/account/tests");
  25. break;
  26. default:
  27. throw new Exception("Invalid action.");
  28. }
  29. ?>