Skip to content
Snippets Groups Projects
Commit aa63bf9a authored by David Paul's avatar David Paul
Browse files

Add debug information and more customisation

parent 9497b8e7
Branches
No related tags found
No related merge requests found
......@@ -4,6 +4,17 @@ session_start();
require_once("lib/parsedown/Parsedown.php");
require_once("lib/lti/lti_util.php");
require_once("settings.php");
function debug($message, $variable) {
if ($pail_debug) {
if ($message) {
echo $message;
}
if ($variable) {
var_dump($variable);
}
}
}
?>
<html lang="en">
<head>
......@@ -22,6 +33,7 @@ require_once("settings.php");
<body class="markdown-body">
<?php
debug("Starting...");
// Check if this is a valid LTI request
$valid_lti_request = is_lti_request();
if ($valid_lti_request) {
......@@ -33,32 +45,44 @@ require_once("settings.php");
$_SESSION["oauth_consumer_key"] = $oauth_consumer_key;
$_SESSION["oauth_consumer_secret"] = $oauth_consumer_secret;
}
debug("oauth_consumer_key", $oauth_consumer_key);
debug("oauth_consumer_secret", $oauth_consumer_secret);
$context = new BLTI($oauth_consumer_secret, true, false);
// Ensure context is valid and context_id and user_id are alphanumeric only
$valid_lti_request = $context->valid
&& ctype_alnum($context->info["context_id"]) && ctype_alnum($context->info["user_id"]);
&& ctype_alnum($context->info[$pail_context_id]) && ctype_alnum($context->info[$pail_user_id]);
}
if (!$valid_lti_request) {
// If not a valid LTI request, display an error
debug("Ensure context id is alphanumeric only", $context->info[$pail_context_id]);
debug("Ensure user id is alphanumeric only", $context->info[]$pail_user_id);
debug("Invalid LTI context", $context);
require("error_templates/not_lti.php");
} else {
// Determine name of file to display
$pail_dirname = getcwd() . DIRECTORY_SEPARATOR .
"generated" . DIRECTORY_SEPARATOR .
$context->info["context_id"] . DIRECTORY_SEPARATOR .
$context->info["user_id"] . DIRECTORY_SEPARATOR;
$pail_generated_dir . DIRECTORY_SEPARATOR .
$context->info[$pail_context_id] . DIRECTORY_SEPARATOR .
$context->info[$pail_user_id] . DIRECTORY_SEPARATOR;
// Default to display.md unless another file is requested
$pail_filename = isset($_REQUEST["display"]) ? $_REQUEST["display"] : "display.md";
$pail_filename = $pail_dirname . $pail_filename;
debug("pail_filename:", $pail_filename);
debug("pail_reset:", $pail_reset);
debug("pail_filename exists: " . file_exists($pail_filename));
// Generate file if necessary
if ($pail_reset || !file_exists($pail_filename)) {
debug("Generating:", $pail_filename);
$output = null;
$retval = null;
$pail_command = "./generate.sh " .
"-c \"" . $context->info["context_id"] . "\"" . " ".
"-u \"" . $context->info["user_id"] . "\" " .
"-c \"" . $context->info[$pail_context_id] . "\"" . " ".
"-u \"" . $context->info[$pail_user_id] . "\" " .
$pail_generate_command;
debug("Executing:", $pail_command);
exec($pail_command, $output, $retval);
debug("Output:", $output);
debug("retval", $retval);
}
// Attempt to read the file
......@@ -68,6 +92,7 @@ require_once("settings.php");
}
if ($file_contents === false) {
// Display error if unable to read file
debug("Unable to read file:", $file_contents);
require("error_templates/file_unavailable.php");
// Display file
} else {
......
......@@ -8,6 +8,9 @@ $pail_title = "Personalising Assessment for Individualised Learning";
// A short description of the page generated by PAIL.
$pail_description = "Personalising assessment for individualised learning";
// The subdirectory where assessments are generated
$pail_generated_dir = "generated"
// The command to execute to generate files.
// It will be passed a final parameter that is the directory in which all files should be generated.
$pail_generate_command = "python3 example.py";
......@@ -18,4 +21,14 @@ $pail_contact = "pail@example.edu";
// If true, files are regenerated each time a user visits the site.
// If false, files are only generated the first time (and then redisplayed on subsequent visits).
$pail_reset = false;
// The key to use to get the context id from the LTI context
$pail_context_id = "context_id";
// The key to use to get the user id from the LTI context
$pail_user_id = "user_id";
// If true, prints out some debug information with the assessment page
// If false, no debug information is printed on the assessment page
$pail_debug = false;
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment