post data from edit_clue.php. */
require_once 'common.inc';
startpage(RESTRICTED);
try {
    if (!isset($_POST['id'])) {
        throw new Exception("No clue id specified.");
    }
    $clue_id = $_POST['id'];
    foreach ($_POST as $key => $value) {
        if (preg_match('/^responsetext([0-9]+)$/', $key, $matches)) {
            /* Update or delete an existing response */
            $resp_id = $matches[1];
            $grade = $_POST["responsegrade{$resp_id}"];
            if ($grade == 'correct' or $grade == 'incorrect') {
                $correct = $grade == 'correct';
                Database::update_response($resp_id, $value, $correct);
            } elseif ($grade == 'delete') {
                Database::delete_response($resp_id);
            }
        } elseif (preg_match('/^(new|added)responsetext([0-9]+)$/', $key, $matches)) {
            $new_or_added = $matches[1];
            $number = $matches[2];
            if (!isset($_POST["{$new_or_added}responsegrade{$number}"])) {
                continue;
            }
            $grade = $_POST["{$new_or_added}responsegrade{$number}"];
            if ($grade == 'correct' or $grade == 'incorrect') {
                $correct = $grade == 'correct';
                Database::add_response($clue_id, $value, $correct);
            }
        }