Skip to content
Snippets Groups Projects
Commit 7116a121 authored by Maths Computer Science McS's avatar Maths Computer Science McS
Browse files

Fix missing semi-colon and other bugs, including one with context in PHP

parent a523c3a4
No related branches found
No related tags found
No related merge requests found
README.md 100644 → 100755
......@@ -28,7 +28,7 @@ To set up, you should upload the PAIL files to a PHP server and modify ```settin
| ```$pail_generate_command``` | The command used to generate the personalised assessment for the user. It will be passed the directory in which to store any generated files as its last command line argument. There are no checks that this program does only store files in the specified directory, so you should ensure you trust that this command will do the right thing.
| ```$pail_contact``` | The contact email people should be directed to if there are any issues
| ```$pail_reset``` | If false (the default), files are only generated the first time the learner visits the LTI tool (and simply displayed on subsequent visits). If true, the files are generated each time the learner visits.
| ```$pail_generated_dir``` | The subdirectory where files will be generated (defaults to "generated")
| ```$pail_generated_dir``` | The subdirectory where files will be generated (defaults to "generated") - note that you will need to change this in ```generate.sh``` if you change it here
| ```$pail_context_id``` | The key to use to get the context ID from the LTI context (defaults to "context_id", which should always be appropriate)
| ```$pail_user_id``` | The key to use to get the user ID from the LTI context (defaults to "user_id". To get student number at UNE, use "lis_person_sourcedid" instead)
| ```$pail_debug``` | Whether to output debug information with the page (defaults to false)
......
index.php 100644 → 100755
......@@ -5,14 +5,15 @@ require_once("lib/parsedown/Parsedown.php");
require_once("lib/lti/lti_util.php");
require_once("settings.php");
function debug($message, $variable) {
function debug($message, $variable, $pail_debug) {
if ($pail_debug) {
if ($message) {
echo $message;
echo $message . " ";
}
if ($variable) {
if (!is_null($variable)) {
var_dump($variable);
}
echo "<br />";
}
}
?>
......@@ -33,9 +34,10 @@ function debug($message, $variable) {
<body class="markdown-body">
<?php
debug("Starting...");
debug("Starting...", null, $pail_debug);
// Check if this is a valid LTI request
$valid_lti_request = is_lti_request();
debug("Valid LTI request:", $valid_lti_request, $pail_debug);
if ($valid_lti_request) {
$oauth_consumer_key = "";
$oauth_consumer_secret = "";
......@@ -45,8 +47,8 @@ function debug($message, $variable) {
$_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);
debug("oauth_consumer_key", $oauth_consumer_key, $pail_debug);
debug("oauth_consumer_secret", $oauth_consumer_secret, $pail_debug);
$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
......@@ -54,11 +56,14 @@ function debug($message, $variable) {
}
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);
debug("LTI message type should be 'basic-lti-launch-request'", $_REQUEST["lti_message_type"], $pail_debug);
debug("LTI version should be 'LTI-1p0'", $_REQUEST["lti_version"], $pail_debug);
debug("Ensure context id is alphanumeric only", $context->info[$pail_context_id], $pail_debug);
debug("Ensure user id is alphanumeric only", $context->info[$pail_user_id], $pail_debug);
debug("Invalid LTI context", $context, $pail_debug);
require("error_templates/not_lti.php");
} else {
debug("LTI Context: ", $context, $pail_debug);
// Determine name of file to display
$pail_dirname = getcwd() . DIRECTORY_SEPARATOR .
$pail_generated_dir . DIRECTORY_SEPARATOR .
......@@ -67,22 +72,22 @@ function debug($message, $variable) {
// 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));
debug("pail_filename:", $pail_filename, $pail_debug);
debug("pail_reset:", $pail_reset, $pail_debug);
debug("pail_filename exists: " . file_exists($pail_filename), null, $pail_debug);
// Generate file if necessary
if ($pail_reset || !file_exists($pail_filename)) {
debug("Generating:", $pail_filename);
debug("Generating:", $pail_filename, $pail_debug);
$output = null;
$retval = null;
$pail_command = "./generate.sh " .
"-c \"" . $context->info[$pail_context_id] . "\"" . " ".
"-u \"" . $context->info[$pail_user_id] . "\" " .
$pail_generate_command;
debug("Executing:", $pail_command);
debug("Executing:", $pail_command, $pail_debug);
exec($pail_command, $output, $retval);
debug("Output:", $output);
debug("retval", $retval);
debug("Output:", $output, $pail_debug);
debug("retval", $retval, $pail_debug);
}
// Attempt to read the file
......@@ -92,15 +97,15 @@ function debug($message, $variable) {
}
if ($file_contents === false) {
// Display error if unable to read file
debug("Unable to read file:", $file_contents);
debug("Unable to read file:", $file_contents, $pail_debug);
require("error_templates/file_unavailable.php");
// Display file
} else {
echo Parsedown::instance()->text($file_contents) . "\n";
}
}
debug("Finished", null, $pail_debug);
?>
<footer><small>Generated by <a href="https://gitlab.une.edu.au/dpaul4/pail">PAIL</a></small></footer>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment