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);
            }
        }
    }
    $title = "Successfully edited responses";
    $message = "<p>Successfully edited responses!</p>";
} catch (Exception $e) {
    $title = "Error editing responses";
    $message = sprintf("<p class=\"error\">Error editing responses: %s</p>", $e->getMessage());
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
<link rel="stylesheet" type="text/css" href="theme.css" />
Example #2
0
        $clue_ids[$i] = Database::add_clue($clue_text, $cat_id, $point_value, $wrong_point_value);
    }
    /* Step 3.  Add the responses */
    for ($i = 1; $i <= 5; $i++) {
        if (is_null($_POST["response{$i}"])) {
            continue;
        }
        $raw_response = $_POST["response{$i}"];
        if (!trim($raw_response)) {
            continue;
        }
        $responses = explode("\n", $_POST["response{$i}"]);
        foreach ($responses as $response) {
            $trimmed_response = trim($response);
            $correct = 1;
            Database::add_response($clue_ids[$i], $trimmed_response, $correct);
        }
    }
    $title = "Category added successfully";
    $message = "<p>Successfully added the category, clues, and responses!</p>";
} catch (Exception $e) {
    $title = "Error adding category";
    $message = sprintf("<p class=\"error\">Error adding category: %s</p>", $e->getMessage());
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
<link rel="stylesheet" type="text/css" href="theme.css" />
<link rel="icon" type="image/png" href="shcicon.png" />