} if (!$trial->addRecord()) { // Bind a record to the trial, if it fails then throw exception throw new Exception("No record is linked with this user, please try selecting a different record."); } if ($trial->user->isLocal()) { if ($trial->record->getCentre() != $trial->user->getCentre()) { // Ensure that a 'local' user isn't trying to manipulate someone else's record throw new Exception("You have tried to manipulate a record from another centre."); } } if ($trial->checkPageLogin($page)) { // Check that the user has the privilege to access this page switch ($_POST['request']) { case 'addFlag': $flag = $trial->addFlagInput($_POST); // Add form input to create a new flag if ($flag) { // If a new flag was produced, return it echo json_encode(array("message" => "Flag successfully added", "flag" => $flag)); } else { // Otherwise throw an error throw new Exception("Flag form not completely filled in, please try again."); } break; case 'clearFlag': $flag = new Flag($_POST['flag_id']); // Retrieve flag from DB and delete it $flag->deleteFromDB(); echo json_encode(array("message" => "Flag cleared")); break;