From b7e436b0373ea6fb377c4d4b7003d38586fb1847 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Thu, 25 Aug 2011 12:38:12 -0400 Subject: [PATCH 01/78] Adding basiclti plugin --- mod/basiclti/OAuth.php | 839 ++++++++++++++ mod/basiclti/TODO.txt | 0 mod/basiclti/TrivialStore.php | 105 ++ .../backup_basiclti_activity_task.class.php | 91 ++ .../moodle2/backup_basiclti_stepslib.php | 87 ++ .../restore_basiclti_activity_task.class.php | 131 +++ .../moodle2/restore_basiclti_stepslib.php | 101 ++ mod/basiclti/basiclti.js | 56 + mod/basiclti/db/access.php | 71 ++ mod/basiclti/db/install.xml | 81 ++ mod/basiclti/db/log.php | 0 mod/basiclti/db/upgrade.php | 241 ++++ mod/basiclti/edit_form.php | 227 ++++ mod/basiclti/index.php | 121 ++ mod/basiclti/lang/en/basiclti.php | 162 +++ mod/basiclti/lang/en/help/basiclti/index.html | 1 + mod/basiclti/lang/en/help/basiclti/mods.html | 1 + mod/basiclti/launch.php | 85 ++ mod/basiclti/lib.php | 1010 +++++++++++++++++ mod/basiclti/localadminlib.php | 85 ++ mod/basiclti/locallib.php | 757 ++++++++++++ mod/basiclti/mod_form.php | 481 ++++++++ mod/basiclti/pix/icon.gif | Bin 0 -> 1982 bytes mod/basiclti/service.php | 391 +++++++ mod/basiclti/settings.php | 100 ++ mod/basiclti/simpletest/testlocallib.php | 89 ++ mod/basiclti/styles.css | 29 + mod/basiclti/submissions.php | 92 ++ mod/basiclti/typessettings.php | 258 +++++ mod/basiclti/version.php | 50 + mod/basiclti/view.php | 132 +++ 31 files changed, 5874 insertions(+) create mode 100644 mod/basiclti/OAuth.php create mode 100644 mod/basiclti/TODO.txt create mode 100644 mod/basiclti/TrivialStore.php create mode 100644 mod/basiclti/backup/moodle2/backup_basiclti_activity_task.class.php create mode 100644 mod/basiclti/backup/moodle2/backup_basiclti_stepslib.php create mode 100644 mod/basiclti/backup/moodle2/restore_basiclti_activity_task.class.php create mode 100644 mod/basiclti/backup/moodle2/restore_basiclti_stepslib.php create mode 100644 mod/basiclti/basiclti.js create mode 100644 mod/basiclti/db/access.php create mode 100644 mod/basiclti/db/install.xml create mode 100644 mod/basiclti/db/log.php create mode 100644 mod/basiclti/db/upgrade.php create mode 100644 mod/basiclti/edit_form.php create mode 100644 mod/basiclti/index.php create mode 100644 mod/basiclti/lang/en/basiclti.php create mode 100644 mod/basiclti/lang/en/help/basiclti/index.html create mode 100644 mod/basiclti/lang/en/help/basiclti/mods.html create mode 100644 mod/basiclti/launch.php create mode 100644 mod/basiclti/lib.php create mode 100644 mod/basiclti/localadminlib.php create mode 100644 mod/basiclti/locallib.php create mode 100644 mod/basiclti/mod_form.php create mode 100644 mod/basiclti/pix/icon.gif create mode 100644 mod/basiclti/service.php create mode 100644 mod/basiclti/settings.php create mode 100644 mod/basiclti/simpletest/testlocallib.php create mode 100644 mod/basiclti/styles.css create mode 100644 mod/basiclti/submissions.php create mode 100644 mod/basiclti/typessettings.php create mode 100644 mod/basiclti/version.php create mode 100644 mod/basiclti/view.php diff --git a/mod/basiclti/OAuth.php b/mod/basiclti/OAuth.php new file mode 100644 index 00000000000..9c9d9637818 --- /dev/null +++ b/mod/basiclti/OAuth.php @@ -0,0 +1,839 @@ +. + +defined('MOODLE_INTERNAL') || die; + +$oauth_last_computed_signature = false; + +/* Generic exception class + */ +class OAuthException extends Exception { + // pass +} + +class OAuthConsumer { + public $key; + public $secret; + + function __construct($key, $secret, $callback_url = null) { + $this->key = $key; + $this->secret = $secret; + $this->callback_url = $callback_url; + } + + function __toString() { + return "OAuthConsumer[key=$this->key,secret=$this->secret]"; + } +} + +class OAuthToken { + // access tokens and request tokens + public $key; + public $secret; + + /** + * key = the token + * secret = the token secret + */ + function __construct($key, $secret) { + $this->key = $key; + $this->secret = $secret; + } + + /** + * generates the basic string serialization of a token that a server + * would respond to request_token and access_token calls with + */ + function to_string() { + return "oauth_token=" . + OAuthUtil::urlencode_rfc3986($this->key) . + "&oauth_token_secret=" . + OAuthUtil::urlencode_rfc3986($this->secret); + } + + function __toString() { + return $this->to_string(); + } +} + +class OAuthSignatureMethod { + public function check_signature(&$request, $consumer, $token, $signature) { + $built = $this->build_signature($request, $consumer, $token); + return $built == $signature; + } +} + +class OAuthSignatureMethod_HMAC_SHA1 extends OAuthSignatureMethod { + function get_name() { + return "HMAC-SHA1"; + } + + public function build_signature($request, $consumer, $token) { + global $oauth_last_computed_signature; + $oauth_last_computed_signature = false; + + $base_string = $request->get_signature_base_string(); + $request->base_string = $base_string; + + $key_parts = array( + $consumer->secret, + ($token) ? $token->secret : "" + ); + + $key_parts = OAuthUtil::urlencode_rfc3986($key_parts); + $key = implode('&', $key_parts); + + $computed_signature = base64_encode(hash_hmac('sha1', $base_string, $key, true)); + $oauth_last_computed_signature = $computed_signature; + return $computed_signature; + } + +} + +class OAuthSignatureMethod_PLAINTEXT extends OAuthSignatureMethod { + public function get_name() { + return "PLAINTEXT"; + } + + public function build_signature($request, $consumer, $token) { + $sig = array( + OAuthUtil::urlencode_rfc3986($consumer->secret) + ); + + if ($token) { + array_push($sig, OAuthUtil::urlencode_rfc3986($token->secret)); + } else { + array_push($sig, ''); + } + + $raw = implode("&", $sig); + // for debug purposes + $request->base_string = $raw; + + return OAuthUtil::urlencode_rfc3986($raw); + } +} + +class OAuthSignatureMethod_RSA_SHA1 extends OAuthSignatureMethod { + public function get_name() { + return "RSA-SHA1"; + } + + protected function fetch_public_cert(&$request) { + // not implemented yet, ideas are: + // (1) do a lookup in a table of trusted certs keyed off of consumer + // (2) fetch via http using a url provided by the requester + // (3) some sort of specific discovery code based on request + // + // either way should return a string representation of the certificate + throw Exception("fetch_public_cert not implemented"); + } + + protected function fetch_private_cert(&$request) { + // not implemented yet, ideas are: + // (1) do a lookup in a table of trusted certs keyed off of consumer + // + // either way should return a string representation of the certificate + throw Exception("fetch_private_cert not implemented"); + } + + public function build_signature(&$request, $consumer, $token) { + $base_string = $request->get_signature_base_string(); + $request->base_string = $base_string; + + // Fetch the private key cert based on the request + $cert = $this->fetch_private_cert($request); + + // Pull the private key ID from the certificate + $privatekeyid = openssl_get_privatekey($cert); + + // Sign using the key + $ok = openssl_sign($base_string, $signature, $privatekeyid); + + // Release the key resource + openssl_free_key($privatekeyid); + + return base64_encode($signature); + } + + public function check_signature(&$request, $consumer, $token, $signature) { + $decoded_sig = base64_decode($signature); + + $base_string = $request->get_signature_base_string(); + + // Fetch the public key cert based on the request + $cert = $this->fetch_public_cert($request); + + // Pull the public key ID from the certificate + $publickeyid = openssl_get_publickey($cert); + + // Check the computed signature against the one passed in the query + $ok = openssl_verify($base_string, $decoded_sig, $publickeyid); + + // Release the key resource + openssl_free_key($publickeyid); + + return $ok == 1; + } +} + +class OAuthRequest { + private $parameters; + private $http_method; + private $http_url; + // for debug purposes + public $base_string; + public static $version = '1.0'; + public static $POST_INPUT = 'php://input'; + + function __construct($http_method, $http_url, $parameters = null) { + @$parameters or $parameters = array(); + $this->parameters = $parameters; + $this->http_method = $http_method; + $this->http_url = $http_url; + } + + /** + * attempt to build up a request from what was passed to the server + */ + public static function from_request($http_method = null, $http_url = null, $parameters = null) { + $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on") ? 'http' : 'https'; + $port = ""; + if ($_SERVER['SERVER_PORT'] != "80" && $_SERVER['SERVER_PORT'] != "443" && strpos(':', $_SERVER['HTTP_HOST']) < 0) { + $port = ':' . $_SERVER['SERVER_PORT']; + } + @$http_url or $http_url = $scheme . + '://' . $_SERVER['HTTP_HOST'] . + $port . + $_SERVER['REQUEST_URI']; + @$http_method or $http_method = $_SERVER['REQUEST_METHOD']; + + // We weren't handed any parameters, so let's find the ones relevant to + // this request. + // If you run XML-RPC or similar you should use this to provide your own + // parsed parameter-list + if (!$parameters) { + // Find request headers + $request_headers = OAuthUtil::get_headers(); + + // Parse the query-string to find GET parameters + $parameters = OAuthUtil::parse_parameters($_SERVER['QUERY_STRING']); + + $ourpost = $_POST; + // Deal with magic_quotes + // http://www.php.net/manual/en/security.magicquotes.disabling.php + if (get_magic_quotes_gpc()) { + $outpost = array(); + foreach ($_POST as $k => $v) { + $v = stripslashes($v); + $ourpost[$k] = $v; + } + } + // Add POST Parameters if they exist + $parameters = array_merge($parameters, $ourpost); + + // We have a Authorization-header with OAuth data. Parse the header + // and add those overriding any duplicates from GET or POST + if (@substr($request_headers['Authorization'], 0, 6) == "OAuth ") { + $header_parameters = OAuthUtil::split_header($request_headers['Authorization']); + $parameters = array_merge($parameters, $header_parameters); + } + + } + + return new OAuthRequest($http_method, $http_url, $parameters); + } + + /** + * pretty much a helper function to set up the request + */ + public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters = null) { + @$parameters or $parameters = array(); + $defaults = array( + "oauth_version" => self::$version, + "oauth_nonce" => self::generate_nonce(), + "oauth_timestamp" => self::generate_timestamp(), + "oauth_consumer_key" => $consumer->key + ); + if ($token) { + $defaults['oauth_token'] = $token->key; + } + + $parameters = array_merge($defaults, $parameters); + + // Parse the query-string to find and add GET parameters + $parts = parse_url($http_url); + if (isset($parts['query'])) { + $qparms = OAuthUtil::parse_parameters($parts['query']); + $parameters = array_merge($qparms, $parameters); + } + + return new OAuthRequest($http_method, $http_url, $parameters); + } + + public function set_parameter($name, $value, $allow_duplicates = true) { + if ($allow_duplicates && isset($this->parameters[$name])) { + // We have already added parameter(s) with this name, so add to the list + if (is_scalar($this->parameters[$name])) { + // This is the first duplicate, so transform scalar (string) + // into an array so we can add the duplicates + $this->parameters[$name] = array($this->parameters[$name]); + } + + $this->parameters[$name][] = $value; + } else { + $this->parameters[$name] = $value; + } + } + + public function get_parameter($name) { + return isset($this->parameters[$name]) ? $this->parameters[$name] : null; + } + + public function get_parameters() { + return $this->parameters; + } + + public function unset_parameter($name) { + unset($this->parameters[$name]); + } + + /** + * The request parameters, sorted and concatenated into a normalized string. + * @return string + */ + public function get_signable_parameters() { + // Grab all parameters + $params = $this->parameters; + + // Remove oauth_signature if present + // Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.") + if (isset($params['oauth_signature'])) { + unset($params['oauth_signature']); + } + + return OAuthUtil::build_http_query($params); + } + + /** + * Returns the base string of this request + * + * The base string defined as the method, the url + * and the parameters (normalized), each urlencoded + * and the concated with &. + */ + public function get_signature_base_string() { + $parts = array( + $this->get_normalized_http_method(), + $this->get_normalized_http_url(), + $this->get_signable_parameters() + ); + + $parts = OAuthUtil::urlencode_rfc3986($parts); + + return implode('&', $parts); + } + + /** + * just uppercases the http method + */ + public function get_normalized_http_method() { + return strtoupper($this->http_method); + } + + /** + * parses the url and rebuilds it to be + * scheme://host/path + */ + public function get_normalized_http_url() { + $parts = parse_url($this->http_url); + + $port = @$parts['port']; + $scheme = $parts['scheme']; + $host = $parts['host']; + $path = @$parts['path']; + + $port or $port = ($scheme == 'https') ? '443' : '80'; + + if (($scheme == 'https' && $port != '443') || ($scheme == 'http' && $port != '80')) { + $host = "$host:$port"; + } + return "$scheme://$host$path"; + } + + /** + * builds a url usable for a GET request + */ + public function to_url() { + $post_data = $this->to_postdata(); + $out = $this->get_normalized_http_url(); + if ($post_data) { + $out .= '?'.$post_data; + } + return $out; + } + + /** + * builds the data one would send in a POST request + */ + public function to_postdata() { + return OAuthUtil::build_http_query($this->parameters); + } + + /** + * builds the Authorization: header + */ + public function to_header() { + $out = 'Authorization: OAuth realm=""'; + $total = array(); + foreach ($this->parameters as $k => $v) { + if (substr($k, 0, 5) != "oauth") { + continue; + } + if (is_array($v)) { + throw new OAuthException('Arrays not supported in headers'); + } + $out .= ',' . + OAuthUtil::urlencode_rfc3986($k) . + '="' . + OAuthUtil::urlencode_rfc3986($v) . + '"'; + } + return $out; + } + + public function __toString() { + return $this->to_url(); + } + + public function sign_request($signature_method, $consumer, $token) { + $this->set_parameter("oauth_signature_method", $signature_method->get_name(), false); + $signature = $this->build_signature($signature_method, $consumer, $token); + $this->set_parameter("oauth_signature", $signature, false); + } + + public function build_signature($signature_method, $consumer, $token) { + $signature = $signature_method->build_signature($this, $consumer, $token); + return $signature; + } + + /** + * util function: current timestamp + */ + private static function generate_timestamp() { + return time(); + } + + /** + * util function: current nonce + */ + private static function generate_nonce() { + $mt = microtime(); + $rand = mt_rand(); + + return md5($mt.$rand); // md5s look nicer than numbers + } +} + +class OAuthServer { + protected $timestamp_threshold = 300; // in seconds, five minutes + protected $version = 1.0; // hi blaine + protected $signature_methods = array(); + protected $data_store; + + function __construct($data_store) { + $this->data_store = $data_store; + } + + public function add_signature_method($signature_method) { + $this->signature_methods[$signature_method->get_name()] = $signature_method; + } + + // high level functions + + /** + * process a request_token request + * returns the request token on success + */ + public function fetch_request_token(&$request) { + $this->get_version($request); + + $consumer = $this->get_consumer($request); + + // no token required for the initial token request + $token = null; + + $this->check_signature($request, $consumer, $token); + + $new_token = $this->data_store->new_request_token($consumer); + + return $new_token; + } + + /** + * process an access_token request + * returns the access token on success + */ + public function fetch_access_token(&$request) { + $this->get_version($request); + + $consumer = $this->get_consumer($request); + + // requires authorized request token + $token = $this->get_token($request, $consumer, "request"); + + $this->check_signature($request, $consumer, $token); + + $new_token = $this->data_store->new_access_token($token, $consumer); + + return $new_token; + } + + /** + * verify an api call, checks all the parameters + */ + public function verify_request(&$request) { + global $oauth_last_computed_signature; + $oauth_last_computed_signature = false; + $this->get_version($request); + $consumer = $this->get_consumer($request); + $token = $this->get_token($request, $consumer, "access"); + $this->check_signature($request, $consumer, $token); + return array( + $consumer, + $token + ); + } + + // Internals from here + /** + * version 1 + */ + private function get_version(&$request) { + $version = $request->get_parameter("oauth_version"); + if (!$version) { + $version = 1.0; + } + if ($version && $version != $this->version) { + throw new OAuthException("OAuth version '$version' not supported"); + } + return $version; + } + + /** + * figure out the signature with some defaults + */ + private function get_signature_method(&$request) { + $signature_method = @ $request->get_parameter("oauth_signature_method"); + if (!$signature_method) { + $signature_method = "PLAINTEXT"; + } + if (!in_array($signature_method, array_keys($this->signature_methods))) { + throw new OAuthException("Signature method '$signature_method' not supported " . + "try one of the following: " . + implode(", ", array_keys($this->signature_methods))); + } + return $this->signature_methods[$signature_method]; + } + + /** + * try to find the consumer for the provided request's consumer key + */ + private function get_consumer(&$request) { + $consumer_key = @ $request->get_parameter("oauth_consumer_key"); + if (!$consumer_key) { + throw new OAuthException("Invalid consumer key"); + } + + $consumer = $this->data_store->lookup_consumer($consumer_key); + if (!$consumer) { + throw new OAuthException("Invalid consumer"); + } + + return $consumer; + } + + /** + * try to find the token for the provided request's token key + */ + private function get_token(&$request, $consumer, $token_type = "access") { + $token_field = @ $request->get_parameter('oauth_token'); + if (!$token_field) { + return false; + } + $token = $this->data_store->lookup_token($consumer, $token_type, $token_field); + if (!$token) { + throw new OAuthException("Invalid $token_type token: $token_field"); + } + return $token; + } + + /** + * all-in-one function to check the signature on a request + * should guess the signature method appropriately + */ + private function check_signature(&$request, $consumer, $token) { + // this should probably be in a different method + global $oauth_last_computed_signature; + $oauth_last_computed_signature = false; + + $timestamp = @ $request->get_parameter('oauth_timestamp'); + $nonce = @ $request->get_parameter('oauth_nonce'); + + $this->check_timestamp($timestamp); + $this->check_nonce($consumer, $token, $nonce, $timestamp); + + $signature_method = $this->get_signature_method($request); + + $signature = $request->get_parameter('oauth_signature'); + $valid_sig = $signature_method->check_signature($request, $consumer, $token, $signature); + + if (!$valid_sig) { + $ex_text = "Invalid signature"; + if ($oauth_last_computed_signature) { + $ex_text = $ex_text . " ours= $oauth_last_computed_signature yours=$signature"; + } + throw new OAuthException($ex_text); + } + } + + /** + * check that the timestamp is new enough + */ + private function check_timestamp($timestamp) { + // verify that timestamp is recentish + $now = time(); + if ($now - $timestamp > $this->timestamp_threshold) { + throw new OAuthException("Expired timestamp, yours $timestamp, ours $now"); + } + } + + /** + * check that the nonce is not repeated + */ + private function check_nonce($consumer, $token, $nonce, $timestamp) { + // verify that the nonce is uniqueish + $found = $this->data_store->lookup_nonce($consumer, $token, $nonce, $timestamp); + if ($found) { + throw new OAuthException("Nonce already used: $nonce"); + } + } + +} + +class OAuthDataStore { + function lookup_consumer($consumer_key) { + // implement me + } + + function lookup_token($consumer, $token_type, $token) { + // implement me + } + + function lookup_nonce($consumer, $token, $nonce, $timestamp) { + // implement me + } + + function new_request_token($consumer) { + // return a new token attached to this consumer + } + + function new_access_token($token, $consumer) { + // return a new access token attached to this consumer + // for the user associated with this token if the request token + // is authorized + // should also invalidate the request token + } + +} + +class OAuthUtil { + public static function urlencode_rfc3986($input) { + if (is_array($input)) { + return array_map(array( + 'OAuthUtil', + 'urlencode_rfc3986' + ), $input); + } else { + if (is_scalar($input)) { + return str_replace('+', ' ', str_replace('%7E', '~', rawurlencode($input))); + } else { + return ''; + } + } + } + + // This decode function isn't taking into consideration the above + // modifications to the encoding process. However, this method doesn't + // seem to be used anywhere so leaving it as is. + public static function urldecode_rfc3986($string) { + return urldecode($string); + } + + // Utility function for turning the Authorization: header into + // parameters, has to do some unescaping + // Can filter out any non-oauth parameters if needed (default behaviour) + public static function split_header($header, $only_allow_oauth_parameters = true) { + $pattern = '/(([-_a-z]*)=("([^"]*)"|([^,]*)),?)/'; + $offset = 0; + $params = array(); + while (preg_match($pattern, $header, $matches, PREG_OFFSET_CAPTURE, $offset) > 0) { + $match = $matches[0]; + $header_name = $matches[2][0]; + $header_content = (isset($matches[5])) ? $matches[5][0] : $matches[4][0]; + if (preg_match('/^oauth_/', $header_name) || !$only_allow_oauth_parameters) { + $params[$header_name] = self::urldecode_rfc3986($header_content); + } + $offset = $match[1] + strlen($match[0]); + } + + if (isset($params['realm'])) { + unset($params['realm']); + } + + return $params; + } + + // helper to try to sort out headers for people who aren't running apache + public static function get_headers() { + if (function_exists('apache_request_headers')) { + // we need this to get the actual Authorization: header + // because apache tends to tell us it doesn't exist + return apache_request_headers(); + } + // otherwise we don't have apache and are just going to have to hope + // that $_SERVER actually contains what we need + $out = array(); + foreach ($_SERVER as $key => $value) { + if (substr($key, 0, 5) == "HTTP_") { + // this is chaos, basically it is just there to capitalize the first + // letter of every word that is not an initial HTTP and strip HTTP + // code from przemek + $key = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($key, 5))))); + $out[$key] = $value; + } + } + return $out; + } + + // This function takes a input like a=b&a=c&d=e and returns the parsed + // parameters like this + // array('a' => array('b','c'), 'd' => 'e') + public static function parse_parameters($input) { + if (!isset($input) || !$input) { + return array(); + } + + $pairs = explode('&', $input); + + $parsed_parameters = array(); + foreach ($pairs as $pair) { + $split = explode('=', $pair, 2); + $parameter = self::urldecode_rfc3986($split[0]); + $value = isset($split[1]) ? self::urldecode_rfc3986($split[1]) : ''; + + if (isset($parsed_parameters[$parameter])) { + // We have already recieved parameter(s) with this name, so add to the list + // of parameters with this name + + if (is_scalar($parsed_parameters[$parameter])) { + // This is the first duplicate, so transform scalar (string) into an array + // so we can add the duplicates + $parsed_parameters[$parameter] = array( + $parsed_parameters[$parameter] + ); + } + + $parsed_parameters[$parameter][] = $value; + } else { + $parsed_parameters[$parameter] = $value; + } + } + return $parsed_parameters; + } + + public static function build_http_query($params) { + if (!$params) { + return ''; + } + + // Urlencode both keys and values + $keys = self::urlencode_rfc3986(array_keys($params)); + $values = self::urlencode_rfc3986(array_values($params)); + $params = array_combine($keys, $values); + + // Parameters are sorted by name, using lexicographical byte value ordering. + // Ref: Spec: 9.1.1 (1) + uksort($params, 'strcmp'); + + $pairs = array(); + foreach ($params as $parameter => $value) { + if (is_array($value)) { + // If two or more parameters share the same name, they are sorted by their value + // Ref: Spec: 9.1.1 (1) + natsort($value); + foreach ($value as $duplicate_value) { + $pairs[] = $parameter . '=' . $duplicate_value; + } + } else { + $pairs[] = $parameter . '=' . $value; + } + } + // For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61) + // Each name-value pair is separated by an '&' character (ASCII code 38) + return implode('&', $pairs); + } +} \ No newline at end of file diff --git a/mod/basiclti/TODO.txt b/mod/basiclti/TODO.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/mod/basiclti/TrivialStore.php b/mod/basiclti/TrivialStore.php new file mode 100644 index 00000000000..05eb9fc4721 --- /dev/null +++ b/mod/basiclti/TrivialStore.php @@ -0,0 +1,105 @@ +. + +/** + * This file contains a Trivial memory-based store - no support for tokens + * + * @package basiclti + * @copyright IMS Global Learning Consortium + * + * @author Charles Severance csev@umich.edu + * + * @license http://www.apache.org/licenses/LICENSE-2.0 + */ + +defined('MOODLE_INTERNAL') || die; + +/** + * A Trivial memory-based store - no support for tokens + */ +class TrivialOAuthDataStore extends OAuthDataStore { + private $consumers = array(); + + function add_consumer($consumer_key, $consumer_secret) { + $this->consumers[$consumer_key] = $consumer_secret; + } + + function lookup_consumer($consumer_key) { + if ( strpos($consumer_key, "http://" ) === 0 ) { + $consumer = new OAuthConsumer($consumer_key, "secret", null); + return $consumer; + } + if ( $this->consumers[$consumer_key] ) { + $consumer = new OAuthConsumer($consumer_key, $this->consumers[$consumer_key], null); + return $consumer; + } + return null; + } + + function lookup_token($consumer, $token_type, $token) { + return new OAuthToken($consumer, ""); + } + + // Return NULL if the nonce has not been used + // Return $nonce if the nonce was previously used + function lookup_nonce($consumer, $token, $nonce, $timestamp) { + // Should add some clever logic to keep nonces from + // being reused - for no we are really trusting + // that the timestamp will save us + return null; + } + + function new_request_token($consumer) { + return null; + } + + function new_access_token($token, $consumer) { + return null; + } +} diff --git a/mod/basiclti/backup/moodle2/backup_basiclti_activity_task.class.php b/mod/basiclti/backup/moodle2/backup_basiclti_activity_task.class.php new file mode 100644 index 00000000000..4c142637ba6 --- /dev/null +++ b/mod/basiclti/backup/moodle2/backup_basiclti_activity_task.class.php @@ -0,0 +1,91 @@ +. + + +/** + * This file contains the basiclti module backup class + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once($CFG->dirroot . '/mod/basiclti/backup/moodle2/backup_basiclti_stepslib.php'); + +/** + * basiclti backup task that provides all the settings and steps to perform one + * complete backup of the module + */ +class backup_basiclti_activity_task extends backup_activity_task { + + /** + * Define (add) particular settings this activity can have + */ + protected function define_my_settings() { + // No particular settings for this activity + } + + /** + * Define (add) particular steps this activity can have + */ + protected function define_my_steps() { + // Choice only has one structure step + $this->add_step(new backup_basiclti_activity_structure_step('basiclti_structure', 'basiclti.xml')); + } + + /** + * Code the transformations to perform in the activity in + * order to get transportable (encoded) links + */ + static public function encode_content_links($content) { + global $CFG; + + $base = preg_quote($CFG->wwwroot, "/"); + + // Link to the list of basiclti tools + $search="/(".$base."\/mod\/basiclti\/index.php\?id\=)([0-9]+)/"; + $content= preg_replace($search, '$@BASICLTIINDEX*$2@$', $content); + + // Link to basiclti view by moduleid + $search="/(".$base."\/mod\/basiclti\/view.php\?id\=)([0-9]+)/"; + $content= preg_replace($search, '$@BASICLTIVIEWBYID*$2@$', $content); + + return $content; + } +} diff --git a/mod/basiclti/backup/moodle2/backup_basiclti_stepslib.php b/mod/basiclti/backup/moodle2/backup_basiclti_stepslib.php new file mode 100644 index 00000000000..768e3ca6590 --- /dev/null +++ b/mod/basiclti/backup/moodle2/backup_basiclti_stepslib.php @@ -0,0 +1,87 @@ +. + +/** + * This file contains all the backup steps that will be used + * by the backup_basiclti_activity_task + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Define all the backup steps that will be used by the backup_basiclti_activity_task + */ + +/** + * Define the complete assignment structure for backup, with file and id annotations + */ +class backup_basiclti_activity_structure_step extends backup_activity_structure_step { + + protected function define_structure() { + + // To know if we are including userinfo + $userinfo = $this->get_setting_value('userinfo'); + + // Define each element separated + $basiclti = new backup_nested_element('basiclti', array('id'), array( + 'name', 'intro', 'introformat', 'timecreated', 'timemodified', + 'typeid', 'toolurl', 'preferheight', 'instructorchoiccesendname', + 'instructorchoicesendemailaddr', 'organizationid', + 'organizationurl', 'organizationdescr', 'launchinpopup', + 'debuglaunch', 'instructorchoiceacceptgrades', 'instructorchoiceallowroster', + 'instructorchoiceallowsetting', 'grade', 'instructorcustomparameters')); + + // Build the tree + // (none) + + // Define sources + $basiclti->set_source_table('basiclti', array('id' => backup::VAR_ACTIVITYID)); + + // Define id annotations + // (none) + + // Define file annotations + $basiclti->annotate_files('mod_basiclti', 'intro', null); // This file areas haven't itemid + + // Return the root element (basiclti), wrapped into standard activity structure + return $this->prepare_activity_structure($basiclti); + } +} diff --git a/mod/basiclti/backup/moodle2/restore_basiclti_activity_task.class.php b/mod/basiclti/backup/moodle2/restore_basiclti_activity_task.class.php new file mode 100644 index 00000000000..4f8b12f3071 --- /dev/null +++ b/mod/basiclti/backup/moodle2/restore_basiclti_activity_task.class.php @@ -0,0 +1,131 @@ +. + +/** + * This file contains the basicLTI module restore class + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +defined('MOODLE_INTERNAL') || die(); + +require_once($CFG->dirroot . '/mod/basiclti/backup/moodle2/restore_basiclti_stepslib.php'); // Because it exists (must) + +/** + * basiclti restore task that provides all the settings and steps to perform one + * complete restore of the activity + */ +class restore_basiclti_activity_task extends restore_activity_task { + + /** + * Define (add) particular settings this activity can have + */ + protected function define_my_settings() { + // No particular settings for this activity + } + + /** + * Define (add) particular steps this activity can have + */ + protected function define_my_steps() { + // label only has one structure step + $this->add_step(new restore_basiclti_activity_structure_step('basiclti_structure', 'basiclti.xml')); + } + + /** + * Define the contents in the activity that must be + * processed by the link decoder + */ + static public function define_decode_contents() { + $contents = array(); + + $contents[] = new restore_decode_content('basiclti', array('intro'), 'basiclti'); + + return $contents; + } + + /** + * Define the decoding rules for links belonging + * to the activity to be executed by the link decoder + */ + static public function define_decode_rules() { + $rules = array(); + + $rules[] = new restore_decode_rule('BASICLTIVIEWBYID', '/mod/basiclti/view.php?id=$1', 'course_module'); + $rules[] = new restore_decode_rule('BASICLTIINDEX', '/mod/basiclti/index.php?id=$1', 'course'); + + return $rules; + + } + + /** + * Define the restore log rules that will be applied + * by the {@link restore_logs_processor} when restoring + * basiclti logs. It must return one array + * of {@link restore_log_rule} objects + */ + static public function define_restore_log_rules() { + $rules = array(); + + $rules[] = new restore_log_rule('basiclti', 'add', 'view.php?id={course_module}', '{basiclti}'); + $rules[] = new restore_log_rule('basiclti', 'update', 'view.php?id={course_module}', '{basiclti}'); + $rules[] = new restore_log_rule('basiclti', 'view', 'view.php?id={course_module}', '{basiclti}'); + + return $rules; + } + + /** + * Define the restore log rules that will be applied + * by the {@link restore_logs_processor} when restoring + * course logs. It must return one array + * of {@link restore_log_rule} objects + * + * Note this rules are applied when restoring course logs + * by the restore final task, but are defined here at + * activity level. All them are rules not linked to any module instance (cmid = 0) + */ + static public function define_restore_log_rules_for_course() { + $rules = array(); + + $rules[] = new restore_log_rule('basiclti', 'view all', 'index.php?id={course}', null); + + return $rules; + } +} diff --git a/mod/basiclti/backup/moodle2/restore_basiclti_stepslib.php b/mod/basiclti/backup/moodle2/restore_basiclti_stepslib.php new file mode 100644 index 00000000000..566c463c83e --- /dev/null +++ b/mod/basiclti/backup/moodle2/restore_basiclti_stepslib.php @@ -0,0 +1,101 @@ +. + + +/** + * This file contains all the restore steps that will be used + * by the restore_basiclti_activity_task + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Define all the restore steps that will be used by the restore_basiclti_activity_task + */ + +/** + * Structure step to restore one basiclti activity + */ +class restore_basiclti_activity_structure_step extends restore_activity_structure_step { + + protected function define_structure() { + + $paths = array(); + $paths[] = new restore_path_element('basiclti', '/activity/basiclti'); + + // Return the paths wrapped into standard activity structure + return $this->prepare_activity_structure($paths); + } + + protected function process_basiclti($data) { + global $DB; + + $data = (object)$data; + $oldid = $data->id; + $data->course = $this->get_courseid(); + + // insert the basiclti record + $newitemid = $DB->insert_record('basiclti', $data); + // immediately after inserting "activity" record, call this + $this->apply_activity_instance($newitemid); + } + + protected function after_execute() { + global $DB; + + $basicltis = $DB->get_records('basiclti'); + foreach ($basicltis as $basiclti) { + if (!$DB->get_record('basiclti_types_config', + array('typeid' => $basiclti->typeid, 'name' => 'toolurl', 'value' => $basiclti->toolurl))) { + + $basiclti->typeid = 0; + } + + $basiclti->placementsecret = uniqid('', true); + $basiclti->timeplacementsecret = time(); + + $DB->update_record('basiclti', $basiclti); + } + + // Add basiclti related files, no need to match by itemname (just internally handled context) + $this->add_related_files('mod_basiclti', 'intro', null); + } +} diff --git a/mod/basiclti/basiclti.js b/mod/basiclti/basiclti.js new file mode 100644 index 00000000000..be112a0ab3d --- /dev/null +++ b/mod/basiclti/basiclti.js @@ -0,0 +1,56 @@ +// This file is part of BasicLTI4Moodle +// +// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) +// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web +// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI +// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS +// are already supporting or going to support BasicLTI. This project Implements the consumer +// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas. +// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem +// at the GESSI research group at UPC. +// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI +// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a +// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier. +// +// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis +// of the Universitat Politecnica de Catalunya http://www.upc.edu +// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * This file contains a library of javasxript functions for the BasicLTI module + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @author Charles Severance + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +function basicltiDebugToggle() { + var ele = document.getElementById('basicltiDebug'); + if(ele.style.display == ''block') { + ele.style.display = 'none'; + } + else { + ele.style.display = 'block'; + } +} diff --git a/mod/basiclti/db/access.php b/mod/basiclti/db/access.php new file mode 100644 index 00000000000..341461f19ff --- /dev/null +++ b/mod/basiclti/db/access.php @@ -0,0 +1,71 @@ +: +// +// component_name should be the same as the directory name of the mod or block. +// +// Core moodle capabilities are defined thus: +// moodle/: +// +// Examples: mod/forum:viewpost +// block/recent_activity:view +// moodle/site:deleteuser +// +// The variable name for the capability definitions array is $capabilities + +/** + * This file contains the capabilities used by the basiclti module + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$capabilities = array( + + 'mod/basiclti:view' => array( + + 'captype' => 'read', + 'contextlevel' => CONTEXT_MODULE, + 'archetypes' => array( + 'guest' => CAP_ALLOW, + 'student' => CAP_ALLOW, + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ) + ), + + 'mod/basiclti:grade' => array( + 'riskbitmask' => RISK_XSS, + + 'captype' => 'write', + 'contextlevel' => CONTEXT_MODULE, + 'archetypes' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ) + ), +); diff --git a/mod/basiclti/db/install.xml b/mod/basiclti/db/install.xml new file mode 100644 index 00000000000..33ffe135ae3 --- /dev/null +++ b/mod/basiclti/db/install.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + + +
+
+
diff --git a/mod/basiclti/db/log.php b/mod/basiclti/db/log.php new file mode 100644 index 00000000000..e69de29bb2d diff --git a/mod/basiclti/db/upgrade.php b/mod/basiclti/db/upgrade.php new file mode 100644 index 00000000000..65f743f1828 --- /dev/null +++ b/mod/basiclti/db/upgrade.php @@ -0,0 +1,241 @@ +. + +/** + * This file keeps track of upgrades to the basiclti module + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + + +/** + * xmldb_basiclti_upgrade is the function that upgrades Moodle's + * database when is needed + * + * This function is automaticly called when version number in + * version.php changes. + * + * @param int $oldversion New old version number. + * + * @return boolean + */ + +function xmldb_basiclti_upgrade($oldversion=0) { + + global $DB; + + $dbman = $DB->get_manager(); + $result = true; + + if ($result && $oldversion < 2008090201) { + + $table = new xmldb_table('basiclti_types'); + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); + $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null); + + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + + upgrade_mod_savepoint($result, 2008090201, 'basiclti_types'); + + $table = new xmldb_table('basiclti_types_config'); + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); + $table->add_field('typeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null); + $table->add_field('name', XMLDB_TYPE_CHAR, '100', XMLDB_NOTNULL, null, null, null, null); + $table->add_field('value', XMLDB_TYPE_CHAR, '255', XMLDB_NOTNULL, null, null, null, null); + + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + + upgrade_mod_savepoint($result, 2008090201, 'basiclti_types_config'); + + $table = new xmldb_table('basiclti'); + $field = new xmldb_field('typeid'); + + if (!$dbman->field_exists($table, $field)) { + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null); + $dbman->add_field($table, $field); + } + upgrade_mod_savepoint($result, 2008090201, 'basiclti'); + } + + if ($result && $oldversion < 2008091201) { + $table = new xmldb_table('basiclti_types'); + $field = new xmldb_field('rawname'); + + if (!$dbman->field_exists($table, $field)) { + $field->set_attributes(XMLDB_TYPE_CHAR, '100', null, null, null, null, null); + $dbman->add_field($table, $field); + } + + upgrade_mod_savepoint($result, 2008091202, 'basiclti_types'); + } + + if ($result && $oldversion < 2011011200) { + $table = new xmldb_table('basiclti'); + + $field = new xmldb_field('acceptgrades'); + if (!$dbman->field_exists($table, $field)) { + $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null); + $result = $result && $dbman->add_field($table, $field); + } + $field = new xmldb_field('instructorchoiceacceptgrades'); + if (!$dbman->field_exists($table, $field)) { + $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null); + $result = $result && $dbman->add_field($table, $field); + } + $field = new xmldb_field('allowroster'); + if (!$dbman->field_exists($table, $field)) { + $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null); + $result = $result && $dbman->add_field($table, $field); + } + $field = new xmldb_field('instructorchoiceallowroster'); + if (!$dbman->field_exists($table, $field)) { + $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null); + $result = $result && $dbman->add_field($table, $field); + } + $field = new xmldb_field('allowsetting'); + if (!$dbman->field_exists($table, $field)) { + $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null); + $result = $result && $dbman->add_field($table, $field); + } + $field = new xmldb_field('instructorchoiceallowsetting'); + if (!$dbman->field_exists($table, $field)) { + $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null); + $result = $result && $dbman->add_field($table, $field); + } + $field = new xmldb_field('setting'); + if (!$dbman->field_exists($table, $field)) { + $field->set_attributes(XMLDB_TYPE_CHAR, '8192', null, null, null, '', null); + $result = $result && $dbman->add_field($table, $field); + } + + $field = new xmldb_field('placementsecret'); + if (!$dbman->field_exists($table, $field)) { + $field->set_attributes(XMLDB_TYPE_CHAR, '1024', null, null, null, '', null); + $result = $result && $dbman->add_field($table, $field); + } + + $field = new xmldb_field('timeplacementsecret'); + if (!$dbman->field_exists($table, $field)) { + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null); + $result = $result && $dbman->add_field($table, $field); + } + + $field = new xmldb_field('oldplacementsecret'); + if (!$dbman->field_exists($table, $field)) { + $field->set_attributes(XMLDB_TYPE_CHAR, '1024', null, null, null, '', null); + $result = $result && $dbman->add_field($table, $field); + } + + upgrade_mod_savepoint(true, 2011011200, 'basiclti'); + } + + if ($result && $oldversion < 2011011304) { + $table = new xmldb_table('basiclti'); + $field = new xmldb_field('grade'); + if (!$dbman->field_exists($table, $field)) { + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '100', null); + $result = $result && $dbman->add_field($table, $field); + } + + upgrade_mod_savepoint(true, 2011011304, 'basiclti'); + } + + if ($result && $oldversion < 2011052600) { + $table = new xmldb_table('basiclti'); + + $field = new xmldb_field('resourcekey'); + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + $field = new xmldb_field('password'); + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + $field = new xmldb_field('sendname'); + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + $field = new xmldb_field('sendemailaddr'); + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + $field = new xmldb_field('allowroster'); + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + $field = new xmldb_field('allowsetting'); + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + $field = new xmldb_field('acceptgrades'); + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + $field = new xmldb_field('customparameters'); + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + upgrade_mod_savepoint(true, 2011052600, 'basiclti'); + } + + if($result && $oldversion < 2011070100) { + $table = new xmldb_table('basiclti'); + + $field = new xmldb_field('instructorcustomparameters'); + if (!$dbman->field_exists($table, $field)) { + $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, null, null, '', null); + $result = $result && $dbman->add_field($table, $field); + } + + upgrade_mod_savepoint(true, 2011070100, 'basiclti'); + } + + return $result; +} + diff --git a/mod/basiclti/edit_form.php b/mod/basiclti/edit_form.php new file mode 100644 index 00000000000..ce9ff27c716 --- /dev/null +++ b/mod/basiclti/edit_form.php @@ -0,0 +1,227 @@ +. + +/** + * This file defines de main basiclti configuration form + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @author Charles Severance + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +require_once($CFG->libdir.'/formslib.php'); + +class mod_basiclti_edit_types_form extends moodleform{ + + function definition() { + $mform =& $this->_form; + +//------------------------------------------------------------------------------- + // Add basiclti elements + $mform->addElement('header', 'setup', get_string('modstandardels', 'form')); + + $mform->addElement('text', 'lti_typename', get_string('typename', 'basiclti')); + $mform->setType('lti_typename', PARAM_INT); +// $mform->addHelpButton('lti_typename', 'typename','basiclti'); + $mform->addRule('lti_typename', null, 'required', null, 'client'); + + $regex = '/^(http|https):\/\/([a-z0-9-]\.+)*/i'; + + $mform->addElement('text', 'lti_toolurl', get_string('toolurl', 'basiclti'), array('size'=>'64')); + $mform->setType('lti_toolurl', PARAM_TEXT); +// $mform->addHelpButton('lti_toolurl', 'toolurl', 'basiclti'); + $mform->addRule('lti_toolurl', get_string('validurl', 'basiclti'), 'regex', $regex, 'client'); + $mform->addRule('lti_toolurl', null, 'required', null, 'client'); + + $mform->addElement('text', 'lti_resourcekey', get_string('resourcekey', 'basiclti')); + $mform->setType('lti_resourcekey', PARAM_TEXT); + + $mform->addElement('passwordunmask', 'lti_password', get_string('password', 'basiclti')); + $mform->setType('lti_password', PARAM_TEXT); + +//------------------------------------------------------------------------------- + // Add size parameters + $mform->addElement('header', 'size', get_string('size', 'basiclti')); + + $mform->addElement('text', 'lti_preferheight', get_string('preferheight', 'basiclti')); + $mform->setType('lti_preferheight', PARAM_INT); +// $mform->addHelpButton('lti_preferheight', 'preferheight', 'basiclti'); + + +//------------------------------------------------------------------------------- + // Add privacy preferences fieldset where users choose whether to send their data + $mform->addElement('header', 'privacy', get_string('privacy', 'basiclti')); + + $options=array(); + $options[0] = get_string('never', 'basiclti'); + $options[1] = get_string('always', 'basiclti'); + $options[2] = get_string('delegate', 'basiclti'); + + $defaults=array(); + $defaults[0] = get_string('donot', 'basiclti'); + $defaults[1] = get_string('send', 'basiclti'); + + $mform->addElement('select', 'lti_sendname', get_string('sendname', 'basiclti'), $options); + $mform->setDefault('lti_sendname', '0'); +// $mform->addHelpButton('lti_sendname', 'sendname', 'basiclti'); + + $mform->addElement('select', 'lti_instructorchoicesendname', get_string('setdefault', 'basiclti'), $defaults); + $mform->setDefault('lti_instructorchoicesendname', '0'); + $mform->disabledIf('lti_instructorchoicesendname', 'lti_sendname', 'neq', 2); + + $mform->addElement('select', 'lti_sendemailaddr', get_string('sendemailaddr', 'basiclti'), $options); + $mform->setDefault('lti_sendemailaddr', '0'); +// $mform->addHelpButton('lti_sendemailaddr', 'sendemailaddr', 'basiclti'); + + $mform->addElement('select', 'lti_instructorchoicesendemailaddr', get_string('setdefault', 'basiclti'), $defaults); + $mform->setDefault('lti_instructorchoicesendemailaddr', '0'); + $mform->disabledIf('lti_instructorchoicesendemailaddr', 'lti_sendemailaddr', 'neq', 2); + +//------------------------------------------------------------------------------- + // BLTI Extensions + $mform->addElement('header', 'extensions', get_string('extensions', 'basiclti')); + + $defaults_accept=array(); + $defaults_accept[0] = get_string('donotaccept', 'basiclti'); + $defaults_accept[1] = get_string('accept', 'basiclti'); + + $defaults_allow=array(); + $defaults_allow[0] = get_string('donotallow', 'basiclti'); + $defaults_allow[1] = get_string('allow', 'basiclti'); + + // Add grading preferences fieldset where the tool is allowed to return grades + $mform->addElement('select', 'lti_acceptgrades', get_string('acceptgrades', 'basiclti'), $options); + $mform->setDefault('lti_acceptgrades', '0'); +// $mform->addHelpButton('lti_acceptgrades', 'acceptgrades', 'basiclti'); + + $mform->addElement('select', 'lti_instructorchoiceacceptgrades', get_string('setdefault', 'basiclti'), $defaults_accept); + $mform->setDefault('lti_instructorchoiceacceptgrades', '0'); + $mform->disabledIf('lti_instructorchoiceacceptgrades', 'lti_acceptgrades', 'neq', 2); + + // Add grading preferences fieldset where the tool is allowed to retrieve rosters + $mform->addElement('select', 'lti_allowroster', get_string('allowroster', 'basiclti'), $options); + $mform->setDefault('lti_allowroster', '0'); +// $mform->addHelpButton('lti_allowroster', 'allowroster', 'basiclti'); + + $mform->addElement('select', 'lti_instructorchoiceallowroster', get_string('setdefault', 'basiclti'), $defaults_allow); + $mform->setDefault('lti_instructorchoiceallowroster', '0'); + $mform->disabledIf('lti_instructorchoiceallowroster', 'lti_allowroster', 'neq', 2); + + // Add grading preferences fieldset where the tool is allowed to update settings + $mform->addElement('select', 'lti_allowsetting', get_string('allowsetting', 'basiclti'), $options); + $mform->setDefault('lti_allowsetting', '0'); +// $mform->addHelpButton('lti_allowsetting', 'allowsetting', 'basiclti'); + + $mform->addElement('select', 'lti_instructorchoiceallowsetting', get_string('setdefault', 'basiclti'), $defaults_allow); + $mform->setDefault('lti_instructorchoiceallowsetting', '0'); + $mform->disabledIf('lti_instructorchoiceallowsetting', 'lti_allowsetting', 'neq', 2); + +//------------------------------------------------------------------------------- + // Add custom parameters fieldset + $mform->addElement('header', 'custom', get_string('custom', 'basiclti')); + + $mform->addElement('textarea', 'lti_customparameters', '', array('rows'=>15, 'cols'=>60)); + $mform->setType('lti_customparameters', PARAM_TEXT); + + $mform->addElement('select', 'lti_allowinstructorcustom', get_string('allowinstructorcustom', 'basiclti'), $defaults_allow); + $mform->setDefault('lti_allowinstructorcustom', '0'); + +//------------------------------------------------------------------------------- + // Add setup parameters fieldset + $mform->addElement('header', 'setupoptions', get_string('setupoptions', 'basiclti')); + + // Adding option to change id that is placed in context_id + $idoptions = array(); + $idoptions[0] = get_string('id', 'basiclti'); + $idoptions[1] = get_string('courseid', 'basiclti'); + + $mform->addElement('select', 'lti_moodle_course_field', get_string('moodle_course_field', 'basiclti'), $idoptions); + $mform->setDefault('lti_moodle_course_field', '0'); + + // Added option to allow user to specify if this is a resource or activity type + $classoptions = array(); + $classoptions[0] = get_string('activity', 'basiclti'); + $classoptions[1] = get_string('resource', 'basiclti'); + + $mform->addElement('select', 'lti_module_class_type', get_string('module_class_type', 'basiclti'), $classoptions); + $mform->setDefault('lti_module_class_type', '0'); + +//------------------------------------------------------------------------------- + // Add organization parameters fieldset + $mform->addElement('header', 'organization', get_string('organization', 'basiclti')); + + $mform->addElement('text', 'lti_organizationid', get_string('organizationid', 'basiclti')); + $mform->setType('lti_organizationid', PARAM_TEXT); +// $mform->addHelpButton('lti_organizationid', 'organizationid', 'basiclti'); + + $mform->addElement('text', 'lti_organizationurl', get_string('organizationurl', 'basiclti')); + $mform->setType('lti_organizationurl', PARAM_TEXT); +// $mform->addHelpButton('lti_organizationurl', 'organizationurl', 'basiclti'); + + /* Suppress this for now - Chuck + $mform->addElement('text', 'lti_organizationdescr', get_string('organizationdescr', 'basiclti')); + $mform->setType('lti_organizationdescr', PARAM_TEXT); + $mform->addHelpButton('lti_organizationdescr', 'organizationdescr', 'basiclti'); + */ + +//------------------------------------------------------------------------------- + // Add launch parameters fieldset + $mform->addElement('header', 'launchoptions', get_string('launchoptions', 'basiclti')); + + $launchoptions=array(); + $launchoptions[0] = get_string('launch_in_moodle', 'basiclti'); + $launchoptions[1] = get_string('launch_in_popup', 'basiclti'); + + $mform->addElement('select', 'lti_launchinpopup', get_string('launchinpopup', 'basiclti'), $launchoptions); + $mform->setDefault('lti_launchinpopup', '0'); +// $mform->addHelpButton('lti_launchinpopup', 'launchinpopup', 'basiclti'); + +//------------------------------------------------------------------------------- + // Add a hidden element to signal a tool fixing operation after a problematic backup - restore process + $mform->addElement('hidden', 'lti_fix'); + +//------------------------------------------------------------------------------- + // Add standard buttons, common to all modules + $this->add_action_buttons(); + + } +} diff --git a/mod/basiclti/index.php b/mod/basiclti/index.php new file mode 100644 index 00000000000..cf3c6cbcb17 --- /dev/null +++ b/mod/basiclti/index.php @@ -0,0 +1,121 @@ +. + +/** + * This page lists all the instances of basiclti in a particular course + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +require_once("../../config.php"); +require_once($CFG->dirroot.'/mod/basiclti/lib.php'); + +$id = required_param('id', PARAM_INT); // course id + +if (! $course = $DB->get_record("course", array("id" => $id))) { + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course ID is incorrect'); +} + +$url = new moodle_url('/mod/basiclti/index.php', array('id'=>$id)); +$PAGE->set_url($url); +$PAGE->set_pagelayout('incourse'); + +require_login($course); + +add_to_log($course->id, "basiclti", "view all", "index.php?id=$course->id", ""); + +$pagetitle = strip_tags($course->shortname.': '.get_string("modulenamepluralformatted", "basiclti")); +$PAGE->set_title($pagetitle); +$PAGE->set_heading($course->fullname); + +echo $OUTPUT->header(); + +/// Print the main part of the page +echo $OUTPUT->heading(get_string("modulenamepluralformatted", "basiclti")); + +/// Get all the appropriate data +if (! $basicltis = get_all_instances_in_course("basiclti", $course)) { + notice("There are no basicltis", "../../course/view.php?id=$course->id"); + die; +} + +/// Print the list of instances (your module will probably extend this) +$timenow = time(); +$strname = get_string("name"); +$strsectionname = get_string('sectionname', 'format_'.$course->format); +$usesections = course_format_uses_sections($course->format); +if ($usesections) { + $sections = get_all_sections($course->id); +} + +$table = new html_table(); +$table->attributes['class'] = 'generaltable mod_index'; + +if ($usesections) { + $table->head = array ($strsectionname, $strname); + $table->align = array ("center", "left"); +} else { + $table->head = array ($strname); +} + +foreach ($basicltis as $basiclti) { + if (!$basiclti->visible) { + //Show dimmed if the mod is hidden + $link = "coursemodule\">$basiclti->name"; + } else { + //Show normal if the mod is visible + $link = "coursemodule\">$basiclti->name"; + } + + if ($course->format == "weeks" or $course->format == "topics") { + $table->data[] = array ($basiclti->section, $link); + } else { + $table->data[] = array ($link); + } +} + +echo "
"; + +echo html_writer::table($table); + +/// Finish the page + +echo $OUTPUT->footer(); + diff --git a/mod/basiclti/lang/en/basiclti.php b/mod/basiclti/lang/en/basiclti.php new file mode 100644 index 00000000000..bc8ae94d49f --- /dev/null +++ b/mod/basiclti/lang/en/basiclti.php @@ -0,0 +1,162 @@ +. + +/** + * This file contains en_utf8 translation of the Basic LTI module + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['accept'] = 'Accept'; +$string['acceptgrades'] = 'Accept grades from tool'; +$string['activity'] = 'Activity'; +$string['addnewapp'] = 'Enable External Application'; +$string['addserver'] = 'Add new trusted server'; +$string['addtype'] = 'Create a new Basic LTI activity'; +$string['allow'] = 'Allow'; +$string['allowinstructorcustom'] = 'Allow instructors to add custom parameters'; +$string['allowroster'] = 'Allow tool access to course roster'; +$string['allowsetting'] = 'Allow tool to store 8K of settings in Moodle'; +$string['always'] = 'Always'; +$string['basiclti'] = 'Basic LTI'; +$string['basiclti_base_string'] = 'Basic LTI OAuth Base String'; +$string['basiclti_in_new_window'] = 'Your activity has opened in a new window'; +$string['basiclti_endpoint'] = 'Basic LTI Launch Endpoint'; +$string['basiclti_parameters'] = 'Basic LTI Launch Parameters'; +$string['basicltiactivities'] = 'Basic LTI Activities'; +$string['basicltifieldset'] = 'Custom example fieldset'; +$string['basicltiintro'] = 'Activity Description'; +$string['basicltiname'] = 'Activity Name'; +$string['basicltisettings'] = 'Basic Learning Tool Interoperability Settings'; +$string['comment'] = 'Comment'; +$string['configpassword'] = 'Default Remote Tool Password'; +$string['configpreferheight'] = 'Default preferred height'; +$string['configpreferwidget'] = 'Set widget as default launch'; +$string['configpreferwidth'] = 'Default preferred width'; +$string['configresourceurl'] = 'Default Resource URL'; +$string['configtoolurl'] = 'Default Remote Tool URL'; +$string['configtypes'] = 'Enable Basic LTI Applications'; +$string['configuredtools'] = 'Configured Basic LTI activities'; +$string['courseid'] = 'Course id number'; +$string['coursemisconf'] = 'Course is misconfigured'; +$string['curllibrarymissing'] = 'PHP Curl library must be installed to use LTI'; +$string['custom'] = 'Custom parameters'; +$string['custominstr'] = 'Custom parameters'; +$string['debuglaunch'] = 'Debug Option'; +$string['debuglaunchoff'] = 'Normal launch'; +$string['debuglaunchon'] = 'Debug launch'; +$string['delegate'] = 'Delegate to Professor'; +$string['donot'] = 'Do not send'; +$string['donotaccept'] = 'Do not accept'; +$string['donotallow'] = 'Do not allow'; +$string['enableemailnotification'] = 'Send notification emails'; +$string['enableemailnotification_help'] = 'If enabled, students will receive email notification when their tool submissions are graded.'; +$string['errormisconfig'] = 'Misconfigured tool. Please ask your Moodle administrator to fix the configuration of the tool.'; +$string['extensions'] = 'Basic LTI Extension Services'; +$string['failedtoconnect'] = 'Moodle was unable to communicate with the \"$a\" system'; +$string['filterconfig'] = 'Basic LTI administration'; +$string['filtername'] = 'Basic LTI'; +$string['filter_basiclti_configlink'] = 'Configure your preferred sites and their passwords'; +$string['filter_basiclti_password'] = 'Password is mandatory'; +$string['fixexistingconf'] = 'Use an existing configuration for the misconfigured instance'; +$string['fixnew'] = 'New Configuration'; +$string['fixnewconf'] = 'Define a new configuration for the misconfigured instance'; +$string['fixold'] = 'Use Existing'; +$string['grading'] = 'Grade Routing'; +$string['id'] = 'id'; +$string['imsroleadmin'] = 'Instructor,Administrator'; +$string['imsroleinstructor'] = 'Instructor'; +$string['imsrolelearner'] = 'Learner'; +$string['invalidid'] = 'basic LTI ID was incorrect'; +$string['launch_in_moodle'] = 'Launch tool in moodle'; +$string['launch_in_popup'] = 'Launch tool in a pop-up'; +$string['launchinpopup'] = 'Popup Option'; +$string['launchoptions'] = 'Launch Options'; +$string['lti_errormsg'] = 'The tool returned the following error message: \"$a\"'; +$string['misconfiguredtools'] = 'Misconfigured tool instances were detected'; +$string['missingparameterserror'] = 'The page is misconfigured: \"$a\"'; +$string['module_class_type'] = 'Moodle module type'; +$string['modulename'] = 'Basic LTI'; +$string['modulenameplural'] = 'basicltis'; +$string['modulenamepluralformatted'] = 'Basic LTI Instances'; +$string['moodle_course_field'] = 'Course identification field'; +$string['never'] = 'Never'; +$string['noattempts'] = 'No attempts have been made on this tool instance'; +$string['noservers'] = 'No servers found'; +$string['notypes'] = 'There are currently no LTI tools setup in Moodle. Click the Install link above to add some.'; +$string['noviewusers'] = 'No users were found with permissions to use this tool'; +$string['optionalsettings'] = 'Optional settings'; +$string['organization'] ='Organization details'; +$string['organizationdescr'] ='Organization Description'; +$string['organizationid'] ='Organization ID'; +$string['organizationurl'] ='Organization URL'; +$string['pagesize'] = 'Submissions shown per page'; +$string['password'] = 'Remote Tool Password'; +$string['pluginadministration'] = 'Basic LTI administration'; +$string['pluginname'] = 'BasicLTI'; +$string['preferheight'] = 'Preferred Height'; +$string['preferwidget'] = 'Prefer Widget Launch'; +$string['preferwidth'] = 'Preferred Width'; +$string['press_to_submit'] = 'Press to launch this activity'; +$string['privacy'] = 'Privacy'; +$string['quickgrade'] = 'Allow quick grading'; +$string['quickgrade_help'] = 'If enabled, multiple tools can be graded on one page. Add grades and comments then click the "Save all my feedback" button to save all changes for that page.'; +$string['redirect'] = 'You will be redirected in few seconds. If you are not, press the button.'; +$string['resource'] = 'Resource'; +$string['resourcekey'] = 'Resource Key'; +$string['resourceurl'] = 'Resource URL'; +$string['saveallfeedback'] = 'Save all my feedback'; +$string['send'] = 'Send'; +$string['sendemailaddr'] = 'Send user email address to the external tool'; +$string['sendname'] = 'Send user name and surname to the external tool'; +$string['setdefault'] = 'Set a default value for the professor if delegating'; +$string['setupbox'] = 'Basic LTI Tool Setup Box'; +$string['setupoptions'] = 'Setup Options'; +$string['size'] = 'Size parameters'; +$string['submission'] = 'Submission'; +$string['toggle_debug_data'] = 'Toggle Debug Data'; +$string['toolsetup'] = 'Basic LTI Tool Setup'; +$string['toolurl'] = 'Remote Tool URL'; +$string['typename'] = 'Remote Tool Name'; +$string['types'] = 'Types'; +$string['validurl'] = 'A valid URL must start with http(s)://'; +$string['viewsubmissions'] = 'View submissions and grading screen'; + diff --git a/mod/basiclti/lang/en/help/basiclti/index.html b/mod/basiclti/lang/en/help/basiclti/index.html new file mode 100644 index 00000000000..a4d31a32cdb --- /dev/null +++ b/mod/basiclti/lang/en/help/basiclti/index.html @@ -0,0 +1 @@ +

Basic LTI

diff --git a/mod/basiclti/lang/en/help/basiclti/mods.html b/mod/basiclti/lang/en/help/basiclti/mods.html new file mode 100644 index 00000000000..a4d31a32cdb --- /dev/null +++ b/mod/basiclti/lang/en/help/basiclti/mods.html @@ -0,0 +1 @@ +

Basic LTI

diff --git a/mod/basiclti/launch.php b/mod/basiclti/launch.php new file mode 100644 index 00000000000..3326ce0af35 --- /dev/null +++ b/mod/basiclti/launch.php @@ -0,0 +1,85 @@ +. + +/** + * This file contains all necessary code to view a basiclti activity instance + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once("../../config.php"); +require_once($CFG->dirroot.'/mod/basiclti/lib.php'); +require_once($CFG->dirroot.'/mod/basiclti/locallib.php'); + +$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or + $object = optional_param('withobject', false, PARAM_BOOL); // Launch BasicLTI in an object + +if ($id) { + if (! $cm = $DB->get_record("course_modules", array("id" => $id))) { + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect'); + } + + if (! $course = $DB->get_record("course", array("id" => $cm->course))) { + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured'); + } + + if (! $basiclti = $DB->get_record("basiclti", array("id" => $cm->instance))) { + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect'); + } + +} else { + if (! $basiclti = $DB->get_record("basiclti", array("id" => $a))) { + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect'); + } + if (! $course = $DB->get_record("course", array("id" => $basiclti->course))) { + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured'); + } + if (! $cm = get_coursemodule_from_instance("basiclti", $basiclti->id, $course->id)) { + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect'); + } +} + +require_login($course); + +add_to_log($course->id, "basiclti", "launch", "launch.php?id=$cm->id", "$basiclti->id"); + +basiclti_view($basiclti, $object); + diff --git a/mod/basiclti/lib.php b/mod/basiclti/lib.php new file mode 100644 index 00000000000..809a84b02e7 --- /dev/null +++ b/mod/basiclti/lib.php @@ -0,0 +1,1010 @@ +. + +/** + * This file contains a library of functions and constants for the + * BasicLTI module + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +require_once($CFG->dirroot.'/mod/basiclti/locallib.php'); + +/** + * List of features supported in URL module + * @param string $feature FEATURE_xx constant for requested feature + * @return mixed True if module supports feature, false if not, null if doesn't know + */ +function basiclti_supports($feature) { + switch($feature) { + case FEATURE_GROUPS: return false; + case FEATURE_GROUPINGS: return false; + case FEATURE_GROUPMEMBERSONLY: return true; + case FEATURE_MOD_INTRO: return true; + case FEATURE_COMPLETION_TRACKS_VIEWS: return true; + case FEATURE_GRADE_HAS_GRADE: return true; + case FEATURE_GRADE_OUTCOMES: return true; + case FEATURE_BACKUP_MOODLE2: return true; + + default: return null; + } +} + +/** + * Given an object containing all the necessary data, + * (defined by the form in mod.html) this function + * will create a new instance and return the id number + * of the new instance. + * + * @param object $instance An object from the form in mod.html + * @return int The id of the newly inserted basiclti record + **/ +function basiclti_add_instance($basiclti) { + global $DB; + $basiclti->timecreated = time(); + $basiclti->timemodified = $basiclti->timecreated; + $basiclti->placementsecret = uniqid('', true); + $basiclti->timeplacementsecret = time(); + + $id = $DB->insert_record("basiclti", $basiclti); + + $basiclti = $DB->get_record('basiclti', array('id'=>$id)); + + if ($basiclti->instructorchoiceacceptgrades == 1) { + basiclti_grade_item_update($basiclti); + } + + return $id; +} + +/** + * Given an object containing all the necessary data, + * (defined by the form in mod.html) this function + * will update an existing instance with new data. + * + * @param object $instance An object from the form in mod.html + * @return boolean Success/Fail + **/ +function basiclti_update_instance($basiclti) { + global $DB; + + $basiclti->timemodified = time(); + $basiclti->id = $basiclti->instance; + + $basicltirec = $DB->get_record("basiclti", array("id" => $basiclti->id)); + $basiclti->grade = $basicltirec->grade; + + if (empty($basiclti->preferwidget)) { + $basiclti->preferwidget = 0; + } + + if ($basiclti->instructorchoiceacceptgrades == 1) { + basiclti_grade_item_update($basiclti); + } else { + basiclti_grade_item_delete($basiclti); + } + + return $DB->update_record("basiclti", $basiclti); +} + +/** + * Given an ID of an instance of this module, + * this function will permanently delete the instance + * and any data that depends on it. + * + * @param int $id Id of the module instance + * @return boolean Success/Failure + **/ +function basiclti_delete_instance($id) { + global $DB; + + if (! $basiclti = $DB->get_record("basiclti", array("id" => $id))) { + return false; + } + + $result = true; + + # Delete any dependent records here # + basiclti_grade_item_delete($basiclti); + + return $DB->delete_records("basiclti", array("id" => $basiclti->id)); +} + +/** + * Return a small object with summary information about what a + * user has done with a given particular instance of this module + * Used for user activity reports. + * $return->time = the time they did it + * $return->info = a short text description + * + * @return null + * @TODO: implement this moodle function (if needed) + **/ +function basiclti_user_outline($course, $user, $mod, $basiclti) { + return $return; +} + +/** + * Print a detailed representation of what a user has done with + * a given particular instance of this module, for user activity reports. + * + * @return boolean + * @TODO: implement this moodle function (if needed) + **/ +function basiclti_user_complete($course, $user, $mod, $basiclti) { + return true; +} + +/** + * Given a course and a time, this module should find recent activity + * that has occurred in basiclti activities and print it out. + * Return true if there was output, or false is there was none. + * + * @uses $CFG + * @return boolean + * @TODO: implement this moodle function + **/ +function basiclti_print_recent_activity($course, $isteacher, $timestart) { + return false; // True if anything was printed, otherwise false +} + +/** + * Function to be run periodically according to the moodle cron + * This function searches for things that need to be done, such + * as sending out mail, toggling flags etc ... + * + * @uses $CFG + * @return boolean + **/ +function basiclti_cron () { + return true; +} + +/** + * Must return an array of grades for a given instance of this module, + * indexed by user. It also returns a maximum allowed grade. + * + * Example: + * $return->grades = array of grades; + * $return->maxgrade = maximum allowed grade; + * + * return $return; + * + * @param int $basicltiid ID of an instance of this module + * @return mixed Null or object with an array of grades and with the maximum grade + * + * @TODO: implement this moodle function (if needed) + **/ +function basiclti_grades($basicltiid) { + return null; +} + +/** + * Must return an array of user records (all data) who are participants + * for a given instance of basiclti. Must include every user involved + * in the instance, independient of his role (student, teacher, admin...) + * See other modules as example. + * + * @param int $basicltiid ID of an instance of this module + * @return mixed boolean/array of students + * + * @TODO: implement this moodle function + **/ +function basiclti_get_participants($basicltiid) { + return false; +} + +/** + * This function returns if a scale is being used by one basiclti + * it it has support for grading and scales. Commented code should be + * modified if necessary. See forum, glossary or journal modules + * as reference. + * + * @param int $basicltiid ID of an instance of this module + * @return mixed + * + * @TODO: implement this moodle function (if needed) + **/ +function basiclti_scale_used ($basicltiid, $scaleid) { + $return = false; + + //$rec = get_record("basiclti","id","$basicltiid","scale","-$scaleid"); + // + //if (!empty($rec) && !empty($scaleid)) { + // $return = true; + //} + + return $return; +} + +/** + * Checks if scale is being used by any instance of basiclti. + * This function was added in 1.9 + * + * This is used to find out if scale used anywhere + * @param $scaleid int + * @return boolean True if the scale is used by any basiclti + * + */ +function basiclti_scale_used_anywhere($scaleid) { + global $DB; + + if ($scaleid and $DB->record_exists('basiclti', array('grade' => -$scaleid))) { + return true; + } else { + return false; + } +} + +/** + * Execute post-install custom actions for the module + * This function was added in 1.9 + * + * @return boolean true if success, false on error + */ +function basiclti_install() { + return true; +} + +/** + * Execute post-uninstall custom actions for the module + * This function was added in 1.9 + * + * @return boolean true if success, false on error + */ +function basiclti_uninstall() { + return true; +} + +/** + * Returns available Basic LTI types + * + * @return array of basicLTI types + */ +function basiclti_get_basiclti_types() { + global $DB; + + return $DB->get_records('basiclti_types'); +} + +/** + * Returns Basic LTI types configuration + * + * @return array of basicLTI types + */ +function basiclti_get_types() { + $types = array(); + + $basicltitypes = basiclti_get_basiclti_types(); + if (!empty($basicltitypes)) { + foreach ($basicltitypes as $basicltitype) { + $ltitypesconfig = basiclti_get_type_config($basicltitype->id); + + $modclass = MOD_CLASS_ACTIVITY; + if (isset($ltitypesconfig['module_class_type'])) { + if ($ltitypesconfig['module_class_type']=='1') { + $modclass = MOD_CLASS_RESOURCE; + } + } + + $type = new object(); + $type->modclass = $modclass; + $type->type = 'basiclti&type='.urlencode($basicltitype->rawname); + $type->typestr = $basicltitype->name; + $types[] = $type; + } + } + + return $types; +} + +////////////////////////////////////////////////////////////////////////////////////// +/// Any other basiclti functions go here. Each of them must have a name that +/// starts with basiclti_ +/// Remember (see note in first lines) that, if this section grows, it's HIGHLY +/// recommended to move all funcions below to a new "localib.php" file. + +///** +// * +// */ +//function process_outcomes($userid, $course, $basiclti) { +// global $CFG, $USER; +// +// if (empty($CFG->enableoutcomes)) { +// return; +// } +// +// require_once($CFG->libdir.'/gradelib.php'); +// +// if (!$formdata = data_submitted() or !confirm_sesskey()) { +// return; +// } +// +// $data = array(); +// $grading_info = grade_get_grades($course->id, 'mod', 'basiclti', $basiclti->id, $userid); +// +// if (!empty($grading_info->outcomes)) { +// foreach ($grading_info->outcomes as $n => $old) { +// $name = 'outcome_'.$n; +// if (isset($formdata->{$name}[$userid]) and $old->grades[$userid]->grade != $formdata->{$name}[$userid]) { +// $data[$n] = $formdata->{$name}[$userid]; +// } +// } +// } +// if (count($data) > 0) { +// grade_update_outcomes('mod/basiclti', $course->id, 'mod', 'basiclti', $basiclti->id, $userid, $data); +// } +// +//} + +/** + * Top-level function for handling of submissions called by submissions.php + * + * This is for handling the teacher interaction with the grading interface + * + * @global object + * @param string $mode Specifies the kind of teacher interaction taking place + */ +function basiclti_submissions($cm, $course, $basiclti, $mode) { + ///The main switch is changed to facilitate + ///1) Batch fast grading + ///2) Skip to the next one on the popup + ///3) Save and Skip to the next one on the popup + + //make user global so we can use the id + global $USER, $OUTPUT, $DB; + + $mailinfo = optional_param('mailinfo', null, PARAM_BOOL); + + if (optional_param('next', null, PARAM_BOOL)) { + $mode='next'; + } + if (optional_param('saveandnext', null, PARAM_BOOL)) { + $mode='saveandnext'; + } + + if (is_null($mailinfo)) { + if (optional_param('sesskey', null, PARAM_BOOL)) { + set_user_preference('basiclti_mailinfo', $mailinfo); + } else { + $mailinfo = get_user_preferences('basiclti_mailinfo', 0); + } + } else { + set_user_preference('basiclti_mailinfo', $mailinfo); + } + + switch ($mode) { + case 'grade': // We are in a main window grading + if ($submission = process_feedback()) { + basiclti_display_submissions($cm, $course, $basiclti, get_string('changessaved')); + } else { + basiclti_display_submissions($cm, $course, $basiclti); + } + break; + + case 'single': // We are in a main window displaying one submission + if ($submission = process_feedback()) { + basiclti_display_submissions($cm, $course, $basiclti, get_string('changessaved')); + } else { + display_submission(); + } + break; + + case 'all': // Main window, display everything + basiclti_display_submissions($cm, $course, $basiclti); + break; + + case 'fastgrade': + /// do the fast grading stuff - this process should work for all 3 subclasses + $grading = false; + $commenting = false; + $col = false; + if (isset($_POST['submissioncomment'])) { + $col = 'submissioncomment'; + $commenting = true; + } + if (isset($_POST['menu'])) { + $col = 'menu'; + $grading = true; + } + if (!$col) { + //both submissioncomment and grade columns collapsed.. + basiclti_display_submissions($cm, $course, $basiclti); + break; + } + + foreach ($_POST[$col] as $id => $unusedvalue) { + + $id = (int)$id; //clean parameter name + + // Get grade item + $gradeitem = $DB->get_record('grade_items', array('courseid' => $cm->course, 'iteminstance' => $cm->instance)); + + // Get grade + $gradeentry = $DB->get_record('grade_grades', array('userid' => $id, 'itemid' => $gradeitem->id)); + + $grade = $_POST['menu'][$id]; + $feedback = trim($_POST['submissioncomment'][$id]); + + if ((!$gradeentry) && (($grade != '-1') || ($feedback != ''))) { + $newsubmission = true; + } else { + $newsubmission = false; + } + + //for fast grade, we need to check if any changes take place + $updatedb = false; + + if ($gradeentry) { + if ($grading) { + $grade = $_POST['menu'][$id]; + $updatedb = $updatedb || (($gradeentry->rawgrade != $grade) && ($gradeentry->rawgrade != '-1')); + if ($grade != '-1') { + $gradeentry->rawgrade = $grade; + $gradeentry->finalgrade = $grade; + } else { + $gradeentry->rawgrade = null; + $gradeentry->finalgrade = null; + } + } else { + if (!$newsubmission) { + unset($gradeentry->rawgrade); // Don't need to update this. + } + } + + if ($commenting) { + $commentvalue = trim($_POST['submissioncomment'][$id]); + $updatedb = $updatedb || ($gradeentry->feedback != $commentvalue); + // Special case + if (($gradeentry->feedback == null) && ($commentvalue == "")) { + unset($gradeentry->feedback); + } + $gradeentry->feedback = $commentvalue; + } else { + unset($gradeentry->feedback); // Don't need to update this. + } + + } else { // No previous grade entry found + if ($newsubmission) { + if ($grade != '-1') { + $gradeentry->rawgrade = $grade; + $updatedb = true; + } + if ($feedback != '') { + $gradeentry->feedback = $feedback; + $updatedb = true; + } + } + } + + $gradeentry->usermodified = $USER->id; + if (!$gradeentry->timecreated) { + $gradeentry->timecreated = time(); + } + $gradeentry->timemodified = time(); + + //if it is not an update, we don't change the last modified time etc. + //this will also not write into database if no submissioncomment and grade is entered. + if ($updatedb) { + if ($gradeentry->rawgrade == '-1') { + $gradeentry->rawgrade = null; + } + + if ($newsubmission) { + if (!isset($gradeentry->feedback)) { + $gradeentry->feedback = ''; + } + $gradeentry->itemid = $gradeitem->id; + $gradeentry->userid = $id; + $sid = $DB->insert_record("grade_grades", $gradeentry); + $gradeentry->id = $sid; + } else { + $DB->update_record("grade_grades", $gradeentry); + } + + //add to log only if updating + add_to_log($course->id, 'basiclti', 'update grades', + 'submissions.php?id='.$cm->id.'&user='.$USER->id, + $USER->id, $cm->id); + } + + } + + $message = $OUTPUT->notification(get_string('changessaved'), 'notifysuccess'); + + basiclti_display_submissions($cm, $course, $basiclti, $message); + break; + + case 'saveandnext': + ///We are in pop up. save the current one and go to the next one. + //first we save the current changes + if ($submission = process_feedback()) { + //print_heading(get_string('changessaved')); + //$extra_javascript = $this->update_main_listing($submission); + } + + case 'next': + /// We are currently in pop up, but we want to skip to next one without saving. + /// This turns out to be similar to a single case + /// The URL used is for the next submission. + $offset = required_param('offset', PARAM_INT); + $nextid = required_param('nextid', PARAM_INT); + $id = required_param('id', PARAM_INT); + $offset = (int)$offset+1; + //$this->display_submission($offset+1 , $nextid); + redirect('submissions.php?id='.$id.'&userid='. $nextid . '&mode=single&offset='.$offset); + break; + + case 'singlenosave': + display_submission(); + break; + + default: + echo "Critical error. Something is seriously wrong!!"; + break; + } +} + +/** + * Display all the submissions ready for grading + * + * @global object + * @global object + * @global object + * @global object + * @param string $message + * @return bool|void + */ +function basiclti_display_submissions($cm, $course, $basiclti, $message='') { + global $CFG, $DB, $OUTPUT, $PAGE; + require_once($CFG->libdir.'/gradelib.php'); + + /* first we check to see if the form has just been submitted + * to request user_preference updates + */ + $updatepref = optional_param('updatepref', 0, PARAM_INT); + + if (isset($_POST['updatepref'])) { + $perpage = optional_param('perpage', 10, PARAM_INT); + $perpage = ($perpage <= 0) ? 10 : $perpage; + $filter = optional_param('filter', 0, PARAM_INT); + set_user_preference('basiclti_perpage', $perpage); + set_user_preference('basiclti_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL)); + set_user_preference('basiclti_filter', $filter); + } + + /* next we get perpage and quickgrade (allow quick grade) params + * from database + */ + $perpage = get_user_preferences('basiclti_perpage', 10); + $quickgrade = get_user_preferences('basiclti_quickgrade', 0); + $filter = get_user_preferences('basiclti_filter', 0); + $grading_info = grade_get_grades($course->id, 'mod', 'basiclti', $basiclti->id); + + if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) { + $uses_outcomes = true; + } else { + $uses_outcomes = false; + } + + $page = optional_param('page', 0, PARAM_INT); + $strsaveallfeedback = get_string('saveallfeedback', 'basiclti'); + + $tabindex = 1; //tabindex for quick grading tabbing; Not working for dropdowns yet + add_to_log($course->id, 'basiclti', 'view submission', 'submissions.php?id='.$cm->id, $basiclti->id, $cm->id); + + $PAGE->set_title(format_string($basiclti->name, true)); + $PAGE->set_heading($course->fullname); + echo $OUTPUT->header(); + + echo '
'; + + //hook to allow plagiarism plugins to update status/print links. + plagiarism_update_status($course, $cm); + + /// Print quickgrade form around the table + if ($quickgrade) { + $formattrs = array(); + $formattrs['action'] = new moodle_url('/mod/basiclti/submissions.php'); + $formattrs['id'] = 'fastg'; + $formattrs['method'] = 'post'; + + echo html_writer::start_tag('form', $formattrs); + echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=> $cm->id)); + echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'mode', 'value'=> 'fastgrade')); + echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'page', 'value'=> $page)); + echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=> sesskey())); + } + + $course_context = get_context_instance(CONTEXT_COURSE, $course->id); + if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) { + echo ''; + } + + if (!empty($message)) { + echo $message; // display messages here if any + } + + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + +/// Check to see if groups are being used in this tool + + /// find out current groups mode + $groupmode = groups_get_activity_groupmode($cm); + $currentgroup = groups_get_activity_group($cm, true); + groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/basiclti/submissions.php?id=' . $cm->id); + + /// Get all ppl that are allowed to submit tools + list($esql, $params) = get_enrolled_sql($context, 'mod/basiclti:view', $currentgroup); + + $sql = "SELECT u.id FROM {user} u ". + "LEFT JOIN ($esql) eu ON eu.id=u.id ". + "WHERE u.deleted = 0 AND eu.id=u.id "; + + $users = $DB->get_records_sql($sql, $params); + if (!empty($users)) { + $users = array_keys($users); + } + + // if groupmembersonly used, remove users who are not in any group + if ($users and !empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) { + if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) { + $users = array_intersect($users, array_keys($groupingusers)); + } + } + + $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade'); + if ($uses_outcomes) { + $tablecolumns[] = 'outcome'; // no sorting based on outcomes column + } + + $tableheaders = array('', + get_string('fullname'), + get_string('grade'), + get_string('comment', 'basiclti'), + get_string('lastmodified').' ('.get_string('submission', 'basiclti').')', + get_string('lastmodified').' ('.get_string('grade').')', + get_string('status'), + get_string('finalgrade', 'grades')); + if ($uses_outcomes) { + $tableheaders[] = get_string('outcome', 'grades'); + } + + require_once($CFG->libdir.'/tablelib.php'); + $table = new flexible_table('mod-basiclti-submissions'); + + $table->define_columns($tablecolumns); + $table->define_headers($tableheaders); + $table->define_baseurl($CFG->wwwroot.'/mod/basiclti/submissions.php?id='.$cm->id.'&currentgroup='.$currentgroup); + + $table->sortable(true, 'lastname');//sorted by lastname by default + $table->collapsible(true); + $table->initialbars(true); + + $table->column_suppress('picture'); + $table->column_suppress('fullname'); + + $table->column_class('picture', 'picture'); + $table->column_class('fullname', 'fullname'); + $table->column_class('grade', 'grade'); + $table->column_class('submissioncomment', 'comment'); + $table->column_class('timemodified', 'timemodified'); + $table->column_class('timemarked', 'timemarked'); + $table->column_class('status', 'status'); + $table->column_class('finalgrade', 'finalgrade'); + if ($uses_outcomes) { + $table->column_class('outcome', 'outcome'); + } + + $table->set_attribute('cellspacing', '0'); + $table->set_attribute('id', 'attempts'); + $table->set_attribute('class', 'submissions'); + $table->set_attribute('width', '100%'); + + $table->no_sorting('finalgrade'); + $table->no_sorting('outcome'); + + // Start working -- this is necessary as soon as the niceties are over + $table->setup(); + + if (empty($users)) { + echo $OUTPUT->heading(get_string('noviewusers', 'basiclti')); + echo '
'; + return true; + } + + /// Construct the SQL + list($where, $params) = $table->get_sql_where(); + if ($where) { + $where .= ' AND '; + } + + if ($sort = $table->get_sql_sort()) { + $sort = ' ORDER BY '.$sort; + } + + $ufields = user_picture::fields('u'); + + $gradeitem = $DB->get_record('grade_items', array('courseid' => $cm->course, 'iteminstance' => $cm->instance)); + + $select = "SELECT $ufields, + g.rawgrade, g.feedback, + g.timemodified, g.timecreated "; + + $sql = 'FROM {user} u'. + ' LEFT JOIN {grade_grades} g ON u.id = g.userid AND g.itemid = '.$gradeitem->id. + ' LEFT JOIN {grade_items} i ON g.itemid = i.id'. + ' AND i.iteminstance = '.$basiclti->id. + ' WHERE '.$where.'u.id IN ('.implode(',', $users).') '; + + $ausers = $DB->get_records_sql($select.$sql.$sort, $params, $table->get_page_start(), $table->get_page_size()); + + $table->pagesize($perpage, count($users)); + + ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next + $offset = $page * $perpage; + $strupdate = get_string('update'); + $strgrade = get_string('grade'); + $grademenu = make_grades_menu($basiclti->grade); + if ($ausers !== false) { + $grading_info = grade_get_grades($course->id, 'mod', 'basiclti', $basiclti->id, array_keys($ausers)); + $endposition = $offset + $perpage; + $currentposition = 0; + foreach ($ausers as $auser) { + + if ($auser->timemodified > 0) { + $timemodified = '
'.userdate($auser->timemodified).'
'; + } else { + $timemodified = '
 
'; + } + if ($auser->timecreated > 0) { + $timecreated = '
'.userdate($auser->timecreated).'
'; + } else { + $timecreated = '
 
'; + } + + if ($currentposition == $offset && $offset < $endposition) { + $final_grade = $grading_info->items[0]->grades[$auser->id]; + $grademax = $grading_info->items[0]->grademax; + $final_grade->formatted_grade = round($final_grade->grade, 2) .' / ' . round($grademax, 2); + $locked_overridden = 'locked'; + if ($final_grade->overridden) { + $locked_overridden = 'overridden'; + } + + /// Calculate user status + $picture = $OUTPUT->user_picture($auser); + + $studentmodified = '
 
'; + $teachermodified = '
 
'; + $status = '
 
'; + + if ($final_grade->locked or $final_grade->overridden) { + $grade = '
'.$final_grade->formatted_grade . '
'; + } else if ($quickgrade) { // allow editing + $attributes = array(); + $attributes['tabindex'] = $tabindex++; + if ($auser->rawgrade != "") { + $menu = html_writer::select(make_grades_menu($basiclti->grade), 'menu['.$auser->id.']', round($auser->rawgrade, 0), array(-1=>get_string('nograde')), $attributes); + } else { + $menu = html_writer::select(make_grades_menu($basiclti->grade), 'menu['.$auser->id.']', -1, array(-1=>get_string('nograde')), $attributes); + } + $grade = '
'.$menu.'
'; + } else if ($final_grade->grade) { + if ($auser->rawgrade != "") { + $grade = '
'.$final_grade->formatted_grade.'
'; + } else { + $grade = '
-1
'; + } + + } else { + $grade = '
No Grade
'; + } + + if ($final_grade->locked or $final_grade->overridden) { + $comment = '
'.$final_grade->str_feedback.'
'; + } else if ($quickgrade) { + $comment = '
' + . '
'; + } else { + $comment = '
'.shorten_text(strip_tags($auser->feedback), 15).'
'; + } + + if (empty($auser->status)) { /// Confirm we have exclusively 0 or 1 + $auser->status = 0; + } else { + $auser->status = 1; + } + + $buttontext = ($auser->status == 1) ? $strupdate : $strgrade; + + ///No more buttons, we use popups ;-). + $popup_url = '/mod/basiclti/submissions.php?id='.$cm->id + . '&userid='.$auser->id.'&mode=single'.'&filter='.$filter.'&offset='.$offset++; + + $button = $OUTPUT->action_link($popup_url, $buttontext); + + $status = '
'.$button.'
'; + + $finalgrade = ''.$final_grade->str_grade.''; + + $outcomes = ''; + + if ($uses_outcomes) { + + foreach ($grading_info->outcomes as $n => $outcome) { + $outcomes .= '
'; + $options = make_grades_menu(-$outcome->scaleid); + + if ($outcome->grades[$auser->id]->locked or !$quickgrade) { + $options[0] = get_string('nooutcome', 'grades'); + $outcomes .= ': '.$options[$outcome->grades[$auser->id]->grade].''; + } else { + $attributes = array(); + $attributes['tabindex'] = $tabindex++; + $attributes['id'] = 'outcome_'.$n.'_'.$auser->id; + $outcomes .= ' '.html_writer::select($options, 'outcome_'.$n.'['.$auser->id.']', $outcome->grades[$auser->id]->grade, array(0=>get_string('nooutcome', 'grades')), $attributes); + } + $outcomes .= '
'; + } + } + + $userlink = '' . fullname($auser, has_capability('moodle/site:viewfullnames', $context)) . ''; + $row = array($picture, $userlink, $grade, $comment, $timemodified, $timecreated, $status, $finalgrade); + if ($uses_outcomes) { + $row[] = $outcomes; + } + + $table->add_data($row); + } + $currentposition++; + } + } + + $table->print_html(); /// Print the whole table + + /// Print quickgrade form around the table + if ($quickgrade && $table->started_output) { + $mailinfopref = false; + if (get_user_preferences('basiclti_mailinfo', 1)) { + $mailinfopref = true; + } + $emailnotification = html_writer::checkbox('mailinfo', 1, $mailinfopref, get_string('enableemailnotification', 'basiclti')); + + $emailnotification .= $OUTPUT->help_icon('enableemailnotification', 'basiclti'); + echo html_writer::tag('div', $emailnotification, array('class'=>'emailnotification')); + + $savefeedback = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'fastg', 'value'=>get_string('saveallfeedback', 'basiclti'))); + echo html_writer::tag('div', $savefeedback, array('class'=>'fastgbutton')); + + echo html_writer::end_tag('form'); + } else if ($quickgrade) { + echo html_writer::end_tag('form'); + } + + echo ''; + /// End of fast grading form + + /// Mini form for setting user preference + + $formaction = new moodle_url('/mod/basiclti/submissions.php', array('id'=>$cm->id)); + $mform = new MoodleQuickForm('optionspref', 'post', $formaction, '', array('class'=>'optionspref')); + + $mform->addElement('hidden', 'updatepref'); + $mform->setDefault('updatepref', 1); + $mform->addElement('header', 'qgprefs', get_string('optionalsettings', 'basiclti')); +// $mform->addElement('select', 'filter', get_string('show'), $filters); + + $mform->setDefault('filter', $filter); + + $mform->addElement('text', 'perpage', get_string('pagesize', 'basiclti'), array('size'=>1)); + $mform->setDefault('perpage', $perpage); + + $mform->addElement('checkbox', 'quickgrade', get_string('quickgrade', 'basiclti')); + $mform->setDefault('quickgrade', $quickgrade); + $mform->addHelpButton('quickgrade', 'quickgrade', 'basiclti'); + + $mform->addElement('submit', 'savepreferences', get_string('savepreferences')); + + $mform->display(); + + echo $OUTPUT->footer(); +} + +/** + * Create grade item for given basiclti + * + * @param object $basiclti object with extra cmidnumber + * @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook + * @return int 0 if ok, error code otherwise + */ +function basiclti_grade_item_update($basiclti, $grades=null) { + global $CFG; + require_once($CFG->libdir.'/gradelib.php'); + + if (!isset($basiclti->courseid)) { + $basiclti->courseid = $basiclti->course; + } + + $params = array('itemname'=>$basiclti->name, 'idnumber'=>$basiclti->cmidnumber); + + if ($basiclti->grade > 0) { + $params['gradetype'] = GRADE_TYPE_VALUE; + $params['grademax'] = $basiclti->grade; + $params['grademin'] = 0; + + } else if ($basiclti->grade < 0) { + $params['gradetype'] = GRADE_TYPE_SCALE; + $params['scaleid'] = -$basiclti->grade; + + } else { + $params['gradetype'] = GRADE_TYPE_TEXT; // allow text comments only + } + + if ($grades === 'reset') { + $params['reset'] = true; + $grades = null; + } + + return grade_update('mod/basiclti', $basiclti->courseid, 'mod', 'basiclti', $basiclti->id, 0, $grades, $params); +} + +/** + * Delete grade item for given basiclti + * + * @param object $basiclti object + * @return object basiclti + */ +function basiclti_grade_item_delete($basiclti) { + global $CFG; + require_once($CFG->libdir.'/gradelib.php'); + + if (!isset($basiclti->courseid)) { + $basiclti->courseid = $basiclti->course; + } + + return grade_update('mod/basiclti', $basiclti->courseid, 'mod', 'basiclti', $basiclti->id, 0, null, array('deleted'=>1)); +} + diff --git a/mod/basiclti/localadminlib.php b/mod/basiclti/localadminlib.php new file mode 100644 index 00000000000..f6fe1182c7c --- /dev/null +++ b/mod/basiclti/localadminlib.php @@ -0,0 +1,85 @@ +. + +/** + * This file contains some functions and classes used in Basic LTI + * module administration + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +require_once($CFG->libdir.'/adminlib.php'); + +/** + * + * @TODO: finish doc this class and it's functions + */ +class admin_setting_basicltimodule_configlink extends admin_setting { + + /** + * Constructor + * @param string $name of setting + * @param string $visiblename localised + * @param string $description long localised info + */ + function admin_setting_basicltimodule_configlink($name, $visiblename, $description) { + parent::__construct($name, $visiblename, $description, ''); + } + + function get_setting() { + return true; + } + + function write_setting($data) { + return ""; + } + + function output_html($data, $query='') { + global $CFG; + return format_admin_setting($this, "", + '', + $this->description, true, '', null, $query); + } +} diff --git a/mod/basiclti/locallib.php b/mod/basiclti/locallib.php new file mode 100644 index 00000000000..b200c27a5b1 --- /dev/null +++ b/mod/basiclti/locallib.php @@ -0,0 +1,757 @@ +. + +/** + * This file contains the library of functions and constants for the basiclti module + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +require_once($CFG->dirroot.'/mod/basiclti/OAuth.php'); + +/** + * Prints a Basic LTI activity + * + * $param int $basicltiid Basic LTI activity id + */ +function basiclti_view($instance, $makeobject=false) { + global $PAGE; + + $typeconfig = basiclti_get_type_config($instance->typeid); + $endpoint = $typeconfig['toolurl']; + $key = $typeconfig['resourcekey']; + $secret = $typeconfig['password']; + $orgid = $typeconfig['organizationid']; + /* Suppress this for now - Chuck + $orgdesc = $typeconfig['organizationdescr']; + */ + + $course = $PAGE->course; + $requestparams = basiclti_build_request($instance, $typeconfig, $course); + + // Make sure we let the tool know what LMS they are being called from + $requestparams["ext_lms"] = "moodle-2"; + + // Add oauth_callback to be compliant with the 1.0A spec + $requestparams["oauth_callback"] = "about:blank"; + + $submittext = get_string('press_to_submit', 'basiclti'); + $parms = sign_parameters($requestparams, $endpoint, "POST", $key, $secret, $submittext, $orgid /*, $orgdesc*/); + + $debuglaunch = ( $instance->debuglaunch == 1 ); + if ( $makeobject ) { + // TODO: Need frame height + $height = $instance->preferheight; + if ((!$height) || ($height == 0)) { + $height = 400; + } + $content = post_launch_html($parms, $endpoint, $debuglaunch, $height); + } else { + $content = post_launch_html($parms, $endpoint, $debuglaunch, false); + } +// $cm = get_coursemodule_from_instance("basiclti", $instance->id); +// print ''.$content.''; + print $content; +} + +/** + * This function builds the request that must be sent to the tool producer + * + * @param object $instance Basic LTI instance object + * @param object $typeconfig Basic LTI tool configuration + * @param object $course Course object + * + * @return array $request Request details + */ +function basiclti_build_request($instance, $typeconfig, $course) { + global $USER, $CFG; + + $context = get_context_instance(CONTEXT_COURSE, $course->id); + $role = basiclti_get_ims_role($USER, $context); + + $locale = $course->lang; + if ( strlen($locale) < 1 ) { + $locale = $CFG->lang; + } + + $requestparams = array( + "resource_link_id" => $instance->id, + "resource_link_title" => $instance->name, + "resource_link_description" => $instance->intro, + "user_id" => $USER->id, + "roles" => $role, + "context_id" => $course->id, + "context_label" => $course->shortname, + "context_title" => $course->fullname, + "launch_presentation_locale" => $locale, + ); + + $placementsecret = $instance->placementsecret; + if ( isset($placementsecret) ) { + $suffix = ':::' . $USER->id . ':::' . $instance->id; + $plaintext = $placementsecret . $suffix; + $hashsig = hash('sha256', $plaintext, false); + $sourcedid = $hashsig . $suffix; + } + + if ( isset($placementsecret) && + ( $typeconfig['acceptgrades'] == 1 || + ( $typeconfig['acceptgrades'] == 2 && $instance->instructorchoiceacceptgrades == 1 ) ) ) { + $requestparams["lis_result_sourcedid"] = $sourcedid; + $requestparams["ext_ims_lis_basic_outcome_url"] = $CFG->wwwroot.'/mod/basiclti/service.php'; + } + + if ( isset($placementsecret) && + ( $typeconfig['allowroster'] == 1 || + ( $typeconfig['allowroster'] == 2 && $instance->instructorchoiceallowroster == 1 ) ) ) { + $requestparams["ext_ims_lis_memberships_id"] = $sourcedid; + $requestparams["ext_ims_lis_memberships_url"] = $CFG->wwwroot.'/mod/basiclti/service.php'; + } + + if ( isset($placementsecret) && + ( $typeconfig['allowsetting'] == 1 || + ( $typeconfig['allowsetting'] == 2 && $instance->instructorchoiceallowsetting == 1 ) ) ) { + $requestparams["ext_ims_lti_tool_setting_id"] = $sourcedid; + $requestparams["ext_ims_lti_tool_setting_url"] = $CFG->wwwroot.'/mod/basiclti/service.php'; + $setting = $instance->setting; + if ( isset($setting) ) { + $requestparams["ext_ims_lti_tool_setting"] = $setting; + } + } + + // Send user's name and email data if appropriate + if ( $typeconfig['sendname'] == 1 || + ( $typeconfig['sendname'] == 2 && $instance->instructorchoicesendname == 1 ) ) { + $requestparams["lis_person_name_given"] = $USER->firstname; + $requestparams["lis_person_name_family"] = $USER->lastname; + $requestparams["lis_person_name_full"] = $USER->firstname." ".$USER->lastname; + } + + if ( $typeconfig['sendemailaddr'] == 1 || + ( $typeconfig['sendemailaddr'] == 2 && $instance->instructorchoicesendemailaddr == 1 ) ) { + $requestparams["lis_person_contact_email_primary"] = $USER->email; + } + + // Concatenate the custom parameters from the administrator and the instructor + // Instructor parameters are only taken into consideration if the administrator + // has giver permission + $customstr = $typeconfig['customparameters']; + $instructorcustomstr = $instance->instructorcustomparameters; + $custom = array(); + $instructorcustom = array(); + if ($customstr) { + $custom = split_custom_parameters($customstr); + } + if (!isset($typeconfig['allowinstructorcustom']) || $typeconfig['allowinstructorcustom'] == 0) { + $requestparams = array_merge($custom, $requestparams); + } else { + if ($instructorcustomstr) { + $instructorcustom = split_custom_parameters($instructorcustomstr); + } + foreach ($instructorcustom as $key => $val) { + if (array_key_exists($key, $custom)) { + // Ignore the instructor's parameter + } else { + $custom[$key] = $val; + } + } + $requestparams = array_merge($custom, $requestparams); + } + + return $requestparams; +} + +/** + * Splits the custom parameters field to the various parameters + * + * @param string $customstr String containing the parameters + * + * @return Array of custom parameters + */ +function split_custom_parameters($customstr) { + $textlib = textlib_get_instance(); + + $lines = preg_split("/[\n;]/", $customstr); + $retval = array(); + foreach ($lines as $line) { + $pos = strpos($line, "="); + if ( $pos === false || $pos < 1 ) { + continue; + } + $key = trim($textlib->substr($line, 0, $pos)); + $val = trim($textlib->substr($line, $pos+1)); + $key = map_keyname($key); + $retval['custom_'.$key] = $val; + } + return $retval; +} + +/** + * Used for building the names of the different custom parameters + * + * @param string $key Parameter name + * + * @return string Processed name + */ +function map_keyname($key) { + $textlib = textlib_get_instance(); + + $newkey = ""; + $key = $textlib->strtolower(trim($key)); + foreach (str_split($key) as $ch) { + if ( ($ch >= 'a' && $ch <= 'z') || ($ch >= '0' && $ch <= '9') ) { + $newkey .= $ch; + } else { + $newkey .= '_'; + } + } + return $newkey; +} + +/** + * Returns the IMS user role in a given context + * + * This function queries Moodle for an user role and + * returns the correspondant IMS role + * + * @param StdClass $user Moodle user instance + * @param StdClass $context Moodle context + * + * @return string IMS Role + * + */ +function basiclti_get_ims_role($user, $context) { + + $roles = get_user_roles($context, $user->id); + $rolesname = array(); + foreach ($roles as $role) { + $rolesname[] = $role->shortname; + } + + if (in_array('admin', $rolesname) || in_array('coursecreator', $rolesname)) { + return get_string('imsroleadmin', 'basiclti'); + } + + if (in_array('editingteacher', $rolesname) || in_array('teacher', $rolesname)) { + return get_string('imsroleinstructor', 'basiclti'); + } + + return get_string('imsrolelearner', 'basiclti'); +} + +/** + * Returns configuration details for the tool + * + * @param int $typeid Basic LTI tool typeid + * + * @return array Tool Configuration + */ +function basiclti_get_type_config($typeid) { + global $DB; + + $typeconfig = array(); + $configs = $DB->get_records('basiclti_types_config', array('typeid' => $typeid)); + if (!empty($configs)) { + foreach ($configs as $config) { + $typeconfig[$config->name] = $config->value; + } + } + return $typeconfig; +} + +/** + * Returns all tool instances with a typeid of 0 that + * marks them as unconfigured. These tools usually proceed from a + * backup - restore process. + * + */ +function basiclti_get_unconfigured_tools() { + global $DB; + + return $DB->get_records('basiclti', array('typeid' => 0)); +} + +/** + * Returns all basicLTI tools configured by the administrator + * + */ +function basiclti_filter_get_types() { + global $DB; + + return $DB->get_records('basiclti_types'); +} + +/** + * Prints the various configured tool types + * + */ +function basiclti_filter_print_types() { + global $CFG; + + $types = basiclti_filter_get_types(); + if (!empty($types)) { + echo '
    '; + foreach ($types as $type) { + echo '
  • '. + $type->name. + ''. + ''. + 'Update'. + ''. + ''. + 'Delete'. + ''. + ''. + '
  • '; + + } + echo '
'; + } else { + echo '
'; + echo get_string('notypes', 'basiclti'); + echo '
'; + } +} + +/** + * Delete a Basic LTI configuration + * + * @param int $id Configuration id + */ +function basiclti_delete_type($id) { + global $DB; + + $instances = $DB->get_records('basiclti', array('typeid' => $id)); + foreach ($instances as $instance) { + $instance->typeid = 0; + $DB->update_record('basiclti', $instance); + } + + $DB->delete_records('basiclti_types', array('id' => $id)); + $DB->delete_records('basiclti_types_config', array('typeid' => $id)); +} + +/** + * Transforms a basic LTI object to an array + * + * @param object $bltiobject Basic LTI object + * + * @return array Basic LTI configuration details + */ +function basiclti_get_config($bltiobject) { + $typeconfig = array(); + $typeconfig = (array)$bltiobject; + $additionalconfig = basiclti_get_type_config($bltiobject->typeid); + $typeconfig = array_merge($typeconfig, $additionalconfig); + return $typeconfig; +} + +/** + * + * Generates some of the tool configuration based on the instance details + * + * @param int $id + * + * @return Instance configuration + * + */ +function basiclti_get_type_config_from_instance($id) { + global $DB; + + $instance = $DB->get_record('basiclti', array('id' => $id)); + $config = basiclti_get_config($instance); + + $type = new stdClass(); + $type->lti_fix = $id; + if (isset($config['toolurl'])) { + $type->lti_toolurl = $config['toolurl']; + } + if (isset($config['preferheight'])) { + $type->lti_preferheight = $config['preferheight']; + } + if (isset($config['instructorchoicesendname'])) { + $type->lti_sendname = $config['instructorchoicesendname']; + } + if (isset($config['instructorchoicesendemailaddr'])) { + $type->lti_sendemailaddr = $config['instructorchoicesendemailaddr']; + } + if (isset($config['instructorchoiceacceptgrades'])) { + $type->lti_acceptgrades = $config['instructorchoiceacceptgrades']; + } + if (isset($config['instructorchoiceallowroster'])) { + $type->lti_allowroster = $config['instructorchoiceallowroster']; + } + if (isset($config['instructorchoiceallowsetting'])) { + $type->lti_allowsetting = $config['instructorchoiceallowsetting']; + } + if (isset($config['instructorcustomparameters'])) { + $type->lti_allowsetting = $config['instructorcustomparameters']; + } + return $type; +} + +/** + * Generates some of the tool configuration based on the admin configuration details + * + * @param int $id + * + * @return Configuration details + */ +function basiclti_get_type_type_config($id) { + global $DB; + + $basicltitype = $DB->get_record('basiclti_types', array('id' => $id)); + $config = basiclti_get_type_config($id); + + $type->lti_typename = $basicltitype->name; + if (isset($config['toolurl'])) { + $type->lti_toolurl = $config['toolurl']; + } + if (isset($config['resourcekey'])) { + $type->lti_resourcekey = $config['resourcekey']; + } + if (isset($config['password'])) { + $type->lti_password = $config['password']; + } + if (isset($config['preferheight'])) { + $type->lti_preferheight = $config['preferheight']; + } + if (isset($config['sendname'])) { + $type->lti_sendname = $config['sendname']; + } + if (isset($config['instructorchoicesendname'])){ + $type->lti_instructorchoicesendname = $config['instructorchoicesendname']; + } + if (isset($config['sendemailaddr'])){ + $type->lti_sendemailaddr = $config['sendemailaddr']; + } + if (isset($config['instructorchoicesendemailaddr'])){ + $type->lti_instructorchoicesendemailaddr = $config['instructorchoicesendemailaddr']; + } + if (isset($config['acceptgrades'])){ + $type->lti_acceptgrades = $config['acceptgrades']; + } + if (isset($config['instructorchoiceacceptgrades'])){ + $type->lti_instructorchoiceacceptgrades = $config['instructorchoiceacceptgrades']; + } + if (isset($config['allowroster'])){ + $type->lti_allowroster = $config['allowroster']; + } + if (isset($config['instructorchoiceallowroster'])){ + $type->lti_instructorchoiceallowroster = $config['instructorchoiceallowroster']; + } + if (isset($config['allowsetting'])){ + $type->lti_allowsetting = $config['allowsetting']; + } + if (isset($config['instructorchoiceallowsetting'])){ + $type->lti_instructorchoiceallowsetting = $config['instructorchoiceallowsetting']; + } + if (isset($config['customparameters'])) { + $type->lti_customparameters = $config['customparameters']; + } + if (isset($config['allowinstructorcustom'])) { + $type->lti_allowinstructorcustom = $config['allowinstructorcustom']; + } + if (isset($config['organizationid'])) { + $type->lti_organizationid = $config['organizationid']; + } + if (isset($config['organizationurl'])) { + $type->lti_organizationurl = $config['organizationurl']; + } + if (isset($config['organizationdescr'])) { + $type->lti_organizationdescr = $config['organizationdescr']; + } + if (isset($config['launchinpopup'])) { + $type->lti_launchinpopup = $config['launchinpopup']; + } + if (isset($config['debuglaunch'])) { + $type->lti_debuglaunch = $config['debuglaunch']; + } + if (isset($config['moodle_course_field'])) { + $type->lti_moodle_course_field = $config['moodle_course_field']; + } + if (isset($config['module_class_type'])) { + $type->lti_module_class_type = $config['module_class_type']; + } + + return $type; +} + +/** + * Add a tool configuration in the database + * + * @param $config Tool configuration + * + * @return int Record id number + */ +function basiclti_add_config($config) { + global $DB; + + return $DB->insert_record('basiclti_types_config', $config); +} + +/** + * Updates a tool configuration in the database + * + * @param $config Tool configuration + * + * @return Record id number + */ +function basiclti_update_config($config) { + global $DB; + + $return = true; + if ($old = $DB->get_record('basiclti_types_config', array('typeid' => $config->typeid, 'name' => $config->name))) { + $config->id = $old->id; + $return = $DB->update_record('basiclti_types_config', $config); + } else { + $return = $DB->insert_record('basiclti_types_config', $config); + } + return $return; +} + +/** + * Prints the screen that handles misconfigured objects due to + * an incomplete backup - restore process + * + * @param int $id ID of the misconfigured tool + * + */ +function basiclti_fix_misconfigured_choice($id) { + global $CFG, $USER, $OUTPUT; + + echo $OUTPUT->box_start('generalbox'); + echo '
'; + $types = basiclti_filter_get_types(); + if (!empty($types)) { + echo '

'.get_string('fixexistingconf', 'basiclti').'


'; + echo '
sesskey.' method="post">'; + + foreach ($types as $type) { + echo ''.$type->name.'
'; + } + echo ''; + echo '
'; + echo '
'; + echo '
'; + } else { + echo '
'; + echo get_string('notypes', 'basiclti'); + echo '
'; + } + echo '
'; + echo $OUTPUT->box_end(); + + echo $OUTPUT->box_start("generalbox"); + echo '
'; + echo '

'.get_string('fixnewconf', 'basiclti').'


'; + echo '
sesskey.' method="post">'; + echo ''; + echo ''; + echo '
'; + echo '
'; + echo '
'; + echo $OUTPUT->box_end(); + +} + + +/** + * Signs the petition to launch the external tool using OAuth + * + * @param $oldparms Parameters to be passed for signing + * @param $endpoint url of the external tool + * @param $method Method for sending the parameters (e.g. POST) + * @param $oauth_consumoer_key Key + * @param $oauth_consumoer_secret Secret + * @param $submittext The text for the submit button + * @param $orgid LMS name + * @param $orgdesc LMS key + */ +function sign_parameters($oldparms, $endpoint, $method, $oauthconsumerkey, $oauthconsumersecret, $submittext, $orgid /*, $orgdesc*/) { + global $lastbasestring; + $parms = $oldparms; + $parms["lti_version"] = "LTI-1p0"; + $parms["lti_message_type"] = "basic-lti-launch-request"; + if ( $orgid ) { + $parms["tool_consumer_instance_guid"] = $orgid; + } + /* Suppress this for now - Chuck + if ( $orgdesc ) $parms["tool_consumer_instance_description"] = $orgdesc; + */ + $parms["ext_submit"] = $submittext; + + $testtoken = ''; + + $hmacmethod = new OAuthSignatureMethod_HMAC_SHA1(); + $testconsumer = new OAuthConsumer($oauthconsumerkey, $oauthconsumersecret, null); + + $accreq = OAuthRequest::from_consumer_and_token($testconsumer, $testtoken, $method, $endpoint, $parms); + $accreq->sign_request($hmacmethod, $testconsumer, $testtoken); + + // Pass this back up "out of band" for debugging + $lastbasestring = $accreq->get_signature_base_string(); + + $newparms = $accreq->get_parameters(); + + return $newparms; +} + +/** + * Posts the launch petition HTML + * + * @param $newparms Signed parameters + * @param $endpoint URL of the external tool + * @param $debug Debug (true/false) + */ +function post_launch_html($newparms, $endpoint, $debug=false, $height=false) { + global $lastbasestring; + if ($height) { + $r = "
\n"; + } else { + $r = "\n"; + } + $submittext = $newparms['ext_submit']; + + // Contruct html for the launch parameters + foreach ($newparms as $key => $value) { + $key = htmlspecialchars($key); + $value = htmlspecialchars($value); + if ( $key == "ext_submit" ) { + $r .= "\n"; + } + + if ( $debug ) { + $r .= "\n"; + $r .= ""; + $r .= get_string("toggle_debug_data", "basiclti")."\n"; + $r .= "
\n"; + $r .= "".get_string("basiclti_endpoint", "basiclti")."
\n"; + $r .= $endpoint . "
\n 
\n"; + $r .= "".get_string("basiclti_parameters", "basiclti")."
\n"; + foreach ($newparms as $key => $value) { + $key = htmlspecialchars($key); + $value = htmlspecialchars($value); + $r .= "$key = $value
\n"; + } + $r .= " 
\n"; + $r .= "

".get_string("basiclti_base_string", "basiclti")."
\n".$lastbasestring."

\n"; + $r .= "
\n"; + } + $r .= "
\n"; + + if ( ! $debug ) { + $ext_submit = "ext_submit"; + $ext_submit_text = $submittext; + $r .= " \n"; + } + return $r; +} + +/** + * Returns a link with info about the state of the basiclti submissions + * + * This is used by view_header to put this link at the top right of the page. + * For teachers it gives the number of submitted assignments with a link + * For students it gives the time of their submission. + * This will be suitable for most assignment types. + * + * @global object + * @global object + * @param bool $allgroup print all groups info if user can access all groups, suitable for index.php + * @return string + */ +function submittedlink($cm, $allgroups=false) { + global $CFG; + + $submitted = ''; + $urlbase = "{$CFG->wwwroot}/mod/basiclti/"; + + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + if (has_capability('mod/basiclti:grade', $context)) { + if ($allgroups and has_capability('moodle/site:accessallgroups', $context)) { + $group = 0; + } else { + $group = groups_get_activity_group($cm); + } + + $submitted = ''. + get_string('viewsubmissions', 'basiclti').''; + } else { + if (isloggedin()) { + // TODO Insert code for students if needed + } + } + + return $submitted; +} + diff --git a/mod/basiclti/mod_form.php b/mod/basiclti/mod_form.php new file mode 100644 index 00000000000..8a27a9e70d4 --- /dev/null +++ b/mod/basiclti/mod_form.php @@ -0,0 +1,481 @@ +. + +/** + * This file defines the main basiclti configuration form + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +require_once($CFG->dirroot.'/course/moodleform_mod.php'); +require_once($CFG->dirroot.'/mod/basiclti/locallib.php'); + +class mod_basiclti_mod_form extends moodleform_mod { + + function definition() { + global $DB; + + $typename = optional_param('type', false, PARAM_ALPHA); + + if (empty($typename)) { + //Updating instance + if (!empty($this->_instance)) { + $basiclti = $DB->get_record('basiclti', array('id' => $this->_instance)); + $this->typeid = $basiclti->typeid; + + $typeconfig = basiclti_get_config($basiclti); + $this->typeconfig = $typeconfig; + + } else { // New not pre-configured instance + $this->typeid = 0; + } + } else { + // New pre-configured instance + $basicltitype = $DB->get_record('basiclti_types', array('rawname' => $typename)); + $this->typeid = $basicltitype->id; + + $typeconfig = basiclti_get_type_config($this->typeid); + $this->typeconfig = $typeconfig; + } + + $mform =& $this->_form; +//------------------------------------------------------------------------------- + /// Adding the "general" fieldset, where all the common settings are shown + $mform->addElement('header', 'general', get_string('general', 'form')); + /// Adding the standard "name" field + $mform->addElement('text', 'name', get_string('basicltiname', 'basiclti'), array('size'=>'64')); + $mform->setType('name', PARAM_TEXT); + $mform->addRule('name', null, 'required', null, 'client'); + /// Adding the optional "intro" and "introformat" pair of fields + $this->add_intro_editor(true, get_string('basicltiintro', 'basiclti')); + +//------------------------------------------------------------------------------- + $mform->addElement('hidden', 'typeid', $this->typeid); + $mform->addElement('hidden', 'toolurl', $this->typeconfig['toolurl']); + $mform->addElement('hidden', 'type', $typename); + +//------------------------------------------------------------------------------- + // Add privacy preferences fieldset where users choose whether to send their data + $mform->addElement('header', 'privacy', get_string('privacy', 'basiclti')); + + $privacyoptions=array(); + $privacyoptions[0] = get_string('donot', 'basiclti'); + $privacyoptions[1] = get_string('send', 'basiclti'); + + $mform->addElement('select', 'instructorchoicesendname', get_string('sendname', 'basiclti'), $privacyoptions); + + if (isset($this->typeconfig['instructorchoicesendname'])) { + if ($this->typeconfig['instructorchoicesendname'] == 0) { + $mform->setDefault('instructorchoicesendname', '0'); + } else if ($this->typeconfig['instructorchoicesendname'] == 1) { + $mform->setDefault('instructorchoicesendname', '1'); + } + } +// $mform->addHelpButton('instructorchoicesendname', 'sendname', 'basiclti'); + + $mform->addElement('select', 'instructorchoicesendemailaddr', get_string('sendemailaddr', 'basiclti'), $privacyoptions); + + if (isset($this->typeconfig['instructorchoicesendemailaddr'])) { + if ($this->typeconfig['instructorchoicesendemailaddr'] == 0) { + $mform->setDefault('instructorchoicesendemailaddr', '0'); + } else if ($this->typeconfig['instructorchoicesendemailaddr'] == 1) { + $mform->setDefault('instructorchoicesendemailaddr', '1'); + } + } + // $mform->addHelpButton('instructorchoicesendemailaddr', 'sendemailaddr', 'basiclti'); + +//------------------------------------------------------------------------------- + // Add grading preferences fieldset where the instructor determines whether to accept grades + $mform->addElement('header', 'extensions', get_string('extensions', 'basiclti')); + + $extensionoptions=array(); + $extensionoptions[0] = get_string('donotaccept', 'basiclti'); + $extensionoptions[1] = get_string('accept', 'basiclti'); + + $mform->addElement('select', 'instructorchoiceacceptgrades', get_string('acceptgrades', 'basiclti'), $extensionoptions); + if (isset($this->typeconfig['instructorchoiceacceptgrades'])) { + if ($this->typeconfig['instructorchoiceacceptgrades'] == 0) { + $mform->setDefault('instructorchoiceacceptgrades', '0'); + } else if ($this->typeconfig['instructorchoiceacceptgrades'] == 1) { + $mform->setDefault('instructorchoiceacceptgrades', '1'); + } + } + // $mform->addHelpButton('instructorchoiceacceptgrades', 'acceptgrades', 'basiclti'); + + $extensionoptions=array(); + $extensionoptions[0] = get_string('donotallow', 'basiclti'); + $extensionoptions[1] = get_string('allow', 'basiclti'); + + $mform->addElement('select', 'instructorchoiceallowroster', get_string('allowroster', 'basiclti'), $extensionoptions); + if (isset($this->typeconfig['instructorchoiceallowroster'])) { + if ($this->typeconfig['instructorchoiceallowroster'] == 0) { + $mform->setDefault('instructorchoiceallowroster', '0'); + } else if ($this->typeconfig['instructorchoiceallowroster'] == 1) { + $mform->setDefault('instructorchoiceallowroster', '1'); + } + } + // $mform->addHelpButton('instructorchoiceallowroster', 'allowroster', 'basiclti'); + $mform->setAdvanced('instructorchoiceallowroster'); + + $mform->addElement('select', 'instructorchoiceallowsetting', get_string('allowsetting', 'basiclti'), $extensionoptions); + + if (isset($this->typeconfig['instructorchoiceallowsetting'])) { + if ($this->typeconfig['instructorchoiceallowsetting'] == 0) { + $mform->setDefault('instructorchoiceallowsetting', '0'); + } else if ($this->typeconfig['instructorchoiceallowsetting'] == 1) { + $mform->setDefault('instructorchoiceallowsetting', '1'); + } + } +// $mform->addHelpButton('instructorchoiceallowsetting', 'allowsetting', 'basiclti'); + $mform->setAdvanced('instructorchoiceallowsetting'); + +//------------------------------------------------------------------------------- + if (isset($this->typeconfig['allowinstructorcustom'])) { + if ($this->typeconfig['allowinstructorcustom'] == 1) { + // Add custom parameters fieldset + $mform->addElement('header', 'launchoptions', get_string('custominstr', 'basiclti')); + + $mform->addElement('textarea', 'instructorcustomparameters', '', array('rows'=>15, 'cols'=>60)); + $mform->setType('instructorcustomparameters', PARAM_TEXT); + $mform->setAdvanced('instructorcustomparameters'); + } + } + +//------------------------------------------------------------------------------- + // Add launch parameters fieldset + $mform->addElement('header', 'launchoptions', get_string('launchoptions', 'basiclti')); + + // Size parameters + $mform->addElement('text', 'preferheight', get_string('preferheight', 'basiclti')); + if (isset($this->typeconfig['preferheight'])) { + $mform->setDefault('preferheight', $this->typeconfig['preferheight']); + } + + $launchoptions=array(); + $launchoptions[0] = get_string('launch_in_moodle', 'basiclti'); + $launchoptions[1] = get_string('launch_in_popup', 'basiclti'); + + $mform->addElement('select', 'launchinpopup', get_string('launchinpopup', 'basiclti'), $launchoptions); + + if (isset($this->typeconfig['launchinpopup'])) { + if ($this->typeconfig['launchinpopup'] == 0) { + $mform->setDefault('launchinpopup', '0'); + } else if ($this->typeconfig['launchinpopup'] == 1) { + $mform->setDefault('launchinpopup', '1'); + } + } + + $debugoptions=array(); + $debugoptions[0] = get_string('debuglaunchoff', 'basiclti'); + $debugoptions[1] = get_string('debuglaunchon', 'basiclti'); + + $mform->addElement('select', 'debuglaunch', get_string('debuglaunch', 'basiclti'), $debugoptions); + + if (isset($this->typeconfig['debuglaunch'])) { + if ($this->typeconfig['debuglaunch'] == 0) { + $mform->setDefault('debuglaunch', '0'); + } else if ($this->typeconfig['debuglaunch'] == 1) { + $mform->setDefault('debuglaunch', '1'); + } + } + +//------------------------------------------------------------------------------- + // Organization parameters + if (isset($this->typeconfig['organizationid'])) { + $mform->addElement('hidden', 'organizationid', $this->typeconfig['organizationid']); + } + if (isset($this->typeconfig['organizationurl'])) { + $mform->addElement('hidden', 'organizationurl', $this->typeconfig['organizationurl']); + } +// $mform->addElement('hidden', 'organizationdescr', $this->typeconfig['organizationdescr']); + +//------------------------------------------------------------------------------- + // add standard elements, common to all modules + $this->standard_coursemodule_elements(); +//------------------------------------------------------------------------------- + // add standard buttons, common to all modules + $this->add_action_buttons(); + } + + /** + * Make fields editable or non-editable depending on the administrator choices + * @see moodleform_mod::definition_after_data() + */ + function definition_after_data() { + parent::definition_after_data(); + $mform =& $this->_form; + $typeid =& $mform->getElement('typeid'); + $typeidvalue = $mform->getElementValue('typeid'); + + //Depending on the selection of the administrator + //we don't want to have these appear as possible selections in the form but + //we want the form to display them if they are set. + if (!empty($typeidvalue)) { + $typeconfig = basiclti_get_type_config($typeidvalue); + + if ($typeconfig["sendname"] != 2) { + $field =& $mform->getElement('instructorchoicesendname'); + $mform->setDefault('instructorchoicesendname', $typeconfig["sendname"]); + $field->freeze(); + $field->setPersistantFreeze(true); + } + if ($typeconfig["sendemailaddr"] != 2) { + $field =& $mform->getElement('instructorchoicesendemailaddr'); + $mform->setDefault('instructorchoicesendemailaddr', $typeconfig["sendemailaddr"]); + $field->freeze(); + $field->setPersistantFreeze(true); + } + if ($typeconfig["acceptgrades"] != 2) { + $field =& $mform->getElement('instructorchoiceacceptgrades'); + $mform->setDefault('instructorchoiceacceptgrades', $typeconfig["acceptgrades"]); + $field->freeze(); + $field->setPersistantFreeze(true); + } + if ($typeconfig["allowroster"] != 2) { + $field =& $mform->getElement('instructorchoiceallowroster'); + $mform->setDefault('instructorchoiceallowroster', $typeconfig["allowroster"]); + $field->freeze(); + $field->setPersistantFreeze(true); + } + if ($typeconfig["allowsetting"] != 2) { + $field =& $mform->getElement('instructorchoiceallowsetting'); + $mform->setDefault('instructorchoiceallowsetting', $typeconfig["allowsetting"]); + $field->freeze(); + $field->setPersistantFreeze(true); + } + } + } + + /** + * Function overwritten to change default values using + * global configuration + * + * @param array $default_values passed by reference + */ + function data_preprocessing(&$default_values) { + global $CFG; + $default_values['typeid'] = $this->typeid; + + if (!isset($default_values['toolurl'])) { + if (isset($this->typeconfig['toolurl'])) { + $default_values['toolurl'] = $this->typeconfig['toolurl']; + } else if (isset($CFG->basiclti_toolurl)) { + $default_values['toolurl'] = $CFG->basiclti_toolurl; + } + } + + if (!isset($default_values['resourcekey'])) { + if (isset($this->typeconfig['resourcekey'])) { + $default_values['resourcekey'] = $this->typeconfig['resourcekey']; + } else if (isset($CFG->basiclti_resourcekey)) { + $default_values['resourcekey'] = $CFG->basiclti_resourcekey; + } + } + + if (!isset($default_values['password'])) { + if (isset($this->typeconfig['password'])) { + $default_values['password'] = $this->typeconfig['password']; + } else if (isset($CFG->basiclti_password)) { + $default_values['password'] = $CFG->basiclti_password; + } + } + + if (!isset($default_values['preferheight'])) { + if (isset($this->typeconfig['preferheight'])) { + $default_values['preferheight'] = $this->typeconfig['preferheight']; + } else if (isset($CFG->basiclti_preferheight)) { + $default_values['preferheight'] = $CFG->basiclti_preferheight; + } + } + + if (!isset($default_values['sendname'])) { + if (isset($this->typeconfig['sendname'])) { + $default_values['sendname'] = $this->typeconfig['sendname']; + } else if (isset($CFG->basiclti_sendname)) { + $default_values['sendname'] = $CFG->basiclti_sendname; + } + } + + if (!isset($default_values['instructorchoicesendname'])) { + if (isset($this->typeconfig['instructorchoicesendname'])) { + $default_values['instructorchoicesendname'] = $this->typeconfig['instructorchoicesendname']; + } else { + if ($this->typeconfig['sendname'] == 2) { + $default_values['instructorchoicesendname'] = $CFG->basiclti_instructorchoicesendname; + } else { + $default_values['instructorchoicesendname'] = $this->typeconfig['sendname']; + } + } + } + + if (!isset($default_values['sendemailaddr'])) { + if (isset($this->typeconfig['sendemailaddr'])) { + $default_values['sendemailaddr'] = $this->typeconfig['sendemailaddr']; + } else if (isset($CFG->basiclti_sendemailaddr)) { + $default_values['sendemailaddr'] = $CFG->basiclti_sendemailaddr; + } + } + + if (!isset($default_values['instructorchoicesendemailaddr'])) { + if (isset($this->typeconfig['instructorchoicesendemailaddr'])) { + $default_values['instructorchoicesendemailaddr'] = $this->typeconfig['instructorchoicesendemailaddr']; + } else { + if ($this->typeconfig['sendemailaddr'] == 2) { + $default_values['instructorchoicesendemailaddr'] = $CFG->basiclti_instructorchoicesendemailaddr; + } else { + $default_values['instructorchoicesendemailaddr'] = $this->typeconfig['sendemailaddr']; + } + } + } + + if (!isset($default_values['acceptgrades'])) { + if (isset($this->typeconfig['acceptgrades'])) { + $default_values['acceptgrades'] = $this->typeconfig['acceptgrades']; + } else if (isset($CFG->basiclti_acceptgrades)) { + $default_values['acceptgrades'] = $CFG->basiclti_acceptgrades; + } + } + + if (!isset($default_values['instructorchoiceacceptgrades'])) { + if (isset($this->typeconfig['instructorchoiceacceptgrades'])) { + $default_values['instructorchoiceacceptgrades'] = $this->typeconfig['instructorchoiceacceptgrades']; + } else { + if ($this->typeconfig['acceptgrades'] == 2) { + $default_values['instructorchoiceacceptgrades'] = $CFG->basiclti_instructorchoiceacceptgrades; + } else { + $default_values['instructorchoiceacceptgrades'] = $this->typeconfig['acceptgrades']; + } + } + } + + if (!isset($default_values['allowroster'])) { + if (isset($this->typeconfig['allowroster'])) { + $default_values['allowroster'] = $this->typeconfig['allowroster']; + } else if (isset($CFG->basiclti_allowroster)) { + $default_values['allowroster'] = $CFG->basiclti_allowroster; + } + } + + if (!isset($default_values['instructorchoiceallowroster'])) { + if (isset($this->typeconfig['instructorchoiceallowroster'])) { + $default_values['instructorchoiceallowroster'] = $this->typeconfig['instructorchoiceallowroster']; + } else { + if ($this->typeconfig['allowroster'] == 2) { + $default_values['instructorchoiceallowroster'] = $CFG->basiclti_instructorchoiceallowroster; + } else { + $default_values['instructorchoiceallowroster'] = $this->typeconfig['allowroster']; + } + } + } + + if (!isset($default_values['allowsetting'])) { + if (isset($this->typeconfig['allowsetting'])) { + $default_values['allowsetting'] = $this->typeconfig['allowsetting']; + } else if (isset($CFG->basiclti_allowsetting)) { + $default_values['allowsetting'] = $CFG->basiclti_allowsetting; + } + } + + if (!isset($default_values['instructorchoiceallowsetting'])) { + if (isset($this->typeconfig['instructorchoiceallowsetting'])) { + $default_values['instructorchoiceallowsetting'] = $this->typeconfig['instructorchoiceallowsetting']; + } else { + if ($this->typeconfig['allowsetting'] == 2) { + $default_values['instructorchoiceallowsetting'] = $CFG->basiclti_instructorchoiceallowsetting; + } else { + $default_values['instructorchoiceallowsetting'] = $this->typeconfig['allowsetting']; + } + } + } + + if (!isset($default_values['customparameters'])) { + if (isset($this->typeconfig['customparameters'])) { + $default_values['customparameters'] = $this->typeconfig['customparameters']; + } else if (isset($CFG->basiclti_customparameters)) { + $default_values['customparameters'] = $CFG->basiclti_customparameters; + } + } + + if (!isset($default_values['allowinstructorcustom'])) { + if (isset($this->typeconfig['allowinstructorcustom'])) { + $default_values['allowinstructorcustom'] = $this->typeconfig['allowinstructorcustom']; + } else if (isset($CFG->basiclti_allowinstructorcustom)) { + $default_values['allowinstructorcustom'] = $CFG->basiclti_allowinstructorcustom; + } + } + + if (!isset($default_values['organizationid'])) { + if (isset($this->typeconfig['organizationid'])) { + $default_values['organizationid'] = $this->typeconfig['organizationid']; + } else if (isset($CFG->basiclti_organizationid)) { + $default_values['organizationid'] = $CFG->basiclti_organizationid; + } + } + + if (!isset($default_values['organizationurl'])) { + if (isset($this->typeconfig['organizationurl'])) { + $default_values['organizationurl'] = $this->typeconfig['organizationurl']; + } else if (isset($CFG->basiclti_organizationurl)) { + $default_values['organizationurl'] = $CFG->basiclti_organizationurl; + } + } + + if (!isset($default_values['organizationdescr'])) { + if (isset($this->typeconfig['organizationdescr'])) { + $default_values['organizationdescr'] = $this->typeconfig['organizationdescr']; + } else if (isset($CFG->basiclti_organizationdescr)) { + $default_values['organizationdescr'] = $CFG->basiclti_organizationdescr; + } + } + + if (!isset($default_values['launchinpopup'])) { + if (isset($this->typeconfig['launchinpopup'])) { + $default_values['launchinpopup'] = $this->typeconfig['launchinpopup']; + } else if (isset($CFG->basiclti_launchinpopup)) { + $default_values['launchinpopup'] = $CFG->basiclti_launchinpopup; + } + } + + } +} + diff --git a/mod/basiclti/pix/icon.gif b/mod/basiclti/pix/icon.gif new file mode 100644 index 0000000000000000000000000000000000000000..b9e56fe67d6fa8c767592c240b66ab065a918729 GIT binary patch literal 1982 zcmah~3s4hh5Z>UmVnM-f4{q|4( zjZ~HyKV9t){%{j;#R6o)lop6y3yF1**aE3`5I2E%E2vt*&iRf@_RVY=KC^X1=q$hB zSikH#|8dD9!&R?_rUxX|2Tqa%#_9u8mIY<336gFU%9?|7w}#BxK31`vBw=E1)5N^5 zLKU0Crj~{&)=!?Z^9@z2Xm(RfQA=#`*Ku=qO;>j&q~s-(bR?CwCzW<2r{|@n+EeY_ zV&zityk;@|okYDYqu|{PYNt%MD{FptPWf(S#m;==9+j%KkUdb$cD-fWUuxT{soqPm z9aPl;E%RBK-Kl@4M{hr2wD&NzKUivaSG~Krdg;EJWk;8+IBK_pV};Z4aZl|hm+L?6 ztzUio1G{SZ7rh^@cQ&j&wW{&->gMBX);K?J>07ss+tAjxq3v2z+xbn~E`8Z{WXq15 zt=rGF?zq(6{zrS~)o;GN)Vc5Wp6=^i-#^&fbECVP+kfbO&yP0`_dYms;@4xRZadHX zdHUS%eHZUsxP14*PxpSg@sQ&<{>VMn_{YSsSD*&Qb5CUwiBg&-jTS}60K6npo6QC< z62NG(FlZ;|6cv+0FM<~Yfe#45M@_M2u|koaoyDx20<>Tih6t#qAGy1W>p;f16qdf`*-`3LU z8HghgZ_(*9Wr)M^xuRn-RcrOyUv)SPK!cd#nAt(X^ z(4Yqs&>U_gC_xHo5D8{rpb~WG(j!HWR+=ZFRSzswypU-C#Xyt+8B(}~F}GYX3&4ue zeE!*xCI?5vKn7BDUUWxvR@5kJ7X8*Bw1y9Q9L(E#>f}fFFfU)3SHtIZYvl9un%wy* zR4YcW0m{&7#K+YXYJJX+^i-!aH3$bhBwvH(>g10++N3>7MS=zs@@@0&+YlS@jdm4$ zUXGVCSZeV2kb8J>SKxq;JWF)W>+?Ol*i#OQe;)h1E%#CLZFwF&<-zkjY?>HLL=!S1 zo|q0KkwT;r$wWH7%^-3HB2=hQ4+~K@gX-1Tg9)n9+pm@T$LWImzTuAs?~;@@(TtuV z`5B;KDs_4T?Q*!c|8aXT{|oZ7#qBS)0&Hag#>5TU9x7dPL=bRt&}PX6NV=%FDti@F(T14QjBAZCS@inN)kb;4F=NX zV@ZZ)X~srtqkz@L;xNP|@J+*Eah2m9;vF2i65!bij(gI?anClPh${g54g8G<{8#fw z!g+g*!vPX$X6}^QWsdB*GfNj}OVrD2Mu#P@(&&uFN_zRkxP(M`VF_zvE%R%Ip;3ux zS#ooA1#2`=H6w*&L_$hdUXi)VT5Z(V1O|@}k57@x^9pPWjpdr0kPzW(({{*;3t3Hp z(USl3wS&`2tSpl!SLM$3_X+T*}LD99_*Pg>`Ah3gX0F&`}qatc5ZBx)P}u2LeUX-#LFuv MgIHQR${S|<4UG8`6#xJL literal 0 HcmV?d00001 diff --git a/mod/basiclti/service.php b/mod/basiclti/service.php new file mode 100644 index 00000000000..34ac795f218 --- /dev/null +++ b/mod/basiclti/service.php @@ -0,0 +1,391 @@ +. + +/** + * This file contains all necessary code to support basiclti services + * like outcomes and roster access. + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @author Charles Severance + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once("../../config.php"); +require_once($CFG->dirroot.'/mod/basiclti/lib.php'); +require_once($CFG->dirroot.'/mod/basiclti/locallib.php'); +require_once($CFG->dirroot.'/mod/basiclti/OAuth.php'); +require_once($CFG->dirroot.'/mod/basiclti/TrivialStore.php'); + +error_reporting(E_ALL & ~E_NOTICE); +ini_set("display_errors", 1); + +$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); +$PAGE->set_url('/mod/basiclti/service.php'); +$PAGE->set_pagetype('admin-setting-' . $section); +$PAGE->set_pagelayout('admin'); +$PAGE->navigation->clear_cache(); + +function message_response($major, $severity, $minor=false, $message=false, $xml=false) { + $lti_message_type = $_REQUEST['lti_message_type']; + $retval = ""."\n" . + "\n" . + " $lti_message_type\n" . + " \n" . + " $major\n" . + " $severity\n"; + if (! $codeminor === false) { + $retval = $retval . " $minor\n"; + } + $retval = $retval . + " $message\n" . + " \n"; + if (! $xml === false) { + $retval = $retval . $xml; + } + $retval = $retval . "\n"; + return $retval; +} + +function do_error($message) { + print message_response('Fail', 'Error', false, $message); + exit(); +} + +$lti_version = $_REQUEST['lti_version']; +if ($lti_version != "LTI-1p0") { + do_error("Improperly formed message: wrong lti version: ".$lti_version); +} + +$lti_message_type = $_REQUEST['lti_message_type']; +if (! isset($lti_message_type)) { + do_error("Improperly formed message: no lti_message_type parameter"); +} + +$message_type = false; +if ($lti_message_type == "basic-lis-replaceresult" || + $lti_message_type == "basic-lis-createresult" || + $lti_message_type == "basic-lis-updateresult" || + $lti_message_type == "basic-lis-deleteresult" || + $lti_message_type == "basic-lis-readresult") { + $sourcedid = $_REQUEST['sourcedid']; + $message_type = "basicoutcome"; +} else if ($lti_message_type == "basic-lti-loadsetting" || + $lti_message_type == "basic-lti-savesetting" || + $lti_message_type == "basic-lti-deletesetting") { + $sourcedid = $_REQUEST['id']; + $message_type = "toolsetting"; +} else if ($lti_message_type == "basic-lis-readmembershipsforcontext") { + $sourcedid = $_REQUEST['id']; + $message_type = "roster"; +} + +if ($message_type == false) { + do_error("Illegal lti_message_type"); +} + +if (!isset($sourcedid)) { + do_error("sourcedid missing"); +} +// Truncate to maximum length +$sourcedid = substr($sourcedid, 0, 2048); + +try { + $info = explode(':::', $sourcedid); + if (! is_array($info)) { + do_error("Bad sourcedid (1)"); + } + $signature = $info[0]; + $userid = intval($info[1]); + $placement = $info[2]; +} catch (Exception $e) { + do_error("Bad sourcedid (2)"); +} + +if (isset($signature) && isset($userid) && isset($placement)) { + // OK +} else { + do_error("Bad sourcedid (3)"); +} + +// Retrieve the Basic LTI placement +if (! $basiclti = $DB->get_record('basiclti', array('id'=>$placement))) { + do_error("Bad sourcedid (4)"); +} + +$basiclti_types_config = (object)$basiclti_types_config; + +$typeconfig = basiclti_get_type_config($basiclti->typeid); + +if (isset($typeconfig) && isset($typeconfig['password'])) { + // OK +} else { + do_error("Unable to load type"); +} + +if ($message_type == "basicoutcome") { + if ($typeconfig["acceptgrades"] == 1 || + ($typeconfig["acceptgrades"] == 2 && $basiclti->instructorchoiceacceptgrades == 1)) { + // The placement is configured to accept grades + } else { + do_error("Not permitted (1)"); + } +} else if ($message_type == "toolsetting") { + if ($typeconfig["allowsetting"] == 1 || + ($typeconfig["allowsetting"] == 2 && $basiclti->instructorchoiceallowsetting == 1)) { + // OK + } else { + do_error("Not permitted (2)"); + } +} else if ($message_type == "roster") { + if ($typeconfig["allowroster"] == 1 || + ($typeconfig["allowroster"] == 2 && $basiclti->instructorchoiceallowroster == 1)) { + // OK + } else { + do_error("Not permitted (3)"); + } +} + +// Retrieve the secret we use to sign lis_result_sourcedid +$placementsecret = $basiclti->placementsecret; +$oldplacementsecret = $basiclti->oldplacementsecret; +if (! isset($placementsecret)) { + do_error("Not permitted (4)"); +} + +$suffix = ':::' . $userid . ':::' . $placement; +$plaintext = $placementsecret . $suffix; +$hashsig = hash('sha256', $plaintext, false); +if (($hashsig != $signature) && isset($oldplacementsecret) && (strlen($oldplacementsecret) > 1)) { + $plaintext = $oldplacementsecret . $suffix; + $hashsig = hash('sha256', $plaintext, false); +} + +if ($hashsig != $signature) { + do_error("Invalid sourcedid"); +} + +// Check the OAuth Signature +$oauth_secret = $typeconfig["password"]; +$oauth_consumer_key = $typeconfig["resourcekey"]; +if (! isset($oauth_secret)) { + do_error("Not permitted (5)"); +} +if (! isset($oauth_consumer_key)) { + do_error("Not permitted (6)"); +} + +// Verify the message signature +$store = new TrivialOAuthDataStore(); +$store->add_consumer($oauth_consumer_key, $oauth_secret); + +$server = new OAuthServer($store); + +$method = new OAuthSignatureMethod_HMAC_SHA1(); +$server->add_signature_method($method); +$request = OAuthRequest::from_request(); + +$basestring = $request->get_signature_base_string(); +try { + $server->verify_request($request); +} catch (Exception $e) { + do_error($e->getMessage()); +} + +if (! $course = $DB->get_record('course', array('id'=>$basiclti->course))) { + do_error("Could not retrieve course"); +} + +// TODO: Check that user is in course + +if (! $cm = get_coursemodule_from_instance("basiclti", $basiclti->id, $course->id)) { + do_error("Course Module ID was incorrect"); +} + +// Lets store the grade +require_once($CFG->libdir.'/gradelib.php'); + +// Beginning of actual grade processing +if ($message_type == "basicoutcome") { + $source = 'mod/basiclti'; + $courseid = $course->id; + $itemtype = 'mod'; + $itemmodule = 'basiclti'; + $iteminstance = $basiclti->id; + + if ($lti_message_type == "basic-lis-readresult") { + unset($grade); + $thegrade = grade_get_grades($courseid, $itemtype, $itemmodule, $iteminstance, $userid); + // print_r($thegrade->items[0]->grades); + if (isset($thegrade) && is_array($thegrade->items[0]->grades)) { + foreach ($thegrade->items[0]->grades as $agrade) { + $grade = $agrade->grade; + break; + } + } + if (! isset($grade)) { + do_error("Unable to read grade"); + } + + $result = " \n" . + " \n" . + " " . + htmlspecialchars($grade/100.0) . + "\n" . + " \n" . + " \n"; + print message_response('Success', 'Status', false, "Grade read", $result); + exit(); + } + + if ($lti_message_type == "basic-lis-deleteresult") { + $params = array(); + $params['itemname'] = $basiclti->name; + + $grade = new stdClass(); + $grade->userid = $userid; + $grade->rawgrade = null; + + grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance, 0, $grade, array('deleted'=>1)); + } else { + if (isset($_REQUEST['result_resultscore_textstring'])) { + $gradeval = floatval($_REQUEST['result_resultscore_textstring']); + if ($gradeval <= 1.0 && $gradeval >= 0.0) { + $gradeval = $gradeval * 100.0; + } + } else { + do_error('Missing Grade'); + } + $params = array(); + $params['itemname'] = $basiclti->name; + + $grade = new stdClass(); + $grade->userid = $userid; + $grade->rawgrade = $gradeval; + + grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance, 0, $grade, $params); + } + + print message_response('Success', 'Status', 'fullsuccess', 'Grade updated'); + +} else if ($lti_message_type == "basic-lti-loadsetting") { + $xml = " \n" . + " ".htmlspecialchars($basiclti->setting)."\n" . + " \n"; + print message_response('Success', 'Status', 'fullsuccess', 'Setting retrieved', $xml); +} else if ($lti_message_type == "basic-lti-savesetting") { + $setting = $_REQUEST['setting']; + if (! isset($setting)) { + do_error('Missing setting value'); + } + $record = $DB->get_record('basiclti', array('id'=>$basiclti->id)); + $record->setting = $setting; + $success = $DB->update_record('basiclti', $record); + if ($success) { + print message_response('Success', 'Status', 'fullsuccess', 'Setting updated'); + } else { + do_error("Error updating error"); + } +} else if ($lti_message_type == "basic-lti-deletesetting") { + $record = $DB->get_record('basiclti', array('id'=>$basiclti->id)); + $record->setting = ''; + $success = $DB->update_record('basiclti', $record); + if ($success) { + print message_response('Success', 'Status', 'fullsuccess', 'Setting deleted'); + } else { + do_error("Error updating error"); + } +} else if ($message_type == "roster") { + if (! $course = $DB->get_record('course', array('id'=>$basiclti->course))) { + do_error("Could not retrieve course"); + } + if (! $context = get_context_instance(CONTEXT_COURSE, $course->id)) { + do_error("Could not retrieve context"); + } + $sql = 'SELECT u.id, u.username, u.firstname, u.lastname, u.email, ro.shortname + FROM '.$CFG->prefix.'role_assignments ra + JOIN '.$CFG->prefix.'user AS u ON ra.userid = u.id + JOIN '.$CFG->prefix.'role ro ON ra.roleid = ro.id + WHERE ra.contextid = '.$context->id; + $userlist = $DB->get_recordset_sql($sql); + $xml = " \n"; + foreach ($userlist as $user) { + $role = "Learner"; + if ($user->shortname == 'editingteacher' || $user->shortname == 'admin') { + $role = 'Instructor'; + } + $userxml = " \n". + " ".htmlspecialchars($user->id)."\n". + " $role\n"; + if ($typeconfig["sendname"] == 1 || + ($typeconfig["sendname"] == 2 && $basiclti->instructorchoicesendname == 1)) { + if (isset($user->firstname)) { + $userxml .= " ".htmlspecialchars($user->firstname)."\n"; + } + if (isset($user->lastname)) { + $userxml .= " ".htmlspecialchars($user->lastname)."\n"; + } + } + if ($typeconfig["sendemailaddr"] == 1 || + ($typeconfig["sendemailaddr"] == 2 && $basiclti->instructorchoicesendemailaddr == 1)) { + if (isset($user->email)) { + $userxml .= " ".htmlspecialchars($user->email)."\n"; + } + } + $placementsecret = $basiclti->placementsecret; + if (isset($placementsecret)) { + $suffix = ':::' . $user->id . ':::' . $basiclti->id; + $plaintext = $placementsecret . $suffix; + $hashsig = hash('sha256', $plaintext, false); + $sourcedid = $hashsig . $suffix; + } + if ($typeconfig["acceptgrades"] == 1 || + ($typeconfig["acceptgrades"] == 2 && $basiclti->instructorchoiceacceptgrades == 1)) { + if (isset($sourcedid)) { + $userxml .= " ".htmlspecialchars($sourcedid)."\n"; + } + } + $userxml .= " \n"; + $xml .= $userxml; + } + $xml .= " \n"; + print message_response('Success', 'Status', 'fullsuccess', 'Roster retreived', $xml); + +} + diff --git a/mod/basiclti/settings.php b/mod/basiclti/settings.php new file mode 100644 index 00000000000..65976f8d755 --- /dev/null +++ b/mod/basiclti/settings.php @@ -0,0 +1,100 @@ +. + +/** + * This file defines the global basiclti administration form + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +if ($ADMIN->fulltree) { + require_once($CFG->dirroot.'/mod/basiclti/locallib.php'); + + $str = ''; + + $types = basiclti_filter_get_types(); + if (!empty($types)) { + $str .= '

'.get_string('addtype', 'basiclti').'

'; + $str .= ''; + + foreach ($types as $type) { + $str .= ''. + ''. + ''. + ''; + + } + $str .= '
'.$type->name.''. + 'Update'.'  '. + ''. + 'Delete'. + ''. + '
'; + } else { + $str .= '
'; + $str .= '

'.get_string('addtype', 'basiclti').'

'; + $str .= get_string('notypes', 'basiclti'); + $str .= '
'; + } + + + $settings->add(new admin_setting_heading('basiclti_types', get_string('configuredtools', 'basiclti'), $str)); + + $unconfigured = basiclti_get_unconfigured_tools(); + if (!empty($unconfigured)) { + $newstr = ''; + $newstr .= ''; + + foreach ($unconfigured as $unconf) { + $coursename = $DB->get_field('course', 'shortname', array('id' => $unconf->course)); + $newstr .= ''. + ''. + ''. + ''; + } + $newstr .= '
Course Tool Name
'.$coursename.''.$unconf->name.''. + 'Update'.'  '.'
'; + + $settings->add(new admin_setting_heading('basiclti_mis_types', get_string('misconfiguredtools', 'basiclti'), $newstr)); + } +} diff --git a/mod/basiclti/simpletest/testlocallib.php b/mod/basiclti/simpletest/testlocallib.php new file mode 100644 index 00000000000..464ebd89011 --- /dev/null +++ b/mod/basiclti/simpletest/testlocallib.php @@ -0,0 +1,89 @@ +. + +/** + * This file contains unit tests for (some of) mod/basiclti/locallib.php + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Charles Severance csev@unmich.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +if (!defined('MOODLE_INTERNAL')) { + die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page. +} + +require_once($CFG->dirroot . '/mod/basiclti/locallib.php'); + +class basiclti_locallib_test extends UnitTestCase { + public static $includecoverage = array('mod/basiclti/locallib.php'); + function test_split_custom_parameters() { + $this->assertEqual(split_custom_parameters("x=1\ny=2"), + array('custom_x' => '1', 'custom_y'=> '2')); + $this->assertEqual(split_custom_parameters('x=1;y=2'), + array('custom_x' => '1', 'custom_y'=> '2')); + $this->assertEqual(split_custom_parameters('Review:Chapter=1.2.56'), + array('custom_review_chapter' => '1.2.56')); + $this->assertEqual(split_custom_parameters('Complex!@#$^*(){}[]KEY=Complex!@#$^*(){}[]Value'), + array('custom_complex____________key' => 'Complex!@#$^*(){}[]Value')); + $this->assertEqual(5, 5); + } + + function test_sign_parameters() { + $correct = array ( 'context_id' => '12345', 'context_label' => 'SI124', 'context_title' => 'Social Computing', 'ext_submit' => 'Click Me', 'lti_message_type' => 'basic-lti-launch-request', 'lti_version' => 'LTI-1p0', 'oauth_consumer_key' => 'lmsng.school.edu', 'oauth_nonce' => '47458148e33a8f9dafb888c3684cf476', 'oauth_signature' => 'qWgaBIezihCbeHgcwUy14tZcyDQ=', 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_timestamp' => '1307141660', 'oauth_version' => '1.0', 'resource_link_id' => '123', 'resource_link_title' => 'Weekly Blog', 'roles' => 'Learner', 'tool_consumer_instance_guid' => 'lmsng.school.edu', 'user_id' => '789'); + + $requestparams = array('resource_link_id' => '123', 'resource_link_title' => 'Weekly Blog', 'user_id' => '789', 'roles' => 'Learner', 'context_id' => '12345', 'context_label' => 'SI124', 'context_title' => 'Social Computing'); + + $parms = sign_parameters($requestparams, 'http://www.imsglobal.org/developer/BLTI/tool.php', 'POST', + 'lmsng.school.edu', 'secret', 'Click Me', 'lmsng.school.edu' /*, $org_desc*/); + $this->assertTrue(isset($parms['oauth_nonce'])); + $this->assertTrue(isset($parms['oauth_signature'])); + $this->assertTrue(isset($parms['oauth_timestamp'])); + + // Those things that are hard to mock + $correct['oauth_nonce'] = $parms['oauth_nonce']; + $correct['oauth_signature'] = $parms['oauth_signature']; + $correct['oauth_timestamp'] = $parms['oauth_timestamp']; + ksort($parms); + ksort($correct); + $this->assertEqual($parms, $correct); + } + +} diff --git a/mod/basiclti/styles.css b/mod/basiclti/styles.css new file mode 100644 index 00000000000..82a3ae4f3a0 --- /dev/null +++ b/mod/basiclti/styles.css @@ -0,0 +1,29 @@ +.path-mod-basiclti .basicltiframe {position: relative;width: 100%;height: 100%;} + +/** General Styles **/ +.path-mod-basiclti .userpicture, +.path-mod-basiclti .picture.user, +.path-mod-basiclti .picture.teacher {width:35px;height: 35px;vertical-align:top;} +.path-mod-basiclti .feedback .files, +.path-mod-basiclti .feedback .grade, +.path-mod-basiclti .feedback .outcome, +.path-mod-basiclti .feedback .finalgrade {float: right;} +.path-mod-basiclti .feedback .disabledfeedback {width: 500px;height: 250px;} +.path-mod-basiclti .feedback .from {float: left;} +.path-mod-basiclti .files img {margin-right: 4px;} +.path-mod-basiclti .files a {white-space:nowrap;} +.path-mod-basiclti .late {color: red;} +.path-mod-basiclti .message {text-align: center;} + +/** Styles for submissions.php **/ +#page-mod-basiclti-submissions fieldset.felement {margin-left: 16%;} +#page-mod-basiclti-submissions form#options div {text-align:right;margin-left:auto;margin-right:20px;} +#page-mod-basiclti-submissions .header .commands {display: inline;} +#page-mod-basiclti-submissions .picture {width: 35px;} +#page-mod-basiclti-submissions .fullname, +#page-mod-basiclti-submissions .timemodified, +#page-mod-basiclti-submissions .timemarked {text-align: left;} +#page-mod-basiclti-submissions .submissions .grade, +#page-mod-basiclti-submissions .submissions .outcome, +#page-mod-basiclti-submissions .submissions .finalgrade {text-align: right;} +#page-mod-basiclti-submissions .qgprefs #optiontable {text-align:right;margin-left:auto;} diff --git a/mod/basiclti/submissions.php b/mod/basiclti/submissions.php new file mode 100644 index 00000000000..11aa5ecf42a --- /dev/null +++ b/mod/basiclti/submissions.php @@ -0,0 +1,92 @@ +. + + +/** + * This file contains submissions-specific code for the basiclti module + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +require_once("../../config.php"); +require_once($CFG->dirroot.'/mod/basiclti/lib.php'); +require_once($CFG->libdir.'/plagiarismlib.php'); + +$id = optional_param('id', 0, PARAM_INT); // Course module ID +$a = optional_param('a', 0, PARAM_INT); // Assignment ID +$mode = optional_param('mode', 'all', PARAM_ALPHA); // What mode are we in? +$download = optional_param('download' , 'none', PARAM_ALPHA); //ZIP download asked for? + +$url = new moodle_url('/mod/basiclti/submissions.php'); +if ($id) { + if (! $cm = get_coursemodule_from_id('basiclti', $id)) { + print_error('invalidcoursemodule'); + } + + if (! $basiclti = $DB->get_record("basiclti", array("id"=>$cm->instance))) { + print_error('invalidid', 'basiclti'); + } + + if (! $course = $DB->get_record("course", array("id"=>$basiclti->course))) { + print_error('coursemisconf', 'basiclti'); + } + $url->param('id', $id); +} else { + if (!$basiclti = $DB->get_record("basiclti", array("id"=>$a))) { + print_error('invalidcoursemodule'); + } + if (! $course = $DB->get_record("course", array("id"=>$basiclti->course))) { + print_error('coursemisconf', 'basiclti'); + } + if (! $cm = get_coursemodule_from_instance("basiclti", $basiclti->id, $course->id)) { + print_error('invalidcoursemodule'); + } + $url->param('a', $a); +} + +if ($mode !== 'all') { + $url->param('mode', $mode); +} +$PAGE->set_url($url); +require_login($course, false, $cm); + +require_capability('mod/basiclti:grade', get_context_instance(CONTEXT_MODULE, $cm->id)); + +basiclti_submissions($cm, $course, $basiclti, $mode); // Display or process the submissions diff --git a/mod/basiclti/typessettings.php b/mod/basiclti/typessettings.php new file mode 100644 index 00000000000..8b8be8edbcd --- /dev/null +++ b/mod/basiclti/typessettings.php @@ -0,0 +1,258 @@ +. + +/** + * This file contains the script used to clone Moodle admin setting page. + * It is used to create a new form used to pre-configure basiclti + * activities + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once('../../config.php'); +require_once($CFG->libdir.'/adminlib.php'); +require_once($CFG->dirroot.'/mod/basiclti/edit_form.php'); +require_once($CFG->dirroot.'/mod/basiclti/locallib.php'); + +$section = 'modsettingbasiclti'; +$return = optional_param('return', '', PARAM_ALPHA); +$adminediting = optional_param('adminedit', -1, PARAM_BOOL); +$action = optional_param('action', null, PARAM_TEXT); +$id = optional_param('id', null, PARAM_INT); +$useexisting = optional_param('useexisting', null, PARAM_INT); +$definenew = optional_param('definenew', null, PARAM_INT); + +/// no guest autologin +require_login(0, false); +$url = new moodle_url('/mod/basiclti/typesettings.php'); +$PAGE->set_url($url); + +admin_externalpage_setup('managemodules'); // Hacky solution for printing the admin page + +/// WRITING SUBMITTED DATA (IF ANY) ------------------------------------------------------------------------------- + +$statusmsg = ''; +$errormsg = ''; +$focus = ''; + +if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton)) { + if (isset($id)) { + $type = new StdClass(); + $type->id = $id; + $type->name = $data->lti_typename; + $type->rawname = preg_replace('/[^a-zA-Z]/', '', $type->name); + if ($DB->update_record('basiclti_types', $type)) { + unset ($data->lti_typename); + //@TODO: update work + foreach ($data as $key => $value) { + if (substr($key, 0, 4)=='lti_' && !is_null($value)) { + $record = new StdClass(); + $record->typeid = $id; + $record->name = substr($key, 4); + $record->value = $value; + if (basiclti_update_config($record)) { + $statusmsg = get_string('changessaved'); + } else { + $errormsg = get_string('errorwithsettings', 'admin'); + } + } + } + + // Update toolurl for all existing instances - it is the only common parameter + // between configurations and instances + $instances = $DB->get_records('basiclti', array('typeid' => $id)); + foreach ($instances as $instance) { + if ($instance->toolurl != $data->lti_toolurl) { + $instance->toolurl = $data->lti_toolurl; + $DB->update_record('basiclti', $instance); + } + } + } + redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingbasiclti"); + die; + } else { + $type = new StdClass(); + $type->name = $data->lti_typename; + $type->rawname = preg_replace('/[^a-zA-Z]/', '', $type->name); + if ($id = $DB->insert_record('basiclti_types', $type)) { + if (!empty($data->lti_fix)) { + $instance = $DB->get_record('basiclti', array('id' => $data->lti_fix)); + $instance->typeid = $id; + $DB->update_record('basiclti', $instance); + } + unset ($data->lti_fix); + + unset ($data->lti_typename); + foreach ($data as $key => $value) { + if (substr($key, 0, 4)=='lti_' && !is_null($value)) { + $record = new StdClass(); + $record->typeid = $id; + $record->name = substr($key, 4); + $record->value = $value; + if (basiclti_add_config($record)) { + $statusmsg = get_string('changessaved'); + } else { + $errormsg = get_string('errorwithsettings', 'admin'); + } + } + } + } else { + $errormsg = get_string('errorwithsettings', 'admin'); + } + redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingbasiclti"); + die; + } + if (empty($adminroot->errors)) { + switch ($return) { + case 'site': redirect("$CFG->wwwroot/"); + case 'admin': redirect("$CFG->wwwroot/$CFG->admin/"); + } + } else { + $errormsg = get_string('errorwithsettings', 'admin'); + $firsterror = reset($adminroot->errors); + $focus = $firsterror->id; + } + $adminroot =& admin_get_root(true); //reload tree + $page =& $adminroot->locate($section); +} + +if ($action == 'delete') { + basiclti_delete_type($id); + redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingbasiclti"); + die; +} + +if (($action == 'fix') && isset($useexisting)) { + $instance = $DB->get_record('basiclti', array('id' => $id)); + $instance->typeid = $useexisting; + $DB->update_record('basiclti', $instance); + redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingbasiclti"); + die; +} + +/// print header stuff ------------------------------------------------------------ +$PAGE->set_focuscontrol($focus); +if (empty($SITE->fullname)) { + $PAGE->set_title($settingspage->visiblename); + $PAGE->set_heading($settingspage->visiblename); + + $PAGE->navbar->add('Basic LTI Administration', $CFG->wwwroot.'/admin/settings.php?section=modsettingbasiclti'); + + echo $OUTPUT->header(); + + echo $OUTPUT->box(get_string('configintrosite', 'admin')); + + if ($errormsg !== '') { + echo $OUTPUT->notification($errormsg); + + } else if ($statusmsg !== '') { + echo $OUTPUT->notification($statusmsg, 'notifysuccess'); + } + + // --------------------------------------------------------------------------------------------------------------- + + echo '
'; + echo '
'; + echo html_writer::input_hidden_params($PAGE->url); + echo ''; + echo ''; + + echo $settingspage->output_html(); + + echo '
'; + + echo '
'; + echo '
'; + +} else { + if ($PAGE->user_allowed_editing()) { + $url = clone($PAGE->url); + if ($PAGE->user_is_editing()) { + $caption = get_string('blockseditoff'); + $url->param('adminedit', 'off'); + } else { + $caption = get_string('blocksediton'); + $url->param('adminedit', 'on'); + } + $buttons = $OUTPUT->single_button($url, $caption, 'get'); + } + + $PAGE->set_title("$SITE->shortname: " . get_string('toolsetup', 'basiclti')); + + $PAGE->navbar->add('Basic LTI Administration', $CFG->wwwroot.'/admin/settings.php?section=modsettingbasiclti'); + + echo $OUTPUT->header(); + + + + if ($errormsg !== '') { + echo $OUTPUT->notification($errormsg); + + } else if ($statusmsg !== '') { + echo $OUTPUT->notification($statusmsg, 'notifysuccess'); + } + + // --------------------------------------------------------------------------------------------------------------- + echo $OUTPUT->heading(get_string('toolsetup', 'basiclti')); + echo $OUTPUT->box_start('generalbox'); + if ($action == 'add') { + $form = new mod_basiclti_edit_types_form(); + $form->display(); + } else if ($action == 'update') { + $form = new mod_basiclti_edit_types_form('typessettings.php?id='.$id); + $type = basiclti_get_type_type_config($id); + $form->set_data($type); + $form->display(); + } else if ($action == 'fix') { + if (!isset($definenew) && !isset($useexisting)) { + basiclti_fix_misconfigured_choice($id); + } else if (isset($definenew)) { + $form = new mod_basiclti_edit_types_form(); + $type = basiclti_get_type_config_from_instance($id); + $form->set_data($type); + $form->display(); + } + } + + echo $OUTPUT->box_end(); +} + +echo $OUTPUT->footer(); diff --git a/mod/basiclti/version.php b/mod/basiclti/version.php new file mode 100644 index 00000000000..3b68fb8d645 --- /dev/null +++ b/mod/basiclti/version.php @@ -0,0 +1,50 @@ +. + +/** + * This file defines the version of basiclti + * This fragment is called by moodle_needs_upgrading() and /admin/index.php + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$module->version = 2011072000; // The current module version (Date: YYYYMMDDXX) +$module->cron = 0; // Period for cron to check this module (secs) diff --git a/mod/basiclti/view.php b/mod/basiclti/view.php new file mode 100644 index 00000000000..b8b5778cd24 --- /dev/null +++ b/mod/basiclti/view.php @@ -0,0 +1,132 @@ +. + +/** + * This file contains all necessary code to view a basiclti activity instance + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once('../../config.php'); +require_once($CFG->dirroot.'/mod/basiclti/lib.php'); +require_once($CFG->dirroot.'/mod/basiclti/locallib.php'); + +$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or +$a = optional_param('a', 0, PARAM_INT); // basiclti ID + +if ($id) { + if (! $cm = get_coursemodule_from_id("basiclti", $id)) { + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect'); + } + + if (! $course = $DB->get_record("course", array("id" => $cm->course))) { + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured'); + } + + if (! $basiclti = $DB->get_record("basiclti", array("id" => $cm->instance))) { + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect'); + } + +} else { + if (! $basiclti = $DB->get_record("basiclti", array("id" => $a))) { + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect'); + } + if (! $course = $DB->get_record("course", array("id" => $basiclti->course))) { + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured'); + } + if (! $cm = get_coursemodule_from_instance("basiclti", $basiclti->id, $course->id)) { + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect'); + } +} + +$PAGE->set_cm($cm, $course); // set's up global $COURSE +$context = get_context_instance(CONTEXT_MODULE, $cm->id); +$PAGE->set_context($context); + +$url = new moodle_url('/mod/basiclti/view.php', array('id'=>$cm->id)); +$PAGE->set_url($url); +$PAGE->set_pagelayout('incourse'); +require_login($course); + +add_to_log($course->id, "basiclti", "view", "view.php?id=$cm->id", "$basiclti->id"); + +$pagetitle = strip_tags($course->shortname.': '.format_string($basiclti->name)); +$PAGE->set_title($pagetitle); +$PAGE->set_heading($course->fullname); + +/// Print the page header +echo $OUTPUT->header(); + +/// Print the main part of the page +echo $OUTPUT->heading(format_string($basiclti->name)); +echo $OUTPUT->box($basiclti->intro, 'generalbox description', 'intro'); + +if ($basiclti->typeid == 0) { + print_error('errormisconfig', 'basiclti'); +} + +if ($basiclti->instructorchoiceacceptgrades == 1) { + echo ''; +} + +echo $OUTPUT->box_start('generalbox activity'); + + +if ( $basiclti->launchinpopup > 0 ) { + print "\n"; + print "

".get_string("basiclti_in_new_window", "basiclti")."

\n"; +} else { + // Request the launch content with an object tag + $height = $basiclti->preferheight; + if ((!$height) || ($height == 0)) { + $height = 400; + } + print ''; + +} + +echo $OUTPUT->box_end(); + +/// Finish the page +echo $OUTPUT->footer(); From a64b29cf9d6d3bf77028497f8828998bebb40f32 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Thu, 25 Aug 2011 15:30:13 -0400 Subject: [PATCH 02/78] Renamed plugin from basiclti to blti --- mod/basiclti/db/upgrade.php | 241 ------------------ mod/basiclti/styles.css | 29 --- mod/{basiclti => blti}/OAuth.php | 0 mod/{basiclti => blti}/TODO.txt | 0 mod/{basiclti => blti}/TrivialStore.php | 2 +- .../backup_blti_activity_task.class.php} | 20 +- .../backup/moodle2/backup_blti_stepslib.php} | 14 +- .../restore_blti_activity_task.class.php} | 22 +- .../backup/moodle2/restore_blti_stepslib.php} | 18 +- mod/{basiclti => blti}/basiclti.js | 2 +- mod/{basiclti => blti}/db/access.php | 10 +- mod/{basiclti => blti}/db/install.xml | 19 +- mod/{basiclti => blti}/db/log.php | 0 mod/blti/db/upgrade.php | 72 ++++++ mod/{basiclti => blti}/edit_form.php | 118 ++++----- mod/{basiclti => blti}/index.php | 14 +- .../en/basiclti.php => blti/lang/en/blti.php} | 3 +- .../lang/en/help/basiclti/index.html | 0 .../lang/en/help/basiclti/mods.html | 0 mod/{basiclti => blti}/launch.php | 16 +- mod/{basiclti => blti}/lib.php | 154 +++++------ mod/{basiclti => blti}/localadminlib.php | 8 +- mod/{basiclti => blti}/locallib.php | 120 ++++----- mod/{basiclti => blti}/mod_form.php | 144 +++++------ mod/{basiclti => blti}/pix/icon.gif | Bin mod/{basiclti => blti}/service.php | 30 +-- mod/{basiclti => blti}/settings.php | 24 +- .../simpletest/testlocallib.php | 8 +- mod/blti/styles.css | 29 +++ mod/{basiclti => blti}/submissions.php | 24 +- mod/{basiclti => blti}/typessettings.php | 60 ++--- mod/{basiclti => blti}/version.php | 2 +- mod/{basiclti => blti}/view.php | 24 +- 33 files changed, 524 insertions(+), 703 deletions(-) delete mode 100644 mod/basiclti/db/upgrade.php delete mode 100644 mod/basiclti/styles.css rename mod/{basiclti => blti}/OAuth.php (100%) rename mod/{basiclti => blti}/TODO.txt (100%) rename mod/{basiclti => blti}/TrivialStore.php (99%) rename mod/{basiclti/backup/moodle2/backup_basiclti_activity_task.class.php => blti/backup/moodle2/backup_blti_activity_task.class.php} (80%) rename mod/{basiclti/backup/moodle2/backup_basiclti_stepslib.php => blti/backup/moodle2/backup_blti_stepslib.php} (88%) rename mod/{basiclti/backup/moodle2/restore_basiclti_activity_task.class.php => blti/backup/moodle2/restore_blti_activity_task.class.php} (79%) rename mod/{basiclti/backup/moodle2/restore_basiclti_stepslib.php => blti/backup/moodle2/restore_blti_stepslib.php} (86%) rename mod/{basiclti => blti}/basiclti.js (99%) rename mod/{basiclti => blti}/db/access.php (89%) rename mod/{basiclti => blti}/db/install.xml (86%) rename mod/{basiclti => blti}/db/log.php (100%) create mode 100644 mod/blti/db/upgrade.php rename mod/{basiclti => blti}/edit_form.php (76%) rename mod/{basiclti => blti}/index.php (90%) rename mod/{basiclti/lang/en/basiclti.php => blti/lang/en/blti.php} (97%) rename mod/{basiclti => blti}/lang/en/help/basiclti/index.html (100%) rename mod/{basiclti => blti}/lang/en/help/basiclti/mods.html (100%) rename mod/{basiclti => blti}/launch.php (85%) rename mod/{basiclti => blti}/lib.php (84%) rename mod/{basiclti => blti}/localadminlib.php (88%) rename mod/{basiclti => blti}/locallib.php (84%) rename mod/{basiclti => blti}/mod_form.php (80%) rename mod/{basiclti => blti}/pix/icon.gif (100%) rename mod/{basiclti => blti}/service.php (91%) rename mod/{basiclti => blti}/settings.php (75%) rename mod/{basiclti => blti}/simpletest/testlocallib.php (95%) create mode 100644 mod/blti/styles.css rename mod/{basiclti => blti}/submissions.php (80%) rename mod/{basiclti => blti}/typessettings.php (83%) rename mod/{basiclti => blti}/version.php (97%) rename mod/{basiclti => blti}/view.php (83%) diff --git a/mod/basiclti/db/upgrade.php b/mod/basiclti/db/upgrade.php deleted file mode 100644 index 65f743f1828..00000000000 --- a/mod/basiclti/db/upgrade.php +++ /dev/null @@ -1,241 +0,0 @@ -. - -/** - * This file keeps track of upgrades to the basiclti module - * - * @package basiclti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis - * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - - -/** - * xmldb_basiclti_upgrade is the function that upgrades Moodle's - * database when is needed - * - * This function is automaticly called when version number in - * version.php changes. - * - * @param int $oldversion New old version number. - * - * @return boolean - */ - -function xmldb_basiclti_upgrade($oldversion=0) { - - global $DB; - - $dbman = $DB->get_manager(); - $result = true; - - if ($result && $oldversion < 2008090201) { - - $table = new xmldb_table('basiclti_types'); - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); - $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null); - - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - - upgrade_mod_savepoint($result, 2008090201, 'basiclti_types'); - - $table = new xmldb_table('basiclti_types_config'); - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); - $table->add_field('typeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null); - $table->add_field('name', XMLDB_TYPE_CHAR, '100', XMLDB_NOTNULL, null, null, null, null); - $table->add_field('value', XMLDB_TYPE_CHAR, '255', XMLDB_NOTNULL, null, null, null, null); - - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - - upgrade_mod_savepoint($result, 2008090201, 'basiclti_types_config'); - - $table = new xmldb_table('basiclti'); - $field = new xmldb_field('typeid'); - - if (!$dbman->field_exists($table, $field)) { - $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null); - $dbman->add_field($table, $field); - } - upgrade_mod_savepoint($result, 2008090201, 'basiclti'); - } - - if ($result && $oldversion < 2008091201) { - $table = new xmldb_table('basiclti_types'); - $field = new xmldb_field('rawname'); - - if (!$dbman->field_exists($table, $field)) { - $field->set_attributes(XMLDB_TYPE_CHAR, '100', null, null, null, null, null); - $dbman->add_field($table, $field); - } - - upgrade_mod_savepoint($result, 2008091202, 'basiclti_types'); - } - - if ($result && $oldversion < 2011011200) { - $table = new xmldb_table('basiclti'); - - $field = new xmldb_field('acceptgrades'); - if (!$dbman->field_exists($table, $field)) { - $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null); - $result = $result && $dbman->add_field($table, $field); - } - $field = new xmldb_field('instructorchoiceacceptgrades'); - if (!$dbman->field_exists($table, $field)) { - $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null); - $result = $result && $dbman->add_field($table, $field); - } - $field = new xmldb_field('allowroster'); - if (!$dbman->field_exists($table, $field)) { - $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null); - $result = $result && $dbman->add_field($table, $field); - } - $field = new xmldb_field('instructorchoiceallowroster'); - if (!$dbman->field_exists($table, $field)) { - $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null); - $result = $result && $dbman->add_field($table, $field); - } - $field = new xmldb_field('allowsetting'); - if (!$dbman->field_exists($table, $field)) { - $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null); - $result = $result && $dbman->add_field($table, $field); - } - $field = new xmldb_field('instructorchoiceallowsetting'); - if (!$dbman->field_exists($table, $field)) { - $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null); - $result = $result && $dbman->add_field($table, $field); - } - $field = new xmldb_field('setting'); - if (!$dbman->field_exists($table, $field)) { - $field->set_attributes(XMLDB_TYPE_CHAR, '8192', null, null, null, '', null); - $result = $result && $dbman->add_field($table, $field); - } - - $field = new xmldb_field('placementsecret'); - if (!$dbman->field_exists($table, $field)) { - $field->set_attributes(XMLDB_TYPE_CHAR, '1024', null, null, null, '', null); - $result = $result && $dbman->add_field($table, $field); - } - - $field = new xmldb_field('timeplacementsecret'); - if (!$dbman->field_exists($table, $field)) { - $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null); - $result = $result && $dbman->add_field($table, $field); - } - - $field = new xmldb_field('oldplacementsecret'); - if (!$dbman->field_exists($table, $field)) { - $field->set_attributes(XMLDB_TYPE_CHAR, '1024', null, null, null, '', null); - $result = $result && $dbman->add_field($table, $field); - } - - upgrade_mod_savepoint(true, 2011011200, 'basiclti'); - } - - if ($result && $oldversion < 2011011304) { - $table = new xmldb_table('basiclti'); - $field = new xmldb_field('grade'); - if (!$dbman->field_exists($table, $field)) { - $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '100', null); - $result = $result && $dbman->add_field($table, $field); - } - - upgrade_mod_savepoint(true, 2011011304, 'basiclti'); - } - - if ($result && $oldversion < 2011052600) { - $table = new xmldb_table('basiclti'); - - $field = new xmldb_field('resourcekey'); - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - $field = new xmldb_field('password'); - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - $field = new xmldb_field('sendname'); - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - $field = new xmldb_field('sendemailaddr'); - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - $field = new xmldb_field('allowroster'); - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - $field = new xmldb_field('allowsetting'); - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - $field = new xmldb_field('acceptgrades'); - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - $field = new xmldb_field('customparameters'); - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - upgrade_mod_savepoint(true, 2011052600, 'basiclti'); - } - - if($result && $oldversion < 2011070100) { - $table = new xmldb_table('basiclti'); - - $field = new xmldb_field('instructorcustomparameters'); - if (!$dbman->field_exists($table, $field)) { - $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, null, null, '', null); - $result = $result && $dbman->add_field($table, $field); - } - - upgrade_mod_savepoint(true, 2011070100, 'basiclti'); - } - - return $result; -} - diff --git a/mod/basiclti/styles.css b/mod/basiclti/styles.css deleted file mode 100644 index 82a3ae4f3a0..00000000000 --- a/mod/basiclti/styles.css +++ /dev/null @@ -1,29 +0,0 @@ -.path-mod-basiclti .basicltiframe {position: relative;width: 100%;height: 100%;} - -/** General Styles **/ -.path-mod-basiclti .userpicture, -.path-mod-basiclti .picture.user, -.path-mod-basiclti .picture.teacher {width:35px;height: 35px;vertical-align:top;} -.path-mod-basiclti .feedback .files, -.path-mod-basiclti .feedback .grade, -.path-mod-basiclti .feedback .outcome, -.path-mod-basiclti .feedback .finalgrade {float: right;} -.path-mod-basiclti .feedback .disabledfeedback {width: 500px;height: 250px;} -.path-mod-basiclti .feedback .from {float: left;} -.path-mod-basiclti .files img {margin-right: 4px;} -.path-mod-basiclti .files a {white-space:nowrap;} -.path-mod-basiclti .late {color: red;} -.path-mod-basiclti .message {text-align: center;} - -/** Styles for submissions.php **/ -#page-mod-basiclti-submissions fieldset.felement {margin-left: 16%;} -#page-mod-basiclti-submissions form#options div {text-align:right;margin-left:auto;margin-right:20px;} -#page-mod-basiclti-submissions .header .commands {display: inline;} -#page-mod-basiclti-submissions .picture {width: 35px;} -#page-mod-basiclti-submissions .fullname, -#page-mod-basiclti-submissions .timemodified, -#page-mod-basiclti-submissions .timemarked {text-align: left;} -#page-mod-basiclti-submissions .submissions .grade, -#page-mod-basiclti-submissions .submissions .outcome, -#page-mod-basiclti-submissions .submissions .finalgrade {text-align: right;} -#page-mod-basiclti-submissions .qgprefs #optiontable {text-align:right;margin-left:auto;} diff --git a/mod/basiclti/OAuth.php b/mod/blti/OAuth.php similarity index 100% rename from mod/basiclti/OAuth.php rename to mod/blti/OAuth.php diff --git a/mod/basiclti/TODO.txt b/mod/blti/TODO.txt similarity index 100% rename from mod/basiclti/TODO.txt rename to mod/blti/TODO.txt diff --git a/mod/basiclti/TrivialStore.php b/mod/blti/TrivialStore.php similarity index 99% rename from mod/basiclti/TrivialStore.php rename to mod/blti/TrivialStore.php index 05eb9fc4721..6e7086bd8de 100644 --- a/mod/basiclti/TrivialStore.php +++ b/mod/blti/TrivialStore.php @@ -50,7 +50,7 @@ /** * This file contains a Trivial memory-based store - no support for tokens * - * @package basiclti + * @package blti * @copyright IMS Global Learning Consortium * * @author Charles Severance csev@umich.edu diff --git a/mod/basiclti/backup/moodle2/backup_basiclti_activity_task.class.php b/mod/blti/backup/moodle2/backup_blti_activity_task.class.php similarity index 80% rename from mod/basiclti/backup/moodle2/backup_basiclti_activity_task.class.php rename to mod/blti/backup/moodle2/backup_blti_activity_task.class.php index 4c142637ba6..7639ec99c10 100644 --- a/mod/basiclti/backup/moodle2/backup_basiclti_activity_task.class.php +++ b/mod/blti/backup/moodle2/backup_blti_activity_task.class.php @@ -32,9 +32,9 @@ /** - * This file contains the basiclti module backup class + * This file contains the blti module backup class * - * @package basiclti + * @package blti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -46,13 +46,13 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -require_once($CFG->dirroot . '/mod/basiclti/backup/moodle2/backup_basiclti_stepslib.php'); +require_once($CFG->dirroot . '/mod/blti/backup/moodle2/backup_blti_stepslib.php'); /** - * basiclti backup task that provides all the settings and steps to perform one + * blti backup task that provides all the settings and steps to perform one * complete backup of the module */ -class backup_basiclti_activity_task extends backup_activity_task { +class backup_blti_activity_task extends backup_activity_task { /** * Define (add) particular settings this activity can have @@ -66,7 +66,7 @@ class backup_basiclti_activity_task extends backup_activity_task { */ protected function define_my_steps() { // Choice only has one structure step - $this->add_step(new backup_basiclti_activity_structure_step('basiclti_structure', 'basiclti.xml')); + $this->add_step(new backup_blti_activity_structure_step('blti_structure', 'blti.xml')); } /** @@ -79,12 +79,12 @@ class backup_basiclti_activity_task extends backup_activity_task { $base = preg_quote($CFG->wwwroot, "/"); // Link to the list of basiclti tools - $search="/(".$base."\/mod\/basiclti\/index.php\?id\=)([0-9]+)/"; - $content= preg_replace($search, '$@BASICLTIINDEX*$2@$', $content); + $search="/(".$base."\/mod\/blti\/index.php\?id\=)([0-9]+)/"; + $content= preg_replace($search, '$@BLTIINDEX*$2@$', $content); // Link to basiclti view by moduleid - $search="/(".$base."\/mod\/basiclti\/view.php\?id\=)([0-9]+)/"; - $content= preg_replace($search, '$@BASICLTIVIEWBYID*$2@$', $content); + $search="/(".$base."\/mod\/blti\/view.php\?id\=)([0-9]+)/"; + $content= preg_replace($search, '$@BLTIVIEWBYID*$2@$', $content); return $content; } diff --git a/mod/basiclti/backup/moodle2/backup_basiclti_stepslib.php b/mod/blti/backup/moodle2/backup_blti_stepslib.php similarity index 88% rename from mod/basiclti/backup/moodle2/backup_basiclti_stepslib.php rename to mod/blti/backup/moodle2/backup_blti_stepslib.php index 768e3ca6590..8e2bf7b362e 100644 --- a/mod/basiclti/backup/moodle2/backup_basiclti_stepslib.php +++ b/mod/blti/backup/moodle2/backup_blti_stepslib.php @@ -32,9 +32,9 @@ /** * This file contains all the backup steps that will be used - * by the backup_basiclti_activity_task + * by the backup_blti_activity_task * - * @package basiclti + * @package blti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -47,13 +47,13 @@ */ /** - * Define all the backup steps that will be used by the backup_basiclti_activity_task + * Define all the backup steps that will be used by the backup_blti_activity_task */ /** * Define the complete assignment structure for backup, with file and id annotations */ -class backup_basiclti_activity_structure_step extends backup_activity_structure_step { +class backup_blti_activity_structure_step extends backup_activity_structure_step { protected function define_structure() { @@ -61,7 +61,7 @@ class backup_basiclti_activity_structure_step extends backup_activity_structure_ $userinfo = $this->get_setting_value('userinfo'); // Define each element separated - $basiclti = new backup_nested_element('basiclti', array('id'), array( + $basiclti = new backup_nested_element('blti', array('id'), array( 'name', 'intro', 'introformat', 'timecreated', 'timemodified', 'typeid', 'toolurl', 'preferheight', 'instructorchoiccesendname', 'instructorchoicesendemailaddr', 'organizationid', @@ -73,13 +73,13 @@ class backup_basiclti_activity_structure_step extends backup_activity_structure_ // (none) // Define sources - $basiclti->set_source_table('basiclti', array('id' => backup::VAR_ACTIVITYID)); + $basiclti->set_source_table('blti', array('id' => backup::VAR_ACTIVITYID)); // Define id annotations // (none) // Define file annotations - $basiclti->annotate_files('mod_basiclti', 'intro', null); // This file areas haven't itemid + $basiclti->annotate_files('mod_blti', 'intro', null); // This file areas haven't itemid // Return the root element (basiclti), wrapped into standard activity structure return $this->prepare_activity_structure($basiclti); diff --git a/mod/basiclti/backup/moodle2/restore_basiclti_activity_task.class.php b/mod/blti/backup/moodle2/restore_blti_activity_task.class.php similarity index 79% rename from mod/basiclti/backup/moodle2/restore_basiclti_activity_task.class.php rename to mod/blti/backup/moodle2/restore_blti_activity_task.class.php index 4f8b12f3071..9aeea107911 100644 --- a/mod/basiclti/backup/moodle2/restore_basiclti_activity_task.class.php +++ b/mod/blti/backup/moodle2/restore_blti_activity_task.class.php @@ -33,7 +33,7 @@ /** * This file contains the basicLTI module restore class * - * @package basiclti + * @package blti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -46,13 +46,13 @@ */ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->dirroot . '/mod/basiclti/backup/moodle2/restore_basiclti_stepslib.php'); // Because it exists (must) +require_once($CFG->dirroot . '/mod/blti/backup/moodle2/restore_blti_stepslib.php'); // Because it exists (must) /** * basiclti restore task that provides all the settings and steps to perform one * complete restore of the activity */ -class restore_basiclti_activity_task extends restore_activity_task { +class restore_blti_activity_task extends restore_activity_task { /** * Define (add) particular settings this activity can have @@ -66,7 +66,7 @@ class restore_basiclti_activity_task extends restore_activity_task { */ protected function define_my_steps() { // label only has one structure step - $this->add_step(new restore_basiclti_activity_structure_step('basiclti_structure', 'basiclti.xml')); + $this->add_step(new restore_blti_activity_structure_step('blti_structure', 'blti.xml')); } /** @@ -76,7 +76,7 @@ class restore_basiclti_activity_task extends restore_activity_task { static public function define_decode_contents() { $contents = array(); - $contents[] = new restore_decode_content('basiclti', array('intro'), 'basiclti'); + $contents[] = new restore_decode_content('blti', array('intro'), 'blti'); return $contents; } @@ -88,8 +88,8 @@ class restore_basiclti_activity_task extends restore_activity_task { static public function define_decode_rules() { $rules = array(); - $rules[] = new restore_decode_rule('BASICLTIVIEWBYID', '/mod/basiclti/view.php?id=$1', 'course_module'); - $rules[] = new restore_decode_rule('BASICLTIINDEX', '/mod/basiclti/index.php?id=$1', 'course'); + $rules[] = new restore_decode_rule('BLTIVIEWBYID', '/mod/blti/view.php?id=$1', 'course_module'); + $rules[] = new restore_decode_rule('BLTIINDEX', '/mod/blti/index.php?id=$1', 'course'); return $rules; @@ -104,9 +104,9 @@ class restore_basiclti_activity_task extends restore_activity_task { static public function define_restore_log_rules() { $rules = array(); - $rules[] = new restore_log_rule('basiclti', 'add', 'view.php?id={course_module}', '{basiclti}'); - $rules[] = new restore_log_rule('basiclti', 'update', 'view.php?id={course_module}', '{basiclti}'); - $rules[] = new restore_log_rule('basiclti', 'view', 'view.php?id={course_module}', '{basiclti}'); + $rules[] = new restore_log_rule('blti', 'add', 'view.php?id={course_module}', '{blti}'); + $rules[] = new restore_log_rule('blti', 'update', 'view.php?id={course_module}', '{blti}'); + $rules[] = new restore_log_rule('blti', 'view', 'view.php?id={course_module}', '{blti}'); return $rules; } @@ -124,7 +124,7 @@ class restore_basiclti_activity_task extends restore_activity_task { static public function define_restore_log_rules_for_course() { $rules = array(); - $rules[] = new restore_log_rule('basiclti', 'view all', 'index.php?id={course}', null); + $rules[] = new restore_log_rule('blti', 'view all', 'index.php?id={course}', null); return $rules; } diff --git a/mod/basiclti/backup/moodle2/restore_basiclti_stepslib.php b/mod/blti/backup/moodle2/restore_blti_stepslib.php similarity index 86% rename from mod/basiclti/backup/moodle2/restore_basiclti_stepslib.php rename to mod/blti/backup/moodle2/restore_blti_stepslib.php index 566c463c83e..25a474eda32 100644 --- a/mod/basiclti/backup/moodle2/restore_basiclti_stepslib.php +++ b/mod/blti/backup/moodle2/restore_blti_stepslib.php @@ -35,7 +35,7 @@ * This file contains all the restore steps that will be used * by the restore_basiclti_activity_task * - * @package basiclti + * @package blti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -54,18 +54,18 @@ /** * Structure step to restore one basiclti activity */ -class restore_basiclti_activity_structure_step extends restore_activity_structure_step { +class restore_blti_activity_structure_step extends restore_activity_structure_step { protected function define_structure() { $paths = array(); - $paths[] = new restore_path_element('basiclti', '/activity/basiclti'); + $paths[] = new restore_path_element('blti', '/activity/blti'); // Return the paths wrapped into standard activity structure return $this->prepare_activity_structure($paths); } - protected function process_basiclti($data) { + protected function process_blti($data) { global $DB; $data = (object)$data; @@ -73,7 +73,7 @@ class restore_basiclti_activity_structure_step extends restore_activity_structur $data->course = $this->get_courseid(); // insert the basiclti record - $newitemid = $DB->insert_record('basiclti', $data); + $newitemid = $DB->insert_record('blti', $data); // immediately after inserting "activity" record, call this $this->apply_activity_instance($newitemid); } @@ -81,9 +81,9 @@ class restore_basiclti_activity_structure_step extends restore_activity_structur protected function after_execute() { global $DB; - $basicltis = $DB->get_records('basiclti'); + $basicltis = $DB->get_records('blti'); foreach ($basicltis as $basiclti) { - if (!$DB->get_record('basiclti_types_config', + if (!$DB->get_record('blti_types_config', array('typeid' => $basiclti->typeid, 'name' => 'toolurl', 'value' => $basiclti->toolurl))) { $basiclti->typeid = 0; @@ -92,10 +92,10 @@ class restore_basiclti_activity_structure_step extends restore_activity_structur $basiclti->placementsecret = uniqid('', true); $basiclti->timeplacementsecret = time(); - $DB->update_record('basiclti', $basiclti); + $DB->update_record('blti', $basiclti); } // Add basiclti related files, no need to match by itemname (just internally handled context) - $this->add_related_files('mod_basiclti', 'intro', null); + $this->add_related_files('mod_blti', 'intro', null); } } diff --git a/mod/basiclti/basiclti.js b/mod/blti/basiclti.js similarity index 99% rename from mod/basiclti/basiclti.js rename to mod/blti/basiclti.js index be112a0ab3d..2d9dfe340a3 100644 --- a/mod/basiclti/basiclti.js +++ b/mod/blti/basiclti.js @@ -32,7 +32,7 @@ /** * This file contains a library of javasxript functions for the BasicLTI module * - * @package basiclti + * @package blti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu diff --git a/mod/basiclti/db/access.php b/mod/blti/db/access.php similarity index 89% rename from mod/basiclti/db/access.php rename to mod/blti/db/access.php index 341461f19ff..6188180db66 100644 --- a/mod/basiclti/db/access.php +++ b/mod/blti/db/access.php @@ -1,6 +1,6 @@ array( + 'mod/bltii:view' => array( 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, @@ -57,7 +57,7 @@ $capabilities = array( ) ), - 'mod/basiclti:grade' => array( + 'mod/blti:grade' => array( 'riskbitmask' => RISK_XSS, 'captype' => 'write', diff --git a/mod/basiclti/db/install.xml b/mod/blti/db/install.xml similarity index 86% rename from mod/basiclti/db/install.xml rename to mod/blti/db/install.xml index 33ffe135ae3..c9d1023daf8 100644 --- a/mod/basiclti/db/install.xml +++ b/mod/blti/db/install.xml @@ -1,10 +1,10 @@ - - +
@@ -42,19 +42,8 @@
- - - - - - - - - -
- - +
@@ -65,7 +54,7 @@
- +
diff --git a/mod/basiclti/db/log.php b/mod/blti/db/log.php similarity index 100% rename from mod/basiclti/db/log.php rename to mod/blti/db/log.php diff --git a/mod/blti/db/upgrade.php b/mod/blti/db/upgrade.php new file mode 100644 index 00000000000..d8c8b505b39 --- /dev/null +++ b/mod/blti/db/upgrade.php @@ -0,0 +1,72 @@ +. + +/** + * This file keeps track of upgrades to the basiclti module + * + * @package blti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + + +/** + * xmldb_blti_upgrade is the function that upgrades Moodle's + * database when is needed + * + * This function is automaticly called when version number in + * version.php changes. + * + * @param int $oldversion New old version number. + * + * @return boolean + */ + +function xmldb_blti_upgrade($oldversion=0) { + + global $DB; + + $dbman = $DB->get_manager(); + $result = true; + + + + return $result; +} + diff --git a/mod/basiclti/edit_form.php b/mod/blti/edit_form.php similarity index 76% rename from mod/basiclti/edit_form.php rename to mod/blti/edit_form.php index ce9ff27c716..b13f2599145 100644 --- a/mod/basiclti/edit_form.php +++ b/mod/blti/edit_form.php @@ -33,7 +33,7 @@ /** * This file defines de main basiclti configuration form * - * @package basiclti + * @package blti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -50,7 +50,7 @@ defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir.'/formslib.php'); -class mod_basiclti_edit_types_form extends moodleform{ +class mod_blti_edit_types_form extends moodleform{ function definition() { $mform =& $this->_form; @@ -59,161 +59,161 @@ class mod_basiclti_edit_types_form extends moodleform{ // Add basiclti elements $mform->addElement('header', 'setup', get_string('modstandardels', 'form')); - $mform->addElement('text', 'lti_typename', get_string('typename', 'basiclti')); + $mform->addElement('text', 'lti_typename', get_string('typename', 'blti')); $mform->setType('lti_typename', PARAM_INT); -// $mform->addHelpButton('lti_typename', 'typename','basiclti'); +// $mform->addHelpButton('lti_typename', 'typename','blti'); $mform->addRule('lti_typename', null, 'required', null, 'client'); $regex = '/^(http|https):\/\/([a-z0-9-]\.+)*/i'; - $mform->addElement('text', 'lti_toolurl', get_string('toolurl', 'basiclti'), array('size'=>'64')); + $mform->addElement('text', 'lti_toolurl', get_string('toolurl', 'blti'), array('size'=>'64')); $mform->setType('lti_toolurl', PARAM_TEXT); -// $mform->addHelpButton('lti_toolurl', 'toolurl', 'basiclti'); - $mform->addRule('lti_toolurl', get_string('validurl', 'basiclti'), 'regex', $regex, 'client'); +// $mform->addHelpButton('lti_toolurl', 'toolurl', 'blti'); + $mform->addRule('lti_toolurl', get_string('validurl', 'blti'), 'regex', $regex, 'client'); $mform->addRule('lti_toolurl', null, 'required', null, 'client'); - $mform->addElement('text', 'lti_resourcekey', get_string('resourcekey', 'basiclti')); + $mform->addElement('text', 'lti_resourcekey', get_string('resourcekey', 'blti')); $mform->setType('lti_resourcekey', PARAM_TEXT); - $mform->addElement('passwordunmask', 'lti_password', get_string('password', 'basiclti')); + $mform->addElement('passwordunmask', 'lti_password', get_string('password', 'blti')); $mform->setType('lti_password', PARAM_TEXT); //------------------------------------------------------------------------------- // Add size parameters - $mform->addElement('header', 'size', get_string('size', 'basiclti')); + $mform->addElement('header', 'size', get_string('size', 'blti')); - $mform->addElement('text', 'lti_preferheight', get_string('preferheight', 'basiclti')); + $mform->addElement('text', 'lti_preferheight', get_string('preferheight', 'blti')); $mform->setType('lti_preferheight', PARAM_INT); -// $mform->addHelpButton('lti_preferheight', 'preferheight', 'basiclti'); +// $mform->addHelpButton('lti_preferheight', 'preferheight', 'blti'); //------------------------------------------------------------------------------- // Add privacy preferences fieldset where users choose whether to send their data - $mform->addElement('header', 'privacy', get_string('privacy', 'basiclti')); + $mform->addElement('header', 'privacy', get_string('privacy', 'blti')); $options=array(); - $options[0] = get_string('never', 'basiclti'); - $options[1] = get_string('always', 'basiclti'); - $options[2] = get_string('delegate', 'basiclti'); + $options[0] = get_string('never', 'blti'); + $options[1] = get_string('always', 'blti'); + $options[2] = get_string('delegate', 'blti'); $defaults=array(); - $defaults[0] = get_string('donot', 'basiclti'); - $defaults[1] = get_string('send', 'basiclti'); + $defaults[0] = get_string('donot', 'blti'); + $defaults[1] = get_string('send', 'blti'); - $mform->addElement('select', 'lti_sendname', get_string('sendname', 'basiclti'), $options); + $mform->addElement('select', 'lti_sendname', get_string('sendname', 'blti'), $options); $mform->setDefault('lti_sendname', '0'); -// $mform->addHelpButton('lti_sendname', 'sendname', 'basiclti'); +// $mform->addHelpButton('lti_sendname', 'sendname', 'blti'); - $mform->addElement('select', 'lti_instructorchoicesendname', get_string('setdefault', 'basiclti'), $defaults); + $mform->addElement('select', 'lti_instructorchoicesendname', get_string('setdefault', 'blti'), $defaults); $mform->setDefault('lti_instructorchoicesendname', '0'); $mform->disabledIf('lti_instructorchoicesendname', 'lti_sendname', 'neq', 2); - $mform->addElement('select', 'lti_sendemailaddr', get_string('sendemailaddr', 'basiclti'), $options); + $mform->addElement('select', 'lti_sendemailaddr', get_string('sendemailaddr', 'blti'), $options); $mform->setDefault('lti_sendemailaddr', '0'); -// $mform->addHelpButton('lti_sendemailaddr', 'sendemailaddr', 'basiclti'); +// $mform->addHelpButton('lti_sendemailaddr', 'sendemailaddr', 'blti'); - $mform->addElement('select', 'lti_instructorchoicesendemailaddr', get_string('setdefault', 'basiclti'), $defaults); + $mform->addElement('select', 'lti_instructorchoicesendemailaddr', get_string('setdefault', 'blti'), $defaults); $mform->setDefault('lti_instructorchoicesendemailaddr', '0'); $mform->disabledIf('lti_instructorchoicesendemailaddr', 'lti_sendemailaddr', 'neq', 2); //------------------------------------------------------------------------------- // BLTI Extensions - $mform->addElement('header', 'extensions', get_string('extensions', 'basiclti')); + $mform->addElement('header', 'extensions', get_string('extensions', 'blti')); $defaults_accept=array(); - $defaults_accept[0] = get_string('donotaccept', 'basiclti'); - $defaults_accept[1] = get_string('accept', 'basiclti'); + $defaults_accept[0] = get_string('donotaccept', 'blti'); + $defaults_accept[1] = get_string('accept', 'blti'); $defaults_allow=array(); - $defaults_allow[0] = get_string('donotallow', 'basiclti'); - $defaults_allow[1] = get_string('allow', 'basiclti'); + $defaults_allow[0] = get_string('donotallow', 'blti'); + $defaults_allow[1] = get_string('allow', 'blti'); // Add grading preferences fieldset where the tool is allowed to return grades - $mform->addElement('select', 'lti_acceptgrades', get_string('acceptgrades', 'basiclti'), $options); + $mform->addElement('select', 'lti_acceptgrades', get_string('acceptgrades', 'blti'), $options); $mform->setDefault('lti_acceptgrades', '0'); -// $mform->addHelpButton('lti_acceptgrades', 'acceptgrades', 'basiclti'); +// $mform->addHelpButton('lti_acceptgrades', 'acceptgrades', 'blti'); - $mform->addElement('select', 'lti_instructorchoiceacceptgrades', get_string('setdefault', 'basiclti'), $defaults_accept); + $mform->addElement('select', 'lti_instructorchoiceacceptgrades', get_string('setdefault', 'blti'), $defaults_accept); $mform->setDefault('lti_instructorchoiceacceptgrades', '0'); $mform->disabledIf('lti_instructorchoiceacceptgrades', 'lti_acceptgrades', 'neq', 2); // Add grading preferences fieldset where the tool is allowed to retrieve rosters - $mform->addElement('select', 'lti_allowroster', get_string('allowroster', 'basiclti'), $options); + $mform->addElement('select', 'lti_allowroster', get_string('allowroster', 'blti'), $options); $mform->setDefault('lti_allowroster', '0'); -// $mform->addHelpButton('lti_allowroster', 'allowroster', 'basiclti'); +// $mform->addHelpButton('lti_allowroster', 'allowroster', 'blti'); - $mform->addElement('select', 'lti_instructorchoiceallowroster', get_string('setdefault', 'basiclti'), $defaults_allow); + $mform->addElement('select', 'lti_instructorchoiceallowroster', get_string('setdefault', 'blti'), $defaults_allow); $mform->setDefault('lti_instructorchoiceallowroster', '0'); $mform->disabledIf('lti_instructorchoiceallowroster', 'lti_allowroster', 'neq', 2); // Add grading preferences fieldset where the tool is allowed to update settings - $mform->addElement('select', 'lti_allowsetting', get_string('allowsetting', 'basiclti'), $options); + $mform->addElement('select', 'lti_allowsetting', get_string('allowsetting', 'blti'), $options); $mform->setDefault('lti_allowsetting', '0'); -// $mform->addHelpButton('lti_allowsetting', 'allowsetting', 'basiclti'); +// $mform->addHelpButton('lti_allowsetting', 'allowsetting', 'blti'); - $mform->addElement('select', 'lti_instructorchoiceallowsetting', get_string('setdefault', 'basiclti'), $defaults_allow); + $mform->addElement('select', 'lti_instructorchoiceallowsetting', get_string('setdefault', 'blti'), $defaults_allow); $mform->setDefault('lti_instructorchoiceallowsetting', '0'); $mform->disabledIf('lti_instructorchoiceallowsetting', 'lti_allowsetting', 'neq', 2); //------------------------------------------------------------------------------- // Add custom parameters fieldset - $mform->addElement('header', 'custom', get_string('custom', 'basiclti')); + $mform->addElement('header', 'custom', get_string('custom', 'blti')); $mform->addElement('textarea', 'lti_customparameters', '', array('rows'=>15, 'cols'=>60)); $mform->setType('lti_customparameters', PARAM_TEXT); - $mform->addElement('select', 'lti_allowinstructorcustom', get_string('allowinstructorcustom', 'basiclti'), $defaults_allow); + $mform->addElement('select', 'lti_allowinstructorcustom', get_string('allowinstructorcustom', 'blti'), $defaults_allow); $mform->setDefault('lti_allowinstructorcustom', '0'); //------------------------------------------------------------------------------- // Add setup parameters fieldset - $mform->addElement('header', 'setupoptions', get_string('setupoptions', 'basiclti')); + $mform->addElement('header', 'setupoptions', get_string('setupoptions', 'blti')); // Adding option to change id that is placed in context_id $idoptions = array(); - $idoptions[0] = get_string('id', 'basiclti'); - $idoptions[1] = get_string('courseid', 'basiclti'); + $idoptions[0] = get_string('id', 'blti'); + $idoptions[1] = get_string('courseid', 'blti'); - $mform->addElement('select', 'lti_moodle_course_field', get_string('moodle_course_field', 'basiclti'), $idoptions); + $mform->addElement('select', 'lti_moodle_course_field', get_string('moodle_course_field', 'blti'), $idoptions); $mform->setDefault('lti_moodle_course_field', '0'); // Added option to allow user to specify if this is a resource or activity type $classoptions = array(); - $classoptions[0] = get_string('activity', 'basiclti'); - $classoptions[1] = get_string('resource', 'basiclti'); + $classoptions[0] = get_string('activity', 'blti'); + $classoptions[1] = get_string('resource', 'blti'); - $mform->addElement('select', 'lti_module_class_type', get_string('module_class_type', 'basiclti'), $classoptions); + $mform->addElement('select', 'lti_module_class_type', get_string('module_class_type', 'blti'), $classoptions); $mform->setDefault('lti_module_class_type', '0'); //------------------------------------------------------------------------------- // Add organization parameters fieldset - $mform->addElement('header', 'organization', get_string('organization', 'basiclti')); + $mform->addElement('header', 'organization', get_string('organization', 'blti')); - $mform->addElement('text', 'lti_organizationid', get_string('organizationid', 'basiclti')); + $mform->addElement('text', 'lti_organizationid', get_string('organizationid', 'blti')); $mform->setType('lti_organizationid', PARAM_TEXT); -// $mform->addHelpButton('lti_organizationid', 'organizationid', 'basiclti'); +// $mform->addHelpButton('lti_organizationid', 'organizationid', 'blti'); - $mform->addElement('text', 'lti_organizationurl', get_string('organizationurl', 'basiclti')); + $mform->addElement('text', 'lti_organizationurl', get_string('organizationurl', 'blti')); $mform->setType('lti_organizationurl', PARAM_TEXT); -// $mform->addHelpButton('lti_organizationurl', 'organizationurl', 'basiclti'); +// $mform->addHelpButton('lti_organizationurl', 'organizationurl', 'blti'); /* Suppress this for now - Chuck - $mform->addElement('text', 'lti_organizationdescr', get_string('organizationdescr', 'basiclti')); + $mform->addElement('text', 'lti_organizationdescr', get_string('organizationdescr', 'blti')); $mform->setType('lti_organizationdescr', PARAM_TEXT); - $mform->addHelpButton('lti_organizationdescr', 'organizationdescr', 'basiclti'); + $mform->addHelpButton('lti_organizationdescr', 'organizationdescr', 'blti'); */ //------------------------------------------------------------------------------- // Add launch parameters fieldset - $mform->addElement('header', 'launchoptions', get_string('launchoptions', 'basiclti')); + $mform->addElement('header', 'launchoptions', get_string('launchoptions', 'blti')); $launchoptions=array(); - $launchoptions[0] = get_string('launch_in_moodle', 'basiclti'); - $launchoptions[1] = get_string('launch_in_popup', 'basiclti'); + $launchoptions[0] = get_string('launch_in_moodle', 'blti'); + $launchoptions[1] = get_string('launch_in_popup', 'blti'); - $mform->addElement('select', 'lti_launchinpopup', get_string('launchinpopup', 'basiclti'), $launchoptions); + $mform->addElement('select', 'lti_launchinpopup', get_string('launchinpopup', 'blti'), $launchoptions); $mform->setDefault('lti_launchinpopup', '0'); -// $mform->addHelpButton('lti_launchinpopup', 'launchinpopup', 'basiclti'); +// $mform->addHelpButton('lti_launchinpopup', 'launchinpopup', 'blti'); //------------------------------------------------------------------------------- // Add a hidden element to signal a tool fixing operation after a problematic backup - restore process diff --git a/mod/basiclti/index.php b/mod/blti/index.php similarity index 90% rename from mod/basiclti/index.php rename to mod/blti/index.php index cf3c6cbcb17..fb2ff0fb5ed 100644 --- a/mod/basiclti/index.php +++ b/mod/blti/index.php @@ -33,7 +33,7 @@ /** * This page lists all the instances of basiclti in a particular course * - * @package basiclti + * @package blti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -45,7 +45,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once("../../config.php"); -require_once($CFG->dirroot.'/mod/basiclti/lib.php'); +require_once($CFG->dirroot.'/mod/blti/lib.php'); $id = required_param('id', PARAM_INT); // course id @@ -53,25 +53,25 @@ if (! $course = $DB->get_record("course", array("id" => $id))) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course ID is incorrect'); } -$url = new moodle_url('/mod/basiclti/index.php', array('id'=>$id)); +$url = new moodle_url('/mod/blti/index.php', array('id'=>$id)); $PAGE->set_url($url); $PAGE->set_pagelayout('incourse'); require_login($course); -add_to_log($course->id, "basiclti", "view all", "index.php?id=$course->id", ""); +add_to_log($course->id, "blti", "view all", "index.php?id=$course->id", ""); -$pagetitle = strip_tags($course->shortname.': '.get_string("modulenamepluralformatted", "basiclti")); +$pagetitle = strip_tags($course->shortname.': '.get_string("modulenamepluralformatted", "blti")); $PAGE->set_title($pagetitle); $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); /// Print the main part of the page -echo $OUTPUT->heading(get_string("modulenamepluralformatted", "basiclti")); +echo $OUTPUT->heading(get_string("modulenamepluralformatted", "blti")); /// Get all the appropriate data -if (! $basicltis = get_all_instances_in_course("basiclti", $course)) { +if (! $basicltis = get_all_instances_in_course("blti", $course)) { notice("There are no basicltis", "../../course/view.php?id=$course->id"); die; } diff --git a/mod/basiclti/lang/en/basiclti.php b/mod/blti/lang/en/blti.php similarity index 97% rename from mod/basiclti/lang/en/basiclti.php rename to mod/blti/lang/en/blti.php index bc8ae94d49f..62d95d44bbd 100644 --- a/mod/basiclti/lang/en/basiclti.php +++ b/mod/blti/lang/en/blti.php @@ -56,6 +56,7 @@ $string['allowinstructorcustom'] = 'Allow instructors to add custom parameters'; $string['allowroster'] = 'Allow tool access to course roster'; $string['allowsetting'] = 'Allow tool to store 8K of settings in Moodle'; $string['always'] = 'Always'; +$string['blti'] = 'Basic LTI'; $string['basiclti'] = 'Basic LTI'; $string['basiclti_base_string'] = 'Basic LTI OAuth Base String'; $string['basiclti_in_new_window'] = 'Your activity has opened in a new window'; @@ -131,7 +132,7 @@ $string['organizationurl'] ='Organization URL'; $string['pagesize'] = 'Submissions shown per page'; $string['password'] = 'Remote Tool Password'; $string['pluginadministration'] = 'Basic LTI administration'; -$string['pluginname'] = 'BasicLTI'; +$string['pluginname'] = 'BLTI'; $string['preferheight'] = 'Preferred Height'; $string['preferwidget'] = 'Prefer Widget Launch'; $string['preferwidth'] = 'Preferred Width'; diff --git a/mod/basiclti/lang/en/help/basiclti/index.html b/mod/blti/lang/en/help/basiclti/index.html similarity index 100% rename from mod/basiclti/lang/en/help/basiclti/index.html rename to mod/blti/lang/en/help/basiclti/index.html diff --git a/mod/basiclti/lang/en/help/basiclti/mods.html b/mod/blti/lang/en/help/basiclti/mods.html similarity index 100% rename from mod/basiclti/lang/en/help/basiclti/mods.html rename to mod/blti/lang/en/help/basiclti/mods.html diff --git a/mod/basiclti/launch.php b/mod/blti/launch.php similarity index 85% rename from mod/basiclti/launch.php rename to mod/blti/launch.php index 3326ce0af35..42769b63e41 100644 --- a/mod/basiclti/launch.php +++ b/mod/blti/launch.php @@ -33,7 +33,7 @@ /** * This file contains all necessary code to view a basiclti activity instance * - * @package basiclti + * @package blti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -46,8 +46,8 @@ */ require_once("../../config.php"); -require_once($CFG->dirroot.'/mod/basiclti/lib.php'); -require_once($CFG->dirroot.'/mod/basiclti/locallib.php'); +require_once($CFG->dirroot.'/mod/blti/lib.php'); +require_once($CFG->dirroot.'/mod/blti/locallib.php'); $id = optional_param('id', 0, PARAM_INT); // Course Module ID, or $object = optional_param('withobject', false, PARAM_BOOL); // Launch BasicLTI in an object @@ -61,25 +61,25 @@ if ($id) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured'); } - if (! $basiclti = $DB->get_record("basiclti", array("id" => $cm->instance))) { + if (! $basiclti = $DB->get_record("blti", array("id" => $cm->instance))) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect'); } } else { - if (! $basiclti = $DB->get_record("basiclti", array("id" => $a))) { + if (! $basiclti = $DB->get_record("blti", array("id" => $a))) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect'); } if (! $course = $DB->get_record("course", array("id" => $basiclti->course))) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured'); } - if (! $cm = get_coursemodule_from_instance("basiclti", $basiclti->id, $course->id)) { + if (! $cm = get_coursemodule_from_instance("blti", $basiclti->id, $course->id)) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect'); } } require_login($course); -add_to_log($course->id, "basiclti", "launch", "launch.php?id=$cm->id", "$basiclti->id"); +add_to_log($course->id, "blti", "launch", "launch.php?id=$cm->id", "$basiclti->id"); -basiclti_view($basiclti, $object); +blti_view($basiclti, $object); diff --git a/mod/basiclti/lib.php b/mod/blti/lib.php similarity index 84% rename from mod/basiclti/lib.php rename to mod/blti/lib.php index 809a84b02e7..e0888ef63f9 100644 --- a/mod/basiclti/lib.php +++ b/mod/blti/lib.php @@ -34,7 +34,7 @@ * This file contains a library of functions and constants for the * BasicLTI module * - * @package basiclti + * @package blti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -48,14 +48,14 @@ defined('MOODLE_INTERNAL') || die; -require_once($CFG->dirroot.'/mod/basiclti/locallib.php'); +require_once($CFG->dirroot.'/mod/blti/locallib.php'); /** * List of features supported in URL module * @param string $feature FEATURE_xx constant for requested feature * @return mixed True if module supports feature, false if not, null if doesn't know */ -function basiclti_supports($feature) { +function blti_supports($feature) { switch($feature) { case FEATURE_GROUPS: return false; case FEATURE_GROUPINGS: return false; @@ -79,19 +79,19 @@ function basiclti_supports($feature) { * @param object $instance An object from the form in mod.html * @return int The id of the newly inserted basiclti record **/ -function basiclti_add_instance($basiclti) { +function blti_add_instance($basiclti) { global $DB; $basiclti->timecreated = time(); $basiclti->timemodified = $basiclti->timecreated; $basiclti->placementsecret = uniqid('', true); $basiclti->timeplacementsecret = time(); - $id = $DB->insert_record("basiclti", $basiclti); + $id = $DB->insert_record("blti", $basiclti); - $basiclti = $DB->get_record('basiclti', array('id'=>$id)); + $basiclti = $DB->get_record('blti', array('id'=>$id)); if ($basiclti->instructorchoiceacceptgrades == 1) { - basiclti_grade_item_update($basiclti); + blti_grade_item_update($basiclti); } return $id; @@ -105,13 +105,13 @@ function basiclti_add_instance($basiclti) { * @param object $instance An object from the form in mod.html * @return boolean Success/Fail **/ -function basiclti_update_instance($basiclti) { +function blti_update_instance($basiclti) { global $DB; $basiclti->timemodified = time(); $basiclti->id = $basiclti->instance; - $basicltirec = $DB->get_record("basiclti", array("id" => $basiclti->id)); + $basicltirec = $DB->get_record("blti", array("id" => $basiclti->id)); $basiclti->grade = $basicltirec->grade; if (empty($basiclti->preferwidget)) { @@ -119,12 +119,12 @@ function basiclti_update_instance($basiclti) { } if ($basiclti->instructorchoiceacceptgrades == 1) { - basiclti_grade_item_update($basiclti); + blti_grade_item_update($basiclti); } else { - basiclti_grade_item_delete($basiclti); + blti_grade_item_delete($basiclti); } - return $DB->update_record("basiclti", $basiclti); + return $DB->update_record("blti", $basiclti); } /** @@ -135,19 +135,19 @@ function basiclti_update_instance($basiclti) { * @param int $id Id of the module instance * @return boolean Success/Failure **/ -function basiclti_delete_instance($id) { +function blti_delete_instance($id) { global $DB; - if (! $basiclti = $DB->get_record("basiclti", array("id" => $id))) { + if (! $basiclti = $DB->get_record("blti", array("id" => $id))) { return false; } $result = true; # Delete any dependent records here # - basiclti_grade_item_delete($basiclti); + blti_grade_item_delete($basiclti); - return $DB->delete_records("basiclti", array("id" => $basiclti->id)); + return $DB->delete_records("blti", array("id" => $basiclti->id)); } /** @@ -160,7 +160,7 @@ function basiclti_delete_instance($id) { * @return null * @TODO: implement this moodle function (if needed) **/ -function basiclti_user_outline($course, $user, $mod, $basiclti) { +function blti_user_outline($course, $user, $mod, $basiclti) { return $return; } @@ -171,7 +171,7 @@ function basiclti_user_outline($course, $user, $mod, $basiclti) { * @return boolean * @TODO: implement this moodle function (if needed) **/ -function basiclti_user_complete($course, $user, $mod, $basiclti) { +function blti_user_complete($course, $user, $mod, $basiclti) { return true; } @@ -184,7 +184,7 @@ function basiclti_user_complete($course, $user, $mod, $basiclti) { * @return boolean * @TODO: implement this moodle function **/ -function basiclti_print_recent_activity($course, $isteacher, $timestart) { +function blti_print_recent_activity($course, $isteacher, $timestart) { return false; // True if anything was printed, otherwise false } @@ -196,7 +196,7 @@ function basiclti_print_recent_activity($course, $isteacher, $timestart) { * @uses $CFG * @return boolean **/ -function basiclti_cron () { +function blti_cron () { return true; } @@ -215,7 +215,7 @@ function basiclti_cron () { * * @TODO: implement this moodle function (if needed) **/ -function basiclti_grades($basicltiid) { +function blti_grades($basicltiid) { return null; } @@ -230,7 +230,7 @@ function basiclti_grades($basicltiid) { * * @TODO: implement this moodle function **/ -function basiclti_get_participants($basicltiid) { +function blti_get_participants($basicltiid) { return false; } @@ -245,7 +245,7 @@ function basiclti_get_participants($basicltiid) { * * @TODO: implement this moodle function (if needed) **/ -function basiclti_scale_used ($basicltiid, $scaleid) { +function blti_scale_used ($basicltiid, $scaleid) { $return = false; //$rec = get_record("basiclti","id","$basicltiid","scale","-$scaleid"); @@ -266,10 +266,10 @@ function basiclti_scale_used ($basicltiid, $scaleid) { * @return boolean True if the scale is used by any basiclti * */ -function basiclti_scale_used_anywhere($scaleid) { +function blti_scale_used_anywhere($scaleid) { global $DB; - if ($scaleid and $DB->record_exists('basiclti', array('grade' => -$scaleid))) { + if ($scaleid and $DB->record_exists('blti', array('grade' => -$scaleid))) { return true; } else { return false; @@ -282,7 +282,7 @@ function basiclti_scale_used_anywhere($scaleid) { * * @return boolean true if success, false on error */ -function basiclti_install() { +function blti_install() { return true; } @@ -292,7 +292,7 @@ function basiclti_install() { * * @return boolean true if success, false on error */ -function basiclti_uninstall() { +function blti_uninstall() { return true; } @@ -301,10 +301,10 @@ function basiclti_uninstall() { * * @return array of basicLTI types */ -function basiclti_get_basiclti_types() { +function blti_get_blti_types() { global $DB; - return $DB->get_records('basiclti_types'); + return $DB->get_records('blti_types'); } /** @@ -312,13 +312,13 @@ function basiclti_get_basiclti_types() { * * @return array of basicLTI types */ -function basiclti_get_types() { +function blti_get_types() { $types = array(); - $basicltitypes = basiclti_get_basiclti_types(); + $basicltitypes = blti_get_blti_types(); if (!empty($basicltitypes)) { foreach ($basicltitypes as $basicltitype) { - $ltitypesconfig = basiclti_get_type_config($basicltitype->id); + $ltitypesconfig = blti_get_type_config($basicltitype->id); $modclass = MOD_CLASS_ACTIVITY; if (isset($ltitypesconfig['module_class_type'])) { @@ -329,7 +329,7 @@ function basiclti_get_types() { $type = new object(); $type->modclass = $modclass; - $type->type = 'basiclti&type='.urlencode($basicltitype->rawname); + $type->type = 'blti&type='.urlencode($basicltitype->rawname); $type->typestr = $basicltitype->name; $types[] = $type; } @@ -385,7 +385,7 @@ function basiclti_get_types() { * @global object * @param string $mode Specifies the kind of teacher interaction taking place */ -function basiclti_submissions($cm, $course, $basiclti, $mode) { +function blti_submissions($cm, $course, $basiclti, $mode) { ///The main switch is changed to facilitate ///1) Batch fast grading ///2) Skip to the next one on the popup @@ -405,33 +405,33 @@ function basiclti_submissions($cm, $course, $basiclti, $mode) { if (is_null($mailinfo)) { if (optional_param('sesskey', null, PARAM_BOOL)) { - set_user_preference('basiclti_mailinfo', $mailinfo); + set_user_preference('blti_mailinfo', $mailinfo); } else { - $mailinfo = get_user_preferences('basiclti_mailinfo', 0); + $mailinfo = get_user_preferences('blti_mailinfo', 0); } } else { - set_user_preference('basiclti_mailinfo', $mailinfo); + set_user_preference('blti_mailinfo', $mailinfo); } switch ($mode) { case 'grade': // We are in a main window grading if ($submission = process_feedback()) { - basiclti_display_submissions($cm, $course, $basiclti, get_string('changessaved')); + blti_display_submissions($cm, $course, $basiclti, get_string('changessaved')); } else { - basiclti_display_submissions($cm, $course, $basiclti); + blti_display_submissions($cm, $course, $basiclti); } break; case 'single': // We are in a main window displaying one submission if ($submission = process_feedback()) { - basiclti_display_submissions($cm, $course, $basiclti, get_string('changessaved')); + blti_display_submissions($cm, $course, $basiclti, get_string('changessaved')); } else { display_submission(); } break; case 'all': // Main window, display everything - basiclti_display_submissions($cm, $course, $basiclti); + blti_display_submissions($cm, $course, $basiclti); break; case 'fastgrade': @@ -449,7 +449,7 @@ function basiclti_submissions($cm, $course, $basiclti, $mode) { } if (!$col) { //both submissioncomment and grade columns collapsed.. - basiclti_display_submissions($cm, $course, $basiclti); + blti_display_submissions($cm, $course, $basiclti); break; } @@ -543,7 +543,7 @@ function basiclti_submissions($cm, $course, $basiclti, $mode) { } //add to log only if updating - add_to_log($course->id, 'basiclti', 'update grades', + add_to_log($course->id, 'blti', 'update grades', 'submissions.php?id='.$cm->id.'&user='.$USER->id, $USER->id, $cm->id); } @@ -552,7 +552,7 @@ function basiclti_submissions($cm, $course, $basiclti, $mode) { $message = $OUTPUT->notification(get_string('changessaved'), 'notifysuccess'); - basiclti_display_submissions($cm, $course, $basiclti, $message); + blti_display_submissions($cm, $course, $basiclti, $message); break; case 'saveandnext': @@ -595,7 +595,7 @@ function basiclti_submissions($cm, $course, $basiclti, $mode) { * @param string $message * @return bool|void */ -function basiclti_display_submissions($cm, $course, $basiclti, $message='') { +function blti_display_submissions($cm, $course, $basiclti, $message='') { global $CFG, $DB, $OUTPUT, $PAGE; require_once($CFG->libdir.'/gradelib.php'); @@ -608,18 +608,18 @@ function basiclti_display_submissions($cm, $course, $basiclti, $message='') { $perpage = optional_param('perpage', 10, PARAM_INT); $perpage = ($perpage <= 0) ? 10 : $perpage; $filter = optional_param('filter', 0, PARAM_INT); - set_user_preference('basiclti_perpage', $perpage); - set_user_preference('basiclti_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL)); - set_user_preference('basiclti_filter', $filter); + set_user_preference('blti_perpage', $perpage); + set_user_preference('blti_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL)); + set_user_preference('blti_filter', $filter); } /* next we get perpage and quickgrade (allow quick grade) params * from database */ - $perpage = get_user_preferences('basiclti_perpage', 10); - $quickgrade = get_user_preferences('basiclti_quickgrade', 0); - $filter = get_user_preferences('basiclti_filter', 0); - $grading_info = grade_get_grades($course->id, 'mod', 'basiclti', $basiclti->id); + $perpage = get_user_preferences('blti_perpage', 10); + $quickgrade = get_user_preferences('blti_quickgrade', 0); + $filter = get_user_preferences('blti_filter', 0); + $grading_info = grade_get_grades($course->id, 'mod', 'blti', $basiclti->id); if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) { $uses_outcomes = true; @@ -628,10 +628,10 @@ function basiclti_display_submissions($cm, $course, $basiclti, $message='') { } $page = optional_param('page', 0, PARAM_INT); - $strsaveallfeedback = get_string('saveallfeedback', 'basiclti'); + $strsaveallfeedback = get_string('saveallfeedback', 'blti'); $tabindex = 1; //tabindex for quick grading tabbing; Not working for dropdowns yet - add_to_log($course->id, 'basiclti', 'view submission', 'submissions.php?id='.$cm->id, $basiclti->id, $cm->id); + add_to_log($course->id, 'blti', 'view submission', 'submissions.php?id='.$cm->id, $basiclti->id, $cm->id); $PAGE->set_title(format_string($basiclti->name, true)); $PAGE->set_heading($course->fullname); @@ -645,7 +645,7 @@ function basiclti_display_submissions($cm, $course, $basiclti, $message='') { /// Print quickgrade form around the table if ($quickgrade) { $formattrs = array(); - $formattrs['action'] = new moodle_url('/mod/basiclti/submissions.php'); + $formattrs['action'] = new moodle_url('/mod/blti/submissions.php'); $formattrs['id'] = 'fastg'; $formattrs['method'] = 'post'; @@ -673,10 +673,10 @@ function basiclti_display_submissions($cm, $course, $basiclti, $message='') { /// find out current groups mode $groupmode = groups_get_activity_groupmode($cm); $currentgroup = groups_get_activity_group($cm, true); - groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/basiclti/submissions.php?id=' . $cm->id); + groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/blti/submissions.php?id=' . $cm->id); /// Get all ppl that are allowed to submit tools - list($esql, $params) = get_enrolled_sql($context, 'mod/basiclti:view', $currentgroup); + list($esql, $params) = get_enrolled_sql($context, 'mod/blti:view', $currentgroup); $sql = "SELECT u.id FROM {user} u ". "LEFT JOIN ($esql) eu ON eu.id=u.id ". @@ -702,8 +702,8 @@ function basiclti_display_submissions($cm, $course, $basiclti, $message='') { $tableheaders = array('', get_string('fullname'), get_string('grade'), - get_string('comment', 'basiclti'), - get_string('lastmodified').' ('.get_string('submission', 'basiclti').')', + get_string('comment', 'blti'), + get_string('lastmodified').' ('.get_string('submission', 'blti').')', get_string('lastmodified').' ('.get_string('grade').')', get_string('status'), get_string('finalgrade', 'grades')); @@ -712,11 +712,11 @@ function basiclti_display_submissions($cm, $course, $basiclti, $message='') { } require_once($CFG->libdir.'/tablelib.php'); - $table = new flexible_table('mod-basiclti-submissions'); + $table = new flexible_table('mod-blti-submissions'); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); - $table->define_baseurl($CFG->wwwroot.'/mod/basiclti/submissions.php?id='.$cm->id.'&currentgroup='.$currentgroup); + $table->define_baseurl($CFG->wwwroot.'/mod/blti/submissions.php?id='.$cm->id.'&currentgroup='.$currentgroup); $table->sortable(true, 'lastname');//sorted by lastname by default $table->collapsible(true); @@ -749,7 +749,7 @@ function basiclti_display_submissions($cm, $course, $basiclti, $message='') { $table->setup(); if (empty($users)) { - echo $OUTPUT->heading(get_string('noviewusers', 'basiclti')); + echo $OUTPUT->heading(get_string('noviewusers', 'blti')); echo ''; return true; } @@ -788,7 +788,7 @@ function basiclti_display_submissions($cm, $course, $basiclti, $message='') { $strgrade = get_string('grade'); $grademenu = make_grades_menu($basiclti->grade); if ($ausers !== false) { - $grading_info = grade_get_grades($course->id, 'mod', 'basiclti', $basiclti->id, array_keys($ausers)); + $grading_info = grade_get_grades($course->id, 'mod', 'blti', $basiclti->id, array_keys($ausers)); $endposition = $offset + $perpage; $currentposition = 0; foreach ($ausers as $auser) { @@ -861,7 +861,7 @@ function basiclti_display_submissions($cm, $course, $basiclti, $message='') { $buttontext = ($auser->status == 1) ? $strupdate : $strgrade; ///No more buttons, we use popups ;-). - $popup_url = '/mod/basiclti/submissions.php?id='.$cm->id + $popup_url = '/mod/blti/submissions.php?id='.$cm->id . '&userid='.$auser->id.'&mode=single'.'&filter='.$filter.'&offset='.$offset++; $button = $OUTPUT->action_link($popup_url, $buttontext); @@ -908,15 +908,15 @@ function basiclti_display_submissions($cm, $course, $basiclti, $message='') { /// Print quickgrade form around the table if ($quickgrade && $table->started_output) { $mailinfopref = false; - if (get_user_preferences('basiclti_mailinfo', 1)) { + if (get_user_preferences('blti_mailinfo', 1)) { $mailinfopref = true; } - $emailnotification = html_writer::checkbox('mailinfo', 1, $mailinfopref, get_string('enableemailnotification', 'basiclti')); + $emailnotification = html_writer::checkbox('mailinfo', 1, $mailinfopref, get_string('enableemailnotification', 'blti')); - $emailnotification .= $OUTPUT->help_icon('enableemailnotification', 'basiclti'); + $emailnotification .= $OUTPUT->help_icon('enableemailnotification', 'blti'); echo html_writer::tag('div', $emailnotification, array('class'=>'emailnotification')); - $savefeedback = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'fastg', 'value'=>get_string('saveallfeedback', 'basiclti'))); + $savefeedback = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'fastg', 'value'=>get_string('saveallfeedback', 'blti'))); echo html_writer::tag('div', $savefeedback, array('class'=>'fastgbutton')); echo html_writer::end_tag('form'); @@ -929,22 +929,22 @@ function basiclti_display_submissions($cm, $course, $basiclti, $message='') { /// Mini form for setting user preference - $formaction = new moodle_url('/mod/basiclti/submissions.php', array('id'=>$cm->id)); + $formaction = new moodle_url('/mod/blti/submissions.php', array('id'=>$cm->id)); $mform = new MoodleQuickForm('optionspref', 'post', $formaction, '', array('class'=>'optionspref')); $mform->addElement('hidden', 'updatepref'); $mform->setDefault('updatepref', 1); - $mform->addElement('header', 'qgprefs', get_string('optionalsettings', 'basiclti')); + $mform->addElement('header', 'qgprefs', get_string('optionalsettings', 'blti')); // $mform->addElement('select', 'filter', get_string('show'), $filters); $mform->setDefault('filter', $filter); - $mform->addElement('text', 'perpage', get_string('pagesize', 'basiclti'), array('size'=>1)); + $mform->addElement('text', 'perpage', get_string('pagesize', 'blti'), array('size'=>1)); $mform->setDefault('perpage', $perpage); - $mform->addElement('checkbox', 'quickgrade', get_string('quickgrade', 'basiclti')); + $mform->addElement('checkbox', 'quickgrade', get_string('quickgrade', 'blti')); $mform->setDefault('quickgrade', $quickgrade); - $mform->addHelpButton('quickgrade', 'quickgrade', 'basiclti'); + $mform->addHelpButton('quickgrade', 'quickgrade', 'blti'); $mform->addElement('submit', 'savepreferences', get_string('savepreferences')); @@ -960,7 +960,7 @@ function basiclti_display_submissions($cm, $course, $basiclti, $message='') { * @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook * @return int 0 if ok, error code otherwise */ -function basiclti_grade_item_update($basiclti, $grades=null) { +function blti_grade_item_update($basiclti, $grades=null) { global $CFG; require_once($CFG->libdir.'/gradelib.php'); @@ -988,7 +988,7 @@ function basiclti_grade_item_update($basiclti, $grades=null) { $grades = null; } - return grade_update('mod/basiclti', $basiclti->courseid, 'mod', 'basiclti', $basiclti->id, 0, $grades, $params); + return grade_update('mod/blti', $basiclti->courseid, 'mod', 'blti', $basiclti->id, 0, $grades, $params); } /** @@ -997,7 +997,7 @@ function basiclti_grade_item_update($basiclti, $grades=null) { * @param object $basiclti object * @return object basiclti */ -function basiclti_grade_item_delete($basiclti) { +function blti_grade_item_delete($basiclti) { global $CFG; require_once($CFG->libdir.'/gradelib.php'); @@ -1005,6 +1005,6 @@ function basiclti_grade_item_delete($basiclti) { $basiclti->courseid = $basiclti->course; } - return grade_update('mod/basiclti', $basiclti->courseid, 'mod', 'basiclti', $basiclti->id, 0, null, array('deleted'=>1)); + return grade_update('mod/blti', $basiclti->courseid, 'mod', 'blti', $basiclti->id, 0, null, array('deleted'=>1)); } diff --git a/mod/basiclti/localadminlib.php b/mod/blti/localadminlib.php similarity index 88% rename from mod/basiclti/localadminlib.php rename to mod/blti/localadminlib.php index f6fe1182c7c..4ccb940da7f 100644 --- a/mod/basiclti/localadminlib.php +++ b/mod/blti/localadminlib.php @@ -34,7 +34,7 @@ * This file contains some functions and classes used in Basic LTI * module administration * - * @package basiclti + * @package blti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -54,7 +54,7 @@ require_once($CFG->libdir.'/adminlib.php'); * * @TODO: finish doc this class and it's functions */ -class admin_setting_basicltimodule_configlink extends admin_setting { +class admin_setting_bltimodule_configlink extends admin_setting { /** * Constructor @@ -62,7 +62,7 @@ class admin_setting_basicltimodule_configlink extends admin_setting { * @param string $visiblename localised * @param string $description long localised info */ - function admin_setting_basicltimodule_configlink($name, $visiblename, $description) { + function admin_setting_bltimodule_configlink($name, $visiblename, $description) { parent::__construct($name, $visiblename, $description, ''); } @@ -78,7 +78,7 @@ class admin_setting_basicltimodule_configlink extends admin_setting { global $CFG; return format_admin_setting($this, "", '', $this->description, true, '', null, $query); } diff --git a/mod/basiclti/locallib.php b/mod/blti/locallib.php similarity index 84% rename from mod/basiclti/locallib.php rename to mod/blti/locallib.php index b200c27a5b1..2310b0a4ce8 100644 --- a/mod/basiclti/locallib.php +++ b/mod/blti/locallib.php @@ -33,7 +33,7 @@ /** * This file contains the library of functions and constants for the basiclti module * - * @package basiclti + * @package blti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -47,17 +47,17 @@ defined('MOODLE_INTERNAL') || die; -require_once($CFG->dirroot.'/mod/basiclti/OAuth.php'); +require_once($CFG->dirroot.'/mod/blti/OAuth.php'); /** * Prints a Basic LTI activity * * $param int $basicltiid Basic LTI activity id */ -function basiclti_view($instance, $makeobject=false) { +function blti_view($instance, $makeobject=false) { global $PAGE; - $typeconfig = basiclti_get_type_config($instance->typeid); + $typeconfig = blti_get_type_config($instance->typeid); $endpoint = $typeconfig['toolurl']; $key = $typeconfig['resourcekey']; $secret = $typeconfig['password']; @@ -67,7 +67,7 @@ function basiclti_view($instance, $makeobject=false) { */ $course = $PAGE->course; - $requestparams = basiclti_build_request($instance, $typeconfig, $course); + $requestparams = blti_build_request($instance, $typeconfig, $course); // Make sure we let the tool know what LMS they are being called from $requestparams["ext_lms"] = "moodle-2"; @@ -75,7 +75,7 @@ function basiclti_view($instance, $makeobject=false) { // Add oauth_callback to be compliant with the 1.0A spec $requestparams["oauth_callback"] = "about:blank"; - $submittext = get_string('press_to_submit', 'basiclti'); + $submittext = get_string('press_to_submit', 'blti'); $parms = sign_parameters($requestparams, $endpoint, "POST", $key, $secret, $submittext, $orgid /*, $orgdesc*/); $debuglaunch = ( $instance->debuglaunch == 1 ); @@ -89,7 +89,7 @@ function basiclti_view($instance, $makeobject=false) { } else { $content = post_launch_html($parms, $endpoint, $debuglaunch, false); } -// $cm = get_coursemodule_from_instance("basiclti", $instance->id); +// $cm = get_coursemodule_from_instance("blti", $instance->id); // print ''.$content.''; print $content; } @@ -103,11 +103,11 @@ function basiclti_view($instance, $makeobject=false) { * * @return array $request Request details */ -function basiclti_build_request($instance, $typeconfig, $course) { +function blti_build_request($instance, $typeconfig, $course) { global $USER, $CFG; $context = get_context_instance(CONTEXT_COURSE, $course->id); - $role = basiclti_get_ims_role($USER, $context); + $role = blti_get_ims_role($USER, $context); $locale = $course->lang; if ( strlen($locale) < 1 ) { @@ -138,21 +138,21 @@ function basiclti_build_request($instance, $typeconfig, $course) { ( $typeconfig['acceptgrades'] == 1 || ( $typeconfig['acceptgrades'] == 2 && $instance->instructorchoiceacceptgrades == 1 ) ) ) { $requestparams["lis_result_sourcedid"] = $sourcedid; - $requestparams["ext_ims_lis_basic_outcome_url"] = $CFG->wwwroot.'/mod/basiclti/service.php'; + $requestparams["ext_ims_lis_basic_outcome_url"] = $CFG->wwwroot.'/mod/blti/service.php'; } if ( isset($placementsecret) && ( $typeconfig['allowroster'] == 1 || ( $typeconfig['allowroster'] == 2 && $instance->instructorchoiceallowroster == 1 ) ) ) { $requestparams["ext_ims_lis_memberships_id"] = $sourcedid; - $requestparams["ext_ims_lis_memberships_url"] = $CFG->wwwroot.'/mod/basiclti/service.php'; + $requestparams["ext_ims_lis_memberships_url"] = $CFG->wwwroot.'/mod/blti/service.php'; } if ( isset($placementsecret) && ( $typeconfig['allowsetting'] == 1 || ( $typeconfig['allowsetting'] == 2 && $instance->instructorchoiceallowsetting == 1 ) ) ) { $requestparams["ext_ims_lti_tool_setting_id"] = $sourcedid; - $requestparams["ext_ims_lti_tool_setting_url"] = $CFG->wwwroot.'/mod/basiclti/service.php'; + $requestparams["ext_ims_lti_tool_setting_url"] = $CFG->wwwroot.'/mod/blti/service.php'; $setting = $instance->setting; if ( isset($setting) ) { $requestparams["ext_ims_lti_tool_setting"] = $setting; @@ -260,7 +260,7 @@ function map_keyname($key) { * @return string IMS Role * */ -function basiclti_get_ims_role($user, $context) { +function blti_get_ims_role($user, $context) { $roles = get_user_roles($context, $user->id); $rolesname = array(); @@ -269,14 +269,14 @@ function basiclti_get_ims_role($user, $context) { } if (in_array('admin', $rolesname) || in_array('coursecreator', $rolesname)) { - return get_string('imsroleadmin', 'basiclti'); + return get_string('imsroleadmin', 'blti'); } if (in_array('editingteacher', $rolesname) || in_array('teacher', $rolesname)) { - return get_string('imsroleinstructor', 'basiclti'); + return get_string('imsroleinstructor', 'blti'); } - return get_string('imsrolelearner', 'basiclti'); + return get_string('imsrolelearner', 'blti'); } /** @@ -286,11 +286,11 @@ function basiclti_get_ims_role($user, $context) { * * @return array Tool Configuration */ -function basiclti_get_type_config($typeid) { +function blti_get_type_config($typeid) { global $DB; $typeconfig = array(); - $configs = $DB->get_records('basiclti_types_config', array('typeid' => $typeid)); + $configs = $DB->get_records('blti_types_config', array('typeid' => $typeid)); if (!empty($configs)) { foreach ($configs as $config) { $typeconfig[$config->name] = $config->value; @@ -305,30 +305,30 @@ function basiclti_get_type_config($typeid) { * backup - restore process. * */ -function basiclti_get_unconfigured_tools() { +function blti_get_unconfigured_tools() { global $DB; - return $DB->get_records('basiclti', array('typeid' => 0)); + return $DB->get_records('blti', array('typeid' => 0)); } /** * Returns all basicLTI tools configured by the administrator * */ -function basiclti_filter_get_types() { +function blti_filter_get_types() { global $DB; - return $DB->get_records('basiclti_types'); + return $DB->get_records('blti_types'); } /** * Prints the various configured tool types * */ -function basiclti_filter_print_types() { +function blti_filter_print_types() { global $CFG; - $types = basiclti_filter_get_types(); + $types = blti_filter_get_types(); if (!empty($types)) { echo '
    '; foreach ($types as $type) { @@ -348,7 +348,7 @@ function basiclti_filter_print_types() { echo '
'; } else { echo '
'; - echo get_string('notypes', 'basiclti'); + echo get_string('notypes', 'blti'); echo '
'; } } @@ -358,17 +358,17 @@ function basiclti_filter_print_types() { * * @param int $id Configuration id */ -function basiclti_delete_type($id) { +function blti_delete_type($id) { global $DB; - $instances = $DB->get_records('basiclti', array('typeid' => $id)); + $instances = $DB->get_records('blti', array('typeid' => $id)); foreach ($instances as $instance) { $instance->typeid = 0; - $DB->update_record('basiclti', $instance); + $DB->update_record('blti', $instance); } - $DB->delete_records('basiclti_types', array('id' => $id)); - $DB->delete_records('basiclti_types_config', array('typeid' => $id)); + $DB->delete_records('blti_types', array('id' => $id)); + $DB->delete_records('blti_types_config', array('typeid' => $id)); } /** @@ -378,10 +378,10 @@ function basiclti_delete_type($id) { * * @return array Basic LTI configuration details */ -function basiclti_get_config($bltiobject) { +function blti_get_config($bltiobject) { $typeconfig = array(); $typeconfig = (array)$bltiobject; - $additionalconfig = basiclti_get_type_config($bltiobject->typeid); + $additionalconfig = blti_get_type_config($bltiobject->typeid); $typeconfig = array_merge($typeconfig, $additionalconfig); return $typeconfig; } @@ -395,11 +395,11 @@ function basiclti_get_config($bltiobject) { * @return Instance configuration * */ -function basiclti_get_type_config_from_instance($id) { +function blti_get_type_config_from_instance($id) { global $DB; - $instance = $DB->get_record('basiclti', array('id' => $id)); - $config = basiclti_get_config($instance); + $instance = $DB->get_record('blti', array('id' => $id)); + $config = blti_get_config($instance); $type = new stdClass(); $type->lti_fix = $id; @@ -437,11 +437,11 @@ function basiclti_get_type_config_from_instance($id) { * * @return Configuration details */ -function basiclti_get_type_type_config($id) { +function blti_get_type_type_config($id) { global $DB; - $basicltitype = $DB->get_record('basiclti_types', array('id' => $id)); - $config = basiclti_get_type_config($id); + $basicltitype = $DB->get_record('blti_types', array('id' => $id)); + $config = blti_get_type_config($id); $type->lti_typename = $basicltitype->name; if (isset($config['toolurl'])) { @@ -524,10 +524,10 @@ function basiclti_get_type_type_config($id) { * * @return int Record id number */ -function basiclti_add_config($config) { +function blti_add_config($config) { global $DB; - return $DB->insert_record('basiclti_types_config', $config); + return $DB->insert_record('blti_types_config', $config); } /** @@ -537,15 +537,15 @@ function basiclti_add_config($config) { * * @return Record id number */ -function basiclti_update_config($config) { +function blti_update_config($config) { global $DB; $return = true; - if ($old = $DB->get_record('basiclti_types_config', array('typeid' => $config->typeid, 'name' => $config->name))) { + if ($old = $DB->get_record('blti_types_config', array('typeid' => $config->typeid, 'name' => $config->name))) { $config->id = $old->id; - $return = $DB->update_record('basiclti_types_config', $config); + $return = $DB->update_record('blti_types_config', $config); } else { - $return = $DB->insert_record('basiclti_types_config', $config); + $return = $DB->insert_record('blti_types_config', $config); } return $return; } @@ -557,26 +557,26 @@ function basiclti_update_config($config) { * @param int $id ID of the misconfigured tool * */ -function basiclti_fix_misconfigured_choice($id) { +function blti_fix_misconfigured_choice($id) { global $CFG, $USER, $OUTPUT; echo $OUTPUT->box_start('generalbox'); echo '
'; - $types = basiclti_filter_get_types(); + $types = blti_filter_get_types(); if (!empty($types)) { - echo '

'.get_string('fixexistingconf', 'basiclti').'


'; - echo '
sesskey.' method="post">'; + echo '

'.get_string('fixexistingconf', 'blti').'


'; + echo 'sesskey.' method="post">'; foreach ($types as $type) { echo ''.$type->name.'
'; } echo ''; echo '
'; - echo '
'; + echo '
'; echo ''; } else { echo '
'; - echo get_string('notypes', 'basiclti'); + echo get_string('notypes', 'blti'); echo '
'; } echo '
'; @@ -584,11 +584,11 @@ function basiclti_fix_misconfigured_choice($id) { echo $OUTPUT->box_start("generalbox"); echo '
'; - echo '

'.get_string('fixnewconf', 'basiclti').'


'; - echo '
sesskey.' method="post">'; + echo '

'.get_string('fixnewconf', 'blti').'


'; + echo 'sesskey.' method="post">'; echo ''; echo ''; - echo '
'; + echo '
'; echo ''; echo '
'; echo $OUTPUT->box_end(); @@ -683,18 +683,18 @@ function post_launch_html($newparms, $endpoint, $debug=false, $height=false) { $r .= " //]]> \n"; $r .= "\n"; $r .= ""; - $r .= get_string("toggle_debug_data", "basiclti")."\n"; + $r .= get_string("toggle_debug_data", "blti")."\n"; $r .= "
\n"; - $r .= "".get_string("basiclti_endpoint", "basiclti")."
\n"; + $r .= "".get_string("basiclti_endpoint", "blti")."
\n"; $r .= $endpoint . "
\n 
\n"; - $r .= "".get_string("basiclti_parameters", "basiclti")."
\n"; + $r .= "".get_string("basiclti_parameters", "blti")."
\n"; foreach ($newparms as $key => $value) { $key = htmlspecialchars($key); $value = htmlspecialchars($value); $r .= "$key = $value
\n"; } $r .= " 
\n"; - $r .= "

".get_string("basiclti_base_string", "basiclti")."
\n".$lastbasestring."

\n"; + $r .= "

".get_string("basiclti_base_string", "blti")."
\n".$lastbasestring."

\n"; $r .= "
\n"; } $r .= "\n"; @@ -734,10 +734,10 @@ function submittedlink($cm, $allgroups=false) { global $CFG; $submitted = ''; - $urlbase = "{$CFG->wwwroot}/mod/basiclti/"; + $urlbase = "{$CFG->wwwroot}/mod/blti/"; $context = get_context_instance(CONTEXT_MODULE, $cm->id); - if (has_capability('mod/basiclti:grade', $context)) { + if (has_capability('mod/blti:grade', $context)) { if ($allgroups and has_capability('moodle/site:accessallgroups', $context)) { $group = 0; } else { @@ -745,7 +745,7 @@ function submittedlink($cm, $allgroups=false) { } $submitted = ''. - get_string('viewsubmissions', 'basiclti').''; + get_string('viewsubmissions', 'blti').''; } else { if (isloggedin()) { // TODO Insert code for students if needed diff --git a/mod/basiclti/mod_form.php b/mod/blti/mod_form.php similarity index 80% rename from mod/basiclti/mod_form.php rename to mod/blti/mod_form.php index 8a27a9e70d4..9eceb6ac89e 100644 --- a/mod/basiclti/mod_form.php +++ b/mod/blti/mod_form.php @@ -33,7 +33,7 @@ /** * This file defines the main basiclti configuration form * - * @package basiclti + * @package blti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -48,9 +48,9 @@ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot.'/course/moodleform_mod.php'); -require_once($CFG->dirroot.'/mod/basiclti/locallib.php'); +require_once($CFG->dirroot.'/mod/blti/locallib.php'); -class mod_basiclti_mod_form extends moodleform_mod { +class mod_blti_mod_form extends moodleform_mod { function definition() { global $DB; @@ -60,10 +60,10 @@ class mod_basiclti_mod_form extends moodleform_mod { if (empty($typename)) { //Updating instance if (!empty($this->_instance)) { - $basiclti = $DB->get_record('basiclti', array('id' => $this->_instance)); + $basiclti = $DB->get_record('blti', array('id' => $this->_instance)); $this->typeid = $basiclti->typeid; - $typeconfig = basiclti_get_config($basiclti); + $typeconfig = blti_get_config($basiclti); $this->typeconfig = $typeconfig; } else { // New not pre-configured instance @@ -71,10 +71,10 @@ class mod_basiclti_mod_form extends moodleform_mod { } } else { // New pre-configured instance - $basicltitype = $DB->get_record('basiclti_types', array('rawname' => $typename)); + $basicltitype = $DB->get_record('blti_types', array('rawname' => $typename)); $this->typeid = $basicltitype->id; - $typeconfig = basiclti_get_type_config($this->typeid); + $typeconfig = blti_get_type_config($this->typeid); $this->typeconfig = $typeconfig; } @@ -83,11 +83,11 @@ class mod_basiclti_mod_form extends moodleform_mod { /// Adding the "general" fieldset, where all the common settings are shown $mform->addElement('header', 'general', get_string('general', 'form')); /// Adding the standard "name" field - $mform->addElement('text', 'name', get_string('basicltiname', 'basiclti'), array('size'=>'64')); + $mform->addElement('text', 'name', get_string('basicltiname', 'blti'), array('size'=>'64')); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', null, 'required', null, 'client'); /// Adding the optional "intro" and "introformat" pair of fields - $this->add_intro_editor(true, get_string('basicltiintro', 'basiclti')); + $this->add_intro_editor(true, get_string('basicltiintro', 'blti')); //------------------------------------------------------------------------------- $mform->addElement('hidden', 'typeid', $this->typeid); @@ -96,13 +96,13 @@ class mod_basiclti_mod_form extends moodleform_mod { //------------------------------------------------------------------------------- // Add privacy preferences fieldset where users choose whether to send their data - $mform->addElement('header', 'privacy', get_string('privacy', 'basiclti')); + $mform->addElement('header', 'privacy', get_string('privacy', 'blti')); $privacyoptions=array(); - $privacyoptions[0] = get_string('donot', 'basiclti'); - $privacyoptions[1] = get_string('send', 'basiclti'); + $privacyoptions[0] = get_string('donot', 'blti'); + $privacyoptions[1] = get_string('send', 'blti'); - $mform->addElement('select', 'instructorchoicesendname', get_string('sendname', 'basiclti'), $privacyoptions); + $mform->addElement('select', 'instructorchoicesendname', get_string('sendname', 'blti'), $privacyoptions); if (isset($this->typeconfig['instructorchoicesendname'])) { if ($this->typeconfig['instructorchoicesendname'] == 0) { @@ -111,9 +111,9 @@ class mod_basiclti_mod_form extends moodleform_mod { $mform->setDefault('instructorchoicesendname', '1'); } } -// $mform->addHelpButton('instructorchoicesendname', 'sendname', 'basiclti'); +// $mform->addHelpButton('instructorchoicesendname', 'sendname', 'blti'); - $mform->addElement('select', 'instructorchoicesendemailaddr', get_string('sendemailaddr', 'basiclti'), $privacyoptions); + $mform->addElement('select', 'instructorchoicesendemailaddr', get_string('sendemailaddr', 'blti'), $privacyoptions); if (isset($this->typeconfig['instructorchoicesendemailaddr'])) { if ($this->typeconfig['instructorchoicesendemailaddr'] == 0) { @@ -122,17 +122,17 @@ class mod_basiclti_mod_form extends moodleform_mod { $mform->setDefault('instructorchoicesendemailaddr', '1'); } } - // $mform->addHelpButton('instructorchoicesendemailaddr', 'sendemailaddr', 'basiclti'); + // $mform->addHelpButton('instructorchoicesendemailaddr', 'sendemailaddr', 'blti'); //------------------------------------------------------------------------------- // Add grading preferences fieldset where the instructor determines whether to accept grades - $mform->addElement('header', 'extensions', get_string('extensions', 'basiclti')); + $mform->addElement('header', 'extensions', get_string('extensions', 'blti')); $extensionoptions=array(); - $extensionoptions[0] = get_string('donotaccept', 'basiclti'); - $extensionoptions[1] = get_string('accept', 'basiclti'); + $extensionoptions[0] = get_string('donotaccept', 'blti'); + $extensionoptions[1] = get_string('accept', 'blti'); - $mform->addElement('select', 'instructorchoiceacceptgrades', get_string('acceptgrades', 'basiclti'), $extensionoptions); + $mform->addElement('select', 'instructorchoiceacceptgrades', get_string('acceptgrades', 'blti'), $extensionoptions); if (isset($this->typeconfig['instructorchoiceacceptgrades'])) { if ($this->typeconfig['instructorchoiceacceptgrades'] == 0) { $mform->setDefault('instructorchoiceacceptgrades', '0'); @@ -140,13 +140,13 @@ class mod_basiclti_mod_form extends moodleform_mod { $mform->setDefault('instructorchoiceacceptgrades', '1'); } } - // $mform->addHelpButton('instructorchoiceacceptgrades', 'acceptgrades', 'basiclti'); + // $mform->addHelpButton('instructorchoiceacceptgrades', 'acceptgrades', 'blti'); $extensionoptions=array(); - $extensionoptions[0] = get_string('donotallow', 'basiclti'); - $extensionoptions[1] = get_string('allow', 'basiclti'); + $extensionoptions[0] = get_string('donotallow', 'blti'); + $extensionoptions[1] = get_string('allow', 'blti'); - $mform->addElement('select', 'instructorchoiceallowroster', get_string('allowroster', 'basiclti'), $extensionoptions); + $mform->addElement('select', 'instructorchoiceallowroster', get_string('allowroster', 'blti'), $extensionoptions); if (isset($this->typeconfig['instructorchoiceallowroster'])) { if ($this->typeconfig['instructorchoiceallowroster'] == 0) { $mform->setDefault('instructorchoiceallowroster', '0'); @@ -154,10 +154,10 @@ class mod_basiclti_mod_form extends moodleform_mod { $mform->setDefault('instructorchoiceallowroster', '1'); } } - // $mform->addHelpButton('instructorchoiceallowroster', 'allowroster', 'basiclti'); + // $mform->addHelpButton('instructorchoiceallowroster', 'allowroster', 'blti'); $mform->setAdvanced('instructorchoiceallowroster'); - $mform->addElement('select', 'instructorchoiceallowsetting', get_string('allowsetting', 'basiclti'), $extensionoptions); + $mform->addElement('select', 'instructorchoiceallowsetting', get_string('allowsetting', 'blti'), $extensionoptions); if (isset($this->typeconfig['instructorchoiceallowsetting'])) { if ($this->typeconfig['instructorchoiceallowsetting'] == 0) { @@ -166,14 +166,14 @@ class mod_basiclti_mod_form extends moodleform_mod { $mform->setDefault('instructorchoiceallowsetting', '1'); } } -// $mform->addHelpButton('instructorchoiceallowsetting', 'allowsetting', 'basiclti'); +// $mform->addHelpButton('instructorchoiceallowsetting', 'allowsetting', 'blti'); $mform->setAdvanced('instructorchoiceallowsetting'); //------------------------------------------------------------------------------- if (isset($this->typeconfig['allowinstructorcustom'])) { if ($this->typeconfig['allowinstructorcustom'] == 1) { // Add custom parameters fieldset - $mform->addElement('header', 'launchoptions', get_string('custominstr', 'basiclti')); + $mform->addElement('header', 'launchoptions', get_string('custominstr', 'blti')); $mform->addElement('textarea', 'instructorcustomparameters', '', array('rows'=>15, 'cols'=>60)); $mform->setType('instructorcustomparameters', PARAM_TEXT); @@ -183,19 +183,19 @@ class mod_basiclti_mod_form extends moodleform_mod { //------------------------------------------------------------------------------- // Add launch parameters fieldset - $mform->addElement('header', 'launchoptions', get_string('launchoptions', 'basiclti')); + $mform->addElement('header', 'launchoptions', get_string('launchoptions', 'blti')); // Size parameters - $mform->addElement('text', 'preferheight', get_string('preferheight', 'basiclti')); + $mform->addElement('text', 'preferheight', get_string('preferheight', 'blti')); if (isset($this->typeconfig['preferheight'])) { $mform->setDefault('preferheight', $this->typeconfig['preferheight']); } $launchoptions=array(); - $launchoptions[0] = get_string('launch_in_moodle', 'basiclti'); - $launchoptions[1] = get_string('launch_in_popup', 'basiclti'); + $launchoptions[0] = get_string('launch_in_moodle', 'blti'); + $launchoptions[1] = get_string('launch_in_popup', 'blti'); - $mform->addElement('select', 'launchinpopup', get_string('launchinpopup', 'basiclti'), $launchoptions); + $mform->addElement('select', 'launchinpopup', get_string('launchinpopup', 'blti'), $launchoptions); if (isset($this->typeconfig['launchinpopup'])) { if ($this->typeconfig['launchinpopup'] == 0) { @@ -206,10 +206,10 @@ class mod_basiclti_mod_form extends moodleform_mod { } $debugoptions=array(); - $debugoptions[0] = get_string('debuglaunchoff', 'basiclti'); - $debugoptions[1] = get_string('debuglaunchon', 'basiclti'); + $debugoptions[0] = get_string('debuglaunchoff', 'blti'); + $debugoptions[1] = get_string('debuglaunchon', 'blti'); - $mform->addElement('select', 'debuglaunch', get_string('debuglaunch', 'basiclti'), $debugoptions); + $mform->addElement('select', 'debuglaunch', get_string('debuglaunch', 'blti'), $debugoptions); if (isset($this->typeconfig['debuglaunch'])) { if ($this->typeconfig['debuglaunch'] == 0) { @@ -251,7 +251,7 @@ class mod_basiclti_mod_form extends moodleform_mod { //we don't want to have these appear as possible selections in the form but //we want the form to display them if they are set. if (!empty($typeidvalue)) { - $typeconfig = basiclti_get_type_config($typeidvalue); + $typeconfig = blti_get_type_config($typeidvalue); if ($typeconfig["sendname"] != 2) { $field =& $mform->getElement('instructorchoicesendname'); @@ -299,40 +299,40 @@ class mod_basiclti_mod_form extends moodleform_mod { if (!isset($default_values['toolurl'])) { if (isset($this->typeconfig['toolurl'])) { $default_values['toolurl'] = $this->typeconfig['toolurl']; - } else if (isset($CFG->basiclti_toolurl)) { - $default_values['toolurl'] = $CFG->basiclti_toolurl; + } else if (isset($CFG->blti_toolurl)) { + $default_values['toolurl'] = $CFG->blti_toolurl; } } if (!isset($default_values['resourcekey'])) { if (isset($this->typeconfig['resourcekey'])) { $default_values['resourcekey'] = $this->typeconfig['resourcekey']; - } else if (isset($CFG->basiclti_resourcekey)) { - $default_values['resourcekey'] = $CFG->basiclti_resourcekey; + } else if (isset($CFG->blti_resourcekey)) { + $default_values['resourcekey'] = $CFG->blti_resourcekey; } } if (!isset($default_values['password'])) { if (isset($this->typeconfig['password'])) { $default_values['password'] = $this->typeconfig['password']; - } else if (isset($CFG->basiclti_password)) { - $default_values['password'] = $CFG->basiclti_password; + } else if (isset($CFG->blti_password)) { + $default_values['password'] = $CFG->blti_password; } } if (!isset($default_values['preferheight'])) { if (isset($this->typeconfig['preferheight'])) { $default_values['preferheight'] = $this->typeconfig['preferheight']; - } else if (isset($CFG->basiclti_preferheight)) { - $default_values['preferheight'] = $CFG->basiclti_preferheight; + } else if (isset($CFG->blti_preferheight)) { + $default_values['preferheight'] = $CFG->blti_preferheight; } } if (!isset($default_values['sendname'])) { if (isset($this->typeconfig['sendname'])) { $default_values['sendname'] = $this->typeconfig['sendname']; - } else if (isset($CFG->basiclti_sendname)) { - $default_values['sendname'] = $CFG->basiclti_sendname; + } else if (isset($CFG->blti_sendname)) { + $default_values['sendname'] = $CFG->blti_sendname; } } @@ -341,7 +341,7 @@ class mod_basiclti_mod_form extends moodleform_mod { $default_values['instructorchoicesendname'] = $this->typeconfig['instructorchoicesendname']; } else { if ($this->typeconfig['sendname'] == 2) { - $default_values['instructorchoicesendname'] = $CFG->basiclti_instructorchoicesendname; + $default_values['instructorchoicesendname'] = $CFG->blti_instructorchoicesendname; } else { $default_values['instructorchoicesendname'] = $this->typeconfig['sendname']; } @@ -351,8 +351,8 @@ class mod_basiclti_mod_form extends moodleform_mod { if (!isset($default_values['sendemailaddr'])) { if (isset($this->typeconfig['sendemailaddr'])) { $default_values['sendemailaddr'] = $this->typeconfig['sendemailaddr']; - } else if (isset($CFG->basiclti_sendemailaddr)) { - $default_values['sendemailaddr'] = $CFG->basiclti_sendemailaddr; + } else if (isset($CFG->blti_sendemailaddr)) { + $default_values['sendemailaddr'] = $CFG->blti_sendemailaddr; } } @@ -361,7 +361,7 @@ class mod_basiclti_mod_form extends moodleform_mod { $default_values['instructorchoicesendemailaddr'] = $this->typeconfig['instructorchoicesendemailaddr']; } else { if ($this->typeconfig['sendemailaddr'] == 2) { - $default_values['instructorchoicesendemailaddr'] = $CFG->basiclti_instructorchoicesendemailaddr; + $default_values['instructorchoicesendemailaddr'] = $CFG->blti_instructorchoicesendemailaddr; } else { $default_values['instructorchoicesendemailaddr'] = $this->typeconfig['sendemailaddr']; } @@ -371,8 +371,8 @@ class mod_basiclti_mod_form extends moodleform_mod { if (!isset($default_values['acceptgrades'])) { if (isset($this->typeconfig['acceptgrades'])) { $default_values['acceptgrades'] = $this->typeconfig['acceptgrades']; - } else if (isset($CFG->basiclti_acceptgrades)) { - $default_values['acceptgrades'] = $CFG->basiclti_acceptgrades; + } else if (isset($CFG->blti_acceptgrades)) { + $default_values['acceptgrades'] = $CFG->blti_acceptgrades; } } @@ -381,7 +381,7 @@ class mod_basiclti_mod_form extends moodleform_mod { $default_values['instructorchoiceacceptgrades'] = $this->typeconfig['instructorchoiceacceptgrades']; } else { if ($this->typeconfig['acceptgrades'] == 2) { - $default_values['instructorchoiceacceptgrades'] = $CFG->basiclti_instructorchoiceacceptgrades; + $default_values['instructorchoiceacceptgrades'] = $CFG->blti_instructorchoiceacceptgrades; } else { $default_values['instructorchoiceacceptgrades'] = $this->typeconfig['acceptgrades']; } @@ -391,8 +391,8 @@ class mod_basiclti_mod_form extends moodleform_mod { if (!isset($default_values['allowroster'])) { if (isset($this->typeconfig['allowroster'])) { $default_values['allowroster'] = $this->typeconfig['allowroster']; - } else if (isset($CFG->basiclti_allowroster)) { - $default_values['allowroster'] = $CFG->basiclti_allowroster; + } else if (isset($CFG->blti_allowroster)) { + $default_values['allowroster'] = $CFG->blti_allowroster; } } @@ -401,7 +401,7 @@ class mod_basiclti_mod_form extends moodleform_mod { $default_values['instructorchoiceallowroster'] = $this->typeconfig['instructorchoiceallowroster']; } else { if ($this->typeconfig['allowroster'] == 2) { - $default_values['instructorchoiceallowroster'] = $CFG->basiclti_instructorchoiceallowroster; + $default_values['instructorchoiceallowroster'] = $CFG->blti_instructorchoiceallowroster; } else { $default_values['instructorchoiceallowroster'] = $this->typeconfig['allowroster']; } @@ -411,8 +411,8 @@ class mod_basiclti_mod_form extends moodleform_mod { if (!isset($default_values['allowsetting'])) { if (isset($this->typeconfig['allowsetting'])) { $default_values['allowsetting'] = $this->typeconfig['allowsetting']; - } else if (isset($CFG->basiclti_allowsetting)) { - $default_values['allowsetting'] = $CFG->basiclti_allowsetting; + } else if (isset($CFG->blti_allowsetting)) { + $default_values['allowsetting'] = $CFG->blti_allowsetting; } } @@ -421,7 +421,7 @@ class mod_basiclti_mod_form extends moodleform_mod { $default_values['instructorchoiceallowsetting'] = $this->typeconfig['instructorchoiceallowsetting']; } else { if ($this->typeconfig['allowsetting'] == 2) { - $default_values['instructorchoiceallowsetting'] = $CFG->basiclti_instructorchoiceallowsetting; + $default_values['instructorchoiceallowsetting'] = $CFG->blti_instructorchoiceallowsetting; } else { $default_values['instructorchoiceallowsetting'] = $this->typeconfig['allowsetting']; } @@ -431,48 +431,48 @@ class mod_basiclti_mod_form extends moodleform_mod { if (!isset($default_values['customparameters'])) { if (isset($this->typeconfig['customparameters'])) { $default_values['customparameters'] = $this->typeconfig['customparameters']; - } else if (isset($CFG->basiclti_customparameters)) { - $default_values['customparameters'] = $CFG->basiclti_customparameters; + } else if (isset($CFG->blti_customparameters)) { + $default_values['customparameters'] = $CFG->blti_customparameters; } } if (!isset($default_values['allowinstructorcustom'])) { if (isset($this->typeconfig['allowinstructorcustom'])) { $default_values['allowinstructorcustom'] = $this->typeconfig['allowinstructorcustom']; - } else if (isset($CFG->basiclti_allowinstructorcustom)) { - $default_values['allowinstructorcustom'] = $CFG->basiclti_allowinstructorcustom; + } else if (isset($CFG->blti_allowinstructorcustom)) { + $default_values['allowinstructorcustom'] = $CFG->blti_allowinstructorcustom; } } if (!isset($default_values['organizationid'])) { if (isset($this->typeconfig['organizationid'])) { $default_values['organizationid'] = $this->typeconfig['organizationid']; - } else if (isset($CFG->basiclti_organizationid)) { - $default_values['organizationid'] = $CFG->basiclti_organizationid; + } else if (isset($CFG->blti_organizationid)) { + $default_values['organizationid'] = $CFG->blti_organizationid; } } if (!isset($default_values['organizationurl'])) { if (isset($this->typeconfig['organizationurl'])) { $default_values['organizationurl'] = $this->typeconfig['organizationurl']; - } else if (isset($CFG->basiclti_organizationurl)) { - $default_values['organizationurl'] = $CFG->basiclti_organizationurl; + } else if (isset($CFG->blti_organizationurl)) { + $default_values['organizationurl'] = $CFG->blti_organizationurl; } } if (!isset($default_values['organizationdescr'])) { if (isset($this->typeconfig['organizationdescr'])) { $default_values['organizationdescr'] = $this->typeconfig['organizationdescr']; - } else if (isset($CFG->basiclti_organizationdescr)) { - $default_values['organizationdescr'] = $CFG->basiclti_organizationdescr; + } else if (isset($CFG->blti_organizationdescr)) { + $default_values['organizationdescr'] = $CFG->blti_organizationdescr; } } if (!isset($default_values['launchinpopup'])) { if (isset($this->typeconfig['launchinpopup'])) { $default_values['launchinpopup'] = $this->typeconfig['launchinpopup']; - } else if (isset($CFG->basiclti_launchinpopup)) { - $default_values['launchinpopup'] = $CFG->basiclti_launchinpopup; + } else if (isset($CFG->blti_launchinpopup)) { + $default_values['launchinpopup'] = $CFG->blti_launchinpopup; } } diff --git a/mod/basiclti/pix/icon.gif b/mod/blti/pix/icon.gif similarity index 100% rename from mod/basiclti/pix/icon.gif rename to mod/blti/pix/icon.gif diff --git a/mod/basiclti/service.php b/mod/blti/service.php similarity index 91% rename from mod/basiclti/service.php rename to mod/blti/service.php index 34ac795f218..7b51d16d8d9 100644 --- a/mod/basiclti/service.php +++ b/mod/blti/service.php @@ -34,7 +34,7 @@ * This file contains all necessary code to support basiclti services * like outcomes and roster access. * - * @package basiclti + * @package blti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -48,16 +48,16 @@ */ require_once("../../config.php"); -require_once($CFG->dirroot.'/mod/basiclti/lib.php'); -require_once($CFG->dirroot.'/mod/basiclti/locallib.php'); -require_once($CFG->dirroot.'/mod/basiclti/OAuth.php'); -require_once($CFG->dirroot.'/mod/basiclti/TrivialStore.php'); +require_once($CFG->dirroot.'/mod/blti/lib.php'); +require_once($CFG->dirroot.'/mod/blti/locallib.php'); +require_once($CFG->dirroot.'/mod/blti/OAuth.php'); +require_once($CFG->dirroot.'/mod/blti/TrivialStore.php'); error_reporting(E_ALL & ~E_NOTICE); ini_set("display_errors", 1); $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); -$PAGE->set_url('/mod/basiclti/service.php'); +$PAGE->set_url('/mod/blti/service.php'); $PAGE->set_pagetype('admin-setting-' . $section); $PAGE->set_pagelayout('admin'); $PAGE->navigation->clear_cache(); @@ -145,13 +145,13 @@ if (isset($signature) && isset($userid) && isset($placement)) { } // Retrieve the Basic LTI placement -if (! $basiclti = $DB->get_record('basiclti', array('id'=>$placement))) { +if (! $basiclti = $DB->get_record('blti', array('id'=>$placement))) { do_error("Bad sourcedid (4)"); } $basiclti_types_config = (object)$basiclti_types_config; -$typeconfig = basiclti_get_type_config($basiclti->typeid); +$typeconfig = blti_get_type_config($basiclti->typeid); if (isset($typeconfig) && isset($typeconfig['password'])) { // OK @@ -234,7 +234,7 @@ if (! $course = $DB->get_record('course', array('id'=>$basiclti->course))) { // TODO: Check that user is in course -if (! $cm = get_coursemodule_from_instance("basiclti", $basiclti->id, $course->id)) { +if (! $cm = get_coursemodule_from_instance("blti", $basiclti->id, $course->id)) { do_error("Course Module ID was incorrect"); } @@ -243,10 +243,10 @@ require_once($CFG->libdir.'/gradelib.php'); // Beginning of actual grade processing if ($message_type == "basicoutcome") { - $source = 'mod/basiclti'; + $source = 'mod/blti'; $courseid = $course->id; $itemtype = 'mod'; - $itemmodule = 'basiclti'; + $itemmodule = 'blti'; $iteminstance = $basiclti->id; if ($lti_message_type == "basic-lis-readresult") { @@ -314,18 +314,18 @@ if ($message_type == "basicoutcome") { if (! isset($setting)) { do_error('Missing setting value'); } - $record = $DB->get_record('basiclti', array('id'=>$basiclti->id)); + $record = $DB->get_record('blti', array('id'=>$basiclti->id)); $record->setting = $setting; - $success = $DB->update_record('basiclti', $record); + $success = $DB->update_record('blti', $record); if ($success) { print message_response('Success', 'Status', 'fullsuccess', 'Setting updated'); } else { do_error("Error updating error"); } } else if ($lti_message_type == "basic-lti-deletesetting") { - $record = $DB->get_record('basiclti', array('id'=>$basiclti->id)); + $record = $DB->get_record('blti', array('id'=>$basiclti->id)); $record->setting = ''; - $success = $DB->update_record('basiclti', $record); + $success = $DB->update_record('blti', $record); if ($success) { print message_response('Success', 'Status', 'fullsuccess', 'Setting deleted'); } else { diff --git a/mod/basiclti/settings.php b/mod/blti/settings.php similarity index 75% rename from mod/basiclti/settings.php rename to mod/blti/settings.php index 65976f8d755..c730ce1f96b 100644 --- a/mod/basiclti/settings.php +++ b/mod/blti/settings.php @@ -33,7 +33,7 @@ /** * This file defines the global basiclti administration form * - * @package basiclti + * @package blti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -48,21 +48,21 @@ defined('MOODLE_INTERNAL') || die; if ($ADMIN->fulltree) { - require_once($CFG->dirroot.'/mod/basiclti/locallib.php'); + require_once($CFG->dirroot.'/mod/blti/locallib.php'); $str = ''; - $types = basiclti_filter_get_types(); + $types = blti_filter_get_types(); if (!empty($types)) { - $str .= '

'.get_string('addtype', 'basiclti').'

'; + $str .= '

'.get_string('addtype', 'blti').'

'; $str .= '
'; foreach ($types as $type) { $str .= ''. ''. - ''. @@ -72,15 +72,15 @@ if ($ADMIN->fulltree) { $str .= '
'.$type->name.''. + ''. 'Update'.'  '. - ''. + ''. 'Delete'. ''. '
'; } else { $str .= '
'; - $str .= '

'.get_string('addtype', 'basiclti').'

'; - $str .= get_string('notypes', 'basiclti'); + $str .= '

'.get_string('addtype', 'blti').'

'; + $str .= get_string('notypes', 'blti'); $str .= '
'; } - $settings->add(new admin_setting_heading('basiclti_types', get_string('configuredtools', 'basiclti'), $str)); + $settings->add(new admin_setting_heading('blti_types', get_string('configuredtools', 'blti'), $str)); - $unconfigured = basiclti_get_unconfigured_tools(); + $unconfigured = blti_get_unconfigured_tools(); if (!empty($unconfigured)) { $newstr = ''; $newstr .= ''; @@ -89,12 +89,12 @@ if ($ADMIN->fulltree) { $coursename = $DB->get_field('course', 'shortname', array('id' => $unconf->course)); $newstr .= ''. ''. - ''. ''; } $newstr .= '
Course Tool Name
'.$coursename.''.$unconf->name.''. + ''. 'Update'.'  '.'
'; - $settings->add(new admin_setting_heading('basiclti_mis_types', get_string('misconfiguredtools', 'basiclti'), $newstr)); + $settings->add(new admin_setting_heading('blti_mis_types', get_string('misconfiguredtools', 'blti'), $newstr)); } } diff --git a/mod/basiclti/simpletest/testlocallib.php b/mod/blti/simpletest/testlocallib.php similarity index 95% rename from mod/basiclti/simpletest/testlocallib.php rename to mod/blti/simpletest/testlocallib.php index 464ebd89011..a7756c8ecc2 100644 --- a/mod/basiclti/simpletest/testlocallib.php +++ b/mod/blti/simpletest/testlocallib.php @@ -33,7 +33,7 @@ /** * This file contains unit tests for (some of) mod/basiclti/locallib.php * - * @package basiclti + * @package blti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -50,10 +50,10 @@ if (!defined('MOODLE_INTERNAL')) { die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page. } -require_once($CFG->dirroot . '/mod/basiclti/locallib.php'); +require_once($CFG->dirroot . '/mod/blti/locallib.php'); -class basiclti_locallib_test extends UnitTestCase { - public static $includecoverage = array('mod/basiclti/locallib.php'); +class blti_locallib_test extends UnitTestCase { + public static $includecoverage = array('mod/blti/locallib.php'); function test_split_custom_parameters() { $this->assertEqual(split_custom_parameters("x=1\ny=2"), array('custom_x' => '1', 'custom_y'=> '2')); diff --git a/mod/blti/styles.css b/mod/blti/styles.css new file mode 100644 index 00000000000..0be6d5f9bf9 --- /dev/null +++ b/mod/blti/styles.css @@ -0,0 +1,29 @@ +.path-mod-blti .bltiframe {position: relative;width: 100%;height: 100%;} + +/** General Styles **/ +.path-mod-blti .userpicture, +.path-mod-blti .picture.user, +.path-mod-blti .picture.teacher {width:35px;height: 35px;vertical-align:top;} +.path-mod-blti .feedback .files, +.path-mod-blti .feedback .grade, +.path-mod-blti .feedback .outcome, +.path-mod-blti .feedback .finalgrade {float: right;} +.path-mod-blti .feedback .disabledfeedback {width: 500px;height: 250px;} +.path-mod-blti .feedback .from {float: left;} +.path-mod-blti .files img {margin-right: 4px;} +.path-mod-blti .files a {white-space:nowrap;} +.path-mod-blti .late {color: red;} +.path-mod-blti .message {text-align: center;} + +/** Styles for submissions.php **/ +#page-mod-blti-submissions fieldset.felement {margin-left: 16%;} +#page-mod-blti-submissions form#options div {text-align:right;margin-left:auto;margin-right:20px;} +#page-mod-blti-submissions .header .commands {display: inline;} +#page-mod-blti-submissions .picture {width: 35px;} +#page-mod-blti-submissions .fullname, +#page-mod-blti-submissions .timemodified, +#page-mod-blti-submissions .timemarked {text-align: left;} +#page-mod-blti-submissions .submissions .grade, +#page-mod-blti-submissions .submissions .outcome, +#page-mod-blti-submissions .submissions .finalgrade {text-align: right;} +#page-mod-blti-submissions .qgprefs #optiontable {text-align:right;margin-left:auto;} diff --git a/mod/basiclti/submissions.php b/mod/blti/submissions.php similarity index 80% rename from mod/basiclti/submissions.php rename to mod/blti/submissions.php index 11aa5ecf42a..0de13f7aec2 100644 --- a/mod/basiclti/submissions.php +++ b/mod/blti/submissions.php @@ -34,7 +34,7 @@ /** * This file contains submissions-specific code for the basiclti module * - * @package basiclti + * @package blti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -46,7 +46,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once("../../config.php"); -require_once($CFG->dirroot.'/mod/basiclti/lib.php'); +require_once($CFG->dirroot.'/mod/blti/lib.php'); require_once($CFG->libdir.'/plagiarismlib.php'); $id = optional_param('id', 0, PARAM_INT); // Course module ID @@ -54,28 +54,28 @@ $a = optional_param('a', 0, PARAM_INT); // Assignment ID $mode = optional_param('mode', 'all', PARAM_ALPHA); // What mode are we in? $download = optional_param('download' , 'none', PARAM_ALPHA); //ZIP download asked for? -$url = new moodle_url('/mod/basiclti/submissions.php'); +$url = new moodle_url('/mod/blti/submissions.php'); if ($id) { - if (! $cm = get_coursemodule_from_id('basiclti', $id)) { + if (! $cm = get_coursemodule_from_id('blti', $id)) { print_error('invalidcoursemodule'); } - if (! $basiclti = $DB->get_record("basiclti", array("id"=>$cm->instance))) { - print_error('invalidid', 'basiclti'); + if (! $basiclti = $DB->get_record("blti", array("id"=>$cm->instance))) { + print_error('invalidid', 'blti'); } if (! $course = $DB->get_record("course", array("id"=>$basiclti->course))) { - print_error('coursemisconf', 'basiclti'); + print_error('coursemisconf', 'blti'); } $url->param('id', $id); } else { - if (!$basiclti = $DB->get_record("basiclti", array("id"=>$a))) { + if (!$basiclti = $DB->get_record("blti", array("id"=>$a))) { print_error('invalidcoursemodule'); } if (! $course = $DB->get_record("course", array("id"=>$basiclti->course))) { - print_error('coursemisconf', 'basiclti'); + print_error('coursemisconf', 'blti'); } - if (! $cm = get_coursemodule_from_instance("basiclti", $basiclti->id, $course->id)) { + if (! $cm = get_coursemodule_from_instance("blti", $basiclti->id, $course->id)) { print_error('invalidcoursemodule'); } $url->param('a', $a); @@ -87,6 +87,6 @@ if ($mode !== 'all') { $PAGE->set_url($url); require_login($course, false, $cm); -require_capability('mod/basiclti:grade', get_context_instance(CONTEXT_MODULE, $cm->id)); +require_capability('mod/blti:grade', get_context_instance(CONTEXT_MODULE, $cm->id)); -basiclti_submissions($cm, $course, $basiclti, $mode); // Display or process the submissions +blti_submissions($cm, $course, $basiclti, $mode); // Display or process the submissions diff --git a/mod/basiclti/typessettings.php b/mod/blti/typessettings.php similarity index 83% rename from mod/basiclti/typessettings.php rename to mod/blti/typessettings.php index 8b8be8edbcd..0ef7c4ad352 100644 --- a/mod/basiclti/typessettings.php +++ b/mod/blti/typessettings.php @@ -35,7 +35,7 @@ * It is used to create a new form used to pre-configure basiclti * activities * - * @package basiclti + * @package blti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -49,10 +49,10 @@ require_once('../../config.php'); require_once($CFG->libdir.'/adminlib.php'); -require_once($CFG->dirroot.'/mod/basiclti/edit_form.php'); -require_once($CFG->dirroot.'/mod/basiclti/locallib.php'); +require_once($CFG->dirroot.'/mod/blti/edit_form.php'); +require_once($CFG->dirroot.'/mod/blti/locallib.php'); -$section = 'modsettingbasiclti'; +$section = 'modsettingblti'; $return = optional_param('return', '', PARAM_ALPHA); $adminediting = optional_param('adminedit', -1, PARAM_BOOL); $action = optional_param('action', null, PARAM_TEXT); @@ -62,7 +62,7 @@ $definenew = optional_param('definenew', null, PARAM_INT); /// no guest autologin require_login(0, false); -$url = new moodle_url('/mod/basiclti/typesettings.php'); +$url = new moodle_url('/mod/blti/typesettings.php'); $PAGE->set_url($url); admin_externalpage_setup('managemodules'); // Hacky solution for printing the admin page @@ -79,7 +79,7 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton $type->id = $id; $type->name = $data->lti_typename; $type->rawname = preg_replace('/[^a-zA-Z]/', '', $type->name); - if ($DB->update_record('basiclti_types', $type)) { + if ($DB->update_record('blti_types', $type)) { unset ($data->lti_typename); //@TODO: update work foreach ($data as $key => $value) { @@ -88,7 +88,7 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton $record->typeid = $id; $record->name = substr($key, 4); $record->value = $value; - if (basiclti_update_config($record)) { + if (blti_update_config($record)) { $statusmsg = get_string('changessaved'); } else { $errormsg = get_string('errorwithsettings', 'admin'); @@ -98,25 +98,25 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton // Update toolurl for all existing instances - it is the only common parameter // between configurations and instances - $instances = $DB->get_records('basiclti', array('typeid' => $id)); + $instances = $DB->get_records('blti', array('typeid' => $id)); foreach ($instances as $instance) { if ($instance->toolurl != $data->lti_toolurl) { $instance->toolurl = $data->lti_toolurl; - $DB->update_record('basiclti', $instance); + $DB->update_record('blti', $instance); } } } - redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingbasiclti"); + redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingblti"); die; } else { $type = new StdClass(); $type->name = $data->lti_typename; $type->rawname = preg_replace('/[^a-zA-Z]/', '', $type->name); - if ($id = $DB->insert_record('basiclti_types', $type)) { + if ($id = $DB->insert_record('blti_types', $type)) { if (!empty($data->lti_fix)) { - $instance = $DB->get_record('basiclti', array('id' => $data->lti_fix)); + $instance = $DB->get_record('blti', array('id' => $data->lti_fix)); $instance->typeid = $id; - $DB->update_record('basiclti', $instance); + $DB->update_record('blti', $instance); } unset ($data->lti_fix); @@ -127,7 +127,7 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton $record->typeid = $id; $record->name = substr($key, 4); $record->value = $value; - if (basiclti_add_config($record)) { + if (blti_add_config($record)) { $statusmsg = get_string('changessaved'); } else { $errormsg = get_string('errorwithsettings', 'admin'); @@ -137,7 +137,7 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton } else { $errormsg = get_string('errorwithsettings', 'admin'); } - redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingbasiclti"); + redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingblti"); die; } if (empty($adminroot->errors)) { @@ -155,16 +155,16 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton } if ($action == 'delete') { - basiclti_delete_type($id); - redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingbasiclti"); + blti_delete_type($id); + redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingblti"); die; } if (($action == 'fix') && isset($useexisting)) { - $instance = $DB->get_record('basiclti', array('id' => $id)); + $instance = $DB->get_record('blti', array('id' => $id)); $instance->typeid = $useexisting; - $DB->update_record('basiclti', $instance); - redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingbasiclti"); + $DB->update_record('blti', $instance); + redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingblti"); die; } @@ -174,7 +174,7 @@ if (empty($SITE->fullname)) { $PAGE->set_title($settingspage->visiblename); $PAGE->set_heading($settingspage->visiblename); - $PAGE->navbar->add('Basic LTI Administration', $CFG->wwwroot.'/admin/settings.php?section=modsettingbasiclti'); + $PAGE->navbar->add('Basic LTI Administration', $CFG->wwwroot.'/admin/settings.php?section=modsettingblti'); echo $OUTPUT->header(); @@ -215,9 +215,9 @@ if (empty($SITE->fullname)) { $buttons = $OUTPUT->single_button($url, $caption, 'get'); } - $PAGE->set_title("$SITE->shortname: " . get_string('toolsetup', 'basiclti')); + $PAGE->set_title("$SITE->shortname: " . get_string('toolsetup', 'blti')); - $PAGE->navbar->add('Basic LTI Administration', $CFG->wwwroot.'/admin/settings.php?section=modsettingbasiclti'); + $PAGE->navbar->add('Basic LTI Administration', $CFG->wwwroot.'/admin/settings.php?section=modsettingblti'); echo $OUTPUT->header(); @@ -231,22 +231,22 @@ if (empty($SITE->fullname)) { } // --------------------------------------------------------------------------------------------------------------- - echo $OUTPUT->heading(get_string('toolsetup', 'basiclti')); + echo $OUTPUT->heading(get_string('toolsetup', 'blti')); echo $OUTPUT->box_start('generalbox'); if ($action == 'add') { - $form = new mod_basiclti_edit_types_form(); + $form = new mod_blti_edit_types_form(); $form->display(); } else if ($action == 'update') { - $form = new mod_basiclti_edit_types_form('typessettings.php?id='.$id); - $type = basiclti_get_type_type_config($id); + $form = new mod_blti_edit_types_form('typessettings.php?id='.$id); + $type = blti_get_type_type_config($id); $form->set_data($type); $form->display(); } else if ($action == 'fix') { if (!isset($definenew) && !isset($useexisting)) { - basiclti_fix_misconfigured_choice($id); + blti_fix_misconfigured_choice($id); } else if (isset($definenew)) { - $form = new mod_basiclti_edit_types_form(); - $type = basiclti_get_type_config_from_instance($id); + $form = new mod_blti_edit_types_form(); + $type = blti_get_type_config_from_instance($id); $form->set_data($type); $form->display(); } diff --git a/mod/basiclti/version.php b/mod/blti/version.php similarity index 97% rename from mod/basiclti/version.php rename to mod/blti/version.php index 3b68fb8d645..8fd6b4546ce 100644 --- a/mod/basiclti/version.php +++ b/mod/blti/version.php @@ -34,7 +34,7 @@ * This file defines the version of basiclti * This fragment is called by moodle_needs_upgrading() and /admin/index.php * - * @package basiclti + * @package blti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu diff --git a/mod/basiclti/view.php b/mod/blti/view.php similarity index 83% rename from mod/basiclti/view.php rename to mod/blti/view.php index b8b5778cd24..0484070b4b9 100644 --- a/mod/basiclti/view.php +++ b/mod/blti/view.php @@ -33,7 +33,7 @@ /** * This file contains all necessary code to view a basiclti activity instance * - * @package basiclti + * @package blti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -46,14 +46,14 @@ */ require_once('../../config.php'); -require_once($CFG->dirroot.'/mod/basiclti/lib.php'); -require_once($CFG->dirroot.'/mod/basiclti/locallib.php'); +require_once($CFG->dirroot.'/mod/blti/lib.php'); +require_once($CFG->dirroot.'/mod/blti/locallib.php'); $id = optional_param('id', 0, PARAM_INT); // Course Module ID, or -$a = optional_param('a', 0, PARAM_INT); // basiclti ID +$a = optional_param('a', 0, PARAM_INT); // blti ID if ($id) { - if (! $cm = get_coursemodule_from_id("basiclti", $id)) { + if (! $cm = get_coursemodule_from_id("blti", $id)) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect'); } @@ -61,18 +61,18 @@ if ($id) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured'); } - if (! $basiclti = $DB->get_record("basiclti", array("id" => $cm->instance))) { + if (! $basiclti = $DB->get_record("blti", array("id" => $cm->instance))) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect'); } } else { - if (! $basiclti = $DB->get_record("basiclti", array("id" => $a))) { + if (! $basiclti = $DB->get_record("blti", array("id" => $a))) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect'); } if (! $course = $DB->get_record("course", array("id" => $basiclti->course))) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured'); } - if (! $cm = get_coursemodule_from_instance("basiclti", $basiclti->id, $course->id)) { + if (! $cm = get_coursemodule_from_instance("blti", $basiclti->id, $course->id)) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect'); } } @@ -81,12 +81,12 @@ $PAGE->set_cm($cm, $course); // set's up global $COURSE $context = get_context_instance(CONTEXT_MODULE, $cm->id); $PAGE->set_context($context); -$url = new moodle_url('/mod/basiclti/view.php', array('id'=>$cm->id)); +$url = new moodle_url('/mod/blti/view.php', array('id'=>$cm->id)); $PAGE->set_url($url); $PAGE->set_pagelayout('incourse'); require_login($course); -add_to_log($course->id, "basiclti", "view", "view.php?id=$cm->id", "$basiclti->id"); +add_to_log($course->id, "blti", "view", "view.php?id=$cm->id", "$basiclti->id"); $pagetitle = strip_tags($course->shortname.': '.format_string($basiclti->name)); $PAGE->set_title($pagetitle); @@ -100,7 +100,7 @@ echo $OUTPUT->heading(format_string($basiclti->name)); echo $OUTPUT->box($basiclti->intro, 'generalbox description', 'intro'); if ($basiclti->typeid == 0) { - print_error('errormisconfig', 'basiclti'); + print_error('errormisconfig', 'blti'); } if ($basiclti->instructorchoiceacceptgrades == 1) { @@ -115,7 +115,7 @@ if ( $basiclti->launchinpopup > 0 ) { print "window.open('launch.php?id=".$cm->id."','window name');"; print "//]]\n"; print "\n"; - print "

".get_string("basiclti_in_new_window", "basiclti")."

\n"; + print "

".get_string("basiclti_in_new_window", "blti")."

\n"; } else { // Request the launch content with an object tag $height = $basiclti->preferheight; From 285f82504645c67dc21dcdecc57c380698e5fbe9 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Fri, 26 Aug 2011 17:06:32 -0400 Subject: [PATCH 03/78] Adjusting layout of editor pages & starting changes of blti properties --- mod/blti/db/install.xml | 61 +++++++------- mod/blti/edit_form.php | 109 +++++++------------------ mod/blti/lang/en/blti.php | 40 +++++++--- mod/blti/lib.php | 59 ++++++-------- mod/blti/locallib.php | 13 +++ mod/blti/mod_form.php | 157 ++++++++++++------------------------- mod/blti/styles.css | 3 + mod/blti/typessettings.php | 27 +++---- 8 files changed, 191 insertions(+), 278 deletions(-) diff --git a/mod/blti/db/install.xml b/mod/blti/db/install.xml index c9d1023daf8..a0a84d83efa 100644 --- a/mod/blti/db/install.xml +++ b/mod/blti/db/install.xml @@ -1,5 +1,5 @@ - @@ -9,31 +9,23 @@ - - + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + @@ -42,17 +34,24 @@ - - - + + + + + + + + - + + +
@@ -62,9 +61,11 @@ - + + +
-
+ \ No newline at end of file diff --git a/mod/blti/edit_form.php b/mod/blti/edit_form.php index b13f2599145..55e07873612 100644 --- a/mod/blti/edit_form.php +++ b/mod/blti/edit_form.php @@ -57,8 +57,8 @@ class mod_blti_edit_types_form extends moodleform{ //------------------------------------------------------------------------------- // Add basiclti elements - $mform->addElement('header', 'setup', get_string('modstandardels', 'form')); - + $mform->addElement('header', 'setup', get_string('tool_settings', 'blti')); + $mform->addElement('text', 'lti_typename', get_string('typename', 'blti')); $mform->setType('lti_typename', PARAM_INT); // $mform->addHelpButton('lti_typename', 'typename','blti'); @@ -78,96 +78,66 @@ class mod_blti_edit_types_form extends moodleform{ $mform->addElement('passwordunmask', 'lti_password', get_string('password', 'blti')); $mform->setType('lti_password', PARAM_TEXT); -//------------------------------------------------------------------------------- - // Add size parameters - $mform->addElement('header', 'size', get_string('size', 'blti')); - - $mform->addElement('text', 'lti_preferheight', get_string('preferheight', 'blti')); - $mform->setType('lti_preferheight', PARAM_INT); -// $mform->addHelpButton('lti_preferheight', 'preferheight', 'blti'); - - -//------------------------------------------------------------------------------- + $mform->addElement('textarea', 'lti_customparameters', get_string('custom', 'blti'), array('rows'=>4, 'cols'=>60)); + $mform->setType('lti_customparameters', PARAM_TEXT); + + $mform->addElement('checkbox', 'lti_coursevisible', ' ', ' ' . get_string('show_in_course', 'blti')); + // Add privacy preferences fieldset where users choose whether to send their data $mform->addElement('header', 'privacy', get_string('privacy', 'blti')); $options=array(); $options[0] = get_string('never', 'blti'); $options[1] = get_string('always', 'blti'); - $options[2] = get_string('delegate', 'blti'); - - $defaults=array(); - $defaults[0] = get_string('donot', 'blti'); - $defaults[1] = get_string('send', 'blti'); + $options[2] = get_string('delegate_yes', 'blti'); + $options[3] = get_string('delegate_no', 'blti'); $mform->addElement('select', 'lti_sendname', get_string('sendname', 'blti'), $options); - $mform->setDefault('lti_sendname', '0'); + $mform->setDefault('lti_sendname', '2'); // $mform->addHelpButton('lti_sendname', 'sendname', 'blti'); - $mform->addElement('select', 'lti_instructorchoicesendname', get_string('setdefault', 'blti'), $defaults); - $mform->setDefault('lti_instructorchoicesendname', '0'); - $mform->disabledIf('lti_instructorchoicesendname', 'lti_sendname', 'neq', 2); - $mform->addElement('select', 'lti_sendemailaddr', get_string('sendemailaddr', 'blti'), $options); - $mform->setDefault('lti_sendemailaddr', '0'); + $mform->setDefault('lti_sendemailaddr', '2'); // $mform->addHelpButton('lti_sendemailaddr', 'sendemailaddr', 'blti'); - $mform->addElement('select', 'lti_instructorchoicesendemailaddr', get_string('setdefault', 'blti'), $defaults); - $mform->setDefault('lti_instructorchoicesendemailaddr', '0'); - $mform->disabledIf('lti_instructorchoicesendemailaddr', 'lti_sendemailaddr', 'neq', 2); - //------------------------------------------------------------------------------- // BLTI Extensions - $mform->addElement('header', 'extensions', get_string('extensions', 'blti')); - - $defaults_accept=array(); - $defaults_accept[0] = get_string('donotaccept', 'blti'); - $defaults_accept[1] = get_string('accept', 'blti'); - - $defaults_allow=array(); - $defaults_allow[0] = get_string('donotallow', 'blti'); - $defaults_allow[1] = get_string('allow', 'blti'); // Add grading preferences fieldset where the tool is allowed to return grades $mform->addElement('select', 'lti_acceptgrades', get_string('acceptgrades', 'blti'), $options); - $mform->setDefault('lti_acceptgrades', '0'); + $mform->setDefault('lti_acceptgrades', '2'); // $mform->addHelpButton('lti_acceptgrades', 'acceptgrades', 'blti'); - $mform->addElement('select', 'lti_instructorchoiceacceptgrades', get_string('setdefault', 'blti'), $defaults_accept); - $mform->setDefault('lti_instructorchoiceacceptgrades', '0'); - $mform->disabledIf('lti_instructorchoiceacceptgrades', 'lti_acceptgrades', 'neq', 2); - // Add grading preferences fieldset where the tool is allowed to retrieve rosters $mform->addElement('select', 'lti_allowroster', get_string('allowroster', 'blti'), $options); - $mform->setDefault('lti_allowroster', '0'); + $mform->setDefault('lti_allowroster', '2'); // $mform->addHelpButton('lti_allowroster', 'allowroster', 'blti'); - $mform->addElement('select', 'lti_instructorchoiceallowroster', get_string('setdefault', 'blti'), $defaults_allow); - $mform->setDefault('lti_instructorchoiceallowroster', '0'); - $mform->disabledIf('lti_instructorchoiceallowroster', 'lti_allowroster', 'neq', 2); - + /* // Add grading preferences fieldset where the tool is allowed to update settings $mform->addElement('select', 'lti_allowsetting', get_string('allowsetting', 'blti'), $options); $mform->setDefault('lti_allowsetting', '0'); // $mform->addHelpButton('lti_allowsetting', 'allowsetting', 'blti'); - - $mform->addElement('select', 'lti_instructorchoiceallowsetting', get_string('setdefault', 'blti'), $defaults_allow); - $mform->setDefault('lti_instructorchoiceallowsetting', '0'); - $mform->disabledIf('lti_instructorchoiceallowsetting', 'lti_allowsetting', 'neq', 2); + */ //------------------------------------------------------------------------------- - // Add custom parameters fieldset - $mform->addElement('header', 'custom', get_string('custom', 'blti')); + // Add launch parameters fieldset + $mform->addElement('header', 'launchoptions', get_string('launchoptions', 'blti')); - $mform->addElement('textarea', 'lti_customparameters', '', array('rows'=>15, 'cols'=>60)); - $mform->setType('lti_customparameters', PARAM_TEXT); + $launchoptions=array(); + $launchoptions[0] = get_string('embed', 'blti'); + $launchoptions[1] = get_string('embed_no_blocks', 'blti'); + $launchoptions[2] = get_string('popup_window', 'blti'); + $launchoptions[3] = get_string('new_window', 'blti'); - $mform->addElement('select', 'lti_allowinstructorcustom', get_string('allowinstructorcustom', 'blti'), $defaults_allow); - $mform->setDefault('lti_allowinstructorcustom', '0'); + $mform->addElement('select', 'lti_launchinpopup', get_string('launchinpopup', 'blti'), $launchoptions); + $mform->setDefault('lti_launchinpopup', '0'); +// $mform->addHelpButton('lti_launchinpopup', 'launchinpopup', 'blti'); + //------------------------------------------------------------------------------- // Add setup parameters fieldset - $mform->addElement('header', 'setupoptions', get_string('setupoptions', 'blti')); + $mform->addElement('header', 'setupoptions', get_string('miscellaneous', 'blti')); // Adding option to change id that is placed in context_id $idoptions = array(); @@ -176,18 +146,7 @@ class mod_blti_edit_types_form extends moodleform{ $mform->addElement('select', 'lti_moodle_course_field', get_string('moodle_course_field', 'blti'), $idoptions); $mform->setDefault('lti_moodle_course_field', '0'); - - // Added option to allow user to specify if this is a resource or activity type - $classoptions = array(); - $classoptions[0] = get_string('activity', 'blti'); - $classoptions[1] = get_string('resource', 'blti'); - - $mform->addElement('select', 'lti_module_class_type', get_string('module_class_type', 'blti'), $classoptions); - $mform->setDefault('lti_module_class_type', '0'); - -//------------------------------------------------------------------------------- - // Add organization parameters fieldset - $mform->addElement('header', 'organization', get_string('organization', 'blti')); + $mform->addElement('text', 'lti_organizationid', get_string('organizationid', 'blti')); $mform->setType('lti_organizationid', PARAM_TEXT); @@ -203,18 +162,6 @@ class mod_blti_edit_types_form extends moodleform{ $mform->addHelpButton('lti_organizationdescr', 'organizationdescr', 'blti'); */ -//------------------------------------------------------------------------------- - // Add launch parameters fieldset - $mform->addElement('header', 'launchoptions', get_string('launchoptions', 'blti')); - - $launchoptions=array(); - $launchoptions[0] = get_string('launch_in_moodle', 'blti'); - $launchoptions[1] = get_string('launch_in_popup', 'blti'); - - $mform->addElement('select', 'lti_launchinpopup', get_string('launchinpopup', 'blti'), $launchoptions); - $mform->setDefault('lti_launchinpopup', '0'); -// $mform->addHelpButton('lti_launchinpopup', 'launchinpopup', 'blti'); - //------------------------------------------------------------------------------- // Add a hidden element to signal a tool fixing operation after a problematic backup - restore process $mform->addElement('hidden', 'lti_fix'); diff --git a/mod/blti/lang/en/blti.php b/mod/blti/lang/en/blti.php index 62d95d44bbd..b13eeb7c591 100644 --- a/mod/blti/lang/en/blti.php +++ b/mod/blti/lang/en/blti.php @@ -53,7 +53,7 @@ $string['addserver'] = 'Add new trusted server'; $string['addtype'] = 'Create a new Basic LTI activity'; $string['allow'] = 'Allow'; $string['allowinstructorcustom'] = 'Allow instructors to add custom parameters'; -$string['allowroster'] = 'Allow tool access to course roster'; +$string['allowroster'] = 'Tool may access course roster'; $string['allowsetting'] = 'Allow tool to store 8K of settings in Moodle'; $string['always'] = 'Always'; $string['blti'] = 'Basic LTI'; @@ -109,13 +109,13 @@ $string['imsrolelearner'] = 'Learner'; $string['invalidid'] = 'basic LTI ID was incorrect'; $string['launch_in_moodle'] = 'Launch tool in moodle'; $string['launch_in_popup'] = 'Launch tool in a pop-up'; -$string['launchinpopup'] = 'Popup Option'; +$string['launchinpopup'] = 'Launch Container'; $string['launchoptions'] = 'Launch Options'; $string['lti_errormsg'] = 'The tool returned the following error message: \"$a\"'; $string['misconfiguredtools'] = 'Misconfigured tool instances were detected'; $string['missingparameterserror'] = 'The page is misconfigured: \"$a\"'; $string['module_class_type'] = 'Moodle module type'; -$string['modulename'] = 'Basic LTI'; +$string['modulename'] = 'External Tool'; $string['modulenameplural'] = 'basicltis'; $string['modulenamepluralformatted'] = 'Basic LTI Instances'; $string['moodle_course_field'] = 'Course identification field'; @@ -130,7 +130,7 @@ $string['organizationdescr'] ='Organization Description'; $string['organizationid'] ='Organization ID'; $string['organizationurl'] ='Organization URL'; $string['pagesize'] = 'Submissions shown per page'; -$string['password'] = 'Remote Tool Password'; +$string['password'] = 'Shared Secret'; $string['pluginadministration'] = 'Basic LTI administration'; $string['pluginname'] = 'BLTI'; $string['preferheight'] = 'Preferred Height'; @@ -142,12 +142,12 @@ $string['quickgrade'] = 'Allow quick grading'; $string['quickgrade_help'] = 'If enabled, multiple tools can be graded on one page. Add grades and comments then click the "Save all my feedback" button to save all changes for that page.'; $string['redirect'] = 'You will be redirected in few seconds. If you are not, press the button.'; $string['resource'] = 'Resource'; -$string['resourcekey'] = 'Resource Key'; +$string['resourcekey'] = 'Consumer Key'; $string['resourceurl'] = 'Resource URL'; $string['saveallfeedback'] = 'Save all my feedback'; $string['send'] = 'Send'; -$string['sendemailaddr'] = 'Send user email address to the external tool'; -$string['sendname'] = 'Send user name and surname to the external tool'; +$string['sendemailaddr'] = 'Share launcher\'s email with tool'; +$string['sendname'] = 'Share launcher\'s name with tool'; $string['setdefault'] = 'Set a default value for the professor if delegating'; $string['setupbox'] = 'Basic LTI Tool Setup Box'; $string['setupoptions'] = 'Setup Options'; @@ -155,9 +155,31 @@ $string['size'] = 'Size parameters'; $string['submission'] = 'Submission'; $string['toggle_debug_data'] = 'Toggle Debug Data'; $string['toolsetup'] = 'Basic LTI Tool Setup'; -$string['toolurl'] = 'Remote Tool URL'; -$string['typename'] = 'Remote Tool Name'; +$string['toolurl'] = 'Tool Base URL'; +$string['typename'] = 'Tool Name'; $string['types'] = 'Types'; $string['validurl'] = 'A valid URL must start with http(s)://'; $string['viewsubmissions'] = 'View submissions and grading screen'; +//New admin strings + +$string['show_in_course'] = 'Show tool type when creating tool instances'; +$string['delegate_yes'] = 'Delegate to Instructor (Default: Yes)'; +$string['delegate_no'] = 'Delegate to Instructor (Default: No)'; +$string['tool_settings'] = 'Tool Settings'; +$string['miscellaneous'] = 'Miscellaneous'; +$string['embed'] = 'Embed'; +$string['embed_no_blocks'] = 'Embed, without blocks'; +$string['popup_window'] = 'Popup window'; +$string['new_window'] = 'New browser window / tab'; + +//New instructor strings +$string['display_name'] = 'Display activity name when launched'; +$string['display_description'] = 'Display activity description when launched'; +$string['external_tool_type'] = 'External tool type'; +$string['launch_url'] = 'Launch URL'; +$string['share_name'] = 'Share launcher\'s name with the tool'; +$string['share_email'] = 'Share launcher\'s email with the tool'; +$string['accept_grades'] = 'Accept grades from the tool'; +$string['share_roster'] = 'Allow the tool to access this course\'s roster'; +$string['automatic'] = 'Automatic, based on Launch URL'; \ No newline at end of file diff --git a/mod/blti/lib.php b/mod/blti/lib.php index e0888ef63f9..2c13f93a652 100644 --- a/mod/blti/lib.php +++ b/mod/blti/lib.php @@ -79,18 +79,19 @@ function blti_supports($feature) { * @param object $instance An object from the form in mod.html * @return int The id of the newly inserted basiclti record **/ -function blti_add_instance($basiclti) { +function blti_add_instance($formdata) { global $DB; - $basiclti->timecreated = time(); - $basiclti->timemodified = $basiclti->timecreated; - $basiclti->placementsecret = uniqid('', true); - $basiclti->timeplacementsecret = time(); + $formdata->timecreated = time(); + $formdata->timemodified = $formdata->timecreated; + //$basiclti->placementsecret = uniqid('', true); + //$basiclti->timeplacementsecret = time(); - $id = $DB->insert_record("blti", $basiclti); + $id = $DB->insert_record("blti", $formdata); - $basiclti = $DB->get_record('blti', array('id'=>$id)); - - if ($basiclti->instructorchoiceacceptgrades == 1) { + if ($formdata->instructorchoiceacceptgrades == 1) { + $basiclti = $DB->get_record('blti', array('id'=>$id)); + $basiclti->cmidnumber = $formdata->cmidnumber; + blti_grade_item_update($basiclti); } @@ -105,26 +106,22 @@ function blti_add_instance($basiclti) { * @param object $instance An object from the form in mod.html * @return boolean Success/Fail **/ -function blti_update_instance($basiclti) { +function blti_update_instance($formdata) { global $DB; - $basiclti->timemodified = time(); - $basiclti->id = $basiclti->instance; + $formdata->timemodified = time(); + $formdata->id = $formdata->instance; - $basicltirec = $DB->get_record("blti", array("id" => $basiclti->id)); - $basiclti->grade = $basicltirec->grade; - - if (empty($basiclti->preferwidget)) { - $basiclti->preferwidget = 0; - } - - if ($basiclti->instructorchoiceacceptgrades == 1) { - blti_grade_item_update($basiclti); + if ($formdata->instructorchoiceacceptgrades == 1) { + $basicltirec = $DB->get_record("blti", array("id" => $formdata->id)); + $basicltirec->cmidnumber = $formdata->cmidnumber; + + blti_grade_item_update($basicltirec); } else { - blti_grade_item_delete($basiclti); + blti_grade_item_delete($formdata); } - return $DB->update_record("blti", $basiclti); + return $DB->update_record("blti", $formdata); } /** @@ -312,7 +309,7 @@ function blti_get_blti_types() { * * @return array of basicLTI types */ -function blti_get_types() { +/*function blti_get_types() { $types = array(); $basicltitypes = blti_get_blti_types(); @@ -336,7 +333,7 @@ function blti_get_types() { } return $types; -} +}*/ ////////////////////////////////////////////////////////////////////////////////////// /// Any other basiclti functions go here. Each of them must have a name that @@ -964,10 +961,6 @@ function blti_grade_item_update($basiclti, $grades=null) { global $CFG; require_once($CFG->libdir.'/gradelib.php'); - if (!isset($basiclti->courseid)) { - $basiclti->courseid = $basiclti->course; - } - $params = array('itemname'=>$basiclti->name, 'idnumber'=>$basiclti->cmidnumber); if ($basiclti->grade > 0) { @@ -988,7 +981,7 @@ function blti_grade_item_update($basiclti, $grades=null) { $grades = null; } - return grade_update('mod/blti', $basiclti->courseid, 'mod', 'blti', $basiclti->id, 0, $grades, $params); + return grade_update('mod/blti', $basiclti->course, 'mod', 'blti', $basiclti->id, 0, $grades, $params); } /** @@ -1001,10 +994,6 @@ function blti_grade_item_delete($basiclti) { global $CFG; require_once($CFG->libdir.'/gradelib.php'); - if (!isset($basiclti->courseid)) { - $basiclti->courseid = $basiclti->course; - } - - return grade_update('mod/blti', $basiclti->courseid, 'mod', 'blti', $basiclti->id, 0, null, array('deleted'=>1)); + return grade_update('mod/blti', $basiclti->course, 'mod', 'blti', $basiclti->id, 0, null, array('deleted'=>1)); } diff --git a/mod/blti/locallib.php b/mod/blti/locallib.php index 2310b0a4ce8..1885cb169ed 100644 --- a/mod/blti/locallib.php +++ b/mod/blti/locallib.php @@ -321,6 +321,19 @@ function blti_filter_get_types() { return $DB->get_records('blti_types'); } +function blti_get_types_for_add_instance(){ + $admintypes = blti_filter_get_types(); + + $types = array(); + $types[0] = get_string('automatic', 'blti'); + + foreach($admintypes as $type) { + $types[$type->id] = $type->name; + } + + return $types; +} + /** * Prints the various configured tool types * diff --git a/mod/blti/mod_form.php b/mod/blti/mod_form.php index 9eceb6ac89e..670f4216424 100644 --- a/mod/blti/mod_form.php +++ b/mod/blti/mod_form.php @@ -87,113 +87,65 @@ class mod_blti_mod_form extends moodleform_mod { $mform->setType('name', PARAM_TEXT); $mform->addRule('name', null, 'required', null, 'client'); /// Adding the optional "intro" and "introformat" pair of fields - $this->add_intro_editor(true, get_string('basicltiintro', 'blti')); + $this->add_intro_editor(false, get_string('basicltiintro', 'blti')); + $mform->setAdvanced('introeditor'); + $mform->addElement('checkbox', 'showtitle', ' ', ' ' . get_string('display_name', 'blti')); + $mform->setAdvanced('showtitle'); + + $mform->addElement('checkbox', 'showdescription', ' ', ' ' . get_string('display_description', 'blti')); + $mform->setAdvanced('showdescription'); + + //Tool settings + $mform->addElement('select', 'typeid', get_string('external_tool_type', 'blti'), blti_get_types_for_add_instance()); + //$mform->setDefault('typeid', '0'); + + $mform->addElement('text', 'toolurl', get_string('launch_url', 'blti'), array('size'=>'64')); + $mform->setType('toolurl', PARAM_TEXT); + + $mform->addElement('text', 'resourcekey', get_string('resourcekey', 'blti')); + $mform->setType('resourcekey', PARAM_TEXT); + $mform->setAdvanced('resourcekey'); + + $mform->addElement('passwordunmask', 'password', get_string('password', 'blti')); + $mform->setType('password', PARAM_TEXT); + $mform->setAdvanced('password'); + + $mform->addElement('textarea', 'instructorcustomparameters', get_string('custom', 'blti'), array('rows'=>4, 'cols'=>60)); + $mform->setType('instructorcustomparameters', PARAM_TEXT); + $mform->setAdvanced('instructorcustomparameters'); + //------------------------------------------------------------------------------- - $mform->addElement('hidden', 'typeid', $this->typeid); - $mform->addElement('hidden', 'toolurl', $this->typeconfig['toolurl']); + //$mform->addElement('hidden', 'typeid', $this->typeid); + //$mform->addElement('hidden', 'toolurl', $this->typeconfig['toolurl']); $mform->addElement('hidden', 'type', $typename); //------------------------------------------------------------------------------- // Add privacy preferences fieldset where users choose whether to send their data $mform->addElement('header', 'privacy', get_string('privacy', 'blti')); - $privacyoptions=array(); - $privacyoptions[0] = get_string('donot', 'blti'); - $privacyoptions[1] = get_string('send', 'blti'); - - $mform->addElement('select', 'instructorchoicesendname', get_string('sendname', 'blti'), $privacyoptions); - - if (isset($this->typeconfig['instructorchoicesendname'])) { - if ($this->typeconfig['instructorchoicesendname'] == 0) { - $mform->setDefault('instructorchoicesendname', '0'); - } else if ($this->typeconfig['instructorchoicesendname'] == 1) { - $mform->setDefault('instructorchoicesendname', '1'); - } - } -// $mform->addHelpButton('instructorchoicesendname', 'sendname', 'blti'); - - $mform->addElement('select', 'instructorchoicesendemailaddr', get_string('sendemailaddr', 'blti'), $privacyoptions); - - if (isset($this->typeconfig['instructorchoicesendemailaddr'])) { - if ($this->typeconfig['instructorchoicesendemailaddr'] == 0) { - $mform->setDefault('instructorchoicesendemailaddr', '0'); - } else if ($this->typeconfig['instructorchoicesendemailaddr'] == 1) { - $mform->setDefault('instructorchoicesendemailaddr', '1'); - } - } - // $mform->addHelpButton('instructorchoicesendemailaddr', 'sendemailaddr', 'blti'); + $mform->addElement('checkbox', 'instructorchoicesendname', ' ', ' ' . get_string('share_name', 'blti')); + $mform->setDefault('instructorchoicesendname', '1'); + + $mform->addElement('checkbox', 'instructorchoicesendemailaddr', ' ', ' ' . get_string('share_email', 'blti')); + $mform->setDefault('instructorchoicesendemailaddr', '1'); + + $mform->addElement('checkbox', 'instructorchoiceacceptgrades', ' ', ' ' . get_string('accept_grades', 'blti')); + $mform->setDefault('instructorchoiceacceptgrades', '1'); + + $mform->addElement('checkbox', 'instructorchoiceallowroster', ' ', ' ' . get_string('share_roster', 'blti')); + $mform->setDefault('instructorchoiceallowroster', '1'); //------------------------------------------------------------------------------- - // Add grading preferences fieldset where the instructor determines whether to accept grades - $mform->addElement('header', 'extensions', get_string('extensions', 'blti')); - $extensionoptions=array(); - $extensionoptions[0] = get_string('donotaccept', 'blti'); - $extensionoptions[1] = get_string('accept', 'blti'); - - $mform->addElement('select', 'instructorchoiceacceptgrades', get_string('acceptgrades', 'blti'), $extensionoptions); - if (isset($this->typeconfig['instructorchoiceacceptgrades'])) { - if ($this->typeconfig['instructorchoiceacceptgrades'] == 0) { - $mform->setDefault('instructorchoiceacceptgrades', '0'); - } else if ($this->typeconfig['instructorchoiceacceptgrades'] == 1) { - $mform->setDefault('instructorchoiceacceptgrades', '1'); - } - } - // $mform->addHelpButton('instructorchoiceacceptgrades', 'acceptgrades', 'blti'); - - $extensionoptions=array(); - $extensionoptions[0] = get_string('donotallow', 'blti'); - $extensionoptions[1] = get_string('allow', 'blti'); - - $mform->addElement('select', 'instructorchoiceallowroster', get_string('allowroster', 'blti'), $extensionoptions); - if (isset($this->typeconfig['instructorchoiceallowroster'])) { - if ($this->typeconfig['instructorchoiceallowroster'] == 0) { - $mform->setDefault('instructorchoiceallowroster', '0'); - } else if ($this->typeconfig['instructorchoiceallowroster'] == 1) { - $mform->setDefault('instructorchoiceallowroster', '1'); - } - } - // $mform->addHelpButton('instructorchoiceallowroster', 'allowroster', 'blti'); - $mform->setAdvanced('instructorchoiceallowroster'); - - $mform->addElement('select', 'instructorchoiceallowsetting', get_string('allowsetting', 'blti'), $extensionoptions); - - if (isset($this->typeconfig['instructorchoiceallowsetting'])) { - if ($this->typeconfig['instructorchoiceallowsetting'] == 0) { - $mform->setDefault('instructorchoiceallowsetting', '0'); - } else if ($this->typeconfig['instructorchoiceallowsetting'] == 1) { - $mform->setDefault('instructorchoiceallowsetting', '1'); - } - } -// $mform->addHelpButton('instructorchoiceallowsetting', 'allowsetting', 'blti'); - $mform->setAdvanced('instructorchoiceallowsetting'); - -//------------------------------------------------------------------------------- - if (isset($this->typeconfig['allowinstructorcustom'])) { - if ($this->typeconfig['allowinstructorcustom'] == 1) { - // Add custom parameters fieldset - $mform->addElement('header', 'launchoptions', get_string('custominstr', 'blti')); - - $mform->addElement('textarea', 'instructorcustomparameters', '', array('rows'=>15, 'cols'=>60)); - $mform->setType('instructorcustomparameters', PARAM_TEXT); - $mform->setAdvanced('instructorcustomparameters'); - } - } - -//------------------------------------------------------------------------------- // Add launch parameters fieldset $mform->addElement('header', 'launchoptions', get_string('launchoptions', 'blti')); - // Size parameters - $mform->addElement('text', 'preferheight', get_string('preferheight', 'blti')); - if (isset($this->typeconfig['preferheight'])) { - $mform->setDefault('preferheight', $this->typeconfig['preferheight']); - } - $launchoptions=array(); - $launchoptions[0] = get_string('launch_in_moodle', 'blti'); - $launchoptions[1] = get_string('launch_in_popup', 'blti'); + $launchoptions[0] = get_string('embed', 'blti'); + $launchoptions[1] = get_string('embed_no_blocks', 'blti'); + $launchoptions[2] = get_string('popup_window', 'blti'); + $launchoptions[3] = get_string('new_window', 'blti'); $mform->addElement('select', 'launchinpopup', get_string('launchinpopup', 'blti'), $launchoptions); @@ -205,7 +157,7 @@ class mod_blti_mod_form extends moodleform_mod { } } - $debugoptions=array(); +/* $debugoptions=array(); $debugoptions[0] = get_string('debuglaunchoff', 'blti'); $debugoptions[1] = get_string('debuglaunchon', 'blti'); @@ -218,16 +170,7 @@ class mod_blti_mod_form extends moodleform_mod { $mform->setDefault('debuglaunch', '1'); } } - -//------------------------------------------------------------------------------- - // Organization parameters - if (isset($this->typeconfig['organizationid'])) { - $mform->addElement('hidden', 'organizationid', $this->typeconfig['organizationid']); - } - if (isset($this->typeconfig['organizationurl'])) { - $mform->addElement('hidden', 'organizationurl', $this->typeconfig['organizationurl']); - } -// $mform->addElement('hidden', 'organizationdescr', $this->typeconfig['organizationdescr']); +*/ //------------------------------------------------------------------------------- // add standard elements, common to all modules @@ -243,7 +186,7 @@ class mod_blti_mod_form extends moodleform_mod { */ function definition_after_data() { parent::definition_after_data(); - $mform =& $this->_form; + /* $mform =& $this->_form; $typeid =& $mform->getElement('typeid'); $typeidvalue = $mform->getElementValue('typeid'); @@ -283,7 +226,7 @@ class mod_blti_mod_form extends moodleform_mod { $field->freeze(); $field->setPersistantFreeze(true); } - } + }*/ } /** @@ -293,7 +236,7 @@ class mod_blti_mod_form extends moodleform_mod { * @param array $default_values passed by reference */ function data_preprocessing(&$default_values) { - global $CFG; +/* global $CFG; $default_values['typeid'] = $this->typeid; if (!isset($default_values['toolurl'])) { @@ -475,7 +418,7 @@ class mod_blti_mod_form extends moodleform_mod { $default_values['launchinpopup'] = $CFG->blti_launchinpopup; } } - +*/ } } diff --git a/mod/blti/styles.css b/mod/blti/styles.css index 0be6d5f9bf9..72126e44e21 100644 --- a/mod/blti/styles.css +++ b/mod/blti/styles.css @@ -27,3 +27,6 @@ #page-mod-blti-submissions .submissions .outcome, #page-mod-blti-submissions .submissions .finalgrade {text-align: right;} #page-mod-blti-submissions .qgprefs #optiontable {text-align:right;margin-left:auto;} + +/* Styles for admin */ +.path-admin-mod-blti .mform .fitem .fitemtitle { min-width:15em;padding-right:1em } /* Prevent setting titles from wrapping */ diff --git a/mod/blti/typessettings.php b/mod/blti/typessettings.php index 0ef7c4ad352..44214014b6a 100644 --- a/mod/blti/typessettings.php +++ b/mod/blti/typessettings.php @@ -74,11 +74,16 @@ $errormsg = ''; $focus = ''; if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton)) { + $type = new StdClass(); + $type->name = $data->lti_typename; + $type->baseurl = $data->lti_toolurl; + $type->course = $SITE->id; + $type->coursevisible = 1; + $type->timemodified = time(); + if (isset($id)) { - $type = new StdClass(); $type->id = $id; - $type->name = $data->lti_typename; - $type->rawname = preg_replace('/[^a-zA-Z]/', '', $type->name); + if ($DB->update_record('blti_types', $type)) { unset ($data->lti_typename); //@TODO: update work @@ -95,23 +100,13 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton } } } - - // Update toolurl for all existing instances - it is the only common parameter - // between configurations and instances - $instances = $DB->get_records('blti', array('typeid' => $id)); - foreach ($instances as $instance) { - if ($instance->toolurl != $data->lti_toolurl) { - $instance->toolurl = $data->lti_toolurl; - $DB->update_record('blti', $instance); - } - } } redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingblti"); die; } else { - $type = new StdClass(); - $type->name = $data->lti_typename; - $type->rawname = preg_replace('/[^a-zA-Z]/', '', $type->name); + $type->createdby = $USER->id; + $type->timecreated = time(); + if ($id = $DB->insert_record('blti_types', $type)) { if (!empty($data->lti_fix)) { $instance = $DB->get_record('blti', array('id' => $data->lti_fix)); From 5f24742f86a4aad22837f35530a497103d190c8d Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Mon, 29 Aug 2011 16:27:41 -0400 Subject: [PATCH 04/78] Test launch works --- mod/blti/db/install.xml | 10 ++- mod/blti/locallib.php | 150 ++++++++++++++++++------------------- mod/blti/settings.php | 19 +---- mod/blti/typessettings.php | 38 ++-------- mod/blti/view.php | 11 +-- 5 files changed, 92 insertions(+), 136 deletions(-) diff --git a/mod/blti/db/install.xml b/mod/blti/db/install.xml index a0a84d83efa..2836791b1cc 100644 --- a/mod/blti/db/install.xml +++ b/mod/blti/db/install.xml @@ -1,5 +1,5 @@ - @@ -38,8 +38,9 @@ - - + + + @@ -50,7 +51,8 @@ - + + diff --git a/mod/blti/locallib.php b/mod/blti/locallib.php index 1885cb169ed..8e616f1469a 100644 --- a/mod/blti/locallib.php +++ b/mod/blti/locallib.php @@ -49,6 +49,8 @@ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot.'/mod/blti/OAuth.php'); +define('BLTI_URL_DOMAIN_REGEX', '/(?:https?:\/\/)?(?:www\.)?([^\/]+)(?:\/|$)/i'); + /** * Prints a Basic LTI activity * @@ -57,10 +59,21 @@ require_once($CFG->dirroot.'/mod/blti/OAuth.php'); function blti_view($instance, $makeobject=false) { global $PAGE; - $typeconfig = blti_get_type_config($instance->typeid); - $endpoint = $typeconfig['toolurl']; - $key = $typeconfig['resourcekey']; - $secret = $typeconfig['password']; + if(empty($instance->typeid)){ + $tool = blti_get_tool_by_url_match($instance->toolurl); + if($tool){ + $typeid = $tool->id; + } else { + //Tool not found + } + } else { + $typeid = $instance->typeid; + } + + $typeconfig = blti_get_type_config($typeid); + $endpoint = !empty($instance->toolurl) ? $instance->toolurl : $typeconfig['toolurl']; + $key = !empty($instance->resourcekey) ? $instance->resourcekey : $typeconfig['resourcekey']; + $secret = !empty($instance->password) ? $instance->password : $typeconfig['password']; $orgid = $typeconfig['organizationid']; /* Suppress this for now - Chuck $orgdesc = $typeconfig['organizationdescr']; @@ -80,11 +93,8 @@ function blti_view($instance, $makeobject=false) { $debuglaunch = ( $instance->debuglaunch == 1 ); if ( $makeobject ) { - // TODO: Need frame height - $height = $instance->preferheight; - if ((!$height) || ($height == 0)) { - $height = 400; - } + $height = 600; + $content = post_launch_html($parms, $endpoint, $debuglaunch, $height); } else { $content = post_launch_html($parms, $endpoint, $debuglaunch, false); @@ -126,7 +136,7 @@ function blti_build_request($instance, $typeconfig, $course) { "launch_presentation_locale" => $locale, ); - $placementsecret = $instance->placementsecret; + $placementsecret = $typeconfig['servicesalt']; if ( isset($placementsecret) ) { $suffix = ':::' . $USER->id . ':::' . $instance->id; $plaintext = $placementsecret . $suffix; @@ -148,17 +158,6 @@ function blti_build_request($instance, $typeconfig, $course) { $requestparams["ext_ims_lis_memberships_url"] = $CFG->wwwroot.'/mod/blti/service.php'; } - if ( isset($placementsecret) && - ( $typeconfig['allowsetting'] == 1 || - ( $typeconfig['allowsetting'] == 2 && $instance->instructorchoiceallowsetting == 1 ) ) ) { - $requestparams["ext_ims_lti_tool_setting_id"] = $sourcedid; - $requestparams["ext_ims_lti_tool_setting_url"] = $CFG->wwwroot.'/mod/blti/service.php'; - $setting = $instance->setting; - if ( isset($setting) ) { - $requestparams["ext_ims_lti_tool_setting"] = $setting; - } - } - // Send user's name and email data if appropriate if ( $typeconfig['sendname'] == 1 || ( $typeconfig['sendname'] == 2 && $instance->instructorchoicesendname == 1 ) ) { @@ -299,16 +298,10 @@ function blti_get_type_config($typeid) { return $typeconfig; } -/** - * Returns all tool instances with a typeid of 0 that - * marks them as unconfigured. These tools usually proceed from a - * backup - restore process. - * - */ -function blti_get_unconfigured_tools() { +function blti_get_tools_by_domain($domain){ global $DB; - - return $DB->get_records('blti', array('typeid' => 0)); + + return $DB->get_records('blti_types', array('tooldomain' => $domain)); } /** @@ -334,6 +327,53 @@ function blti_get_types_for_add_instance(){ return $types; } +function blti_get_domain_from_url($url){ + $matches = array(); + + if(preg_match(BLTI_URL_DOMAIN_REGEX, $url, $matches)){ + return $matches[1]; + } +} + +function blti_get_tool_by_url_match($url){ + $domain = blti_get_domain_from_url($url); + + $possibletools = blti_get_tools_by_domain($domain); + + return blti_get_best_tool_by_url($url, $possibletools); +} + +function blti_get_best_tool_by_url($url, $tools){ + if(count($tools) === 0){ + return null; + } + + $urllower = strtolower($url); + + foreach($tools as $tool){ + $tool->_matchscore = 0; + + $toolbaseurllower = strtolower($tool->baseurl); + + if($urllower === $toolbaseurllower){ + $tool->_matchscore += 100; + } else if(strstr($urllower, $toolbaseurllower) >= 0){ + $tool->_matchscore += 50; + } + } + + $bestmatch = array_reduce($tools, function($value, $tool){ + if($tool->_matchscore > $value->_matchscore){ + return $tool; + } else { + return $value; + } + + }, (object)array('_matchscore' => -1)); + + return $bestmatch; +} + /** * Prints the various configured tool types * @@ -554,7 +594,9 @@ function blti_update_config($config) { global $DB; $return = true; - if ($old = $DB->get_record('blti_types_config', array('typeid' => $config->typeid, 'name' => $config->name))) { + $old = $DB->get_record('blti_types_config', array('typeid' => $config->typeid, 'name' => $config->name)); + + if ($old) { $config->id = $old->id; $return = $DB->update_record('blti_types_config', $config); } else { @@ -563,52 +605,6 @@ function blti_update_config($config) { return $return; } -/** - * Prints the screen that handles misconfigured objects due to - * an incomplete backup - restore process - * - * @param int $id ID of the misconfigured tool - * - */ -function blti_fix_misconfigured_choice($id) { - global $CFG, $USER, $OUTPUT; - - echo $OUTPUT->box_start('generalbox'); - echo '
'; - $types = blti_filter_get_types(); - if (!empty($types)) { - echo '

'.get_string('fixexistingconf', 'blti').'


'; - echo '
sesskey.' method="post">'; - - foreach ($types as $type) { - echo ''.$type->name.'
'; - } - echo ''; - echo '
'; - echo '
'; - echo ''; - } else { - echo '
'; - echo get_string('notypes', 'blti'); - echo '
'; - } - echo '
'; - echo $OUTPUT->box_end(); - - echo $OUTPUT->box_start("generalbox"); - echo '
'; - echo '

'.get_string('fixnewconf', 'blti').'


'; - echo '
sesskey.' method="post">'; - echo ''; - echo ''; - echo '
'; - echo ''; - echo '
'; - echo $OUTPUT->box_end(); - -} - - /** * Signs the petition to launch the external tool using OAuth * diff --git a/mod/blti/settings.php b/mod/blti/settings.php index c730ce1f96b..c0a7d71da9e 100644 --- a/mod/blti/settings.php +++ b/mod/blti/settings.php @@ -79,22 +79,5 @@ if ($ADMIN->fulltree) { $settings->add(new admin_setting_heading('blti_types', get_string('configuredtools', 'blti'), $str)); - - $unconfigured = blti_get_unconfigured_tools(); - if (!empty($unconfigured)) { - $newstr = '
'; - $newstr .= ''; - - foreach ($unconfigured as $unconf) { - $coursename = $DB->get_field('course', 'shortname', array('id' => $unconf->course)); - $newstr .= ''. - ''. - ''. - ''; - } - $newstr .= '
Course Tool Name
'.$coursename.''.$unconf->name.''. - 'Update'.'  '.'
'; - - $settings->add(new admin_setting_heading('blti_mis_types', get_string('misconfiguredtools', 'blti'), $newstr)); - } + } diff --git a/mod/blti/typessettings.php b/mod/blti/typessettings.php index 44214014b6a..670e2a384cd 100644 --- a/mod/blti/typessettings.php +++ b/mod/blti/typessettings.php @@ -77,6 +77,7 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton $type = new StdClass(); $type->name = $data->lti_typename; $type->baseurl = $data->lti_toolurl; + $type->tooldomain = blti_get_domain_from_url($data->lti_toolurl); $type->course = $SITE->id; $type->coursevisible = 1; $type->timemodified = time(); @@ -86,7 +87,7 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton if ($DB->update_record('blti_types', $type)) { unset ($data->lti_typename); - //@TODO: update work + foreach ($data as $key => $value) { if (substr($key, 0, 4)=='lti_' && !is_null($value)) { $record = new StdClass(); @@ -107,14 +108,12 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton $type->createdby = $USER->id; $type->timecreated = time(); - if ($id = $DB->insert_record('blti_types', $type)) { - if (!empty($data->lti_fix)) { - $instance = $DB->get_record('blti', array('id' => $data->lti_fix)); - $instance->typeid = $id; - $DB->update_record('blti', $instance); - } - unset ($data->lti_fix); - + //Create a salt value to be used for signing passed data to extension services + $data->lti_servicesalt = uniqid('', true); + + $id = $DB->insert_record('blti_types', $type); + + if ($id) { unset ($data->lti_typename); foreach ($data as $key => $value) { if (substr($key, 0, 4)=='lti_' && !is_null($value)) { @@ -135,18 +134,6 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingblti"); die; } - if (empty($adminroot->errors)) { - switch ($return) { - case 'site': redirect("$CFG->wwwroot/"); - case 'admin': redirect("$CFG->wwwroot/$CFG->admin/"); - } - } else { - $errormsg = get_string('errorwithsettings', 'admin'); - $firsterror = reset($adminroot->errors); - $focus = $firsterror->id; - } - $adminroot =& admin_get_root(true); //reload tree - $page =& $adminroot->locate($section); } if ($action == 'delete') { @@ -236,15 +223,6 @@ if (empty($SITE->fullname)) { $type = blti_get_type_type_config($id); $form->set_data($type); $form->display(); - } else if ($action == 'fix') { - if (!isset($definenew) && !isset($useexisting)) { - blti_fix_misconfigured_choice($id); - } else if (isset($definenew)) { - $form = new mod_blti_edit_types_form(); - $type = blti_get_type_config_from_instance($id); - $form->set_data($type); - $form->display(); - } } echo $OUTPUT->box_end(); diff --git a/mod/blti/view.php b/mod/blti/view.php index 0484070b4b9..47364bf3f64 100644 --- a/mod/blti/view.php +++ b/mod/blti/view.php @@ -99,10 +99,6 @@ echo $OUTPUT->header(); echo $OUTPUT->heading(format_string($basiclti->name)); echo $OUTPUT->box($basiclti->intro, 'generalbox description', 'intro'); -if ($basiclti->typeid == 0) { - print_error('errormisconfig', 'blti'); -} - if ($basiclti->instructorchoiceacceptgrades == 1) { echo ''; } @@ -110,7 +106,7 @@ if ($basiclti->instructorchoiceacceptgrades == 1) { echo $OUTPUT->box_start('generalbox activity'); -if ( $basiclti->launchinpopup > 0 ) { +if ( false /*$basiclti->launchinpopup > 0*/ ) { print "\n"; - print "

".get_string("basiclti_in_new_window", "blti")."

\n"; +if ( $launchcontainer == BLTI_LAUNCH_CONTAINER_WINDOW ) { + echo "\n"; + echo "

".get_string("basiclti_in_new_window", "blti")."

\n"; } else { // Request the launch content with an object tag - /*$height = $basiclti->preferheight; - if ((!$height) || ($height == 0)) { - $height = 400; - }*/ - $height=600; - print ''; + echo ''; + + //Output script to make the object tag be as large as possible + $resize = <<<'SCRIPT' + +SCRIPT; + + echo $resize; } -echo $OUTPUT->box_end(); /// Finish the page echo $OUTPUT->footer(); From 0d8afb44ee194e1c1a33d146bc381f2f11ce042d Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Tue, 30 Aug 2011 17:39:28 -0400 Subject: [PATCH 06/78] Removing course id field admin setting, making cmidnumber advanced in instructor interface, wiring up setting to show tool in creation screen --- mod/blti/db/install.xml | 2 +- mod/blti/edit_form.php | 4 ---- mod/blti/lang/en/blti.php | 1 - mod/blti/locallib.php | 26 +++++++++++++------------- mod/blti/mod_form.php | 21 +++++++++++---------- mod/blti/typessettings.php | 4 +++- 6 files changed, 28 insertions(+), 30 deletions(-) diff --git a/mod/blti/db/install.xml b/mod/blti/db/install.xml index 2836791b1cc..2fb59755d75 100644 --- a/mod/blti/db/install.xml +++ b/mod/blti/db/install.xml @@ -42,7 +42,7 @@ - + diff --git a/mod/blti/edit_form.php b/mod/blti/edit_form.php index 995824d2b89..ef1e7da79be 100644 --- a/mod/blti/edit_form.php +++ b/mod/blti/edit_form.php @@ -132,10 +132,6 @@ class mod_blti_edit_types_form extends moodleform{ $idoptions[0] = get_string('id', 'blti'); $idoptions[1] = get_string('courseid', 'blti'); - $mform->addElement('select', 'lti_moodle_course_field', get_string('moodle_course_field', 'blti'), $idoptions); - $mform->setDefault('lti_moodle_course_field', '0'); - - $mform->addElement('text', 'lti_organizationid', get_string('organizationid', 'blti')); $mform->setType('lti_organizationid', PARAM_TEXT); // $mform->addHelpButton('lti_organizationid', 'organizationid', 'blti'); diff --git a/mod/blti/lang/en/blti.php b/mod/blti/lang/en/blti.php index afc41ef394d..d607cc88959 100644 --- a/mod/blti/lang/en/blti.php +++ b/mod/blti/lang/en/blti.php @@ -118,7 +118,6 @@ $string['module_class_type'] = 'Moodle module type'; $string['modulename'] = 'External Tool'; $string['modulenameplural'] = 'basicltis'; $string['modulenamepluralformatted'] = 'Basic LTI Instances'; -$string['moodle_course_field'] = 'Course identification field'; $string['never'] = 'Never'; $string['noattempts'] = 'No attempts have been made on this tool instance'; $string['noservers'] = 'No servers found'; diff --git a/mod/blti/locallib.php b/mod/blti/locallib.php index 6d32d437e88..a7e6eb34a36 100644 --- a/mod/blti/locallib.php +++ b/mod/blti/locallib.php @@ -97,16 +97,12 @@ function blti_view($instance, $makeobject=false) { $parms = sign_parameters($requestparams, $endpoint, "POST", $key, $secret, $submittext, $orgid /*, $orgdesc*/); $debuglaunch = ( $instance->debuglaunch == 1 ); - if ( $makeobject ) { - $height = 600; - - $content = post_launch_html($parms, $endpoint, $debuglaunch, $height); - } else { - $content = post_launch_html($parms, $endpoint, $debuglaunch, false); - } + + $content = post_launch_html($parms, $endpoint, $debuglaunch); + // $cm = get_coursemodule_from_instance("blti", $instance->id); // print ''.$content.''; - print $content; + echo $content; } /** @@ -320,7 +316,8 @@ function blti_filter_get_types() { } function blti_get_types_for_add_instance(){ - $admintypes = blti_filter_get_types(); + global $DB; + $admintypes = $DB->get_records('blti_types', array('coursevisible' => 1)); $types = array(); $types[0] = get_string('automatic', 'blti'); @@ -548,12 +545,15 @@ function blti_get_type_type_config($id) { if (isset($config['launchcontainer'])) { $type->lti_launchcontainer = $config['launchcontainer']; } + + if (isset($config['coursevisible'])) { + $type->lti_coursevisible = $config['coursevisible']; + } + if (isset($config['debuglaunch'])) { $type->lti_debuglaunch = $config['debuglaunch']; } - if (isset($config['moodle_course_field'])) { - $type->lti_moodle_course_field = $config['moodle_course_field']; - } + if (isset($config['module_class_type'])) { $type->lti_module_class_type = $config['module_class_type']; } @@ -644,7 +644,7 @@ function sign_parameters($oldparms, $endpoint, $method, $oauthconsumerkey, $oaut * @param $endpoint URL of the external tool * @param $debug Debug (true/false) */ -function post_launch_html($newparms, $endpoint, $debug=false, $height=false) { +function post_launch_html($newparms, $endpoint, $debug=false) { global $lastbasestring; $r = "
\n"; diff --git a/mod/blti/mod_form.php b/mod/blti/mod_form.php index 7ec6413f718..32e4ff90c67 100644 --- a/mod/blti/mod_form.php +++ b/mod/blti/mod_form.php @@ -103,6 +103,15 @@ class mod_blti_mod_form extends moodleform_mod { $mform->addElement('text', 'toolurl', get_string('launch_url', 'blti'), array('size'=>'64')); $mform->setType('toolurl', PARAM_TEXT); + $launchoptions=array(); + $launchoptions[BLTI_LAUNCH_CONTAINER_DEFAULT] = get_string('default', 'blti'); + $launchoptions[BLTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'blti'); + $launchoptions[BLTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'blti'); + $launchoptions[BLTI_LAUNCH_CONTAINER_WINDOW] = get_string('new_window', 'blti'); + + $mform->addElement('select', 'launchcontainer', get_string('launchinpopup', 'blti'), $launchoptions); + $mform->setDefault('launchcontainer', BLTI_LAUNCH_CONTAINER_DEFAULT); + $mform->addElement('text', 'resourcekey', get_string('resourcekey', 'blti')); $mform->setType('resourcekey', PARAM_TEXT); $mform->setAdvanced('resourcekey'); @@ -115,16 +124,6 @@ class mod_blti_mod_form extends moodleform_mod { $mform->setType('instructorcustomparameters', PARAM_TEXT); $mform->setAdvanced('instructorcustomparameters'); - $launchoptions=array(); - $launchoptions[BLTI_LAUNCH_CONTAINER_DEFAULT] = get_string('default', 'blti'); - $launchoptions[BLTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'blti'); - $launchoptions[BLTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'blti'); - $launchoptions[BLTI_LAUNCH_CONTAINER_WINDOW] = get_string('new_window', 'blti'); - - $mform->addElement('select', 'launchcontainer', get_string('launchinpopup', 'blti'), $launchoptions); - - $mform->setDefault('launchcontainer', BLTI_LAUNCH_CONTAINER_DEFAULT); - //------------------------------------------------------------------------------- //$mform->addElement('hidden', 'typeid', $this->typeid); //$mform->addElement('hidden', 'toolurl', $this->typeconfig['toolurl']); @@ -166,6 +165,8 @@ class mod_blti_mod_form extends moodleform_mod { //------------------------------------------------------------------------------- // add standard elements, common to all modules $this->standard_coursemodule_elements(); + + $mform->setAdvanced('cmidnumber'); //------------------------------------------------------------------------------- // add standard buttons, common to all modules $this->add_action_buttons(); diff --git a/mod/blti/typessettings.php b/mod/blti/typessettings.php index 670e2a384cd..e168193d505 100644 --- a/mod/blti/typessettings.php +++ b/mod/blti/typessettings.php @@ -79,9 +79,11 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton $type->baseurl = $data->lti_toolurl; $type->tooldomain = blti_get_domain_from_url($data->lti_toolurl); $type->course = $SITE->id; - $type->coursevisible = 1; + $type->coursevisible = !empty($data->lti_coursevisible) ? $data->lti_coursevisible : 0; $type->timemodified = time(); + $data->lti_coursevisible = $type->coursevisible;//When not checked, it does not appear in data array. Set it manually. + if (isset($id)) { $type->id = $id; From 73300339b02e81c8c7d70cacd03b9574fbe18b25 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Wed, 31 Aug 2011 10:13:20 -0400 Subject: [PATCH 07/78] Renaming plugin to lti from blti --- mod/blti/styles.css | 32 ---- mod/{blti => lti}/OAuth.php | 0 mod/{blti => lti}/TODO.txt | 0 mod/{blti => lti}/TrivialStore.php | 2 +- .../backup_lti_activity_task.class.php} | 20 +-- .../backup/moodle2/backup_lti_stepslib.php} | 14 +- .../restore_lti_activity_task.class.php} | 22 +-- .../backup/moodle2/restore_lti_stepslib.php} | 18 +- mod/{blti => lti}/basiclti.js | 2 +- mod/{blti => lti}/db/access.php | 10 +- mod/{blti => lti}/db/install.xml | 8 +- mod/{blti => lti}/db/log.php | 0 mod/{blti => lti}/db/upgrade.php | 6 +- mod/{blti => lti}/edit_form.php | 82 +++++----- mod/{blti => lti}/index.php | 14 +- .../lang/en/help/basiclti/index.html | 0 .../lang/en/help/basiclti/mods.html | 0 .../lang/en/blti.php => lti/lang/en/lti.php} | 4 +- mod/{blti => lti}/launch.php | 16 +- mod/{blti => lti}/lib.php | 154 +++++++++--------- mod/{blti => lti}/localadminlib.php | 8 +- mod/{blti => lti}/locallib.php | 136 ++++++++-------- mod/{blti => lti}/mod_form.php | 132 +++++++-------- mod/{blti => lti}/pix/icon.gif | Bin mod/{blti => lti}/service.php | 30 ++-- mod/{blti => lti}/settings.php | 18 +- mod/{blti => lti}/simpletest/testlocallib.php | 10 +- mod/lti/styles.css | 32 ++++ mod/{blti => lti}/submissions.php | 24 +-- mod/{blti => lti}/typessettings.php | 48 +++--- mod/{blti => lti}/version.php | 2 +- mod/{blti => lti}/view.php | 34 ++-- 32 files changed, 439 insertions(+), 439 deletions(-) delete mode 100644 mod/blti/styles.css rename mod/{blti => lti}/OAuth.php (100%) rename mod/{blti => lti}/TODO.txt (100%) rename mod/{blti => lti}/TrivialStore.php (99%) rename mod/{blti/backup/moodle2/backup_blti_activity_task.class.php => lti/backup/moodle2/backup_lti_activity_task.class.php} (81%) rename mod/{blti/backup/moodle2/backup_blti_stepslib.php => lti/backup/moodle2/backup_lti_stepslib.php} (87%) rename mod/{blti/backup/moodle2/restore_blti_activity_task.class.php => lti/backup/moodle2/restore_lti_activity_task.class.php} (81%) rename mod/{blti/backup/moodle2/restore_blti_stepslib.php => lti/backup/moodle2/restore_lti_stepslib.php} (87%) rename mod/{blti => lti}/basiclti.js (99%) rename mod/{blti => lti}/db/access.php (90%) rename mod/{blti => lti}/db/install.xml (94%) rename mod/{blti => lti}/db/log.php (100%) rename mod/{blti => lti}/db/upgrade.php (92%) rename mod/{blti => lti}/edit_form.php (75%) rename mod/{blti => lti}/index.php (89%) rename mod/{blti => lti}/lang/en/help/basiclti/index.html (100%) rename mod/{blti => lti}/lang/en/help/basiclti/mods.html (100%) rename mod/{blti/lang/en/blti.php => lti/lang/en/lti.php} (97%) rename mod/{blti => lti}/launch.php (86%) rename mod/{blti => lti}/lib.php (85%) rename mod/{blti => lti}/localadminlib.php (89%) rename mod/{blti => lti}/locallib.php (82%) rename mod/{blti => lti}/mod_form.php (78%) rename mod/{blti => lti}/pix/icon.gif (100%) rename mod/{blti => lti}/service.php (92%) rename mod/{blti => lti}/settings.php (79%) rename mod/{blti => lti}/simpletest/testlocallib.php (95%) create mode 100644 mod/lti/styles.css rename mod/{blti => lti}/submissions.php (81%) rename mod/{blti => lti}/typessettings.php (86%) rename mod/{blti => lti}/version.php (97%) rename mod/{blti => lti}/view.php (82%) diff --git a/mod/blti/styles.css b/mod/blti/styles.css deleted file mode 100644 index 72126e44e21..00000000000 --- a/mod/blti/styles.css +++ /dev/null @@ -1,32 +0,0 @@ -.path-mod-blti .bltiframe {position: relative;width: 100%;height: 100%;} - -/** General Styles **/ -.path-mod-blti .userpicture, -.path-mod-blti .picture.user, -.path-mod-blti .picture.teacher {width:35px;height: 35px;vertical-align:top;} -.path-mod-blti .feedback .files, -.path-mod-blti .feedback .grade, -.path-mod-blti .feedback .outcome, -.path-mod-blti .feedback .finalgrade {float: right;} -.path-mod-blti .feedback .disabledfeedback {width: 500px;height: 250px;} -.path-mod-blti .feedback .from {float: left;} -.path-mod-blti .files img {margin-right: 4px;} -.path-mod-blti .files a {white-space:nowrap;} -.path-mod-blti .late {color: red;} -.path-mod-blti .message {text-align: center;} - -/** Styles for submissions.php **/ -#page-mod-blti-submissions fieldset.felement {margin-left: 16%;} -#page-mod-blti-submissions form#options div {text-align:right;margin-left:auto;margin-right:20px;} -#page-mod-blti-submissions .header .commands {display: inline;} -#page-mod-blti-submissions .picture {width: 35px;} -#page-mod-blti-submissions .fullname, -#page-mod-blti-submissions .timemodified, -#page-mod-blti-submissions .timemarked {text-align: left;} -#page-mod-blti-submissions .submissions .grade, -#page-mod-blti-submissions .submissions .outcome, -#page-mod-blti-submissions .submissions .finalgrade {text-align: right;} -#page-mod-blti-submissions .qgprefs #optiontable {text-align:right;margin-left:auto;} - -/* Styles for admin */ -.path-admin-mod-blti .mform .fitem .fitemtitle { min-width:15em;padding-right:1em } /* Prevent setting titles from wrapping */ diff --git a/mod/blti/OAuth.php b/mod/lti/OAuth.php similarity index 100% rename from mod/blti/OAuth.php rename to mod/lti/OAuth.php diff --git a/mod/blti/TODO.txt b/mod/lti/TODO.txt similarity index 100% rename from mod/blti/TODO.txt rename to mod/lti/TODO.txt diff --git a/mod/blti/TrivialStore.php b/mod/lti/TrivialStore.php similarity index 99% rename from mod/blti/TrivialStore.php rename to mod/lti/TrivialStore.php index 6e7086bd8de..88940932b0f 100644 --- a/mod/blti/TrivialStore.php +++ b/mod/lti/TrivialStore.php @@ -50,7 +50,7 @@ /** * This file contains a Trivial memory-based store - no support for tokens * - * @package blti + * @package lti * @copyright IMS Global Learning Consortium * * @author Charles Severance csev@umich.edu diff --git a/mod/blti/backup/moodle2/backup_blti_activity_task.class.php b/mod/lti/backup/moodle2/backup_lti_activity_task.class.php similarity index 81% rename from mod/blti/backup/moodle2/backup_blti_activity_task.class.php rename to mod/lti/backup/moodle2/backup_lti_activity_task.class.php index 7639ec99c10..c70d92d210a 100644 --- a/mod/blti/backup/moodle2/backup_blti_activity_task.class.php +++ b/mod/lti/backup/moodle2/backup_lti_activity_task.class.php @@ -32,9 +32,9 @@ /** - * This file contains the blti module backup class + * This file contains the lti module backup class * - * @package blti + * @package lti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -46,13 +46,13 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -require_once($CFG->dirroot . '/mod/blti/backup/moodle2/backup_blti_stepslib.php'); +require_once($CFG->dirroot . '/mod/lti/backup/moodle2/backup_lti_stepslib.php'); /** - * blti backup task that provides all the settings and steps to perform one + * lti backup task that provides all the settings and steps to perform one * complete backup of the module */ -class backup_blti_activity_task extends backup_activity_task { +class backup_lti_activity_task extends backup_activity_task { /** * Define (add) particular settings this activity can have @@ -66,7 +66,7 @@ class backup_blti_activity_task extends backup_activity_task { */ protected function define_my_steps() { // Choice only has one structure step - $this->add_step(new backup_blti_activity_structure_step('blti_structure', 'blti.xml')); + $this->add_step(new backup_lti_activity_structure_step('lti_structure', 'lti.xml')); } /** @@ -79,12 +79,12 @@ class backup_blti_activity_task extends backup_activity_task { $base = preg_quote($CFG->wwwroot, "/"); // Link to the list of basiclti tools - $search="/(".$base."\/mod\/blti\/index.php\?id\=)([0-9]+)/"; - $content= preg_replace($search, '$@BLTIINDEX*$2@$', $content); + $search="/(".$base."\/mod\/lti\/index.php\?id\=)([0-9]+)/"; + $content= preg_replace($search, '$@LTIINDEX*$2@$', $content); // Link to basiclti view by moduleid - $search="/(".$base."\/mod\/blti\/view.php\?id\=)([0-9]+)/"; - $content= preg_replace($search, '$@BLTIVIEWBYID*$2@$', $content); + $search="/(".$base."\/mod\/lti\/view.php\?id\=)([0-9]+)/"; + $content= preg_replace($search, '$@LTIVIEWBYID*$2@$', $content); return $content; } diff --git a/mod/blti/backup/moodle2/backup_blti_stepslib.php b/mod/lti/backup/moodle2/backup_lti_stepslib.php similarity index 87% rename from mod/blti/backup/moodle2/backup_blti_stepslib.php rename to mod/lti/backup/moodle2/backup_lti_stepslib.php index 8e2bf7b362e..7824727bb34 100644 --- a/mod/blti/backup/moodle2/backup_blti_stepslib.php +++ b/mod/lti/backup/moodle2/backup_lti_stepslib.php @@ -32,9 +32,9 @@ /** * This file contains all the backup steps that will be used - * by the backup_blti_activity_task + * by the backup_lti_activity_task * - * @package blti + * @package lti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -47,13 +47,13 @@ */ /** - * Define all the backup steps that will be used by the backup_blti_activity_task + * Define all the backup steps that will be used by the backup_lti_activity_task */ /** * Define the complete assignment structure for backup, with file and id annotations */ -class backup_blti_activity_structure_step extends backup_activity_structure_step { +class backup_lti_activity_structure_step extends backup_activity_structure_step { protected function define_structure() { @@ -61,7 +61,7 @@ class backup_blti_activity_structure_step extends backup_activity_structure_step $userinfo = $this->get_setting_value('userinfo'); // Define each element separated - $basiclti = new backup_nested_element('blti', array('id'), array( + $basiclti = new backup_nested_element('lti', array('id'), array( 'name', 'intro', 'introformat', 'timecreated', 'timemodified', 'typeid', 'toolurl', 'preferheight', 'instructorchoiccesendname', 'instructorchoicesendemailaddr', 'organizationid', @@ -73,13 +73,13 @@ class backup_blti_activity_structure_step extends backup_activity_structure_step // (none) // Define sources - $basiclti->set_source_table('blti', array('id' => backup::VAR_ACTIVITYID)); + $basiclti->set_source_table('lti', array('id' => backup::VAR_ACTIVITYID)); // Define id annotations // (none) // Define file annotations - $basiclti->annotate_files('mod_blti', 'intro', null); // This file areas haven't itemid + $basiclti->annotate_files('mod_lti', 'intro', null); // This file areas haven't itemid // Return the root element (basiclti), wrapped into standard activity structure return $this->prepare_activity_structure($basiclti); diff --git a/mod/blti/backup/moodle2/restore_blti_activity_task.class.php b/mod/lti/backup/moodle2/restore_lti_activity_task.class.php similarity index 81% rename from mod/blti/backup/moodle2/restore_blti_activity_task.class.php rename to mod/lti/backup/moodle2/restore_lti_activity_task.class.php index 9aeea107911..1c383310fa7 100644 --- a/mod/blti/backup/moodle2/restore_blti_activity_task.class.php +++ b/mod/lti/backup/moodle2/restore_lti_activity_task.class.php @@ -33,7 +33,7 @@ /** * This file contains the basicLTI module restore class * - * @package blti + * @package lti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -46,13 +46,13 @@ */ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->dirroot . '/mod/blti/backup/moodle2/restore_blti_stepslib.php'); // Because it exists (must) +require_once($CFG->dirroot . '/mod/lti/backup/moodle2/restore_lti_stepslib.php'); // Because it exists (must) /** * basiclti restore task that provides all the settings and steps to perform one * complete restore of the activity */ -class restore_blti_activity_task extends restore_activity_task { +class restore_lti_activity_task extends restore_activity_task { /** * Define (add) particular settings this activity can have @@ -66,7 +66,7 @@ class restore_blti_activity_task extends restore_activity_task { */ protected function define_my_steps() { // label only has one structure step - $this->add_step(new restore_blti_activity_structure_step('blti_structure', 'blti.xml')); + $this->add_step(new restore_lti_activity_structure_step('lti_structure', 'lti.xml')); } /** @@ -76,7 +76,7 @@ class restore_blti_activity_task extends restore_activity_task { static public function define_decode_contents() { $contents = array(); - $contents[] = new restore_decode_content('blti', array('intro'), 'blti'); + $contents[] = new restore_decode_content('lti', array('intro'), 'lti'); return $contents; } @@ -88,8 +88,8 @@ class restore_blti_activity_task extends restore_activity_task { static public function define_decode_rules() { $rules = array(); - $rules[] = new restore_decode_rule('BLTIVIEWBYID', '/mod/blti/view.php?id=$1', 'course_module'); - $rules[] = new restore_decode_rule('BLTIINDEX', '/mod/blti/index.php?id=$1', 'course'); + $rules[] = new restore_decode_rule('LTIVIEWBYID', '/mod/lti/view.php?id=$1', 'course_module'); + $rules[] = new restore_decode_rule('LTIINDEX', '/mod/lti/index.php?id=$1', 'course'); return $rules; @@ -104,9 +104,9 @@ class restore_blti_activity_task extends restore_activity_task { static public function define_restore_log_rules() { $rules = array(); - $rules[] = new restore_log_rule('blti', 'add', 'view.php?id={course_module}', '{blti}'); - $rules[] = new restore_log_rule('blti', 'update', 'view.php?id={course_module}', '{blti}'); - $rules[] = new restore_log_rule('blti', 'view', 'view.php?id={course_module}', '{blti}'); + $rules[] = new restore_log_rule('lti', 'add', 'view.php?id={course_module}', '{lti}'); + $rules[] = new restore_log_rule('lti', 'update', 'view.php?id={course_module}', '{lti}'); + $rules[] = new restore_log_rule('lti', 'view', 'view.php?id={course_module}', '{lti}'); return $rules; } @@ -124,7 +124,7 @@ class restore_blti_activity_task extends restore_activity_task { static public function define_restore_log_rules_for_course() { $rules = array(); - $rules[] = new restore_log_rule('blti', 'view all', 'index.php?id={course}', null); + $rules[] = new restore_log_rule('lti', 'view all', 'index.php?id={course}', null); return $rules; } diff --git a/mod/blti/backup/moodle2/restore_blti_stepslib.php b/mod/lti/backup/moodle2/restore_lti_stepslib.php similarity index 87% rename from mod/blti/backup/moodle2/restore_blti_stepslib.php rename to mod/lti/backup/moodle2/restore_lti_stepslib.php index 25a474eda32..2fe5082979a 100644 --- a/mod/blti/backup/moodle2/restore_blti_stepslib.php +++ b/mod/lti/backup/moodle2/restore_lti_stepslib.php @@ -35,7 +35,7 @@ * This file contains all the restore steps that will be used * by the restore_basiclti_activity_task * - * @package blti + * @package lti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -54,18 +54,18 @@ /** * Structure step to restore one basiclti activity */ -class restore_blti_activity_structure_step extends restore_activity_structure_step { +class restore_lti_activity_structure_step extends restore_activity_structure_step { protected function define_structure() { $paths = array(); - $paths[] = new restore_path_element('blti', '/activity/blti'); + $paths[] = new restore_path_element('lti', '/activity/lti'); // Return the paths wrapped into standard activity structure return $this->prepare_activity_structure($paths); } - protected function process_blti($data) { + protected function process_lti($data) { global $DB; $data = (object)$data; @@ -73,7 +73,7 @@ class restore_blti_activity_structure_step extends restore_activity_structure_st $data->course = $this->get_courseid(); // insert the basiclti record - $newitemid = $DB->insert_record('blti', $data); + $newitemid = $DB->insert_record('lti', $data); // immediately after inserting "activity" record, call this $this->apply_activity_instance($newitemid); } @@ -81,9 +81,9 @@ class restore_blti_activity_structure_step extends restore_activity_structure_st protected function after_execute() { global $DB; - $basicltis = $DB->get_records('blti'); + $basicltis = $DB->get_records('lti'); foreach ($basicltis as $basiclti) { - if (!$DB->get_record('blti_types_config', + if (!$DB->get_record('lti_types_config', array('typeid' => $basiclti->typeid, 'name' => 'toolurl', 'value' => $basiclti->toolurl))) { $basiclti->typeid = 0; @@ -92,10 +92,10 @@ class restore_blti_activity_structure_step extends restore_activity_structure_st $basiclti->placementsecret = uniqid('', true); $basiclti->timeplacementsecret = time(); - $DB->update_record('blti', $basiclti); + $DB->update_record('lti', $basiclti); } // Add basiclti related files, no need to match by itemname (just internally handled context) - $this->add_related_files('mod_blti', 'intro', null); + $this->add_related_files('mod_lti', 'intro', null); } } diff --git a/mod/blti/basiclti.js b/mod/lti/basiclti.js similarity index 99% rename from mod/blti/basiclti.js rename to mod/lti/basiclti.js index 5b0673cc7c3..b211a5196ff 100644 --- a/mod/blti/basiclti.js +++ b/mod/lti/basiclti.js @@ -32,7 +32,7 @@ /** * This file contains a library of javasxript functions for the BasicLTI module * - * @package blti + * @package lti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu diff --git a/mod/blti/db/access.php b/mod/lti/db/access.php similarity index 90% rename from mod/blti/db/access.php rename to mod/lti/db/access.php index 6188180db66..cfedb54f5a4 100644 --- a/mod/blti/db/access.php +++ b/mod/lti/db/access.php @@ -1,6 +1,6 @@ array( + 'mod/ltii:view' => array( 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, @@ -57,7 +57,7 @@ $capabilities = array( ) ), - 'mod/blti:grade' => array( + 'mod/lti:grade' => array( 'riskbitmask' => RISK_XSS, 'captype' => 'write', diff --git a/mod/blti/db/install.xml b/mod/lti/db/install.xml similarity index 94% rename from mod/blti/db/install.xml rename to mod/lti/db/install.xml index 2fb59755d75..14e77cc4692 100644 --- a/mod/blti/db/install.xml +++ b/mod/lti/db/install.xml @@ -1,10 +1,10 @@ - - +
@@ -34,7 +34,7 @@
- +
@@ -55,7 +55,7 @@
- +
diff --git a/mod/blti/db/log.php b/mod/lti/db/log.php similarity index 100% rename from mod/blti/db/log.php rename to mod/lti/db/log.php diff --git a/mod/blti/db/upgrade.php b/mod/lti/db/upgrade.php similarity index 92% rename from mod/blti/db/upgrade.php rename to mod/lti/db/upgrade.php index d8c8b505b39..ed0531f3a44 100644 --- a/mod/blti/db/upgrade.php +++ b/mod/lti/db/upgrade.php @@ -33,7 +33,7 @@ /** * This file keeps track of upgrades to the basiclti module * - * @package blti + * @package lti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -47,7 +47,7 @@ /** - * xmldb_blti_upgrade is the function that upgrades Moodle's + * xmldb_lti_upgrade is the function that upgrades Moodle's * database when is needed * * This function is automaticly called when version number in @@ -58,7 +58,7 @@ * @return boolean */ -function xmldb_blti_upgrade($oldversion=0) { +function xmldb_lti_upgrade($oldversion=0) { global $DB; diff --git a/mod/blti/edit_form.php b/mod/lti/edit_form.php similarity index 75% rename from mod/blti/edit_form.php rename to mod/lti/edit_form.php index ef1e7da79be..85a9837489c 100644 --- a/mod/blti/edit_form.php +++ b/mod/lti/edit_form.php @@ -33,7 +33,7 @@ /** * This file defines de main basiclti configuration form * - * @package blti + * @package lti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -50,100 +50,100 @@ defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir.'/formslib.php'); -class mod_blti_edit_types_form extends moodleform{ +class mod_lti_edit_types_form extends moodleform{ function definition() { $mform =& $this->_form; //------------------------------------------------------------------------------- // Add basiclti elements - $mform->addElement('header', 'setup', get_string('tool_settings', 'blti')); + $mform->addElement('header', 'setup', get_string('tool_settings', 'lti')); - $mform->addElement('text', 'lti_typename', get_string('typename', 'blti')); + $mform->addElement('text', 'lti_typename', get_string('typename', 'lti')); $mform->setType('lti_typename', PARAM_INT); -// $mform->addHelpButton('lti_typename', 'typename','blti'); +// $mform->addHelpButton('lti_typename', 'typename','lti'); $mform->addRule('lti_typename', null, 'required', null, 'client'); $regex = '/^(http|https):\/\/([a-z0-9-]\.+)*/i'; - $mform->addElement('text', 'lti_toolurl', get_string('toolurl', 'blti'), array('size'=>'64')); + $mform->addElement('text', 'lti_toolurl', get_string('toolurl', 'lti'), array('size'=>'64')); $mform->setType('lti_toolurl', PARAM_TEXT); -// $mform->addHelpButton('lti_toolurl', 'toolurl', 'blti'); - $mform->addRule('lti_toolurl', get_string('validurl', 'blti'), 'regex', $regex, 'client'); +// $mform->addHelpButton('lti_toolurl', 'toolurl', 'lti'); + $mform->addRule('lti_toolurl', get_string('validurl', 'lti'), 'regex', $regex, 'client'); $mform->addRule('lti_toolurl', null, 'required', null, 'client'); - $mform->addElement('text', 'lti_resourcekey', get_string('resourcekey', 'blti')); + $mform->addElement('text', 'lti_resourcekey', get_string('resourcekey', 'lti')); $mform->setType('lti_resourcekey', PARAM_TEXT); - $mform->addElement('passwordunmask', 'lti_password', get_string('password', 'blti')); + $mform->addElement('passwordunmask', 'lti_password', get_string('password', 'lti')); $mform->setType('lti_password', PARAM_TEXT); - $mform->addElement('textarea', 'lti_customparameters', get_string('custom', 'blti'), array('rows'=>4, 'cols'=>60)); + $mform->addElement('textarea', 'lti_customparameters', get_string('custom', 'lti'), array('rows'=>4, 'cols'=>60)); $mform->setType('lti_customparameters', PARAM_TEXT); - $mform->addElement('checkbox', 'lti_coursevisible', ' ', ' ' . get_string('show_in_course', 'blti')); + $mform->addElement('checkbox', 'lti_coursevisible', ' ', ' ' . get_string('show_in_course', 'lti')); $launchoptions=array(); - $launchoptions[BLTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'blti'); - $launchoptions[BLTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'blti'); - $launchoptions[BLTI_LAUNCH_CONTAINER_WINDOW] = get_string('new_window', 'blti'); + $launchoptions[LTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'lti'); + $launchoptions[LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'lti'); + $launchoptions[LTI_LAUNCH_CONTAINER_WINDOW] = get_string('new_window', 'lti'); - $mform->addElement('select', 'lti_launchcontainer', get_string('default_launch_container', 'blti'), $launchoptions); - $mform->setDefault('lti_launchcontainer', BLTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS); -// $mform->addHelpButton('lti_launchinpopup', 'launchinpopup', 'blti'); + $mform->addElement('select', 'lti_launchcontainer', get_string('default_launch_container', 'lti'), $launchoptions); + $mform->setDefault('lti_launchcontainer', LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS); +// $mform->addHelpButton('lti_launchinpopup', 'launchinpopup', 'lti'); // Add privacy preferences fieldset where users choose whether to send their data - $mform->addElement('header', 'privacy', get_string('privacy', 'blti')); + $mform->addElement('header', 'privacy', get_string('privacy', 'lti')); $options=array(); - $options[0] = get_string('never', 'blti'); - $options[1] = get_string('always', 'blti'); - $options[2] = get_string('delegate_yes', 'blti'); - $options[3] = get_string('delegate_no', 'blti'); + $options[0] = get_string('never', 'lti'); + $options[1] = get_string('always', 'lti'); + $options[2] = get_string('delegate_yes', 'lti'); + $options[3] = get_string('delegate_no', 'lti'); - $mform->addElement('select', 'lti_sendname', get_string('sendname', 'blti'), $options); + $mform->addElement('select', 'lti_sendname', get_string('sendname', 'lti'), $options); $mform->setDefault('lti_sendname', '2'); -// $mform->addHelpButton('lti_sendname', 'sendname', 'blti'); +// $mform->addHelpButton('lti_sendname', 'sendname', 'lti'); - $mform->addElement('select', 'lti_sendemailaddr', get_string('sendemailaddr', 'blti'), $options); + $mform->addElement('select', 'lti_sendemailaddr', get_string('sendemailaddr', 'lti'), $options); $mform->setDefault('lti_sendemailaddr', '2'); -// $mform->addHelpButton('lti_sendemailaddr', 'sendemailaddr', 'blti'); +// $mform->addHelpButton('lti_sendemailaddr', 'sendemailaddr', 'lti'); //------------------------------------------------------------------------------- - // BLTI Extensions + // LTI Extensions // Add grading preferences fieldset where the tool is allowed to return grades - $mform->addElement('select', 'lti_acceptgrades', get_string('acceptgrades', 'blti'), $options); + $mform->addElement('select', 'lti_acceptgrades', get_string('acceptgrades', 'lti'), $options); $mform->setDefault('lti_acceptgrades', '2'); -// $mform->addHelpButton('lti_acceptgrades', 'acceptgrades', 'blti'); +// $mform->addHelpButton('lti_acceptgrades', 'acceptgrades', 'lti'); // Add grading preferences fieldset where the tool is allowed to retrieve rosters - $mform->addElement('select', 'lti_allowroster', get_string('allowroster', 'blti'), $options); + $mform->addElement('select', 'lti_allowroster', get_string('allowroster', 'lti'), $options); $mform->setDefault('lti_allowroster', '2'); -// $mform->addHelpButton('lti_allowroster', 'allowroster', 'blti'); +// $mform->addHelpButton('lti_allowroster', 'allowroster', 'lti'); //------------------------------------------------------------------------------- // Add setup parameters fieldset - $mform->addElement('header', 'setupoptions', get_string('miscellaneous', 'blti')); + $mform->addElement('header', 'setupoptions', get_string('miscellaneous', 'lti')); // Adding option to change id that is placed in context_id $idoptions = array(); - $idoptions[0] = get_string('id', 'blti'); - $idoptions[1] = get_string('courseid', 'blti'); + $idoptions[0] = get_string('id', 'lti'); + $idoptions[1] = get_string('courseid', 'lti'); - $mform->addElement('text', 'lti_organizationid', get_string('organizationid', 'blti')); + $mform->addElement('text', 'lti_organizationid', get_string('organizationid', 'lti')); $mform->setType('lti_organizationid', PARAM_TEXT); -// $mform->addHelpButton('lti_organizationid', 'organizationid', 'blti'); +// $mform->addHelpButton('lti_organizationid', 'organizationid', 'lti'); - $mform->addElement('text', 'lti_organizationurl', get_string('organizationurl', 'blti')); + $mform->addElement('text', 'lti_organizationurl', get_string('organizationurl', 'lti')); $mform->setType('lti_organizationurl', PARAM_TEXT); -// $mform->addHelpButton('lti_organizationurl', 'organizationurl', 'blti'); +// $mform->addHelpButton('lti_organizationurl', 'organizationurl', 'lti'); /* Suppress this for now - Chuck - $mform->addElement('text', 'lti_organizationdescr', get_string('organizationdescr', 'blti')); + $mform->addElement('text', 'lti_organizationdescr', get_string('organizationdescr', 'lti')); $mform->setType('lti_organizationdescr', PARAM_TEXT); - $mform->addHelpButton('lti_organizationdescr', 'organizationdescr', 'blti'); + $mform->addHelpButton('lti_organizationdescr', 'organizationdescr', 'lti'); */ //------------------------------------------------------------------------------- diff --git a/mod/blti/index.php b/mod/lti/index.php similarity index 89% rename from mod/blti/index.php rename to mod/lti/index.php index fb2ff0fb5ed..f26503344c6 100644 --- a/mod/blti/index.php +++ b/mod/lti/index.php @@ -33,7 +33,7 @@ /** * This page lists all the instances of basiclti in a particular course * - * @package blti + * @package lti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -45,7 +45,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once("../../config.php"); -require_once($CFG->dirroot.'/mod/blti/lib.php'); +require_once($CFG->dirroot.'/mod/lti/lib.php'); $id = required_param('id', PARAM_INT); // course id @@ -53,25 +53,25 @@ if (! $course = $DB->get_record("course", array("id" => $id))) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course ID is incorrect'); } -$url = new moodle_url('/mod/blti/index.php', array('id'=>$id)); +$url = new moodle_url('/mod/lti/index.php', array('id'=>$id)); $PAGE->set_url($url); $PAGE->set_pagelayout('incourse'); require_login($course); -add_to_log($course->id, "blti", "view all", "index.php?id=$course->id", ""); +add_to_log($course->id, "lti", "view all", "index.php?id=$course->id", ""); -$pagetitle = strip_tags($course->shortname.': '.get_string("modulenamepluralformatted", "blti")); +$pagetitle = strip_tags($course->shortname.': '.get_string("modulenamepluralformatted", "lti")); $PAGE->set_title($pagetitle); $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); /// Print the main part of the page -echo $OUTPUT->heading(get_string("modulenamepluralformatted", "blti")); +echo $OUTPUT->heading(get_string("modulenamepluralformatted", "lti")); /// Get all the appropriate data -if (! $basicltis = get_all_instances_in_course("blti", $course)) { +if (! $basicltis = get_all_instances_in_course("lti", $course)) { notice("There are no basicltis", "../../course/view.php?id=$course->id"); die; } diff --git a/mod/blti/lang/en/help/basiclti/index.html b/mod/lti/lang/en/help/basiclti/index.html similarity index 100% rename from mod/blti/lang/en/help/basiclti/index.html rename to mod/lti/lang/en/help/basiclti/index.html diff --git a/mod/blti/lang/en/help/basiclti/mods.html b/mod/lti/lang/en/help/basiclti/mods.html similarity index 100% rename from mod/blti/lang/en/help/basiclti/mods.html rename to mod/lti/lang/en/help/basiclti/mods.html diff --git a/mod/blti/lang/en/blti.php b/mod/lti/lang/en/lti.php similarity index 97% rename from mod/blti/lang/en/blti.php rename to mod/lti/lang/en/lti.php index d607cc88959..e0caae84a23 100644 --- a/mod/blti/lang/en/blti.php +++ b/mod/lti/lang/en/lti.php @@ -56,7 +56,7 @@ $string['allowinstructorcustom'] = 'Allow instructors to add custom parameters'; $string['allowroster'] = 'Tool may access course roster'; $string['allowsetting'] = 'Allow tool to store 8K of settings in Moodle'; $string['always'] = 'Always'; -$string['blti'] = 'Basic LTI'; +$string['lti'] = 'Basic LTI'; $string['basiclti'] = 'Basic LTI'; $string['basiclti_base_string'] = 'Basic LTI OAuth Base String'; $string['basiclti_in_new_window'] = 'Your activity has opened in a new window'; @@ -131,7 +131,7 @@ $string['organizationurl'] ='Organization URL'; $string['pagesize'] = 'Submissions shown per page'; $string['password'] = 'Shared Secret'; $string['pluginadministration'] = 'Basic LTI administration'; -$string['pluginname'] = 'BLTI'; +$string['pluginname'] = 'LTI'; $string['preferheight'] = 'Preferred Height'; $string['preferwidget'] = 'Prefer Widget Launch'; $string['preferwidth'] = 'Preferred Width'; diff --git a/mod/blti/launch.php b/mod/lti/launch.php similarity index 86% rename from mod/blti/launch.php rename to mod/lti/launch.php index 42769b63e41..9a7c5cf002c 100644 --- a/mod/blti/launch.php +++ b/mod/lti/launch.php @@ -33,7 +33,7 @@ /** * This file contains all necessary code to view a basiclti activity instance * - * @package blti + * @package lti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -46,8 +46,8 @@ */ require_once("../../config.php"); -require_once($CFG->dirroot.'/mod/blti/lib.php'); -require_once($CFG->dirroot.'/mod/blti/locallib.php'); +require_once($CFG->dirroot.'/mod/lti/lib.php'); +require_once($CFG->dirroot.'/mod/lti/locallib.php'); $id = optional_param('id', 0, PARAM_INT); // Course Module ID, or $object = optional_param('withobject', false, PARAM_BOOL); // Launch BasicLTI in an object @@ -61,25 +61,25 @@ if ($id) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured'); } - if (! $basiclti = $DB->get_record("blti", array("id" => $cm->instance))) { + if (! $basiclti = $DB->get_record("lti", array("id" => $cm->instance))) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect'); } } else { - if (! $basiclti = $DB->get_record("blti", array("id" => $a))) { + if (! $basiclti = $DB->get_record("lti", array("id" => $a))) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect'); } if (! $course = $DB->get_record("course", array("id" => $basiclti->course))) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured'); } - if (! $cm = get_coursemodule_from_instance("blti", $basiclti->id, $course->id)) { + if (! $cm = get_coursemodule_from_instance("lti", $basiclti->id, $course->id)) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect'); } } require_login($course); -add_to_log($course->id, "blti", "launch", "launch.php?id=$cm->id", "$basiclti->id"); +add_to_log($course->id, "lti", "launch", "launch.php?id=$cm->id", "$basiclti->id"); -blti_view($basiclti, $object); +lti_view($basiclti, $object); diff --git a/mod/blti/lib.php b/mod/lti/lib.php similarity index 85% rename from mod/blti/lib.php rename to mod/lti/lib.php index 214de3cab06..abb51dd4201 100644 --- a/mod/blti/lib.php +++ b/mod/lti/lib.php @@ -34,7 +34,7 @@ * This file contains a library of functions and constants for the * BasicLTI module * - * @package blti + * @package lti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -48,14 +48,14 @@ defined('MOODLE_INTERNAL') || die; -require_once($CFG->dirroot.'/mod/blti/locallib.php'); +require_once($CFG->dirroot.'/mod/lti/locallib.php'); /** * List of features supported in URL module * @param string $feature FEATURE_xx constant for requested feature * @return mixed True if module supports feature, false if not, null if doesn't know */ -function blti_supports($feature) { +function lti_supports($feature) { switch($feature) { case FEATURE_GROUPS: return false; case FEATURE_GROUPINGS: return false; @@ -79,20 +79,20 @@ function blti_supports($feature) { * @param object $instance An object from the form in mod.html * @return int The id of the newly inserted basiclti record **/ -function blti_add_instance($formdata) { +function lti_add_instance($formdata) { global $DB; $formdata->timecreated = time(); $formdata->timemodified = $formdata->timecreated; //$basiclti->placementsecret = uniqid('', true); //$basiclti->timeplacementsecret = time(); - $id = $DB->insert_record("blti", $formdata); + $id = $DB->insert_record("lti", $formdata); if ($formdata->instructorchoiceacceptgrades == 1) { - $basiclti = $DB->get_record('blti', array('id'=>$id)); + $basiclti = $DB->get_record('lti', array('id'=>$id)); $basiclti->cmidnumber = $formdata->cmidnumber; - blti_grade_item_update($basiclti); + lti_grade_item_update($basiclti); } return $id; @@ -106,7 +106,7 @@ function blti_add_instance($formdata) { * @param object $instance An object from the form in mod.html * @return boolean Success/Fail **/ -function blti_update_instance($formdata) { +function lti_update_instance($formdata) { global $DB; $formdata->timemodified = time(); @@ -121,15 +121,15 @@ function blti_update_instance($formdata) { } if ($formdata->instructorchoiceacceptgrades == 1) { - $basicltirec = $DB->get_record("blti", array("id" => $formdata->id)); + $basicltirec = $DB->get_record("lti", array("id" => $formdata->id)); $basicltirec->cmidnumber = $formdata->cmidnumber; - blti_grade_item_update($basicltirec); + lti_grade_item_update($basicltirec); } else { - blti_grade_item_delete($formdata); + lti_grade_item_delete($formdata); } - return $DB->update_record("blti", $formdata); + return $DB->update_record("lti", $formdata); } /** @@ -140,19 +140,19 @@ function blti_update_instance($formdata) { * @param int $id Id of the module instance * @return boolean Success/Failure **/ -function blti_delete_instance($id) { +function lti_delete_instance($id) { global $DB; - if (! $basiclti = $DB->get_record("blti", array("id" => $id))) { + if (! $basiclti = $DB->get_record("lti", array("id" => $id))) { return false; } $result = true; # Delete any dependent records here # - blti_grade_item_delete($basiclti); + lti_grade_item_delete($basiclti); - return $DB->delete_records("blti", array("id" => $basiclti->id)); + return $DB->delete_records("lti", array("id" => $basiclti->id)); } /** @@ -165,7 +165,7 @@ function blti_delete_instance($id) { * @return null * @TODO: implement this moodle function (if needed) **/ -function blti_user_outline($course, $user, $mod, $basiclti) { +function lti_user_outline($course, $user, $mod, $basiclti) { return $return; } @@ -176,7 +176,7 @@ function blti_user_outline($course, $user, $mod, $basiclti) { * @return boolean * @TODO: implement this moodle function (if needed) **/ -function blti_user_complete($course, $user, $mod, $basiclti) { +function lti_user_complete($course, $user, $mod, $basiclti) { return true; } @@ -189,7 +189,7 @@ function blti_user_complete($course, $user, $mod, $basiclti) { * @return boolean * @TODO: implement this moodle function **/ -function blti_print_recent_activity($course, $isteacher, $timestart) { +function lti_print_recent_activity($course, $isteacher, $timestart) { return false; // True if anything was printed, otherwise false } @@ -201,7 +201,7 @@ function blti_print_recent_activity($course, $isteacher, $timestart) { * @uses $CFG * @return boolean **/ -function blti_cron () { +function lti_cron () { return true; } @@ -220,7 +220,7 @@ function blti_cron () { * * @TODO: implement this moodle function (if needed) **/ -function blti_grades($basicltiid) { +function lti_grades($basicltiid) { return null; } @@ -235,7 +235,7 @@ function blti_grades($basicltiid) { * * @TODO: implement this moodle function **/ -function blti_get_participants($basicltiid) { +function lti_get_participants($basicltiid) { return false; } @@ -250,7 +250,7 @@ function blti_get_participants($basicltiid) { * * @TODO: implement this moodle function (if needed) **/ -function blti_scale_used ($basicltiid, $scaleid) { +function lti_scale_used ($basicltiid, $scaleid) { $return = false; //$rec = get_record("basiclti","id","$basicltiid","scale","-$scaleid"); @@ -271,10 +271,10 @@ function blti_scale_used ($basicltiid, $scaleid) { * @return boolean True if the scale is used by any basiclti * */ -function blti_scale_used_anywhere($scaleid) { +function lti_scale_used_anywhere($scaleid) { global $DB; - if ($scaleid and $DB->record_exists('blti', array('grade' => -$scaleid))) { + if ($scaleid and $DB->record_exists('lti', array('grade' => -$scaleid))) { return true; } else { return false; @@ -287,7 +287,7 @@ function blti_scale_used_anywhere($scaleid) { * * @return boolean true if success, false on error */ -function blti_install() { +function lti_install() { return true; } @@ -297,7 +297,7 @@ function blti_install() { * * @return boolean true if success, false on error */ -function blti_uninstall() { +function lti_uninstall() { return true; } @@ -306,10 +306,10 @@ function blti_uninstall() { * * @return array of basicLTI types */ -function blti_get_blti_types() { +function lti_get_lti_types() { global $DB; - return $DB->get_records('blti_types'); + return $DB->get_records('lti_types'); } /** @@ -317,13 +317,13 @@ function blti_get_blti_types() { * * @return array of basicLTI types */ -/*function blti_get_types() { +/*function lti_get_types() { $types = array(); - $basicltitypes = blti_get_blti_types(); + $basicltitypes = lti_get_lti_types(); if (!empty($basicltitypes)) { foreach ($basicltitypes as $basicltitype) { - $ltitypesconfig = blti_get_type_config($basicltitype->id); + $ltitypesconfig = lti_get_type_config($basicltitype->id); $modclass = MOD_CLASS_ACTIVITY; if (isset($ltitypesconfig['module_class_type'])) { @@ -334,7 +334,7 @@ function blti_get_blti_types() { $type = new object(); $type->modclass = $modclass; - $type->type = 'blti&type='.urlencode($basicltitype->rawname); + $type->type = 'lti&type='.urlencode($basicltitype->rawname); $type->typestr = $basicltitype->name; $types[] = $type; } @@ -390,7 +390,7 @@ function blti_get_blti_types() { * @global object * @param string $mode Specifies the kind of teacher interaction taking place */ -function blti_submissions($cm, $course, $basiclti, $mode) { +function lti_submissions($cm, $course, $basiclti, $mode) { ///The main switch is changed to facilitate ///1) Batch fast grading ///2) Skip to the next one on the popup @@ -410,33 +410,33 @@ function blti_submissions($cm, $course, $basiclti, $mode) { if (is_null($mailinfo)) { if (optional_param('sesskey', null, PARAM_BOOL)) { - set_user_preference('blti_mailinfo', $mailinfo); + set_user_preference('lti_mailinfo', $mailinfo); } else { - $mailinfo = get_user_preferences('blti_mailinfo', 0); + $mailinfo = get_user_preferences('lti_mailinfo', 0); } } else { - set_user_preference('blti_mailinfo', $mailinfo); + set_user_preference('lti_mailinfo', $mailinfo); } switch ($mode) { case 'grade': // We are in a main window grading if ($submission = process_feedback()) { - blti_display_submissions($cm, $course, $basiclti, get_string('changessaved')); + lti_display_submissions($cm, $course, $basiclti, get_string('changessaved')); } else { - blti_display_submissions($cm, $course, $basiclti); + lti_display_submissions($cm, $course, $basiclti); } break; case 'single': // We are in a main window displaying one submission if ($submission = process_feedback()) { - blti_display_submissions($cm, $course, $basiclti, get_string('changessaved')); + lti_display_submissions($cm, $course, $basiclti, get_string('changessaved')); } else { display_submission(); } break; case 'all': // Main window, display everything - blti_display_submissions($cm, $course, $basiclti); + lti_display_submissions($cm, $course, $basiclti); break; case 'fastgrade': @@ -454,7 +454,7 @@ function blti_submissions($cm, $course, $basiclti, $mode) { } if (!$col) { //both submissioncomment and grade columns collapsed.. - blti_display_submissions($cm, $course, $basiclti); + lti_display_submissions($cm, $course, $basiclti); break; } @@ -548,7 +548,7 @@ function blti_submissions($cm, $course, $basiclti, $mode) { } //add to log only if updating - add_to_log($course->id, 'blti', 'update grades', + add_to_log($course->id, 'lti', 'update grades', 'submissions.php?id='.$cm->id.'&user='.$USER->id, $USER->id, $cm->id); } @@ -557,7 +557,7 @@ function blti_submissions($cm, $course, $basiclti, $mode) { $message = $OUTPUT->notification(get_string('changessaved'), 'notifysuccess'); - blti_display_submissions($cm, $course, $basiclti, $message); + lti_display_submissions($cm, $course, $basiclti, $message); break; case 'saveandnext': @@ -600,7 +600,7 @@ function blti_submissions($cm, $course, $basiclti, $mode) { * @param string $message * @return bool|void */ -function blti_display_submissions($cm, $course, $basiclti, $message='') { +function lti_display_submissions($cm, $course, $basiclti, $message='') { global $CFG, $DB, $OUTPUT, $PAGE; require_once($CFG->libdir.'/gradelib.php'); @@ -613,18 +613,18 @@ function blti_display_submissions($cm, $course, $basiclti, $message='') { $perpage = optional_param('perpage', 10, PARAM_INT); $perpage = ($perpage <= 0) ? 10 : $perpage; $filter = optional_param('filter', 0, PARAM_INT); - set_user_preference('blti_perpage', $perpage); - set_user_preference('blti_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL)); - set_user_preference('blti_filter', $filter); + set_user_preference('lti_perpage', $perpage); + set_user_preference('lti_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL)); + set_user_preference('lti_filter', $filter); } /* next we get perpage and quickgrade (allow quick grade) params * from database */ - $perpage = get_user_preferences('blti_perpage', 10); - $quickgrade = get_user_preferences('blti_quickgrade', 0); - $filter = get_user_preferences('blti_filter', 0); - $grading_info = grade_get_grades($course->id, 'mod', 'blti', $basiclti->id); + $perpage = get_user_preferences('lti_perpage', 10); + $quickgrade = get_user_preferences('lti_quickgrade', 0); + $filter = get_user_preferences('lti_filter', 0); + $grading_info = grade_get_grades($course->id, 'mod', 'lti', $basiclti->id); if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) { $uses_outcomes = true; @@ -633,10 +633,10 @@ function blti_display_submissions($cm, $course, $basiclti, $message='') { } $page = optional_param('page', 0, PARAM_INT); - $strsaveallfeedback = get_string('saveallfeedback', 'blti'); + $strsaveallfeedback = get_string('saveallfeedback', 'lti'); $tabindex = 1; //tabindex for quick grading tabbing; Not working for dropdowns yet - add_to_log($course->id, 'blti', 'view submission', 'submissions.php?id='.$cm->id, $basiclti->id, $cm->id); + add_to_log($course->id, 'lti', 'view submission', 'submissions.php?id='.$cm->id, $basiclti->id, $cm->id); $PAGE->set_title(format_string($basiclti->name, true)); $PAGE->set_heading($course->fullname); @@ -650,7 +650,7 @@ function blti_display_submissions($cm, $course, $basiclti, $message='') { /// Print quickgrade form around the table if ($quickgrade) { $formattrs = array(); - $formattrs['action'] = new moodle_url('/mod/blti/submissions.php'); + $formattrs['action'] = new moodle_url('/mod/lti/submissions.php'); $formattrs['id'] = 'fastg'; $formattrs['method'] = 'post'; @@ -678,10 +678,10 @@ function blti_display_submissions($cm, $course, $basiclti, $message='') { /// find out current groups mode $groupmode = groups_get_activity_groupmode($cm); $currentgroup = groups_get_activity_group($cm, true); - groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/blti/submissions.php?id=' . $cm->id); + groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/lti/submissions.php?id=' . $cm->id); /// Get all ppl that are allowed to submit tools - list($esql, $params) = get_enrolled_sql($context, 'mod/blti:view', $currentgroup); + list($esql, $params) = get_enrolled_sql($context, 'mod/lti:view', $currentgroup); $sql = "SELECT u.id FROM {user} u ". "LEFT JOIN ($esql) eu ON eu.id=u.id ". @@ -707,8 +707,8 @@ function blti_display_submissions($cm, $course, $basiclti, $message='') { $tableheaders = array('', get_string('fullname'), get_string('grade'), - get_string('comment', 'blti'), - get_string('lastmodified').' ('.get_string('submission', 'blti').')', + get_string('comment', 'lti'), + get_string('lastmodified').' ('.get_string('submission', 'lti').')', get_string('lastmodified').' ('.get_string('grade').')', get_string('status'), get_string('finalgrade', 'grades')); @@ -717,11 +717,11 @@ function blti_display_submissions($cm, $course, $basiclti, $message='') { } require_once($CFG->libdir.'/tablelib.php'); - $table = new flexible_table('mod-blti-submissions'); + $table = new flexible_table('mod-lti-submissions'); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); - $table->define_baseurl($CFG->wwwroot.'/mod/blti/submissions.php?id='.$cm->id.'&currentgroup='.$currentgroup); + $table->define_baseurl($CFG->wwwroot.'/mod/lti/submissions.php?id='.$cm->id.'&currentgroup='.$currentgroup); $table->sortable(true, 'lastname');//sorted by lastname by default $table->collapsible(true); @@ -754,7 +754,7 @@ function blti_display_submissions($cm, $course, $basiclti, $message='') { $table->setup(); if (empty($users)) { - echo $OUTPUT->heading(get_string('noviewusers', 'blti')); + echo $OUTPUT->heading(get_string('noviewusers', 'lti')); echo ''; return true; } @@ -793,7 +793,7 @@ function blti_display_submissions($cm, $course, $basiclti, $message='') { $strgrade = get_string('grade'); $grademenu = make_grades_menu($basiclti->grade); if ($ausers !== false) { - $grading_info = grade_get_grades($course->id, 'mod', 'blti', $basiclti->id, array_keys($ausers)); + $grading_info = grade_get_grades($course->id, 'mod', 'lti', $basiclti->id, array_keys($ausers)); $endposition = $offset + $perpage; $currentposition = 0; foreach ($ausers as $auser) { @@ -866,7 +866,7 @@ function blti_display_submissions($cm, $course, $basiclti, $message='') { $buttontext = ($auser->status == 1) ? $strupdate : $strgrade; ///No more buttons, we use popups ;-). - $popup_url = '/mod/blti/submissions.php?id='.$cm->id + $popup_url = '/mod/lti/submissions.php?id='.$cm->id . '&userid='.$auser->id.'&mode=single'.'&filter='.$filter.'&offset='.$offset++; $button = $OUTPUT->action_link($popup_url, $buttontext); @@ -913,15 +913,15 @@ function blti_display_submissions($cm, $course, $basiclti, $message='') { /// Print quickgrade form around the table if ($quickgrade && $table->started_output) { $mailinfopref = false; - if (get_user_preferences('blti_mailinfo', 1)) { + if (get_user_preferences('lti_mailinfo', 1)) { $mailinfopref = true; } - $emailnotification = html_writer::checkbox('mailinfo', 1, $mailinfopref, get_string('enableemailnotification', 'blti')); + $emailnotification = html_writer::checkbox('mailinfo', 1, $mailinfopref, get_string('enableemailnotification', 'lti')); - $emailnotification .= $OUTPUT->help_icon('enableemailnotification', 'blti'); + $emailnotification .= $OUTPUT->help_icon('enableemailnotification', 'lti'); echo html_writer::tag('div', $emailnotification, array('class'=>'emailnotification')); - $savefeedback = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'fastg', 'value'=>get_string('saveallfeedback', 'blti'))); + $savefeedback = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'fastg', 'value'=>get_string('saveallfeedback', 'lti'))); echo html_writer::tag('div', $savefeedback, array('class'=>'fastgbutton')); echo html_writer::end_tag('form'); @@ -934,22 +934,22 @@ function blti_display_submissions($cm, $course, $basiclti, $message='') { /// Mini form for setting user preference - $formaction = new moodle_url('/mod/blti/submissions.php', array('id'=>$cm->id)); + $formaction = new moodle_url('/mod/lti/submissions.php', array('id'=>$cm->id)); $mform = new MoodleQuickForm('optionspref', 'post', $formaction, '', array('class'=>'optionspref')); $mform->addElement('hidden', 'updatepref'); $mform->setDefault('updatepref', 1); - $mform->addElement('header', 'qgprefs', get_string('optionalsettings', 'blti')); + $mform->addElement('header', 'qgprefs', get_string('optionalsettings', 'lti')); // $mform->addElement('select', 'filter', get_string('show'), $filters); $mform->setDefault('filter', $filter); - $mform->addElement('text', 'perpage', get_string('pagesize', 'blti'), array('size'=>1)); + $mform->addElement('text', 'perpage', get_string('pagesize', 'lti'), array('size'=>1)); $mform->setDefault('perpage', $perpage); - $mform->addElement('checkbox', 'quickgrade', get_string('quickgrade', 'blti')); + $mform->addElement('checkbox', 'quickgrade', get_string('quickgrade', 'lti')); $mform->setDefault('quickgrade', $quickgrade); - $mform->addHelpButton('quickgrade', 'quickgrade', 'blti'); + $mform->addHelpButton('quickgrade', 'quickgrade', 'lti'); $mform->addElement('submit', 'savepreferences', get_string('savepreferences')); @@ -965,7 +965,7 @@ function blti_display_submissions($cm, $course, $basiclti, $message='') { * @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook * @return int 0 if ok, error code otherwise */ -function blti_grade_item_update($basiclti, $grades=null) { +function lti_grade_item_update($basiclti, $grades=null) { global $CFG; require_once($CFG->libdir.'/gradelib.php'); @@ -989,7 +989,7 @@ function blti_grade_item_update($basiclti, $grades=null) { $grades = null; } - return grade_update('mod/blti', $basiclti->course, 'mod', 'blti', $basiclti->id, 0, $grades, $params); + return grade_update('mod/lti', $basiclti->course, 'mod', 'lti', $basiclti->id, 0, $grades, $params); } /** @@ -998,10 +998,10 @@ function blti_grade_item_update($basiclti, $grades=null) { * @param object $basiclti object * @return object basiclti */ -function blti_grade_item_delete($basiclti) { +function lti_grade_item_delete($basiclti) { global $CFG; require_once($CFG->libdir.'/gradelib.php'); - return grade_update('mod/blti', $basiclti->course, 'mod', 'blti', $basiclti->id, 0, null, array('deleted'=>1)); + return grade_update('mod/lti', $basiclti->course, 'mod', 'lti', $basiclti->id, 0, null, array('deleted'=>1)); } diff --git a/mod/blti/localadminlib.php b/mod/lti/localadminlib.php similarity index 89% rename from mod/blti/localadminlib.php rename to mod/lti/localadminlib.php index 4ccb940da7f..54379d2e4b7 100644 --- a/mod/blti/localadminlib.php +++ b/mod/lti/localadminlib.php @@ -34,7 +34,7 @@ * This file contains some functions and classes used in Basic LTI * module administration * - * @package blti + * @package lti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -54,7 +54,7 @@ require_once($CFG->libdir.'/adminlib.php'); * * @TODO: finish doc this class and it's functions */ -class admin_setting_bltimodule_configlink extends admin_setting { +class admin_setting_ltimodule_configlink extends admin_setting { /** * Constructor @@ -62,7 +62,7 @@ class admin_setting_bltimodule_configlink extends admin_setting { * @param string $visiblename localised * @param string $description long localised info */ - function admin_setting_bltimodule_configlink($name, $visiblename, $description) { + function admin_setting_ltimodule_configlink($name, $visiblename, $description) { parent::__construct($name, $visiblename, $description, ''); } @@ -78,7 +78,7 @@ class admin_setting_bltimodule_configlink extends admin_setting { global $CFG; return format_admin_setting($this, "", '', $this->description, true, '', null, $query); } diff --git a/mod/blti/locallib.php b/mod/lti/locallib.php similarity index 82% rename from mod/blti/locallib.php rename to mod/lti/locallib.php index a7e6eb34a36..afdc4ec1c60 100644 --- a/mod/blti/locallib.php +++ b/mod/lti/locallib.php @@ -33,7 +33,7 @@ /** * This file contains the library of functions and constants for the basiclti module * - * @package blti + * @package lti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -47,25 +47,25 @@ defined('MOODLE_INTERNAL') || die; -require_once($CFG->dirroot.'/mod/blti/OAuth.php'); +require_once($CFG->dirroot.'/mod/lti/OAuth.php'); -define('BLTI_URL_DOMAIN_REGEX', '/(?:https?:\/\/)?(?:www\.)?([^\/]+)(?:\/|$)/i'); +define('LTI_URL_DOMAIN_REGEX', '/(?:https?:\/\/)?(?:www\.)?([^\/]+)(?:\/|$)/i'); -define('BLTI_LAUNCH_CONTAINER_DEFAULT', 1); -define('BLTI_LAUNCH_CONTAINER_EMBED', 2); -define('BLTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS', 3); -define('BLTI_LAUNCH_CONTAINER_WINDOW', 4); +define('LTI_LAUNCH_CONTAINER_DEFAULT', 1); +define('LTI_LAUNCH_CONTAINER_EMBED', 2); +define('LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS', 3); +define('LTI_LAUNCH_CONTAINER_WINDOW', 4); /** * Prints a Basic LTI activity * * $param int $basicltiid Basic LTI activity id */ -function blti_view($instance, $makeobject=false) { +function lti_view($instance, $makeobject=false) { global $PAGE; if(empty($instance->typeid)){ - $tool = blti_get_tool_by_url_match($instance->toolurl); + $tool = lti_get_tool_by_url_match($instance->toolurl); if($tool){ $typeid = $tool->id; } else { @@ -75,7 +75,7 @@ function blti_view($instance, $makeobject=false) { $typeid = $instance->typeid; } - $typeconfig = blti_get_type_config($typeid); + $typeconfig = lti_get_type_config($typeid); $endpoint = !empty($instance->toolurl) ? $instance->toolurl : $typeconfig['toolurl']; $key = !empty($instance->resourcekey) ? $instance->resourcekey : $typeconfig['resourcekey']; $secret = !empty($instance->password) ? $instance->password : $typeconfig['password']; @@ -85,7 +85,7 @@ function blti_view($instance, $makeobject=false) { */ $course = $PAGE->course; - $requestparams = blti_build_request($instance, $typeconfig, $course); + $requestparams = lti_build_request($instance, $typeconfig, $course); // Make sure we let the tool know what LMS they are being called from $requestparams["ext_lms"] = "moodle-2"; @@ -93,14 +93,14 @@ function blti_view($instance, $makeobject=false) { // Add oauth_callback to be compliant with the 1.0A spec $requestparams["oauth_callback"] = "about:blank"; - $submittext = get_string('press_to_submit', 'blti'); + $submittext = get_string('press_to_submit', 'lti'); $parms = sign_parameters($requestparams, $endpoint, "POST", $key, $secret, $submittext, $orgid /*, $orgdesc*/); $debuglaunch = ( $instance->debuglaunch == 1 ); $content = post_launch_html($parms, $endpoint, $debuglaunch); -// $cm = get_coursemodule_from_instance("blti", $instance->id); +// $cm = get_coursemodule_from_instance("lti", $instance->id); // print ''.$content.''; echo $content; } @@ -114,11 +114,11 @@ function blti_view($instance, $makeobject=false) { * * @return array $request Request details */ -function blti_build_request($instance, $typeconfig, $course) { +function lti_build_request($instance, $typeconfig, $course) { global $USER, $CFG; $context = get_context_instance(CONTEXT_COURSE, $course->id); - $role = blti_get_ims_role($USER, $context); + $role = lti_get_ims_role($USER, $context); $locale = $course->lang; if ( strlen($locale) < 1 ) { @@ -149,14 +149,14 @@ function blti_build_request($instance, $typeconfig, $course) { ( $typeconfig['acceptgrades'] == 1 || ( $typeconfig['acceptgrades'] == 2 && $instance->instructorchoiceacceptgrades == 1 ) ) ) { $requestparams["lis_result_sourcedid"] = $sourcedid; - $requestparams["ext_ims_lis_basic_outcome_url"] = $CFG->wwwroot.'/mod/blti/service.php'; + $requestparams["ext_ims_lis_basic_outcome_url"] = $CFG->wwwroot.'/mod/lti/service.php'; } if ( isset($placementsecret) && ( $typeconfig['allowroster'] == 1 || ( $typeconfig['allowroster'] == 2 && $instance->instructorchoiceallowroster == 1 ) ) ) { $requestparams["ext_ims_lis_memberships_id"] = $sourcedid; - $requestparams["ext_ims_lis_memberships_url"] = $CFG->wwwroot.'/mod/blti/service.php'; + $requestparams["ext_ims_lis_memberships_url"] = $CFG->wwwroot.'/mod/lti/service.php'; } // Send user's name and email data if appropriate @@ -260,7 +260,7 @@ function map_keyname($key) { * @return string IMS Role * */ -function blti_get_ims_role($user, $context) { +function lti_get_ims_role($user, $context) { $roles = get_user_roles($context, $user->id); $rolesname = array(); @@ -269,14 +269,14 @@ function blti_get_ims_role($user, $context) { } if (in_array('admin', $rolesname) || in_array('coursecreator', $rolesname)) { - return get_string('imsroleadmin', 'blti'); + return get_string('imsroleadmin', 'lti'); } if (in_array('editingteacher', $rolesname) || in_array('teacher', $rolesname)) { - return get_string('imsroleinstructor', 'blti'); + return get_string('imsroleinstructor', 'lti'); } - return get_string('imsrolelearner', 'blti'); + return get_string('imsrolelearner', 'lti'); } /** @@ -286,11 +286,11 @@ function blti_get_ims_role($user, $context) { * * @return array Tool Configuration */ -function blti_get_type_config($typeid) { +function lti_get_type_config($typeid) { global $DB; $typeconfig = array(); - $configs = $DB->get_records('blti_types_config', array('typeid' => $typeid)); + $configs = $DB->get_records('lti_types_config', array('typeid' => $typeid)); if (!empty($configs)) { foreach ($configs as $config) { $typeconfig[$config->name] = $config->value; @@ -299,28 +299,28 @@ function blti_get_type_config($typeid) { return $typeconfig; } -function blti_get_tools_by_domain($domain){ +function lti_get_tools_by_domain($domain){ global $DB; - return $DB->get_records('blti_types', array('tooldomain' => $domain)); + return $DB->get_records('lti_types', array('tooldomain' => $domain)); } /** * Returns all basicLTI tools configured by the administrator * */ -function blti_filter_get_types() { +function lti_filter_get_types() { global $DB; - return $DB->get_records('blti_types'); + return $DB->get_records('lti_types'); } -function blti_get_types_for_add_instance(){ +function lti_get_types_for_add_instance(){ global $DB; - $admintypes = $DB->get_records('blti_types', array('coursevisible' => 1)); + $admintypes = $DB->get_records('lti_types', array('coursevisible' => 1)); $types = array(); - $types[0] = get_string('automatic', 'blti'); + $types[0] = get_string('automatic', 'lti'); foreach($admintypes as $type) { $types[$type->id] = $type->name; @@ -329,23 +329,23 @@ function blti_get_types_for_add_instance(){ return $types; } -function blti_get_domain_from_url($url){ +function lti_get_domain_from_url($url){ $matches = array(); - if(preg_match(BLTI_URL_DOMAIN_REGEX, $url, $matches)){ + if(preg_match(LTI_URL_DOMAIN_REGEX, $url, $matches)){ return $matches[1]; } } -function blti_get_tool_by_url_match($url){ - $domain = blti_get_domain_from_url($url); +function lti_get_tool_by_url_match($url){ + $domain = lti_get_domain_from_url($url); - $possibletools = blti_get_tools_by_domain($domain); + $possibletools = lti_get_tools_by_domain($domain); - return blti_get_best_tool_by_url($url, $possibletools); + return lti_get_best_tool_by_url($url, $possibletools); } -function blti_get_best_tool_by_url($url, $tools){ +function lti_get_best_tool_by_url($url, $tools){ if(count($tools) === 0){ return null; } @@ -380,10 +380,10 @@ function blti_get_best_tool_by_url($url, $tools){ * Prints the various configured tool types * */ -function blti_filter_print_types() { +function lti_filter_print_types() { global $CFG; - $types = blti_filter_get_types(); + $types = lti_filter_get_types(); if (!empty($types)) { echo '
    '; foreach ($types as $type) { @@ -403,7 +403,7 @@ function blti_filter_print_types() { echo '
'; } else { echo '
'; - echo get_string('notypes', 'blti'); + echo get_string('notypes', 'lti'); echo '
'; } } @@ -413,30 +413,30 @@ function blti_filter_print_types() { * * @param int $id Configuration id */ -function blti_delete_type($id) { +function lti_delete_type($id) { global $DB; - $instances = $DB->get_records('blti', array('typeid' => $id)); + $instances = $DB->get_records('lti', array('typeid' => $id)); foreach ($instances as $instance) { $instance->typeid = 0; - $DB->update_record('blti', $instance); + $DB->update_record('lti', $instance); } - $DB->delete_records('blti_types', array('id' => $id)); - $DB->delete_records('blti_types_config', array('typeid' => $id)); + $DB->delete_records('lti_types', array('id' => $id)); + $DB->delete_records('lti_types_config', array('typeid' => $id)); } /** * Transforms a basic LTI object to an array * - * @param object $bltiobject Basic LTI object + * @param object $ltiobject Basic LTI object * * @return array Basic LTI configuration details */ -function blti_get_config($bltiobject) { +function lti_get_config($ltiobject) { $typeconfig = array(); - $typeconfig = (array)$bltiobject; - $additionalconfig = blti_get_type_config($bltiobject->typeid); + $typeconfig = (array)$ltiobject; + $additionalconfig = lti_get_type_config($ltiobject->typeid); $typeconfig = array_merge($typeconfig, $additionalconfig); return $typeconfig; } @@ -450,11 +450,11 @@ function blti_get_config($bltiobject) { * @return Instance configuration * */ -function blti_get_type_config_from_instance($id) { +function lti_get_type_config_from_instance($id) { global $DB; - $instance = $DB->get_record('blti', array('id' => $id)); - $config = blti_get_config($instance); + $instance = $DB->get_record('lti', array('id' => $id)); + $config = lti_get_config($instance); $type = new stdClass(); $type->lti_fix = $id; @@ -487,11 +487,11 @@ function blti_get_type_config_from_instance($id) { * * @return Configuration details */ -function blti_get_type_type_config($id) { +function lti_get_type_type_config($id) { global $DB; - $basicltitype = $DB->get_record('blti_types', array('id' => $id)); - $config = blti_get_type_config($id); + $basicltitype = $DB->get_record('lti_types', array('id' => $id)); + $config = lti_get_type_config($id); $type->lti_typename = $basicltitype->name; if (isset($config['toolurl'])) { @@ -568,10 +568,10 @@ function blti_get_type_type_config($id) { * * @return int Record id number */ -function blti_add_config($config) { +function lti_add_config($config) { global $DB; - return $DB->insert_record('blti_types_config', $config); + return $DB->insert_record('lti_types_config', $config); } /** @@ -581,17 +581,17 @@ function blti_add_config($config) { * * @return Record id number */ -function blti_update_config($config) { +function lti_update_config($config) { global $DB; $return = true; - $old = $DB->get_record('blti_types_config', array('typeid' => $config->typeid, 'name' => $config->name)); + $old = $DB->get_record('lti_types_config', array('typeid' => $config->typeid, 'name' => $config->name)); if ($old) { $config->id = $old->id; - $return = $DB->update_record('blti_types_config', $config); + $return = $DB->update_record('lti_types_config', $config); } else { - $return = $DB->insert_record('blti_types_config', $config); + $return = $DB->insert_record('lti_types_config', $config); } return $return; } @@ -681,18 +681,18 @@ function post_launch_html($newparms, $endpoint, $debug=false) { $r .= " //]]> \n"; $r .= "\n"; $r .= ""; - $r .= get_string("toggle_debug_data", "blti")."\n"; + $r .= get_string("toggle_debug_data", "lti")."\n"; $r .= "
\n"; - $r .= "".get_string("basiclti_endpoint", "blti")."
\n"; + $r .= "".get_string("basiclti_endpoint", "lti")."
\n"; $r .= $endpoint . "
\n 
\n"; - $r .= "".get_string("basiclti_parameters", "blti")."
\n"; + $r .= "".get_string("basiclti_parameters", "lti")."
\n"; foreach ($newparms as $key => $value) { $key = htmlspecialchars($key); $value = htmlspecialchars($value); $r .= "$key = $value
\n"; } $r .= " 
\n"; - $r .= "

".get_string("basiclti_base_string", "blti")."
\n".$lastbasestring."

\n"; + $r .= "

".get_string("basiclti_base_string", "lti")."
\n".$lastbasestring."

\n"; $r .= "
\n"; } $r .= "\n"; @@ -732,10 +732,10 @@ function submittedlink($cm, $allgroups=false) { global $CFG; $submitted = ''; - $urlbase = "{$CFG->wwwroot}/mod/blti/"; + $urlbase = "{$CFG->wwwroot}/mod/lti/"; $context = get_context_instance(CONTEXT_MODULE, $cm->id); - if (has_capability('mod/blti:grade', $context)) { + if (has_capability('mod/lti:grade', $context)) { if ($allgroups and has_capability('moodle/site:accessallgroups', $context)) { $group = 0; } else { @@ -743,7 +743,7 @@ function submittedlink($cm, $allgroups=false) { } $submitted = ''. - get_string('viewsubmissions', 'blti').''; + get_string('viewsubmissions', 'lti').''; } else { if (isloggedin()) { // TODO Insert code for students if needed diff --git a/mod/blti/mod_form.php b/mod/lti/mod_form.php similarity index 78% rename from mod/blti/mod_form.php rename to mod/lti/mod_form.php index 32e4ff90c67..9a531cf9a08 100644 --- a/mod/blti/mod_form.php +++ b/mod/lti/mod_form.php @@ -33,7 +33,7 @@ /** * This file defines the main basiclti configuration form * - * @package blti + * @package lti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -48,9 +48,9 @@ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot.'/course/moodleform_mod.php'); -require_once($CFG->dirroot.'/mod/blti/locallib.php'); +require_once($CFG->dirroot.'/mod/lti/locallib.php'); -class mod_blti_mod_form extends moodleform_mod { +class mod_lti_mod_form extends moodleform_mod { function definition() { global $DB; @@ -60,10 +60,10 @@ class mod_blti_mod_form extends moodleform_mod { if (empty($typename)) { //Updating instance if (!empty($this->_instance)) { - $basiclti = $DB->get_record('blti', array('id' => $this->_instance)); + $basiclti = $DB->get_record('lti', array('id' => $this->_instance)); $this->typeid = $basiclti->typeid; - $typeconfig = blti_get_config($basiclti); + $typeconfig = lti_get_config($basiclti); $this->typeconfig = $typeconfig; } else { // New not pre-configured instance @@ -71,10 +71,10 @@ class mod_blti_mod_form extends moodleform_mod { } } else { // New pre-configured instance - $basicltitype = $DB->get_record('blti_types', array('rawname' => $typename)); + $basicltitype = $DB->get_record('lti_types', array('rawname' => $typename)); $this->typeid = $basicltitype->id; - $typeconfig = blti_get_type_config($this->typeid); + $typeconfig = lti_get_type_config($this->typeid); $this->typeconfig = $typeconfig; } @@ -83,44 +83,44 @@ class mod_blti_mod_form extends moodleform_mod { /// Adding the "general" fieldset, where all the common settings are shown $mform->addElement('header', 'general', get_string('general', 'form')); /// Adding the standard "name" field - $mform->addElement('text', 'name', get_string('basicltiname', 'blti'), array('size'=>'64')); + $mform->addElement('text', 'name', get_string('basicltiname', 'lti'), array('size'=>'64')); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', null, 'required', null, 'client'); /// Adding the optional "intro" and "introformat" pair of fields - $this->add_intro_editor(false, get_string('basicltiintro', 'blti')); + $this->add_intro_editor(false, get_string('basicltiintro', 'lti')); $mform->setAdvanced('introeditor'); - $mform->addElement('checkbox', 'showtitle', ' ', ' ' . get_string('display_name', 'blti')); + $mform->addElement('checkbox', 'showtitle', ' ', ' ' . get_string('display_name', 'lti')); $mform->setAdvanced('showtitle'); - $mform->addElement('checkbox', 'showdescription', ' ', ' ' . get_string('display_description', 'blti')); + $mform->addElement('checkbox', 'showdescription', ' ', ' ' . get_string('display_description', 'lti')); $mform->setAdvanced('showdescription'); //Tool settings - $mform->addElement('select', 'typeid', get_string('external_tool_type', 'blti'), blti_get_types_for_add_instance()); + $mform->addElement('select', 'typeid', get_string('external_tool_type', 'lti'), lti_get_types_for_add_instance()); //$mform->setDefault('typeid', '0'); - $mform->addElement('text', 'toolurl', get_string('launch_url', 'blti'), array('size'=>'64')); + $mform->addElement('text', 'toolurl', get_string('launch_url', 'lti'), array('size'=>'64')); $mform->setType('toolurl', PARAM_TEXT); $launchoptions=array(); - $launchoptions[BLTI_LAUNCH_CONTAINER_DEFAULT] = get_string('default', 'blti'); - $launchoptions[BLTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'blti'); - $launchoptions[BLTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'blti'); - $launchoptions[BLTI_LAUNCH_CONTAINER_WINDOW] = get_string('new_window', 'blti'); + $launchoptions[LTI_LAUNCH_CONTAINER_DEFAULT] = get_string('default', 'lti'); + $launchoptions[LTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'lti'); + $launchoptions[LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'lti'); + $launchoptions[LTI_LAUNCH_CONTAINER_WINDOW] = get_string('new_window', 'lti'); - $mform->addElement('select', 'launchcontainer', get_string('launchinpopup', 'blti'), $launchoptions); - $mform->setDefault('launchcontainer', BLTI_LAUNCH_CONTAINER_DEFAULT); + $mform->addElement('select', 'launchcontainer', get_string('launchinpopup', 'lti'), $launchoptions); + $mform->setDefault('launchcontainer', LTI_LAUNCH_CONTAINER_DEFAULT); - $mform->addElement('text', 'resourcekey', get_string('resourcekey', 'blti')); + $mform->addElement('text', 'resourcekey', get_string('resourcekey', 'lti')); $mform->setType('resourcekey', PARAM_TEXT); $mform->setAdvanced('resourcekey'); - $mform->addElement('passwordunmask', 'password', get_string('password', 'blti')); + $mform->addElement('passwordunmask', 'password', get_string('password', 'lti')); $mform->setType('password', PARAM_TEXT); $mform->setAdvanced('password'); - $mform->addElement('textarea', 'instructorcustomparameters', get_string('custom', 'blti'), array('rows'=>4, 'cols'=>60)); + $mform->addElement('textarea', 'instructorcustomparameters', get_string('custom', 'lti'), array('rows'=>4, 'cols'=>60)); $mform->setType('instructorcustomparameters', PARAM_TEXT); $mform->setAdvanced('instructorcustomparameters'); @@ -131,27 +131,27 @@ class mod_blti_mod_form extends moodleform_mod { //------------------------------------------------------------------------------- // Add privacy preferences fieldset where users choose whether to send their data - $mform->addElement('header', 'privacy', get_string('privacy', 'blti')); + $mform->addElement('header', 'privacy', get_string('privacy', 'lti')); - $mform->addElement('checkbox', 'instructorchoicesendname', ' ', ' ' . get_string('share_name', 'blti')); + $mform->addElement('checkbox', 'instructorchoicesendname', ' ', ' ' . get_string('share_name', 'lti')); $mform->setDefault('instructorchoicesendname', '1'); - $mform->addElement('checkbox', 'instructorchoicesendemailaddr', ' ', ' ' . get_string('share_email', 'blti')); + $mform->addElement('checkbox', 'instructorchoicesendemailaddr', ' ', ' ' . get_string('share_email', 'lti')); $mform->setDefault('instructorchoicesendemailaddr', '1'); - $mform->addElement('checkbox', 'instructorchoiceacceptgrades', ' ', ' ' . get_string('accept_grades', 'blti')); + $mform->addElement('checkbox', 'instructorchoiceacceptgrades', ' ', ' ' . get_string('accept_grades', 'lti')); $mform->setDefault('instructorchoiceacceptgrades', '1'); - $mform->addElement('checkbox', 'instructorchoiceallowroster', ' ', ' ' . get_string('share_roster', 'blti')); + $mform->addElement('checkbox', 'instructorchoiceallowroster', ' ', ' ' . get_string('share_roster', 'lti')); $mform->setDefault('instructorchoiceallowroster', '1'); //------------------------------------------------------------------------------- /* $debugoptions=array(); - $debugoptions[0] = get_string('debuglaunchoff', 'blti'); - $debugoptions[1] = get_string('debuglaunchon', 'blti'); + $debugoptions[0] = get_string('debuglaunchoff', 'lti'); + $debugoptions[1] = get_string('debuglaunchon', 'lti'); - $mform->addElement('select', 'debuglaunch', get_string('debuglaunch', 'blti'), $debugoptions); + $mform->addElement('select', 'debuglaunch', get_string('debuglaunch', 'lti'), $debugoptions); if (isset($this->typeconfig['debuglaunch'])) { if ($this->typeconfig['debuglaunch'] == 0) { @@ -186,7 +186,7 @@ class mod_blti_mod_form extends moodleform_mod { //we don't want to have these appear as possible selections in the form but //we want the form to display them if they are set. if (!empty($typeidvalue)) { - $typeconfig = blti_get_type_config($typeidvalue); + $typeconfig = lti_get_type_config($typeidvalue); if ($typeconfig["sendname"] != 2) { $field =& $mform->getElement('instructorchoicesendname'); @@ -234,40 +234,40 @@ class mod_blti_mod_form extends moodleform_mod { if (!isset($default_values['toolurl'])) { if (isset($this->typeconfig['toolurl'])) { $default_values['toolurl'] = $this->typeconfig['toolurl']; - } else if (isset($CFG->blti_toolurl)) { - $default_values['toolurl'] = $CFG->blti_toolurl; + } else if (isset($CFG->lti_toolurl)) { + $default_values['toolurl'] = $CFG->lti_toolurl; } } if (!isset($default_values['resourcekey'])) { if (isset($this->typeconfig['resourcekey'])) { $default_values['resourcekey'] = $this->typeconfig['resourcekey']; - } else if (isset($CFG->blti_resourcekey)) { - $default_values['resourcekey'] = $CFG->blti_resourcekey; + } else if (isset($CFG->lti_resourcekey)) { + $default_values['resourcekey'] = $CFG->lti_resourcekey; } } if (!isset($default_values['password'])) { if (isset($this->typeconfig['password'])) { $default_values['password'] = $this->typeconfig['password']; - } else if (isset($CFG->blti_password)) { - $default_values['password'] = $CFG->blti_password; + } else if (isset($CFG->lti_password)) { + $default_values['password'] = $CFG->lti_password; } } if (!isset($default_values['preferheight'])) { if (isset($this->typeconfig['preferheight'])) { $default_values['preferheight'] = $this->typeconfig['preferheight']; - } else if (isset($CFG->blti_preferheight)) { - $default_values['preferheight'] = $CFG->blti_preferheight; + } else if (isset($CFG->lti_preferheight)) { + $default_values['preferheight'] = $CFG->lti_preferheight; } } if (!isset($default_values['sendname'])) { if (isset($this->typeconfig['sendname'])) { $default_values['sendname'] = $this->typeconfig['sendname']; - } else if (isset($CFG->blti_sendname)) { - $default_values['sendname'] = $CFG->blti_sendname; + } else if (isset($CFG->lti_sendname)) { + $default_values['sendname'] = $CFG->lti_sendname; } } @@ -276,7 +276,7 @@ class mod_blti_mod_form extends moodleform_mod { $default_values['instructorchoicesendname'] = $this->typeconfig['instructorchoicesendname']; } else { if ($this->typeconfig['sendname'] == 2) { - $default_values['instructorchoicesendname'] = $CFG->blti_instructorchoicesendname; + $default_values['instructorchoicesendname'] = $CFG->lti_instructorchoicesendname; } else { $default_values['instructorchoicesendname'] = $this->typeconfig['sendname']; } @@ -286,8 +286,8 @@ class mod_blti_mod_form extends moodleform_mod { if (!isset($default_values['sendemailaddr'])) { if (isset($this->typeconfig['sendemailaddr'])) { $default_values['sendemailaddr'] = $this->typeconfig['sendemailaddr']; - } else if (isset($CFG->blti_sendemailaddr)) { - $default_values['sendemailaddr'] = $CFG->blti_sendemailaddr; + } else if (isset($CFG->lti_sendemailaddr)) { + $default_values['sendemailaddr'] = $CFG->lti_sendemailaddr; } } @@ -296,7 +296,7 @@ class mod_blti_mod_form extends moodleform_mod { $default_values['instructorchoicesendemailaddr'] = $this->typeconfig['instructorchoicesendemailaddr']; } else { if ($this->typeconfig['sendemailaddr'] == 2) { - $default_values['instructorchoicesendemailaddr'] = $CFG->blti_instructorchoicesendemailaddr; + $default_values['instructorchoicesendemailaddr'] = $CFG->lti_instructorchoicesendemailaddr; } else { $default_values['instructorchoicesendemailaddr'] = $this->typeconfig['sendemailaddr']; } @@ -306,8 +306,8 @@ class mod_blti_mod_form extends moodleform_mod { if (!isset($default_values['acceptgrades'])) { if (isset($this->typeconfig['acceptgrades'])) { $default_values['acceptgrades'] = $this->typeconfig['acceptgrades']; - } else if (isset($CFG->blti_acceptgrades)) { - $default_values['acceptgrades'] = $CFG->blti_acceptgrades; + } else if (isset($CFG->lti_acceptgrades)) { + $default_values['acceptgrades'] = $CFG->lti_acceptgrades; } } @@ -316,7 +316,7 @@ class mod_blti_mod_form extends moodleform_mod { $default_values['instructorchoiceacceptgrades'] = $this->typeconfig['instructorchoiceacceptgrades']; } else { if ($this->typeconfig['acceptgrades'] == 2) { - $default_values['instructorchoiceacceptgrades'] = $CFG->blti_instructorchoiceacceptgrades; + $default_values['instructorchoiceacceptgrades'] = $CFG->lti_instructorchoiceacceptgrades; } else { $default_values['instructorchoiceacceptgrades'] = $this->typeconfig['acceptgrades']; } @@ -326,8 +326,8 @@ class mod_blti_mod_form extends moodleform_mod { if (!isset($default_values['allowroster'])) { if (isset($this->typeconfig['allowroster'])) { $default_values['allowroster'] = $this->typeconfig['allowroster']; - } else if (isset($CFG->blti_allowroster)) { - $default_values['allowroster'] = $CFG->blti_allowroster; + } else if (isset($CFG->lti_allowroster)) { + $default_values['allowroster'] = $CFG->lti_allowroster; } } @@ -336,7 +336,7 @@ class mod_blti_mod_form extends moodleform_mod { $default_values['instructorchoiceallowroster'] = $this->typeconfig['instructorchoiceallowroster']; } else { if ($this->typeconfig['allowroster'] == 2) { - $default_values['instructorchoiceallowroster'] = $CFG->blti_instructorchoiceallowroster; + $default_values['instructorchoiceallowroster'] = $CFG->lti_instructorchoiceallowroster; } else { $default_values['instructorchoiceallowroster'] = $this->typeconfig['allowroster']; } @@ -346,8 +346,8 @@ class mod_blti_mod_form extends moodleform_mod { if (!isset($default_values['allowsetting'])) { if (isset($this->typeconfig['allowsetting'])) { $default_values['allowsetting'] = $this->typeconfig['allowsetting']; - } else if (isset($CFG->blti_allowsetting)) { - $default_values['allowsetting'] = $CFG->blti_allowsetting; + } else if (isset($CFG->lti_allowsetting)) { + $default_values['allowsetting'] = $CFG->lti_allowsetting; } } @@ -356,7 +356,7 @@ class mod_blti_mod_form extends moodleform_mod { $default_values['instructorchoiceallowsetting'] = $this->typeconfig['instructorchoiceallowsetting']; } else { if ($this->typeconfig['allowsetting'] == 2) { - $default_values['instructorchoiceallowsetting'] = $CFG->blti_instructorchoiceallowsetting; + $default_values['instructorchoiceallowsetting'] = $CFG->lti_instructorchoiceallowsetting; } else { $default_values['instructorchoiceallowsetting'] = $this->typeconfig['allowsetting']; } @@ -366,48 +366,48 @@ class mod_blti_mod_form extends moodleform_mod { if (!isset($default_values['customparameters'])) { if (isset($this->typeconfig['customparameters'])) { $default_values['customparameters'] = $this->typeconfig['customparameters']; - } else if (isset($CFG->blti_customparameters)) { - $default_values['customparameters'] = $CFG->blti_customparameters; + } else if (isset($CFG->lti_customparameters)) { + $default_values['customparameters'] = $CFG->lti_customparameters; } } if (!isset($default_values['allowinstructorcustom'])) { if (isset($this->typeconfig['allowinstructorcustom'])) { $default_values['allowinstructorcustom'] = $this->typeconfig['allowinstructorcustom']; - } else if (isset($CFG->blti_allowinstructorcustom)) { - $default_values['allowinstructorcustom'] = $CFG->blti_allowinstructorcustom; + } else if (isset($CFG->lti_allowinstructorcustom)) { + $default_values['allowinstructorcustom'] = $CFG->lti_allowinstructorcustom; } } if (!isset($default_values['organizationid'])) { if (isset($this->typeconfig['organizationid'])) { $default_values['organizationid'] = $this->typeconfig['organizationid']; - } else if (isset($CFG->blti_organizationid)) { - $default_values['organizationid'] = $CFG->blti_organizationid; + } else if (isset($CFG->lti_organizationid)) { + $default_values['organizationid'] = $CFG->lti_organizationid; } } if (!isset($default_values['organizationurl'])) { if (isset($this->typeconfig['organizationurl'])) { $default_values['organizationurl'] = $this->typeconfig['organizationurl']; - } else if (isset($CFG->blti_organizationurl)) { - $default_values['organizationurl'] = $CFG->blti_organizationurl; + } else if (isset($CFG->lti_organizationurl)) { + $default_values['organizationurl'] = $CFG->lti_organizationurl; } } if (!isset($default_values['organizationdescr'])) { if (isset($this->typeconfig['organizationdescr'])) { $default_values['organizationdescr'] = $this->typeconfig['organizationdescr']; - } else if (isset($CFG->blti_organizationdescr)) { - $default_values['organizationdescr'] = $CFG->blti_organizationdescr; + } else if (isset($CFG->lti_organizationdescr)) { + $default_values['organizationdescr'] = $CFG->lti_organizationdescr; } } if (!isset($default_values['launchinpopup'])) { if (isset($this->typeconfig['launchinpopup'])) { $default_values['launchinpopup'] = $this->typeconfig['launchinpopup']; - } else if (isset($CFG->blti_launchinpopup)) { - $default_values['launchinpopup'] = $CFG->blti_launchinpopup; + } else if (isset($CFG->lti_launchinpopup)) { + $default_values['launchinpopup'] = $CFG->lti_launchinpopup; } } */ diff --git a/mod/blti/pix/icon.gif b/mod/lti/pix/icon.gif similarity index 100% rename from mod/blti/pix/icon.gif rename to mod/lti/pix/icon.gif diff --git a/mod/blti/service.php b/mod/lti/service.php similarity index 92% rename from mod/blti/service.php rename to mod/lti/service.php index 7b51d16d8d9..8555e238442 100644 --- a/mod/blti/service.php +++ b/mod/lti/service.php @@ -34,7 +34,7 @@ * This file contains all necessary code to support basiclti services * like outcomes and roster access. * - * @package blti + * @package lti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -48,16 +48,16 @@ */ require_once("../../config.php"); -require_once($CFG->dirroot.'/mod/blti/lib.php'); -require_once($CFG->dirroot.'/mod/blti/locallib.php'); -require_once($CFG->dirroot.'/mod/blti/OAuth.php'); -require_once($CFG->dirroot.'/mod/blti/TrivialStore.php'); +require_once($CFG->dirroot.'/mod/lti/lib.php'); +require_once($CFG->dirroot.'/mod/lti/locallib.php'); +require_once($CFG->dirroot.'/mod/lti/OAuth.php'); +require_once($CFG->dirroot.'/mod/lti/TrivialStore.php'); error_reporting(E_ALL & ~E_NOTICE); ini_set("display_errors", 1); $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); -$PAGE->set_url('/mod/blti/service.php'); +$PAGE->set_url('/mod/lti/service.php'); $PAGE->set_pagetype('admin-setting-' . $section); $PAGE->set_pagelayout('admin'); $PAGE->navigation->clear_cache(); @@ -145,13 +145,13 @@ if (isset($signature) && isset($userid) && isset($placement)) { } // Retrieve the Basic LTI placement -if (! $basiclti = $DB->get_record('blti', array('id'=>$placement))) { +if (! $basiclti = $DB->get_record('lti', array('id'=>$placement))) { do_error("Bad sourcedid (4)"); } $basiclti_types_config = (object)$basiclti_types_config; -$typeconfig = blti_get_type_config($basiclti->typeid); +$typeconfig = lti_get_type_config($basiclti->typeid); if (isset($typeconfig) && isset($typeconfig['password'])) { // OK @@ -234,7 +234,7 @@ if (! $course = $DB->get_record('course', array('id'=>$basiclti->course))) { // TODO: Check that user is in course -if (! $cm = get_coursemodule_from_instance("blti", $basiclti->id, $course->id)) { +if (! $cm = get_coursemodule_from_instance("lti", $basiclti->id, $course->id)) { do_error("Course Module ID was incorrect"); } @@ -243,10 +243,10 @@ require_once($CFG->libdir.'/gradelib.php'); // Beginning of actual grade processing if ($message_type == "basicoutcome") { - $source = 'mod/blti'; + $source = 'mod/lti'; $courseid = $course->id; $itemtype = 'mod'; - $itemmodule = 'blti'; + $itemmodule = 'lti'; $iteminstance = $basiclti->id; if ($lti_message_type == "basic-lis-readresult") { @@ -314,18 +314,18 @@ if ($message_type == "basicoutcome") { if (! isset($setting)) { do_error('Missing setting value'); } - $record = $DB->get_record('blti', array('id'=>$basiclti->id)); + $record = $DB->get_record('lti', array('id'=>$basiclti->id)); $record->setting = $setting; - $success = $DB->update_record('blti', $record); + $success = $DB->update_record('lti', $record); if ($success) { print message_response('Success', 'Status', 'fullsuccess', 'Setting updated'); } else { do_error("Error updating error"); } } else if ($lti_message_type == "basic-lti-deletesetting") { - $record = $DB->get_record('blti', array('id'=>$basiclti->id)); + $record = $DB->get_record('lti', array('id'=>$basiclti->id)); $record->setting = ''; - $success = $DB->update_record('blti', $record); + $success = $DB->update_record('lti', $record); if ($success) { print message_response('Success', 'Status', 'fullsuccess', 'Setting deleted'); } else { diff --git a/mod/blti/settings.php b/mod/lti/settings.php similarity index 79% rename from mod/blti/settings.php rename to mod/lti/settings.php index c0a7d71da9e..8b91db7ab63 100644 --- a/mod/blti/settings.php +++ b/mod/lti/settings.php @@ -33,7 +33,7 @@ /** * This file defines the global basiclti administration form * - * @package blti + * @package lti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -48,21 +48,21 @@ defined('MOODLE_INTERNAL') || die; if ($ADMIN->fulltree) { - require_once($CFG->dirroot.'/mod/blti/locallib.php'); + require_once($CFG->dirroot.'/mod/lti/locallib.php'); $str = ''; - $types = blti_filter_get_types(); + $types = lti_filter_get_types(); if (!empty($types)) { - $str .= '

'.get_string('addtype', 'blti').'

'; + $str .= '

'.get_string('addtype', 'lti').'

'; $str .= '
'; foreach ($types as $type) { $str .= ''. ''. - ''. @@ -72,12 +72,12 @@ if ($ADMIN->fulltree) { $str .= '
'.$type->name.''. + ''. 'Update'.'  '. - ''. + ''. 'Delete'. ''. '
'; } else { $str .= '
'; - $str .= '

'.get_string('addtype', 'blti').'

'; - $str .= get_string('notypes', 'blti'); + $str .= '

'.get_string('addtype', 'lti').'

'; + $str .= get_string('notypes', 'lti'); $str .= '
'; } - $settings->add(new admin_setting_heading('blti_types', get_string('configuredtools', 'blti'), $str)); + $settings->add(new admin_setting_heading('lti_types', get_string('configuredtools', 'lti'), $str)); } diff --git a/mod/blti/simpletest/testlocallib.php b/mod/lti/simpletest/testlocallib.php similarity index 95% rename from mod/blti/simpletest/testlocallib.php rename to mod/lti/simpletest/testlocallib.php index a7756c8ecc2..c4d37541a3c 100644 --- a/mod/blti/simpletest/testlocallib.php +++ b/mod/lti/simpletest/testlocallib.php @@ -33,7 +33,7 @@ /** * This file contains unit tests for (some of) mod/basiclti/locallib.php * - * @package blti + * @package lti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -50,10 +50,10 @@ if (!defined('MOODLE_INTERNAL')) { die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page. } -require_once($CFG->dirroot . '/mod/blti/locallib.php'); +require_once($CFG->dirroot . '/mod/lti/locallib.php'); -class blti_locallib_test extends UnitTestCase { - public static $includecoverage = array('mod/blti/locallib.php'); +class lti_locallib_test extends UnitTestCase { + public static $includecoverage = array('mod/lti/locallib.php'); function test_split_custom_parameters() { $this->assertEqual(split_custom_parameters("x=1\ny=2"), array('custom_x' => '1', 'custom_y'=> '2')); @@ -71,7 +71,7 @@ class blti_locallib_test extends UnitTestCase { $requestparams = array('resource_link_id' => '123', 'resource_link_title' => 'Weekly Blog', 'user_id' => '789', 'roles' => 'Learner', 'context_id' => '12345', 'context_label' => 'SI124', 'context_title' => 'Social Computing'); - $parms = sign_parameters($requestparams, 'http://www.imsglobal.org/developer/BLTI/tool.php', 'POST', + $parms = sign_parameters($requestparams, 'http://www.imsglobal.org/developer/LTI/tool.php', 'POST', 'lmsng.school.edu', 'secret', 'Click Me', 'lmsng.school.edu' /*, $org_desc*/); $this->assertTrue(isset($parms['oauth_nonce'])); $this->assertTrue(isset($parms['oauth_signature'])); diff --git a/mod/lti/styles.css b/mod/lti/styles.css new file mode 100644 index 00000000000..5f74f7e770a --- /dev/null +++ b/mod/lti/styles.css @@ -0,0 +1,32 @@ +.path-mod-lti .ltiframe {position: relative;width: 100%;height: 100%;} + +/** General Styles **/ +.path-mod-lti .userpicture, +.path-mod-lti .picture.user, +.path-mod-lti .picture.teacher {width:35px;height: 35px;vertical-align:top;} +.path-mod-lti .feedback .files, +.path-mod-lti .feedback .grade, +.path-mod-lti .feedback .outcome, +.path-mod-lti .feedback .finalgrade {float: right;} +.path-mod-lti .feedback .disabledfeedback {width: 500px;height: 250px;} +.path-mod-lti .feedback .from {float: left;} +.path-mod-lti .files img {margin-right: 4px;} +.path-mod-lti .files a {white-space:nowrap;} +.path-mod-lti .late {color: red;} +.path-mod-lti .message {text-align: center;} + +/** Styles for submissions.php **/ +#page-mod-lti-submissions fieldset.felement {margin-left: 16%;} +#page-mod-lti-submissions form#options div {text-align:right;margin-left:auto;margin-right:20px;} +#page-mod-lti-submissions .header .commands {display: inline;} +#page-mod-lti-submissions .picture {width: 35px;} +#page-mod-lti-submissions .fullname, +#page-mod-lti-submissions .timemodified, +#page-mod-lti-submissions .timemarked {text-align: left;} +#page-mod-lti-submissions .submissions .grade, +#page-mod-lti-submissions .submissions .outcome, +#page-mod-lti-submissions .submissions .finalgrade {text-align: right;} +#page-mod-lti-submissions .qgprefs #optiontable {text-align:right;margin-left:auto;} + +/* Styles for admin */ +.path-admin-mod-lti .mform .fitem .fitemtitle { min-width:15em;padding-right:1em } /* Prevent setting titles from wrapping */ diff --git a/mod/blti/submissions.php b/mod/lti/submissions.php similarity index 81% rename from mod/blti/submissions.php rename to mod/lti/submissions.php index 0de13f7aec2..8482181d017 100644 --- a/mod/blti/submissions.php +++ b/mod/lti/submissions.php @@ -34,7 +34,7 @@ /** * This file contains submissions-specific code for the basiclti module * - * @package blti + * @package lti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -46,7 +46,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once("../../config.php"); -require_once($CFG->dirroot.'/mod/blti/lib.php'); +require_once($CFG->dirroot.'/mod/lti/lib.php'); require_once($CFG->libdir.'/plagiarismlib.php'); $id = optional_param('id', 0, PARAM_INT); // Course module ID @@ -54,28 +54,28 @@ $a = optional_param('a', 0, PARAM_INT); // Assignment ID $mode = optional_param('mode', 'all', PARAM_ALPHA); // What mode are we in? $download = optional_param('download' , 'none', PARAM_ALPHA); //ZIP download asked for? -$url = new moodle_url('/mod/blti/submissions.php'); +$url = new moodle_url('/mod/lti/submissions.php'); if ($id) { - if (! $cm = get_coursemodule_from_id('blti', $id)) { + if (! $cm = get_coursemodule_from_id('lti', $id)) { print_error('invalidcoursemodule'); } - if (! $basiclti = $DB->get_record("blti", array("id"=>$cm->instance))) { - print_error('invalidid', 'blti'); + if (! $basiclti = $DB->get_record("lti", array("id"=>$cm->instance))) { + print_error('invalidid', 'lti'); } if (! $course = $DB->get_record("course", array("id"=>$basiclti->course))) { - print_error('coursemisconf', 'blti'); + print_error('coursemisconf', 'lti'); } $url->param('id', $id); } else { - if (!$basiclti = $DB->get_record("blti", array("id"=>$a))) { + if (!$basiclti = $DB->get_record("lti", array("id"=>$a))) { print_error('invalidcoursemodule'); } if (! $course = $DB->get_record("course", array("id"=>$basiclti->course))) { - print_error('coursemisconf', 'blti'); + print_error('coursemisconf', 'lti'); } - if (! $cm = get_coursemodule_from_instance("blti", $basiclti->id, $course->id)) { + if (! $cm = get_coursemodule_from_instance("lti", $basiclti->id, $course->id)) { print_error('invalidcoursemodule'); } $url->param('a', $a); @@ -87,6 +87,6 @@ if ($mode !== 'all') { $PAGE->set_url($url); require_login($course, false, $cm); -require_capability('mod/blti:grade', get_context_instance(CONTEXT_MODULE, $cm->id)); +require_capability('mod/lti:grade', get_context_instance(CONTEXT_MODULE, $cm->id)); -blti_submissions($cm, $course, $basiclti, $mode); // Display or process the submissions +lti_submissions($cm, $course, $basiclti, $mode); // Display or process the submissions diff --git a/mod/blti/typessettings.php b/mod/lti/typessettings.php similarity index 86% rename from mod/blti/typessettings.php rename to mod/lti/typessettings.php index e168193d505..72f0639ae2f 100644 --- a/mod/blti/typessettings.php +++ b/mod/lti/typessettings.php @@ -35,7 +35,7 @@ * It is used to create a new form used to pre-configure basiclti * activities * - * @package blti + * @package lti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -49,10 +49,10 @@ require_once('../../config.php'); require_once($CFG->libdir.'/adminlib.php'); -require_once($CFG->dirroot.'/mod/blti/edit_form.php'); -require_once($CFG->dirroot.'/mod/blti/locallib.php'); +require_once($CFG->dirroot.'/mod/lti/edit_form.php'); +require_once($CFG->dirroot.'/mod/lti/locallib.php'); -$section = 'modsettingblti'; +$section = 'modsettinglti'; $return = optional_param('return', '', PARAM_ALPHA); $adminediting = optional_param('adminedit', -1, PARAM_BOOL); $action = optional_param('action', null, PARAM_TEXT); @@ -62,7 +62,7 @@ $definenew = optional_param('definenew', null, PARAM_INT); /// no guest autologin require_login(0, false); -$url = new moodle_url('/mod/blti/typesettings.php'); +$url = new moodle_url('/mod/lti/typesettings.php'); $PAGE->set_url($url); admin_externalpage_setup('managemodules'); // Hacky solution for printing the admin page @@ -77,7 +77,7 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton $type = new StdClass(); $type->name = $data->lti_typename; $type->baseurl = $data->lti_toolurl; - $type->tooldomain = blti_get_domain_from_url($data->lti_toolurl); + $type->tooldomain = lti_get_domain_from_url($data->lti_toolurl); $type->course = $SITE->id; $type->coursevisible = !empty($data->lti_coursevisible) ? $data->lti_coursevisible : 0; $type->timemodified = time(); @@ -87,7 +87,7 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton if (isset($id)) { $type->id = $id; - if ($DB->update_record('blti_types', $type)) { + if ($DB->update_record('lti_types', $type)) { unset ($data->lti_typename); foreach ($data as $key => $value) { @@ -96,7 +96,7 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton $record->typeid = $id; $record->name = substr($key, 4); $record->value = $value; - if (blti_update_config($record)) { + if (lti_update_config($record)) { $statusmsg = get_string('changessaved'); } else { $errormsg = get_string('errorwithsettings', 'admin'); @@ -104,7 +104,7 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton } } } - redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingblti"); + redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti"); die; } else { $type->createdby = $USER->id; @@ -113,7 +113,7 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton //Create a salt value to be used for signing passed data to extension services $data->lti_servicesalt = uniqid('', true); - $id = $DB->insert_record('blti_types', $type); + $id = $DB->insert_record('lti_types', $type); if ($id) { unset ($data->lti_typename); @@ -123,7 +123,7 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton $record->typeid = $id; $record->name = substr($key, 4); $record->value = $value; - if (blti_add_config($record)) { + if (lti_add_config($record)) { $statusmsg = get_string('changessaved'); } else { $errormsg = get_string('errorwithsettings', 'admin'); @@ -133,22 +133,22 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton } else { $errormsg = get_string('errorwithsettings', 'admin'); } - redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingblti"); + redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti"); die; } } if ($action == 'delete') { - blti_delete_type($id); - redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingblti"); + lti_delete_type($id); + redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti"); die; } if (($action == 'fix') && isset($useexisting)) { - $instance = $DB->get_record('blti', array('id' => $id)); + $instance = $DB->get_record('lti', array('id' => $id)); $instance->typeid = $useexisting; - $DB->update_record('blti', $instance); - redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingblti"); + $DB->update_record('lti', $instance); + redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti"); die; } @@ -158,7 +158,7 @@ if (empty($SITE->fullname)) { $PAGE->set_title($settingspage->visiblename); $PAGE->set_heading($settingspage->visiblename); - $PAGE->navbar->add('Basic LTI Administration', $CFG->wwwroot.'/admin/settings.php?section=modsettingblti'); + $PAGE->navbar->add('Basic LTI Administration', $CFG->wwwroot.'/admin/settings.php?section=modsettinglti'); echo $OUTPUT->header(); @@ -199,9 +199,9 @@ if (empty($SITE->fullname)) { $buttons = $OUTPUT->single_button($url, $caption, 'get'); } - $PAGE->set_title("$SITE->shortname: " . get_string('toolsetup', 'blti')); + $PAGE->set_title("$SITE->shortname: " . get_string('toolsetup', 'lti')); - $PAGE->navbar->add('Basic LTI Administration', $CFG->wwwroot.'/admin/settings.php?section=modsettingblti'); + $PAGE->navbar->add('Basic LTI Administration', $CFG->wwwroot.'/admin/settings.php?section=modsettinglti'); echo $OUTPUT->header(); @@ -215,14 +215,14 @@ if (empty($SITE->fullname)) { } // --------------------------------------------------------------------------------------------------------------- - echo $OUTPUT->heading(get_string('toolsetup', 'blti')); + echo $OUTPUT->heading(get_string('toolsetup', 'lti')); echo $OUTPUT->box_start('generalbox'); if ($action == 'add') { - $form = new mod_blti_edit_types_form(); + $form = new mod_lti_edit_types_form(); $form->display(); } else if ($action == 'update') { - $form = new mod_blti_edit_types_form('typessettings.php?id='.$id); - $type = blti_get_type_type_config($id); + $form = new mod_lti_edit_types_form('typessettings.php?id='.$id); + $type = lti_get_type_type_config($id); $form->set_data($type); $form->display(); } diff --git a/mod/blti/version.php b/mod/lti/version.php similarity index 97% rename from mod/blti/version.php rename to mod/lti/version.php index 8fd6b4546ce..39208581e4f 100644 --- a/mod/blti/version.php +++ b/mod/lti/version.php @@ -34,7 +34,7 @@ * This file defines the version of basiclti * This fragment is called by moodle_needs_upgrading() and /admin/index.php * - * @package blti + * @package lti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu diff --git a/mod/blti/view.php b/mod/lti/view.php similarity index 82% rename from mod/blti/view.php rename to mod/lti/view.php index 3624e681548..bed0e6f44a4 100644 --- a/mod/blti/view.php +++ b/mod/lti/view.php @@ -33,7 +33,7 @@ /** * This file contains all necessary code to view a basiclti activity instance * - * @package blti + * @package lti * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu @@ -46,14 +46,14 @@ */ require_once('../../config.php'); -require_once($CFG->dirroot.'/mod/blti/lib.php'); -require_once($CFG->dirroot.'/mod/blti/locallib.php'); +require_once($CFG->dirroot.'/mod/lti/lib.php'); +require_once($CFG->dirroot.'/mod/lti/locallib.php'); $id = optional_param('id', 0, PARAM_INT); // Course Module ID, or -$a = optional_param('a', 0, PARAM_INT); // blti ID +$a = optional_param('a', 0, PARAM_INT); // lti ID if ($id) { - if (! $cm = get_coursemodule_from_id("blti", $id)) { + if (! $cm = get_coursemodule_from_id("lti", $id)) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect'); } @@ -61,37 +61,37 @@ if ($id) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured'); } - if (! $basiclti = $DB->get_record("blti", array("id" => $cm->instance))) { + if (! $basiclti = $DB->get_record("lti", array("id" => $cm->instance))) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect'); } } else { - if (! $basiclti = $DB->get_record("blti", array("id" => $a))) { + if (! $basiclti = $DB->get_record("lti", array("id" => $a))) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect'); } if (! $course = $DB->get_record("course", array("id" => $basiclti->course))) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured'); } - if (! $cm = get_coursemodule_from_instance("blti", $basiclti->id, $course->id)) { + if (! $cm = get_coursemodule_from_instance("lti", $basiclti->id, $course->id)) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect'); } } -$tool = blti_get_tool_by_url_match($basiclti->toolurl); -$toolconfig = blti_get_type_config($tool->id); +$tool = lti_get_tool_by_url_match($basiclti->toolurl); +$toolconfig = lti_get_type_config($tool->id); $PAGE->set_cm($cm, $course); // set's up global $COURSE $context = get_context_instance(CONTEXT_MODULE, $cm->id); $PAGE->set_context($context); -$url = new moodle_url('/mod/blti/view.php', array('id'=>$cm->id)); +$url = new moodle_url('/mod/lti/view.php', array('id'=>$cm->id)); $PAGE->set_url($url); -$launchcontainer = $basiclti->launchcontainer == BLTI_LAUNCH_CONTAINER_DEFAULT ? +$launchcontainer = $basiclti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT ? $toolconfig['launchcontainer'] : $basiclti->launchcontainer; -if($launchcontainer == BLTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS){ +if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS){ $PAGE->set_pagelayout('frametop'); //Use the frametop layout to get the navbar, but no footer $PAGE->blocks->show_only_fake_blocks(); //Disable blocks } else { @@ -100,7 +100,7 @@ if($launchcontainer == BLTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS){ require_login($course); -add_to_log($course->id, "blti", "view", "view.php?id=$cm->id", "$basiclti->id"); +add_to_log($course->id, "lti", "view", "view.php?id=$cm->id", "$basiclti->id"); $pagetitle = strip_tags($course->shortname.': '.format_string($basiclti->name)); $PAGE->set_title($pagetitle); @@ -122,12 +122,12 @@ if ($basiclti->instructorchoiceacceptgrades == 1) { echo ''; } -if ( $launchcontainer == BLTI_LAUNCH_CONTAINER_WINDOW ) { +if ( $launchcontainer == LTI_LAUNCH_CONTAINER_WINDOW ) { echo "\n"; - echo "

".get_string("basiclti_in_new_window", "blti")."

\n"; + echo "

".get_string("basiclti_in_new_window", "lti")."

\n"; } else { // Request the launch content with an object tag echo ''; From a4a07996f0fedc4d797c2f4b9e4492bcb9fcb14a Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Wed, 31 Aug 2011 18:11:19 -0400 Subject: [PATCH 08/78] Implemented admin tool management --- mod/lti/edit_form.php | 4 + mod/lti/lang/en/lti.php | 17 ++- mod/lti/locallib.php | 22 +++- mod/lti/settings.php | 243 +++++++++++++++++++++++++++++++++----- mod/lti/typessettings.php | 37 ++++-- mod/lti/view.php | 6 +- 6 files changed, 279 insertions(+), 50 deletions(-) diff --git a/mod/lti/edit_form.php b/mod/lti/edit_form.php index 85a9837489c..73121312b1f 100644 --- a/mod/lti/edit_form.php +++ b/mod/lti/edit_form.php @@ -149,6 +149,10 @@ class mod_lti_edit_types_form extends moodleform{ //------------------------------------------------------------------------------- // Add a hidden element to signal a tool fixing operation after a problematic backup - restore process $mform->addElement('hidden', 'lti_fix'); + + $tab = optional_param('tab', '', PARAM_ALPHAEXT); + $mform->addElement('hidden', 'tab', $tab); + //------------------------------------------------------------------------------- // Add standard buttons, common to all modules diff --git a/mod/lti/lang/en/lti.php b/mod/lti/lang/en/lti.php index e0caae84a23..746879bf687 100644 --- a/mod/lti/lang/en/lti.php +++ b/mod/lti/lang/en/lti.php @@ -50,7 +50,7 @@ $string['acceptgrades'] = 'Accept grades from tool'; $string['activity'] = 'Activity'; $string['addnewapp'] = 'Enable External Application'; $string['addserver'] = 'Add new trusted server'; -$string['addtype'] = 'Create a new Basic LTI activity'; +$string['addtype'] = 'Add External Tool Configuration'; $string['allow'] = 'Allow'; $string['allowinstructorcustom'] = 'Allow instructors to add custom parameters'; $string['allowroster'] = 'Tool may access course roster'; @@ -75,7 +75,6 @@ $string['configpreferwidth'] = 'Default preferred width'; $string['configresourceurl'] = 'Default Resource URL'; $string['configtoolurl'] = 'Default Remote Tool URL'; $string['configtypes'] = 'Enable Basic LTI Applications'; -$string['configuredtools'] = 'Configured Basic LTI activities'; $string['courseid'] = 'Course id number'; $string['coursemisconf'] = 'Course is misconfigured'; $string['curllibrarymissing'] = 'PHP Curl library must be installed to use LTI'; @@ -171,6 +170,20 @@ $string['embed'] = 'Embed'; $string['embed_no_blocks'] = 'Embed, without blocks'; $string['new_window'] = 'New window'; $string['default_launch_container'] = 'Default Launch Container'; +$string['active'] = 'Active'; +$string['pending'] = 'Pending'; +$string['rejected'] = 'Rejected'; +$string['baseurl'] = 'Base URL'; +$string['action'] = 'Action'; +$string['createdon'] = 'Created On'; +$string['accept'] = 'Accept'; +$string['update'] = 'Update'; +$string['delete'] = 'Delete'; +$string['reject'] = 'Reject'; +$string['external_tool_types'] = 'External Tool Types'; +$string['no_lti_configured'] = 'There are no active External Tools configured.'; +$string['no_lti_pending'] = 'There are no pending External Tools.'; +$string['no_lti_external'] = 'There are no rejected External Tools.'; //New instructor strings $string['display_name'] = 'Display activity name when launched'; diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index afdc4ec1c60..2a4801c2a26 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -56,6 +56,10 @@ define('LTI_LAUNCH_CONTAINER_EMBED', 2); define('LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS', 3); define('LTI_LAUNCH_CONTAINER_WINDOW', 4); +define('LTI_TOOL_STATE_CONFIGURED', 1); +define('LTI_TOOL_STATE_PENDING', 2); +define('LTI_TOOL_STATE_REJECTED', 3); + /** * Prints a Basic LTI activity * @@ -302,7 +306,7 @@ function lti_get_type_config($typeid) { function lti_get_tools_by_domain($domain){ global $DB; - return $DB->get_records('lti_types', array('tooldomain' => $domain)); + return $DB->get_records('lti_types', array('tooldomain' => $domain, 'state' => LTI_TOOL_STATE_CONFIGURED)); } /** @@ -416,16 +420,24 @@ function lti_filter_print_types() { function lti_delete_type($id) { global $DB; + //We should probably just copy the launch URL to the tool instances in this case... using a single query + /* $instances = $DB->get_records('lti', array('typeid' => $id)); foreach ($instances as $instance) { $instance->typeid = 0; $DB->update_record('lti', $instance); - } + }*/ $DB->delete_records('lti_types', array('id' => $id)); $DB->delete_records('lti_types_config', array('typeid' => $id)); } +function lti_set_state_for_type($id, $state){ + global $DB; + + $DB->update_record('lti_types', array('id' => $id, 'state' => $state)); +} + /** * Transforms a basic LTI object to an array * @@ -494,9 +506,9 @@ function lti_get_type_type_config($id) { $config = lti_get_type_config($id); $type->lti_typename = $basicltitype->name; - if (isset($config['toolurl'])) { - $type->lti_toolurl = $config['toolurl']; - } + + $type->lti_toolurl = $basicltitype->baseurl; + if (isset($config['resourcekey'])) { $type->lti_resourcekey = $config['resourcekey']; } diff --git a/mod/lti/settings.php b/mod/lti/settings.php index 8b91db7ab63..169c5425896 100644 --- a/mod/lti/settings.php +++ b/mod/lti/settings.php @@ -47,37 +47,224 @@ defined('MOODLE_INTERNAL') || die; +global $PAGE, $CFG; + +require_once($CFG->dirroot.'/mod/lti/locallib.php'); + +function blti_get_tool_table($tools, $id){ + global $CFG, $USER; + $html = ''; + + $typename = get_string('typename', 'lti'); + $baseurl = get_string('baseurl', 'lti'); + $action = get_string('action', 'lti'); + $createdon = get_string('createdon', 'lti'); + + if (!empty($tools)) { + if($id == 'lti_configured'){ + $html .= ''.get_string('addtype', 'lti').''; + } + + $html .= << + + + + + + + + + +HTML; + + foreach ($tools as $type) { + $date = userdate($type->timecreated); + $accept = get_string('accept', 'lti'); + $update = get_string('update', 'lti'); + $delete = get_string('delete', 'lti'); + + $accepthtml = << + {$accept} + +HTML; + + $deleteaction = 'delete'; + + if($type->state == LTI_TOOL_STATE_CONFIGURED){ + $accepthtml = ''; + } + + if($type->state != LTI_TOOL_STATE_REJECTED) { + $deleteaction = 'reject'; + $delete = get_string('reject', 'lti'); + } + + $html .= << + + + + + +HTML; + } + $html .= '
$typename$baseurl$createdon$action
+ {$type->name} + + {$type->baseurl} + + {$date} + + {$accepthtml} + + {$update} + + + {$delete} + +
'; + } else { + $html .= get_string('no_' . $id, 'lti'); + } + + return $html; +} + if ($ADMIN->fulltree) { require_once($CFG->dirroot.'/mod/lti/locallib.php'); - $str = ''; + $configuredtoolshtml = ''; + $pendingtoolshtml = ''; + $rejectedtoolshtml = ''; - $types = lti_filter_get_types(); - if (!empty($types)) { - $str .= '

'.get_string('addtype', 'lti').'

'; - $str .= ''; - - foreach ($types as $type) { - $str .= ''. - ''. - ''. - ''; - - } - $str .= '
'.$type->name.''. - 'Update'.'  '. - ''. - 'Delete'. - ''. - '
'; - } else { - $str .= '
'; - $str .= '

'.get_string('addtype', 'lti').'

'; - $str .= get_string('notypes', 'lti'); - $str .= '
'; - } - - - $settings->add(new admin_setting_heading('lti_types', get_string('configuredtools', 'lti'), $str)); + $active = get_string('active', 'lti'); + $pending = get_string('pending', 'lti'); + $rejected = get_string('rejected', 'lti'); + $typename = get_string('typename', 'lti'); + $baseurl = get_string('baseurl', 'lti'); + $action = get_string('action', 'lti'); + $createdon = get_string('createdon', 'lti'); + $types = lti_filter_get_types(); + + $configuredtools = array_filter($types, function($value){ + return $value->state == LTI_TOOL_STATE_CONFIGURED; + }); + + $configuredtoolshtml = blti_get_tool_table($configuredtools, 'lti_configured'); + + $pendingtools = array_filter($types, function($value){ + return $value->state == LTI_TOOL_STATE_PENDING; + }); + + $pendingtoolshtml = blti_get_tool_table($pendingtools, 'lti_pending'); + + $rejectedtools = array_filter($types, function($value){ + return $value->state == LTI_TOOL_STATE_REJECTED; + }); + + $rejectedtoolshtml = blti_get_tool_table($rejectedtools, 'lti_rejected'); + + $tab = optional_param('tab', '', PARAM_ALPHAEXT); + $activeselected = ''; + $pendingselected = ''; + $rejectedselected = ''; + switch($tab){ + case 'lti_pending': + $pendingselected = 'class="selected"'; + break; + case 'lti_rejected': + $rejectedselected = 'class="selected"'; + break; + default: + $activeselected = 'class="selected"'; + break; + } + + $template = << + +
+
+ $configuredtoolshtml +
+
+ $pendingtoolshtml +
+
+ $rejectedtoolshtml +
+
+ + + +HTML; + + $PAGE->requires->yui2_lib('tabview'); + $PAGE->requires->yui2_lib('datatable'); + + $settings->add(new admin_setting_heading('lti_types', get_string('external_tool_types', 'lti'), $template /* $str*/)); } diff --git a/mod/lti/typessettings.php b/mod/lti/typessettings.php index 72f0639ae2f..4237b849687 100644 --- a/mod/lti/typessettings.php +++ b/mod/lti/typessettings.php @@ -67,13 +67,18 @@ $PAGE->set_url($url); admin_externalpage_setup('managemodules'); // Hacky solution for printing the admin page +$tab = optional_param('tab', '', PARAM_ALPHAEXT); +$redirect = "$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti&tab={$tab}"; + /// WRITING SUBMITTED DATA (IF ANY) ------------------------------------------------------------------------------- $statusmsg = ''; $errormsg = ''; $focus = ''; -if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton)) { +$data = data_submitted(); + +if (confirm_sesskey() && isset($data->submitbutton)) { $type = new StdClass(); $type->name = $data->lti_typename; $type->baseurl = $data->lti_toolurl; @@ -104,11 +109,12 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton } } } - redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti"); + redirect($redirect); die; } else { $type->createdby = $USER->id; $type->timecreated = time(); + $type->state = LTI_TOOL_STATE_CONFIGURED; //Create a salt value to be used for signing passed data to extension services $data->lti_servicesalt = uniqid('', true); @@ -133,22 +139,29 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton } else { $errormsg = get_string('errorwithsettings', 'admin'); } - redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti"); + redirect($redirect); die; } +} else if(isset($data->cancel)){ + redirect($redirect); + die; +} + +if ($action == 'accept') { + lti_set_state_for_type($id, LTI_TOOL_STATE_CONFIGURED); + redirect($redirect); + die; +} + +if ($action == 'reject') { + lti_set_state_for_type($id, LTI_TOOL_STATE_REJECTED); + redirect($redirect); + die; } if ($action == 'delete') { lti_delete_type($id); - redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti"); - die; -} - -if (($action == 'fix') && isset($useexisting)) { - $instance = $DB->get_record('lti', array('id' => $id)); - $instance->typeid = $useexisting; - $DB->update_record('lti', $instance); - redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti"); + redirect($redirect); die; } diff --git a/mod/lti/view.php b/mod/lti/view.php index bed0e6f44a4..36568338810 100644 --- a/mod/lti/view.php +++ b/mod/lti/view.php @@ -92,8 +92,8 @@ $launchcontainer = $basiclti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT ? $basiclti->launchcontainer; if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS){ - $PAGE->set_pagelayout('frametop'); //Use the frametop layout to get the navbar, but no footer - $PAGE->blocks->show_only_fake_blocks(); //Disable blocks + $PAGE->set_pagelayout('frametop'); //Most frametops don't include footer, and pre-post blocks + $PAGE->blocks->show_only_fake_blocks(); //Disable blocks for layouts which do include pre-post blocks } else { $PAGE->set_pagelayout('incourse'); } @@ -159,7 +159,7 @@ if ( $launchcontainer == LTI_LAUNCH_CONTAINER_WINDOW ) { setInterval(resize, 250); })(); - //]] + //]] SCRIPT; From f5134df4348deedda7114ca6747377ad4522ae73 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Wed, 31 Aug 2011 18:33:42 -0400 Subject: [PATCH 09/78] Fixing localization string --- mod/lti/lang/en/lti.php | 2 +- mod/lti/typessettings.php | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/mod/lti/lang/en/lti.php b/mod/lti/lang/en/lti.php index 746879bf687..7f733d81a73 100644 --- a/mod/lti/lang/en/lti.php +++ b/mod/lti/lang/en/lti.php @@ -183,7 +183,7 @@ $string['reject'] = 'Reject'; $string['external_tool_types'] = 'External Tool Types'; $string['no_lti_configured'] = 'There are no active External Tools configured.'; $string['no_lti_pending'] = 'There are no pending External Tools.'; -$string['no_lti_external'] = 'There are no rejected External Tools.'; +$string['no_lti_rejected'] = 'There are no rejected External Tools.'; //New instructor strings $string['display_name'] = 'Display activity name when launched'; diff --git a/mod/lti/typessettings.php b/mod/lti/typessettings.php index 4237b849687..12386e0f8b1 100644 --- a/mod/lti/typessettings.php +++ b/mod/lti/typessettings.php @@ -218,8 +218,6 @@ if (empty($SITE->fullname)) { echo $OUTPUT->header(); - - if ($errormsg !== '') { echo $OUTPUT->notification($errormsg); From a0eeacf9c73ba39b5574f2ddfd805498e3e07b28 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Thu, 1 Sep 2011 13:22:08 -0400 Subject: [PATCH 10/78] Fixing issues with launching a tool which is not configured in the admin side, and improving utility methods for determing if a tool should be registered --- mod/lti/db/install.xml | 13 ++++-- mod/lti/locallib.php | 101 ++++++++++++++++++++++++++++++++++------- mod/lti/view.php | 6 ++- 3 files changed, 98 insertions(+), 22 deletions(-) diff --git a/mod/lti/db/install.xml b/mod/lti/db/install.xml index 14e77cc4692..f606a694b2d 100644 --- a/mod/lti/db/install.xml +++ b/mod/lti/db/install.xml @@ -1,5 +1,5 @@ - @@ -22,10 +22,13 @@ - - + + + + - + + @@ -42,7 +45,7 @@ - + diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index 2a4801c2a26..e0fc4aed843 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -60,26 +60,47 @@ define('LTI_TOOL_STATE_CONFIGURED', 1); define('LTI_TOOL_STATE_PENDING', 2); define('LTI_TOOL_STATE_REJECTED', 3); +define('LTI_SETTING_NEVER', 0); +define('LTI_SETTING_ALWAYS', 1); +define('LTI_SETTING_DEFAULT', 2); + /** * Prints a Basic LTI activity * * $param int $basicltiid Basic LTI activity id */ function lti_view($instance, $makeobject=false) { - global $PAGE; + global $PAGE, $CFG; if(empty($instance->typeid)){ $tool = lti_get_tool_by_url_match($instance->toolurl); if($tool){ $typeid = $tool->id; } else { - //Tool not found + $typeid = null; } } else { $typeid = $instance->typeid; } - $typeconfig = lti_get_type_config($typeid); + if($typeid){ + $typeconfig = lti_get_type_config($typeid); + } else { + //There is no admin configuration for this tool. Use configuration in the lti instance record plus some defaults. + $typeconfig = (array)$instance; + + $typeconfig['sendname'] = $instance->instructorchoicesendname; + $typeconfig['sendemailaddr'] = $instance->instructorchoicesendemailaddr; + $typeconfig['customparameters'] = $instance->instructorcustomparameters; + } + + //Default the organizationid if not specified + if(empty($typeconfig['organizationid'])){ + $urlparts = parse_url($CFG->wwwroot); + + $typeconfig['organizationid'] = $urlparts['host']; + } + $endpoint = !empty($instance->toolurl) ? $instance->toolurl : $typeconfig['toolurl']; $key = !empty($instance->resourcekey) ? $instance->resourcekey : $typeconfig['resourcekey']; $secret = !empty($instance->password) ? $instance->password : $typeconfig['password']; @@ -104,8 +125,6 @@ function lti_view($instance, $makeobject=false) { $content = post_launch_html($parms, $endpoint, $debuglaunch); -// $cm = get_coursemodule_from_instance("lti", $instance->id); -// print ''.$content.''; echo $content; } @@ -303,10 +322,42 @@ function lti_get_type_config($typeid) { return $typeconfig; } -function lti_get_tools_by_domain($domain){ - global $DB; +function lti_get_tools_by_url($url, $state){ + $domain = lti_get_domain_from_url($url); - return $DB->get_records('lti_types', array('tooldomain' => $domain, 'state' => LTI_TOOL_STATE_CONFIGURED)); + return lti_get_tools_by_domain($domain, $state); +} + +function lti_get_tools_by_domain($domain, $state = null, $courseid = null){ + global $DB, $SITE; + + $filters = array('tooldomain' => $domain); + + $statefilter = ''; + $coursefilter = ''; + + if($state){ + $statefilter = 'AND state = :state'; + } + + if($courseid && $courseid != $SITE->id){ + $coursefilter = 'OR course = :courseid'; + } + + $query = <<get_records_sql($query, array( + 'courseid' => $courseid, + 'siteid' => $SITE->id, + 'tooldomain' => $domain, + 'state' => $state + )); } /** @@ -341,29 +392,42 @@ function lti_get_domain_from_url($url){ } } -function lti_get_tool_by_url_match($url){ - $domain = lti_get_domain_from_url($url); - - $possibletools = lti_get_tools_by_domain($domain); +function lti_get_tool_by_url_match($url, $courseid = null){ + $possibletools = lti_get_tools_by_url($url, LTI_TOOL_STATE_CONFIGURED, $courseid); return lti_get_best_tool_by_url($url, $possibletools); } +function lti_get_url_thumbprint($url){ + $urlparts = parse_url(strtolower($url)); + if(!isset($urlparts['path'])){ + $urlparts['path'] = ''; + } + + if(substr($urlparts['host'], 0, 3) === 'www'){ + $urllparts['host'] = substr(3); + } + + return $urllower = $urlparts['host'] . '/' . $urlparts['path']; +} + function lti_get_best_tool_by_url($url, $tools){ if(count($tools) === 0){ return null; } - $urllower = strtolower($url); + $urllower = lti_get_url_thumbprint($url); foreach($tools as $tool){ $tool->_matchscore = 0; - - $toolbaseurllower = strtolower($tool->baseurl); + + $toolbaseurllower = lti_get_url_thumbprint($tool->baseurl); if($urllower === $toolbaseurllower){ + //100 points for exact match $tool->_matchscore += 100; - } else if(strstr($urllower, $toolbaseurllower) >= 0){ + } else if(substr($urllower, 0, strlen($toolbaseurllower)) === $toolbaseurllower){ + //50 points if it starts with the base URL $tool->_matchscore += 50; } } @@ -377,6 +441,11 @@ function lti_get_best_tool_by_url($url, $tools){ }, (object)array('_matchscore' => -1)); + //None of the tools are suitable for this URL + if($bestmatch->_matchscore <= 0){ + return null; + } + return $bestmatch; } diff --git a/mod/lti/view.php b/mod/lti/view.php index 36568338810..1a1a533656a 100644 --- a/mod/lti/view.php +++ b/mod/lti/view.php @@ -78,7 +78,11 @@ if ($id) { } $tool = lti_get_tool_by_url_match($basiclti->toolurl); -$toolconfig = lti_get_type_config($tool->id); +if($tool){ + $toolconfig = lti_get_type_config($tool->id); +} else { + $toolconfig = array('launchcontainer' => LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS); +} $PAGE->set_cm($cm, $course); // set's up global $COURSE $context = get_context_instance(CONTEXT_MODULE, $cm->id); From 57e8c4752aadf3f8fb1245db3a12342117142baa Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Thu, 1 Sep 2011 13:26:37 -0400 Subject: [PATCH 11/78] Allowing tools be added even if none exist --- mod/lti/settings.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mod/lti/settings.php b/mod/lti/settings.php index 169c5425896..92193ff2042 100644 --- a/mod/lti/settings.php +++ b/mod/lti/settings.php @@ -60,11 +60,11 @@ function blti_get_tool_table($tools, $id){ $action = get_string('action', 'lti'); $createdon = get_string('createdon', 'lti'); + if($id == 'lti_configured'){ + $html .= ''.get_string('addtype', 'lti').''; + } + if (!empty($tools)) { - if($id == 'lti_configured'){ - $html .= ''.get_string('addtype', 'lti').''; - } - $html .= << From 560ed50ca5c34bb055e58ccd5cc964a7efcb23ad Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Thu, 1 Sep 2011 13:27:33 -0400 Subject: [PATCH 12/78] Adding a newline --- mod/lti/settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/lti/settings.php b/mod/lti/settings.php index 92193ff2042..aabdfa5ca0e 100644 --- a/mod/lti/settings.php +++ b/mod/lti/settings.php @@ -61,7 +61,7 @@ function blti_get_tool_table($tools, $id){ $createdon = get_string('createdon', 'lti'); if($id == 'lti_configured'){ - $html .= ''.get_string('addtype', 'lti').''; + $html .= ''; } if (!empty($tools)) { From 879e97bd3b69ba0bbe3ab74ccca6423a6e82d60b Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Thu, 1 Sep 2011 13:52:09 -0400 Subject: [PATCH 13/78] Extracting add/edit type functions for reuse --- mod/lti/locallib.php | 78 ++++++++++++++++++++++++++++++++++++++- mod/lti/typessettings.php | 54 ++------------------------- 2 files changed, 80 insertions(+), 52 deletions(-) diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index e0fc4aed843..da2d545d087 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -56,6 +56,7 @@ define('LTI_LAUNCH_CONTAINER_EMBED', 2); define('LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS', 3); define('LTI_LAUNCH_CONTAINER_WINDOW', 4); +define('LTI_TOOL_STATE_ANY', 0); define('LTI_TOOL_STATE_CONFIGURED', 1); define('LTI_TOOL_STATE_PENDING', 2); define('LTI_TOOL_STATE_REJECTED', 3); @@ -392,8 +393,8 @@ function lti_get_domain_from_url($url){ } } -function lti_get_tool_by_url_match($url, $courseid = null){ - $possibletools = lti_get_tools_by_url($url, LTI_TOOL_STATE_CONFIGURED, $courseid); +function lti_get_tool_by_url_match($url, $courseid = null, $state = LTI_TOOL_STATE_CONFIGURED){ + $possibletools = lti_get_tools_by_url($url, $state, $courseid); return lti_get_best_tool_by_url($url, $possibletools); } @@ -642,6 +643,79 @@ function lti_get_type_type_config($id) { return $type; } +function lti_prepare_type_for_save($type, $config){ + $type->baseurl = $config->lti_toolurl; + $type->tooldomain = lti_get_domain_from_url($config->lti_toolurl); + $type->name = $config->lti_typename; + + $type->coursevisible = !empty($config->lti_coursevisible) ? $config->lti_coursevisible : 0; + $config->lti_coursevisible = $type->coursevisible; + + $type->timemodified = time(); + + unset ($config->lti_typename); + unset ($config->lti_toolurl); +} + +function lti_update_type($type, $config){ + global $DB; + + lti_prepare_type_for_save($type, $config); + + if ($DB->update_record('lti_types', $type)) { + foreach ($config as $key => $value) { + if (substr($key, 0, 4)=='lti_' && !is_null($value)) { + $record = new StdClass(); + $record->typeid = $type->id; + $record->name = substr($key, 4); + $record->value = $value; + + lti_update_config($record); + } + } + } +} + +function lti_add_type($type, $config){ + global $USER, $SITE, $DB; + + lti_prepare_type_for_save($type, $config); + + if(!isset($type->state)){ + $type->state = LTI_TOOL_STATE_PENDING; + } + + if(!isset($type->timecreated)){ + $type->timecreated = time(); + } + + if(!isset($type->createdby)){ + $type->createdby = $USER->id; + } + + if(!isset($type->course)){ + $type->course = $SITE->id; + } + + //Create a salt value to be used for signing passed data to extension services + $config->lti_servicesalt = uniqid('', true); + + $id = $DB->insert_record('lti_types', $type); + + if ($id) { + foreach ($config as $key => $value) { + if (substr($key, 0, 4)=='lti_' && !is_null($value)) { + $record = new StdClass(); + $record->typeid = $id; + $record->name = substr($key, 4); + $record->value = $value; + + lti_add_config($record); + } + } + } +} + /** * Add a tool configuration in the database * diff --git a/mod/lti/typessettings.php b/mod/lti/typessettings.php index 12386e0f8b1..20f3fda4e41 100644 --- a/mod/lti/typessettings.php +++ b/mod/lti/typessettings.php @@ -80,65 +80,19 @@ $data = data_submitted(); if (confirm_sesskey() && isset($data->submitbutton)) { $type = new StdClass(); - $type->name = $data->lti_typename; - $type->baseurl = $data->lti_toolurl; - $type->tooldomain = lti_get_domain_from_url($data->lti_toolurl); - $type->course = $SITE->id; - $type->coursevisible = !empty($data->lti_coursevisible) ? $data->lti_coursevisible : 0; - $type->timemodified = time(); - - $data->lti_coursevisible = $type->coursevisible;//When not checked, it does not appear in data array. Set it manually. if (isset($id)) { $type->id = $id; + + lti_update_type($type, $data); - if ($DB->update_record('lti_types', $type)) { - unset ($data->lti_typename); - - foreach ($data as $key => $value) { - if (substr($key, 0, 4)=='lti_' && !is_null($value)) { - $record = new StdClass(); - $record->typeid = $id; - $record->name = substr($key, 4); - $record->value = $value; - if (lti_update_config($record)) { - $statusmsg = get_string('changessaved'); - } else { - $errormsg = get_string('errorwithsettings', 'admin'); - } - } - } - } redirect($redirect); die; } else { - $type->createdby = $USER->id; - $type->timecreated = time(); $type->state = LTI_TOOL_STATE_CONFIGURED; + + lti_add_type($type, $data); - //Create a salt value to be used for signing passed data to extension services - $data->lti_servicesalt = uniqid('', true); - - $id = $DB->insert_record('lti_types', $type); - - if ($id) { - unset ($data->lti_typename); - foreach ($data as $key => $value) { - if (substr($key, 0, 4)=='lti_' && !is_null($value)) { - $record = new StdClass(); - $record->typeid = $id; - $record->name = substr($key, 4); - $record->value = $value; - if (lti_add_config($record)) { - $statusmsg = get_string('changessaved'); - } else { - $errormsg = get_string('errorwithsettings', 'admin'); - } - } - } - } else { - $errormsg = get_string('errorwithsettings', 'admin'); - } redirect($redirect); die; } From 844afad045e859e06c5c630149835b8a4ad33f2f Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Thu, 1 Sep 2011 14:01:56 -0400 Subject: [PATCH 14/78] Tool base URLs don't need to start with http(s) --- mod/lti/edit_form.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/mod/lti/edit_form.php b/mod/lti/edit_form.php index 73121312b1f..3c998d45eaa 100644 --- a/mod/lti/edit_form.php +++ b/mod/lti/edit_form.php @@ -64,12 +64,9 @@ class mod_lti_edit_types_form extends moodleform{ // $mform->addHelpButton('lti_typename', 'typename','lti'); $mform->addRule('lti_typename', null, 'required', null, 'client'); - $regex = '/^(http|https):\/\/([a-z0-9-]\.+)*/i'; - $mform->addElement('text', 'lti_toolurl', get_string('toolurl', 'lti'), array('size'=>'64')); $mform->setType('lti_toolurl', PARAM_TEXT); // $mform->addHelpButton('lti_toolurl', 'toolurl', 'lti'); - $mform->addRule('lti_toolurl', get_string('validurl', 'lti'), 'regex', $regex, 'client'); $mform->addRule('lti_toolurl', null, 'required', null, 'client'); $mform->addElement('text', 'lti_resourcekey', get_string('resourcekey', 'lti')); From aa6eca66df12cc715422762359c443b8327e94ac Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Thu, 1 Sep 2011 14:17:59 -0400 Subject: [PATCH 15/78] Setting some default parameters when adding an lti instance --- mod/lti/lib.php | 2017 ++++++++++++++++++++++++----------------------- 1 file changed, 1010 insertions(+), 1007 deletions(-) diff --git a/mod/lti/lib.php b/mod/lti/lib.php index abb51dd4201..c1ee7c611e7 100644 --- a/mod/lti/lib.php +++ b/mod/lti/lib.php @@ -1,1007 +1,1010 @@ -. - -/** - * This file contains a library of functions and constants for the - * BasicLTI module - * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis - * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die; - -require_once($CFG->dirroot.'/mod/lti/locallib.php'); - -/** - * List of features supported in URL module - * @param string $feature FEATURE_xx constant for requested feature - * @return mixed True if module supports feature, false if not, null if doesn't know - */ -function lti_supports($feature) { - switch($feature) { - case FEATURE_GROUPS: return false; - case FEATURE_GROUPINGS: return false; - case FEATURE_GROUPMEMBERSONLY: return true; - case FEATURE_MOD_INTRO: return true; - case FEATURE_COMPLETION_TRACKS_VIEWS: return true; - case FEATURE_GRADE_HAS_GRADE: return true; - case FEATURE_GRADE_OUTCOMES: return true; - case FEATURE_BACKUP_MOODLE2: return true; - - default: return null; - } -} - -/** - * Given an object containing all the necessary data, - * (defined by the form in mod.html) this function - * will create a new instance and return the id number - * of the new instance. - * - * @param object $instance An object from the form in mod.html - * @return int The id of the newly inserted basiclti record - **/ -function lti_add_instance($formdata) { - global $DB; - $formdata->timecreated = time(); - $formdata->timemodified = $formdata->timecreated; - //$basiclti->placementsecret = uniqid('', true); - //$basiclti->timeplacementsecret = time(); - - $id = $DB->insert_record("lti", $formdata); - - if ($formdata->instructorchoiceacceptgrades == 1) { - $basiclti = $DB->get_record('lti', array('id'=>$id)); - $basiclti->cmidnumber = $formdata->cmidnumber; - - lti_grade_item_update($basiclti); - } - - return $id; -} - -/** - * Given an object containing all the necessary data, - * (defined by the form in mod.html) this function - * will update an existing instance with new data. - * - * @param object $instance An object from the form in mod.html - * @return boolean Success/Fail - **/ -function lti_update_instance($formdata) { - global $DB; - - $formdata->timemodified = time(); - $formdata->id = $formdata->instance; - - if(!isset($formdata->showtitle)){ - $formdata->showtitle = 0; - } - - if(!isset($formdata->showdescription)){ - $formdata->showdescription = 0; - } - - if ($formdata->instructorchoiceacceptgrades == 1) { - $basicltirec = $DB->get_record("lti", array("id" => $formdata->id)); - $basicltirec->cmidnumber = $formdata->cmidnumber; - - lti_grade_item_update($basicltirec); - } else { - lti_grade_item_delete($formdata); - } - - return $DB->update_record("lti", $formdata); -} - -/** - * Given an ID of an instance of this module, - * this function will permanently delete the instance - * and any data that depends on it. - * - * @param int $id Id of the module instance - * @return boolean Success/Failure - **/ -function lti_delete_instance($id) { - global $DB; - - if (! $basiclti = $DB->get_record("lti", array("id" => $id))) { - return false; - } - - $result = true; - - # Delete any dependent records here # - lti_grade_item_delete($basiclti); - - return $DB->delete_records("lti", array("id" => $basiclti->id)); -} - -/** - * Return a small object with summary information about what a - * user has done with a given particular instance of this module - * Used for user activity reports. - * $return->time = the time they did it - * $return->info = a short text description - * - * @return null - * @TODO: implement this moodle function (if needed) - **/ -function lti_user_outline($course, $user, $mod, $basiclti) { - return $return; -} - -/** - * Print a detailed representation of what a user has done with - * a given particular instance of this module, for user activity reports. - * - * @return boolean - * @TODO: implement this moodle function (if needed) - **/ -function lti_user_complete($course, $user, $mod, $basiclti) { - return true; -} - -/** - * Given a course and a time, this module should find recent activity - * that has occurred in basiclti activities and print it out. - * Return true if there was output, or false is there was none. - * - * @uses $CFG - * @return boolean - * @TODO: implement this moodle function - **/ -function lti_print_recent_activity($course, $isteacher, $timestart) { - return false; // True if anything was printed, otherwise false -} - -/** - * Function to be run periodically according to the moodle cron - * This function searches for things that need to be done, such - * as sending out mail, toggling flags etc ... - * - * @uses $CFG - * @return boolean - **/ -function lti_cron () { - return true; -} - -/** - * Must return an array of grades for a given instance of this module, - * indexed by user. It also returns a maximum allowed grade. - * - * Example: - * $return->grades = array of grades; - * $return->maxgrade = maximum allowed grade; - * - * return $return; - * - * @param int $basicltiid ID of an instance of this module - * @return mixed Null or object with an array of grades and with the maximum grade - * - * @TODO: implement this moodle function (if needed) - **/ -function lti_grades($basicltiid) { - return null; -} - -/** - * Must return an array of user records (all data) who are participants - * for a given instance of basiclti. Must include every user involved - * in the instance, independient of his role (student, teacher, admin...) - * See other modules as example. - * - * @param int $basicltiid ID of an instance of this module - * @return mixed boolean/array of students - * - * @TODO: implement this moodle function - **/ -function lti_get_participants($basicltiid) { - return false; -} - -/** - * This function returns if a scale is being used by one basiclti - * it it has support for grading and scales. Commented code should be - * modified if necessary. See forum, glossary or journal modules - * as reference. - * - * @param int $basicltiid ID of an instance of this module - * @return mixed - * - * @TODO: implement this moodle function (if needed) - **/ -function lti_scale_used ($basicltiid, $scaleid) { - $return = false; - - //$rec = get_record("basiclti","id","$basicltiid","scale","-$scaleid"); - // - //if (!empty($rec) && !empty($scaleid)) { - // $return = true; - //} - - return $return; -} - -/** - * Checks if scale is being used by any instance of basiclti. - * This function was added in 1.9 - * - * This is used to find out if scale used anywhere - * @param $scaleid int - * @return boolean True if the scale is used by any basiclti - * - */ -function lti_scale_used_anywhere($scaleid) { - global $DB; - - if ($scaleid and $DB->record_exists('lti', array('grade' => -$scaleid))) { - return true; - } else { - return false; - } -} - -/** - * Execute post-install custom actions for the module - * This function was added in 1.9 - * - * @return boolean true if success, false on error - */ -function lti_install() { - return true; -} - -/** - * Execute post-uninstall custom actions for the module - * This function was added in 1.9 - * - * @return boolean true if success, false on error - */ -function lti_uninstall() { - return true; -} - -/** - * Returns available Basic LTI types - * - * @return array of basicLTI types - */ -function lti_get_lti_types() { - global $DB; - - return $DB->get_records('lti_types'); -} - -/** - * Returns Basic LTI types configuration - * - * @return array of basicLTI types - */ -/*function lti_get_types() { - $types = array(); - - $basicltitypes = lti_get_lti_types(); - if (!empty($basicltitypes)) { - foreach ($basicltitypes as $basicltitype) { - $ltitypesconfig = lti_get_type_config($basicltitype->id); - - $modclass = MOD_CLASS_ACTIVITY; - if (isset($ltitypesconfig['module_class_type'])) { - if ($ltitypesconfig['module_class_type']=='1') { - $modclass = MOD_CLASS_RESOURCE; - } - } - - $type = new object(); - $type->modclass = $modclass; - $type->type = 'lti&type='.urlencode($basicltitype->rawname); - $type->typestr = $basicltitype->name; - $types[] = $type; - } - } - - return $types; -}*/ - -////////////////////////////////////////////////////////////////////////////////////// -/// Any other basiclti functions go here. Each of them must have a name that -/// starts with basiclti_ -/// Remember (see note in first lines) that, if this section grows, it's HIGHLY -/// recommended to move all funcions below to a new "localib.php" file. - -///** -// * -// */ -//function process_outcomes($userid, $course, $basiclti) { -// global $CFG, $USER; -// -// if (empty($CFG->enableoutcomes)) { -// return; -// } -// -// require_once($CFG->libdir.'/gradelib.php'); -// -// if (!$formdata = data_submitted() or !confirm_sesskey()) { -// return; -// } -// -// $data = array(); -// $grading_info = grade_get_grades($course->id, 'mod', 'basiclti', $basiclti->id, $userid); -// -// if (!empty($grading_info->outcomes)) { -// foreach ($grading_info->outcomes as $n => $old) { -// $name = 'outcome_'.$n; -// if (isset($formdata->{$name}[$userid]) and $old->grades[$userid]->grade != $formdata->{$name}[$userid]) { -// $data[$n] = $formdata->{$name}[$userid]; -// } -// } -// } -// if (count($data) > 0) { -// grade_update_outcomes('mod/basiclti', $course->id, 'mod', 'basiclti', $basiclti->id, $userid, $data); -// } -// -//} - -/** - * Top-level function for handling of submissions called by submissions.php - * - * This is for handling the teacher interaction with the grading interface - * - * @global object - * @param string $mode Specifies the kind of teacher interaction taking place - */ -function lti_submissions($cm, $course, $basiclti, $mode) { - ///The main switch is changed to facilitate - ///1) Batch fast grading - ///2) Skip to the next one on the popup - ///3) Save and Skip to the next one on the popup - - //make user global so we can use the id - global $USER, $OUTPUT, $DB; - - $mailinfo = optional_param('mailinfo', null, PARAM_BOOL); - - if (optional_param('next', null, PARAM_BOOL)) { - $mode='next'; - } - if (optional_param('saveandnext', null, PARAM_BOOL)) { - $mode='saveandnext'; - } - - if (is_null($mailinfo)) { - if (optional_param('sesskey', null, PARAM_BOOL)) { - set_user_preference('lti_mailinfo', $mailinfo); - } else { - $mailinfo = get_user_preferences('lti_mailinfo', 0); - } - } else { - set_user_preference('lti_mailinfo', $mailinfo); - } - - switch ($mode) { - case 'grade': // We are in a main window grading - if ($submission = process_feedback()) { - lti_display_submissions($cm, $course, $basiclti, get_string('changessaved')); - } else { - lti_display_submissions($cm, $course, $basiclti); - } - break; - - case 'single': // We are in a main window displaying one submission - if ($submission = process_feedback()) { - lti_display_submissions($cm, $course, $basiclti, get_string('changessaved')); - } else { - display_submission(); - } - break; - - case 'all': // Main window, display everything - lti_display_submissions($cm, $course, $basiclti); - break; - - case 'fastgrade': - /// do the fast grading stuff - this process should work for all 3 subclasses - $grading = false; - $commenting = false; - $col = false; - if (isset($_POST['submissioncomment'])) { - $col = 'submissioncomment'; - $commenting = true; - } - if (isset($_POST['menu'])) { - $col = 'menu'; - $grading = true; - } - if (!$col) { - //both submissioncomment and grade columns collapsed.. - lti_display_submissions($cm, $course, $basiclti); - break; - } - - foreach ($_POST[$col] as $id => $unusedvalue) { - - $id = (int)$id; //clean parameter name - - // Get grade item - $gradeitem = $DB->get_record('grade_items', array('courseid' => $cm->course, 'iteminstance' => $cm->instance)); - - // Get grade - $gradeentry = $DB->get_record('grade_grades', array('userid' => $id, 'itemid' => $gradeitem->id)); - - $grade = $_POST['menu'][$id]; - $feedback = trim($_POST['submissioncomment'][$id]); - - if ((!$gradeentry) && (($grade != '-1') || ($feedback != ''))) { - $newsubmission = true; - } else { - $newsubmission = false; - } - - //for fast grade, we need to check if any changes take place - $updatedb = false; - - if ($gradeentry) { - if ($grading) { - $grade = $_POST['menu'][$id]; - $updatedb = $updatedb || (($gradeentry->rawgrade != $grade) && ($gradeentry->rawgrade != '-1')); - if ($grade != '-1') { - $gradeentry->rawgrade = $grade; - $gradeentry->finalgrade = $grade; - } else { - $gradeentry->rawgrade = null; - $gradeentry->finalgrade = null; - } - } else { - if (!$newsubmission) { - unset($gradeentry->rawgrade); // Don't need to update this. - } - } - - if ($commenting) { - $commentvalue = trim($_POST['submissioncomment'][$id]); - $updatedb = $updatedb || ($gradeentry->feedback != $commentvalue); - // Special case - if (($gradeentry->feedback == null) && ($commentvalue == "")) { - unset($gradeentry->feedback); - } - $gradeentry->feedback = $commentvalue; - } else { - unset($gradeentry->feedback); // Don't need to update this. - } - - } else { // No previous grade entry found - if ($newsubmission) { - if ($grade != '-1') { - $gradeentry->rawgrade = $grade; - $updatedb = true; - } - if ($feedback != '') { - $gradeentry->feedback = $feedback; - $updatedb = true; - } - } - } - - $gradeentry->usermodified = $USER->id; - if (!$gradeentry->timecreated) { - $gradeentry->timecreated = time(); - } - $gradeentry->timemodified = time(); - - //if it is not an update, we don't change the last modified time etc. - //this will also not write into database if no submissioncomment and grade is entered. - if ($updatedb) { - if ($gradeentry->rawgrade == '-1') { - $gradeentry->rawgrade = null; - } - - if ($newsubmission) { - if (!isset($gradeentry->feedback)) { - $gradeentry->feedback = ''; - } - $gradeentry->itemid = $gradeitem->id; - $gradeentry->userid = $id; - $sid = $DB->insert_record("grade_grades", $gradeentry); - $gradeentry->id = $sid; - } else { - $DB->update_record("grade_grades", $gradeentry); - } - - //add to log only if updating - add_to_log($course->id, 'lti', 'update grades', - 'submissions.php?id='.$cm->id.'&user='.$USER->id, - $USER->id, $cm->id); - } - - } - - $message = $OUTPUT->notification(get_string('changessaved'), 'notifysuccess'); - - lti_display_submissions($cm, $course, $basiclti, $message); - break; - - case 'saveandnext': - ///We are in pop up. save the current one and go to the next one. - //first we save the current changes - if ($submission = process_feedback()) { - //print_heading(get_string('changessaved')); - //$extra_javascript = $this->update_main_listing($submission); - } - - case 'next': - /// We are currently in pop up, but we want to skip to next one without saving. - /// This turns out to be similar to a single case - /// The URL used is for the next submission. - $offset = required_param('offset', PARAM_INT); - $nextid = required_param('nextid', PARAM_INT); - $id = required_param('id', PARAM_INT); - $offset = (int)$offset+1; - //$this->display_submission($offset+1 , $nextid); - redirect('submissions.php?id='.$id.'&userid='. $nextid . '&mode=single&offset='.$offset); - break; - - case 'singlenosave': - display_submission(); - break; - - default: - echo "Critical error. Something is seriously wrong!!"; - break; - } -} - -/** - * Display all the submissions ready for grading - * - * @global object - * @global object - * @global object - * @global object - * @param string $message - * @return bool|void - */ -function lti_display_submissions($cm, $course, $basiclti, $message='') { - global $CFG, $DB, $OUTPUT, $PAGE; - require_once($CFG->libdir.'/gradelib.php'); - - /* first we check to see if the form has just been submitted - * to request user_preference updates - */ - $updatepref = optional_param('updatepref', 0, PARAM_INT); - - if (isset($_POST['updatepref'])) { - $perpage = optional_param('perpage', 10, PARAM_INT); - $perpage = ($perpage <= 0) ? 10 : $perpage; - $filter = optional_param('filter', 0, PARAM_INT); - set_user_preference('lti_perpage', $perpage); - set_user_preference('lti_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL)); - set_user_preference('lti_filter', $filter); - } - - /* next we get perpage and quickgrade (allow quick grade) params - * from database - */ - $perpage = get_user_preferences('lti_perpage', 10); - $quickgrade = get_user_preferences('lti_quickgrade', 0); - $filter = get_user_preferences('lti_filter', 0); - $grading_info = grade_get_grades($course->id, 'mod', 'lti', $basiclti->id); - - if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) { - $uses_outcomes = true; - } else { - $uses_outcomes = false; - } - - $page = optional_param('page', 0, PARAM_INT); - $strsaveallfeedback = get_string('saveallfeedback', 'lti'); - - $tabindex = 1; //tabindex for quick grading tabbing; Not working for dropdowns yet - add_to_log($course->id, 'lti', 'view submission', 'submissions.php?id='.$cm->id, $basiclti->id, $cm->id); - - $PAGE->set_title(format_string($basiclti->name, true)); - $PAGE->set_heading($course->fullname); - echo $OUTPUT->header(); - - echo '
'; - - //hook to allow plagiarism plugins to update status/print links. - plagiarism_update_status($course, $cm); - - /// Print quickgrade form around the table - if ($quickgrade) { - $formattrs = array(); - $formattrs['action'] = new moodle_url('/mod/lti/submissions.php'); - $formattrs['id'] = 'fastg'; - $formattrs['method'] = 'post'; - - echo html_writer::start_tag('form', $formattrs); - echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=> $cm->id)); - echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'mode', 'value'=> 'fastgrade')); - echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'page', 'value'=> $page)); - echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=> sesskey())); - } - - $course_context = get_context_instance(CONTEXT_COURSE, $course->id); - if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) { - echo ''; - } - - if (!empty($message)) { - echo $message; // display messages here if any - } - - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - -/// Check to see if groups are being used in this tool - - /// find out current groups mode - $groupmode = groups_get_activity_groupmode($cm); - $currentgroup = groups_get_activity_group($cm, true); - groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/lti/submissions.php?id=' . $cm->id); - - /// Get all ppl that are allowed to submit tools - list($esql, $params) = get_enrolled_sql($context, 'mod/lti:view', $currentgroup); - - $sql = "SELECT u.id FROM {user} u ". - "LEFT JOIN ($esql) eu ON eu.id=u.id ". - "WHERE u.deleted = 0 AND eu.id=u.id "; - - $users = $DB->get_records_sql($sql, $params); - if (!empty($users)) { - $users = array_keys($users); - } - - // if groupmembersonly used, remove users who are not in any group - if ($users and !empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) { - if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) { - $users = array_intersect($users, array_keys($groupingusers)); - } - } - - $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade'); - if ($uses_outcomes) { - $tablecolumns[] = 'outcome'; // no sorting based on outcomes column - } - - $tableheaders = array('', - get_string('fullname'), - get_string('grade'), - get_string('comment', 'lti'), - get_string('lastmodified').' ('.get_string('submission', 'lti').')', - get_string('lastmodified').' ('.get_string('grade').')', - get_string('status'), - get_string('finalgrade', 'grades')); - if ($uses_outcomes) { - $tableheaders[] = get_string('outcome', 'grades'); - } - - require_once($CFG->libdir.'/tablelib.php'); - $table = new flexible_table('mod-lti-submissions'); - - $table->define_columns($tablecolumns); - $table->define_headers($tableheaders); - $table->define_baseurl($CFG->wwwroot.'/mod/lti/submissions.php?id='.$cm->id.'&currentgroup='.$currentgroup); - - $table->sortable(true, 'lastname');//sorted by lastname by default - $table->collapsible(true); - $table->initialbars(true); - - $table->column_suppress('picture'); - $table->column_suppress('fullname'); - - $table->column_class('picture', 'picture'); - $table->column_class('fullname', 'fullname'); - $table->column_class('grade', 'grade'); - $table->column_class('submissioncomment', 'comment'); - $table->column_class('timemodified', 'timemodified'); - $table->column_class('timemarked', 'timemarked'); - $table->column_class('status', 'status'); - $table->column_class('finalgrade', 'finalgrade'); - if ($uses_outcomes) { - $table->column_class('outcome', 'outcome'); - } - - $table->set_attribute('cellspacing', '0'); - $table->set_attribute('id', 'attempts'); - $table->set_attribute('class', 'submissions'); - $table->set_attribute('width', '100%'); - - $table->no_sorting('finalgrade'); - $table->no_sorting('outcome'); - - // Start working -- this is necessary as soon as the niceties are over - $table->setup(); - - if (empty($users)) { - echo $OUTPUT->heading(get_string('noviewusers', 'lti')); - echo '
'; - return true; - } - - /// Construct the SQL - list($where, $params) = $table->get_sql_where(); - if ($where) { - $where .= ' AND '; - } - - if ($sort = $table->get_sql_sort()) { - $sort = ' ORDER BY '.$sort; - } - - $ufields = user_picture::fields('u'); - - $gradeitem = $DB->get_record('grade_items', array('courseid' => $cm->course, 'iteminstance' => $cm->instance)); - - $select = "SELECT $ufields, - g.rawgrade, g.feedback, - g.timemodified, g.timecreated "; - - $sql = 'FROM {user} u'. - ' LEFT JOIN {grade_grades} g ON u.id = g.userid AND g.itemid = '.$gradeitem->id. - ' LEFT JOIN {grade_items} i ON g.itemid = i.id'. - ' AND i.iteminstance = '.$basiclti->id. - ' WHERE '.$where.'u.id IN ('.implode(',', $users).') '; - - $ausers = $DB->get_records_sql($select.$sql.$sort, $params, $table->get_page_start(), $table->get_page_size()); - - $table->pagesize($perpage, count($users)); - - ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next - $offset = $page * $perpage; - $strupdate = get_string('update'); - $strgrade = get_string('grade'); - $grademenu = make_grades_menu($basiclti->grade); - if ($ausers !== false) { - $grading_info = grade_get_grades($course->id, 'mod', 'lti', $basiclti->id, array_keys($ausers)); - $endposition = $offset + $perpage; - $currentposition = 0; - foreach ($ausers as $auser) { - - if ($auser->timemodified > 0) { - $timemodified = '
'.userdate($auser->timemodified).'
'; - } else { - $timemodified = '
 
'; - } - if ($auser->timecreated > 0) { - $timecreated = '
'.userdate($auser->timecreated).'
'; - } else { - $timecreated = '
 
'; - } - - if ($currentposition == $offset && $offset < $endposition) { - $final_grade = $grading_info->items[0]->grades[$auser->id]; - $grademax = $grading_info->items[0]->grademax; - $final_grade->formatted_grade = round($final_grade->grade, 2) .' / ' . round($grademax, 2); - $locked_overridden = 'locked'; - if ($final_grade->overridden) { - $locked_overridden = 'overridden'; - } - - /// Calculate user status - $picture = $OUTPUT->user_picture($auser); - - $studentmodified = '
 
'; - $teachermodified = '
 
'; - $status = '
 
'; - - if ($final_grade->locked or $final_grade->overridden) { - $grade = '
'.$final_grade->formatted_grade . '
'; - } else if ($quickgrade) { // allow editing - $attributes = array(); - $attributes['tabindex'] = $tabindex++; - if ($auser->rawgrade != "") { - $menu = html_writer::select(make_grades_menu($basiclti->grade), 'menu['.$auser->id.']', round($auser->rawgrade, 0), array(-1=>get_string('nograde')), $attributes); - } else { - $menu = html_writer::select(make_grades_menu($basiclti->grade), 'menu['.$auser->id.']', -1, array(-1=>get_string('nograde')), $attributes); - } - $grade = '
'.$menu.'
'; - } else if ($final_grade->grade) { - if ($auser->rawgrade != "") { - $grade = '
'.$final_grade->formatted_grade.'
'; - } else { - $grade = '
-1
'; - } - - } else { - $grade = '
No Grade
'; - } - - if ($final_grade->locked or $final_grade->overridden) { - $comment = '
'.$final_grade->str_feedback.'
'; - } else if ($quickgrade) { - $comment = '
' - . '
'; - } else { - $comment = '
'.shorten_text(strip_tags($auser->feedback), 15).'
'; - } - - if (empty($auser->status)) { /// Confirm we have exclusively 0 or 1 - $auser->status = 0; - } else { - $auser->status = 1; - } - - $buttontext = ($auser->status == 1) ? $strupdate : $strgrade; - - ///No more buttons, we use popups ;-). - $popup_url = '/mod/lti/submissions.php?id='.$cm->id - . '&userid='.$auser->id.'&mode=single'.'&filter='.$filter.'&offset='.$offset++; - - $button = $OUTPUT->action_link($popup_url, $buttontext); - - $status = '
'.$button.'
'; - - $finalgrade = ''.$final_grade->str_grade.''; - - $outcomes = ''; - - if ($uses_outcomes) { - - foreach ($grading_info->outcomes as $n => $outcome) { - $outcomes .= '
'; - $options = make_grades_menu(-$outcome->scaleid); - - if ($outcome->grades[$auser->id]->locked or !$quickgrade) { - $options[0] = get_string('nooutcome', 'grades'); - $outcomes .= ': '.$options[$outcome->grades[$auser->id]->grade].''; - } else { - $attributes = array(); - $attributes['tabindex'] = $tabindex++; - $attributes['id'] = 'outcome_'.$n.'_'.$auser->id; - $outcomes .= ' '.html_writer::select($options, 'outcome_'.$n.'['.$auser->id.']', $outcome->grades[$auser->id]->grade, array(0=>get_string('nooutcome', 'grades')), $attributes); - } - $outcomes .= '
'; - } - } - - $userlink = '' . fullname($auser, has_capability('moodle/site:viewfullnames', $context)) . ''; - $row = array($picture, $userlink, $grade, $comment, $timemodified, $timecreated, $status, $finalgrade); - if ($uses_outcomes) { - $row[] = $outcomes; - } - - $table->add_data($row); - } - $currentposition++; - } - } - - $table->print_html(); /// Print the whole table - - /// Print quickgrade form around the table - if ($quickgrade && $table->started_output) { - $mailinfopref = false; - if (get_user_preferences('lti_mailinfo', 1)) { - $mailinfopref = true; - } - $emailnotification = html_writer::checkbox('mailinfo', 1, $mailinfopref, get_string('enableemailnotification', 'lti')); - - $emailnotification .= $OUTPUT->help_icon('enableemailnotification', 'lti'); - echo html_writer::tag('div', $emailnotification, array('class'=>'emailnotification')); - - $savefeedback = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'fastg', 'value'=>get_string('saveallfeedback', 'lti'))); - echo html_writer::tag('div', $savefeedback, array('class'=>'fastgbutton')); - - echo html_writer::end_tag('form'); - } else if ($quickgrade) { - echo html_writer::end_tag('form'); - } - - echo ''; - /// End of fast grading form - - /// Mini form for setting user preference - - $formaction = new moodle_url('/mod/lti/submissions.php', array('id'=>$cm->id)); - $mform = new MoodleQuickForm('optionspref', 'post', $formaction, '', array('class'=>'optionspref')); - - $mform->addElement('hidden', 'updatepref'); - $mform->setDefault('updatepref', 1); - $mform->addElement('header', 'qgprefs', get_string('optionalsettings', 'lti')); -// $mform->addElement('select', 'filter', get_string('show'), $filters); - - $mform->setDefault('filter', $filter); - - $mform->addElement('text', 'perpage', get_string('pagesize', 'lti'), array('size'=>1)); - $mform->setDefault('perpage', $perpage); - - $mform->addElement('checkbox', 'quickgrade', get_string('quickgrade', 'lti')); - $mform->setDefault('quickgrade', $quickgrade); - $mform->addHelpButton('quickgrade', 'quickgrade', 'lti'); - - $mform->addElement('submit', 'savepreferences', get_string('savepreferences')); - - $mform->display(); - - echo $OUTPUT->footer(); -} - -/** - * Create grade item for given basiclti - * - * @param object $basiclti object with extra cmidnumber - * @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook - * @return int 0 if ok, error code otherwise - */ -function lti_grade_item_update($basiclti, $grades=null) { - global $CFG; - require_once($CFG->libdir.'/gradelib.php'); - - $params = array('itemname'=>$basiclti->name, 'idnumber'=>$basiclti->cmidnumber); - - if ($basiclti->grade > 0) { - $params['gradetype'] = GRADE_TYPE_VALUE; - $params['grademax'] = $basiclti->grade; - $params['grademin'] = 0; - - } else if ($basiclti->grade < 0) { - $params['gradetype'] = GRADE_TYPE_SCALE; - $params['scaleid'] = -$basiclti->grade; - - } else { - $params['gradetype'] = GRADE_TYPE_TEXT; // allow text comments only - } - - if ($grades === 'reset') { - $params['reset'] = true; - $grades = null; - } - - return grade_update('mod/lti', $basiclti->course, 'mod', 'lti', $basiclti->id, 0, $grades, $params); -} - -/** - * Delete grade item for given basiclti - * - * @param object $basiclti object - * @return object basiclti - */ -function lti_grade_item_delete($basiclti) { - global $CFG; - require_once($CFG->libdir.'/gradelib.php'); - - return grade_update('mod/lti', $basiclti->course, 'mod', 'lti', $basiclti->id, 0, null, array('deleted'=>1)); -} - +. + +/** + * This file contains a library of functions and constants for the + * BasicLTI module + * + * @package lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +require_once($CFG->dirroot.'/mod/lti/locallib.php'); + +/** + * List of features supported in URL module + * @param string $feature FEATURE_xx constant for requested feature + * @return mixed True if module supports feature, false if not, null if doesn't know + */ +function lti_supports($feature) { + switch($feature) { + case FEATURE_GROUPS: return false; + case FEATURE_GROUPINGS: return false; + case FEATURE_GROUPMEMBERSONLY: return true; + case FEATURE_MOD_INTRO: return true; + case FEATURE_COMPLETION_TRACKS_VIEWS: return true; + case FEATURE_GRADE_HAS_GRADE: return true; + case FEATURE_GRADE_OUTCOMES: return true; + case FEATURE_BACKUP_MOODLE2: return true; + + default: return null; + } +} + +/** + * Given an object containing all the necessary data, + * (defined by the form in mod.html) this function + * will create a new instance and return the id number + * of the new instance. + * + * @param object $instance An object from the form in mod.html + * @return int The id of the newly inserted basiclti record + **/ +function lti_add_instance($formdata) { + global $DB; + $formdata->timecreated = time(); + $formdata->timemodified = $formdata->timecreated; + $formdata->servicesalt = uniqid('', true); + + if(!isset($formdata->grade)){ + $formdata->grade = 100; + } + + $id = $DB->insert_record("lti", $formdata); + + if ($formdata->instructorchoiceacceptgrades == 1) { + $basiclti = $DB->get_record('lti', array('id'=>$id)); + $basiclti->cmidnumber = $formdata->cmidnumber; + + lti_grade_item_update($basiclti); + } + + return $id; +} + +/** + * Given an object containing all the necessary data, + * (defined by the form in mod.html) this function + * will update an existing instance with new data. + * + * @param object $instance An object from the form in mod.html + * @return boolean Success/Fail + **/ +function lti_update_instance($formdata) { + global $DB; + + $formdata->timemodified = time(); + $formdata->id = $formdata->instance; + + if(!isset($formdata->showtitle)){ + $formdata->showtitle = 0; + } + + if(!isset($formdata->showdescription)){ + $formdata->showdescription = 0; + } + + if ($formdata->instructorchoiceacceptgrades == 1) { + $basicltirec = $DB->get_record("lti", array("id" => $formdata->id)); + $basicltirec->cmidnumber = $formdata->cmidnumber; + + lti_grade_item_update($basicltirec); + } else { + lti_grade_item_delete($formdata); + } + + return $DB->update_record("lti", $formdata); +} + +/** + * Given an ID of an instance of this module, + * this function will permanently delete the instance + * and any data that depends on it. + * + * @param int $id Id of the module instance + * @return boolean Success/Failure + **/ +function lti_delete_instance($id) { + global $DB; + + if (! $basiclti = $DB->get_record("lti", array("id" => $id))) { + return false; + } + + $result = true; + + # Delete any dependent records here # + lti_grade_item_delete($basiclti); + + return $DB->delete_records("lti", array("id" => $basiclti->id)); +} + +/** + * Return a small object with summary information about what a + * user has done with a given particular instance of this module + * Used for user activity reports. + * $return->time = the time they did it + * $return->info = a short text description + * + * @return null + * @TODO: implement this moodle function (if needed) + **/ +function lti_user_outline($course, $user, $mod, $basiclti) { + return $return; +} + +/** + * Print a detailed representation of what a user has done with + * a given particular instance of this module, for user activity reports. + * + * @return boolean + * @TODO: implement this moodle function (if needed) + **/ +function lti_user_complete($course, $user, $mod, $basiclti) { + return true; +} + +/** + * Given a course and a time, this module should find recent activity + * that has occurred in basiclti activities and print it out. + * Return true if there was output, or false is there was none. + * + * @uses $CFG + * @return boolean + * @TODO: implement this moodle function + **/ +function lti_print_recent_activity($course, $isteacher, $timestart) { + return false; // True if anything was printed, otherwise false +} + +/** + * Function to be run periodically according to the moodle cron + * This function searches for things that need to be done, such + * as sending out mail, toggling flags etc ... + * + * @uses $CFG + * @return boolean + **/ +function lti_cron () { + return true; +} + +/** + * Must return an array of grades for a given instance of this module, + * indexed by user. It also returns a maximum allowed grade. + * + * Example: + * $return->grades = array of grades; + * $return->maxgrade = maximum allowed grade; + * + * return $return; + * + * @param int $basicltiid ID of an instance of this module + * @return mixed Null or object with an array of grades and with the maximum grade + * + * @TODO: implement this moodle function (if needed) + **/ +function lti_grades($basicltiid) { + return null; +} + +/** + * Must return an array of user records (all data) who are participants + * for a given instance of basiclti. Must include every user involved + * in the instance, independient of his role (student, teacher, admin...) + * See other modules as example. + * + * @param int $basicltiid ID of an instance of this module + * @return mixed boolean/array of students + * + * @TODO: implement this moodle function + **/ +function lti_get_participants($basicltiid) { + return false; +} + +/** + * This function returns if a scale is being used by one basiclti + * it it has support for grading and scales. Commented code should be + * modified if necessary. See forum, glossary or journal modules + * as reference. + * + * @param int $basicltiid ID of an instance of this module + * @return mixed + * + * @TODO: implement this moodle function (if needed) + **/ +function lti_scale_used ($basicltiid, $scaleid) { + $return = false; + + //$rec = get_record("basiclti","id","$basicltiid","scale","-$scaleid"); + // + //if (!empty($rec) && !empty($scaleid)) { + // $return = true; + //} + + return $return; +} + +/** + * Checks if scale is being used by any instance of basiclti. + * This function was added in 1.9 + * + * This is used to find out if scale used anywhere + * @param $scaleid int + * @return boolean True if the scale is used by any basiclti + * + */ +function lti_scale_used_anywhere($scaleid) { + global $DB; + + if ($scaleid and $DB->record_exists('lti', array('grade' => -$scaleid))) { + return true; + } else { + return false; + } +} + +/** + * Execute post-install custom actions for the module + * This function was added in 1.9 + * + * @return boolean true if success, false on error + */ +function lti_install() { + return true; +} + +/** + * Execute post-uninstall custom actions for the module + * This function was added in 1.9 + * + * @return boolean true if success, false on error + */ +function lti_uninstall() { + return true; +} + +/** + * Returns available Basic LTI types + * + * @return array of basicLTI types + */ +function lti_get_lti_types() { + global $DB; + + return $DB->get_records('lti_types'); +} + +/** + * Returns Basic LTI types configuration + * + * @return array of basicLTI types + */ +/*function lti_get_types() { + $types = array(); + + $basicltitypes = lti_get_lti_types(); + if (!empty($basicltitypes)) { + foreach ($basicltitypes as $basicltitype) { + $ltitypesconfig = lti_get_type_config($basicltitype->id); + + $modclass = MOD_CLASS_ACTIVITY; + if (isset($ltitypesconfig['module_class_type'])) { + if ($ltitypesconfig['module_class_type']=='1') { + $modclass = MOD_CLASS_RESOURCE; + } + } + + $type = new object(); + $type->modclass = $modclass; + $type->type = 'lti&type='.urlencode($basicltitype->rawname); + $type->typestr = $basicltitype->name; + $types[] = $type; + } + } + + return $types; +}*/ + +////////////////////////////////////////////////////////////////////////////////////// +/// Any other basiclti functions go here. Each of them must have a name that +/// starts with basiclti_ +/// Remember (see note in first lines) that, if this section grows, it's HIGHLY +/// recommended to move all funcions below to a new "localib.php" file. + +///** +// * +// */ +//function process_outcomes($userid, $course, $basiclti) { +// global $CFG, $USER; +// +// if (empty($CFG->enableoutcomes)) { +// return; +// } +// +// require_once($CFG->libdir.'/gradelib.php'); +// +// if (!$formdata = data_submitted() or !confirm_sesskey()) { +// return; +// } +// +// $data = array(); +// $grading_info = grade_get_grades($course->id, 'mod', 'basiclti', $basiclti->id, $userid); +// +// if (!empty($grading_info->outcomes)) { +// foreach ($grading_info->outcomes as $n => $old) { +// $name = 'outcome_'.$n; +// if (isset($formdata->{$name}[$userid]) and $old->grades[$userid]->grade != $formdata->{$name}[$userid]) { +// $data[$n] = $formdata->{$name}[$userid]; +// } +// } +// } +// if (count($data) > 0) { +// grade_update_outcomes('mod/basiclti', $course->id, 'mod', 'basiclti', $basiclti->id, $userid, $data); +// } +// +//} + +/** + * Top-level function for handling of submissions called by submissions.php + * + * This is for handling the teacher interaction with the grading interface + * + * @global object + * @param string $mode Specifies the kind of teacher interaction taking place + */ +function lti_submissions($cm, $course, $basiclti, $mode) { + ///The main switch is changed to facilitate + ///1) Batch fast grading + ///2) Skip to the next one on the popup + ///3) Save and Skip to the next one on the popup + + //make user global so we can use the id + global $USER, $OUTPUT, $DB; + + $mailinfo = optional_param('mailinfo', null, PARAM_BOOL); + + if (optional_param('next', null, PARAM_BOOL)) { + $mode='next'; + } + if (optional_param('saveandnext', null, PARAM_BOOL)) { + $mode='saveandnext'; + } + + if (is_null($mailinfo)) { + if (optional_param('sesskey', null, PARAM_BOOL)) { + set_user_preference('lti_mailinfo', $mailinfo); + } else { + $mailinfo = get_user_preferences('lti_mailinfo', 0); + } + } else { + set_user_preference('lti_mailinfo', $mailinfo); + } + + switch ($mode) { + case 'grade': // We are in a main window grading + if ($submission = process_feedback()) { + lti_display_submissions($cm, $course, $basiclti, get_string('changessaved')); + } else { + lti_display_submissions($cm, $course, $basiclti); + } + break; + + case 'single': // We are in a main window displaying one submission + if ($submission = process_feedback()) { + lti_display_submissions($cm, $course, $basiclti, get_string('changessaved')); + } else { + display_submission(); + } + break; + + case 'all': // Main window, display everything + lti_display_submissions($cm, $course, $basiclti); + break; + + case 'fastgrade': + /// do the fast grading stuff - this process should work for all 3 subclasses + $grading = false; + $commenting = false; + $col = false; + if (isset($_POST['submissioncomment'])) { + $col = 'submissioncomment'; + $commenting = true; + } + if (isset($_POST['menu'])) { + $col = 'menu'; + $grading = true; + } + if (!$col) { + //both submissioncomment and grade columns collapsed.. + lti_display_submissions($cm, $course, $basiclti); + break; + } + + foreach ($_POST[$col] as $id => $unusedvalue) { + + $id = (int)$id; //clean parameter name + + // Get grade item + $gradeitem = $DB->get_record('grade_items', array('courseid' => $cm->course, 'iteminstance' => $cm->instance)); + + // Get grade + $gradeentry = $DB->get_record('grade_grades', array('userid' => $id, 'itemid' => $gradeitem->id)); + + $grade = $_POST['menu'][$id]; + $feedback = trim($_POST['submissioncomment'][$id]); + + if ((!$gradeentry) && (($grade != '-1') || ($feedback != ''))) { + $newsubmission = true; + } else { + $newsubmission = false; + } + + //for fast grade, we need to check if any changes take place + $updatedb = false; + + if ($gradeentry) { + if ($grading) { + $grade = $_POST['menu'][$id]; + $updatedb = $updatedb || (($gradeentry->rawgrade != $grade) && ($gradeentry->rawgrade != '-1')); + if ($grade != '-1') { + $gradeentry->rawgrade = $grade; + $gradeentry->finalgrade = $grade; + } else { + $gradeentry->rawgrade = null; + $gradeentry->finalgrade = null; + } + } else { + if (!$newsubmission) { + unset($gradeentry->rawgrade); // Don't need to update this. + } + } + + if ($commenting) { + $commentvalue = trim($_POST['submissioncomment'][$id]); + $updatedb = $updatedb || ($gradeentry->feedback != $commentvalue); + // Special case + if (($gradeentry->feedback == null) && ($commentvalue == "")) { + unset($gradeentry->feedback); + } + $gradeentry->feedback = $commentvalue; + } else { + unset($gradeentry->feedback); // Don't need to update this. + } + + } else { // No previous grade entry found + if ($newsubmission) { + if ($grade != '-1') { + $gradeentry->rawgrade = $grade; + $updatedb = true; + } + if ($feedback != '') { + $gradeentry->feedback = $feedback; + $updatedb = true; + } + } + } + + $gradeentry->usermodified = $USER->id; + if (!$gradeentry->timecreated) { + $gradeentry->timecreated = time(); + } + $gradeentry->timemodified = time(); + + //if it is not an update, we don't change the last modified time etc. + //this will also not write into database if no submissioncomment and grade is entered. + if ($updatedb) { + if ($gradeentry->rawgrade == '-1') { + $gradeentry->rawgrade = null; + } + + if ($newsubmission) { + if (!isset($gradeentry->feedback)) { + $gradeentry->feedback = ''; + } + $gradeentry->itemid = $gradeitem->id; + $gradeentry->userid = $id; + $sid = $DB->insert_record("grade_grades", $gradeentry); + $gradeentry->id = $sid; + } else { + $DB->update_record("grade_grades", $gradeentry); + } + + //add to log only if updating + add_to_log($course->id, 'lti', 'update grades', + 'submissions.php?id='.$cm->id.'&user='.$USER->id, + $USER->id, $cm->id); + } + + } + + $message = $OUTPUT->notification(get_string('changessaved'), 'notifysuccess'); + + lti_display_submissions($cm, $course, $basiclti, $message); + break; + + case 'saveandnext': + ///We are in pop up. save the current one and go to the next one. + //first we save the current changes + if ($submission = process_feedback()) { + //print_heading(get_string('changessaved')); + //$extra_javascript = $this->update_main_listing($submission); + } + + case 'next': + /// We are currently in pop up, but we want to skip to next one without saving. + /// This turns out to be similar to a single case + /// The URL used is for the next submission. + $offset = required_param('offset', PARAM_INT); + $nextid = required_param('nextid', PARAM_INT); + $id = required_param('id', PARAM_INT); + $offset = (int)$offset+1; + //$this->display_submission($offset+1 , $nextid); + redirect('submissions.php?id='.$id.'&userid='. $nextid . '&mode=single&offset='.$offset); + break; + + case 'singlenosave': + display_submission(); + break; + + default: + echo "Critical error. Something is seriously wrong!!"; + break; + } +} + +/** + * Display all the submissions ready for grading + * + * @global object + * @global object + * @global object + * @global object + * @param string $message + * @return bool|void + */ +function lti_display_submissions($cm, $course, $basiclti, $message='') { + global $CFG, $DB, $OUTPUT, $PAGE; + require_once($CFG->libdir.'/gradelib.php'); + + /* first we check to see if the form has just been submitted + * to request user_preference updates + */ + $updatepref = optional_param('updatepref', 0, PARAM_INT); + + if (isset($_POST['updatepref'])) { + $perpage = optional_param('perpage', 10, PARAM_INT); + $perpage = ($perpage <= 0) ? 10 : $perpage; + $filter = optional_param('filter', 0, PARAM_INT); + set_user_preference('lti_perpage', $perpage); + set_user_preference('lti_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL)); + set_user_preference('lti_filter', $filter); + } + + /* next we get perpage and quickgrade (allow quick grade) params + * from database + */ + $perpage = get_user_preferences('lti_perpage', 10); + $quickgrade = get_user_preferences('lti_quickgrade', 0); + $filter = get_user_preferences('lti_filter', 0); + $grading_info = grade_get_grades($course->id, 'mod', 'lti', $basiclti->id); + + if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) { + $uses_outcomes = true; + } else { + $uses_outcomes = false; + } + + $page = optional_param('page', 0, PARAM_INT); + $strsaveallfeedback = get_string('saveallfeedback', 'lti'); + + $tabindex = 1; //tabindex for quick grading tabbing; Not working for dropdowns yet + add_to_log($course->id, 'lti', 'view submission', 'submissions.php?id='.$cm->id, $basiclti->id, $cm->id); + + $PAGE->set_title(format_string($basiclti->name, true)); + $PAGE->set_heading($course->fullname); + echo $OUTPUT->header(); + + echo '
'; + + //hook to allow plagiarism plugins to update status/print links. + plagiarism_update_status($course, $cm); + + /// Print quickgrade form around the table + if ($quickgrade) { + $formattrs = array(); + $formattrs['action'] = new moodle_url('/mod/lti/submissions.php'); + $formattrs['id'] = 'fastg'; + $formattrs['method'] = 'post'; + + echo html_writer::start_tag('form', $formattrs); + echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=> $cm->id)); + echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'mode', 'value'=> 'fastgrade')); + echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'page', 'value'=> $page)); + echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=> sesskey())); + } + + $course_context = get_context_instance(CONTEXT_COURSE, $course->id); + if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) { + echo ''; + } + + if (!empty($message)) { + echo $message; // display messages here if any + } + + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + +/// Check to see if groups are being used in this tool + + /// find out current groups mode + $groupmode = groups_get_activity_groupmode($cm); + $currentgroup = groups_get_activity_group($cm, true); + groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/lti/submissions.php?id=' . $cm->id); + + /// Get all ppl that are allowed to submit tools + list($esql, $params) = get_enrolled_sql($context, 'mod/lti:view', $currentgroup); + + $sql = "SELECT u.id FROM {user} u ". + "LEFT JOIN ($esql) eu ON eu.id=u.id ". + "WHERE u.deleted = 0 AND eu.id=u.id "; + + $users = $DB->get_records_sql($sql, $params); + if (!empty($users)) { + $users = array_keys($users); + } + + // if groupmembersonly used, remove users who are not in any group + if ($users and !empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) { + if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) { + $users = array_intersect($users, array_keys($groupingusers)); + } + } + + $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade'); + if ($uses_outcomes) { + $tablecolumns[] = 'outcome'; // no sorting based on outcomes column + } + + $tableheaders = array('', + get_string('fullname'), + get_string('grade'), + get_string('comment', 'lti'), + get_string('lastmodified').' ('.get_string('submission', 'lti').')', + get_string('lastmodified').' ('.get_string('grade').')', + get_string('status'), + get_string('finalgrade', 'grades')); + if ($uses_outcomes) { + $tableheaders[] = get_string('outcome', 'grades'); + } + + require_once($CFG->libdir.'/tablelib.php'); + $table = new flexible_table('mod-lti-submissions'); + + $table->define_columns($tablecolumns); + $table->define_headers($tableheaders); + $table->define_baseurl($CFG->wwwroot.'/mod/lti/submissions.php?id='.$cm->id.'&currentgroup='.$currentgroup); + + $table->sortable(true, 'lastname');//sorted by lastname by default + $table->collapsible(true); + $table->initialbars(true); + + $table->column_suppress('picture'); + $table->column_suppress('fullname'); + + $table->column_class('picture', 'picture'); + $table->column_class('fullname', 'fullname'); + $table->column_class('grade', 'grade'); + $table->column_class('submissioncomment', 'comment'); + $table->column_class('timemodified', 'timemodified'); + $table->column_class('timemarked', 'timemarked'); + $table->column_class('status', 'status'); + $table->column_class('finalgrade', 'finalgrade'); + if ($uses_outcomes) { + $table->column_class('outcome', 'outcome'); + } + + $table->set_attribute('cellspacing', '0'); + $table->set_attribute('id', 'attempts'); + $table->set_attribute('class', 'submissions'); + $table->set_attribute('width', '100%'); + + $table->no_sorting('finalgrade'); + $table->no_sorting('outcome'); + + // Start working -- this is necessary as soon as the niceties are over + $table->setup(); + + if (empty($users)) { + echo $OUTPUT->heading(get_string('noviewusers', 'lti')); + echo '
'; + return true; + } + + /// Construct the SQL + list($where, $params) = $table->get_sql_where(); + if ($where) { + $where .= ' AND '; + } + + if ($sort = $table->get_sql_sort()) { + $sort = ' ORDER BY '.$sort; + } + + $ufields = user_picture::fields('u'); + + $gradeitem = $DB->get_record('grade_items', array('courseid' => $cm->course, 'iteminstance' => $cm->instance)); + + $select = "SELECT $ufields, + g.rawgrade, g.feedback, + g.timemodified, g.timecreated "; + + $sql = 'FROM {user} u'. + ' LEFT JOIN {grade_grades} g ON u.id = g.userid AND g.itemid = '.$gradeitem->id. + ' LEFT JOIN {grade_items} i ON g.itemid = i.id'. + ' AND i.iteminstance = '.$basiclti->id. + ' WHERE '.$where.'u.id IN ('.implode(',', $users).') '; + + $ausers = $DB->get_records_sql($select.$sql.$sort, $params, $table->get_page_start(), $table->get_page_size()); + + $table->pagesize($perpage, count($users)); + + ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next + $offset = $page * $perpage; + $strupdate = get_string('update'); + $strgrade = get_string('grade'); + $grademenu = make_grades_menu($basiclti->grade); + if ($ausers !== false) { + $grading_info = grade_get_grades($course->id, 'mod', 'lti', $basiclti->id, array_keys($ausers)); + $endposition = $offset + $perpage; + $currentposition = 0; + foreach ($ausers as $auser) { + + if ($auser->timemodified > 0) { + $timemodified = '
'.userdate($auser->timemodified).'
'; + } else { + $timemodified = '
 
'; + } + if ($auser->timecreated > 0) { + $timecreated = '
'.userdate($auser->timecreated).'
'; + } else { + $timecreated = '
 
'; + } + + if ($currentposition == $offset && $offset < $endposition) { + $final_grade = $grading_info->items[0]->grades[$auser->id]; + $grademax = $grading_info->items[0]->grademax; + $final_grade->formatted_grade = round($final_grade->grade, 2) .' / ' . round($grademax, 2); + $locked_overridden = 'locked'; + if ($final_grade->overridden) { + $locked_overridden = 'overridden'; + } + + /// Calculate user status + $picture = $OUTPUT->user_picture($auser); + + $studentmodified = '
 
'; + $teachermodified = '
 
'; + $status = '
 
'; + + if ($final_grade->locked or $final_grade->overridden) { + $grade = '
'.$final_grade->formatted_grade . '
'; + } else if ($quickgrade) { // allow editing + $attributes = array(); + $attributes['tabindex'] = $tabindex++; + if ($auser->rawgrade != "") { + $menu = html_writer::select(make_grades_menu($basiclti->grade), 'menu['.$auser->id.']', round($auser->rawgrade, 0), array(-1=>get_string('nograde')), $attributes); + } else { + $menu = html_writer::select(make_grades_menu($basiclti->grade), 'menu['.$auser->id.']', -1, array(-1=>get_string('nograde')), $attributes); + } + $grade = '
'.$menu.'
'; + } else if ($final_grade->grade) { + if ($auser->rawgrade != "") { + $grade = '
'.$final_grade->formatted_grade.'
'; + } else { + $grade = '
-1
'; + } + + } else { + $grade = '
No Grade
'; + } + + if ($final_grade->locked or $final_grade->overridden) { + $comment = '
'.$final_grade->str_feedback.'
'; + } else if ($quickgrade) { + $comment = '
' + . '
'; + } else { + $comment = '
'.shorten_text(strip_tags($auser->feedback), 15).'
'; + } + + if (empty($auser->status)) { /// Confirm we have exclusively 0 or 1 + $auser->status = 0; + } else { + $auser->status = 1; + } + + $buttontext = ($auser->status == 1) ? $strupdate : $strgrade; + + ///No more buttons, we use popups ;-). + $popup_url = '/mod/lti/submissions.php?id='.$cm->id + . '&userid='.$auser->id.'&mode=single'.'&filter='.$filter.'&offset='.$offset++; + + $button = $OUTPUT->action_link($popup_url, $buttontext); + + $status = '
'.$button.'
'; + + $finalgrade = ''.$final_grade->str_grade.''; + + $outcomes = ''; + + if ($uses_outcomes) { + + foreach ($grading_info->outcomes as $n => $outcome) { + $outcomes .= '
'; + $options = make_grades_menu(-$outcome->scaleid); + + if ($outcome->grades[$auser->id]->locked or !$quickgrade) { + $options[0] = get_string('nooutcome', 'grades'); + $outcomes .= ': '.$options[$outcome->grades[$auser->id]->grade].''; + } else { + $attributes = array(); + $attributes['tabindex'] = $tabindex++; + $attributes['id'] = 'outcome_'.$n.'_'.$auser->id; + $outcomes .= ' '.html_writer::select($options, 'outcome_'.$n.'['.$auser->id.']', $outcome->grades[$auser->id]->grade, array(0=>get_string('nooutcome', 'grades')), $attributes); + } + $outcomes .= '
'; + } + } + + $userlink = '' . fullname($auser, has_capability('moodle/site:viewfullnames', $context)) . ''; + $row = array($picture, $userlink, $grade, $comment, $timemodified, $timecreated, $status, $finalgrade); + if ($uses_outcomes) { + $row[] = $outcomes; + } + + $table->add_data($row); + } + $currentposition++; + } + } + + $table->print_html(); /// Print the whole table + + /// Print quickgrade form around the table + if ($quickgrade && $table->started_output) { + $mailinfopref = false; + if (get_user_preferences('lti_mailinfo', 1)) { + $mailinfopref = true; + } + $emailnotification = html_writer::checkbox('mailinfo', 1, $mailinfopref, get_string('enableemailnotification', 'lti')); + + $emailnotification .= $OUTPUT->help_icon('enableemailnotification', 'lti'); + echo html_writer::tag('div', $emailnotification, array('class'=>'emailnotification')); + + $savefeedback = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'fastg', 'value'=>get_string('saveallfeedback', 'lti'))); + echo html_writer::tag('div', $savefeedback, array('class'=>'fastgbutton')); + + echo html_writer::end_tag('form'); + } else if ($quickgrade) { + echo html_writer::end_tag('form'); + } + + echo ''; + /// End of fast grading form + + /// Mini form for setting user preference + + $formaction = new moodle_url('/mod/lti/submissions.php', array('id'=>$cm->id)); + $mform = new MoodleQuickForm('optionspref', 'post', $formaction, '', array('class'=>'optionspref')); + + $mform->addElement('hidden', 'updatepref'); + $mform->setDefault('updatepref', 1); + $mform->addElement('header', 'qgprefs', get_string('optionalsettings', 'lti')); +// $mform->addElement('select', 'filter', get_string('show'), $filters); + + $mform->setDefault('filter', $filter); + + $mform->addElement('text', 'perpage', get_string('pagesize', 'lti'), array('size'=>1)); + $mform->setDefault('perpage', $perpage); + + $mform->addElement('checkbox', 'quickgrade', get_string('quickgrade', 'lti')); + $mform->setDefault('quickgrade', $quickgrade); + $mform->addHelpButton('quickgrade', 'quickgrade', 'lti'); + + $mform->addElement('submit', 'savepreferences', get_string('savepreferences')); + + $mform->display(); + + echo $OUTPUT->footer(); +} + +/** + * Create grade item for given basiclti + * + * @param object $basiclti object with extra cmidnumber + * @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook + * @return int 0 if ok, error code otherwise + */ +function lti_grade_item_update($basiclti, $grades=null) { + global $CFG; + require_once($CFG->libdir.'/gradelib.php'); + + $params = array('itemname'=>$basiclti->name, 'idnumber'=>$basiclti->cmidnumber); + + if ($basiclti->grade > 0) { + $params['gradetype'] = GRADE_TYPE_VALUE; + $params['grademax'] = $basiclti->grade; + $params['grademin'] = 0; + + } else if ($basiclti->grade < 0) { + $params['gradetype'] = GRADE_TYPE_SCALE; + $params['scaleid'] = -$basiclti->grade; + + } else { + $params['gradetype'] = GRADE_TYPE_TEXT; // allow text comments only + } + + if ($grades === 'reset') { + $params['reset'] = true; + $grades = null; + } + + return grade_update('mod/lti', $basiclti->course, 'mod', 'lti', $basiclti->id, 0, $grades, $params); +} + +/** + * Delete grade item for given basiclti + * + * @param object $basiclti object + * @return object basiclti + */ +function lti_grade_item_delete($basiclti) { + global $CFG; + require_once($CFG->libdir.'/gradelib.php'); + + return grade_update('mod/lti', $basiclti->course, 'mod', 'lti', $basiclti->id, 0, null, array('deleted'=>1)); +} + From b9b2e7bbf821a9b451f5ac84b7b7f00c8365ae94 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Fri, 9 Sep 2011 16:16:27 -0400 Subject: [PATCH 16/78] Adding oauth body code (from Chuck), implemented outcome services (only replaceResult tested) --- mod/lti/OAuthBody.php | 158 ++++ mod/lti/locallib.php | 1835 ++++++++++++++++++++-------------------- mod/lti/oldservice.php | 391 +++++++++ mod/lti/service.php | 621 +++++--------- 4 files changed, 1704 insertions(+), 1301 deletions(-) create mode 100644 mod/lti/OAuthBody.php create mode 100644 mod/lti/oldservice.php diff --git a/mod/lti/OAuthBody.php b/mod/lti/OAuthBody.php new file mode 100644 index 00000000000..1d70444a3c6 --- /dev/null +++ b/mod/lti/OAuthBody.php @@ -0,0 +1,158 @@ +. + +require_once($CFG->dirroot . '/mod/lti/OAuth.php'); +require_once($CFG->dirroot . '/mod/lti/TrivialStore.php'); + +function getOAuthKeyFromHeaders() +{ + $request_headers = OAuthUtil::get_headers(); + // print_r($request_headers); + + if (@substr($request_headers['Authorization'], 0, 6) == "OAuth ") { + $header_parameters = OAuthUtil::split_header($request_headers['Authorization']); + + // echo("HEADER PARMS=\n"); + // print_r($header_parameters); + return $header_parameters['oauth_consumer_key']; + } + return false; +} + +function handleOAuthBodyPOST($oauth_consumer_key, $oauth_consumer_secret) +{ + $request_headers = OAuthUtil::get_headers(); + // print_r($request_headers); + + // Must reject application/x-www-form-urlencoded + if ($request_headers['Content-type'] == 'application/x-www-form-urlencoded' ) { + throw new Exception("OAuth request body signing must not use application/x-www-form-urlencoded"); + } + + if (@substr($request_headers['Authorization'], 0, 6) == "OAuth ") { + $header_parameters = OAuthUtil::split_header($request_headers['Authorization']); + + // echo("HEADER PARMS=\n"); + // print_r($header_parameters); + $oauth_body_hash = $header_parameters['oauth_body_hash']; + // echo("OBH=".$oauth_body_hash."\n"); + } + + if ( ! isset($oauth_body_hash) ) { + throw new Exception("OAuth request body signing requires oauth_body_hash body"); + } + + // Verify the message signature + $store = new TrivialOAuthDataStore(); + $store->add_consumer($oauth_consumer_key, $oauth_consumer_secret); + + $server = new OAuthServer($store); + + $method = new OAuthSignatureMethod_HMAC_SHA1(); + $server->add_signature_method($method); + $request = OAuthRequest::from_request(); + + try { + $server->verify_request($request); + } catch (Exception $e) { + $message = $e->getMessage(); + throw new Exception("OAuth signature failed: " . $message); + } + + $postdata = file_get_contents('php://input'); + // echo($postdata); + + $hash = base64_encode(sha1($postdata, TRUE)); + + if ( $hash != $oauth_body_hash ) { + throw new Exception("OAuth oauth_body_hash mismatch"); + } + + return $postdata; +} + +function sendOAuthBodyPOST($method, $endpoint, $oauth_consumer_key, $oauth_consumer_secret, $content_type, $body) +{ + $hash = base64_encode(sha1($body, TRUE)); + + $parms = array('oauth_body_hash' => $hash); + + $test_token = ''; + $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); + $test_consumer = new OAuthConsumer($oauth_consumer_key, $oauth_consumer_secret, NULL); + + $acc_req = OAuthRequest::from_consumer_and_token($test_consumer, $test_token, $method, $endpoint, $parms); + $acc_req->sign_request($hmac_method, $test_consumer, $test_token); + + $header = $acc_req->to_header(); + $header = $header . "\r\nContent-type: " . $content_type . "\r\n"; + + $params = array('http' => array( + 'method' => 'POST', + 'content' => $body, + 'header' => $header + )); + $ctx = stream_context_create($params); + $fp = @fopen($endpoint, 'rb', false, $ctx); + if (!$fp) { + throw new Exception("Problem with $endpoint, $php_errormsg"); + } + $response = @stream_get_contents($fp); + if ($response === false) { + throw new Exception("Problem reading data from $endpoint, $php_errormsg"); + } + return $response; +} \ No newline at end of file diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index da2d545d087..240f1c4b389 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -1,910 +1,925 @@ -. - -/** - * This file contains the library of functions and constants for the basiclti module - * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis - * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die; - -require_once($CFG->dirroot.'/mod/lti/OAuth.php'); - -define('LTI_URL_DOMAIN_REGEX', '/(?:https?:\/\/)?(?:www\.)?([^\/]+)(?:\/|$)/i'); - -define('LTI_LAUNCH_CONTAINER_DEFAULT', 1); -define('LTI_LAUNCH_CONTAINER_EMBED', 2); -define('LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS', 3); -define('LTI_LAUNCH_CONTAINER_WINDOW', 4); - -define('LTI_TOOL_STATE_ANY', 0); -define('LTI_TOOL_STATE_CONFIGURED', 1); -define('LTI_TOOL_STATE_PENDING', 2); -define('LTI_TOOL_STATE_REJECTED', 3); - -define('LTI_SETTING_NEVER', 0); -define('LTI_SETTING_ALWAYS', 1); -define('LTI_SETTING_DEFAULT', 2); - -/** - * Prints a Basic LTI activity - * - * $param int $basicltiid Basic LTI activity id - */ -function lti_view($instance, $makeobject=false) { - global $PAGE, $CFG; - - if(empty($instance->typeid)){ - $tool = lti_get_tool_by_url_match($instance->toolurl); - if($tool){ - $typeid = $tool->id; - } else { - $typeid = null; - } - } else { - $typeid = $instance->typeid; - } - - if($typeid){ - $typeconfig = lti_get_type_config($typeid); - } else { - //There is no admin configuration for this tool. Use configuration in the lti instance record plus some defaults. - $typeconfig = (array)$instance; - - $typeconfig['sendname'] = $instance->instructorchoicesendname; - $typeconfig['sendemailaddr'] = $instance->instructorchoicesendemailaddr; - $typeconfig['customparameters'] = $instance->instructorcustomparameters; - } - - //Default the organizationid if not specified - if(empty($typeconfig['organizationid'])){ - $urlparts = parse_url($CFG->wwwroot); - - $typeconfig['organizationid'] = $urlparts['host']; - } - - $endpoint = !empty($instance->toolurl) ? $instance->toolurl : $typeconfig['toolurl']; - $key = !empty($instance->resourcekey) ? $instance->resourcekey : $typeconfig['resourcekey']; - $secret = !empty($instance->password) ? $instance->password : $typeconfig['password']; - $orgid = $typeconfig['organizationid']; - /* Suppress this for now - Chuck - $orgdesc = $typeconfig['organizationdescr']; - */ - - $course = $PAGE->course; - $requestparams = lti_build_request($instance, $typeconfig, $course); - - // Make sure we let the tool know what LMS they are being called from - $requestparams["ext_lms"] = "moodle-2"; - - // Add oauth_callback to be compliant with the 1.0A spec - $requestparams["oauth_callback"] = "about:blank"; - - $submittext = get_string('press_to_submit', 'lti'); - $parms = sign_parameters($requestparams, $endpoint, "POST", $key, $secret, $submittext, $orgid /*, $orgdesc*/); - - $debuglaunch = ( $instance->debuglaunch == 1 ); - - $content = post_launch_html($parms, $endpoint, $debuglaunch); - - echo $content; -} - -/** - * This function builds the request that must be sent to the tool producer - * - * @param object $instance Basic LTI instance object - * @param object $typeconfig Basic LTI tool configuration - * @param object $course Course object - * - * @return array $request Request details - */ -function lti_build_request($instance, $typeconfig, $course) { - global $USER, $CFG; - - $context = get_context_instance(CONTEXT_COURSE, $course->id); - $role = lti_get_ims_role($USER, $context); - - $locale = $course->lang; - if ( strlen($locale) < 1 ) { - $locale = $CFG->lang; - } - - $requestparams = array( - "resource_link_id" => $instance->id, - "resource_link_title" => $instance->name, - "resource_link_description" => $instance->intro, - "user_id" => $USER->id, - "roles" => $role, - "context_id" => $course->id, - "context_label" => $course->shortname, - "context_title" => $course->fullname, - "launch_presentation_locale" => $locale, - ); - - $placementsecret = $typeconfig['servicesalt']; - if ( isset($placementsecret) ) { - $suffix = ':::' . $USER->id . ':::' . $instance->id; - $plaintext = $placementsecret . $suffix; - $hashsig = hash('sha256', $plaintext, false); - $sourcedid = $hashsig . $suffix; - } - - if ( isset($placementsecret) && - ( $typeconfig['acceptgrades'] == 1 || - ( $typeconfig['acceptgrades'] == 2 && $instance->instructorchoiceacceptgrades == 1 ) ) ) { - $requestparams["lis_result_sourcedid"] = $sourcedid; - $requestparams["ext_ims_lis_basic_outcome_url"] = $CFG->wwwroot.'/mod/lti/service.php'; - } - - if ( isset($placementsecret) && - ( $typeconfig['allowroster'] == 1 || - ( $typeconfig['allowroster'] == 2 && $instance->instructorchoiceallowroster == 1 ) ) ) { - $requestparams["ext_ims_lis_memberships_id"] = $sourcedid; - $requestparams["ext_ims_lis_memberships_url"] = $CFG->wwwroot.'/mod/lti/service.php'; - } - - // Send user's name and email data if appropriate - if ( $typeconfig['sendname'] == 1 || - ( $typeconfig['sendname'] == 2 && $instance->instructorchoicesendname == 1 ) ) { - $requestparams["lis_person_name_given"] = $USER->firstname; - $requestparams["lis_person_name_family"] = $USER->lastname; - $requestparams["lis_person_name_full"] = $USER->firstname." ".$USER->lastname; - } - - if ( $typeconfig['sendemailaddr'] == 1 || - ( $typeconfig['sendemailaddr'] == 2 && $instance->instructorchoicesendemailaddr == 1 ) ) { - $requestparams["lis_person_contact_email_primary"] = $USER->email; - } - - // Concatenate the custom parameters from the administrator and the instructor - // Instructor parameters are only taken into consideration if the administrator - // has giver permission - $customstr = $typeconfig['customparameters']; - $instructorcustomstr = $instance->instructorcustomparameters; - $custom = array(); - $instructorcustom = array(); - if ($customstr) { - $custom = split_custom_parameters($customstr); - } - if (!isset($typeconfig['allowinstructorcustom']) || $typeconfig['allowinstructorcustom'] == 0) { - $requestparams = array_merge($custom, $requestparams); - } else { - if ($instructorcustomstr) { - $instructorcustom = split_custom_parameters($instructorcustomstr); - } - foreach ($instructorcustom as $key => $val) { - if (array_key_exists($key, $custom)) { - // Ignore the instructor's parameter - } else { - $custom[$key] = $val; - } - } - $requestparams = array_merge($custom, $requestparams); - } - - return $requestparams; -} - -/** - * Splits the custom parameters field to the various parameters - * - * @param string $customstr String containing the parameters - * - * @return Array of custom parameters - */ -function split_custom_parameters($customstr) { - $textlib = textlib_get_instance(); - - $lines = preg_split("/[\n;]/", $customstr); - $retval = array(); - foreach ($lines as $line) { - $pos = strpos($line, "="); - if ( $pos === false || $pos < 1 ) { - continue; - } - $key = trim($textlib->substr($line, 0, $pos)); - $val = trim($textlib->substr($line, $pos+1)); - $key = map_keyname($key); - $retval['custom_'.$key] = $val; - } - return $retval; -} - -/** - * Used for building the names of the different custom parameters - * - * @param string $key Parameter name - * - * @return string Processed name - */ -function map_keyname($key) { - $textlib = textlib_get_instance(); - - $newkey = ""; - $key = $textlib->strtolower(trim($key)); - foreach (str_split($key) as $ch) { - if ( ($ch >= 'a' && $ch <= 'z') || ($ch >= '0' && $ch <= '9') ) { - $newkey .= $ch; - } else { - $newkey .= '_'; - } - } - return $newkey; -} - -/** - * Returns the IMS user role in a given context - * - * This function queries Moodle for an user role and - * returns the correspondant IMS role - * - * @param StdClass $user Moodle user instance - * @param StdClass $context Moodle context - * - * @return string IMS Role - * - */ -function lti_get_ims_role($user, $context) { - - $roles = get_user_roles($context, $user->id); - $rolesname = array(); - foreach ($roles as $role) { - $rolesname[] = $role->shortname; - } - - if (in_array('admin', $rolesname) || in_array('coursecreator', $rolesname)) { - return get_string('imsroleadmin', 'lti'); - } - - if (in_array('editingteacher', $rolesname) || in_array('teacher', $rolesname)) { - return get_string('imsroleinstructor', 'lti'); - } - - return get_string('imsrolelearner', 'lti'); -} - -/** - * Returns configuration details for the tool - * - * @param int $typeid Basic LTI tool typeid - * - * @return array Tool Configuration - */ -function lti_get_type_config($typeid) { - global $DB; - - $typeconfig = array(); - $configs = $DB->get_records('lti_types_config', array('typeid' => $typeid)); - if (!empty($configs)) { - foreach ($configs as $config) { - $typeconfig[$config->name] = $config->value; - } - } - return $typeconfig; -} - -function lti_get_tools_by_url($url, $state){ - $domain = lti_get_domain_from_url($url); - - return lti_get_tools_by_domain($domain, $state); -} - -function lti_get_tools_by_domain($domain, $state = null, $courseid = null){ - global $DB, $SITE; - - $filters = array('tooldomain' => $domain); - - $statefilter = ''; - $coursefilter = ''; - - if($state){ - $statefilter = 'AND state = :state'; - } - - if($courseid && $courseid != $SITE->id){ - $coursefilter = 'OR course = :courseid'; - } - - $query = <<get_records_sql($query, array( - 'courseid' => $courseid, - 'siteid' => $SITE->id, - 'tooldomain' => $domain, - 'state' => $state - )); -} - -/** - * Returns all basicLTI tools configured by the administrator - * - */ -function lti_filter_get_types() { - global $DB; - - return $DB->get_records('lti_types'); -} - -function lti_get_types_for_add_instance(){ - global $DB; - $admintypes = $DB->get_records('lti_types', array('coursevisible' => 1)); - - $types = array(); - $types[0] = get_string('automatic', 'lti'); - - foreach($admintypes as $type) { - $types[$type->id] = $type->name; - } - - return $types; -} - -function lti_get_domain_from_url($url){ - $matches = array(); - - if(preg_match(LTI_URL_DOMAIN_REGEX, $url, $matches)){ - return $matches[1]; - } -} - -function lti_get_tool_by_url_match($url, $courseid = null, $state = LTI_TOOL_STATE_CONFIGURED){ - $possibletools = lti_get_tools_by_url($url, $state, $courseid); - - return lti_get_best_tool_by_url($url, $possibletools); -} - -function lti_get_url_thumbprint($url){ - $urlparts = parse_url(strtolower($url)); - if(!isset($urlparts['path'])){ - $urlparts['path'] = ''; - } - - if(substr($urlparts['host'], 0, 3) === 'www'){ - $urllparts['host'] = substr(3); - } - - return $urllower = $urlparts['host'] . '/' . $urlparts['path']; -} - -function lti_get_best_tool_by_url($url, $tools){ - if(count($tools) === 0){ - return null; - } - - $urllower = lti_get_url_thumbprint($url); - - foreach($tools as $tool){ - $tool->_matchscore = 0; - - $toolbaseurllower = lti_get_url_thumbprint($tool->baseurl); - - if($urllower === $toolbaseurllower){ - //100 points for exact match - $tool->_matchscore += 100; - } else if(substr($urllower, 0, strlen($toolbaseurllower)) === $toolbaseurllower){ - //50 points if it starts with the base URL - $tool->_matchscore += 50; - } - } - - $bestmatch = array_reduce($tools, function($value, $tool){ - if($tool->_matchscore > $value->_matchscore){ - return $tool; - } else { - return $value; - } - - }, (object)array('_matchscore' => -1)); - - //None of the tools are suitable for this URL - if($bestmatch->_matchscore <= 0){ - return null; - } - - return $bestmatch; -} - -/** - * Prints the various configured tool types - * - */ -function lti_filter_print_types() { - global $CFG; - - $types = lti_filter_get_types(); - if (!empty($types)) { - echo '
    '; - foreach ($types as $type) { - echo '
  • '. - $type->name. - ''. - ''. - 'Update'. - ''. - ''. - 'Delete'. - ''. - ''. - '
  • '; - - } - echo '
'; - } else { - echo '
'; - echo get_string('notypes', 'lti'); - echo '
'; - } -} - -/** - * Delete a Basic LTI configuration - * - * @param int $id Configuration id - */ -function lti_delete_type($id) { - global $DB; - - //We should probably just copy the launch URL to the tool instances in this case... using a single query - /* - $instances = $DB->get_records('lti', array('typeid' => $id)); - foreach ($instances as $instance) { - $instance->typeid = 0; - $DB->update_record('lti', $instance); - }*/ - - $DB->delete_records('lti_types', array('id' => $id)); - $DB->delete_records('lti_types_config', array('typeid' => $id)); -} - -function lti_set_state_for_type($id, $state){ - global $DB; - - $DB->update_record('lti_types', array('id' => $id, 'state' => $state)); -} - -/** - * Transforms a basic LTI object to an array - * - * @param object $ltiobject Basic LTI object - * - * @return array Basic LTI configuration details - */ -function lti_get_config($ltiobject) { - $typeconfig = array(); - $typeconfig = (array)$ltiobject; - $additionalconfig = lti_get_type_config($ltiobject->typeid); - $typeconfig = array_merge($typeconfig, $additionalconfig); - return $typeconfig; -} - -/** - * - * Generates some of the tool configuration based on the instance details - * - * @param int $id - * - * @return Instance configuration - * - */ -function lti_get_type_config_from_instance($id) { - global $DB; - - $instance = $DB->get_record('lti', array('id' => $id)); - $config = lti_get_config($instance); - - $type = new stdClass(); - $type->lti_fix = $id; - if (isset($config['toolurl'])) { - $type->lti_toolurl = $config['toolurl']; - } - if (isset($config['instructorchoicesendname'])) { - $type->lti_sendname = $config['instructorchoicesendname']; - } - if (isset($config['instructorchoicesendemailaddr'])) { - $type->lti_sendemailaddr = $config['instructorchoicesendemailaddr']; - } - if (isset($config['instructorchoiceacceptgrades'])) { - $type->lti_acceptgrades = $config['instructorchoiceacceptgrades']; - } - if (isset($config['instructorchoiceallowroster'])) { - $type->lti_allowroster = $config['instructorchoiceallowroster']; - } - - if (isset($config['instructorcustomparameters'])) { - $type->lti_allowsetting = $config['instructorcustomparameters']; - } - return $type; -} - -/** - * Generates some of the tool configuration based on the admin configuration details - * - * @param int $id - * - * @return Configuration details - */ -function lti_get_type_type_config($id) { - global $DB; - - $basicltitype = $DB->get_record('lti_types', array('id' => $id)); - $config = lti_get_type_config($id); - - $type->lti_typename = $basicltitype->name; - - $type->lti_toolurl = $basicltitype->baseurl; - - if (isset($config['resourcekey'])) { - $type->lti_resourcekey = $config['resourcekey']; - } - if (isset($config['password'])) { - $type->lti_password = $config['password']; - } - - if (isset($config['sendname'])) { - $type->lti_sendname = $config['sendname']; - } - if (isset($config['instructorchoicesendname'])){ - $type->lti_instructorchoicesendname = $config['instructorchoicesendname']; - } - if (isset($config['sendemailaddr'])){ - $type->lti_sendemailaddr = $config['sendemailaddr']; - } - if (isset($config['instructorchoicesendemailaddr'])){ - $type->lti_instructorchoicesendemailaddr = $config['instructorchoicesendemailaddr']; - } - if (isset($config['acceptgrades'])){ - $type->lti_acceptgrades = $config['acceptgrades']; - } - if (isset($config['instructorchoiceacceptgrades'])){ - $type->lti_instructorchoiceacceptgrades = $config['instructorchoiceacceptgrades']; - } - if (isset($config['allowroster'])){ - $type->lti_allowroster = $config['allowroster']; - } - if (isset($config['instructorchoiceallowroster'])){ - $type->lti_instructorchoiceallowroster = $config['instructorchoiceallowroster']; - } - - if (isset($config['customparameters'])) { - $type->lti_customparameters = $config['customparameters']; - } - - if (isset($config['organizationid'])) { - $type->lti_organizationid = $config['organizationid']; - } - if (isset($config['organizationurl'])) { - $type->lti_organizationurl = $config['organizationurl']; - } - if (isset($config['organizationdescr'])) { - $type->lti_organizationdescr = $config['organizationdescr']; - } - if (isset($config['launchcontainer'])) { - $type->lti_launchcontainer = $config['launchcontainer']; - } - - if (isset($config['coursevisible'])) { - $type->lti_coursevisible = $config['coursevisible']; - } - - if (isset($config['debuglaunch'])) { - $type->lti_debuglaunch = $config['debuglaunch']; - } - - if (isset($config['module_class_type'])) { - $type->lti_module_class_type = $config['module_class_type']; - } - - return $type; -} - -function lti_prepare_type_for_save($type, $config){ - $type->baseurl = $config->lti_toolurl; - $type->tooldomain = lti_get_domain_from_url($config->lti_toolurl); - $type->name = $config->lti_typename; - - $type->coursevisible = !empty($config->lti_coursevisible) ? $config->lti_coursevisible : 0; - $config->lti_coursevisible = $type->coursevisible; - - $type->timemodified = time(); - - unset ($config->lti_typename); - unset ($config->lti_toolurl); -} - -function lti_update_type($type, $config){ - global $DB; - - lti_prepare_type_for_save($type, $config); - - if ($DB->update_record('lti_types', $type)) { - foreach ($config as $key => $value) { - if (substr($key, 0, 4)=='lti_' && !is_null($value)) { - $record = new StdClass(); - $record->typeid = $type->id; - $record->name = substr($key, 4); - $record->value = $value; - - lti_update_config($record); - } - } - } -} - -function lti_add_type($type, $config){ - global $USER, $SITE, $DB; - - lti_prepare_type_for_save($type, $config); - - if(!isset($type->state)){ - $type->state = LTI_TOOL_STATE_PENDING; - } - - if(!isset($type->timecreated)){ - $type->timecreated = time(); - } - - if(!isset($type->createdby)){ - $type->createdby = $USER->id; - } - - if(!isset($type->course)){ - $type->course = $SITE->id; - } - - //Create a salt value to be used for signing passed data to extension services - $config->lti_servicesalt = uniqid('', true); - - $id = $DB->insert_record('lti_types', $type); - - if ($id) { - foreach ($config as $key => $value) { - if (substr($key, 0, 4)=='lti_' && !is_null($value)) { - $record = new StdClass(); - $record->typeid = $id; - $record->name = substr($key, 4); - $record->value = $value; - - lti_add_config($record); - } - } - } -} - -/** - * Add a tool configuration in the database - * - * @param $config Tool configuration - * - * @return int Record id number - */ -function lti_add_config($config) { - global $DB; - - return $DB->insert_record('lti_types_config', $config); -} - -/** - * Updates a tool configuration in the database - * - * @param $config Tool configuration - * - * @return Record id number - */ -function lti_update_config($config) { - global $DB; - - $return = true; - $old = $DB->get_record('lti_types_config', array('typeid' => $config->typeid, 'name' => $config->name)); - - if ($old) { - $config->id = $old->id; - $return = $DB->update_record('lti_types_config', $config); - } else { - $return = $DB->insert_record('lti_types_config', $config); - } - return $return; -} - -/** - * Signs the petition to launch the external tool using OAuth - * - * @param $oldparms Parameters to be passed for signing - * @param $endpoint url of the external tool - * @param $method Method for sending the parameters (e.g. POST) - * @param $oauth_consumoer_key Key - * @param $oauth_consumoer_secret Secret - * @param $submittext The text for the submit button - * @param $orgid LMS name - * @param $orgdesc LMS key - */ -function sign_parameters($oldparms, $endpoint, $method, $oauthconsumerkey, $oauthconsumersecret, $submittext, $orgid /*, $orgdesc*/) { - global $lastbasestring; - $parms = $oldparms; - $parms["lti_version"] = "LTI-1p0"; - $parms["lti_message_type"] = "basic-lti-launch-request"; - if ( $orgid ) { - $parms["tool_consumer_instance_guid"] = $orgid; - } - /* Suppress this for now - Chuck - if ( $orgdesc ) $parms["tool_consumer_instance_description"] = $orgdesc; - */ - $parms["ext_submit"] = $submittext; - - $testtoken = ''; - - $hmacmethod = new OAuthSignatureMethod_HMAC_SHA1(); - $testconsumer = new OAuthConsumer($oauthconsumerkey, $oauthconsumersecret, null); - - $accreq = OAuthRequest::from_consumer_and_token($testconsumer, $testtoken, $method, $endpoint, $parms); - $accreq->sign_request($hmacmethod, $testconsumer, $testtoken); - - // Pass this back up "out of band" for debugging - $lastbasestring = $accreq->get_signature_base_string(); - - $newparms = $accreq->get_parameters(); - - return $newparms; -} - -/** - * Posts the launch petition HTML - * - * @param $newparms Signed parameters - * @param $endpoint URL of the external tool - * @param $debug Debug (true/false) - */ -function post_launch_html($newparms, $endpoint, $debug=false) { - global $lastbasestring; - - $r = "
\n"; - - $submittext = $newparms['ext_submit']; - - // Contruct html for the launch parameters - foreach ($newparms as $key => $value) { - $key = htmlspecialchars($key); - $value = htmlspecialchars($value); - if ( $key == "ext_submit" ) { - $r .= "\n"; - } - - if ( $debug ) { - $r .= "\n"; - $r .= ""; - $r .= get_string("toggle_debug_data", "lti")."\n"; - $r .= "
\n"; - $r .= "".get_string("basiclti_endpoint", "lti")."
\n"; - $r .= $endpoint . "
\n 
\n"; - $r .= "".get_string("basiclti_parameters", "lti")."
\n"; - foreach ($newparms as $key => $value) { - $key = htmlspecialchars($key); - $value = htmlspecialchars($value); - $r .= "$key = $value
\n"; - } - $r .= " 
\n"; - $r .= "

".get_string("basiclti_base_string", "lti")."
\n".$lastbasestring."

\n"; - $r .= "
\n"; - } - $r .= "\n"; - - if ( ! $debug ) { - $ext_submit = "ext_submit"; - $ext_submit_text = $submittext; - $r .= " \n"; - } - return $r; -} - -/** - * Returns a link with info about the state of the basiclti submissions - * - * This is used by view_header to put this link at the top right of the page. - * For teachers it gives the number of submitted assignments with a link - * For students it gives the time of their submission. - * This will be suitable for most assignment types. - * - * @global object - * @global object - * @param bool $allgroup print all groups info if user can access all groups, suitable for index.php - * @return string - */ -function submittedlink($cm, $allgroups=false) { - global $CFG; - - $submitted = ''; - $urlbase = "{$CFG->wwwroot}/mod/lti/"; - - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - if (has_capability('mod/lti:grade', $context)) { - if ($allgroups and has_capability('moodle/site:accessallgroups', $context)) { - $group = 0; - } else { - $group = groups_get_activity_group($cm); - } - - $submitted = ''. - get_string('viewsubmissions', 'lti').''; - } else { - if (isloggedin()) { - // TODO Insert code for students if needed - } - } - - return $submitted; -} - +. + +/** + * This file contains the library of functions and constants for the basiclti module + * + * @package lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +require_once($CFG->dirroot.'/mod/lti/OAuth.php'); + +define('LTI_URL_DOMAIN_REGEX', '/(?:https?:\/\/)?(?:www\.)?([^\/]+)(?:\/|$)/i'); + +define('LTI_LAUNCH_CONTAINER_DEFAULT', 1); +define('LTI_LAUNCH_CONTAINER_EMBED', 2); +define('LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS', 3); +define('LTI_LAUNCH_CONTAINER_WINDOW', 4); + +define('LTI_TOOL_STATE_ANY', 0); +define('LTI_TOOL_STATE_CONFIGURED', 1); +define('LTI_TOOL_STATE_PENDING', 2); +define('LTI_TOOL_STATE_REJECTED', 3); + +define('LTI_SETTING_NEVER', 0); +define('LTI_SETTING_ALWAYS', 1); +define('LTI_SETTING_DEFAULT', 2); + +/** + * Prints a Basic LTI activity + * + * $param int $basicltiid Basic LTI activity id + */ +function lti_view($instance, $makeobject=false) { + global $PAGE, $CFG; + + if(empty($instance->typeid)){ + $tool = lti_get_tool_by_url_match($instance->toolurl); + if($tool){ + $typeid = $tool->id; + } else { + $typeid = null; + } + } else { + $typeid = $instance->typeid; + } + + if($typeid){ + $typeconfig = lti_get_type_config($typeid); + } else { + //There is no admin configuration for this tool. Use configuration in the lti instance record plus some defaults. + $typeconfig = (array)$instance; + + $typeconfig['sendname'] = $instance->instructorchoicesendname; + $typeconfig['sendemailaddr'] = $instance->instructorchoicesendemailaddr; + $typeconfig['customparameters'] = $instance->instructorcustomparameters; + } + + //Default the organizationid if not specified + if(empty($typeconfig['organizationid'])){ + $urlparts = parse_url($CFG->wwwroot); + + $typeconfig['organizationid'] = $urlparts['host']; + } + + $endpoint = !empty($instance->toolurl) ? $instance->toolurl : $typeconfig['toolurl']; + $key = !empty($instance->resourcekey) ? $instance->resourcekey : $typeconfig['resourcekey']; + $secret = !empty($instance->password) ? $instance->password : $typeconfig['password']; + $orgid = $typeconfig['organizationid']; + /* Suppress this for now - Chuck + $orgdesc = $typeconfig['organizationdescr']; + */ + + $course = $PAGE->course; + $requestparams = lti_build_request($instance, $typeconfig, $course); + + // Make sure we let the tool know what LMS they are being called from + $requestparams["ext_lms"] = "moodle-2"; + + // Add oauth_callback to be compliant with the 1.0A spec + $requestparams["oauth_callback"] = "about:blank"; + + $submittext = get_string('press_to_submit', 'lti'); + $parms = sign_parameters($requestparams, $endpoint, "POST", $key, $secret, $submittext, $orgid /*, $orgdesc*/); + + $debuglaunch = ( $instance->debuglaunch == 1 ); + + $content = post_launch_html($parms, $endpoint, $debuglaunch); + + echo $content; +} + +/** + * This function builds the request that must be sent to the tool producer + * + * @param object $instance Basic LTI instance object + * @param object $typeconfig Basic LTI tool configuration + * @param object $course Course object + * + * @return array $request Request details + */ +function lti_build_request($instance, $typeconfig, $course) { + global $USER, $CFG; + + $context = get_context_instance(CONTEXT_COURSE, $course->id); + $role = lti_get_ims_role($USER, $context); + + $locale = $course->lang; + if ( strlen($locale) < 1 ) { + $locale = $CFG->lang; + } + + $requestparams = array( + "resource_link_id" => $instance->id, + "resource_link_title" => $instance->name, + "resource_link_description" => $instance->intro, + "user_id" => $USER->id, + "roles" => $role, + "context_id" => $course->id, + "context_label" => $course->shortname, + "context_title" => $course->fullname, + "launch_presentation_locale" => $locale, + ); + + //$placementsecret = $typeconfig['servicesalt']; + + //Always use the servicesalt on the instance. + //TODO: Remove from type settings + $placementsecret = $instance->servicesalt; + + if ( isset($placementsecret) ) { + $data = new stdClass(); + + $data->instanceid = $instance->id; + $data->userid = $USER->id; + + $json = json_encode($data); + + $hash = hash('sha256', $json . $placementsecret, false); + + $container = new stdClass(); + $container->data = $data; + $container->hash = $hash; + + $sourcedid = json_encode($container); + } + + if ( isset($placementsecret) && + ( $typeconfig['acceptgrades'] == 1 || + ( $typeconfig['acceptgrades'] == 2 && $instance->instructorchoiceacceptgrades == 1 ) ) ) { + $requestparams["lis_result_sourcedid"] = $sourcedid; + $requestparams["ext_ims_lis_basic_outcome_url"] = $CFG->wwwroot.'/mod/lti/service.php'; + } + + if ( isset($placementsecret) && + ( $typeconfig['allowroster'] == 1 || + ( $typeconfig['allowroster'] == 2 && $instance->instructorchoiceallowroster == 1 ) ) ) { + $requestparams["ext_ims_lis_memberships_id"] = $sourcedid; + $requestparams["ext_ims_lis_memberships_url"] = $CFG->wwwroot.'/mod/lti/service.php'; + } + + // Send user's name and email data if appropriate + if ( $typeconfig['sendname'] == 1 || + ( $typeconfig['sendname'] == 2 && $instance->instructorchoicesendname == 1 ) ) { + $requestparams["lis_person_name_given"] = $USER->firstname; + $requestparams["lis_person_name_family"] = $USER->lastname; + $requestparams["lis_person_name_full"] = $USER->firstname." ".$USER->lastname; + } + + if ( $typeconfig['sendemailaddr'] == 1 || + ( $typeconfig['sendemailaddr'] == 2 && $instance->instructorchoicesendemailaddr == 1 ) ) { + $requestparams["lis_person_contact_email_primary"] = $USER->email; + } + + // Concatenate the custom parameters from the administrator and the instructor + // Instructor parameters are only taken into consideration if the administrator + // has giver permission + $customstr = $typeconfig['customparameters']; + $instructorcustomstr = $instance->instructorcustomparameters; + $custom = array(); + $instructorcustom = array(); + if ($customstr) { + $custom = split_custom_parameters($customstr); + } + if (!isset($typeconfig['allowinstructorcustom']) || $typeconfig['allowinstructorcustom'] == 0) { + $requestparams = array_merge($custom, $requestparams); + } else { + if ($instructorcustomstr) { + $instructorcustom = split_custom_parameters($instructorcustomstr); + } + foreach ($instructorcustom as $key => $val) { + if (array_key_exists($key, $custom)) { + // Ignore the instructor's parameter + } else { + $custom[$key] = $val; + } + } + $requestparams = array_merge($custom, $requestparams); + } + + return $requestparams; +} + +/** + * Splits the custom parameters field to the various parameters + * + * @param string $customstr String containing the parameters + * + * @return Array of custom parameters + */ +function split_custom_parameters($customstr) { + $textlib = textlib_get_instance(); + + $lines = preg_split("/[\n;]/", $customstr); + $retval = array(); + foreach ($lines as $line) { + $pos = strpos($line, "="); + if ( $pos === false || $pos < 1 ) { + continue; + } + $key = trim($textlib->substr($line, 0, $pos)); + $val = trim($textlib->substr($line, $pos+1)); + $key = map_keyname($key); + $retval['custom_'.$key] = $val; + } + return $retval; +} + +/** + * Used for building the names of the different custom parameters + * + * @param string $key Parameter name + * + * @return string Processed name + */ +function map_keyname($key) { + $textlib = textlib_get_instance(); + + $newkey = ""; + $key = $textlib->strtolower(trim($key)); + foreach (str_split($key) as $ch) { + if ( ($ch >= 'a' && $ch <= 'z') || ($ch >= '0' && $ch <= '9') ) { + $newkey .= $ch; + } else { + $newkey .= '_'; + } + } + return $newkey; +} + +/** + * Returns the IMS user role in a given context + * + * This function queries Moodle for an user role and + * returns the correspondant IMS role + * + * @param StdClass $user Moodle user instance + * @param StdClass $context Moodle context + * + * @return string IMS Role + * + */ +function lti_get_ims_role($user, $context) { + + $roles = get_user_roles($context, $user->id); + $rolesname = array(); + foreach ($roles as $role) { + $rolesname[] = $role->shortname; + } + + if (in_array('admin', $rolesname) || in_array('coursecreator', $rolesname)) { + return get_string('imsroleadmin', 'lti'); + } + + if (in_array('editingteacher', $rolesname) || in_array('teacher', $rolesname)) { + return get_string('imsroleinstructor', 'lti'); + } + + return get_string('imsrolelearner', 'lti'); +} + +/** + * Returns configuration details for the tool + * + * @param int $typeid Basic LTI tool typeid + * + * @return array Tool Configuration + */ +function lti_get_type_config($typeid) { + global $DB; + + $typeconfig = array(); + $configs = $DB->get_records('lti_types_config', array('typeid' => $typeid)); + if (!empty($configs)) { + foreach ($configs as $config) { + $typeconfig[$config->name] = $config->value; + } + } + return $typeconfig; +} + +function lti_get_tools_by_url($url, $state){ + $domain = lti_get_domain_from_url($url); + + return lti_get_tools_by_domain($domain, $state); +} + +function lti_get_tools_by_domain($domain, $state = null, $courseid = null){ + global $DB, $SITE; + + $filters = array('tooldomain' => $domain); + + $statefilter = ''; + $coursefilter = ''; + + if($state){ + $statefilter = 'AND state = :state'; + } + + if($courseid && $courseid != $SITE->id){ + $coursefilter = 'OR course = :courseid'; + } + + $query = <<get_records_sql($query, array( + 'courseid' => $courseid, + 'siteid' => $SITE->id, + 'tooldomain' => $domain, + 'state' => $state + )); +} + +/** + * Returns all basicLTI tools configured by the administrator + * + */ +function lti_filter_get_types() { + global $DB; + + return $DB->get_records('lti_types'); +} + +function lti_get_types_for_add_instance(){ + global $DB; + $admintypes = $DB->get_records('lti_types', array('coursevisible' => 1)); + + $types = array(); + $types[0] = get_string('automatic', 'lti'); + + foreach($admintypes as $type) { + $types[$type->id] = $type->name; + } + + return $types; +} + +function lti_get_domain_from_url($url){ + $matches = array(); + + if(preg_match(LTI_URL_DOMAIN_REGEX, $url, $matches)){ + return $matches[1]; + } +} + +function lti_get_tool_by_url_match($url, $courseid = null, $state = LTI_TOOL_STATE_CONFIGURED){ + $possibletools = lti_get_tools_by_url($url, $state, $courseid); + + return lti_get_best_tool_by_url($url, $possibletools); +} + +function lti_get_url_thumbprint($url){ + $urlparts = parse_url(strtolower($url)); + if(!isset($urlparts['path'])){ + $urlparts['path'] = ''; + } + + if(substr($urlparts['host'], 0, 3) === 'www'){ + $urllparts['host'] = substr(3); + } + + return $urllower = $urlparts['host'] . '/' . $urlparts['path']; +} + +function lti_get_best_tool_by_url($url, $tools){ + if(count($tools) === 0){ + return null; + } + + $urllower = lti_get_url_thumbprint($url); + + foreach($tools as $tool){ + $tool->_matchscore = 0; + + $toolbaseurllower = lti_get_url_thumbprint($tool->baseurl); + + if($urllower === $toolbaseurllower){ + //100 points for exact match + $tool->_matchscore += 100; + } else if(substr($urllower, 0, strlen($toolbaseurllower)) === $toolbaseurllower){ + //50 points if it starts with the base URL + $tool->_matchscore += 50; + } + } + + $bestmatch = array_reduce($tools, function($value, $tool){ + if($tool->_matchscore > $value->_matchscore){ + return $tool; + } else { + return $value; + } + + }, (object)array('_matchscore' => -1)); + + //None of the tools are suitable for this URL + if($bestmatch->_matchscore <= 0){ + return null; + } + + return $bestmatch; +} + +/** + * Prints the various configured tool types + * + */ +function lti_filter_print_types() { + global $CFG; + + $types = lti_filter_get_types(); + if (!empty($types)) { + echo '
    '; + foreach ($types as $type) { + echo '
  • '. + $type->name. + ''. + ''. + 'Update'. + ''. + ''. + 'Delete'. + ''. + ''. + '
  • '; + + } + echo '
'; + } else { + echo '
'; + echo get_string('notypes', 'lti'); + echo '
'; + } +} + +/** + * Delete a Basic LTI configuration + * + * @param int $id Configuration id + */ +function lti_delete_type($id) { + global $DB; + + //We should probably just copy the launch URL to the tool instances in this case... using a single query + /* + $instances = $DB->get_records('lti', array('typeid' => $id)); + foreach ($instances as $instance) { + $instance->typeid = 0; + $DB->update_record('lti', $instance); + }*/ + + $DB->delete_records('lti_types', array('id' => $id)); + $DB->delete_records('lti_types_config', array('typeid' => $id)); +} + +function lti_set_state_for_type($id, $state){ + global $DB; + + $DB->update_record('lti_types', array('id' => $id, 'state' => $state)); +} + +/** + * Transforms a basic LTI object to an array + * + * @param object $ltiobject Basic LTI object + * + * @return array Basic LTI configuration details + */ +function lti_get_config($ltiobject) { + $typeconfig = array(); + $typeconfig = (array)$ltiobject; + $additionalconfig = lti_get_type_config($ltiobject->typeid); + $typeconfig = array_merge($typeconfig, $additionalconfig); + return $typeconfig; +} + +/** + * + * Generates some of the tool configuration based on the instance details + * + * @param int $id + * + * @return Instance configuration + * + */ +function lti_get_type_config_from_instance($id) { + global $DB; + + $instance = $DB->get_record('lti', array('id' => $id)); + $config = lti_get_config($instance); + + $type = new stdClass(); + $type->lti_fix = $id; + if (isset($config['toolurl'])) { + $type->lti_toolurl = $config['toolurl']; + } + if (isset($config['instructorchoicesendname'])) { + $type->lti_sendname = $config['instructorchoicesendname']; + } + if (isset($config['instructorchoicesendemailaddr'])) { + $type->lti_sendemailaddr = $config['instructorchoicesendemailaddr']; + } + if (isset($config['instructorchoiceacceptgrades'])) { + $type->lti_acceptgrades = $config['instructorchoiceacceptgrades']; + } + if (isset($config['instructorchoiceallowroster'])) { + $type->lti_allowroster = $config['instructorchoiceallowroster']; + } + + if (isset($config['instructorcustomparameters'])) { + $type->lti_allowsetting = $config['instructorcustomparameters']; + } + return $type; +} + +/** + * Generates some of the tool configuration based on the admin configuration details + * + * @param int $id + * + * @return Configuration details + */ +function lti_get_type_type_config($id) { + global $DB; + + $basicltitype = $DB->get_record('lti_types', array('id' => $id)); + $config = lti_get_type_config($id); + + $type->lti_typename = $basicltitype->name; + + $type->lti_toolurl = $basicltitype->baseurl; + + if (isset($config['resourcekey'])) { + $type->lti_resourcekey = $config['resourcekey']; + } + if (isset($config['password'])) { + $type->lti_password = $config['password']; + } + + if (isset($config['sendname'])) { + $type->lti_sendname = $config['sendname']; + } + if (isset($config['instructorchoicesendname'])){ + $type->lti_instructorchoicesendname = $config['instructorchoicesendname']; + } + if (isset($config['sendemailaddr'])){ + $type->lti_sendemailaddr = $config['sendemailaddr']; + } + if (isset($config['instructorchoicesendemailaddr'])){ + $type->lti_instructorchoicesendemailaddr = $config['instructorchoicesendemailaddr']; + } + if (isset($config['acceptgrades'])){ + $type->lti_acceptgrades = $config['acceptgrades']; + } + if (isset($config['instructorchoiceacceptgrades'])){ + $type->lti_instructorchoiceacceptgrades = $config['instructorchoiceacceptgrades']; + } + if (isset($config['allowroster'])){ + $type->lti_allowroster = $config['allowroster']; + } + if (isset($config['instructorchoiceallowroster'])){ + $type->lti_instructorchoiceallowroster = $config['instructorchoiceallowroster']; + } + + if (isset($config['customparameters'])) { + $type->lti_customparameters = $config['customparameters']; + } + + if (isset($config['organizationid'])) { + $type->lti_organizationid = $config['organizationid']; + } + if (isset($config['organizationurl'])) { + $type->lti_organizationurl = $config['organizationurl']; + } + if (isset($config['organizationdescr'])) { + $type->lti_organizationdescr = $config['organizationdescr']; + } + if (isset($config['launchcontainer'])) { + $type->lti_launchcontainer = $config['launchcontainer']; + } + + if (isset($config['coursevisible'])) { + $type->lti_coursevisible = $config['coursevisible']; + } + + if (isset($config['debuglaunch'])) { + $type->lti_debuglaunch = $config['debuglaunch']; + } + + if (isset($config['module_class_type'])) { + $type->lti_module_class_type = $config['module_class_type']; + } + + return $type; +} + +function lti_prepare_type_for_save($type, $config){ + $type->baseurl = $config->lti_toolurl; + $type->tooldomain = lti_get_domain_from_url($config->lti_toolurl); + $type->name = $config->lti_typename; + + $type->coursevisible = !empty($config->lti_coursevisible) ? $config->lti_coursevisible : 0; + $config->lti_coursevisible = $type->coursevisible; + + $type->timemodified = time(); + + unset ($config->lti_typename); + unset ($config->lti_toolurl); +} + +function lti_update_type($type, $config){ + global $DB; + + lti_prepare_type_for_save($type, $config); + + if ($DB->update_record('lti_types', $type)) { + foreach ($config as $key => $value) { + if (substr($key, 0, 4)=='lti_' && !is_null($value)) { + $record = new StdClass(); + $record->typeid = $type->id; + $record->name = substr($key, 4); + $record->value = $value; + + lti_update_config($record); + } + } + } +} + +function lti_add_type($type, $config){ + global $USER, $SITE, $DB; + + lti_prepare_type_for_save($type, $config); + + if(!isset($type->state)){ + $type->state = LTI_TOOL_STATE_PENDING; + } + + if(!isset($type->timecreated)){ + $type->timecreated = time(); + } + + if(!isset($type->createdby)){ + $type->createdby = $USER->id; + } + + if(!isset($type->course)){ + $type->course = $SITE->id; + } + + //Create a salt value to be used for signing passed data to extension services + $config->lti_servicesalt = uniqid('', true); + + $id = $DB->insert_record('lti_types', $type); + + if ($id) { + foreach ($config as $key => $value) { + if (substr($key, 0, 4)=='lti_' && !is_null($value)) { + $record = new StdClass(); + $record->typeid = $id; + $record->name = substr($key, 4); + $record->value = $value; + + lti_add_config($record); + } + } + } +} + +/** + * Add a tool configuration in the database + * + * @param $config Tool configuration + * + * @return int Record id number + */ +function lti_add_config($config) { + global $DB; + + return $DB->insert_record('lti_types_config', $config); +} + +/** + * Updates a tool configuration in the database + * + * @param $config Tool configuration + * + * @return Record id number + */ +function lti_update_config($config) { + global $DB; + + $return = true; + $old = $DB->get_record('lti_types_config', array('typeid' => $config->typeid, 'name' => $config->name)); + + if ($old) { + $config->id = $old->id; + $return = $DB->update_record('lti_types_config', $config); + } else { + $return = $DB->insert_record('lti_types_config', $config); + } + return $return; +} + +/** + * Signs the petition to launch the external tool using OAuth + * + * @param $oldparms Parameters to be passed for signing + * @param $endpoint url of the external tool + * @param $method Method for sending the parameters (e.g. POST) + * @param $oauth_consumoer_key Key + * @param $oauth_consumoer_secret Secret + * @param $submittext The text for the submit button + * @param $orgid LMS name + * @param $orgdesc LMS key + */ +function sign_parameters($oldparms, $endpoint, $method, $oauthconsumerkey, $oauthconsumersecret, $submittext, $orgid /*, $orgdesc*/) { + global $lastbasestring; + $parms = $oldparms; + $parms["lti_version"] = "LTI-1p0"; + $parms["lti_message_type"] = "basic-lti-launch-request"; + if ( $orgid ) { + $parms["tool_consumer_instance_guid"] = $orgid; + } + /* Suppress this for now - Chuck + if ( $orgdesc ) $parms["tool_consumer_instance_description"] = $orgdesc; + */ + $parms["ext_submit"] = $submittext; + + $testtoken = ''; + + $hmacmethod = new OAuthSignatureMethod_HMAC_SHA1(); + $testconsumer = new OAuthConsumer($oauthconsumerkey, $oauthconsumersecret, null); + + $accreq = OAuthRequest::from_consumer_and_token($testconsumer, $testtoken, $method, $endpoint, $parms); + $accreq->sign_request($hmacmethod, $testconsumer, $testtoken); + + // Pass this back up "out of band" for debugging + $lastbasestring = $accreq->get_signature_base_string(); + + $newparms = $accreq->get_parameters(); + + return $newparms; +} + +/** + * Posts the launch petition HTML + * + * @param $newparms Signed parameters + * @param $endpoint URL of the external tool + * @param $debug Debug (true/false) + */ +function post_launch_html($newparms, $endpoint, $debug=false) { + global $lastbasestring; + + $r = "
\n"; + + $submittext = $newparms['ext_submit']; + + // Contruct html for the launch parameters + foreach ($newparms as $key => $value) { + $key = htmlspecialchars($key); + $value = htmlspecialchars($value); + if ( $key == "ext_submit" ) { + $r .= "\n"; + } + + if ( $debug ) { + $r .= "\n"; + $r .= ""; + $r .= get_string("toggle_debug_data", "lti")."\n"; + $r .= "
\n"; + $r .= "".get_string("basiclti_endpoint", "lti")."
\n"; + $r .= $endpoint . "
\n 
\n"; + $r .= "".get_string("basiclti_parameters", "lti")."
\n"; + foreach ($newparms as $key => $value) { + $key = htmlspecialchars($key); + $value = htmlspecialchars($value); + $r .= "$key = $value
\n"; + } + $r .= " 
\n"; + $r .= "

".get_string("basiclti_base_string", "lti")."
\n".$lastbasestring."

\n"; + $r .= "
\n"; + } + $r .= "\n"; + + if ( ! $debug ) { + $ext_submit = "ext_submit"; + $ext_submit_text = $submittext; + $r .= " \n"; + } + return $r; +} + +/** + * Returns a link with info about the state of the basiclti submissions + * + * This is used by view_header to put this link at the top right of the page. + * For teachers it gives the number of submitted assignments with a link + * For students it gives the time of their submission. + * This will be suitable for most assignment types. + * + * @global object + * @global object + * @param bool $allgroup print all groups info if user can access all groups, suitable for index.php + * @return string + */ +function submittedlink($cm, $allgroups=false) { + global $CFG; + + $submitted = ''; + $urlbase = "{$CFG->wwwroot}/mod/lti/"; + + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + if (has_capability('mod/lti:grade', $context)) { + if ($allgroups and has_capability('moodle/site:accessallgroups', $context)) { + $group = 0; + } else { + $group = groups_get_activity_group($cm); + } + + $submitted = ''. + get_string('viewsubmissions', 'lti').''; + } else { + if (isloggedin()) { + // TODO Insert code for students if needed + } + } + + return $submitted; +} + diff --git a/mod/lti/oldservice.php b/mod/lti/oldservice.php new file mode 100644 index 00000000000..0eccfd8a1fb --- /dev/null +++ b/mod/lti/oldservice.php @@ -0,0 +1,391 @@ +. + +/** + * This file contains all necessary code to support basiclti services + * like outcomes and roster access. + * + * @package lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @author Charles Severance + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once("../../config.php"); +require_once($CFG->dirroot.'/mod/lti/lib.php'); +require_once($CFG->dirroot.'/mod/lti/locallib.php'); +require_once($CFG->dirroot.'/mod/lti/OAuth.php'); +require_once($CFG->dirroot.'/mod/lti/TrivialStore.php'); + +error_reporting(E_ALL & ~E_NOTICE); +ini_set("display_errors", 1); + +$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); +$PAGE->set_url('/mod/lti/service.php'); +$PAGE->set_pagetype('admin-setting-' . $section); +$PAGE->set_pagelayout('admin'); +$PAGE->navigation->clear_cache(); + +function message_response($major, $severity, $minor=false, $message=false, $xml=false) { + $lti_message_type = $_REQUEST['lti_message_type']; + $retval = ""."\n" . + "\n" . + " $lti_message_type\n" . + " \n" . + " $major\n" . + " $severity\n"; + if (! $codeminor === false) { + $retval = $retval . " $minor\n"; + } + $retval = $retval . + " $message\n" . + " \n"; + if (! $xml === false) { + $retval = $retval . $xml; + } + $retval = $retval . "\n"; + return $retval; +} + +function do_error($message) { + print message_response('Fail', 'Error', false, $message); + exit(); +} + +$lti_version = $_REQUEST['lti_version']; +if ($lti_version != "LTI-1p0") { + do_error("Improperly formed message: wrong lti version: ".$lti_version); +} + +$lti_message_type = $_REQUEST['lti_message_type']; +if (! isset($lti_message_type)) { + do_error("Improperly formed message: no lti_message_type parameter"); +} + +$message_type = false; +if ($lti_message_type == "basic-lis-replaceresult" || + $lti_message_type == "basic-lis-createresult" || + $lti_message_type == "basic-lis-updateresult" || + $lti_message_type == "basic-lis-deleteresult" || + $lti_message_type == "basic-lis-readresult") { + $sourcedid = $_REQUEST['sourcedid']; + $message_type = "basicoutcome"; +} else if ($lti_message_type == "basic-lti-loadsetting" || + $lti_message_type == "basic-lti-savesetting" || + $lti_message_type == "basic-lti-deletesetting") { + $sourcedid = $_REQUEST['id']; + $message_type = "toolsetting"; +} else if ($lti_message_type == "basic-lis-readmembershipsforcontext") { + $sourcedid = $_REQUEST['id']; + $message_type = "roster"; +} + +if ($message_type == false) { + do_error("Illegal lti_message_type"); +} + +if (!isset($sourcedid)) { + do_error("sourcedid missing"); +} +// Truncate to maximum length +$sourcedid = substr($sourcedid, 0, 2048); + +try { + $info = explode(':::', $sourcedid); + if (! is_array($info)) { + do_error("Bad sourcedid (1)"); + } + $signature = $info[0]; + $userid = intval($info[1]); + $placement = $info[2]; +} catch (Exception $e) { + do_error("Bad sourcedid (2)"); +} + +if (isset($signature) && isset($userid) && isset($placement)) { + // OK +} else { + do_error("Bad sourcedid (3)"); +} + +// Retrieve the Basic LTI placement +if (! $basiclti = $DB->get_record('lti', array('id'=>$placement))) { + do_error("Bad sourcedid (4)"); +} + +$basiclti_types_config = (object)$basiclti_types_config; + +$typeconfig = lti_get_type_config($basiclti->typeid); + +if (isset($typeconfig) && isset($typeconfig['password'])) { + // OK +} else { + do_error("Unable to load type"); +} + +if ($message_type == "basicoutcome") { + if ($typeconfig["acceptgrades"] == 1 || + ($typeconfig["acceptgrades"] == 2 && $basiclti->instructorchoiceacceptgrades == 1)) { + // The placement is configured to accept grades + } else { + do_error("Not permitted (1)"); + } +} else if ($message_type == "toolsetting") { + if ($typeconfig["allowsetting"] == 1 || + ($typeconfig["allowsetting"] == 2 && $basiclti->instructorchoiceallowsetting == 1)) { + // OK + } else { + do_error("Not permitted (2)"); + } +} else if ($message_type == "roster") { + if ($typeconfig["allowroster"] == 1 || + ($typeconfig["allowroster"] == 2 && $basiclti->instructorchoiceallowroster == 1)) { + // OK + } else { + do_error("Not permitted (3)"); + } +} + +// Retrieve the secret we use to sign lis_result_sourcedid +$placementsecret = $basiclti->placementsecret; +$oldplacementsecret = $basiclti->oldplacementsecret; +if (! isset($placementsecret)) { + do_error("Not permitted (4)"); +} + +$suffix = ':::' . $userid . ':::' . $placement; +$plaintext = $placementsecret . $suffix; +$hashsig = hash('sha256', $plaintext, false); +if (($hashsig != $signature) && isset($oldplacementsecret) && (strlen($oldplacementsecret) > 1)) { + $plaintext = $oldplacementsecret . $suffix; + $hashsig = hash('sha256', $plaintext, false); +} + +if ($hashsig != $signature) { + do_error("Invalid sourcedid"); +} + +// Check the OAuth Signature +$oauth_secret = $typeconfig["password"]; +$oauth_consumer_key = $typeconfig["resourcekey"]; +if (! isset($oauth_secret)) { + do_error("Not permitted (5)"); +} +if (! isset($oauth_consumer_key)) { + do_error("Not permitted (6)"); +} + +// Verify the message signature +$store = new TrivialOAuthDataStore(); +$store->add_consumer($oauth_consumer_key, $oauth_secret); + +$server = new OAuthServer($store); + +$method = new OAuthSignatureMethod_HMAC_SHA1(); +$server->add_signature_method($method); +$request = OAuthRequest::from_request(); + +$basestring = $request->get_signature_base_string(); +try { + $server->verify_request($request); +} catch (Exception $e) { + do_error($e->getMessage()); +} + +if (! $course = $DB->get_record('course', array('id'=>$basiclti->course))) { + do_error("Could not retrieve course"); +} + +// TODO: Check that user is in course + +if (! $cm = get_coursemodule_from_instance("lti", $basiclti->id, $course->id)) { + do_error("Course Module ID was incorrect"); +} + +// Lets store the grade +require_once($CFG->libdir.'/gradelib.php'); + +// Beginning of actual grade processing +if ($message_type == "basicoutcome") { + $source = 'mod/lti'; + $courseid = $course->id; + $itemtype = 'mod'; + $itemmodule = 'lti'; + $iteminstance = $basiclti->id; + + if ($lti_message_type == "basic-lis-readresult") { + unset($grade); + $thegrade = grade_get_grades($courseid, $itemtype, $itemmodule, $iteminstance, $userid); + // print_r($thegrade->items[0]->grades); + if (isset($thegrade) && is_array($thegrade->items[0]->grades)) { + foreach ($thegrade->items[0]->grades as $agrade) { + $grade = $agrade->grade; + break; + } + } + if (! isset($grade)) { + do_error("Unable to read grade"); + } + + $result = " \n" . + " \n" . + " " . + htmlspecialchars($grade/100.0) . + "\n" . + " \n" . + " \n"; + print message_response('Success', 'Status', false, "Grade read", $result); + exit(); + } + + if ($lti_message_type == "basic-lis-deleteresult") { + $params = array(); + $params['itemname'] = $basiclti->name; + + $grade = new stdClass(); + $grade->userid = $userid; + $grade->rawgrade = null; + + grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance, 0, $grade, array('deleted'=>1)); + } else { + if (isset($_REQUEST['result_resultscore_textstring'])) { + $gradeval = floatval($_REQUEST['result_resultscore_textstring']); + if ($gradeval <= 1.0 && $gradeval >= 0.0) { + $gradeval = $gradeval * 100.0; + } + } else { + do_error('Missing Grade'); + } + $params = array(); + $params['itemname'] = $basiclti->name; + + $grade = new stdClass(); + $grade->userid = $userid; + $grade->rawgrade = $gradeval; + + grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance, 0, $grade, $params); + } + + print message_response('Success', 'Status', 'fullsuccess', 'Grade updated'); + +} else if ($lti_message_type == "basic-lti-loadsetting") { + $xml = " \n" . + " ".htmlspecialchars($basiclti->setting)."\n" . + " \n"; + print message_response('Success', 'Status', 'fullsuccess', 'Setting retrieved', $xml); +} else if ($lti_message_type == "basic-lti-savesetting") { + $setting = $_REQUEST['setting']; + if (! isset($setting)) { + do_error('Missing setting value'); + } + $record = $DB->get_record('lti', array('id'=>$basiclti->id)); + $record->setting = $setting; + $success = $DB->update_record('lti', $record); + if ($success) { + print message_response('Success', 'Status', 'fullsuccess', 'Setting updated'); + } else { + do_error("Error updating error"); + } +} else if ($lti_message_type == "basic-lti-deletesetting") { + $record = $DB->get_record('lti', array('id'=>$basiclti->id)); + $record->setting = ''; + $success = $DB->update_record('lti', $record); + if ($success) { + print message_response('Success', 'Status', 'fullsuccess', 'Setting deleted'); + } else { + do_error("Error updating error"); + } +} else if ($message_type == "roster") { + if (! $course = $DB->get_record('course', array('id'=>$basiclti->course))) { + do_error("Could not retrieve course"); + } + if (! $context = get_context_instance(CONTEXT_COURSE, $course->id)) { + do_error("Could not retrieve context"); + } + $sql = 'SELECT u.id, u.username, u.firstname, u.lastname, u.email, ro.shortname + FROM '.$CFG->prefix.'role_assignments ra + JOIN '.$CFG->prefix.'user AS u ON ra.userid = u.id + JOIN '.$CFG->prefix.'role ro ON ra.roleid = ro.id + WHERE ra.contextid = '.$context->id; + $userlist = $DB->get_recordset_sql($sql); + $xml = " \n"; + foreach ($userlist as $user) { + $role = "Learner"; + if ($user->shortname == 'editingteacher' || $user->shortname == 'admin') { + $role = 'Instructor'; + } + $userxml = " \n". + " ".htmlspecialchars($user->id)."\n". + " $role\n"; + if ($typeconfig["sendname"] == 1 || + ($typeconfig["sendname"] == 2 && $basiclti->instructorchoicesendname == 1)) { + if (isset($user->firstname)) { + $userxml .= " ".htmlspecialchars($user->firstname)."\n"; + } + if (isset($user->lastname)) { + $userxml .= " ".htmlspecialchars($user->lastname)."\n"; + } + } + if ($typeconfig["sendemailaddr"] == 1 || + ($typeconfig["sendemailaddr"] == 2 && $basiclti->instructorchoicesendemailaddr == 1)) { + if (isset($user->email)) { + $userxml .= " ".htmlspecialchars($user->email)."\n"; + } + } + $placementsecret = $basiclti->placementsecret; + if (isset($placementsecret)) { + $suffix = ':::' . $user->id . ':::' . $basiclti->id; + $plaintext = $placementsecret . $suffix; + $hashsig = hash('sha256', $plaintext, false); + $sourcedid = $hashsig . $suffix; + } + if ($typeconfig["acceptgrades"] == 1 || + ($typeconfig["acceptgrades"] == 2 && $basiclti->instructorchoiceacceptgrades == 1)) { + if (isset($sourcedid)) { + $userxml .= " ".htmlspecialchars($sourcedid)."\n"; + } + } + $userxml .= " \n"; + $xml .= $userxml; + } + $xml .= " \n"; + print message_response('Success', 'Status', 'fullsuccess', 'Roster retreived', $xml); + +} + diff --git a/mod/lti/service.php b/mod/lti/service.php index 8555e238442..2f7278c5f80 100644 --- a/mod/lti/service.php +++ b/mod/lti/service.php @@ -1,391 +1,230 @@ -. - -/** - * This file contains all necessary code to support basiclti services - * like outcomes and roster access. - * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis - * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * @author Charles Severance - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -require_once("../../config.php"); -require_once($CFG->dirroot.'/mod/lti/lib.php'); -require_once($CFG->dirroot.'/mod/lti/locallib.php'); -require_once($CFG->dirroot.'/mod/lti/OAuth.php'); -require_once($CFG->dirroot.'/mod/lti/TrivialStore.php'); - -error_reporting(E_ALL & ~E_NOTICE); -ini_set("display_errors", 1); - -$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); -$PAGE->set_url('/mod/lti/service.php'); -$PAGE->set_pagetype('admin-setting-' . $section); -$PAGE->set_pagelayout('admin'); -$PAGE->navigation->clear_cache(); - -function message_response($major, $severity, $minor=false, $message=false, $xml=false) { - $lti_message_type = $_REQUEST['lti_message_type']; - $retval = ""."\n" . - "\n" . - " $lti_message_type\n" . - " \n" . - " $major\n" . - " $severity\n"; - if (! $codeminor === false) { - $retval = $retval . " $minor\n"; - } - $retval = $retval . - " $message\n" . - " \n"; - if (! $xml === false) { - $retval = $retval . $xml; - } - $retval = $retval . "\n"; - return $retval; -} - -function do_error($message) { - print message_response('Fail', 'Error', false, $message); - exit(); -} - -$lti_version = $_REQUEST['lti_version']; -if ($lti_version != "LTI-1p0") { - do_error("Improperly formed message: wrong lti version: ".$lti_version); -} - -$lti_message_type = $_REQUEST['lti_message_type']; -if (! isset($lti_message_type)) { - do_error("Improperly formed message: no lti_message_type parameter"); -} - -$message_type = false; -if ($lti_message_type == "basic-lis-replaceresult" || - $lti_message_type == "basic-lis-createresult" || - $lti_message_type == "basic-lis-updateresult" || - $lti_message_type == "basic-lis-deleteresult" || - $lti_message_type == "basic-lis-readresult") { - $sourcedid = $_REQUEST['sourcedid']; - $message_type = "basicoutcome"; -} else if ($lti_message_type == "basic-lti-loadsetting" || - $lti_message_type == "basic-lti-savesetting" || - $lti_message_type == "basic-lti-deletesetting") { - $sourcedid = $_REQUEST['id']; - $message_type = "toolsetting"; -} else if ($lti_message_type == "basic-lis-readmembershipsforcontext") { - $sourcedid = $_REQUEST['id']; - $message_type = "roster"; -} - -if ($message_type == false) { - do_error("Illegal lti_message_type"); -} - -if (!isset($sourcedid)) { - do_error("sourcedid missing"); -} -// Truncate to maximum length -$sourcedid = substr($sourcedid, 0, 2048); - -try { - $info = explode(':::', $sourcedid); - if (! is_array($info)) { - do_error("Bad sourcedid (1)"); - } - $signature = $info[0]; - $userid = intval($info[1]); - $placement = $info[2]; -} catch (Exception $e) { - do_error("Bad sourcedid (2)"); -} - -if (isset($signature) && isset($userid) && isset($placement)) { - // OK -} else { - do_error("Bad sourcedid (3)"); -} - -// Retrieve the Basic LTI placement -if (! $basiclti = $DB->get_record('lti', array('id'=>$placement))) { - do_error("Bad sourcedid (4)"); -} - -$basiclti_types_config = (object)$basiclti_types_config; - -$typeconfig = lti_get_type_config($basiclti->typeid); - -if (isset($typeconfig) && isset($typeconfig['password'])) { - // OK -} else { - do_error("Unable to load type"); -} - -if ($message_type == "basicoutcome") { - if ($typeconfig["acceptgrades"] == 1 || - ($typeconfig["acceptgrades"] == 2 && $basiclti->instructorchoiceacceptgrades == 1)) { - // The placement is configured to accept grades - } else { - do_error("Not permitted (1)"); - } -} else if ($message_type == "toolsetting") { - if ($typeconfig["allowsetting"] == 1 || - ($typeconfig["allowsetting"] == 2 && $basiclti->instructorchoiceallowsetting == 1)) { - // OK - } else { - do_error("Not permitted (2)"); - } -} else if ($message_type == "roster") { - if ($typeconfig["allowroster"] == 1 || - ($typeconfig["allowroster"] == 2 && $basiclti->instructorchoiceallowroster == 1)) { - // OK - } else { - do_error("Not permitted (3)"); - } -} - -// Retrieve the secret we use to sign lis_result_sourcedid -$placementsecret = $basiclti->placementsecret; -$oldplacementsecret = $basiclti->oldplacementsecret; -if (! isset($placementsecret)) { - do_error("Not permitted (4)"); -} - -$suffix = ':::' . $userid . ':::' . $placement; -$plaintext = $placementsecret . $suffix; -$hashsig = hash('sha256', $plaintext, false); -if (($hashsig != $signature) && isset($oldplacementsecret) && (strlen($oldplacementsecret) > 1)) { - $plaintext = $oldplacementsecret . $suffix; - $hashsig = hash('sha256', $plaintext, false); -} - -if ($hashsig != $signature) { - do_error("Invalid sourcedid"); -} - -// Check the OAuth Signature -$oauth_secret = $typeconfig["password"]; -$oauth_consumer_key = $typeconfig["resourcekey"]; -if (! isset($oauth_secret)) { - do_error("Not permitted (5)"); -} -if (! isset($oauth_consumer_key)) { - do_error("Not permitted (6)"); -} - -// Verify the message signature -$store = new TrivialOAuthDataStore(); -$store->add_consumer($oauth_consumer_key, $oauth_secret); - -$server = new OAuthServer($store); - -$method = new OAuthSignatureMethod_HMAC_SHA1(); -$server->add_signature_method($method); -$request = OAuthRequest::from_request(); - -$basestring = $request->get_signature_base_string(); -try { - $server->verify_request($request); -} catch (Exception $e) { - do_error($e->getMessage()); -} - -if (! $course = $DB->get_record('course', array('id'=>$basiclti->course))) { - do_error("Could not retrieve course"); -} - -// TODO: Check that user is in course - -if (! $cm = get_coursemodule_from_instance("lti", $basiclti->id, $course->id)) { - do_error("Course Module ID was incorrect"); -} - -// Lets store the grade -require_once($CFG->libdir.'/gradelib.php'); - -// Beginning of actual grade processing -if ($message_type == "basicoutcome") { - $source = 'mod/lti'; - $courseid = $course->id; - $itemtype = 'mod'; - $itemmodule = 'lti'; - $iteminstance = $basiclti->id; - - if ($lti_message_type == "basic-lis-readresult") { - unset($grade); - $thegrade = grade_get_grades($courseid, $itemtype, $itemmodule, $iteminstance, $userid); - // print_r($thegrade->items[0]->grades); - if (isset($thegrade) && is_array($thegrade->items[0]->grades)) { - foreach ($thegrade->items[0]->grades as $agrade) { - $grade = $agrade->grade; - break; - } - } - if (! isset($grade)) { - do_error("Unable to read grade"); - } - - $result = " \n" . - " \n" . - " " . - htmlspecialchars($grade/100.0) . - "\n" . - " \n" . - " \n"; - print message_response('Success', 'Status', false, "Grade read", $result); - exit(); - } - - if ($lti_message_type == "basic-lis-deleteresult") { - $params = array(); - $params['itemname'] = $basiclti->name; - - $grade = new stdClass(); - $grade->userid = $userid; - $grade->rawgrade = null; - - grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance, 0, $grade, array('deleted'=>1)); - } else { - if (isset($_REQUEST['result_resultscore_textstring'])) { - $gradeval = floatval($_REQUEST['result_resultscore_textstring']); - if ($gradeval <= 1.0 && $gradeval >= 0.0) { - $gradeval = $gradeval * 100.0; - } - } else { - do_error('Missing Grade'); - } - $params = array(); - $params['itemname'] = $basiclti->name; - - $grade = new stdClass(); - $grade->userid = $userid; - $grade->rawgrade = $gradeval; - - grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance, 0, $grade, $params); - } - - print message_response('Success', 'Status', 'fullsuccess', 'Grade updated'); - -} else if ($lti_message_type == "basic-lti-loadsetting") { - $xml = " \n" . - " ".htmlspecialchars($basiclti->setting)."\n" . - " \n"; - print message_response('Success', 'Status', 'fullsuccess', 'Setting retrieved', $xml); -} else if ($lti_message_type == "basic-lti-savesetting") { - $setting = $_REQUEST['setting']; - if (! isset($setting)) { - do_error('Missing setting value'); - } - $record = $DB->get_record('lti', array('id'=>$basiclti->id)); - $record->setting = $setting; - $success = $DB->update_record('lti', $record); - if ($success) { - print message_response('Success', 'Status', 'fullsuccess', 'Setting updated'); - } else { - do_error("Error updating error"); - } -} else if ($lti_message_type == "basic-lti-deletesetting") { - $record = $DB->get_record('lti', array('id'=>$basiclti->id)); - $record->setting = ''; - $success = $DB->update_record('lti', $record); - if ($success) { - print message_response('Success', 'Status', 'fullsuccess', 'Setting deleted'); - } else { - do_error("Error updating error"); - } -} else if ($message_type == "roster") { - if (! $course = $DB->get_record('course', array('id'=>$basiclti->course))) { - do_error("Could not retrieve course"); - } - if (! $context = get_context_instance(CONTEXT_COURSE, $course->id)) { - do_error("Could not retrieve context"); - } - $sql = 'SELECT u.id, u.username, u.firstname, u.lastname, u.email, ro.shortname - FROM '.$CFG->prefix.'role_assignments ra - JOIN '.$CFG->prefix.'user AS u ON ra.userid = u.id - JOIN '.$CFG->prefix.'role ro ON ra.roleid = ro.id - WHERE ra.contextid = '.$context->id; - $userlist = $DB->get_recordset_sql($sql); - $xml = " \n"; - foreach ($userlist as $user) { - $role = "Learner"; - if ($user->shortname == 'editingteacher' || $user->shortname == 'admin') { - $role = 'Instructor'; - } - $userxml = " \n". - " ".htmlspecialchars($user->id)."\n". - " $role\n"; - if ($typeconfig["sendname"] == 1 || - ($typeconfig["sendname"] == 2 && $basiclti->instructorchoicesendname == 1)) { - if (isset($user->firstname)) { - $userxml .= " ".htmlspecialchars($user->firstname)."\n"; - } - if (isset($user->lastname)) { - $userxml .= " ".htmlspecialchars($user->lastname)."\n"; - } - } - if ($typeconfig["sendemailaddr"] == 1 || - ($typeconfig["sendemailaddr"] == 2 && $basiclti->instructorchoicesendemailaddr == 1)) { - if (isset($user->email)) { - $userxml .= " ".htmlspecialchars($user->email)."\n"; - } - } - $placementsecret = $basiclti->placementsecret; - if (isset($placementsecret)) { - $suffix = ':::' . $user->id . ':::' . $basiclti->id; - $plaintext = $placementsecret . $suffix; - $hashsig = hash('sha256', $plaintext, false); - $sourcedid = $hashsig . $suffix; - } - if ($typeconfig["acceptgrades"] == 1 || - ($typeconfig["acceptgrades"] == 2 && $basiclti->instructorchoiceacceptgrades == 1)) { - if (isset($sourcedid)) { - $userxml .= " ".htmlspecialchars($sourcedid)."\n"; - } - } - $userxml .= " \n"; - $xml .= $userxml; - } - $xml .= " \n"; - print message_response('Success', 'Status', 'fullsuccess', 'Roster retreived', $xml); - -} - +dirroot.'/mod/lti/OAuthBody.php'); +require_once($CFG->dirroot.'/mod/lti/locallib.php'); + +define('LTI_ITEM_TYPE', 'mod'); +define('LTI_ITEM_MODULE', 'lti'); +define('LTI_SOURCE', 'mod/lti'); + +function lti_get_response_xml($codemajor, $description, $messageref, $messagetype){ + $xml = new SimpleXMLElement(''); + $xml->addAttribute('xmlns', 'http://www.imsglobal.org/lis/oms1p0/pox'); + + $headerinfo = $xml->addChild('imsx_POXHeader') + ->addChild('imsx_POXResponseHeaderInfo'); + + $headerinfo->addChild('imsx_version', 'V1.0'); + $headerinfo->addChild('imsx_messageIdentifier', (string)mt_rand()); + + $statusinfo = $headerinfo->addChild('imsx_statusInfo'); + $statusinfo->addchild('imsx_codeMajor', $codemajor); + $statusinfo->addChild('imsx_severity', 'status'); + $statusinfo->addChild('imsx_description', $description); + $statusinfo->addChild('imsx_messageRefIdentifier', $messageref); + + $xml->addChild('imsx_POXBody') + ->addChild($messagetype); + + return $xml; +} + +function lti_parse_message_id($xml){ + $node = $xml->imsx_POXHeader->imsx_POXRequestHeaderInfo->imsx_messageIdentifier; + $messageid = (string)$node; + + return $messageid; +} + +function lti_parse_grade_replace_message($xml){ + $node = $xml->imsx_POXBody->replaceResultRequest->resultRecord->sourcedGUID->sourcedId; + $resultjson = json_decode((string)$node); + + $node = $xml->imsx_POXBody->replaceResultRequest->resultRecord->result->resultScore->textString; + $grade = floatval((string)$node); + + $parsed = new stdClass(); + $parsed->gradeval = $grade * 100; + $parsed->instanceid = $resultjson->data->instanceid; + $parsed->userid = $resultjson->data->userid; + $parsed->messageid = lti_parse_message_id($xml); + + return $parsed; +} + +function lti_parse_grade_read_message($xml){ + $node = $xml->imsx_POXBody->readResultRequest->resultRecord->sourcedGUID->sourcedId; + $resultjson = json_decode((string)$node); + + $parsed = new stdClass(); + $parsed->instanceid = $resultjson->data->instanceid; + $parsed->userid = $resultjson->data->userid; + $parsed->messageid = lti_parse_message_id($xml); + + return $parsed; +} + +function lti_parse_grade_delete_message($xml){ + $node = $xml->imsx_POXBody->deleteResultRequest->resultRecord->sourcedGUID->sourcedId; + $resultjson = json_decode((string)$node); + + $parsed = new stdClass(); + $parsed->instanceid = $resultjson->data->instanceid; + $parsed->userid = $resultjson->data->userid; + $parsed->messageid = lti_parse_message_id($xml); + + return $parsed; +} + +function lti_update_grade($ltiinstance, $userid, $gradeval){ + global $CFG; + require_once($CFG->libdir . '/gradelib.php'); + + $params = array(); + $params['itemname'] = $ltiinstance->name; + + $grade = new stdClass(); + $grade->userid = $userid; + $grade->rawgrade = $gradeval; + + $status = grade_update(LTI_SOURCE, $ltiinstance->course, LTI_ITEM_TYPE, LTI_ITEM_MODULE, $ltiinstance->id, 0, $grade, $params); + + return $status == GRADE_UPDATE_OK; +} + +function lti_read_grade($ltiinstance, $userid){ + global $CFG; + require_once($CFG->libdir . '/gradelib.php'); + + $grades = grade_get_grades($ltiinstance->course, LTI_ITEM_TYPE, LTI_ITEM_MODULE, $ltiinstance->id, $userid); + + if (isset($grades) && is_array($grades->items[0]->grades)) { + foreach ($grades->items[0]->grades as $agrade) { + $grade = $agrade->grade; + break; + } + } + + if(isset($grade)){ + return $grade; + } +} + +function lti_delete_grade($ltiinstance, $userid){ + $grade = new stdClass(); + $grade->userid = $userid; + $grade->rawgrade = null; + + $status = grade_update(LTI_SOURCE, $ltiinstance->course, LTI_ITEM_TYPE, LTI_ITEM_MODULE, $ltiinstance->id, 0, $grade, array('deleted'=>1)); + + return $status == GRADE_UPDATE_OK || $status == GRADE_UPDATE_ITEM_DELETED; //grade_update seems to return ok now, but could reasonably return deleted in the future +} + +function lti_verify_message($ltiinstance){ + //Use the key / secret configured on the tool, or look it up from the admin config + if(empty($ltiinstance->resourcekey) || empty($ltiinstance->password)){ + if($ltiinstance->typeid){ + $typeid = $ltiinstance->typeid; + } else { + $tool = lti_get_tool_by_url_match($ltiinstance->toolurl); + + if(!$tool){ + throw new Exception('Tool configuration not found for tool instance ' . $ltiinstance->id); + } + + $typeid = $tool->id; + } + + $typeconfig = lti_get_type_config($typeid);//Consider only fetching the 2 necessary settings here + + $key = $typeconfig['resourcekey']; + $secret = $typeconfig['password']; + } else { + $key = $ltiinstance->resourcekey; + $secret = $ltiinstance->password; + } + + handleOAuthBodyPOST($key, $secret); +} + +$xmlfragment = file_get_contents("php://input"); +$xml = new SimpleXMLElement($xmlfragment); + +$body = $xml->imsx_POXBody; +foreach($body->children() as $child){ + $messagetype = $child->getName(); +} + +switch($messagetype){ + case 'replaceResultRequest': + $parsed = lti_parse_grade_replace_message($xml); + + $ltiinstance = $DB->get_record('lti', array('id' => $parsed->instanceid)); + + lti_verify_message($ltiinstance); + + $gradestatus = lti_update_grade($ltiinstance, $parsed->userid, $parsed->gradeval); + + $responsexml = lti_get_response_xml( + $gradestatus ? 'success' : 'error', + 'Grade replace response', + $parsed->messageid, + 'replaceResultResponse' + ); + + echo $responsexml->asXML(); + + break; + + case 'readResultRequest': + $parsed = lti_parse_grade_read_message($xml); + + $ltiinstance = $DB->get_record('lti', array('id' => $parsed->instanceid)); + + lti_verify_message($ltiinstance); + + $grade = lti_read_grade($ltiinstance, $parsed->userid); + + $responsexml = lti_get_response_xml( + isset($grade) ? 'success' : 'error', + 'Result read', + $parsed->messageid, + 'readResultResponse' + ); + + $node = $responsexml->imsx_POXBody->readResultResponse; + $node->addChild('result') + ->addChild('resultScore') + ->addChild('textString', isset($grade) ? $grade : ''); + + echo $responsexml->asXML(); + + break; + + case 'deleteResultRequest': + $parsed = lti_parse_grade_delete_message($xml); + + $ltiinstance = $DB->get_record('lti', array('id' => $parsed->instanceid)); + + lti_verify_message($ltiinstance); + + $gradestatus = lti_delete_grade($ltiinstance, $parsed->userid); + + $responsexml = lti_get_response_xml( + $gradestatus ? 'success' : 'error', + 'Grade delete request', + $parsed->messageid, + 'deleteResultResponse' + ); + + echo $responsexml->asXML(); + + break; +} + + +//echo print_r(apache_request_headers(), true); + +//echo '
'; + +//echo file_get_contents("php://input"); \ No newline at end of file From dbb0fec9fd214ca55710d0b28ced8263cb292f4f Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Fri, 16 Sep 2011 10:12:23 -0400 Subject: [PATCH 17/78] Renaming global functions to include lti prefix --- mod/lti/locallib.php | 20 +- mod/lti/simpletest/testlocallib.php | 10 +- mod/lti/view.php | 350 ++++++++++++++-------------- 3 files changed, 190 insertions(+), 190 deletions(-) diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index 240f1c4b389..a7901fd98df 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -120,11 +120,11 @@ function lti_view($instance, $makeobject=false) { $requestparams["oauth_callback"] = "about:blank"; $submittext = get_string('press_to_submit', 'lti'); - $parms = sign_parameters($requestparams, $endpoint, "POST", $key, $secret, $submittext, $orgid /*, $orgdesc*/); + $parms = lti_sign_parameters($requestparams, $endpoint, "POST", $key, $secret, $submittext, $orgid /*, $orgdesc*/); $debuglaunch = ( $instance->debuglaunch == 1 ); - $content = post_launch_html($parms, $endpoint, $debuglaunch); + $content = lti_post_launch_html($parms, $endpoint, $debuglaunch); echo $content; } @@ -219,13 +219,13 @@ function lti_build_request($instance, $typeconfig, $course) { $custom = array(); $instructorcustom = array(); if ($customstr) { - $custom = split_custom_parameters($customstr); + $custom = lti_split_custom_parameters($customstr); } if (!isset($typeconfig['allowinstructorcustom']) || $typeconfig['allowinstructorcustom'] == 0) { $requestparams = array_merge($custom, $requestparams); } else { if ($instructorcustomstr) { - $instructorcustom = split_custom_parameters($instructorcustomstr); + $instructorcustom = lti_split_custom_parameters($instructorcustomstr); } foreach ($instructorcustom as $key => $val) { if (array_key_exists($key, $custom)) { @@ -247,7 +247,7 @@ function lti_build_request($instance, $typeconfig, $course) { * * @return Array of custom parameters */ -function split_custom_parameters($customstr) { +function lti_split_custom_parameters($customstr) { $textlib = textlib_get_instance(); $lines = preg_split("/[\n;]/", $customstr); @@ -259,7 +259,7 @@ function split_custom_parameters($customstr) { } $key = trim($textlib->substr($line, 0, $pos)); $val = trim($textlib->substr($line, $pos+1)); - $key = map_keyname($key); + $key = lti_map_keyname($key); $retval['custom_'.$key] = $val; } return $retval; @@ -272,7 +272,7 @@ function split_custom_parameters($customstr) { * * @return string Processed name */ -function map_keyname($key) { +function lti_map_keyname($key) { $textlib = textlib_get_instance(); $newkey = ""; @@ -778,7 +778,7 @@ function lti_update_config($config) { * @param $orgid LMS name * @param $orgdesc LMS key */ -function sign_parameters($oldparms, $endpoint, $method, $oauthconsumerkey, $oauthconsumersecret, $submittext, $orgid /*, $orgdesc*/) { +function lti_sign_parameters($oldparms, $endpoint, $method, $oauthconsumerkey, $oauthconsumersecret, $submittext, $orgid /*, $orgdesc*/) { global $lastbasestring; $parms = $oldparms; $parms["lti_version"] = "LTI-1p0"; @@ -814,7 +814,7 @@ function sign_parameters($oldparms, $endpoint, $method, $oauthconsumerkey, $oaut * @param $endpoint URL of the external tool * @param $debug Debug (true/false) */ -function post_launch_html($newparms, $endpoint, $debug=false) { +function lti_post_launch_html($newparms, $endpoint, $debug=false) { global $lastbasestring; $r = "
\n"; @@ -898,7 +898,7 @@ function post_launch_html($newparms, $endpoint, $debug=false) { * @param bool $allgroup print all groups info if user can access all groups, suitable for index.php * @return string */ -function submittedlink($cm, $allgroups=false) { +function lti_submittedlink($cm, $allgroups=false) { global $CFG; $submitted = ''; diff --git a/mod/lti/simpletest/testlocallib.php b/mod/lti/simpletest/testlocallib.php index c4d37541a3c..c8536d0219b 100644 --- a/mod/lti/simpletest/testlocallib.php +++ b/mod/lti/simpletest/testlocallib.php @@ -55,13 +55,13 @@ require_once($CFG->dirroot . '/mod/lti/locallib.php'); class lti_locallib_test extends UnitTestCase { public static $includecoverage = array('mod/lti/locallib.php'); function test_split_custom_parameters() { - $this->assertEqual(split_custom_parameters("x=1\ny=2"), + $this->assertEqual(lti_split_custom_parameters("x=1\ny=2"), array('custom_x' => '1', 'custom_y'=> '2')); - $this->assertEqual(split_custom_parameters('x=1;y=2'), + $this->assertEqual(lti_split_custom_parameters('x=1;y=2'), array('custom_x' => '1', 'custom_y'=> '2')); - $this->assertEqual(split_custom_parameters('Review:Chapter=1.2.56'), + $this->assertEqual(lti_split_custom_parameters('Review:Chapter=1.2.56'), array('custom_review_chapter' => '1.2.56')); - $this->assertEqual(split_custom_parameters('Complex!@#$^*(){}[]KEY=Complex!@#$^*(){}[]Value'), + $this->assertEqual(lti_split_custom_parameters('Complex!@#$^*(){}[]KEY=Complex!@#$^*(){}[]Value'), array('custom_complex____________key' => 'Complex!@#$^*(){}[]Value')); $this->assertEqual(5, 5); } @@ -71,7 +71,7 @@ class lti_locallib_test extends UnitTestCase { $requestparams = array('resource_link_id' => '123', 'resource_link_title' => 'Weekly Blog', 'user_id' => '789', 'roles' => 'Learner', 'context_id' => '12345', 'context_label' => 'SI124', 'context_title' => 'Social Computing'); - $parms = sign_parameters($requestparams, 'http://www.imsglobal.org/developer/LTI/tool.php', 'POST', + $parms = lti_sign_parameters($requestparams, 'http://www.imsglobal.org/developer/LTI/tool.php', 'POST', 'lmsng.school.edu', 'secret', 'Click Me', 'lmsng.school.edu' /*, $org_desc*/); $this->assertTrue(isset($parms['oauth_nonce'])); $this->assertTrue(isset($parms['oauth_signature'])); diff --git a/mod/lti/view.php b/mod/lti/view.php index 1a1a533656a..8b1f559e7bb 100644 --- a/mod/lti/view.php +++ b/mod/lti/view.php @@ -1,175 +1,175 @@ -. - -/** - * This file contains all necessary code to view a basiclti activity instance - * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis - * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -require_once('../../config.php'); -require_once($CFG->dirroot.'/mod/lti/lib.php'); -require_once($CFG->dirroot.'/mod/lti/locallib.php'); - -$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or -$a = optional_param('a', 0, PARAM_INT); // lti ID - -if ($id) { - if (! $cm = get_coursemodule_from_id("lti", $id)) { - throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect'); - } - - if (! $course = $DB->get_record("course", array("id" => $cm->course))) { - throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured'); - } - - if (! $basiclti = $DB->get_record("lti", array("id" => $cm->instance))) { - throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect'); - } - -} else { - if (! $basiclti = $DB->get_record("lti", array("id" => $a))) { - throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect'); - } - if (! $course = $DB->get_record("course", array("id" => $basiclti->course))) { - throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured'); - } - if (! $cm = get_coursemodule_from_instance("lti", $basiclti->id, $course->id)) { - throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect'); - } -} - -$tool = lti_get_tool_by_url_match($basiclti->toolurl); -if($tool){ - $toolconfig = lti_get_type_config($tool->id); -} else { - $toolconfig = array('launchcontainer' => LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS); -} - -$PAGE->set_cm($cm, $course); // set's up global $COURSE -$context = get_context_instance(CONTEXT_MODULE, $cm->id); -$PAGE->set_context($context); - -$url = new moodle_url('/mod/lti/view.php', array('id'=>$cm->id)); -$PAGE->set_url($url); - -$launchcontainer = $basiclti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT ? - $toolconfig['launchcontainer'] : - $basiclti->launchcontainer; - -if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS){ - $PAGE->set_pagelayout('frametop'); //Most frametops don't include footer, and pre-post blocks - $PAGE->blocks->show_only_fake_blocks(); //Disable blocks for layouts which do include pre-post blocks -} else { - $PAGE->set_pagelayout('incourse'); -} - -require_login($course); - -add_to_log($course->id, "lti", "view", "view.php?id=$cm->id", "$basiclti->id"); - -$pagetitle = strip_tags($course->shortname.': '.format_string($basiclti->name)); -$PAGE->set_title($pagetitle); -$PAGE->set_heading($course->fullname); - -/// Print the page header -echo $OUTPUT->header(); - -if($basiclti->showtitle) { - /// Print the main part of the page - echo $OUTPUT->heading(format_string($basiclti->name)); -} - -if($basiclti->showdescription && $basiclti->intro){ - echo $OUTPUT->box($basiclti->intro, 'generalbox description', 'intro'); -} - -if ($basiclti->instructorchoiceacceptgrades == 1) { - echo ''; -} - -if ( $launchcontainer == LTI_LAUNCH_CONTAINER_WINDOW ) { - echo "\n"; - echo "

".get_string("basiclti_in_new_window", "lti")."

\n"; -} else { - // Request the launch content with an object tag - echo ''; - - //Output script to make the object tag be as large as possible - $resize = <<<'SCRIPT' - -SCRIPT; - - echo $resize; -} - - -/// Finish the page -echo $OUTPUT->footer(); +. + +/** + * This file contains all necessary code to view a basiclti activity instance + * + * @package lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once('../../config.php'); +require_once($CFG->dirroot.'/mod/lti/lib.php'); +require_once($CFG->dirroot.'/mod/lti/locallib.php'); + +$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or +$a = optional_param('a', 0, PARAM_INT); // lti ID + +if ($id) { + if (! $cm = get_coursemodule_from_id("lti", $id)) { + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect'); + } + + if (! $course = $DB->get_record("course", array("id" => $cm->course))) { + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured'); + } + + if (! $basiclti = $DB->get_record("lti", array("id" => $cm->instance))) { + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect'); + } + +} else { + if (! $basiclti = $DB->get_record("lti", array("id" => $a))) { + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect'); + } + if (! $course = $DB->get_record("course", array("id" => $basiclti->course))) { + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured'); + } + if (! $cm = get_coursemodule_from_instance("lti", $basiclti->id, $course->id)) { + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect'); + } +} + +$tool = lti_get_tool_by_url_match($basiclti->toolurl); +if($tool){ + $toolconfig = lti_get_type_config($tool->id); +} else { + $toolconfig = array('launchcontainer' => LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS); +} + +$PAGE->set_cm($cm, $course); // set's up global $COURSE +$context = get_context_instance(CONTEXT_MODULE, $cm->id); +$PAGE->set_context($context); + +$url = new moodle_url('/mod/lti/view.php', array('id'=>$cm->id)); +$PAGE->set_url($url); + +$launchcontainer = $basiclti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT ? + $toolconfig['launchcontainer'] : + $basiclti->launchcontainer; + +if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS){ + $PAGE->set_pagelayout('frametop'); //Most frametops don't include footer, and pre-post blocks + $PAGE->blocks->show_only_fake_blocks(); //Disable blocks for layouts which do include pre-post blocks +} else { + $PAGE->set_pagelayout('incourse'); +} + +require_login($course); + +add_to_log($course->id, "lti", "view", "view.php?id=$cm->id", "$basiclti->id"); + +$pagetitle = strip_tags($course->shortname.': '.format_string($basiclti->name)); +$PAGE->set_title($pagetitle); +$PAGE->set_heading($course->fullname); + +/// Print the page header +echo $OUTPUT->header(); + +if($basiclti->showtitle) { + /// Print the main part of the page + echo $OUTPUT->heading(format_string($basiclti->name)); +} + +if($basiclti->showdescription && $basiclti->intro){ + echo $OUTPUT->box($basiclti->intro, 'generalbox description', 'intro'); +} + +if ($basiclti->instructorchoiceacceptgrades == 1) { + echo ''; +} + +if ( $launchcontainer == LTI_LAUNCH_CONTAINER_WINDOW ) { + echo "\n"; + echo "

".get_string("basiclti_in_new_window", "lti")."

\n"; +} else { + // Request the launch content with an object tag + echo ''; + + //Output script to make the object tag be as large as possible + $resize = <<<'SCRIPT' + +SCRIPT; + + echo $resize; +} + + +/// Finish the page +echo $OUTPUT->footer(); From 996b0fd9613de8cdd04d2f42528ad4d343e56993 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Fri, 16 Sep 2011 18:37:43 -0400 Subject: [PATCH 18/78] Updates to lti plugin & progress on instructor management of course tools. --- mod/lti/OAuthBody.php | 9 +- mod/lti/basiclti.js | 4 +- mod/lti/edit_form.php | 325 +++++++------- mod/lti/instructor_edit_tool_type.php | 93 ++++ mod/lti/lang/en/lti.php | 394 ++++++++--------- mod/lti/locallib.php | 62 ++- mod/lti/mod_form.js | 124 ++++++ mod/lti/mod_form.php | 615 +++++++++----------------- mod/lti/service.php | 167 +------ mod/lti/servicelib.php | 164 +++++++ mod/lti/settings.php | 540 +++++++++++----------- mod/lti/simpletest/testlocallib.php | 59 ++- mod/lti/typessettings.php | 396 ++++++++--------- 13 files changed, 1520 insertions(+), 1432 deletions(-) create mode 100644 mod/lti/instructor_edit_tool_type.php create mode 100644 mod/lti/mod_form.js create mode 100644 mod/lti/servicelib.php diff --git a/mod/lti/OAuthBody.php b/mod/lti/OAuthBody.php index 1d70444a3c6..757bbf0ad17 100644 --- a/mod/lti/OAuthBody.php +++ b/mod/lti/OAuthBody.php @@ -72,10 +72,11 @@ function getOAuthKeyFromHeaders() return false; } -function handleOAuthBodyPOST($oauth_consumer_key, $oauth_consumer_secret) +function handleOAuthBodyPOST($oauth_consumer_key, $oauth_consumer_secret, $body, $request_headers = null) { - $request_headers = OAuthUtil::get_headers(); - // print_r($request_headers); + if($request_headers == null){ + $request_headers = OAuthUtil::get_headers(); + } // Must reject application/x-www-form-urlencoded if ($request_headers['Content-type'] == 'application/x-www-form-urlencoded' ) { @@ -112,7 +113,7 @@ function handleOAuthBodyPOST($oauth_consumer_key, $oauth_consumer_secret) throw new Exception("OAuth signature failed: " . $message); } - $postdata = file_get_contents('php://input'); + $postdata = $body; // echo($postdata); $hash = base64_encode(sha1($postdata, TRUE)); diff --git a/mod/lti/basiclti.js b/mod/lti/basiclti.js index b211a5196ff..9389a4b450b 100644 --- a/mod/lti/basiclti.js +++ b/mod/lti/basiclti.js @@ -53,6 +53,4 @@ function basicltiDebugToggle() { else { ele.style.display = 'block'; } -} - -alert('a'); \ No newline at end of file +} \ No newline at end of file diff --git a/mod/lti/edit_form.php b/mod/lti/edit_form.php index 3c998d45eaa..991f9865974 100644 --- a/mod/lti/edit_form.php +++ b/mod/lti/edit_form.php @@ -1,159 +1,166 @@ -. - -/** - * This file defines de main basiclti configuration form - * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis - * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * @author Charles Severance - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die; - -require_once($CFG->libdir.'/formslib.php'); - -class mod_lti_edit_types_form extends moodleform{ - - function definition() { - $mform =& $this->_form; - -//------------------------------------------------------------------------------- - // Add basiclti elements - $mform->addElement('header', 'setup', get_string('tool_settings', 'lti')); - - $mform->addElement('text', 'lti_typename', get_string('typename', 'lti')); - $mform->setType('lti_typename', PARAM_INT); -// $mform->addHelpButton('lti_typename', 'typename','lti'); - $mform->addRule('lti_typename', null, 'required', null, 'client'); - - $mform->addElement('text', 'lti_toolurl', get_string('toolurl', 'lti'), array('size'=>'64')); - $mform->setType('lti_toolurl', PARAM_TEXT); -// $mform->addHelpButton('lti_toolurl', 'toolurl', 'lti'); - $mform->addRule('lti_toolurl', null, 'required', null, 'client'); - - $mform->addElement('text', 'lti_resourcekey', get_string('resourcekey', 'lti')); - $mform->setType('lti_resourcekey', PARAM_TEXT); - - $mform->addElement('passwordunmask', 'lti_password', get_string('password', 'lti')); - $mform->setType('lti_password', PARAM_TEXT); - - $mform->addElement('textarea', 'lti_customparameters', get_string('custom', 'lti'), array('rows'=>4, 'cols'=>60)); - $mform->setType('lti_customparameters', PARAM_TEXT); - - $mform->addElement('checkbox', 'lti_coursevisible', ' ', ' ' . get_string('show_in_course', 'lti')); - - $launchoptions=array(); - $launchoptions[LTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'lti'); - $launchoptions[LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'lti'); - $launchoptions[LTI_LAUNCH_CONTAINER_WINDOW] = get_string('new_window', 'lti'); - - $mform->addElement('select', 'lti_launchcontainer', get_string('default_launch_container', 'lti'), $launchoptions); - $mform->setDefault('lti_launchcontainer', LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS); -// $mform->addHelpButton('lti_launchinpopup', 'launchinpopup', 'lti'); - - // Add privacy preferences fieldset where users choose whether to send their data - $mform->addElement('header', 'privacy', get_string('privacy', 'lti')); - - $options=array(); - $options[0] = get_string('never', 'lti'); - $options[1] = get_string('always', 'lti'); - $options[2] = get_string('delegate_yes', 'lti'); - $options[3] = get_string('delegate_no', 'lti'); - - $mform->addElement('select', 'lti_sendname', get_string('sendname', 'lti'), $options); - $mform->setDefault('lti_sendname', '2'); -// $mform->addHelpButton('lti_sendname', 'sendname', 'lti'); - - $mform->addElement('select', 'lti_sendemailaddr', get_string('sendemailaddr', 'lti'), $options); - $mform->setDefault('lti_sendemailaddr', '2'); -// $mform->addHelpButton('lti_sendemailaddr', 'sendemailaddr', 'lti'); - -//------------------------------------------------------------------------------- - // LTI Extensions - - // Add grading preferences fieldset where the tool is allowed to return grades - $mform->addElement('select', 'lti_acceptgrades', get_string('acceptgrades', 'lti'), $options); - $mform->setDefault('lti_acceptgrades', '2'); -// $mform->addHelpButton('lti_acceptgrades', 'acceptgrades', 'lti'); - - // Add grading preferences fieldset where the tool is allowed to retrieve rosters - $mform->addElement('select', 'lti_allowroster', get_string('allowroster', 'lti'), $options); - $mform->setDefault('lti_allowroster', '2'); -// $mform->addHelpButton('lti_allowroster', 'allowroster', 'lti'); - - -//------------------------------------------------------------------------------- - // Add setup parameters fieldset - $mform->addElement('header', 'setupoptions', get_string('miscellaneous', 'lti')); - - // Adding option to change id that is placed in context_id - $idoptions = array(); - $idoptions[0] = get_string('id', 'lti'); - $idoptions[1] = get_string('courseid', 'lti'); - - $mform->addElement('text', 'lti_organizationid', get_string('organizationid', 'lti')); - $mform->setType('lti_organizationid', PARAM_TEXT); -// $mform->addHelpButton('lti_organizationid', 'organizationid', 'lti'); - - $mform->addElement('text', 'lti_organizationurl', get_string('organizationurl', 'lti')); - $mform->setType('lti_organizationurl', PARAM_TEXT); -// $mform->addHelpButton('lti_organizationurl', 'organizationurl', 'lti'); - - /* Suppress this for now - Chuck - $mform->addElement('text', 'lti_organizationdescr', get_string('organizationdescr', 'lti')); - $mform->setType('lti_organizationdescr', PARAM_TEXT); - $mform->addHelpButton('lti_organizationdescr', 'organizationdescr', 'lti'); - */ - -//------------------------------------------------------------------------------- - // Add a hidden element to signal a tool fixing operation after a problematic backup - restore process - $mform->addElement('hidden', 'lti_fix'); - - $tab = optional_param('tab', '', PARAM_ALPHAEXT); - $mform->addElement('hidden', 'tab', $tab); - - -//------------------------------------------------------------------------------- - // Add standard buttons, common to all modules - $this->add_action_buttons(); - - } -} +. + +/** + * This file defines de main basiclti configuration form + * + * @package lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @author Charles Severance + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +require_once($CFG->libdir.'/formslib.php'); +require_once($CFG->dirroot.'/mod/lti/locallib.php'); + +class mod_lti_edit_types_form extends moodleform{ + function definition() { + $mform =& $this->_form; + +//------------------------------------------------------------------------------- + // Add basiclti elements + $mform->addElement('header', 'setup', get_string('tool_settings', 'lti')); + + $mform->addElement('text', 'lti_typename', get_string('typename', 'lti')); + $mform->setType('lti_typename', PARAM_INT); +// $mform->addHelpButton('lti_typename', 'typename','lti'); + $mform->addRule('lti_typename', null, 'required', null, 'client'); + + $mform->addElement('text', 'lti_toolurl', get_string('toolurl', 'lti'), array('size'=>'64')); + $mform->setType('lti_toolurl', PARAM_TEXT); +// $mform->addHelpButton('lti_toolurl', 'toolurl', 'lti'); + $mform->addRule('lti_toolurl', null, 'required', null, 'client'); + + $mform->addElement('text', 'lti_resourcekey', get_string('resourcekey', 'lti')); + $mform->setType('lti_resourcekey', PARAM_TEXT); + + $mform->addElement('passwordunmask', 'lti_password', get_string('password', 'lti')); + $mform->setType('lti_password', PARAM_TEXT); + + $mform->addElement('textarea', 'lti_customparameters', get_string('custom', 'lti'), array('rows'=>4, 'cols'=>60)); + $mform->setType('lti_customparameters', PARAM_TEXT); + + if(!empty($this->_customdata->isadmin)){ + $mform->addElement('checkbox', 'lti_coursevisible', ' ', ' ' . get_string('show_in_course', 'lti')); + } else { + $mform->addElement('hidden', 'lti_coursevisible', '1'); + } + + $launchoptions=array(); + $launchoptions[LTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'lti'); + $launchoptions[LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'lti'); + $launchoptions[LTI_LAUNCH_CONTAINER_WINDOW] = get_string('new_window', 'lti'); + + $mform->addElement('select', 'lti_launchcontainer', get_string('default_launch_container', 'lti'), $launchoptions); + $mform->setDefault('lti_launchcontainer', LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS); +// $mform->addHelpButton('lti_launchinpopup', 'launchinpopup', 'lti'); + + // Add privacy preferences fieldset where users choose whether to send their data + $mform->addElement('header', 'privacy', get_string('privacy', 'lti')); + + $options=array(); + $options[0] = get_string('never', 'lti'); + $options[1] = get_string('always', 'lti'); + $options[2] = get_string('delegate', 'lti'); + + $mform->addElement('select', 'lti_sendname', get_string('sendname', 'lti'), $options); + $mform->setDefault('lti_sendname', '2'); +// $mform->addHelpButton('lti_sendname', 'sendname', 'lti'); + + $mform->addElement('select', 'lti_sendemailaddr', get_string('sendemailaddr', 'lti'), $options); + $mform->setDefault('lti_sendemailaddr', '2'); +// $mform->addHelpButton('lti_sendemailaddr', 'sendemailaddr', 'lti'); + +//------------------------------------------------------------------------------- + // LTI Extensions + + // Add grading preferences fieldset where the tool is allowed to return grades + $mform->addElement('select', 'lti_acceptgrades', get_string('acceptgrades', 'lti'), $options); + $mform->setDefault('lti_acceptgrades', '2'); +// $mform->addHelpButton('lti_acceptgrades', 'acceptgrades', 'lti'); + + // Add grading preferences fieldset where the tool is allowed to retrieve rosters + $mform->addElement('select', 'lti_allowroster', get_string('allowroster', 'lti'), $options); + $mform->setDefault('lti_allowroster', '2'); +// $mform->addHelpButton('lti_allowroster', 'allowroster', 'lti'); + + + if(!empty($this->_customdata->isadmin)){ + //------------------------------------------------------------------------------- + // Add setup parameters fieldset + $mform->addElement('header', 'setupoptions', get_string('miscellaneous', 'lti')); + + // Adding option to change id that is placed in context_id + $idoptions = array(); + $idoptions[0] = get_string('id', 'lti'); + $idoptions[1] = get_string('courseid', 'lti'); + + $mform->addElement('text', 'lti_organizationid', get_string('organizationid', 'lti')); + $mform->setType('lti_organizationid', PARAM_TEXT); + // $mform->addHelpButton('lti_organizationid', 'organizationid', 'lti'); + + $mform->addElement('text', 'lti_organizationurl', get_string('organizationurl', 'lti')); + $mform->setType('lti_organizationurl', PARAM_TEXT); + // $mform->addHelpButton('lti_organizationurl', 'organizationurl', 'lti'); + } + + /* Suppress this for now - Chuck + $mform->addElement('text', 'lti_organizationdescr', get_string('organizationdescr', 'lti')); + $mform->setType('lti_organizationdescr', PARAM_TEXT); + $mform->addHelpButton('lti_organizationdescr', 'organizationdescr', 'lti'); + */ + +//------------------------------------------------------------------------------- + // Add a hidden element to signal a tool fixing operation after a problematic backup - restore process + //$mform->addElement('hidden', 'lti_fix'); + + $tab = optional_param('tab', '', PARAM_ALPHAEXT); + $mform->addElement('hidden', 'tab', $tab); + + $courseid = optional_param('course', 1, PARAM_INT); + $mform->addElement('hidden', 'course', $courseid); + +//------------------------------------------------------------------------------- + // Add standard buttons, common to all modules + $this->add_action_buttons(); + + } +} diff --git a/mod/lti/instructor_edit_tool_type.php b/mod/lti/instructor_edit_tool_type.php new file mode 100644 index 00000000000..b32a8a56fc6 --- /dev/null +++ b/mod/lti/instructor_edit_tool_type.php @@ -0,0 +1,93 @@ +dirroot.'/mod/lti/edit_form.php'); + +$courseid = required_param('course', PARAM_INT); + +require_login($courseid, false); +$url = new moodle_url('/mod/lti/instructor_edit_tool_type.php'); +$PAGE->set_url($url); +$PAGE->set_pagelayout('popup'); + +$action = optional_param('action', null, PARAM_TEXT); +$typeid = optional_param('typeid', null, PARAM_INT); + +if(!empty($typeid)){ + $type = lti_get_type($typeid); + if($type->course != $courseid){ + throw new Exception('You do not have permissions to edit this tool type.'); + + die; + } +} + +echo $OUTPUT->header(); + +$data = data_submitted(); + +if (confirm_sesskey() && isset($data->submitbutton)) { + $type = new stdClass(); + + if (isset($id)) { + /*$type->id = $id; + + lti_update_type($type, $data); + $script = << +SCRIPT;*/ + + die; + } else { + $type->state = LTI_TOOL_STATE_CONFIGURED; + $type->course = $COURSE->id; + + $id = lti_add_type($type, $data); + $name = json_encode($type->name); + + $script = << +SCRIPT; + + echo $script; + + die; + } +} else if(isset($data->cancel)){ + $script = << +SCRIPT; + + echo $script; + die; +} + +//Delete action is called via ajax +if ($action == 'delete'){ + lti_delete_type($typeid); + + die; +} + +echo $OUTPUT->heading(get_string('toolsetup', 'lti')); + +if($action == 'add') { + $form = new mod_lti_edit_types_form(); + $form->display(); +} else if($action == 'edit'){ + $form = new mod_lti_edit_types_form(); + $type = lti_get_type_type_config($typeid); + $form->set_data($type); + $form->display(); +} + +echo $OUTPUT->footer(); diff --git a/mod/lti/lang/en/lti.php b/mod/lti/lang/en/lti.php index 7f733d81a73..f8749d83cf8 100644 --- a/mod/lti/lang/en/lti.php +++ b/mod/lti/lang/en/lti.php @@ -1,198 +1,196 @@ -. - -/** - * This file contains en_utf8 translation of the Basic LTI module - * - * @package basiclti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis - * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -$string['accept'] = 'Accept'; -$string['acceptgrades'] = 'Accept grades from tool'; -$string['activity'] = 'Activity'; -$string['addnewapp'] = 'Enable External Application'; -$string['addserver'] = 'Add new trusted server'; -$string['addtype'] = 'Add External Tool Configuration'; -$string['allow'] = 'Allow'; -$string['allowinstructorcustom'] = 'Allow instructors to add custom parameters'; -$string['allowroster'] = 'Tool may access course roster'; -$string['allowsetting'] = 'Allow tool to store 8K of settings in Moodle'; -$string['always'] = 'Always'; -$string['lti'] = 'Basic LTI'; -$string['basiclti'] = 'Basic LTI'; -$string['basiclti_base_string'] = 'Basic LTI OAuth Base String'; -$string['basiclti_in_new_window'] = 'Your activity has opened in a new window'; -$string['basiclti_endpoint'] = 'Basic LTI Launch Endpoint'; -$string['basiclti_parameters'] = 'Basic LTI Launch Parameters'; -$string['basicltiactivities'] = 'Basic LTI Activities'; -$string['basicltifieldset'] = 'Custom example fieldset'; -$string['basicltiintro'] = 'Activity Description'; -$string['basicltiname'] = 'Activity Name'; -$string['basicltisettings'] = 'Basic Learning Tool Interoperability Settings'; -$string['comment'] = 'Comment'; -$string['configpassword'] = 'Default Remote Tool Password'; -$string['configpreferheight'] = 'Default preferred height'; -$string['configpreferwidget'] = 'Set widget as default launch'; -$string['configpreferwidth'] = 'Default preferred width'; -$string['configresourceurl'] = 'Default Resource URL'; -$string['configtoolurl'] = 'Default Remote Tool URL'; -$string['configtypes'] = 'Enable Basic LTI Applications'; -$string['courseid'] = 'Course id number'; -$string['coursemisconf'] = 'Course is misconfigured'; -$string['curllibrarymissing'] = 'PHP Curl library must be installed to use LTI'; -$string['custom'] = 'Custom parameters'; -$string['custominstr'] = 'Custom parameters'; -$string['debuglaunch'] = 'Debug Option'; -$string['debuglaunchoff'] = 'Normal launch'; -$string['debuglaunchon'] = 'Debug launch'; -$string['delegate'] = 'Delegate to Professor'; -$string['donot'] = 'Do not send'; -$string['donotaccept'] = 'Do not accept'; -$string['donotallow'] = 'Do not allow'; -$string['enableemailnotification'] = 'Send notification emails'; -$string['enableemailnotification_help'] = 'If enabled, students will receive email notification when their tool submissions are graded.'; -$string['errormisconfig'] = 'Misconfigured tool. Please ask your Moodle administrator to fix the configuration of the tool.'; -$string['extensions'] = 'Basic LTI Extension Services'; -$string['failedtoconnect'] = 'Moodle was unable to communicate with the \"$a\" system'; -$string['filterconfig'] = 'Basic LTI administration'; -$string['filtername'] = 'Basic LTI'; -$string['filter_basiclti_configlink'] = 'Configure your preferred sites and their passwords'; -$string['filter_basiclti_password'] = 'Password is mandatory'; -$string['fixexistingconf'] = 'Use an existing configuration for the misconfigured instance'; -$string['fixnew'] = 'New Configuration'; -$string['fixnewconf'] = 'Define a new configuration for the misconfigured instance'; -$string['fixold'] = 'Use Existing'; -$string['grading'] = 'Grade Routing'; -$string['id'] = 'id'; -$string['imsroleadmin'] = 'Instructor,Administrator'; -$string['imsroleinstructor'] = 'Instructor'; -$string['imsrolelearner'] = 'Learner'; -$string['invalidid'] = 'basic LTI ID was incorrect'; -$string['launch_in_moodle'] = 'Launch tool in moodle'; -$string['launch_in_popup'] = 'Launch tool in a pop-up'; -$string['launchinpopup'] = 'Launch Container'; -$string['launchoptions'] = 'Launch Options'; -$string['lti_errormsg'] = 'The tool returned the following error message: \"$a\"'; -$string['misconfiguredtools'] = 'Misconfigured tool instances were detected'; -$string['missingparameterserror'] = 'The page is misconfigured: \"$a\"'; -$string['module_class_type'] = 'Moodle module type'; -$string['modulename'] = 'External Tool'; -$string['modulenameplural'] = 'basicltis'; -$string['modulenamepluralformatted'] = 'Basic LTI Instances'; -$string['never'] = 'Never'; -$string['noattempts'] = 'No attempts have been made on this tool instance'; -$string['noservers'] = 'No servers found'; -$string['notypes'] = 'There are currently no LTI tools setup in Moodle. Click the Install link above to add some.'; -$string['noviewusers'] = 'No users were found with permissions to use this tool'; -$string['optionalsettings'] = 'Optional settings'; -$string['organization'] ='Organization details'; -$string['organizationdescr'] ='Organization Description'; -$string['organizationid'] ='Organization ID'; -$string['organizationurl'] ='Organization URL'; -$string['pagesize'] = 'Submissions shown per page'; -$string['password'] = 'Shared Secret'; -$string['pluginadministration'] = 'Basic LTI administration'; -$string['pluginname'] = 'LTI'; -$string['preferheight'] = 'Preferred Height'; -$string['preferwidget'] = 'Prefer Widget Launch'; -$string['preferwidth'] = 'Preferred Width'; -$string['press_to_submit'] = 'Press to launch this activity'; -$string['privacy'] = 'Privacy'; -$string['quickgrade'] = 'Allow quick grading'; -$string['quickgrade_help'] = 'If enabled, multiple tools can be graded on one page. Add grades and comments then click the "Save all my feedback" button to save all changes for that page.'; -$string['redirect'] = 'You will be redirected in few seconds. If you are not, press the button.'; -$string['resource'] = 'Resource'; -$string['resourcekey'] = 'Consumer Key'; -$string['resourceurl'] = 'Resource URL'; -$string['saveallfeedback'] = 'Save all my feedback'; -$string['send'] = 'Send'; -$string['sendemailaddr'] = 'Share launcher\'s email with tool'; -$string['sendname'] = 'Share launcher\'s name with tool'; -$string['setdefault'] = 'Set a default value for the professor if delegating'; -$string['setupbox'] = 'Basic LTI Tool Setup Box'; -$string['setupoptions'] = 'Setup Options'; -$string['size'] = 'Size parameters'; -$string['submission'] = 'Submission'; -$string['toggle_debug_data'] = 'Toggle Debug Data'; -$string['toolsetup'] = 'Basic LTI Tool Setup'; -$string['toolurl'] = 'Tool Base URL'; -$string['typename'] = 'Tool Name'; -$string['types'] = 'Types'; -$string['validurl'] = 'A valid URL must start with http(s)://'; -$string['viewsubmissions'] = 'View submissions and grading screen'; - -//New admin strings - -$string['show_in_course'] = 'Show tool type when creating tool instances'; -$string['delegate_yes'] = 'Delegate to Instructor (Default: Yes)'; -$string['delegate_no'] = 'Delegate to Instructor (Default: No)'; -$string['tool_settings'] = 'Tool Settings'; -$string['miscellaneous'] = 'Miscellaneous'; -$string['embed'] = 'Embed'; -$string['embed_no_blocks'] = 'Embed, without blocks'; -$string['new_window'] = 'New window'; -$string['default_launch_container'] = 'Default Launch Container'; -$string['active'] = 'Active'; -$string['pending'] = 'Pending'; -$string['rejected'] = 'Rejected'; -$string['baseurl'] = 'Base URL'; -$string['action'] = 'Action'; -$string['createdon'] = 'Created On'; -$string['accept'] = 'Accept'; -$string['update'] = 'Update'; -$string['delete'] = 'Delete'; -$string['reject'] = 'Reject'; -$string['external_tool_types'] = 'External Tool Types'; -$string['no_lti_configured'] = 'There are no active External Tools configured.'; -$string['no_lti_pending'] = 'There are no pending External Tools.'; -$string['no_lti_rejected'] = 'There are no rejected External Tools.'; - -//New instructor strings -$string['display_name'] = 'Display activity name when launched'; -$string['display_description'] = 'Display activity description when launched'; -$string['external_tool_type'] = 'External tool type'; -$string['launch_url'] = 'Launch URL'; -$string['share_name'] = 'Share launcher\'s name with the tool'; -$string['share_email'] = 'Share launcher\'s email with the tool'; -$string['accept_grades'] = 'Accept grades from the tool'; -$string['share_roster'] = 'Allow the tool to access this course\'s roster'; -$string['automatic'] = 'Automatic, based on Launch URL'; -$string['default'] = 'Default'; +. + +/** + * This file contains en_utf8 translation of the Basic LTI module + * + * @package basiclti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['accept'] = 'Accept'; +$string['acceptgrades'] = 'Accept grades from tool'; +$string['activity'] = 'Activity'; +$string['addnewapp'] = 'Enable External Application'; +$string['addserver'] = 'Add new trusted server'; +$string['addtype'] = 'Add External Tool Configuration'; +$string['allow'] = 'Allow'; +$string['allowinstructorcustom'] = 'Allow instructors to add custom parameters'; +$string['allowroster'] = 'Tool may access course roster'; +$string['allowsetting'] = 'Allow tool to store 8K of settings in Moodle'; +$string['always'] = 'Always'; +$string['lti'] = 'Basic LTI'; +$string['basiclti'] = 'Basic LTI'; +$string['basiclti_base_string'] = 'Basic LTI OAuth Base String'; +$string['basiclti_in_new_window'] = 'Your activity has opened in a new window'; +$string['basiclti_endpoint'] = 'Basic LTI Launch Endpoint'; +$string['basiclti_parameters'] = 'Basic LTI Launch Parameters'; +$string['basicltiactivities'] = 'Basic LTI Activities'; +$string['basicltifieldset'] = 'Custom example fieldset'; +$string['basicltiintro'] = 'Activity Description'; +$string['basicltiname'] = 'Activity Name'; +$string['basicltisettings'] = 'Basic Learning Tool Interoperability Settings'; +$string['comment'] = 'Comment'; +$string['configpassword'] = 'Default Remote Tool Password'; +$string['configpreferheight'] = 'Default preferred height'; +$string['configpreferwidget'] = 'Set widget as default launch'; +$string['configpreferwidth'] = 'Default preferred width'; +$string['configresourceurl'] = 'Default Resource URL'; +$string['configtoolurl'] = 'Default Remote Tool URL'; +$string['configtypes'] = 'Enable Basic LTI Applications'; +$string['courseid'] = 'Course id number'; +$string['coursemisconf'] = 'Course is misconfigured'; +$string['curllibrarymissing'] = 'PHP Curl library must be installed to use LTI'; +$string['custom'] = 'Custom parameters'; +$string['custominstr'] = 'Custom parameters'; +$string['debuglaunch'] = 'Debug Option'; +$string['debuglaunchoff'] = 'Normal launch'; +$string['debuglaunchon'] = 'Debug launch'; +$string['donot'] = 'Do not send'; +$string['donotaccept'] = 'Do not accept'; +$string['donotallow'] = 'Do not allow'; +$string['enableemailnotification'] = 'Send notification emails'; +$string['enableemailnotification_help'] = 'If enabled, students will receive email notification when their tool submissions are graded.'; +$string['errormisconfig'] = 'Misconfigured tool. Please ask your Moodle administrator to fix the configuration of the tool.'; +$string['extensions'] = 'Basic LTI Extension Services'; +$string['failedtoconnect'] = 'Moodle was unable to communicate with the \"$a\" system'; +$string['filterconfig'] = 'Basic LTI administration'; +$string['filtername'] = 'Basic LTI'; +$string['filter_basiclti_configlink'] = 'Configure your preferred sites and their passwords'; +$string['filter_basiclti_password'] = 'Password is mandatory'; +$string['fixexistingconf'] = 'Use an existing configuration for the misconfigured instance'; +$string['fixnew'] = 'New Configuration'; +$string['fixnewconf'] = 'Define a new configuration for the misconfigured instance'; +$string['fixold'] = 'Use Existing'; +$string['grading'] = 'Grade Routing'; +$string['id'] = 'id'; +$string['imsroleadmin'] = 'Instructor,Administrator'; +$string['imsroleinstructor'] = 'Instructor'; +$string['imsrolelearner'] = 'Learner'; +$string['invalidid'] = 'basic LTI ID was incorrect'; +$string['launch_in_moodle'] = 'Launch tool in moodle'; +$string['launch_in_popup'] = 'Launch tool in a pop-up'; +$string['launchinpopup'] = 'Launch Container'; +$string['launchoptions'] = 'Launch Options'; +$string['lti_errormsg'] = 'The tool returned the following error message: \"$a\"'; +$string['misconfiguredtools'] = 'Misconfigured tool instances were detected'; +$string['missingparameterserror'] = 'The page is misconfigured: \"$a\"'; +$string['module_class_type'] = 'Moodle module type'; +$string['modulename'] = 'External Tool'; +$string['modulenameplural'] = 'basicltis'; +$string['modulenamepluralformatted'] = 'Basic LTI Instances'; +$string['never'] = 'Never'; +$string['noattempts'] = 'No attempts have been made on this tool instance'; +$string['noservers'] = 'No servers found'; +$string['notypes'] = 'There are currently no LTI tools setup in Moodle. Click the Install link above to add some.'; +$string['noviewusers'] = 'No users were found with permissions to use this tool'; +$string['optionalsettings'] = 'Optional settings'; +$string['organization'] ='Organization details'; +$string['organizationdescr'] ='Organization Description'; +$string['organizationid'] ='Organization ID'; +$string['organizationurl'] ='Organization URL'; +$string['pagesize'] = 'Submissions shown per page'; +$string['password'] = 'Shared Secret'; +$string['pluginadministration'] = 'Basic LTI administration'; +$string['pluginname'] = 'LTI'; +$string['preferheight'] = 'Preferred Height'; +$string['preferwidget'] = 'Prefer Widget Launch'; +$string['preferwidth'] = 'Preferred Width'; +$string['press_to_submit'] = 'Press to launch this activity'; +$string['privacy'] = 'Privacy'; +$string['quickgrade'] = 'Allow quick grading'; +$string['quickgrade_help'] = 'If enabled, multiple tools can be graded on one page. Add grades and comments then click the "Save all my feedback" button to save all changes for that page.'; +$string['redirect'] = 'You will be redirected in few seconds. If you are not, press the button.'; +$string['resource'] = 'Resource'; +$string['resourcekey'] = 'Consumer Key'; +$string['resourceurl'] = 'Resource URL'; +$string['saveallfeedback'] = 'Save all my feedback'; +$string['send'] = 'Send'; +$string['sendemailaddr'] = 'Share launcher\'s email with tool'; +$string['sendname'] = 'Share launcher\'s name with tool'; +$string['setdefault'] = 'Set a default value for the professor if delegating'; +$string['setupbox'] = 'Basic LTI Tool Setup Box'; +$string['setupoptions'] = 'Setup Options'; +$string['size'] = 'Size parameters'; +$string['submission'] = 'Submission'; +$string['toggle_debug_data'] = 'Toggle Debug Data'; +$string['toolsetup'] = 'External Tool Configuration'; +$string['toolurl'] = 'Tool Base URL'; +$string['typename'] = 'Tool Name'; +$string['types'] = 'Types'; +$string['validurl'] = 'A valid URL must start with http(s)://'; +$string['viewsubmissions'] = 'View submissions and grading screen'; + +//New admin strings + +$string['show_in_course'] = 'Show tool type when creating tool instances'; +$string['delegate'] = 'Delegate to Instructor'; +$string['tool_settings'] = 'Tool Settings'; +$string['miscellaneous'] = 'Miscellaneous'; +$string['embed'] = 'Embed'; +$string['embed_no_blocks'] = 'Embed, without blocks'; +$string['new_window'] = 'New window'; +$string['default_launch_container'] = 'Default Launch Container'; +$string['active'] = 'Active'; +$string['pending'] = 'Pending'; +$string['rejected'] = 'Rejected'; +$string['baseurl'] = 'Base URL'; +$string['action'] = 'Action'; +$string['createdon'] = 'Created On'; +$string['accept'] = 'Accept'; +$string['update'] = 'Update'; +$string['delete'] = 'Delete'; +$string['reject'] = 'Reject'; +$string['external_tool_types'] = 'External Tool Types'; +$string['no_lti_configured'] = 'There are no active External Tools configured.'; +$string['no_lti_pending'] = 'There are no pending External Tools.'; +$string['no_lti_rejected'] = 'There are no rejected External Tools.'; + +//New instructor strings +$string['display_name'] = 'Display activity name when launched'; +$string['display_description'] = 'Display activity description when launched'; +$string['external_tool_type'] = 'External tool type'; +$string['launch_url'] = 'Launch URL'; +$string['share_name'] = 'Share launcher\'s name with the tool'; +$string['share_email'] = 'Share launcher\'s email with the tool'; +$string['accept_grades'] = 'Accept grades from the tool'; +$string['share_roster'] = 'Allow the tool to access this course\'s roster'; +$string['automatic'] = 'Automatic, based on Launch URL'; +$string['default'] = 'Default'; diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index a7901fd98df..33051c70fbf 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -129,6 +129,23 @@ function lti_view($instance, $makeobject=false) { echo $content; } +function lti_build_sourcedid($instanceid, $userid, $servicesalt){ + $data = new stdClass(); + + $data->instanceid = $instanceid; + $data->userid = $userid; + + $json = json_encode($data); + + $hash = hash('sha256', $json . $servicesalt, false); + + $container = new stdClass(); + $container->data = $data; + $container->hash = $hash; + + return $container; +} + /** * This function builds the request that must be sent to the tool producer * @@ -168,20 +185,7 @@ function lti_build_request($instance, $typeconfig, $course) { $placementsecret = $instance->servicesalt; if ( isset($placementsecret) ) { - $data = new stdClass(); - - $data->instanceid = $instance->id; - $data->userid = $USER->id; - - $json = json_encode($data); - - $hash = hash('sha256', $json . $placementsecret, false); - - $container = new stdClass(); - $container->data = $data; - $container->hash = $hash; - - $sourcedid = json_encode($container); + $sourcedid = json_encode(lti_build_sourcedid($instance->id, $USER->id, $placementsecret)); } if ( isset($placementsecret) && @@ -338,10 +342,10 @@ function lti_get_type_config($typeid) { return $typeconfig; } -function lti_get_tools_by_url($url, $state){ +function lti_get_tools_by_url($url, $state, $courseid = null){ $domain = lti_get_domain_from_url($url); - return lti_get_tools_by_domain($domain, $state); + return lti_get_tools_by_domain($domain, $state, $courseid); } function lti_get_tools_by_domain($domain, $state = null, $courseid = null){ @@ -387,14 +391,23 @@ function lti_filter_get_types() { } function lti_get_types_for_add_instance(){ - global $DB; - $admintypes = $DB->get_records('lti_types', array('coursevisible' => 1)); + global $DB, $SITE, $COURSE; + + $query = <<get_records_sql($query, array('siteid' => $SITE->id, 'courseid' => $COURSE->id)); $types = array(); - $types[0] = get_string('automatic', 'lti'); + $types[0] = (object)array('name' => get_string('automatic', 'lti'), 'course' => $SITE->id); foreach($admintypes as $type) { - $types[$type->id] = $type->name; + $types[$type->id] = (object)array('name' => $type->name, 'course' => $type->course); } return $types; @@ -409,7 +422,7 @@ function lti_get_domain_from_url($url){ } function lti_get_tool_by_url_match($url, $courseid = null, $state = LTI_TOOL_STATE_CONFIGURED){ - $possibletools = lti_get_tools_by_url($url, $state, $courseid); + $possibletools = lti_get_tools_by_url($url, $courseid, $state); return lti_get_best_tool_by_url($url, $possibletools); } @@ -729,6 +742,8 @@ function lti_add_type($type, $config){ } } } + + return $id; } /** @@ -923,3 +938,8 @@ function lti_submittedlink($cm, $allgroups=false) { return $submitted; } +function lti_get_type($typeid){ + global $DB; + + return $DB->get_record('lti_types', array('id' => $typeid)); +} \ No newline at end of file diff --git a/mod/lti/mod_form.js b/mod/lti/mod_form.js new file mode 100644 index 00000000000..5d01de66109 --- /dev/null +++ b/mod/lti/mod_form.js @@ -0,0 +1,124 @@ +M.mod_lti = M.mod_lti || {}; + +M.mod_lti.editor = { + init: function(Y, settings){ + this.Y = Y; + var self = this; + this.settings = Y.JSON.parse(settings); + + var typeSelector = Y.one('#id_typeid'); + typeSelector.on('change', function(e){ + self.toggleEditButtons(); + }); + + this.createTypeEditorButtons(); + + this.toggleEditButtons(); + }, + + getSelectedToolTypeOption: function(){ + var Y = this.Y; + var typeSelector = Y.one('#id_typeid'); + + return typeSelector.one('option[value=' + typeSelector.get('value') + ']'); + }, + + /** + * Adds buttons for creating, editing, and deleting tool types + */ + createTypeEditorButtons: function(){ + var Y = this.Y; + var self = this; + + var typeSelector = Y.one('#id_typeid'); + + var createIcon = function(id, tooltip, iconUrl){ + return Y.Node.create('') + .set('id', id) + .set('title', tooltip) + .setStyle('margin-left', '.5em') + .set('href', 'javascript:void(0);') + .append(Y.Node.create('')); + } + + var addIcon = createIcon('lti_add_tool_type', 'Add new tool type', this.settings.add_icon_url); + var editIcon = createIcon('lti_edit_tool_type', 'Edit new tool type', this.settings.edit_icon_url); + var deleteIcon = createIcon('lti_delete_tool_type', 'Delete tool type', this.settings.delete_icon_url); + + editIcon.on('click', function(e){ + var toolTypeId = typeSelector.get('value'); + + if(self.getSelectedToolTypeOption().getAttribute('editable')){ + window.open(self.settings.instructor_tool_type_edit_url + '&action=edit&typeid=' + toolTypeId, 'edit_tool'); + } + }); + + addIcon.on('click', function(e){ + window.open(self.settings.instructor_tool_type_edit_url + '&action=add', 'add_tool'); + }); + + deleteIcon.on('click', function(e){ + var toolTypeId = typeSelector.get('value'); + + if(self.getSelectedToolTypeOption().getAttribute('editable')){ + Y.io(self.settings.instructor_tool_type_edit_url + '&action=delete&typeid=' + toolTypeId, { + on: { + success: function(){ + getSelectedOption().remove(); + }, + failure: function(){ + + } + } + }); + } + }); + + typeSelector.insert(addIcon, 'after'); + addIcon.insert(editIcon, 'after'); + editIcon.insert(deleteIcon, 'after'); + }, + + toggleEditButtons: function(){ + var Y = this.Y; + + var lti_edit_tool_type = Y.one('#lti_edit_tool_type'); + var lti_delete_tool_type = Y.one('#lti_delete_tool_type'); + + if(this.getSelectedToolTypeOption().getAttribute('editable')){ + lti_edit_tool_type.setStyle('opacity', '1'); + lti_delete_tool_type.setStyle('opacity', '1'); + } else { + lti_edit_tool_type.setStyle('opacity', '.2'); + lti_delete_tool_type.setStyle('opacity', '.2'); + } + }, + + addToolType: function(text, value){ + var Y = this.Y; + var typeSelector = Y.one('#id_typeid'); + + var option = Y.Node.create(''; - } - - if (!empty($tools)) { - $html .= << -
- - - - - - - - -HTML; - - foreach ($tools as $type) { - $date = userdate($type->timecreated); - $accept = get_string('accept', 'lti'); - $update = get_string('update', 'lti'); - $delete = get_string('delete', 'lti'); - - $accepthtml = << - {$accept} - -HTML; - - $deleteaction = 'delete'; - - if($type->state == LTI_TOOL_STATE_CONFIGURED){ - $accepthtml = ''; - } - - if($type->state != LTI_TOOL_STATE_REJECTED) { - $deleteaction = 'reject'; - $delete = get_string('reject', 'lti'); - } - - $html .= << - - - - - -HTML; - } - $html .= '
$typename$baseurl$createdon$action
- {$type->name} - - {$type->baseurl} - - {$date} - - {$accepthtml} - - {$update} - - - {$delete} - -
'; - } else { - $html .= get_string('no_' . $id, 'lti'); - } - - return $html; -} - -if ($ADMIN->fulltree) { - require_once($CFG->dirroot.'/mod/lti/locallib.php'); - - $configuredtoolshtml = ''; - $pendingtoolshtml = ''; - $rejectedtoolshtml = ''; - - $active = get_string('active', 'lti'); - $pending = get_string('pending', 'lti'); - $rejected = get_string('rejected', 'lti'); - $typename = get_string('typename', 'lti'); - $baseurl = get_string('baseurl', 'lti'); - $action = get_string('action', 'lti'); - $createdon = get_string('createdon', 'lti'); - - $types = lti_filter_get_types(); - - $configuredtools = array_filter($types, function($value){ - return $value->state == LTI_TOOL_STATE_CONFIGURED; - }); - - $configuredtoolshtml = blti_get_tool_table($configuredtools, 'lti_configured'); - - $pendingtools = array_filter($types, function($value){ - return $value->state == LTI_TOOL_STATE_PENDING; - }); - - $pendingtoolshtml = blti_get_tool_table($pendingtools, 'lti_pending'); - - $rejectedtools = array_filter($types, function($value){ - return $value->state == LTI_TOOL_STATE_REJECTED; - }); - - $rejectedtoolshtml = blti_get_tool_table($rejectedtools, 'lti_rejected'); - - $tab = optional_param('tab', '', PARAM_ALPHAEXT); - $activeselected = ''; - $pendingselected = ''; - $rejectedselected = ''; - switch($tab){ - case 'lti_pending': - $pendingselected = 'class="selected"'; - break; - case 'lti_rejected': - $rejectedselected = 'class="selected"'; - break; - default: - $activeselected = 'class="selected"'; - break; - } - - $template = << - -
-
- $configuredtoolshtml -
-
- $pendingtoolshtml -
-
- $rejectedtoolshtml -
-
- - - -HTML; - - $PAGE->requires->yui2_lib('tabview'); - $PAGE->requires->yui2_lib('datatable'); - - $settings->add(new admin_setting_heading('lti_types', get_string('external_tool_types', 'lti'), $template /* $str*/)); -} +. + +/** + * This file defines the global basiclti administration form + * + * @package lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +global $PAGE, $CFG; + +require_once($CFG->dirroot.'/mod/lti/locallib.php'); + +function lti_get_tool_table($tools, $id){ + global $CFG, $USER; + $html = ''; + + $typename = get_string('typename', 'lti'); + $baseurl = get_string('baseurl', 'lti'); + $action = get_string('action', 'lti'); + $createdon = get_string('createdon', 'lti'); + + if($id == 'lti_configured'){ + $html .= ''; + } + + if (!empty($tools)) { + $html .= << + + + + + + + + + +HTML; + + foreach ($tools as $type) { + $date = userdate($type->timecreated); + $accept = get_string('accept', 'lti'); + $update = get_string('update', 'lti'); + $delete = get_string('delete', 'lti'); + + $accepthtml = << + {$accept} + +HTML; + + $deleteaction = 'delete'; + + if($type->state == LTI_TOOL_STATE_CONFIGURED){ + $accepthtml = ''; + } + + if($type->state != LTI_TOOL_STATE_REJECTED) { + $deleteaction = 'reject'; + $delete = get_string('reject', 'lti'); + } + + $html .= << + + + + + +HTML; + } + $html .= '
$typename$baseurl$createdon$action
+ {$type->name} + + {$type->baseurl} + + {$date} + + {$accepthtml} + + {$update} + + + {$delete} + +
'; + } else { + $html .= get_string('no_' . $id, 'lti'); + } + + return $html; +} + +if ($ADMIN->fulltree) { + require_once($CFG->dirroot.'/mod/lti/locallib.php'); + + $configuredtoolshtml = ''; + $pendingtoolshtml = ''; + $rejectedtoolshtml = ''; + + $active = get_string('active', 'lti'); + $pending = get_string('pending', 'lti'); + $rejected = get_string('rejected', 'lti'); + $typename = get_string('typename', 'lti'); + $baseurl = get_string('baseurl', 'lti'); + $action = get_string('action', 'lti'); + $createdon = get_string('createdon', 'lti'); + + $types = lti_filter_get_types(); + + $configuredtools = array_filter($types, function($value){ + return $value->state == LTI_TOOL_STATE_CONFIGURED; + }); + + $configuredtoolshtml = lti_get_tool_table($configuredtools, 'lti_configured'); + + $pendingtools = array_filter($types, function($value){ + return $value->state == LTI_TOOL_STATE_PENDING; + }); + + $pendingtoolshtml = lti_get_tool_table($pendingtools, 'lti_pending'); + + $rejectedtools = array_filter($types, function($value){ + return $value->state == LTI_TOOL_STATE_REJECTED; + }); + + $rejectedtoolshtml = lti_get_tool_table($rejectedtools, 'lti_rejected'); + + $tab = optional_param('tab', '', PARAM_ALPHAEXT); + $activeselected = ''; + $pendingselected = ''; + $rejectedselected = ''; + switch($tab){ + case 'lti_pending': + $pendingselected = 'class="selected"'; + break; + case 'lti_rejected': + $rejectedselected = 'class="selected"'; + break; + default: + $activeselected = 'class="selected"'; + break; + } + + $template = << + +
+
+ $configuredtoolshtml +
+
+ $pendingtoolshtml +
+
+ $rejectedtoolshtml +
+
+ + + +HTML; + + $PAGE->requires->yui2_lib('tabview'); + $PAGE->requires->yui2_lib('datatable'); + + $settings->add(new admin_setting_heading('lti_types', get_string('external_tool_types', 'lti'), $template)); +} diff --git a/mod/lti/simpletest/testlocallib.php b/mod/lti/simpletest/testlocallib.php index c8536d0219b..847c4867e73 100644 --- a/mod/lti/simpletest/testlocallib.php +++ b/mod/lti/simpletest/testlocallib.php @@ -51,19 +51,23 @@ if (!defined('MOODLE_INTERNAL')) { } require_once($CFG->dirroot . '/mod/lti/locallib.php'); +require_once($CFG->dirroot . '/mod/lti/servicelib.php'); class lti_locallib_test extends UnitTestCase { public static $includecoverage = array('mod/lti/locallib.php'); + function test_split_custom_parameters() { - $this->assertEqual(lti_split_custom_parameters("x=1\ny=2"), - array('custom_x' => '1', 'custom_y'=> '2')); - $this->assertEqual(lti_split_custom_parameters('x=1;y=2'), - array('custom_x' => '1', 'custom_y'=> '2')); - $this->assertEqual(lti_split_custom_parameters('Review:Chapter=1.2.56'), - array('custom_review_chapter' => '1.2.56')); - $this->assertEqual(lti_split_custom_parameters('Complex!@#$^*(){}[]KEY=Complex!@#$^*(){}[]Value'), - array('custom_complex____________key' => 'Complex!@#$^*(){}[]Value')); - $this->assertEqual(5, 5); + $this->assertEqual(lti_split_custom_parameters("x=1\ny=2"), + array('custom_x' => '1', 'custom_y'=> '2')); + + $this->assertEqual(lti_split_custom_parameters('x=1;y=2'), + array('custom_x' => '1', 'custom_y'=> '2')); + + $this->assertEqual(lti_split_custom_parameters('Review:Chapter=1.2.56'), + array('custom_review_chapter' => '1.2.56')); + + $this->assertEqual(lti_split_custom_parameters('Complex!@#$^*(){}[]KEY=Complex!@#$^*(){}[]Value'), + array('custom_complex____________key' => 'Complex!@#$^*(){}[]Value')); } function test_sign_parameters() { @@ -86,4 +90,41 @@ class lti_locallib_test extends UnitTestCase { $this->assertEqual($parms, $correct); } + function test_parse_grade_replace_message(){ + $message = << + + + V1.0 + 999998123 + + + + + + + {"data":{"instanceid":"2","userid":"2"},"hash":"0b5078feab59b9938c333ceaae21d8e003a7b295e43cdf55338445254421076b"} + + + + en-us + 0.92 + + + + + + +XML; + + $parsed = lti_parse_grade_replace_message(new SimpleXMLElement($message)); + + $this->assertEqual($parsed->userid, '2'); + $this->assertEqual($parsed->instanceid, '2'); + $this->assertEqual($parsed->sourcedidhash, '0b5078feab59b9938c333ceaae21d8e003a7b295e43cdf55338445254421076b'); + + $ltiinstance = (object)array('servicesalt' => '4e5fcc06de1d58.44963230'); + + lti_verify_sourcedid($ltiinstance, $parsed); + } } diff --git a/mod/lti/typessettings.php b/mod/lti/typessettings.php index 20f3fda4e41..8e5e49ae938 100644 --- a/mod/lti/typessettings.php +++ b/mod/lti/typessettings.php @@ -1,198 +1,198 @@ -. - -/** - * This file contains the script used to clone Moodle admin setting page. - * It is used to create a new form used to pre-configure basiclti - * activities - * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis - * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -require_once('../../config.php'); -require_once($CFG->libdir.'/adminlib.php'); -require_once($CFG->dirroot.'/mod/lti/edit_form.php'); -require_once($CFG->dirroot.'/mod/lti/locallib.php'); - -$section = 'modsettinglti'; -$return = optional_param('return', '', PARAM_ALPHA); -$adminediting = optional_param('adminedit', -1, PARAM_BOOL); -$action = optional_param('action', null, PARAM_TEXT); -$id = optional_param('id', null, PARAM_INT); -$useexisting = optional_param('useexisting', null, PARAM_INT); -$definenew = optional_param('definenew', null, PARAM_INT); - -/// no guest autologin -require_login(0, false); -$url = new moodle_url('/mod/lti/typesettings.php'); -$PAGE->set_url($url); - -admin_externalpage_setup('managemodules'); // Hacky solution for printing the admin page - -$tab = optional_param('tab', '', PARAM_ALPHAEXT); -$redirect = "$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti&tab={$tab}"; - -/// WRITING SUBMITTED DATA (IF ANY) ------------------------------------------------------------------------------- - -$statusmsg = ''; -$errormsg = ''; -$focus = ''; - -$data = data_submitted(); - -if (confirm_sesskey() && isset($data->submitbutton)) { - $type = new StdClass(); - - if (isset($id)) { - $type->id = $id; - - lti_update_type($type, $data); - - redirect($redirect); - die; - } else { - $type->state = LTI_TOOL_STATE_CONFIGURED; - - lti_add_type($type, $data); - - redirect($redirect); - die; - } -} else if(isset($data->cancel)){ - redirect($redirect); - die; -} - -if ($action == 'accept') { - lti_set_state_for_type($id, LTI_TOOL_STATE_CONFIGURED); - redirect($redirect); - die; -} - -if ($action == 'reject') { - lti_set_state_for_type($id, LTI_TOOL_STATE_REJECTED); - redirect($redirect); - die; -} - -if ($action == 'delete') { - lti_delete_type($id); - redirect($redirect); - die; -} - -/// print header stuff ------------------------------------------------------------ -$PAGE->set_focuscontrol($focus); -if (empty($SITE->fullname)) { - $PAGE->set_title($settingspage->visiblename); - $PAGE->set_heading($settingspage->visiblename); - - $PAGE->navbar->add('Basic LTI Administration', $CFG->wwwroot.'/admin/settings.php?section=modsettinglti'); - - echo $OUTPUT->header(); - - echo $OUTPUT->box(get_string('configintrosite', 'admin')); - - if ($errormsg !== '') { - echo $OUTPUT->notification($errormsg); - - } else if ($statusmsg !== '') { - echo $OUTPUT->notification($statusmsg, 'notifysuccess'); - } - - // --------------------------------------------------------------------------------------------------------------- - - echo ''; - echo '
'; - echo html_writer::input_hidden_params($PAGE->url); - echo ''; - echo ''; - - echo $settingspage->output_html(); - - echo '
'; - - echo '
'; - echo ''; - -} else { - if ($PAGE->user_allowed_editing()) { - $url = clone($PAGE->url); - if ($PAGE->user_is_editing()) { - $caption = get_string('blockseditoff'); - $url->param('adminedit', 'off'); - } else { - $caption = get_string('blocksediton'); - $url->param('adminedit', 'on'); - } - $buttons = $OUTPUT->single_button($url, $caption, 'get'); - } - - $PAGE->set_title("$SITE->shortname: " . get_string('toolsetup', 'lti')); - - $PAGE->navbar->add('Basic LTI Administration', $CFG->wwwroot.'/admin/settings.php?section=modsettinglti'); - - echo $OUTPUT->header(); - - if ($errormsg !== '') { - echo $OUTPUT->notification($errormsg); - - } else if ($statusmsg !== '') { - echo $OUTPUT->notification($statusmsg, 'notifysuccess'); - } - - // --------------------------------------------------------------------------------------------------------------- - echo $OUTPUT->heading(get_string('toolsetup', 'lti')); - echo $OUTPUT->box_start('generalbox'); - if ($action == 'add') { - $form = new mod_lti_edit_types_form(); - $form->display(); - } else if ($action == 'update') { - $form = new mod_lti_edit_types_form('typessettings.php?id='.$id); - $type = lti_get_type_type_config($id); - $form->set_data($type); - $form->display(); - } - - echo $OUTPUT->box_end(); -} - -echo $OUTPUT->footer(); +. + +/** + * This file contains the script used to clone Moodle admin setting page. + * It is used to create a new form used to pre-configure basiclti + * activities + * + * @package lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once('../../config.php'); +require_once($CFG->libdir.'/adminlib.php'); +require_once($CFG->dirroot.'/mod/lti/edit_form.php'); +require_once($CFG->dirroot.'/mod/lti/locallib.php'); + +$section = 'modsettinglti'; +$return = optional_param('return', '', PARAM_ALPHA); +$adminediting = optional_param('adminedit', -1, PARAM_BOOL); +$action = optional_param('action', null, PARAM_TEXT); +$id = optional_param('id', null, PARAM_INT); +$useexisting = optional_param('useexisting', null, PARAM_INT); +$definenew = optional_param('definenew', null, PARAM_INT); + +/// no guest autologin +require_login(0, false); +$url = new moodle_url('/mod/lti/typesettings.php'); +$PAGE->set_url($url); + +admin_externalpage_setup('managemodules'); // Hacky solution for printing the admin page + +$tab = optional_param('tab', '', PARAM_ALPHAEXT); +$redirect = "$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti&tab={$tab}"; + +/// WRITING SUBMITTED DATA (IF ANY) ------------------------------------------------------------------------------- + +$statusmsg = ''; +$errormsg = ''; +$focus = ''; + +$data = data_submitted(); + +if (confirm_sesskey() && isset($data->submitbutton)) { + $type = new stdClass(); + + if (isset($id)) { + $type->id = $id; + + lti_update_type($type, $data); + + redirect($redirect); + die; + } else { + $type->state = LTI_TOOL_STATE_CONFIGURED; + + lti_add_type($type, $data); + + redirect($redirect); + die; + } +} else if(isset($data->cancel)){ + redirect($redirect); + die; +} + +if ($action == 'accept') { + lti_set_state_for_type($id, LTI_TOOL_STATE_CONFIGURED); + redirect($redirect); + die; +} + +if ($action == 'reject') { + lti_set_state_for_type($id, LTI_TOOL_STATE_REJECTED); + redirect($redirect); + die; +} + +if ($action == 'delete') { + lti_delete_type($id); + redirect($redirect); + die; +} + +/// print header stuff ------------------------------------------------------------ +$PAGE->set_focuscontrol($focus); +if (empty($SITE->fullname)) { + $PAGE->set_title($settingspage->visiblename); + $PAGE->set_heading($settingspage->visiblename); + + $PAGE->navbar->add('Basic LTI Administration', $CFG->wwwroot.'/admin/settings.php?section=modsettinglti'); + + echo $OUTPUT->header(); + + echo $OUTPUT->box(get_string('configintrosite', 'admin')); + + if ($errormsg !== '') { + echo $OUTPUT->notification($errormsg); + + } else if ($statusmsg !== '') { + echo $OUTPUT->notification($statusmsg, 'notifysuccess'); + } + + // --------------------------------------------------------------------------------------------------------------- + + echo '
'; + echo '
'; + echo html_writer::input_hidden_params($PAGE->url); + echo ''; + echo ''; + + echo $settingspage->output_html(); + + echo '
'; + + echo '
'; + echo '
'; + +} else { + if ($PAGE->user_allowed_editing()) { + $url = clone($PAGE->url); + if ($PAGE->user_is_editing()) { + $caption = get_string('blockseditoff'); + $url->param('adminedit', 'off'); + } else { + $caption = get_string('blocksediton'); + $url->param('adminedit', 'on'); + } + $buttons = $OUTPUT->single_button($url, $caption, 'get'); + } + + $PAGE->set_title("$SITE->shortname: " . get_string('toolsetup', 'lti')); + + $PAGE->navbar->add('Basic LTI Administration', $CFG->wwwroot.'/admin/settings.php?section=modsettinglti'); + + echo $OUTPUT->header(); + + if ($errormsg !== '') { + echo $OUTPUT->notification($errormsg); + + } else if ($statusmsg !== '') { + echo $OUTPUT->notification($statusmsg, 'notifysuccess'); + } + + // --------------------------------------------------------------------------------------------------------------- + echo $OUTPUT->heading(get_string('toolsetup', 'lti')); + echo $OUTPUT->box_start('generalbox'); + if ($action == 'add') { + $form = new mod_lti_edit_types_form(null, (object)array('isadmin' => true)); + $form->display(); + } else if ($action == 'update') { + $form = new mod_lti_edit_types_form('typessettings.php?id='.$id, (object)array('isadmin' => true)); + $type = lti_get_type_type_config($id); + $form->set_data($type); + $form->display(); + } + + echo $OUTPUT->box_end(); +} + +echo $OUTPUT->footer(); From b69dc429519e0b01271c3a47139c2b65f5d27cb4 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Fri, 16 Sep 2011 18:43:01 -0400 Subject: [PATCH 19/78] Fixing a couple issues with grade receipt --- mod/lti/locallib.php | 2 +- mod/lti/service.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index 33051c70fbf..f1e07318ec6 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -422,7 +422,7 @@ function lti_get_domain_from_url($url){ } function lti_get_tool_by_url_match($url, $courseid = null, $state = LTI_TOOL_STATE_CONFIGURED){ - $possibletools = lti_get_tools_by_url($url, $courseid, $state); + $possibletools = lti_get_tools_by_url($url, $state, $courseid); return lti_get_best_tool_by_url($url, $possibletools); } diff --git a/mod/lti/service.php b/mod/lti/service.php index 0512a755464..3dcb89052b5 100644 --- a/mod/lti/service.php +++ b/mod/lti/service.php @@ -82,8 +82,8 @@ switch($messagetype){ } -echo print_r(apache_request_headers(), true); +//echo print_r(apache_request_headers(), true); -echo '
'; +//echo '
'; -echo file_get_contents("php://input"); \ No newline at end of file +//echo file_get_contents("php://input"); \ No newline at end of file From 6831c7cd4ba0f6acb883859f3268950a788ad982 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Mon, 19 Sep 2011 16:26:20 -0400 Subject: [PATCH 20/78] LTI plugin updates. Finishing support of course level plugins. --- mod/lti/ajax.php | 30 +++ mod/lti/edit_form.php | 2 + mod/lti/instructor_edit_tool_type.php | 14 +- mod/lti/lang/en/lti.php | 10 +- mod/lti/locallib.php | 18 +- mod/lti/mod_form.js | 367 ++++++++++++++++++-------- mod/lti/mod_form.php | 27 +- mod/lti/settings.php | 6 +- 8 files changed, 339 insertions(+), 135 deletions(-) create mode 100644 mod/lti/ajax.php diff --git a/mod/lti/ajax.php b/mod/lti/ajax.php new file mode 100644 index 00000000000..54eac007929 --- /dev/null +++ b/mod/lti/ajax.php @@ -0,0 +1,30 @@ +dirroot . '/mod/lti/locallib.php'); + +$courseid = required_param('course', PARAM_INT); + +require_login($courseid, false); + +$action = required_param('action', PARAM_TEXT); + +$response = new stdClass(); + +switch($action){ + case 'find_tool_config': + $toolurl = required_param('toolurl', PARAM_RAW); + + $tool = lti_get_tool_by_url_match($toolurl, $courseid); + + if(!empty($tool)){ + $response->toolid = $tool->id; + $response->toolname = htmlspecialchars($tool->name); + } + + break; +} + +echo json_encode($response); + +die; \ No newline at end of file diff --git a/mod/lti/edit_form.php b/mod/lti/edit_form.php index 991f9865974..cf28c1b1dc0 100644 --- a/mod/lti/edit_form.php +++ b/mod/lti/edit_form.php @@ -84,6 +84,8 @@ class mod_lti_edit_types_form extends moodleform{ $mform->addElement('hidden', 'lti_coursevisible', '1'); } + $mform->addElement('hidden', 'typeid'); + $launchoptions=array(); $launchoptions[LTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'lti'); $launchoptions[LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'lti'); diff --git a/mod/lti/instructor_edit_tool_type.php b/mod/lti/instructor_edit_tool_type.php index b32a8a56fc6..7680a4856be 100644 --- a/mod/lti/instructor_edit_tool_type.php +++ b/mod/lti/instructor_edit_tool_type.php @@ -28,18 +28,23 @@ $data = data_submitted(); if (confirm_sesskey() && isset($data->submitbutton)) { $type = new stdClass(); - if (isset($id)) { - /*$type->id = $id; + if (!empty($typeid)) { + $type->id = $typeid; + $name = json_encode($data->lti_typename); lti_update_type($type, $data); + + //Output script to update the calling window. $script = << -SCRIPT;*/ +SCRIPT; + echo $script; + die; } else { $type->state = LTI_TOOL_STATE_CONFIGURED; @@ -48,6 +53,7 @@ SCRIPT;*/ $id = lti_add_type($type, $data); $name = json_encode($type->name); + //Output script to update the calling window. $script = << @@ -51,12 +54,14 @@ SCRIPT; $type->course = $COURSE->id; $id = lti_add_type($type, $data); - $name = json_encode($type->name); + + $fromdb = lti_get_type($id); + $json = json_encode($fromdb); //Output script to update the calling window. $script = << diff --git a/mod/lti/lang/en/lti.php b/mod/lti/lang/en/lti.php index b949b38761d..67950ff15c7 100644 --- a/mod/lti/lang/en/lti.php +++ b/mod/lti/lang/en/lti.php @@ -201,4 +201,9 @@ $string['delete_confirmation'] = 'Are you sure you want to delete this external $string['cannot_edit'] = 'You may not edit this tool configuration.'; $string['cannot_delete'] = 'You may not delete this tool configuration.'; $string['global_tool_types'] = 'Global tool types'; -$string['course_tool_types'] = 'Course tool types'; \ No newline at end of file +$string['course_tool_types'] = 'Course tool types'; + +$string['using_tool_configuration'] = 'Using tool configuration: '; +$string['domain_mismatch'] = 'Launch URL\'s domain does not match tool configuration.'; +$string['custom_config'] = 'Using custom tool configuration.'; +$string['tool_config_not_found'] = 'Tool configuration not found for this URL.'; \ No newline at end of file diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index c4790e99643..3dca134e163 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -410,7 +410,7 @@ QUERY; $types[0] = (object)array('name' => get_string('automatic', 'lti'), 'course' => $SITE->id); foreach($admintypes as $type) { - $types[$type->id] = (object)array('name' => $type->name, 'course' => $type->course); + $types[$type->id] = $type; } return $types; diff --git a/mod/lti/mod_form.js b/mod/lti/mod_form.js index 7569629f880..edd394d525b 100644 --- a/mod/lti/mod_form.js +++ b/mod/lti/mod_form.js @@ -1,6 +1,5 @@ (function(){ var Y; - var self; M.mod_lti = M.mod_lti || {}; @@ -10,7 +9,7 @@ Y = yui3; } - self = this; + var self = this; this.settings = Y.JSON.parse(settings); this.urlCache = {}; @@ -47,7 +46,13 @@ self.updateAutomaticToolMatch(); }, + clearToolCache: function(){ + this.urlCache = {}; + }, + updateAutomaticToolMatch: function(){ + var self = this; + var toolurl = Y.one('#id_toolurl'); var typeSelector = Y.one('#id_typeid'); var automatchToolDisplay = Y.one('#lti_automatch_tool'); @@ -62,8 +67,29 @@ var url = toolurl.get('value'); - if(!url || typeSelector.get('value') > 0){ + //Hide the display if the url box is empty + if(!url){ automatchToolDisplay.setStyle('display', 'none'); + } else { + automatchToolDisplay.set('innerHTML', ''); + automatchToolDisplay.setStyle('display', ''); + } + + var selectedToolType = typeSelector.get('value'); + var selectedOption = typeSelector.one('option[value=' + selectedToolType + ']'); + + //A specific tool type is selected (not "auto")" + if(selectedToolType > 0){ + //If the entered domain matches the domain of the tool configuration... + var domainRegex = /(?:https?:\/\/)?(?:www\.)?([^\/]+)(?:\/|$)/i; + var match = domainRegex.exec(url); + if(match && match[1] && match[1].toLowerCase() === selectedOption.getAttribute('domain').toLowerCase()){ + automatchToolDisplay.set('innerHTML', '' + M.str.lti.using_tool_configuration + selectedOption.get('text')); + } else { + //The entered URL does not match the domain of the tool configuration + automatchToolDisplay.set('innerHTML', '' + M.str.lti.domain_mismatch); + } + return; } @@ -72,17 +98,15 @@ //We don't care what tool type this tool is associated with if it's manually configured' if(key.get('value') !== '' && secret.get('value') !== ''){ - automatchToolDisplay.set('innerHTML', 'Using custom tool configuration.'); + automatchToolDisplay.set('innerHTML', '' + M.str.lti.custom_config); } else { var continuation = function(toolInfo){ - automatchToolDisplay.setStyle('display', ''); - if(toolInfo.toolname){ - automatchToolDisplay.set('innerHTML', 'Using tool configuration: ' + toolInfo.toolname); + automatchToolDisplay.set('innerHTML', '' + M.str.lti.using_tool_configuration + toolInfo.toolname); } else { //Inform them custom configuration is in use if(key.get('value') === '' || secret.get('value') === ''){ - automatchToolDisplay.set('innerHTML', 'Tool configuration not found for this URL.'); + automatchToolDisplay.set('innerHTML', '' + M.str.lti.tool_config_not_found); } } }; @@ -147,6 +171,8 @@ * Javascript is a requirement to edit course level tools at this point. */ createTypeEditorButtons: function(){ + var self = this; + var typeSelector = Y.one('#id_typeid'); var createIcon = function(id, tooltip, iconUrl){ @@ -181,17 +207,7 @@ if(self.getSelectedToolTypeOption().getAttribute('editable')){ if(confirm(M.str.lti.delete_confirmation)){ - - Y.io(self.settings.instructor_tool_type_edit_url + '&action=delete&typeid=' + toolTypeId, { - on: { - success: function(){ - self.getSelectedToolTypeOption().remove(); - }, - failure: function(){ - - } - } - }); + self.deleteTool(toolTypeId); } } else { alert(M.str.lti.cannot_delete); @@ -218,34 +234,65 @@ } }, - addToolType: function(text, value){ + addToolType: function(toolType){ var typeSelector = Y.one('#id_typeid'); var course_tool_group = Y.one('#course_tool_group'); var option = Y.Node.create('
\ No newline at end of file diff --git a/mod/lti/submissions.php b/mod/lti/grade.php similarity index 63% rename from mod/lti/submissions.php rename to mod/lti/grade.php index 8482181d017..866fe193252 100644 --- a/mod/lti/submissions.php +++ b/mod/lti/grade.php @@ -89,4 +89,96 @@ require_login($course, false, $cm); require_capability('mod/lti:grade', get_context_instance(CONTEXT_MODULE, $cm->id)); -lti_submissions($cm, $course, $basiclti, $mode); // Display or process the submissions +//lti_submissions($cm, $course, $basiclti, $mode); // Display or process the submissions + +$module = array( + 'name' => 'mod_lti_submissions', + 'fullpath' => '/mod/lti/submissions.js', + 'requires' => array('base'), + 'strings' => array( + + ), +); + +$PAGE->requires->js_init_call('M.mod_lti.submissions.init', array(), true, $module); + +$PAGE->requires->yui2_lib('datatable'); + +$submissionquery = <<get_records_sql($submissionquery, array('ltiid' => $basiclti->id)); + +$html = << + + + + + +HTML; + +$rowtemplate = << + + + + + + + + + + +HTML; + +$rows = ''; + +foreach($submissions as $submission){ + $row = $rowtemplate; + + foreach($submission as $key => $value){ + if($key === 'datesubmitted'){ + $value = userdate($value); + } + + $row = str_replace('', $value, $row); + } + + $rows .= $row; +} + +$table = str_replace('', $rows, $html); + +$title = 'Submissions for ' . $basiclti->name; + +$PAGE->set_title(format_string($title , true)); +$PAGE->set_heading($course->fullname); + +echo $OUTPUT->header(); +echo $OUTPUT->heading($title ); + +echo $table; + +echo $OUTPUT->footer(); \ No newline at end of file diff --git a/mod/lti/lib.php b/mod/lti/lib.php index c1ee7c611e7..30fc958e2ca 100644 --- a/mod/lti/lib.php +++ b/mod/lti/lib.php @@ -315,652 +315,6 @@ function lti_get_lti_types() { return $DB->get_records('lti_types'); } -/** - * Returns Basic LTI types configuration - * - * @return array of basicLTI types - */ -/*function lti_get_types() { - $types = array(); - - $basicltitypes = lti_get_lti_types(); - if (!empty($basicltitypes)) { - foreach ($basicltitypes as $basicltitype) { - $ltitypesconfig = lti_get_type_config($basicltitype->id); - - $modclass = MOD_CLASS_ACTIVITY; - if (isset($ltitypesconfig['module_class_type'])) { - if ($ltitypesconfig['module_class_type']=='1') { - $modclass = MOD_CLASS_RESOURCE; - } - } - - $type = new object(); - $type->modclass = $modclass; - $type->type = 'lti&type='.urlencode($basicltitype->rawname); - $type->typestr = $basicltitype->name; - $types[] = $type; - } - } - - return $types; -}*/ - -////////////////////////////////////////////////////////////////////////////////////// -/// Any other basiclti functions go here. Each of them must have a name that -/// starts with basiclti_ -/// Remember (see note in first lines) that, if this section grows, it's HIGHLY -/// recommended to move all funcions below to a new "localib.php" file. - -///** -// * -// */ -//function process_outcomes($userid, $course, $basiclti) { -// global $CFG, $USER; -// -// if (empty($CFG->enableoutcomes)) { -// return; -// } -// -// require_once($CFG->libdir.'/gradelib.php'); -// -// if (!$formdata = data_submitted() or !confirm_sesskey()) { -// return; -// } -// -// $data = array(); -// $grading_info = grade_get_grades($course->id, 'mod', 'basiclti', $basiclti->id, $userid); -// -// if (!empty($grading_info->outcomes)) { -// foreach ($grading_info->outcomes as $n => $old) { -// $name = 'outcome_'.$n; -// if (isset($formdata->{$name}[$userid]) and $old->grades[$userid]->grade != $formdata->{$name}[$userid]) { -// $data[$n] = $formdata->{$name}[$userid]; -// } -// } -// } -// if (count($data) > 0) { -// grade_update_outcomes('mod/basiclti', $course->id, 'mod', 'basiclti', $basiclti->id, $userid, $data); -// } -// -//} - -/** - * Top-level function for handling of submissions called by submissions.php - * - * This is for handling the teacher interaction with the grading interface - * - * @global object - * @param string $mode Specifies the kind of teacher interaction taking place - */ -function lti_submissions($cm, $course, $basiclti, $mode) { - ///The main switch is changed to facilitate - ///1) Batch fast grading - ///2) Skip to the next one on the popup - ///3) Save and Skip to the next one on the popup - - //make user global so we can use the id - global $USER, $OUTPUT, $DB; - - $mailinfo = optional_param('mailinfo', null, PARAM_BOOL); - - if (optional_param('next', null, PARAM_BOOL)) { - $mode='next'; - } - if (optional_param('saveandnext', null, PARAM_BOOL)) { - $mode='saveandnext'; - } - - if (is_null($mailinfo)) { - if (optional_param('sesskey', null, PARAM_BOOL)) { - set_user_preference('lti_mailinfo', $mailinfo); - } else { - $mailinfo = get_user_preferences('lti_mailinfo', 0); - } - } else { - set_user_preference('lti_mailinfo', $mailinfo); - } - - switch ($mode) { - case 'grade': // We are in a main window grading - if ($submission = process_feedback()) { - lti_display_submissions($cm, $course, $basiclti, get_string('changessaved')); - } else { - lti_display_submissions($cm, $course, $basiclti); - } - break; - - case 'single': // We are in a main window displaying one submission - if ($submission = process_feedback()) { - lti_display_submissions($cm, $course, $basiclti, get_string('changessaved')); - } else { - display_submission(); - } - break; - - case 'all': // Main window, display everything - lti_display_submissions($cm, $course, $basiclti); - break; - - case 'fastgrade': - /// do the fast grading stuff - this process should work for all 3 subclasses - $grading = false; - $commenting = false; - $col = false; - if (isset($_POST['submissioncomment'])) { - $col = 'submissioncomment'; - $commenting = true; - } - if (isset($_POST['menu'])) { - $col = 'menu'; - $grading = true; - } - if (!$col) { - //both submissioncomment and grade columns collapsed.. - lti_display_submissions($cm, $course, $basiclti); - break; - } - - foreach ($_POST[$col] as $id => $unusedvalue) { - - $id = (int)$id; //clean parameter name - - // Get grade item - $gradeitem = $DB->get_record('grade_items', array('courseid' => $cm->course, 'iteminstance' => $cm->instance)); - - // Get grade - $gradeentry = $DB->get_record('grade_grades', array('userid' => $id, 'itemid' => $gradeitem->id)); - - $grade = $_POST['menu'][$id]; - $feedback = trim($_POST['submissioncomment'][$id]); - - if ((!$gradeentry) && (($grade != '-1') || ($feedback != ''))) { - $newsubmission = true; - } else { - $newsubmission = false; - } - - //for fast grade, we need to check if any changes take place - $updatedb = false; - - if ($gradeentry) { - if ($grading) { - $grade = $_POST['menu'][$id]; - $updatedb = $updatedb || (($gradeentry->rawgrade != $grade) && ($gradeentry->rawgrade != '-1')); - if ($grade != '-1') { - $gradeentry->rawgrade = $grade; - $gradeentry->finalgrade = $grade; - } else { - $gradeentry->rawgrade = null; - $gradeentry->finalgrade = null; - } - } else { - if (!$newsubmission) { - unset($gradeentry->rawgrade); // Don't need to update this. - } - } - - if ($commenting) { - $commentvalue = trim($_POST['submissioncomment'][$id]); - $updatedb = $updatedb || ($gradeentry->feedback != $commentvalue); - // Special case - if (($gradeentry->feedback == null) && ($commentvalue == "")) { - unset($gradeentry->feedback); - } - $gradeentry->feedback = $commentvalue; - } else { - unset($gradeentry->feedback); // Don't need to update this. - } - - } else { // No previous grade entry found - if ($newsubmission) { - if ($grade != '-1') { - $gradeentry->rawgrade = $grade; - $updatedb = true; - } - if ($feedback != '') { - $gradeentry->feedback = $feedback; - $updatedb = true; - } - } - } - - $gradeentry->usermodified = $USER->id; - if (!$gradeentry->timecreated) { - $gradeentry->timecreated = time(); - } - $gradeentry->timemodified = time(); - - //if it is not an update, we don't change the last modified time etc. - //this will also not write into database if no submissioncomment and grade is entered. - if ($updatedb) { - if ($gradeentry->rawgrade == '-1') { - $gradeentry->rawgrade = null; - } - - if ($newsubmission) { - if (!isset($gradeentry->feedback)) { - $gradeentry->feedback = ''; - } - $gradeentry->itemid = $gradeitem->id; - $gradeentry->userid = $id; - $sid = $DB->insert_record("grade_grades", $gradeentry); - $gradeentry->id = $sid; - } else { - $DB->update_record("grade_grades", $gradeentry); - } - - //add to log only if updating - add_to_log($course->id, 'lti', 'update grades', - 'submissions.php?id='.$cm->id.'&user='.$USER->id, - $USER->id, $cm->id); - } - - } - - $message = $OUTPUT->notification(get_string('changessaved'), 'notifysuccess'); - - lti_display_submissions($cm, $course, $basiclti, $message); - break; - - case 'saveandnext': - ///We are in pop up. save the current one and go to the next one. - //first we save the current changes - if ($submission = process_feedback()) { - //print_heading(get_string('changessaved')); - //$extra_javascript = $this->update_main_listing($submission); - } - - case 'next': - /// We are currently in pop up, but we want to skip to next one without saving. - /// This turns out to be similar to a single case - /// The URL used is for the next submission. - $offset = required_param('offset', PARAM_INT); - $nextid = required_param('nextid', PARAM_INT); - $id = required_param('id', PARAM_INT); - $offset = (int)$offset+1; - //$this->display_submission($offset+1 , $nextid); - redirect('submissions.php?id='.$id.'&userid='. $nextid . '&mode=single&offset='.$offset); - break; - - case 'singlenosave': - display_submission(); - break; - - default: - echo "Critical error. Something is seriously wrong!!"; - break; - } -} - -/** - * Display all the submissions ready for grading - * - * @global object - * @global object - * @global object - * @global object - * @param string $message - * @return bool|void - */ -function lti_display_submissions($cm, $course, $basiclti, $message='') { - global $CFG, $DB, $OUTPUT, $PAGE; - require_once($CFG->libdir.'/gradelib.php'); - - /* first we check to see if the form has just been submitted - * to request user_preference updates - */ - $updatepref = optional_param('updatepref', 0, PARAM_INT); - - if (isset($_POST['updatepref'])) { - $perpage = optional_param('perpage', 10, PARAM_INT); - $perpage = ($perpage <= 0) ? 10 : $perpage; - $filter = optional_param('filter', 0, PARAM_INT); - set_user_preference('lti_perpage', $perpage); - set_user_preference('lti_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL)); - set_user_preference('lti_filter', $filter); - } - - /* next we get perpage and quickgrade (allow quick grade) params - * from database - */ - $perpage = get_user_preferences('lti_perpage', 10); - $quickgrade = get_user_preferences('lti_quickgrade', 0); - $filter = get_user_preferences('lti_filter', 0); - $grading_info = grade_get_grades($course->id, 'mod', 'lti', $basiclti->id); - - if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) { - $uses_outcomes = true; - } else { - $uses_outcomes = false; - } - - $page = optional_param('page', 0, PARAM_INT); - $strsaveallfeedback = get_string('saveallfeedback', 'lti'); - - $tabindex = 1; //tabindex for quick grading tabbing; Not working for dropdowns yet - add_to_log($course->id, 'lti', 'view submission', 'submissions.php?id='.$cm->id, $basiclti->id, $cm->id); - - $PAGE->set_title(format_string($basiclti->name, true)); - $PAGE->set_heading($course->fullname); - echo $OUTPUT->header(); - - echo '
'; - - //hook to allow plagiarism plugins to update status/print links. - plagiarism_update_status($course, $cm); - - /// Print quickgrade form around the table - if ($quickgrade) { - $formattrs = array(); - $formattrs['action'] = new moodle_url('/mod/lti/submissions.php'); - $formattrs['id'] = 'fastg'; - $formattrs['method'] = 'post'; - - echo html_writer::start_tag('form', $formattrs); - echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=> $cm->id)); - echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'mode', 'value'=> 'fastgrade')); - echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'page', 'value'=> $page)); - echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=> sesskey())); - } - - $course_context = get_context_instance(CONTEXT_COURSE, $course->id); - if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) { - echo ''; - } - - if (!empty($message)) { - echo $message; // display messages here if any - } - - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - -/// Check to see if groups are being used in this tool - - /// find out current groups mode - $groupmode = groups_get_activity_groupmode($cm); - $currentgroup = groups_get_activity_group($cm, true); - groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/lti/submissions.php?id=' . $cm->id); - - /// Get all ppl that are allowed to submit tools - list($esql, $params) = get_enrolled_sql($context, 'mod/lti:view', $currentgroup); - - $sql = "SELECT u.id FROM {user} u ". - "LEFT JOIN ($esql) eu ON eu.id=u.id ". - "WHERE u.deleted = 0 AND eu.id=u.id "; - - $users = $DB->get_records_sql($sql, $params); - if (!empty($users)) { - $users = array_keys($users); - } - - // if groupmembersonly used, remove users who are not in any group - if ($users and !empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) { - if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) { - $users = array_intersect($users, array_keys($groupingusers)); - } - } - - $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade'); - if ($uses_outcomes) { - $tablecolumns[] = 'outcome'; // no sorting based on outcomes column - } - - $tableheaders = array('', - get_string('fullname'), - get_string('grade'), - get_string('comment', 'lti'), - get_string('lastmodified').' ('.get_string('submission', 'lti').')', - get_string('lastmodified').' ('.get_string('grade').')', - get_string('status'), - get_string('finalgrade', 'grades')); - if ($uses_outcomes) { - $tableheaders[] = get_string('outcome', 'grades'); - } - - require_once($CFG->libdir.'/tablelib.php'); - $table = new flexible_table('mod-lti-submissions'); - - $table->define_columns($tablecolumns); - $table->define_headers($tableheaders); - $table->define_baseurl($CFG->wwwroot.'/mod/lti/submissions.php?id='.$cm->id.'&currentgroup='.$currentgroup); - - $table->sortable(true, 'lastname');//sorted by lastname by default - $table->collapsible(true); - $table->initialbars(true); - - $table->column_suppress('picture'); - $table->column_suppress('fullname'); - - $table->column_class('picture', 'picture'); - $table->column_class('fullname', 'fullname'); - $table->column_class('grade', 'grade'); - $table->column_class('submissioncomment', 'comment'); - $table->column_class('timemodified', 'timemodified'); - $table->column_class('timemarked', 'timemarked'); - $table->column_class('status', 'status'); - $table->column_class('finalgrade', 'finalgrade'); - if ($uses_outcomes) { - $table->column_class('outcome', 'outcome'); - } - - $table->set_attribute('cellspacing', '0'); - $table->set_attribute('id', 'attempts'); - $table->set_attribute('class', 'submissions'); - $table->set_attribute('width', '100%'); - - $table->no_sorting('finalgrade'); - $table->no_sorting('outcome'); - - // Start working -- this is necessary as soon as the niceties are over - $table->setup(); - - if (empty($users)) { - echo $OUTPUT->heading(get_string('noviewusers', 'lti')); - echo '
'; - return true; - } - - /// Construct the SQL - list($where, $params) = $table->get_sql_where(); - if ($where) { - $where .= ' AND '; - } - - if ($sort = $table->get_sql_sort()) { - $sort = ' ORDER BY '.$sort; - } - - $ufields = user_picture::fields('u'); - - $gradeitem = $DB->get_record('grade_items', array('courseid' => $cm->course, 'iteminstance' => $cm->instance)); - - $select = "SELECT $ufields, - g.rawgrade, g.feedback, - g.timemodified, g.timecreated "; - - $sql = 'FROM {user} u'. - ' LEFT JOIN {grade_grades} g ON u.id = g.userid AND g.itemid = '.$gradeitem->id. - ' LEFT JOIN {grade_items} i ON g.itemid = i.id'. - ' AND i.iteminstance = '.$basiclti->id. - ' WHERE '.$where.'u.id IN ('.implode(',', $users).') '; - - $ausers = $DB->get_records_sql($select.$sql.$sort, $params, $table->get_page_start(), $table->get_page_size()); - - $table->pagesize($perpage, count($users)); - - ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next - $offset = $page * $perpage; - $strupdate = get_string('update'); - $strgrade = get_string('grade'); - $grademenu = make_grades_menu($basiclti->grade); - if ($ausers !== false) { - $grading_info = grade_get_grades($course->id, 'mod', 'lti', $basiclti->id, array_keys($ausers)); - $endposition = $offset + $perpage; - $currentposition = 0; - foreach ($ausers as $auser) { - - if ($auser->timemodified > 0) { - $timemodified = '
'.userdate($auser->timemodified).'
'; - } else { - $timemodified = '
 
'; - } - if ($auser->timecreated > 0) { - $timecreated = '
'.userdate($auser->timecreated).'
'; - } else { - $timecreated = '
 
'; - } - - if ($currentposition == $offset && $offset < $endposition) { - $final_grade = $grading_info->items[0]->grades[$auser->id]; - $grademax = $grading_info->items[0]->grademax; - $final_grade->formatted_grade = round($final_grade->grade, 2) .' / ' . round($grademax, 2); - $locked_overridden = 'locked'; - if ($final_grade->overridden) { - $locked_overridden = 'overridden'; - } - - /// Calculate user status - $picture = $OUTPUT->user_picture($auser); - - $studentmodified = '
 
'; - $teachermodified = '
 
'; - $status = '
 
'; - - if ($final_grade->locked or $final_grade->overridden) { - $grade = '
'.$final_grade->formatted_grade . '
'; - } else if ($quickgrade) { // allow editing - $attributes = array(); - $attributes['tabindex'] = $tabindex++; - if ($auser->rawgrade != "") { - $menu = html_writer::select(make_grades_menu($basiclti->grade), 'menu['.$auser->id.']', round($auser->rawgrade, 0), array(-1=>get_string('nograde')), $attributes); - } else { - $menu = html_writer::select(make_grades_menu($basiclti->grade), 'menu['.$auser->id.']', -1, array(-1=>get_string('nograde')), $attributes); - } - $grade = '
'.$menu.'
'; - } else if ($final_grade->grade) { - if ($auser->rawgrade != "") { - $grade = '
'.$final_grade->formatted_grade.'
'; - } else { - $grade = '
-1
'; - } - - } else { - $grade = '
No Grade
'; - } - - if ($final_grade->locked or $final_grade->overridden) { - $comment = '
'.$final_grade->str_feedback.'
'; - } else if ($quickgrade) { - $comment = '
' - . '
'; - } else { - $comment = '
'.shorten_text(strip_tags($auser->feedback), 15).'
'; - } - - if (empty($auser->status)) { /// Confirm we have exclusively 0 or 1 - $auser->status = 0; - } else { - $auser->status = 1; - } - - $buttontext = ($auser->status == 1) ? $strupdate : $strgrade; - - ///No more buttons, we use popups ;-). - $popup_url = '/mod/lti/submissions.php?id='.$cm->id - . '&userid='.$auser->id.'&mode=single'.'&filter='.$filter.'&offset='.$offset++; - - $button = $OUTPUT->action_link($popup_url, $buttontext); - - $status = '
'.$button.'
'; - - $finalgrade = ''.$final_grade->str_grade.''; - - $outcomes = ''; - - if ($uses_outcomes) { - - foreach ($grading_info->outcomes as $n => $outcome) { - $outcomes .= '
'; - $options = make_grades_menu(-$outcome->scaleid); - - if ($outcome->grades[$auser->id]->locked or !$quickgrade) { - $options[0] = get_string('nooutcome', 'grades'); - $outcomes .= ': '.$options[$outcome->grades[$auser->id]->grade].''; - } else { - $attributes = array(); - $attributes['tabindex'] = $tabindex++; - $attributes['id'] = 'outcome_'.$n.'_'.$auser->id; - $outcomes .= ' '.html_writer::select($options, 'outcome_'.$n.'['.$auser->id.']', $outcome->grades[$auser->id]->grade, array(0=>get_string('nooutcome', 'grades')), $attributes); - } - $outcomes .= '
'; - } - } - - $userlink = '' . fullname($auser, has_capability('moodle/site:viewfullnames', $context)) . ''; - $row = array($picture, $userlink, $grade, $comment, $timemodified, $timecreated, $status, $finalgrade); - if ($uses_outcomes) { - $row[] = $outcomes; - } - - $table->add_data($row); - } - $currentposition++; - } - } - - $table->print_html(); /// Print the whole table - - /// Print quickgrade form around the table - if ($quickgrade && $table->started_output) { - $mailinfopref = false; - if (get_user_preferences('lti_mailinfo', 1)) { - $mailinfopref = true; - } - $emailnotification = html_writer::checkbox('mailinfo', 1, $mailinfopref, get_string('enableemailnotification', 'lti')); - - $emailnotification .= $OUTPUT->help_icon('enableemailnotification', 'lti'); - echo html_writer::tag('div', $emailnotification, array('class'=>'emailnotification')); - - $savefeedback = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'fastg', 'value'=>get_string('saveallfeedback', 'lti'))); - echo html_writer::tag('div', $savefeedback, array('class'=>'fastgbutton')); - - echo html_writer::end_tag('form'); - } else if ($quickgrade) { - echo html_writer::end_tag('form'); - } - - echo ''; - /// End of fast grading form - - /// Mini form for setting user preference - - $formaction = new moodle_url('/mod/lti/submissions.php', array('id'=>$cm->id)); - $mform = new MoodleQuickForm('optionspref', 'post', $formaction, '', array('class'=>'optionspref')); - - $mform->addElement('hidden', 'updatepref'); - $mform->setDefault('updatepref', 1); - $mform->addElement('header', 'qgprefs', get_string('optionalsettings', 'lti')); -// $mform->addElement('select', 'filter', get_string('show'), $filters); - - $mform->setDefault('filter', $filter); - - $mform->addElement('text', 'perpage', get_string('pagesize', 'lti'), array('size'=>1)); - $mform->setDefault('perpage', $perpage); - - $mform->addElement('checkbox', 'quickgrade', get_string('quickgrade', 'lti')); - $mform->setDefault('quickgrade', $quickgrade); - $mform->addHelpButton('quickgrade', 'quickgrade', 'lti'); - - $mform->addElement('submit', 'savepreferences', get_string('savepreferences')); - - $mform->display(); - - echo $OUTPUT->footer(); -} - /** * Create grade item for given basiclti * @@ -1008,3 +362,14 @@ function lti_grade_item_delete($basiclti) { return grade_update('mod/lti', $basiclti->course, 'mod', 'lti', $basiclti->id, 0, null, array('deleted'=>1)); } +function lti_extend_settings_navigation($settings, $parentnode) { + global $PAGE; + + $keys = $parentnode->get_children_key_list(); + + $node = navigation_node::create('Submissions', + new moodle_url('/mod/lti/grade.php', array('id'=>$PAGE->cm->id)), + navigation_node::TYPE_SETTING, null, 'mod_lti_submissions'); + + $parentnode->add_node($node, $keys[1]); +} \ No newline at end of file diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index 60162b3b580..bfb55bce1fe 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -95,6 +95,8 @@ function lti_view($instance, $makeobject=false) { $typeconfig['sendname'] = $instance->instructorchoicesendname; $typeconfig['sendemailaddr'] = $instance->instructorchoicesendemailaddr; $typeconfig['customparameters'] = $instance->instructorcustomparameters; + $typeconfig['acceptgrades'] = $instance->instructorchoiceacceptgrades; + $typeconfig['allowroster'] = $instance->instructorchoiceallowroster; } //Default the organizationid if not specified @@ -131,11 +133,16 @@ function lti_view($instance, $makeobject=false) { echo $content; } -function lti_build_sourcedid($instanceid, $userid, $servicesalt){ +function lti_build_sourcedid($instanceid, $userid, $launchid = null, $servicesalt){ $data = new stdClass(); $data->instanceid = $instanceid; $data->userid = $userid; + if(!empty($launchid)){ + $data->launchid = $launchid; + } else { + $data->launchid = mt_rand(); + } $json = json_encode($data); @@ -183,7 +190,7 @@ function lti_build_request($instance, $typeconfig, $course) { $placementsecret = $instance->servicesalt; if ( isset($placementsecret) ) { - $sourcedid = json_encode(lti_build_sourcedid($instance->id, $USER->id, $placementsecret)); + $sourcedid = json_encode(lti_build_sourcedid($instance->id, $USER->id, null, $placementsecret)); } if ( isset($placementsecret) && @@ -998,44 +1005,6 @@ function lti_post_launch_html($newparms, $endpoint, $debug=false) { return $r; } -/** - * Returns a link with info about the state of the basiclti submissions - * - * This is used by view_header to put this link at the top right of the page. - * For teachers it gives the number of submitted assignments with a link - * For students it gives the time of their submission. - * This will be suitable for most assignment types. - * - * @global object - * @global object - * @param bool $allgroup print all groups info if user can access all groups, suitable for index.php - * @return string - */ -function lti_submittedlink($cm, $allgroups=false) { - global $CFG; - - $submitted = ''; - $urlbase = "{$CFG->wwwroot}/mod/lti/"; - - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - if (has_capability('mod/lti:grade', $context)) { - if ($allgroups and has_capability('moodle/site:accessallgroups', $context)) { - $group = 0; - } else { - $group = groups_get_activity_group($cm); - } - - $submitted = ''. - get_string('viewsubmissions', 'lti').''; - } else { - if (isloggedin()) { - // TODO Insert code for students if needed - } - } - - return $submitted; -} - function lti_get_type($typeid){ global $DB; diff --git a/mod/lti/service.php b/mod/lti/service.php index 3dcb89052b5..9792037675d 100644 --- a/mod/lti/service.php +++ b/mod/lti/service.php @@ -20,7 +20,7 @@ switch($messagetype){ lti_verify_sourcedid($ltiinstance, $parsed); lti_verify_message($ltiinstance, $rawbody); - $gradestatus = lti_update_grade($ltiinstance, $parsed->userid, $parsed->gradeval); + $gradestatus = lti_update_grade($ltiinstance, $parsed->userid, $parsed->launchid, $parsed->gradeval); $responsexml = lti_get_response_xml( $gradestatus ? 'success' : 'error', diff --git a/mod/lti/servicelib.php b/mod/lti/servicelib.php index b3a61682d44..98e352a1a75 100644 --- a/mod/lti/servicelib.php +++ b/mod/lti/servicelib.php @@ -49,6 +49,7 @@ function lti_parse_grade_replace_message($xml){ $parsed->instanceid = $resultjson->data->instanceid; $parsed->userid = $resultjson->data->userid; + $parsed->launchid = $resultjson->data->launchid; $parsed->sourcedidhash = $resultjson->hash; $parsed->messageid = lti_parse_message_id($xml); @@ -63,6 +64,7 @@ function lti_parse_grade_read_message($xml){ $parsed = new stdClass(); $parsed->instanceid = $resultjson->data->instanceid; $parsed->userid = $resultjson->data->userid; + $parsed->launchid = $resultjson->data->launchid; $parsed->sourcedidhash = $resultjson->hash; $parsed->messageid = lti_parse_message_id($xml); @@ -77,6 +79,7 @@ function lti_parse_grade_delete_message($xml){ $parsed = new stdClass(); $parsed->instanceid = $resultjson->data->instanceid; $parsed->userid = $resultjson->data->userid; + $parsed->launchid = $resultjson->data->launchid; $parsed->sourcedidhash = $resultjson->hash; $parsed->messageid = lti_parse_message_id($xml); @@ -84,8 +87,8 @@ function lti_parse_grade_delete_message($xml){ return $parsed; } -function lti_update_grade($ltiinstance, $userid, $gradeval){ - global $CFG; +function lti_update_grade($ltiinstance, $userid, $launchid, $gradeval){ + global $CFG, $DB; require_once($CFG->libdir . '/gradelib.php'); $params = array(); @@ -97,6 +100,33 @@ function lti_update_grade($ltiinstance, $userid, $gradeval){ $status = grade_update(LTI_SOURCE, $ltiinstance->course, LTI_ITEM_TYPE, LTI_ITEM_MODULE, $ltiinstance->id, 0, $grade, $params); + $record = $DB->get_record('lti_submission', array('ltiid' => $ltiinstance->id, 'userid' => $userid, 'launchid' => $launchid), 'id'); + if($record){ + $id = $record->id; + } else { + $id = null; + } + + if(!empty($id)){ + $DB->update_record('lti_submission', array( + 'id' => $id, + 'dateupdated' => time(), + 'gradepercent' => $gradeval, + 'state' => 2 + )); + } else { + $DB->insert_record('lti_submission', array( + 'ltiid' => $ltiinstance->id, + 'userid' => $userid, + 'datesubmitted' => time(), + 'dateupdated' => time(), + 'gradepercent' => $gradeval, + 'originalgrade' => $gradeval, + 'launchid' => $launchid, + 'state' => 1 + )); + } + return $status == GRADE_UPDATE_OK; } @@ -156,7 +186,7 @@ function lti_verify_message($ltiinstance, $body, $headers = null){ } function lti_verify_sourcedid($ltiinstance, $parsed){ - $sourceid = lti_build_sourcedid($parsed->instanceid, $parsed->userid, $ltiinstance->servicesalt); + $sourceid = lti_build_sourcedid($parsed->instanceid, $parsed->userid, $parsed->launchid, $ltiinstance->servicesalt); if($sourceid->hash != $parsed->sourcedidhash){ throw new Exception('SourcedId hash not valid'); diff --git a/mod/lti/submissions.js b/mod/lti/submissions.js new file mode 100644 index 00000000000..03188eef2bf --- /dev/null +++ b/mod/lti/submissions.js @@ -0,0 +1,52 @@ +(function(){ + var Y; + + M.mod_lti = M.mod_lti || {}; + + M.mod_lti.submissions = { + init: function(yui3){ + if(yui3){ + Y = yui3; + } + + this.setupTable(); + + + }, + + setupTable: function(){ + var lti_submissions_table = YAHOO.util.Dom.get('lti_submissions_table'); + + var dataSource = new YAHOO.util.DataSource(lti_submissions_table); + + var configuredColumns = [ + { key: "user", label: "User", sortable:true }, + { key: "date", label: "Submission Date", sortable:true, formatter: 'date' }, + { key: "grade", + label: "Grade", + sortable:true, + formatter: function(cell, record, column, data){ + cell.innerHTML = parseFloat(data).toFixed(1) + '%'; + } + } + ]; + + dataSource.responseType = YAHOO.util.DataSource.TYPE_HTMLTABLE; + dataSource.responseSchema = { + fields: [ + { key: "user" }, + { key: "date", parser: "date" }, + { key: "grade", parser: "number" }, + ] + }; + + new YAHOO.widget.DataTable("lti_submissions_table_container", configuredColumns, dataSource, + { + sortedBy: {key:"date", dir:"desc"} + } + ); + + Y.one('#lti_submissions_table_container').setStyle('display', ''); + } + } +})(); \ No newline at end of file diff --git a/mod/lti/view.php b/mod/lti/view.php index 8b1f559e7bb..ea28f4e1ddb 100644 --- a/mod/lti/view.php +++ b/mod/lti/view.php @@ -122,10 +122,6 @@ if($basiclti->showdescription && $basiclti->intro){ echo $OUTPUT->box($basiclti->intro, 'generalbox description', 'intro'); } -if ($basiclti->instructorchoiceacceptgrades == 1) { - echo ''; -} - if ( $launchcontainer == LTI_LAUNCH_CONTAINER_WINDOW ) { echo " +SCRIPT; + + $clickhere = get_string('return_to_course', 'lti', (object)array('link' => $url)); + + $noscript = << +NOSCRIPT; + + echo $script; + echo $noscript; + + echo ''; + } else { + //If no error, take them back to the course + redirect($url); + } +} \ No newline at end of file diff --git a/mod/lti/view.php b/mod/lti/view.php index fb1759fe5ca..3ae2098ba1a 100644 --- a/mod/lti/view.php +++ b/mod/lti/view.php @@ -91,18 +91,7 @@ $PAGE->set_context($context); $url = new moodle_url('/mod/lti/view.php', array('id'=>$cm->id)); $PAGE->set_url($url); -$launchcontainer = $basiclti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT ? - $toolconfig['launchcontainer'] : - $basiclti->launchcontainer; - -$devicetype = get_device_type(); - -//Scrolling within the object element doesn't work on iOS or Android -//Opening the popup window also had some issues in testing -//For mobile devices, always take up the entire screen to ensure the best experience -if($devicetype === 'mobile' || $devicetype === 'tablet' ){ - $launchcontainer = LTI_LAUNCH_CONTAINER_REPLACE_MOODLE_WINDOW; -} +$launchcontainer = lti_get_launch_container($basiclti, $toolconfig); if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS){ $PAGE->set_pagelayout('frametop'); //Most frametops don't include footer, and pre-post blocks From 57836e2403110b631569ee2bb7ebb950ace82a91 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Fri, 7 Oct 2011 14:59:09 -0400 Subject: [PATCH 36/78] Adding storage for overriding the instance specific icon. --- mod/lti/db/install.xml | 5 +- mod/lti/db/upgrade.php | 155 ++++++++++++++++++++++------------------- mod/lti/version.php | 100 +++++++++++++------------- 3 files changed, 136 insertions(+), 124 deletions(-) diff --git a/mod/lti/db/install.xml b/mod/lti/db/install.xml index 18765eec128..7410fd4d26d 100644 --- a/mod/lti/db/install.xml +++ b/mod/lti/db/install.xml @@ -1,5 +1,5 @@ - @@ -28,7 +28,8 @@ - + + diff --git a/mod/lti/db/upgrade.php b/mod/lti/db/upgrade.php index ed0531f3a44..199e99a1fd9 100644 --- a/mod/lti/db/upgrade.php +++ b/mod/lti/db/upgrade.php @@ -1,72 +1,83 @@ -. - -/** - * This file keeps track of upgrades to the basiclti module - * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis - * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - - -/** - * xmldb_lti_upgrade is the function that upgrades Moodle's - * database when is needed - * - * This function is automaticly called when version number in - * version.php changes. - * - * @param int $oldversion New old version number. - * - * @return boolean - */ - -function xmldb_lti_upgrade($oldversion=0) { - - global $DB; - - $dbman = $DB->get_manager(); - $result = true; - - - - return $result; -} - +. + +/** + * This file keeps track of upgrades to the basiclti module + * + * @package lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + + +/** + * xmldb_lti_upgrade is the function that upgrades Moodle's + * database when is needed + * + * This function is automaticly called when version number in + * version.php changes. + * + * @param int $oldversion New old version number. + * + * @return boolean + */ + +function xmldb_lti_upgrade($oldversion=0) { + global $DB; + + $dbman = $DB->get_manager(); + + if ($oldversion < 2011100701) { + $table = new xmldb_table('lti'); + $field = new xmldb_field('icon', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'servicesalt'); + + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + upgrade_mod_savepoint(true, 2011100701, 'lti'); + } + + $result = true; + + + + return $result; +} + diff --git a/mod/lti/version.php b/mod/lti/version.php index 39208581e4f..c8d95c8550e 100644 --- a/mod/lti/version.php +++ b/mod/lti/version.php @@ -1,50 +1,50 @@ -. - -/** - * This file defines the version of basiclti - * This fragment is called by moodle_needs_upgrading() and /admin/index.php - * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis - * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -$module->version = 2011072000; // The current module version (Date: YYYYMMDDXX) -$module->cron = 0; // Period for cron to check this module (secs) +. + +/** + * This file defines the version of basiclti + * This fragment is called by moodle_needs_upgrading() and /admin/index.php + * + * @package lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$module->version = 2011100701; // The current module version (Date: YYYYMMDDXX) +$module->cron = 0; // Period for cron to check this module (secs) From c07aec164f5785f8cf0df03a5907e5c2d813817e Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Mon, 10 Oct 2011 10:14:56 -0400 Subject: [PATCH 37/78] Implementing custom LTI icon support --- lib/outputlib.php | 7 ++++++- mod/lti/lib.php | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/outputlib.php b/lib/outputlib.php index 8feae4c83d5..efbf61660a8 100644 --- a/lib/outputlib.php +++ b/lib/outputlib.php @@ -911,7 +911,12 @@ class theme_config { $params['component'] = $component; } - return new moodle_url("$CFG->httpswwwroot/theme/image.php", $params); + //Allow references to images on other sites. + if(strstr($imagename, '://')){ + return $imagename; + } else { + return new moodle_url("$CFG->httpswwwroot/theme/image.php", $params); + } } /** diff --git a/mod/lti/lib.php b/mod/lti/lib.php index 7d3fc9de3f3..af8fe9666c0 100644 --- a/mod/lti/lib.php +++ b/mod/lti/lib.php @@ -163,6 +163,20 @@ function lti_delete_instance($id) { return $DB->delete_records("lti", array("id" => $basiclti->id)); } +function lti_get_coursemodule_info($coursemodule){ + global $DB; + + $lti = $DB->get_record('lti', array('id' => $coursemodule->instance), 'icon'); + + $info = new stdClass(); + + if(!empty($lti->icon)){ + $info->icon = $lti->icon; + } + + return $info; +} + /** * Return a small object with summary information about what a * user has done with a given particular instance of this module From a390d4537cb5aba805258d8d7458842f7ea5a9c6 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Mon, 10 Oct 2011 12:10:15 -0400 Subject: [PATCH 38/78] Leaving a little more room beneath embedded object so it doesn't get cut off on some themes. --- mod/lti/view.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mod/lti/view.php b/mod/lti/view.php index 3ae2098ba1a..b4ab3cc59f0 100644 --- a/mod/lti/view.php +++ b/mod/lti/view.php @@ -142,6 +142,8 @@ if ( $launchcontainer == LTI_LAUNCH_CONTAINER_WINDOW ) { var dom = YAHOO.util.Dom; var frame = document.getElementById('contentframe'); + + var padding = 15; //The bottom of the iframe wasn't visible on some themes. Probably because of border widths, etc. var lastHeight; @@ -149,7 +151,8 @@ if ( $launchcontainer == LTI_LAUNCH_CONTAINER_WINDOW ) { var viewportHeight = dom.getViewportHeight(); if(lastHeight !== Math.min(dom.getDocumentHeight(), viewportHeight)){ - frame.style.height = viewportHeight - dom.getY(frame) + 'px'; + + frame.style.height = viewportHeight - dom.getY(frame) - padding + 'px'; lastHeight = Math.min(dom.getDocumentHeight(), dom.getViewportHeight()); } From d66865d95bbebd7b445819f5f89dd74936224f90 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Mon, 10 Oct 2011 12:16:08 -0400 Subject: [PATCH 39/78] Fixing a coding error. --- mod/lti/locallib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index f25c93cfb72..63730addb47 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -556,7 +556,7 @@ function lti_get_url_thumbprint($url){ } if(substr($urlparts['host'], 0, 3) === 'www'){ - $urllparts['host'] = substr(3); + $urllparts['host'] = substr($urlparts['host'], 3); } return $urllower = $urlparts['host'] . '/' . $urlparts['path']; From 020eea1be8144626cc376f186522d9bad0d42b8c Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Mon, 10 Oct 2011 18:27:53 -0400 Subject: [PATCH 40/78] Updating web service verification method to work for LTI messages that don't send a source id. Adding extension so other plugins can handle LTI web service calls. --- mod/lti/locallib.php | 32 ++++++++++++++++++++++++++++++++ mod/lti/service.php | 39 ++++++++++++++++++++++++++++++++++++--- mod/lti/servicelib.php | 36 ++++++++++++++---------------------- 3 files changed, 82 insertions(+), 25 deletions(-) diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index 63730addb47..01c3bb571d1 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -608,6 +608,38 @@ function lti_get_best_tool_by_url($url, $tools, $courseid = null){ return $bestmatch; } +function lti_get_shared_secrets_by_key($key){ + global $DB; + + //Look up the shared secret for the specified key in both the types_config table (for configured tools) + //And in the lti resource table for ad-hoc tools + $query = <<get_records_sql($query, array('key1' => $key, 'key2' => $key)); + + $values = array_map(function($item){ + return $item->value; + }, $sharedsecrets); + + //There should really only be one shared secret per key. But, we can't prevent + //more than one getting entered. For instance, if the same key is used for two tool providers. + return $values; +} + /** * Prints the various configured tool types * diff --git a/mod/lti/service.php b/mod/lti/service.php index b420642967c..0bea3dc344d 100644 --- a/mod/lti/service.php +++ b/mod/lti/service.php @@ -3,7 +3,29 @@ require_once(dirname(__FILE__) . "/../../config.php"); require_once($CFG->dirroot.'/mod/lti/locallib.php'); require_once($CFG->dirroot.'/mod/lti/servicelib.php'); +use moodle\mod\lti as lti; + $rawbody = file_get_contents("php://input"); + +foreach(getallheaders() as $name => $value){ + if($name === 'Authorization'){ + $oauthparams = lti\OAuthUtil::split_header($value); + + $consumerkey = $oauthparams['oauth_consumer_key']; + break; + } +} + +if(empty($consumerkey)){ + throw new Exception('Consumer key is missing.'); +} + +$sharedsecret = lti_verify_message($consumerkey, lti_get_shared_secrets_by_key($consumerkey), $rawbody); + +if($sharedsecret === false){ + throw new Exception('Message signature not valid'); +} + $xml = new SimpleXMLElement($rawbody); $body = $xml->imsx_POXBody; @@ -18,7 +40,6 @@ switch($messagetype){ $ltiinstance = $DB->get_record('lti', array('id' => $parsed->instanceid)); lti_verify_sourcedid($ltiinstance, $parsed); - lti_verify_message($ltiinstance, $rawbody); $gradestatus = lti_update_grade($ltiinstance, $parsed->userid, $parsed->launchid, $parsed->gradeval); @@ -43,7 +64,6 @@ switch($messagetype){ $PAGE->set_context($context); lti_verify_sourcedid($ltiinstance, $parsed); - lti_verify_message($ltiinstance, $rawbody); $grade = lti_read_grade($ltiinstance, $parsed->userid); @@ -69,7 +89,6 @@ switch($messagetype){ $ltiinstance = $DB->get_record('lti', array('id' => $parsed->instanceid)); lti_verify_sourcedid($ltiinstance, $parsed); - lti_verify_message($ltiinstance, $rawbody); $gradestatus = lti_delete_grade($ltiinstance, $parsed->userid); @@ -82,6 +101,20 @@ switch($messagetype){ echo $responsexml->asXML(); + break; + + default: + //Fire an event if we get a web service request which we don't support directly. + //This will allow others to extend the LTI services, which I expect to be a common + //use case, at least until the spec matures. + $data = new stdClass(); + $data->body = $rawbody; + $data->messagetype = $messagetype; + $data->consumerkey = $consumerkey; + $data->sharedsecret = $sharedsecret; + + events_trigger('lti_unknown_service_api_call', $data); + break; } diff --git a/mod/lti/servicelib.php b/mod/lti/servicelib.php index 30219501acf..bde4c6e5039 100644 --- a/mod/lti/servicelib.php +++ b/mod/lti/servicelib.php @@ -161,31 +161,23 @@ function lti_delete_grade($ltiinstance, $userid){ return $status == GRADE_UPDATE_OK || $status == GRADE_UPDATE_ITEM_DELETED; //grade_update seems to return ok now, but could reasonably return deleted in the future } -function lti_verify_message($ltiinstance, $body, $headers = null){ - //Use the key / secret configured on the tool, or look it up from the admin config - if(empty($ltiinstance->resourcekey) || empty($ltiinstance->password)){ - if($ltiinstance->typeid){ - $typeid = $ltiinstance->typeid; - } else { - $tool = lti_get_tool_by_url_match($ltiinstance->toolurl, $ltiinstance->course); - - if(!$tool){ - throw new Exception('Tool configuration not found for tool instance ' . $ltiinstance->id); - } - - $typeid = $tool->id; - } - - $typeconfig = lti_get_type_config($typeid);//Consider only fetching the 2 necessary settings here +function lti_verify_message($key, $sharedsecrets, $body, $headers = null){ + foreach($sharedsecrets as $secret){ + $signaturefailed = false; - $key = $typeconfig['resourcekey']; - $secret = $typeconfig['password']; - } else { - $key = $ltiinstance->resourcekey; - $secret = $ltiinstance->password; + try{ + lti\handleOAuthBodyPOST($key, $secret, $body, $headers); + } + catch(Exception $e){ + $signaturefailed = true; + } + + if(!$signaturefailed){ + return $secret;//Return the secret used to sign the message) + } } - lti\handleOAuthBodyPOST($key, $secret, $body, $headers); + return false; } function lti_verify_sourcedid($ltiinstance, $parsed){ From 3dd9ca24308a1967b2cdbe7bed5e4b3d54fb0638 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Tue, 11 Oct 2011 16:28:07 -0400 Subject: [PATCH 41/78] Some bug fixing & mostly done with help message when an unsigned request doesn't work. --- mod/lti/lang/en/lti.php | 15 +++++++ mod/lti/locallib.php | 89 ++++++++++++++++++++++++++--------------- mod/lti/return.php | 8 ++++ 3 files changed, 80 insertions(+), 32 deletions(-) diff --git a/mod/lti/lang/en/lti.php b/mod/lti/lang/en/lti.php index 34e43766765..e1634bf0587 100644 --- a/mod/lti/lang/en/lti.php +++ b/mod/lti/lang/en/lti.php @@ -211,6 +211,21 @@ $string['tool_config_not_found'] = 'Tool configuration not found for this URL.'; $string['return_to_course'] = 'Click here to return to the course.'; +$string['lti_launch_error'] = 'An error occured when launching the external tool: '; +$string['lti_launch_error_unsigned_help'] = <<<'HTML' +

+ This error may be a result of a missing consumer key and shared secret for the tool provider. +

+

+ If you have a consumer key and shared secret, you may enter it on the + external tool instance (make sure advanced options are visible).
+ Alternatively, you may create a course level tool provider configuration here. +

+

+ To submit a request for an administrator to complete the tool configuration, click here. +

+HTML; + //Instance help $string['external_tool_type_help'] = <<resourcekey)){ + $key = $instance->resourcekey; + } else if(!empty($typeconfig['resourcekey'])){ + $key = $typeconfig['resourcekey']; + } else { + $key = ''; + } + + if(!empty($instance->password)){ + $secret = $instance->password; + } else if(!empty($typeconfig['password'])){ + $secret = $typeconfig['password']; + } else { + $secret = ''; + } + $endpoint = !empty($instance->toolurl) ? $instance->toolurl : $typeconfig['toolurl']; - $key = !empty($instance->resourcekey) ? $instance->resourcekey : $typeconfig['resourcekey']; - $secret = !empty($instance->password) ? $instance->password : $typeconfig['password']; $orgid = $typeconfig['organizationid']; /* Suppress this for now - Chuck $orgdesc = $typeconfig['organizationdescr']; @@ -122,15 +136,26 @@ function lti_view($instance) { $course = $PAGE->course; $requestparams = lti_build_request($instance, $typeconfig, $course); - // Make sure we let the tool know what LMS they are being called from - $requestparams["ext_lms"] = "moodle-2"; - - // Add oauth_callback to be compliant with the 1.0A spec - $requestparams["oauth_callback"] = "about:blank"; - - $submittext = get_string('press_to_submit', 'lti'); - $parms = lti_sign_parameters($requestparams, $endpoint, "POST", $key, $secret, $submittext, $orgid /*, $orgdesc*/); - + $launchcontainer = lti_get_launch_container($instance, $typeconfig); + $returnurlparams = array('course' => $course->id, 'launch_container' => $launchcontainer); + + if ( $orgid ) { + $requestparams["tool_consumer_instance_guid"] = $orgid; + } + + if(!empty($key) && !empty($secret)){ + $parms = lti_sign_parameters($requestparams, $endpoint, "POST", $key, $secret); + } else { + //If no key and secret, do the launch unsigned. + $parms = $requestparams; + + $returnurlparams['unsigned'] = '1'; + } + + //Add the return URL. We send the launch container along to help us avoid frames-within-frames when the user returns + $url = new moodle_url('/mod/lti/return.php', $returnurlparams); + $parms['launch_presentation_return_url'] = $url->out(false); + $debuglaunch = ( $instance->debuglaunch == 1 ); $content = lti_post_launch_html($parms, $endpoint, $debuglaunch); @@ -229,12 +254,6 @@ function lti_build_request($instance, $typeconfig, $course) { $url = new moodle_url('/mod/lti/service.php'); $requestparams['lis_outcome_service_url'] = $url->out(); - $launchcontainer = lti_get_launch_container($instance, $typeconfig); - - //Add the return URL. We send the launch container along to help us avoid frames-within-frames when the user returns - $url = new moodle_url('/mod/lti/return.php', array('course' => $course->id, 'launch_container' => $launchcontainer)); - $requestparams['launch_presentation_return_url'] = $url->out(false); - // Concatenate the custom parameters from the administrator and the instructor // Instructor parameters are only taken into consideration if the administrator // has giver permission @@ -261,6 +280,21 @@ function lti_build_request($instance, $typeconfig, $course) { $requestparams = array_merge($custom, $requestparams); } + // Make sure we let the tool know what LMS they are being called from + $requestparams["ext_lms"] = "moodle-2"; + + // Add oauth_callback to be compliant with the 1.0A spec + $requestparams["oauth_callback"] = "about:blank"; + + $submittext = get_string('press_to_submit', 'lti'); + $requestparams["ext_submit"] = $submittext; + + $requestparams["lti_version"] = "LTI-1p0"; + $requestparams["lti_message_type"] = "basic-lti-launch-request"; + /* Suppress this for now - Chuck + if ( $orgdesc ) $requestparams["tool_consumer_instance_description"] = $orgdesc; + */ + return $requestparams; } @@ -624,7 +658,7 @@ function lti_get_shared_secrets_by_key($key){ UNION - SELECT password + SELECT password AS value FROM {lti} WHERE resourcekey = :key2 QUERY; @@ -959,18 +993,9 @@ function lti_update_config($config) { * @param $orgid LMS name * @param $orgdesc LMS key */ -function lti_sign_parameters($oldparms, $endpoint, $method, $oauthconsumerkey, $oauthconsumersecret, $submittext, $orgid /*, $orgdesc*/) { - global $lastbasestring; +function lti_sign_parameters($oldparms, $endpoint, $method, $oauthconsumerkey, $oauthconsumersecret) { + //global $lastbasestring; $parms = $oldparms; - $parms["lti_version"] = "LTI-1p0"; - $parms["lti_message_type"] = "basic-lti-launch-request"; - if ( $orgid ) { - $parms["tool_consumer_instance_guid"] = $orgid; - } - /* Suppress this for now - Chuck - if ( $orgdesc ) $parms["tool_consumer_instance_description"] = $orgdesc; - */ - $parms["ext_submit"] = $submittext; $testtoken = ''; @@ -981,7 +1006,7 @@ function lti_sign_parameters($oldparms, $endpoint, $method, $oauthconsumerkey, $ $accreq->sign_request($hmacmethod, $testconsumer, $testtoken); // Pass this back up "out of band" for debugging - $lastbasestring = $accreq->get_signature_base_string(); + //$lastbasestring = $accreq->get_signature_base_string(); $newparms = $accreq->get_parameters(); @@ -996,7 +1021,7 @@ function lti_sign_parameters($oldparms, $endpoint, $method, $oauthconsumerkey, $ * @param $debug Debug (true/false) */ function lti_post_launch_html($newparms, $endpoint, $debug=false) { - global $lastbasestring; + //global $lastbasestring; $r = "
\n"; @@ -1043,7 +1068,7 @@ function lti_post_launch_html($newparms, $endpoint, $debug=false) { $r .= "$key = $value
\n"; } $r .= " 
\n"; - $r .= "

".get_string("basiclti_base_string", "lti")."
\n".$lastbasestring."

\n"; + //$r .= "

".get_string("basiclti_base_string", "lti")."
\n".$lastbasestring."

\n"; $r .= "\n"; } $r .= "
\n"; diff --git a/mod/lti/return.php b/mod/lti/return.php index b1c0ed81059..87719617d80 100644 --- a/mod/lti/return.php +++ b/mod/lti/return.php @@ -7,6 +7,7 @@ require_once($CFG->dirroot.'/mod/lti/lib.php'); $courseid = required_param('course', PARAM_INT); $errormsg = optional_param('lti_errormsg', '', PARAM_RAW); +$unsigned = optional_param('unsigned', '0', PARAM_INT); $launchcontainer = optional_param('launch_container', LTI_LAUNCH_CONTAINER_WINDOW, PARAM_INT); $course = $DB->get_record('course', array('id' => $courseid)); @@ -30,8 +31,15 @@ if(!empty($errormsg)){ echo $OUTPUT->header(); + echo get_string('lti_launch_error', 'lti'); + //TODO: Add some help around this error message. echo htmlspecialchars($errormsg); + + if($unsigned == 1){ + echo '

'; + echo get_string('lti_launch_error_unsigned_help', 'lti'); + } echo $OUTPUT->footer(); } else { From 9d57ad1737f0e67d8aab54718d827274a1be1d7d Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Wed, 12 Oct 2011 09:45:14 -0400 Subject: [PATCH 42/78] Fix a bug introduced recently that broke launches (adding the return url after signing). Trim the launch URL to prevent signature errors. --- mod/lti/locallib.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index af5c4c5c209..60233e32c8f 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -124,6 +124,8 @@ function lti_view($instance) { } $endpoint = !empty($instance->toolurl) ? $instance->toolurl : $typeconfig['toolurl']; + $endpiont = trim($endpoint); + $orgid = $typeconfig['organizationid']; /* Suppress this for now - Chuck $orgdesc = $typeconfig['organizationdescr']; @@ -143,19 +145,21 @@ function lti_view($instance) { $requestparams["tool_consumer_instance_guid"] = $orgid; } + if(empty($key) || empty($secret)){ + $returnurlparams['unsigned'] = '1'; + + //Add the return URL. We send the launch container along to help us avoid frames-within-frames when the user returns + $url = new moodle_url('/mod/lti/return.php', $returnurlparams); + $parms['launch_presentation_return_url'] = $url->out(false); + } + if(!empty($key) && !empty($secret)){ $parms = lti_sign_parameters($requestparams, $endpoint, "POST", $key, $secret); } else { //If no key and secret, do the launch unsigned. $parms = $requestparams; - - $returnurlparams['unsigned'] = '1'; } - //Add the return URL. We send the launch container along to help us avoid frames-within-frames when the user returns - $url = new moodle_url('/mod/lti/return.php', $returnurlparams); - $parms['launch_presentation_return_url'] = $url->out(false); - $debuglaunch = ( $instance->debuglaunch == 1 ); $content = lti_post_launch_html($parms, $endpoint, $debuglaunch); @@ -230,12 +234,12 @@ function lti_build_request($instance, $typeconfig, $course) { $requestparams["ext_ims_lis_basic_outcome_url"] = $CFG->wwwroot.'/mod/lti/service.php'; } - if ( isset($placementsecret) && + /*if ( isset($placementsecret) && ( $typeconfig['allowroster'] == LTI_SETTING_ALWAYS || ( $typeconfig['allowroster'] == LTI_SETTING_DELEGATE && $instance->instructorchoiceallowroster == LTI_SETTING_ALWAYS ) ) ) { $requestparams["ext_ims_lis_memberships_id"] = $sourcedid; $requestparams["ext_ims_lis_memberships_url"] = $CFG->wwwroot.'/mod/lti/service.php'; - } + }*/ // Send user's name and email data if appropriate if ( $typeconfig['sendname'] == LTI_SETTING_ALWAYS || From c4d80efeb660cdfe5736537d7a1db67f66749527 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Wed, 12 Oct 2011 13:07:08 -0400 Subject: [PATCH 43/78] More work on the tool return page to help the user get the tool configured. --- mod/lti/db/access.php | 20 ++++++++++++ mod/lti/instructor_edit_tool_type.php | 4 ++- mod/lti/lang/en/lti.php | 21 +++++++++++-- mod/lti/lib.php | 14 +++++---- mod/lti/locallib.php | 20 ++++++++---- mod/lti/request_tool.php | 44 +++++++++++++++++++++++++++ mod/lti/return.php | 22 +++++++++++--- mod/lti/version.php | 2 +- mod/lti/view.php | 2 +- 9 files changed, 127 insertions(+), 22 deletions(-) create mode 100644 mod/lti/request_tool.php diff --git a/mod/lti/db/access.php b/mod/lti/db/access.php index 3006bb90f58..bc8a15f054a 100644 --- a/mod/lti/db/access.php +++ b/mod/lti/db/access.php @@ -68,4 +68,24 @@ $capabilities = array( 'manager' => CAP_ALLOW ) ), + + 'mod/lti:addcoursetool' => array( + 'captype' => 'write', + 'contextlevel' => CONTEXT_COURSE, + 'archetypes' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ) + ), + + 'mod/lti:requesttooladd' => array( + 'captype' => 'write', + 'contextlevel' => CONTEXT_COURSE, + 'archetypes' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ) + ) ); diff --git a/mod/lti/instructor_edit_tool_type.php b/mod/lti/instructor_edit_tool_type.php index 530f0ce4e3d..e355212f77e 100644 --- a/mod/lti/instructor_edit_tool_type.php +++ b/mod/lti/instructor_edit_tool_type.php @@ -12,6 +12,8 @@ $PAGE->set_pagelayout('popup'); $action = optional_param('action', null, PARAM_TEXT); $typeid = optional_param('typeid', null, PARAM_INT); +require_capability('mod/lti:addcoursetool', get_context_instance(CONTEXT_COURSE, $courseid)); + if(!empty($typeid)){ $type = lti_get_type($typeid); if($type->course != $courseid){ @@ -25,7 +27,7 @@ echo $OUTPUT->header(); $data = data_submitted(); -if (confirm_sesskey() && isset($data->submitbutton)) { +if (isset($data->submitbutton) && confirm_sesskey()) { $type = new stdClass(); if (!empty($typeid)) { diff --git a/mod/lti/lang/en/lti.php b/mod/lti/lang/en/lti.php index e1634bf0587..77cebd1070b 100644 --- a/mod/lti/lang/en/lti.php +++ b/mod/lti/lang/en/lti.php @@ -45,6 +45,12 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +//Permissions +$string['lti:view'] = 'View LTI activities'; +$string['lti:grade'] = 'Grade LTI activities'; +$string['lti:addcoursetool'] = 'Grade LTI activities'; +$string['lti:requesttooladd'] = 'Submit a tool to admins for configuration'; + $string['accept'] = 'Accept'; $string['activity'] = 'Activity'; $string['addnewapp'] = 'Enable External Application'; @@ -217,15 +223,24 @@ $string['lti_launch_error_unsigned_help'] = <<<'HTML' This error may be a result of a missing consumer key and shared secret for the tool provider.

- If you have a consumer key and shared secret, you may enter it on the - external tool instance (make sure advanced options are visible).
- Alternatively, you may create a course level tool provider configuration here. + If you have a consumer key and shared secret, you may enter it when editing the external tool instance (make sure advanced options are visible).
+ Alternatively, you may create a course level tool provider configuration here.

+HTML; +$string['lti_launch_error_tool_request'] = <<<'HTML'

To submit a request for an administrator to complete the tool configuration, click here.

HTML; +$string['lti_tool_request_added'] = <<get_children_key_list(); + if(has_capability('mod/lti:grade', get_context_instance(CONTEXT_MODULE, $PAGE->cm->id))){ + $keys = $parentnode->get_children_key_list(); - $node = navigation_node::create('Submissions', - new moodle_url('/mod/lti/grade.php', array('id'=>$PAGE->cm->id)), - navigation_node::TYPE_SETTING, null, 'mod_lti_submissions'); - - $parentnode->add_node($node, $keys[1]); + $node = navigation_node::create('Submissions', + new moodle_url('/mod/lti/grade.php', array('id'=>$PAGE->cm->id)), + navigation_node::TYPE_SETTING, null, 'mod_lti_submissions'); + + $parentnode->add_node($node, $keys[1]); + } } \ No newline at end of file diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index 60233e32c8f..a2239f39fce 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -139,7 +139,7 @@ function lti_view($instance) { $requestparams = lti_build_request($instance, $typeconfig, $course); $launchcontainer = lti_get_launch_container($instance, $typeconfig); - $returnurlparams = array('course' => $course->id, 'launch_container' => $launchcontainer); + $returnurlparams = array('course' => $course->id, 'launch_container' => $launchcontainer, 'instanceid' => $instance->id); if ( $orgid ) { $requestparams["tool_consumer_instance_guid"] = $orgid; @@ -149,8 +149,8 @@ function lti_view($instance) { $returnurlparams['unsigned'] = '1'; //Add the return URL. We send the launch container along to help us avoid frames-within-frames when the user returns - $url = new moodle_url('/mod/lti/return.php', $returnurlparams); - $parms['launch_presentation_return_url'] = $url->out(false); + $url = new moodle_url('/mod/lti/return.php', $returnurlparams); + $requestparams['launch_presentation_return_url'] = $url->out(false); } if(!empty($key) && !empty($secret)){ @@ -1102,9 +1102,17 @@ function lti_get_type($typeid){ } function lti_get_launch_container($lti, $toolconfig){ - $launchcontainer = $lti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT ? - $toolconfig['launchcontainer'] : - $lti->launchcontainer; + if($lti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT){ + if(isset($toolconfig['launchcontainer'])){ + $launchcontainer = $toolconfig['launchcontainer']; + } + } else { + $launchcontainer = $lti->launchcontainer; + } + + if(empty($launchcontainer) || $launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT){ + $launchcontainer = LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS; + } $devicetype = get_device_type(); diff --git a/mod/lti/request_tool.php b/mod/lti/request_tool.php new file mode 100644 index 00000000000..80e50af7499 --- /dev/null +++ b/mod/lti/request_tool.php @@ -0,0 +1,44 @@ +dirroot.'/mod/lti/lib.php'); + +$instanceid = required_param('instanceid', PARAM_INT); + +$lti = $DB->get_record('lti', array('id' => $instanceid)); +$course = $DB->get_record('course', array('id' => $lti->course)); + +require_login($course); + +require_capability('mod/lti:requesttooladd', get_context_instance(CONTEXT_COURSE, $lti->course)); + +$baseurl = lti_get_domain_from_url($lti->toolurl); + +$url = new moodle_url('/mod/lti/request_tool.php', array('instanceid' => $instanceid)); +$PAGE->set_url($url); + +$pagetitle = strip_tags($course->shortname); +$PAGE->set_title($pagetitle); +$PAGE->set_heading($course->fullname); + +$PAGE->set_pagelayout('incourse'); + +echo $OUTPUT->header(); + +//Add a tool type if one does not exist already +if(!lti_get_tool_by_url_match($lti->toolurl, $lti->course, LTI_TOOL_STATE_ANY)){ + //There are no tools (active, pending, or rejected) for the launch URL. Create a new pending tool + $tooltype = new stdClass(); + $toolconfig = new stdClass(); + + $toolconfig->lti_toolurl = lti_get_domain_from_url($lti->toolurl); + $toolconfig->lti_typename = $toolconfig->lti_toolurl; + + lti_add_type($tooltype, $toolconfig); + + echo get_string('lti_tool_request_added', 'lti'); +} else { + echo get_string('lti_tool_request_existing', 'lti'); +} + +echo $OUTPUT->footer(); \ No newline at end of file diff --git a/mod/lti/return.php b/mod/lti/return.php index 87719617d80..fe84ac4e869 100644 --- a/mod/lti/return.php +++ b/mod/lti/return.php @@ -6,8 +6,11 @@ require_once('../../config.php'); require_once($CFG->dirroot.'/mod/lti/lib.php'); $courseid = required_param('course', PARAM_INT); +$instanceid = required_param('instanceid', PARAM_INT); + $errormsg = optional_param('lti_errormsg', '', PARAM_RAW); $unsigned = optional_param('unsigned', '0', PARAM_INT); + $launchcontainer = optional_param('launch_container', LTI_LAUNCH_CONTAINER_WINDOW, PARAM_INT); $course = $DB->get_record('course', array('id' => $courseid)); @@ -28,17 +31,28 @@ if(!empty($errormsg)){ } else { $PAGE->set_pagelayout('incourse'); } - + echo $OUTPUT->header(); echo get_string('lti_launch_error', 'lti'); - //TODO: Add some help around this error message. echo htmlspecialchars($errormsg); - if($unsigned == 1){ + $canaddtools = has_capability('mod/lti:addcoursetool', get_context_instance(CONTEXT_COURSE, $courseid)); + + if($unsigned == 1 && $canaddtools){ echo '

'; - echo get_string('lti_launch_error_unsigned_help', 'lti'); + + $links = new stdClass(); + $coursetooleditor = new moodle_url('/mod/lti/instructor_edit_tool_type.php', array('course' => $courseid, 'action' => 'add')); + $links->course_tool_editor = $coursetooleditor->out(false); + + $adminrequesturl = new moodle_url('/mod/lti/request_tool.php', array('instanceid' => $instanceid)); + $links->admin_request_url = $adminrequesturl->out(false); + + echo get_string('lti_launch_error_unsigned_help', 'lti', $links); + + echo get_string('lti_launch_error_tool_request', 'lti', $links); } echo $OUTPUT->footer(); diff --git a/mod/lti/version.php b/mod/lti/version.php index c8d95c8550e..5fbab518b17 100644 --- a/mod/lti/version.php +++ b/mod/lti/version.php @@ -46,5 +46,5 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$module->version = 2011100701; // The current module version (Date: YYYYMMDDXX) +$module->version = 2011101201; // The current module version (Date: YYYYMMDDXX) $module->cron = 0; // Period for cron to check this module (secs) diff --git a/mod/lti/view.php b/mod/lti/view.php index b4ab3cc59f0..212409f12e4 100644 --- a/mod/lti/view.php +++ b/mod/lti/view.php @@ -81,7 +81,7 @@ $tool = lti_get_tool_by_url_match($basiclti->toolurl); if($tool){ $toolconfig = lti_get_type_config($tool->id); } else { - $toolconfig = array('launchcontainer' => LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS); + $toolconfig = array(); } $PAGE->set_cm($cm, $course); // set's up global $COURSE From 58e3a4f371a984aafe560cc71157fdc65358d179 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Wed, 12 Oct 2011 13:17:32 -0400 Subject: [PATCH 44/78] Preventing column names from wrapping on the instructor add tool page. --- mod/lti/styles.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mod/lti/styles.css b/mod/lti/styles.css index 4485ae0db95..cc284a8d551 100644 --- a/mod/lti/styles.css +++ b/mod/lti/styles.css @@ -30,3 +30,8 @@ /* Styles for admin */ .path-admin-mod-lti .mform .fitem .fitemtitle { min-width:18em;padding-right:1em } /* Prevent setting titles from wrapping */ + +/* Styles for instructor_edit_tool_type.php */ +#page-mod-lti-instructor_edit_tool_type .mform .fitem .fitemtitle { min-width:18em;padding-right:1em } /* Prevent setting titles from wrapping */ + + From 558be8fcef5f76c289ac1a52f07f11d866f9ca75 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Wed, 12 Oct 2011 13:38:38 -0400 Subject: [PATCH 45/78] Adding a comment about the ext_submit button --- mod/lti/locallib.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index a2239f39fce..64c94c7aefa 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -290,6 +290,8 @@ function lti_build_request($instance, $typeconfig, $course) { // Add oauth_callback to be compliant with the 1.0A spec $requestparams["oauth_callback"] = "about:blank"; + //The submit button needs to be part of the signature as it gets posted with the form. + //This needs to be here to support launching without javascript. $submittext = get_string('press_to_submit', 'lti'); $requestparams["ext_submit"] = $submittext; From feb30fd8911415a5797d691017533ec00800a287 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Wed, 12 Oct 2011 13:57:52 -0400 Subject: [PATCH 46/78] Only consider configured tools when receiving LTI web service calls --- mod/lti/locallib.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index 64c94c7aefa..5ec50482211 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -657,11 +657,13 @@ function lti_get_shared_secrets_by_key($key){ SELECT t2.value FROM {lti_types_config} t1 INNER JOIN {lti_types_config} t2 ON t1.typeid = t2.typeid + INNER JOIN {lti_types} type ON t2.typeid = type.id WHERE t1.name = 'resourcekey' AND t1.value = :key1 AND t2.name = 'password' - + AND type.state = :configured + UNION SELECT password AS value @@ -669,7 +671,7 @@ function lti_get_shared_secrets_by_key($key){ WHERE resourcekey = :key2 QUERY; - $sharedsecrets = $DB->get_records_sql($query, array('key1' => $key, 'key2' => $key)); + $sharedsecrets = $DB->get_records_sql($query, array('configured' => LTI_TOOL_STATE_CONFIGURED, 'key1' => $key, 'key2' => $key)); $values = array_map(function($item){ return $item->value; From 6d462df8560ff798ae6af8e8758cf8f6c86d165a Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Wed, 12 Oct 2011 17:47:42 -0400 Subject: [PATCH 47/78] Adding the ability to edit the LTI icon URL --- mod/lti/lang/en/lti.php | 2 ++ mod/lti/mod_form.php | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/mod/lti/lang/en/lti.php b/mod/lti/lang/en/lti.php index 77cebd1070b..bfc91f7d49e 100644 --- a/mod/lti/lang/en/lti.php +++ b/mod/lti/lang/en/lti.php @@ -215,6 +215,8 @@ $string['domain_mismatch'] = 'Launch URL\'s domain does not match tool configura $string['custom_config'] = 'Using custom tool configuration.'; $string['tool_config_not_found'] = 'Tool configuration not found for this URL.'; +$string['icon_url'] = 'Icon URL'; + $string['return_to_course'] = 'Click here to return to the course.'; $string['lti_launch_error'] = 'An error occured when launching the external tool: '; diff --git a/mod/lti/mod_form.php b/mod/lti/mod_form.php index 96ac935bb06..09bd969ad1e 100644 --- a/mod/lti/mod_form.php +++ b/mod/lti/mod_form.php @@ -122,6 +122,11 @@ class mod_lti_mod_form extends moodleform_mod { $mform->setAdvanced('instructorcustomparameters'); $mform->addHelpButton('instructorcustomparameters', 'custom', 'lti'); + $mform->addElement('text', 'icon', get_string('icon_url', 'lti'), array('size'=>'64')); + $mform->setType('icon', PARAM_TEXT); + $mform->setAdvanced('icon'); + //$mform->addHelpButton('icon', 'icon', 'lti'); + //------------------------------------------------------------------------------- // Add privacy preferences fieldset where users choose whether to send their data $mform->addElement('header', 'privacy', get_string('privacy', 'lti')); From 16cac56633e83231b52bda0041b1eb00ec62f745 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Fri, 14 Oct 2011 11:33:23 -0400 Subject: [PATCH 48/78] Fixing the method used to get LTI roles --- mod/lti/db/access.php | 13 ++++++++++- mod/lti/launch.php | 1 + mod/lti/locallib.php | 50 ++++++++++++++++++++----------------------- mod/lti/version.php | 2 +- 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/mod/lti/db/access.php b/mod/lti/db/access.php index bc8a15f054a..c9c70d4c255 100644 --- a/mod/lti/db/access.php +++ b/mod/lti/db/access.php @@ -45,7 +45,6 @@ $capabilities = array( 'mod/lti:view' => array( - 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, 'archetypes' => array( @@ -69,6 +68,18 @@ $capabilities = array( ) ), + 'mod/lti:manage' => array( + 'riskbitmask' => RISK_XSS, + + 'captype' => 'write', + 'contextlevel' => CONTEXT_MODULE, + 'archetypes' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ) + ), + 'mod/lti:addcoursetool' => array( 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, diff --git a/mod/lti/launch.php b/mod/lti/launch.php index 563a96ae37e..fa928635076 100644 --- a/mod/lti/launch.php +++ b/mod/lti/launch.php @@ -80,5 +80,6 @@ require_login($course); add_to_log($course->id, "lti", "launch", "launch.php?id=$cm->id", "$basiclti->id"); +$basiclti->cmid = $cm->id; lti_view($basiclti); diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index 5ec50482211..281eeda5bf3 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -201,8 +201,11 @@ function lti_build_sourcedid($instanceid, $userid, $launchid = null, $servicesal function lti_build_request($instance, $typeconfig, $course) { global $USER, $CFG; - $context = get_context_instance(CONTEXT_COURSE, $course->id); - $role = lti_get_ims_role($USER, $context); + if(empty($instance->cmid)){ + $instance->cmid = 0; + } + + $role = lti_get_ims_role($USER, $instance->cmid); $locale = $course->lang; if ( strlen($locale) < 1 ) { @@ -433,34 +436,27 @@ function lti_map_keyname($key) { } /** - * Returns the IMS user role in a given context - * - * This function queries Moodle for an user role and - * returns the correspondant IMS role - * - * @param StdClass $user Moodle user instance - * @param StdClass $context Moodle context - * - * @return string IMS Role - * + * Gets the IMS role string for the specified user and LTI course module. + * + * @param mixed $user User object or user id + * @param int $cmid The course module id of the LTI activity + * @return string A role string suitable for passing with an LTI launch */ -function lti_get_ims_role($user, $context) { - - $roles = get_user_roles($context, $user->id); - $rolesname = array(); - foreach ($roles as $role) { - $rolesname[] = $role->shortname; +function lti_get_ims_role($user, $cmid) { + $context = get_context_instance(CONTEXT_MODULE, $cmid); + $roles = array(); + + if(has_capability('mod/lti:manage', $context)){ + array_push($roles, 'Instructor'); + } else { + array_push($roles, 'Learner'); } - - if (in_array('admin', $rolesname) || in_array('coursecreator', $rolesname)) { - return get_string('imsroleadmin', 'lti'); + + if(is_siteadmin($user)){ + array_push($roles, 'urn:lti:sysrole:ims/lis/Administrator'); } - - if (in_array('editingteacher', $rolesname) || in_array('teacher', $rolesname)) { - return get_string('imsroleinstructor', 'lti'); - } - - return get_string('imsrolelearner', 'lti'); + + return join(',', $roles); } /** diff --git a/mod/lti/version.php b/mod/lti/version.php index 5fbab518b17..32d70ec8b12 100644 --- a/mod/lti/version.php +++ b/mod/lti/version.php @@ -46,5 +46,5 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$module->version = 2011101201; // The current module version (Date: YYYYMMDDXX) +$module->version = 2011101400; // The current module version (Date: YYYYMMDDXX) $module->cron = 0; // Period for cron to check this module (secs) From 1d4f052e4626579e70485232ca71997a35384075 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Mon, 17 Oct 2011 16:32:17 -0400 Subject: [PATCH 49/78] Update role checking to check course role if module is not available --- mod/lti/locallib.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index 281eeda5bf3..b77a15b4317 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -205,7 +205,7 @@ function lti_build_request($instance, $typeconfig, $course) { $instance->cmid = 0; } - $role = lti_get_ims_role($USER, $instance->cmid); + $role = lti_get_ims_role($USER, $instance->cmid, $instance->course); $locale = $course->lang; if ( strlen($locale) < 1 ) { @@ -442,16 +442,30 @@ function lti_map_keyname($key) { * @param int $cmid The course module id of the LTI activity * @return string A role string suitable for passing with an LTI launch */ -function lti_get_ims_role($user, $cmid) { - $context = get_context_instance(CONTEXT_MODULE, $cmid); +function lti_get_ims_role($user, $cmid, $courseid) { $roles = array(); - if(has_capability('mod/lti:manage', $context)){ - array_push($roles, 'Instructor'); + if(empty($cmid)){ + //If no cmid is passed, check if the user is a teacher in the course + //This allows other modules to programmatically "fake" a launch without + //a real LTI instance + $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid); + + if(has_capability('moodle/course:manageactivities', $coursecontext)){ + array_push($roles, 'Instructor'); + } else { + array_push($roles, 'Learner'); + } } else { - array_push($roles, 'Learner'); + $context = get_context_instance(CONTEXT_MODULE, $cmid); + + if(has_capability('mod/lti:manage', $context)){ + array_push($roles, 'Instructor'); + } else { + array_push($roles, 'Learner'); + } } - + if(is_siteadmin($user)){ array_push($roles, 'urn:lti:sysrole:ims/lis/Administrator'); } From 55e89adf4d9ac9f6ae6a786784574bd2d0346fa6 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Tue, 18 Oct 2011 13:10:58 -0400 Subject: [PATCH 50/78] Adding securetoolurl and secureicon fields --- mod/lti/db/install.xml | 10 ++++++---- mod/lti/db/upgrade.php | 19 ++++++++++++++++++- mod/lti/version.php | 2 +- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/mod/lti/db/install.xml b/mod/lti/db/install.xml index 7410fd4d26d..269645c64b8 100644 --- a/mod/lti/db/install.xml +++ b/mod/lti/db/install.xml @@ -1,5 +1,5 @@ - @@ -14,8 +14,9 @@ - - + + + @@ -29,7 +30,8 @@ - + + diff --git a/mod/lti/db/upgrade.php b/mod/lti/db/upgrade.php index 199e99a1fd9..d115d2774f9 100644 --- a/mod/lti/db/upgrade.php +++ b/mod/lti/db/upgrade.php @@ -65,7 +65,7 @@ function xmldb_lti_upgrade($oldversion=0) { if ($oldversion < 2011100701) { $table = new xmldb_table('lti'); - $field = new xmldb_field('icon', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'servicesalt'); + $field = new xmldb_field('icon', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'servicesalt'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); @@ -74,6 +74,23 @@ function xmldb_lti_upgrade($oldversion=0) { upgrade_mod_savepoint(true, 2011100701, 'lti'); } + if ($oldversion < 2011101801) { + $table = new xmldb_table('lti'); + $field = new xmldb_field('securetoolurl', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'toolurl'); + + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + $field = new xmldb_field('secureicon', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'icon'); + + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + upgrade_mod_savepoint(true, 2011101801, 'lti'); + } + $result = true; diff --git a/mod/lti/version.php b/mod/lti/version.php index 32d70ec8b12..0d98a9eef51 100644 --- a/mod/lti/version.php +++ b/mod/lti/version.php @@ -46,5 +46,5 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$module->version = 2011101400; // The current module version (Date: YYYYMMDDXX) +$module->version = 2011101801; // The current module version (Date: YYYYMMDDXX) $module->cron = 0; // Period for cron to check this module (secs) From d8d04121680072425ee5b64b80cd5ca068f377f9 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Wed, 19 Oct 2011 14:06:15 -0400 Subject: [PATCH 51/78] Updating SSL settings & configuration for the LTI plugin. --- mod/lti/edit_form.php | 9 +++-- mod/lti/lang/en/lti.php | 42 +++++++++++++++++++++ mod/lti/lib.php | 12 ++++-- mod/lti/locallib.php | 77 +++++++++++++++++++++++++++++++++------ mod/lti/mod_form.js | 22 +++++++---- mod/lti/mod_form.php | 13 ++++++- mod/lti/typessettings.php | 4 +- 7 files changed, 151 insertions(+), 28 deletions(-) diff --git a/mod/lti/edit_form.php b/mod/lti/edit_form.php index 9fa2d86c5c4..a47908fcc30 100644 --- a/mod/lti/edit_form.php +++ b/mod/lti/edit_form.php @@ -68,7 +68,6 @@ class mod_lti_edit_types_form extends moodleform{ $mform->addElement('text', 'lti_toolurl', get_string('toolurl', 'lti'), array('size'=>'64')); $mform->setType('lti_toolurl', PARAM_TEXT); $mform->addHelpButton('lti_toolurl', 'toolurl', 'lti'); - $mform->addRule('lti_toolurl', null, 'required', null, 'client'); $mform->addElement('text', 'lti_resourcekey', get_string('resourcekey_admin', 'lti')); @@ -130,6 +129,10 @@ class mod_lti_edit_types_form extends moodleform{ $mform->setDefault('lti_allowroster', '2'); $mform->addHelpButton('lti_allowroster', 'share_roster_admin', 'lti'); + $mform->addElement('checkbox', 'lti_forcessl',' ', ' ' . get_string('force_ssl', 'lti'), $options); + $mform->setDefault('lti_forcessl', '0'); + + $mform->addHelpButton('lti_forcessl', 'force_ssl', 'lti'); if(!empty($this->_customdata->isadmin)){ //------------------------------------------------------------------------------- @@ -143,11 +146,11 @@ class mod_lti_edit_types_form extends moodleform{ $mform->addElement('text', 'lti_organizationid', get_string('organizationid', 'lti')); $mform->setType('lti_organizationid', PARAM_TEXT); - // $mform->addHelpButton('lti_organizationid', 'organizationid', 'lti'); + $mform->addHelpButton('lti_organizationid', 'organizationid', 'lti'); $mform->addElement('text', 'lti_organizationurl', get_string('organizationurl', 'lti')); $mform->setType('lti_organizationurl', PARAM_TEXT); - // $mform->addHelpButton('lti_organizationurl', 'organizationurl', 'lti'); + $mform->addHelpButton('lti_organizationurl', 'organizationurl', 'lti'); } /* Suppress this for now - Chuck diff --git a/mod/lti/lang/en/lti.php b/mod/lti/lang/en/lti.php index bfc91f7d49e..65f22a71135 100644 --- a/mod/lti/lang/en/lti.php +++ b/mod/lti/lang/en/lti.php @@ -189,12 +189,15 @@ $string['no_lti_configured'] = 'There are no active External Tools configured.'; $string['no_lti_pending'] = 'There are no pending External Tools.'; $string['no_lti_rejected'] = 'There are no rejected External Tools.'; $string['accept_grades_admin'] = 'Accept grades from the tool'; +$string['force_ssl'] = 'Force SSL'; +$string['lti_administration'] = 'LTI Administration'; //New instructor strings $string['display_name'] = 'Display activity name when launched'; $string['display_description'] = 'Display activity description when launched'; $string['external_tool_type'] = 'External tool type'; $string['launch_url'] = 'Launch URL'; +$string['secure_launch_url'] = 'Secure Launch URL'; $string['share_name'] = 'Share launcher\'s name with the tool'; $string['share_email'] = 'Share launcher\'s email with the tool'; $string['accept_grades'] = 'Accept grades from the tool'; @@ -216,6 +219,7 @@ $string['custom_config'] = 'Using custom tool configuration.'; $string['tool_config_not_found'] = 'Tool configuration not found for this URL.'; $string['icon_url'] = 'Icon URL'; +$string['secure_icon_url'] = 'Secure Icon URL'; $string['return_to_course'] = 'Click here to return to the course.'; @@ -293,6 +297,24 @@ If you have selected a specific tool type, you may not need to enter a Launch UR into the tool provider's system, and not go to a specific resource, this will likely be the case. HTML; +$string['secure_launch_url_help'] = << HTML; + +$string['force_ssl_help'] = <<get_record('lti', array('id' => $coursemodule->instance), 'icon'); + $lti = $DB->get_record('lti', array('id' => $coursemodule->instance), 'icon, secureicon'); $info = new stdClass(); - if(!empty($lti->icon)){ - $info->icon = $lti->icon; + //We want to use the right icon based on whether the current page is being requested over http or https. + //There's a potential problem here as the icon URLs are cached in the modinfo field and won't be updated for each request. + if(lti_request_is_using_ssl() && !empty($lti->secureicon)){ + $info->icon = $lti->secureicon; + } else { + if(!empty($lti->icon)){ + $info->icon = $lti->icon; + } } return $info; diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index b77a15b4317..d3e182d3100 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -98,6 +98,7 @@ function lti_view($instance) { $typeconfig['customparameters'] = $instance->instructorcustomparameters; $typeconfig['acceptgrades'] = $instance->instructorchoiceacceptgrades; $typeconfig['allowroster'] = $instance->instructorchoiceallowroster; + $typeconfig['forcessl'] = '0'; } //Default the organizationid if not specified @@ -124,17 +125,28 @@ function lti_view($instance) { } $endpoint = !empty($instance->toolurl) ? $instance->toolurl : $typeconfig['toolurl']; - $endpiont = trim($endpoint); + $endpoint = trim($endpoint); - $orgid = $typeconfig['organizationid']; - /* Suppress this for now - Chuck - $orgdesc = $typeconfig['organizationdescr']; - */ - - if(!strstr($endpoint, '://')){ - $endpoint = 'http://' . $endpoint; + //If the current request is using SSL and a secure tool URL is specified, use it + if(lti_request_is_using_ssl() && !empty($instance->securetoolurl)){ + $endpoint = trim($instance->securetoolurl); } + //If SSL is forced, use the secure tool url if specified. Otherwise, make sure https is on the normal launch URL. + if($typeconfig['forcessl'] == '1'){ + if(!empty($instance->securetoolurl)){ + $endpoint = trim($instance->securetoolurl); + } + + $endpoint = lti_ensure_url_is_https($endpoint); + } else { + if(!strstr($endpoint, '://')){ + $endpoint = 'http://' . $endpoint; + } + } + + $orgid = $typeconfig['organizationid']; + $course = $PAGE->course; $requestparams = lti_build_request($instance, $typeconfig, $course); @@ -150,7 +162,13 @@ function lti_view($instance) { //Add the return URL. We send the launch container along to help us avoid frames-within-frames when the user returns $url = new moodle_url('/mod/lti/return.php', $returnurlparams); - $requestparams['launch_presentation_return_url'] = $url->out(false); + $returnurl = $url->out(false); + + if($typeconfig['forcessl'] == '1'){ + $returnurl = lti_ensure_url_is_https($returnurl); + } + + $requestparams['launch_presentation_return_url'] = $returnurl; } if(!empty($key) && !empty($secret)){ @@ -234,7 +252,13 @@ function lti_build_request($instance, $typeconfig, $course) { ( $typeconfig['acceptgrades'] == LTI_SETTING_ALWAYS || ( $typeconfig['acceptgrades'] == LTI_SETTING_DELEGATE && $instance->instructorchoiceacceptgrades == LTI_SETTING_ALWAYS ) ) ) { $requestparams["lis_result_sourcedid"] = $sourcedid; - $requestparams["ext_ims_lis_basic_outcome_url"] = $CFG->wwwroot.'/mod/lti/service.php'; + + $serviceurl = $CFG->wwwroot . '/mod/lti/service.php'; + if($typeconfig['forcessl'] == '1'){ + $serviceurl = lti_ensure_url_is_https($serviceurl); + } + + $requestparams["ext_ims_lis_basic_outcome_url"] = $serviceurl; } /*if ( isset($placementsecret) && @@ -605,8 +629,12 @@ function lti_get_url_thumbprint($url){ $urlparts['path'] = ''; } - if(substr($urlparts['host'], 0, 3) === 'www'){ - $urllparts['host'] = substr($urlparts['host'], 3); + if(!isset($urlparts['host'])){ + $urlparts['host'] = ''; + } + + if(substr($urlparts['host'], 0, 4) === 'www.'){ + $urlparts['host'] = substr($urlparts['host'], 4); } return $urllower = $urlparts['host'] . '/' . $urlparts['path']; @@ -859,6 +887,10 @@ function lti_get_type_type_config($id) { $type->lti_customparameters = $config['customparameters']; } + if(isset($config['forcessl'])){ + $type->lti_forcessl = $config['forcessl']; + } + if (isset($config['organizationid'])) { $type->lti_organizationid = $config['organizationid']; } @@ -895,6 +927,9 @@ function lti_prepare_type_for_save($type, $config){ $type->coursevisible = !empty($config->lti_coursevisible) ? $config->lti_coursevisible : 0; $config->lti_coursevisible = $type->coursevisible; + $type->forcessl = !empty($config->lti_forcessl) ? $config->lti_forcessl : 0; + $config->lti_forcessl = $type->forcessl; + $type->timemodified = time(); unset ($config->lti_typename); @@ -1138,4 +1173,22 @@ function lti_get_launch_container($lti, $toolconfig){ } return $launchcontainer; +} + +function lti_request_is_using_ssl() { + global $ME; + return (stripos($ME, 'https://') === 0); +} + +function lti_ensure_url_is_https($url){ + if(!strstr($url, '://')){ + $url = 'https://' . $url; + } else { + //If the URL starts with http, replace with https + if(stripos($url, 'http://') === 0){ + $url = 'https://' . substr($url, 8); + } + } + + return $url; } \ No newline at end of file diff --git a/mod/lti/mod_form.js b/mod/lti/mod_form.js index edd394d525b..aa80cae04c6 100644 --- a/mod/lti/mod_form.js +++ b/mod/lti/mod_form.js @@ -16,9 +16,14 @@ this.addOptGroups(); + var updateToolMatches = function(){ + self.updateAutomaticToolMatch(Y.one('#id_toolurl')); + self.updateAutomaticToolMatch(Y.one('#id_securetoolurl')); + }; + var typeSelector = Y.one('#id_typeid'); typeSelector.on('change', function(e){ - self.updateAutomaticToolMatch(); + updateToolMatches(); self.toggleEditButtons(); }); @@ -29,6 +34,7 @@ var textAreas = new Y.NodeList([ Y.one('#id_toolurl'), + Y.one('#id_securetoolurl'), Y.one('#id_resourcekey'), Y.one('#id_password') ]); @@ -39,27 +45,29 @@ //If no more changes within 2 seconds, look up the matching tool URL debounce = setTimeout(function(){ - self.updateAutomaticToolMatch(); + updateToolMatches(); }, 2000); }); - self.updateAutomaticToolMatch(); + updateToolMatches(); }, clearToolCache: function(){ this.urlCache = {}; }, - updateAutomaticToolMatch: function(){ + updateAutomaticToolMatch: function(field){ var self = this; - var toolurl = Y.one('#id_toolurl'); + var toolurl = field; var typeSelector = Y.one('#id_typeid'); - var automatchToolDisplay = Y.one('#lti_automatch_tool'); + + var id = field.get('id') + '_lti_automatch_tool'; + var automatchToolDisplay = Y.one('#' + id); if(!automatchToolDisplay){ automatchToolDisplay = Y.Node.create('') - .set('id', 'lti_automatch_tool') + .set('id', id) .setStyle('padding-left', '1em'); toolurl.insert(automatchToolDisplay, 'after'); diff --git a/mod/lti/mod_form.php b/mod/lti/mod_form.php index 09bd969ad1e..cb640b8740c 100644 --- a/mod/lti/mod_form.php +++ b/mod/lti/mod_form.php @@ -97,6 +97,11 @@ class mod_lti_mod_form extends moodleform_mod { $mform->setType('toolurl', PARAM_TEXT); $mform->addHelpButton('toolurl', 'launch_url', 'lti'); + $mform->addElement('text', 'securetoolurl', get_string('secure_launch_url', 'lti'), array('size'=>'64')); + $mform->setType('securetoolurl', PARAM_TEXT); + $mform->setAdvanced('securetoolurl'); + $mform->addHelpButton('securetoolurl', 'secure_launch_url', 'lti'); + $launchoptions=array(); $launchoptions[LTI_LAUNCH_CONTAINER_DEFAULT] = get_string('default', 'lti'); $launchoptions[LTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'lti'); @@ -125,7 +130,12 @@ class mod_lti_mod_form extends moodleform_mod { $mform->addElement('text', 'icon', get_string('icon_url', 'lti'), array('size'=>'64')); $mform->setType('icon', PARAM_TEXT); $mform->setAdvanced('icon'); - //$mform->addHelpButton('icon', 'icon', 'lti'); + $mform->addHelpButton('icon', 'icon_url', 'lti'); + + $mform->addElement('text', 'secureicon', get_string('secure_icon_url', 'lti'), array('size'=>'64')); + $mform->setType('secureicon', PARAM_TEXT); + $mform->setAdvanced('secureicon'); + $mform->addHelpButton('secureicon', 'secure_icon_url', 'lti'); //------------------------------------------------------------------------------- // Add privacy preferences fieldset where users choose whether to send their data @@ -217,6 +227,7 @@ class mod_lti_mod_form extends moodleform_mod { function definition_after_data() { parent::definition_after_data(); + //$mform =& $this->_form; } /** diff --git a/mod/lti/typessettings.php b/mod/lti/typessettings.php index 8e5e49ae938..16834221a5e 100644 --- a/mod/lti/typessettings.php +++ b/mod/lti/typessettings.php @@ -125,7 +125,7 @@ if (empty($SITE->fullname)) { $PAGE->set_title($settingspage->visiblename); $PAGE->set_heading($settingspage->visiblename); - $PAGE->navbar->add('Basic LTI Administration', $CFG->wwwroot.'/admin/settings.php?section=modsettinglti'); + $PAGE->navbar->add(get_string('lti_administration', 'lti'), $CFG->wwwroot.'/admin/settings.php?section=modsettinglti'); echo $OUTPUT->header(); @@ -168,7 +168,7 @@ if (empty($SITE->fullname)) { $PAGE->set_title("$SITE->shortname: " . get_string('toolsetup', 'lti')); - $PAGE->navbar->add('Basic LTI Administration', $CFG->wwwroot.'/admin/settings.php?section=modsettinglti'); + $PAGE->navbar->add(get_string('lti_administration', 'lti'), $CFG->wwwroot.'/admin/settings.php?section=modsettinglti'); echo $OUTPUT->header(); From a0ba4ec67593b25517017b91504b264a3d1d66c3 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Wed, 19 Oct 2011 14:35:40 -0400 Subject: [PATCH 52/78] Add unsupported service support. --- mod/lti/service.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mod/lti/service.php b/mod/lti/service.php index 0bea3dc344d..0d4bee69fe4 100644 --- a/mod/lti/service.php +++ b/mod/lti/service.php @@ -109,12 +109,29 @@ switch($messagetype){ //use case, at least until the spec matures. $data = new stdClass(); $data->body = $rawbody; + $data->xml = $xml; $data->messagetype = $messagetype; $data->consumerkey = $consumerkey; $data->sharedsecret = $sharedsecret; + //If an event handler handles the web service, it should set this global to true + //So this code knows whether to send an "operation not supported" or not. + global $lti_web_service_handled; + $lti_web_service_handled = false; + events_trigger('lti_unknown_service_api_call', $data); + if(!$lti_web_service_handled){ + $responsexml = lti_get_response_xml( + 'unsupported', + 'unsupported', + lti_parse_message_id($xml), + $messagetype + ); + + echo $responsexml->asXML(); + } + break; } From 61eb12d4df4436c8f3729e617860c6595bc09131 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Sun, 6 Nov 2011 21:51:06 -0500 Subject: [PATCH 53/78] MDL-20534 lti: A3, copyright and DOS lf fixed --- mod/lti/ajax.php | 25 +- .../backup_lti_activity_task.class.php | 46 ++-- .../backup/moodle2/backup_lti_stepslib.php | 49 ++-- .../restore_lti_activity_task.class.php | 48 ++-- .../backup/moodle2/restore_lti_stepslib.php | 52 ++-- mod/lti/basiclti.js | 51 ++-- mod/lti/db/access.php | 52 ++-- mod/lti/db/install.xml | 2 +- mod/lti/db/upgrade.php | 49 ++-- mod/lti/edit_form.php | 47 ++-- mod/lti/grade.php | 49 ++-- mod/lti/index.php | 243 +++++++++--------- mod/lti/instructor_edit_tool_type.php | 24 ++ mod/lti/lang/en/lti.php | 45 ++-- mod/lti/launch.php | 45 ++-- mod/lti/lib.php | 50 ++-- mod/lti/localadminlib.php | 171 ++++++------ mod/lti/locallib.php | 49 ++-- mod/lti/mod_form.js | 25 +- mod/lti/mod_form.php | 47 ++-- mod/lti/request_tool.php | 25 +- mod/lti/return.php | 25 +- mod/lti/service.php | 26 +- mod/lti/servicelib.php | 23 ++ mod/lti/settings.php | 47 ++-- mod/lti/simpletest/testlocallib.php | 49 ++-- mod/lti/submissions.js | 25 +- mod/lti/typessettings.php | 48 ++-- mod/lti/version.php | 49 ++-- mod/lti/view.php | 47 ++-- 30 files changed, 855 insertions(+), 678 deletions(-) diff --git a/mod/lti/ajax.php b/mod/lti/ajax.php index cd05a5cf179..e471039b7be 100644 --- a/mod/lti/ajax.php +++ b/mod/lti/ajax.php @@ -1,4 +1,27 @@ . + +/** + * MRTODO: Brief description of this file + * + * @package mod + * @subpackage xml + * @copyright 2011 onwards MRTODO + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ require_once(dirname(__FILE__) . "/../../config.php"); require_once($CFG->dirroot . '/mod/lti/locallib.php'); @@ -28,4 +51,4 @@ switch($action){ echo json_encode($response); -die; \ No newline at end of file +die; diff --git a/mod/lti/backup/moodle2/backup_lti_activity_task.class.php b/mod/lti/backup/moodle2/backup_lti_activity_task.class.php index c70d92d210a..07b4c365e8a 100644 --- a/mod/lti/backup/moodle2/backup_lti_activity_task.class.php +++ b/mod/lti/backup/moodle2/backup_lti_activity_task.class.php @@ -1,4 +1,19 @@ . +// // This file is part of BasicLTI4Moodle // // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) @@ -16,34 +31,19 @@ // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis // of the Universitat Politecnica de Catalunya http://www.upc.edu // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . - /** * This file contains the lti module backup class * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once($CFG->dirroot . '/mod/lti/backup/moodle2/backup_lti_stepslib.php'); diff --git a/mod/lti/backup/moodle2/backup_lti_stepslib.php b/mod/lti/backup/moodle2/backup_lti_stepslib.php index 429794fa641..dfdf68cb61a 100644 --- a/mod/lti/backup/moodle2/backup_lti_stepslib.php +++ b/mod/lti/backup/moodle2/backup_lti_stepslib.php @@ -1,4 +1,19 @@ . +// // This file is part of BasicLTI4Moodle // // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) @@ -16,38 +31,20 @@ // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis // of the Universitat Politecnica de Catalunya http://www.upc.edu // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . /** * This file contains all the backup steps that will be used * by the backup_lti_activity_task * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/** - * Define all the backup steps that will be used by the backup_lti_activity_task + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /** diff --git a/mod/lti/backup/moodle2/restore_lti_activity_task.class.php b/mod/lti/backup/moodle2/restore_lti_activity_task.class.php index 1c383310fa7..773fe2db4d0 100644 --- a/mod/lti/backup/moodle2/restore_lti_activity_task.class.php +++ b/mod/lti/backup/moodle2/restore_lti_activity_task.class.php @@ -1,4 +1,19 @@ . +// // This file is part of BasicLTI4Moodle // // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) @@ -16,34 +31,21 @@ // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis // of the Universitat Politecnica de Catalunya http://www.upc.edu // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . /** - * This file contains the basicLTI module restore class + * This file contains the lti module restore class * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot . '/mod/lti/backup/moodle2/restore_lti_stepslib.php'); // Because it exists (must) diff --git a/mod/lti/backup/moodle2/restore_lti_stepslib.php b/mod/lti/backup/moodle2/restore_lti_stepslib.php index 6114cbdbe58..34a82f52d05 100644 --- a/mod/lti/backup/moodle2/restore_lti_stepslib.php +++ b/mod/lti/backup/moodle2/restore_lti_stepslib.php @@ -1,4 +1,19 @@ . +// // This file is part of BasicLTI4Moodle // // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) @@ -16,39 +31,20 @@ // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis // of the Universitat Politecnica de Catalunya http://www.upc.edu // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . - /** * This file contains all the restore steps that will be used - * by the restore_basiclti_activity_task + * by the restore_lti_activity_task * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/** - * Define all the restore steps that will be used by the restore_basiclti_activity_task + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /** diff --git a/mod/lti/basiclti.js b/mod/lti/basiclti.js index 9389a4b450b..30c7d9dd6b1 100644 --- a/mod/lti/basiclti.js +++ b/mod/lti/basiclti.js @@ -1,3 +1,18 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . +// // This file is part of BasicLTI4Moodle // // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) @@ -15,34 +30,20 @@ // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis // of the Universitat Politecnica de Catalunya http://www.upc.edu // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . /** - * This file contains a library of javasxript functions for the BasicLTI module + * This file contains a library of javasxript functions for the lti module * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * @author Charles Severance - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @author Charles Severance + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ function basicltiDebugToggle() { @@ -53,4 +54,4 @@ function basicltiDebugToggle() { else { ele.style.display = 'block'; } -} \ No newline at end of file +} diff --git a/mod/lti/db/access.php b/mod/lti/db/access.php index c9c70d4c255..63a21c29739 100644 --- a/mod/lti/db/access.php +++ b/mod/lti/db/access.php @@ -1,45 +1,31 @@ : -// -// component_name should be the same as the directory name of the mod or block. -// -// Core moodle capabilities are defined thus: -// moodle/: -// -// Examples: mod/forum:viewpost -// block/recent_activity:view -// moodle/site:deleteuser -// -// The variable name for the capability definitions array is $capabilities +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . /** * This file contains the capabilities used by the lti module * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ $capabilities = array( diff --git a/mod/lti/db/install.xml b/mod/lti/db/install.xml index 269645c64b8..4d62cb08dbc 100644 --- a/mod/lti/db/install.xml +++ b/mod/lti/db/install.xml @@ -95,4 +95,4 @@ - \ No newline at end of file +
diff --git a/mod/lti/db/upgrade.php b/mod/lti/db/upgrade.php index d115d2774f9..b90b312492e 100644 --- a/mod/lti/db/upgrade.php +++ b/mod/lti/db/upgrade.php @@ -1,4 +1,19 @@ . +// // This file is part of BasicLTI4Moodle // // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) @@ -16,36 +31,21 @@ // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis // of the Universitat Politecnica de Catalunya http://www.upc.edu // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . /** - * This file keeps track of upgrades to the basiclti module + * This file keeps track of upgrades to the lti module * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - /** * xmldb_lti_upgrade is the function that upgrades Moodle's * database when is needed @@ -57,7 +57,6 @@ * * @return boolean */ - function xmldb_lti_upgrade($oldversion=0) { global $DB; diff --git a/mod/lti/edit_form.php b/mod/lti/edit_form.php index a47908fcc30..14a6345dafe 100644 --- a/mod/lti/edit_form.php +++ b/mod/lti/edit_form.php @@ -1,4 +1,19 @@ . +// // This file is part of BasicLTI4Moodle // // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) @@ -16,34 +31,20 @@ // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis // of the Universitat Politecnica de Catalunya http://www.upc.edu // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . /** * This file defines de main basiclti configuration form * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * @author Charles Severance - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @author Charles Severance + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die; diff --git a/mod/lti/grade.php b/mod/lti/grade.php index 866fe193252..a7d81c52c5a 100644 --- a/mod/lti/grade.php +++ b/mod/lti/grade.php @@ -1,4 +1,19 @@ . +// // This file is part of BasicLTI4Moodle // // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) @@ -16,35 +31,21 @@ // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis // of the Universitat Politecnica de Catalunya http://www.upc.edu // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . - /** * This file contains submissions-specific code for the basiclti module * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + require_once("../../config.php"); require_once($CFG->dirroot.'/mod/lti/lib.php'); require_once($CFG->libdir.'/plagiarismlib.php'); @@ -181,4 +182,4 @@ echo $OUTPUT->heading($title ); echo $table; -echo $OUTPUT->footer(); \ No newline at end of file +echo $OUTPUT->footer(); diff --git a/mod/lti/index.php b/mod/lti/index.php index f26503344c6..ec9318342f7 100644 --- a/mod/lti/index.php +++ b/mod/lti/index.php @@ -1,121 +1,122 @@ -. - -/** - * This page lists all the instances of basiclti in a particular course - * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis - * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -require_once("../../config.php"); -require_once($CFG->dirroot.'/mod/lti/lib.php'); - -$id = required_param('id', PARAM_INT); // course id - -if (! $course = $DB->get_record("course", array("id" => $id))) { - throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course ID is incorrect'); -} - -$url = new moodle_url('/mod/lti/index.php', array('id'=>$id)); -$PAGE->set_url($url); -$PAGE->set_pagelayout('incourse'); - -require_login($course); - -add_to_log($course->id, "lti", "view all", "index.php?id=$course->id", ""); - -$pagetitle = strip_tags($course->shortname.': '.get_string("modulenamepluralformatted", "lti")); -$PAGE->set_title($pagetitle); -$PAGE->set_heading($course->fullname); - -echo $OUTPUT->header(); - -/// Print the main part of the page -echo $OUTPUT->heading(get_string("modulenamepluralformatted", "lti")); - -/// Get all the appropriate data -if (! $basicltis = get_all_instances_in_course("lti", $course)) { - notice("There are no basicltis", "../../course/view.php?id=$course->id"); - die; -} - -/// Print the list of instances (your module will probably extend this) -$timenow = time(); -$strname = get_string("name"); -$strsectionname = get_string('sectionname', 'format_'.$course->format); -$usesections = course_format_uses_sections($course->format); -if ($usesections) { - $sections = get_all_sections($course->id); -} - -$table = new html_table(); -$table->attributes['class'] = 'generaltable mod_index'; - -if ($usesections) { - $table->head = array ($strsectionname, $strname); - $table->align = array ("center", "left"); -} else { - $table->head = array ($strname); -} - -foreach ($basicltis as $basiclti) { - if (!$basiclti->visible) { - //Show dimmed if the mod is hidden - $link = "coursemodule\">$basiclti->name"; - } else { - //Show normal if the mod is visible - $link = "coursemodule\">$basiclti->name"; - } - - if ($course->format == "weeks" or $course->format == "topics") { - $table->data[] = array ($basiclti->section, $link); - } else { - $table->data[] = array ($link); - } -} - -echo "
"; - -echo html_writer::table($table); - -/// Finish the page - -echo $OUTPUT->footer(); - +. +// +// This file is part of BasicLTI4Moodle +// +// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) +// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web +// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI +// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS +// are already supporting or going to support BasicLTI. This project Implements the consumer +// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas. +// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem +// at the GESSI research group at UPC. +// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI +// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a +// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier. +// +// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis +// of the Universitat Politecnica de Catalunya http://www.upc.edu +// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu + +/** + * This page lists all the instances of basiclti in a particular course + * + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +require_once("../../config.php"); +require_once($CFG->dirroot.'/mod/lti/lib.php'); + +$id = required_param('id', PARAM_INT); // course id + +if (! $course = $DB->get_record("course", array("id" => $id))) { + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course ID is incorrect'); +} + +$url = new moodle_url('/mod/lti/index.php', array('id'=>$id)); +$PAGE->set_url($url); +$PAGE->set_pagelayout('incourse'); + +require_login($course); + +add_to_log($course->id, "lti", "view all", "index.php?id=$course->id", ""); + +$pagetitle = strip_tags($course->shortname.': '.get_string("modulenamepluralformatted", "lti")); +$PAGE->set_title($pagetitle); +$PAGE->set_heading($course->fullname); + +echo $OUTPUT->header(); + +/// Print the main part of the page +echo $OUTPUT->heading(get_string("modulenamepluralformatted", "lti")); + +/// Get all the appropriate data +if (! $basicltis = get_all_instances_in_course("lti", $course)) { + notice("There are no basicltis", "../../course/view.php?id=$course->id"); + die; +} + +/// Print the list of instances (your module will probably extend this) +$timenow = time(); +$strname = get_string("name"); +$strsectionname = get_string('sectionname', 'format_'.$course->format); +$usesections = course_format_uses_sections($course->format); +if ($usesections) { + $sections = get_all_sections($course->id); +} + +$table = new html_table(); +$table->attributes['class'] = 'generaltable mod_index'; + +if ($usesections) { + $table->head = array ($strsectionname, $strname); + $table->align = array ("center", "left"); +} else { + $table->head = array ($strname); +} + +foreach ($basicltis as $basiclti) { + if (!$basiclti->visible) { + //Show dimmed if the mod is hidden + $link = "coursemodule\">$basiclti->name"; + } else { + //Show normal if the mod is visible + $link = "coursemodule\">$basiclti->name"; + } + + if ($course->format == "weeks" or $course->format == "topics") { + $table->data[] = array ($basiclti->section, $link); + } else { + $table->data[] = array ($link); + } +} + +echo "
"; + +echo html_writer::table($table); + +/// Finish the page + +echo $OUTPUT->footer(); + diff --git a/mod/lti/instructor_edit_tool_type.php b/mod/lti/instructor_edit_tool_type.php index e355212f77e..8c91eed5fd0 100644 --- a/mod/lti/instructor_edit_tool_type.php +++ b/mod/lti/instructor_edit_tool_type.php @@ -1,4 +1,28 @@ . + +/** + * MRTODO: Brief description of this file + * + * @package mod + * @subpackage lti + * @copyright 2011 onwards MRTODO + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + require_once('../../config.php'); require_once($CFG->dirroot.'/mod/lti/edit_form.php'); diff --git a/mod/lti/lang/en/lti.php b/mod/lti/lang/en/lti.php index 65f22a71135..05bc246c07c 100644 --- a/mod/lti/lang/en/lti.php +++ b/mod/lti/lang/en/lti.php @@ -1,4 +1,19 @@ . +// // This file is part of BasicLTI4Moodle // // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) @@ -16,33 +31,19 @@ // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis // of the Universitat Politecnica de Catalunya http://www.upc.edu // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . /** * This file contains en_utf8 translation of the Basic LTI module * - * @package basiclti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ //Permissions diff --git a/mod/lti/launch.php b/mod/lti/launch.php index fa928635076..9ad45faeb7d 100644 --- a/mod/lti/launch.php +++ b/mod/lti/launch.php @@ -1,4 +1,19 @@ . +// // This file is part of BasicLTI4Moodle // // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) @@ -16,33 +31,19 @@ // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis // of the Universitat Politecnica de Catalunya http://www.upc.edu // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . /** * This file contains all necessary code to view a basiclti activity instance * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once("../../config.php"); diff --git a/mod/lti/lib.php b/mod/lti/lib.php index 9c24fd1d19b..7b27699493b 100644 --- a/mod/lti/lib.php +++ b/mod/lti/lib.php @@ -1,4 +1,19 @@ . +// // This file is part of BasicLTI4Moodle // // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) @@ -16,34 +31,19 @@ // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis // of the Universitat Politecnica de Catalunya http://www.upc.edu // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . /** - * This file contains a library of functions and constants for the - * BasicLTI module + * This file contains a library of functions and constants for the lti module * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die; @@ -399,4 +399,4 @@ function lti_extend_settings_navigation($settings, $parentnode) { $parentnode->add_node($node, $keys[1]); } -} \ No newline at end of file +} diff --git a/mod/lti/localadminlib.php b/mod/lti/localadminlib.php index 54379d2e4b7..aae78362f98 100644 --- a/mod/lti/localadminlib.php +++ b/mod/lti/localadminlib.php @@ -1,85 +1,86 @@ -. - -/** - * This file contains some functions and classes used in Basic LTI - * module administration - * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis - * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die; - -require_once($CFG->libdir.'/adminlib.php'); - -/** - * - * @TODO: finish doc this class and it's functions - */ -class admin_setting_ltimodule_configlink extends admin_setting { - - /** - * Constructor - * @param string $name of setting - * @param string $visiblename localised - * @param string $description long localised info - */ - function admin_setting_ltimodule_configlink($name, $visiblename, $description) { - parent::__construct($name, $visiblename, $description, ''); - } - - function get_setting() { - return true; - } - - function write_setting($data) { - return ""; - } - - function output_html($data, $query='') { - global $CFG; - return format_admin_setting($this, "", - '', - $this->description, true, '', null, $query); - } -} +. +// +// This file is part of BasicLTI4Moodle +// +// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) +// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web +// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI +// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS +// are already supporting or going to support BasicLTI. This project Implements the consumer +// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas. +// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem +// at the GESSI research group at UPC. +// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI +// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a +// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier. +// +// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis +// of the Universitat Politecnica de Catalunya http://www.upc.edu +// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu + +/** + * This file contains some functions and classes used by the lti + * module administration + * + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * marc.alier@upc.edu + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +require_once($CFG->libdir.'/adminlib.php'); + +/** + * + * @TODO: finish doc this class and it's functions + */ +class admin_setting_ltimodule_configlink extends admin_setting { + + /** + * Constructor + * @param string $name of setting + * @param string $visiblename localised + * @param string $description long localised info + */ + function admin_setting_ltimodule_configlink($name, $visiblename, $description) { + parent::__construct($name, $visiblename, $description, ''); + } + + function get_setting() { + return true; + } + + function write_setting($data) { + return ""; + } + + function output_html($data, $query='') { + global $CFG; + return format_admin_setting($this, "", + '', + $this->description, true, '', null, $query); + } +} diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index d3e182d3100..6a09b307307 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -1,4 +1,19 @@ . +// // This file is part of BasicLTI4Moodle // // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) @@ -16,33 +31,19 @@ // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis // of the Universitat Politecnica de Catalunya http://www.upc.edu // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . /** - * This file contains the library of functions and constants for the basiclti module + * This file contains the library of functions and constants for the lti module * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die; @@ -1191,4 +1192,4 @@ function lti_ensure_url_is_https($url){ } return $url; -} \ No newline at end of file +} diff --git a/mod/lti/mod_form.js b/mod/lti/mod_form.js index aa80cae04c6..f11aa3b08e8 100644 --- a/mod/lti/mod_form.js +++ b/mod/lti/mod_form.js @@ -1,3 +1,26 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * MRTODO: Brief description of this file + * + * @package mod + * @subpackage lti + * @copyright 2011 onwards MRTODO + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ (function(){ var Y; @@ -321,4 +344,4 @@ } }; -})(); \ No newline at end of file +})(); diff --git a/mod/lti/mod_form.php b/mod/lti/mod_form.php index cb640b8740c..2c79049264b 100644 --- a/mod/lti/mod_form.php +++ b/mod/lti/mod_form.php @@ -1,4 +1,19 @@ . +// // This file is part of BasicLTI4Moodle // // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) @@ -16,33 +31,19 @@ // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis // of the Universitat Politecnica de Catalunya http://www.upc.edu // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . /** - * This file defines the main basiclti configuration form + * This file defines the main lti configuration form * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die; diff --git a/mod/lti/request_tool.php b/mod/lti/request_tool.php index 80e50af7499..a49d18ecb17 100644 --- a/mod/lti/request_tool.php +++ b/mod/lti/request_tool.php @@ -1,4 +1,27 @@ . + +/** + * MRTODO: Brief description of this file + * + * @package mod + * @subpackage lti + * @copyright 2011 onwards MRTODO + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ require_once('../../config.php'); require_once($CFG->dirroot.'/mod/lti/lib.php'); @@ -41,4 +64,4 @@ if(!lti_get_tool_by_url_match($lti->toolurl, $lti->course, LTI_TOOL_STATE_ANY)){ echo get_string('lti_tool_request_existing', 'lti'); } -echo $OUTPUT->footer(); \ No newline at end of file +echo $OUTPUT->footer(); diff --git a/mod/lti/return.php b/mod/lti/return.php index fe84ac4e869..8c34ede1731 100644 --- a/mod/lti/return.php +++ b/mod/lti/return.php @@ -1,6 +1,27 @@ . -//This page is used to handle the return back to Moodle from the tool provider +/** + * Handle the return back to Moodle from the tool provider + * + * @package mod + * @subpackage lti + * @copyright 2011 onwards MRTODO + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ require_once('../../config.php'); require_once($CFG->dirroot.'/mod/lti/lib.php'); @@ -92,4 +113,4 @@ NOSCRIPT; //If no error, take them back to the course redirect($url); } -} \ No newline at end of file +} diff --git a/mod/lti/service.php b/mod/lti/service.php index 0d4bee69fe4..b7506dd6b88 100644 --- a/mod/lti/service.php +++ b/mod/lti/service.php @@ -1,4 +1,28 @@ . + +/** + * MRTODO: Brief description of this file + * + * @package mod + * @subpackage lti + * @copyright 2011 onwards MRTODO + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + require_once(dirname(__FILE__) . "/../../config.php"); require_once($CFG->dirroot.'/mod/lti/locallib.php'); require_once($CFG->dirroot.'/mod/lti/servicelib.php'); @@ -140,4 +164,4 @@ switch($messagetype){ //echo '
'; -//echo file_get_contents("php://input"); \ No newline at end of file +//echo file_get_contents("php://input"); diff --git a/mod/lti/servicelib.php b/mod/lti/servicelib.php index bde4c6e5039..cd58b568e6c 100644 --- a/mod/lti/servicelib.php +++ b/mod/lti/servicelib.php @@ -1,4 +1,27 @@ . + +/** + * MRTODO: Brief description of this file + * + * @package mod + * @subpackage lti + * @copyright 2011 onwards MRTODO + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ require_once($CFG->dirroot.'/mod/lti/OAuthBody.php'); diff --git a/mod/lti/settings.php b/mod/lti/settings.php index c0c739535d9..97c7887a06d 100644 --- a/mod/lti/settings.php +++ b/mod/lti/settings.php @@ -1,4 +1,19 @@ . +// // This file is part of BasicLTI4Moodle // // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) @@ -16,33 +31,19 @@ // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis // of the Universitat Politecnica de Catalunya http://www.upc.edu // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . /** - * This file defines the global basiclti administration form + * This file defines the global lti administration form * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die; diff --git a/mod/lti/simpletest/testlocallib.php b/mod/lti/simpletest/testlocallib.php index 847c4867e73..8639a46ead0 100644 --- a/mod/lti/simpletest/testlocallib.php +++ b/mod/lti/simpletest/testlocallib.php @@ -1,4 +1,19 @@ . +// // This file is part of BasicLTI4Moodle // // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) @@ -16,34 +31,20 @@ // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis // of the Universitat Politecnica de Catalunya http://www.upc.edu // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . /** - * This file contains unit tests for (some of) mod/basiclti/locallib.php + * This file contains unit tests for (some of) lti/locallib.php * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Charles Severance csev@unmich.edu - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Charles Severance csev@unmich.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ if (!defined('MOODLE_INTERNAL')) { diff --git a/mod/lti/submissions.js b/mod/lti/submissions.js index 03188eef2bf..ece4e818eab 100644 --- a/mod/lti/submissions.js +++ b/mod/lti/submissions.js @@ -1,3 +1,26 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * MRTODO: Brief description of this file + * + * @package mod + * @subpackage lti + * @copyright 2011 onwards MRTODO + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ (function(){ var Y; @@ -49,4 +72,4 @@ Y.one('#lti_submissions_table_container').setStyle('display', ''); } } -})(); \ No newline at end of file +})(); diff --git a/mod/lti/typessettings.php b/mod/lti/typessettings.php index 16834221a5e..38dd10344ef 100644 --- a/mod/lti/typessettings.php +++ b/mod/lti/typessettings.php @@ -1,4 +1,19 @@ . +// // This file is part of BasicLTI4Moodle // // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) @@ -16,35 +31,20 @@ // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis // of the Universitat Politecnica de Catalunya http://www.upc.edu // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . /** * This file contains the script used to clone Moodle admin setting page. - * It is used to create a new form used to pre-configure basiclti - * activities + * It is used to create a new form used to pre-configure lti activities * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once('../../config.php'); diff --git a/mod/lti/version.php b/mod/lti/version.php index 0d98a9eef51..41155adb5da 100644 --- a/mod/lti/version.php +++ b/mod/lti/version.php @@ -1,4 +1,19 @@ . +// // This file is part of BasicLTI4Moodle // // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) @@ -16,35 +31,21 @@ // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis // of the Universitat Politecnica de Catalunya http://www.upc.edu // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . /** - * This file defines the version of basiclti - * This fragment is called by moodle_needs_upgrading() and /admin/index.php + * This file defines the version of lti * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ $module->version = 2011101801; // The current module version (Date: YYYYMMDDXX) +$module->requires = 2011070100; // Requires this Moodle version $module->cron = 0; // Period for cron to check this module (secs) diff --git a/mod/lti/view.php b/mod/lti/view.php index 212409f12e4..5723b4d0df2 100644 --- a/mod/lti/view.php +++ b/mod/lti/view.php @@ -1,4 +1,19 @@ . +// // This file is part of BasicLTI4Moodle // // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) @@ -16,33 +31,19 @@ // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis // of the Universitat Politecnica de Catalunya http://www.upc.edu // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . /** - * This file contains all necessary code to view a basiclti activity instance + * This file contains all necessary code to view a lti activity instance * - * @package lti - * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis + * @package mod + * @subpackage lti + * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis * marc.alier@upc.edu - * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu - * - * @author Marc Alier - * @author Jordi Piguillem - * @author Nikolas Galanis - * - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu + * @author Marc Alier + * @author Jordi Piguillem + * @author Nikolas Galanis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once('../../config.php'); From e27cb316aa70f8233e6cc4c1c3fabab07e8b8988 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Sun, 6 Nov 2011 22:00:40 -0500 Subject: [PATCH 54/78] MDL-20534 lti: A3, whitespace fixes (Changes by stronk7) --- mod/lti/ajax.php | 5 +- .../backup/moodle2/backup_lti_stepslib.php | 20 +- .../backup/moodle2/restore_lti_stepslib.php | 4 +- mod/lti/db/access.php | 6 +- mod/lti/db/upgrade.php | 20 +- mod/lti/edit_form.php | 26 +- mod/lti/grade.php | 10 +- mod/lti/instructor_edit_tool_type.php | 35 ++- mod/lti/lib.php | 26 +- mod/lti/locallib.php | 224 +++++++++--------- mod/lti/mod_form.js | 44 ++-- mod/lti/mod_form.php | 45 ++-- mod/lti/request_tool.php | 4 +- mod/lti/return.php | 34 +-- mod/lti/service.php | 68 +++--- mod/lti/servicelib.php | 64 ++--- mod/lti/settings.php | 26 +- mod/lti/simpletest/testlocallib.php | 16 +- mod/lti/submissions.js | 24 +- mod/lti/typessettings.php | 8 +- mod/lti/view.php | 8 +- 21 files changed, 354 insertions(+), 363 deletions(-) diff --git a/mod/lti/ajax.php b/mod/lti/ajax.php index e471039b7be..da3e385abea 100644 --- a/mod/lti/ajax.php +++ b/mod/lti/ajax.php @@ -37,15 +37,14 @@ $response = new stdClass(); switch($action){ case 'find_tool_config': $toolurl = required_param('toolurl', PARAM_RAW); - + $tool = lti_get_tool_by_url_match($toolurl, $courseid); - + if(!empty($tool)){ $response->toolid = $tool->id; $response->toolname = htmlspecialchars($tool->name); $response->tooldomain = htmlspecialchars($tool->tooldomain); } - break; } diff --git a/mod/lti/backup/moodle2/backup_lti_stepslib.php b/mod/lti/backup/moodle2/backup_lti_stepslib.php index dfdf68cb61a..224dc81c449 100644 --- a/mod/lti/backup/moodle2/backup_lti_stepslib.php +++ b/mod/lti/backup/moodle2/backup_lti_stepslib.php @@ -59,21 +59,21 @@ class backup_lti_activity_structure_step extends backup_activity_structure_step // Define each element separated $basiclti = new backup_nested_element('lti', array('id'), array( - 'name', - 'intro', - 'introformat', - 'timecreated', + 'name', + 'intro', + 'introformat', + 'timecreated', 'timemodified', - 'typeid', - 'toolurl', - 'preferheight', + 'typeid', + 'toolurl', + 'preferheight', 'launchcontainer', 'instructorchoicesendname', 'instructorchoicesendemailaddr', - 'instructorchoiceacceptgrades', + 'instructorchoiceacceptgrades', 'instructorchoiceallowroster', - 'instructorchoiceallowsetting', - 'grade', + 'instructorchoiceallowsetting', + 'grade', 'instructorcustomparameters', 'showtitle', 'showdescription' diff --git a/mod/lti/backup/moodle2/restore_lti_stepslib.php b/mod/lti/backup/moodle2/restore_lti_stepslib.php index 34a82f52d05..cf3efcd6fa5 100644 --- a/mod/lti/backup/moodle2/restore_lti_stepslib.php +++ b/mod/lti/backup/moodle2/restore_lti_stepslib.php @@ -69,9 +69,9 @@ class restore_lti_activity_structure_step extends restore_activity_structure_ste $data->course = $this->get_courseid(); require_once($CFG->dirroot.'/mod/lti/lib.php'); - + $newitemid = lti_add_instance($data); - + // insert the basiclti record //$newitemid = $DB->insert_record('lti', $data); // immediately after inserting "activity" record, call this diff --git a/mod/lti/db/access.php b/mod/lti/db/access.php index 63a21c29739..9966b74dbf3 100644 --- a/mod/lti/db/access.php +++ b/mod/lti/db/access.php @@ -53,7 +53,7 @@ $capabilities = array( 'manager' => CAP_ALLOW ) ), - + 'mod/lti:manage' => array( 'riskbitmask' => RISK_XSS, @@ -65,7 +65,7 @@ $capabilities = array( 'manager' => CAP_ALLOW ) ), - + 'mod/lti:addcoursetool' => array( 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, @@ -75,7 +75,7 @@ $capabilities = array( 'manager' => CAP_ALLOW ) ), - + 'mod/lti:requesttooladd' => array( 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, diff --git a/mod/lti/db/upgrade.php b/mod/lti/db/upgrade.php index b90b312492e..5f5ed91e571 100644 --- a/mod/lti/db/upgrade.php +++ b/mod/lti/db/upgrade.php @@ -61,7 +61,7 @@ function xmldb_lti_upgrade($oldversion=0) { global $DB; $dbman = $DB->get_manager(); - + if ($oldversion < 2011100701) { $table = new xmldb_table('lti'); $field = new xmldb_field('icon', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'servicesalt'); @@ -71,28 +71,26 @@ function xmldb_lti_upgrade($oldversion=0) { } upgrade_mod_savepoint(true, 2011100701, 'lti'); - } - + } + if ($oldversion < 2011101801) { $table = new xmldb_table('lti'); $field = new xmldb_field('securetoolurl', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'toolurl'); - + if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } - + $field = new xmldb_field('secureicon', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'icon'); - + if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); - } - + } + upgrade_mod_savepoint(true, 2011101801, 'lti'); } - - $result = true; - + $result = true; return $result; } diff --git a/mod/lti/edit_form.php b/mod/lti/edit_form.php index 14a6345dafe..e7a7650a0bf 100644 --- a/mod/lti/edit_form.php +++ b/mod/lti/edit_form.php @@ -59,11 +59,10 @@ class mod_lti_edit_types_form extends moodleform{ //------------------------------------------------------------------------------- // Add basiclti elements $mform->addElement('header', 'setup', get_string('tool_settings', 'lti')); - + $mform->addElement('text', 'lti_typename', get_string('typename', 'lti')); $mform->setType('lti_typename', PARAM_INT); $mform->addHelpButton('lti_typename', 'typename','lti'); - $mform->addRule('lti_typename', null, 'required', null, 'client'); $mform->addElement('text', 'lti_toolurl', get_string('toolurl', 'lti'), array('size'=>'64')); @@ -74,24 +73,24 @@ class mod_lti_edit_types_form extends moodleform{ $mform->addElement('text', 'lti_resourcekey', get_string('resourcekey_admin', 'lti')); $mform->setType('lti_resourcekey', PARAM_TEXT); $mform->addHelpButton('lti_resourcekey', 'resourcekey_admin', 'lti'); - + $mform->addElement('passwordunmask', 'lti_password', get_string('password_admin', 'lti')); $mform->setType('lti_password', PARAM_TEXT); $mform->addHelpButton('lti_password', 'password_admin', 'lti'); - + $mform->addElement('textarea', 'lti_customparameters', get_string('custom', 'lti'), array('rows'=>4, 'cols'=>60)); $mform->setType('lti_customparameters', PARAM_TEXT); $mform->addHelpButton('lti_customparameters', 'custom', 'lti'); - + if(!empty($this->_customdata->isadmin)){ $mform->addElement('checkbox', 'lti_coursevisible', ' ', ' ' . get_string('show_in_course', 'lti')); $mform->addHelpButton('lti_coursevisible', 'show_in_course', 'lti'); } else { $mform->addElement('hidden', 'lti_coursevisible', '1'); } - + $mform->addElement('hidden', 'typeid'); - + $launchoptions=array(); $launchoptions[LTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'lti'); $launchoptions[LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'lti'); @@ -100,7 +99,7 @@ class mod_lti_edit_types_form extends moodleform{ $mform->addElement('select', 'lti_launchcontainer', get_string('default_launch_container', 'lti'), $launchoptions); $mform->setDefault('lti_launchcontainer', LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS); $mform->addHelpButton('lti_launchcontainer', 'default_launch_container', 'lti'); - + // Add privacy preferences fieldset where users choose whether to send their data $mform->addElement('header', 'privacy', get_string('privacy', 'lti')); @@ -132,9 +131,8 @@ class mod_lti_edit_types_form extends moodleform{ $mform->addElement('checkbox', 'lti_forcessl',' ', ' ' . get_string('force_ssl', 'lti'), $options); $mform->setDefault('lti_forcessl', '0'); - $mform->addHelpButton('lti_forcessl', 'force_ssl', 'lti'); - + if(!empty($this->_customdata->isadmin)){ //------------------------------------------------------------------------------- // Add setup parameters fieldset @@ -153,7 +151,7 @@ class mod_lti_edit_types_form extends moodleform{ $mform->setType('lti_organizationurl', PARAM_TEXT); $mform->addHelpButton('lti_organizationurl', 'organizationurl', 'lti'); } - + /* Suppress this for now - Chuck $mform->addElement('text', 'lti_organizationdescr', get_string('organizationdescr', 'lti')); $mform->setType('lti_organizationdescr', PARAM_TEXT); @@ -163,13 +161,13 @@ class mod_lti_edit_types_form extends moodleform{ //------------------------------------------------------------------------------- // Add a hidden element to signal a tool fixing operation after a problematic backup - restore process //$mform->addElement('hidden', 'lti_fix'); - + $tab = optional_param('tab', '', PARAM_ALPHAEXT); $mform->addElement('hidden', 'tab', $tab); - + $courseid = optional_param('course', 1, PARAM_INT); $mform->addElement('hidden', 'course', $courseid); - + //------------------------------------------------------------------------------- // Add standard buttons, common to all modules $this->add_action_buttons(); diff --git a/mod/lti/grade.php b/mod/lti/grade.php index a7d81c52c5a..b6ba5f95b04 100644 --- a/mod/lti/grade.php +++ b/mod/lti/grade.php @@ -96,9 +96,7 @@ $module = array( 'name' => 'mod_lti_submissions', 'fullpath' => '/mod/lti/submissions.js', 'requires' => array('base'), - 'strings' => array( - - ), + 'strings' => array(), ); $PAGE->requires->js_init_call('M.mod_lti.submissions.init', array(), true, $module); @@ -158,15 +156,15 @@ $rows = ''; foreach($submissions as $submission){ $row = $rowtemplate; - + foreach($submission as $key => $value){ if($key === 'datesubmitted'){ $value = userdate($value); } - + $row = str_replace('', $value, $row); } - + $rows .= $row; } diff --git a/mod/lti/instructor_edit_tool_type.php b/mod/lti/instructor_edit_tool_type.php index 8c91eed5fd0..ab9e9aa0af8 100644 --- a/mod/lti/instructor_edit_tool_type.php +++ b/mod/lti/instructor_edit_tool_type.php @@ -42,7 +42,6 @@ if(!empty($typeid)){ $type = lti_get_type($typeid); if($type->course != $courseid){ throw new Exception('You do not have permissions to edit this tool type.'); - die; } } @@ -53,65 +52,61 @@ $data = data_submitted(); if (isset($data->submitbutton) && confirm_sesskey()) { $type = new stdClass(); - + if (!empty($typeid)) { $type->id = $typeid; $name = json_encode($data->lti_typename); lti_update_type($type, $data); - + $fromdb = lti_get_type($typeid); $json = json_encode($fromdb); - + //Output script to update the calling window. $script = << SCRIPT; - + echo $script; - die; } else { $type->state = LTI_TOOL_STATE_CONFIGURED; $type->course = $COURSE->id; - + $id = lti_add_type($type, $data); - + $fromdb = lti_get_type($id); $json = json_encode($fromdb); - + //Output script to update the calling window. $script = << SCRIPT; - + echo $script; - + die; } } else if(isset($data->cancel)){ - $script = << + $script = << SCRIPT; - - echo $script; + + echo $script; die; } //Delete action is called via ajax if ($action == 'delete'){ lti_delete_type($typeid); - die; } diff --git a/mod/lti/lib.php b/mod/lti/lib.php index 7b27699493b..b713b157479 100644 --- a/mod/lti/lib.php +++ b/mod/lti/lib.php @@ -84,22 +84,22 @@ function lti_add_instance($formdata) { $formdata->timecreated = time(); $formdata->timemodified = $formdata->timecreated; $formdata->servicesalt = uniqid('', true); - + if(!isset($formdata->grade)){ $formdata->grade = 100; } - + $id = $DB->insert_record("lti", $formdata); if ($formdata->instructorchoiceacceptgrades == LTI_SETTING_ALWAYS) { $basiclti = $DB->get_record('lti', array('id'=>$id)); - + if(!isset($formdata->cmidnumber)){ $formdata->cmidnumber = ''; } - + $basiclti->cmidnumber = $formdata->cmidnumber; - + lti_grade_item_update($basiclti); } @@ -123,15 +123,15 @@ function lti_update_instance($formdata) { if(!isset($formdata->showtitle)){ $formdata->showtitle = 0; } - + if(!isset($formdata->showdescription)){ $formdata->showdescription = 0; } - + if ($formdata->instructorchoiceacceptgrades == LTI_SETTING_ALWAYS) { $basicltirec = $DB->get_record("lti", array("id" => $formdata->id)); $basicltirec->cmidnumber = $formdata->cmidnumber; - + lti_grade_item_update($basicltirec); } else { lti_grade_item_delete($formdata); @@ -165,11 +165,11 @@ function lti_delete_instance($id) { function lti_get_coursemodule_info($coursemodule){ global $DB; - + $lti = $DB->get_record('lti', array('id' => $coursemodule->instance), 'icon, secureicon'); $info = new stdClass(); - + //We want to use the right icon based on whether the current page is being requested over http or https. //There's a potential problem here as the icon URLs are cached in the modinfo field and won't be updated for each request. if(lti_request_is_using_ssl() && !empty($lti->secureicon)){ @@ -179,7 +179,7 @@ function lti_get_coursemodule_info($coursemodule){ $info->icon = $lti->icon; } } - + return $info; } @@ -389,10 +389,10 @@ function lti_grade_item_delete($basiclti) { function lti_extend_settings_navigation($settings, $parentnode) { global $PAGE; - + if(has_capability('mod/lti:grade', get_context_instance(CONTEXT_MODULE, $PAGE->cm->id))){ $keys = $parentnode->get_children_key_list(); - + $node = navigation_node::create('Submissions', new moodle_url('/mod/lti/grade.php', array('id'=>$PAGE->cm->id)), navigation_node::TYPE_SETTING, null, 'mod_lti_submissions'); diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index 6a09b307307..ae69fc1f4fa 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -87,13 +87,13 @@ function lti_view($instance) { } else { $typeid = $instance->typeid; } - + if($typeid){ $typeconfig = lti_get_type_config($typeid); } else { //There is no admin configuration for this tool. Use configuration in the lti instance record plus some defaults. $typeconfig = (array)$instance; - + $typeconfig['sendname'] = $instance->instructorchoicesendname; $typeconfig['sendemailaddr'] = $instance->instructorchoicesendemailaddr; $typeconfig['customparameters'] = $instance->instructorcustomparameters; @@ -101,14 +101,14 @@ function lti_view($instance) { $typeconfig['allowroster'] = $instance->instructorchoiceallowroster; $typeconfig['forcessl'] = '0'; } - + //Default the organizationid if not specified if(empty($typeconfig['organizationid'])){ $urlparts = parse_url($CFG->wwwroot); - + $typeconfig['organizationid'] = $urlparts['host']; } - + if(!empty($instance->resourcekey)){ $key = $instance->resourcekey; } else if(!empty($typeconfig['resourcekey'])){ @@ -124,28 +124,28 @@ function lti_view($instance) { } else { $secret = ''; } - + $endpoint = !empty($instance->toolurl) ? $instance->toolurl : $typeconfig['toolurl']; $endpoint = trim($endpoint); - + //If the current request is using SSL and a secure tool URL is specified, use it if(lti_request_is_using_ssl() && !empty($instance->securetoolurl)){ $endpoint = trim($instance->securetoolurl); } - + //If SSL is forced, use the secure tool url if specified. Otherwise, make sure https is on the normal launch URL. if($typeconfig['forcessl'] == '1'){ if(!empty($instance->securetoolurl)){ $endpoint = trim($instance->securetoolurl); } - + $endpoint = lti_ensure_url_is_https($endpoint); } else { if(!strstr($endpoint, '://')){ $endpoint = 'http://' . $endpoint; } } - + $orgid = $typeconfig['organizationid']; $course = $PAGE->course; @@ -153,42 +153,42 @@ function lti_view($instance) { $launchcontainer = lti_get_launch_container($instance, $typeconfig); $returnurlparams = array('course' => $course->id, 'launch_container' => $launchcontainer, 'instanceid' => $instance->id); - + if ( $orgid ) { $requestparams["tool_consumer_instance_guid"] = $orgid; } - + if(empty($key) || empty($secret)){ $returnurlparams['unsigned'] = '1'; - + //Add the return URL. We send the launch container along to help us avoid frames-within-frames when the user returns $url = new moodle_url('/mod/lti/return.php', $returnurlparams); $returnurl = $url->out(false); - + if($typeconfig['forcessl'] == '1'){ $returnurl = lti_ensure_url_is_https($returnurl); } - + $requestparams['launch_presentation_return_url'] = $returnurl; } - + if(!empty($key) && !empty($secret)){ $parms = lti_sign_parameters($requestparams, $endpoint, "POST", $key, $secret); } else { //If no key and secret, do the launch unsigned. $parms = $requestparams; } - + $debuglaunch = ( $instance->debuglaunch == 1 ); - + $content = lti_post_launch_html($parms, $endpoint, $debuglaunch); - + echo $content; } function lti_build_sourcedid($instanceid, $userid, $launchid = null, $servicesalt){ $data = new stdClass(); - + $data->instanceid = $instanceid; $data->userid = $userid; if(!empty($launchid)){ @@ -223,7 +223,7 @@ function lti_build_request($instance, $typeconfig, $course) { if(empty($instance->cmid)){ $instance->cmid = 0; } - + $role = lti_get_ims_role($USER, $instance->cmid, $instance->course); $locale = $course->lang; @@ -244,7 +244,7 @@ function lti_build_request($instance, $typeconfig, $course) { ); $placementsecret = $instance->servicesalt; - + if ( isset($placementsecret) ) { $sourcedid = json_encode(lti_build_sourcedid($instance->id, $USER->id, null, $placementsecret)); } @@ -253,12 +253,12 @@ function lti_build_request($instance, $typeconfig, $course) { ( $typeconfig['acceptgrades'] == LTI_SETTING_ALWAYS || ( $typeconfig['acceptgrades'] == LTI_SETTING_DELEGATE && $instance->instructorchoiceacceptgrades == LTI_SETTING_ALWAYS ) ) ) { $requestparams["lis_result_sourcedid"] = $sourcedid; - + $serviceurl = $CFG->wwwroot . '/mod/lti/service.php'; if($typeconfig['forcessl'] == '1'){ $serviceurl = lti_ensure_url_is_https($serviceurl); } - + $requestparams["ext_ims_lis_basic_outcome_url"] = $serviceurl; } @@ -322,29 +322,29 @@ function lti_build_request($instance, $typeconfig, $course) { //This needs to be here to support launching without javascript. $submittext = get_string('press_to_submit', 'lti'); $requestparams["ext_submit"] = $submittext; - + $requestparams["lti_version"] = "LTI-1p0"; $requestparams["lti_message_type"] = "basic-lti-launch-request"; /* Suppress this for now - Chuck if ( $orgdesc ) $requestparams["tool_consumer_instance_description"] = $orgdesc; */ - + return $requestparams; } function lti_get_tool_table($tools, $id){ global $CFG, $USER; $html = ''; - + $typename = get_string('typename', 'lti'); $baseurl = get_string('baseurl', 'lti'); $action = get_string('action', 'lti'); $createdon = get_string('createdon', 'lti'); - + if($id == 'lti_configured'){ $html .= ''; } - + if (!empty($tools)) { $html .= << @@ -358,13 +358,13 @@ function lti_get_tool_table($tools, $id){ HTML; - + foreach ($tools as $type) { $date = userdate($type->timecreated); $accept = get_string('accept', 'lti'); $update = get_string('update', 'lti'); $delete = get_string('delete', 'lti'); - + $accepthtml = << {$accept} @@ -372,16 +372,16 @@ HTML; HTML; $deleteaction = 'delete'; - + if($type->state == LTI_TOOL_STATE_CONFIGURED){ $accepthtml = ''; } - + if($type->state != LTI_TOOL_STATE_REJECTED) { $deleteaction = 'reject'; $delete = get_string('reject', 'lti'); } - + $html .= << @@ -409,7 +409,7 @@ HTML; } else { $html .= get_string('no_' . $id, 'lti'); } - + return $html; } @@ -462,20 +462,20 @@ function lti_map_keyname($key) { /** * Gets the IMS role string for the specified user and LTI course module. - * + * * @param mixed $user User object or user id * @param int $cmid The course module id of the LTI activity * @return string A role string suitable for passing with an LTI launch */ function lti_get_ims_role($user, $cmid, $courseid) { $roles = array(); - + if(empty($cmid)){ //If no cmid is passed, check if the user is a teacher in the course //This allows other modules to programmatically "fake" a launch without //a real LTI instance $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid); - + if(has_capability('moodle/course:manageactivities', $coursecontext)){ array_push($roles, 'Instructor'); } else { @@ -494,7 +494,7 @@ function lti_get_ims_role($user, $cmid, $courseid) { if(is_siteadmin($user)){ array_push($roles, 'urn:lti:sysrole:ims/lis/Administrator'); } - + return join(',', $roles); } @@ -512,48 +512,48 @@ function lti_get_type_config($typeid) { SELECT name, value FROM {lti_types_config} WHERE typeid = :typeid1 - + UNION ALL - + SELECT 'toolurl' AS name, baseurl AS value FROM {lti_types} WHERE id = :typeid2 QUERY; - + $typeconfig = array(); $configs = $DB->get_records_sql($query, array('typeid1' => $typeid, 'typeid2' => $typeid)); - + if (!empty($configs)) { foreach ($configs as $config) { $typeconfig[$config->name] = $config->value; } } - + return $typeconfig; } function lti_get_tools_by_url($url, $state, $courseid = null){ $domain = lti_get_domain_from_url($url); - + return lti_get_tools_by_domain($domain, $state, $courseid); } function lti_get_tools_by_domain($domain, $state = null, $courseid = null){ global $DB, $SITE; - + $filters = array('tooldomain' => $domain); - + $statefilter = ''; $coursefilter = ''; - + if($state){ $statefilter = 'AND state = :state'; } - + if($courseid && $courseid != $SITE->id){ $coursefilter = 'OR course = :courseid'; } - + $query = <<get_records_sql($query, array( - 'courseid' => $courseid, - 'siteid' => $SITE->id, - 'tooldomain' => $domain, + 'courseid' => $courseid, + 'siteid' => $SITE->id, + 'tooldomain' => $domain, 'state' => $state )); } @@ -582,13 +582,13 @@ function lti_filter_get_types($course) { } else { $filter = array(); } - + return $DB->get_records('lti_types', $filter); } function lti_get_types_for_add_instance(){ global $DB, $SITE, $COURSE; - + $query = <<get_records_sql($query, array('siteid' => $SITE->id, 'courseid' => $COURSE->id, 'active' => LTI_TOOL_STATE_CONFIGURED)); - + $types = array(); $types[0] = (object)array('name' => get_string('automatic', 'lti'), 'course' => $SITE->id); - + foreach($admintypes as $type) { $types[$type->id] = $type; } - + return $types; } function lti_get_domain_from_url($url){ $matches = array(); - + if(preg_match(LTI_URL_DOMAIN_REGEX, $url, $matches)){ return $matches[1]; } @@ -620,7 +620,7 @@ function lti_get_domain_from_url($url){ function lti_get_tool_by_url_match($url, $courseid = null, $state = LTI_TOOL_STATE_CONFIGURED){ $possibletools = lti_get_tools_by_url($url, $state, $courseid); - + return lti_get_best_tool_by_url($url, $possibletools, $courseid); } @@ -629,15 +629,15 @@ function lti_get_url_thumbprint($url){ if(!isset($urlparts['path'])){ $urlparts['path'] = ''; } - + if(!isset($urlparts['host'])){ $urlparts['host'] = ''; } - + if(substr($urlparts['host'], 0, 4) === 'www.'){ $urlparts['host'] = substr($urlparts['host'], 4); } - + return $urllower = $urlparts['host'] . '/' . $urlparts['path']; } @@ -645,14 +645,14 @@ function lti_get_best_tool_by_url($url, $tools, $courseid = null){ if(count($tools) === 0){ return null; } - + $urllower = lti_get_url_thumbprint($url); - + foreach($tools as $tool){ $tool->_matchscore = 0; - + $toolbaseurllower = lti_get_url_thumbprint($tool->baseurl); - + if($urllower === $toolbaseurllower){ //100 points for exact thumbprint match $tool->_matchscore += 100; @@ -660,7 +660,7 @@ function lti_get_best_tool_by_url($url, $tools, $courseid = null){ //50 points if tool thumbprint starts with the base URL thumbprint $tool->_matchscore += 50; } - + //Prefer course tools over site tools if(!empty($courseid)){ //Minus 25 points for not matching the course id (global tools) @@ -669,27 +669,27 @@ function lti_get_best_tool_by_url($url, $tools, $courseid = null){ } } } - + $bestmatch = array_reduce($tools, function($value, $tool){ if($tool->_matchscore > $value->_matchscore){ return $tool; } else { return $value; } - + }, (object)array('_matchscore' => -1)); - + //None of the tools are suitable for this URL if($bestmatch->_matchscore <= 0){ return null; } - + return $bestmatch; } function lti_get_shared_secrets_by_key($key){ global $DB; - + //Look up the shared secret for the specified key in both the types_config table (for configured tools) //And in the lti resource table for ad-hoc tools $query = <<get_records_sql($query, array('configured' => LTI_TOOL_STATE_CONFIGURED, 'key1' => $key, 'key2' => $key)); - + $values = array_map(function($item){ return $item->value; }, $sharedsecrets); - + //There should really only be one shared secret per key. But, we can't prevent //more than one getting entered. For instance, if the same key is used for two tool providers. return $values; @@ -775,7 +775,7 @@ function lti_delete_type($id) { function lti_set_state_for_type($id, $state){ global $DB; - + $DB->update_record('lti_types', array('id' => $id, 'state' => $state)); } @@ -847,11 +847,11 @@ function lti_get_type_type_config($id) { $config = lti_get_type_config($id); $type->lti_typename = $basicltitype->name; - + $type->typeid = $basicltitype->id; - + $type->lti_toolurl = $basicltitype->baseurl; - + if (isset($config['resourcekey'])) { $type->lti_resourcekey = $config['resourcekey']; } @@ -891,7 +891,7 @@ function lti_get_type_type_config($id) { if(isset($config['forcessl'])){ $type->lti_forcessl = $config['forcessl']; } - + if (isset($config['organizationid'])) { $type->lti_organizationid = $config['organizationid']; } @@ -904,15 +904,15 @@ function lti_get_type_type_config($id) { if (isset($config['launchcontainer'])) { $type->lti_launchcontainer = $config['launchcontainer']; } - + if (isset($config['coursevisible'])) { $type->lti_coursevisible = $config['coursevisible']; } - + if (isset($config['debuglaunch'])) { $type->lti_debuglaunch = $config['debuglaunch']; } - + if (isset($config['module_class_type'])) { $type->lti_module_class_type = $config['module_class_type']; } @@ -924,24 +924,24 @@ function lti_prepare_type_for_save($type, $config){ $type->baseurl = $config->lti_toolurl; $type->tooldomain = lti_get_domain_from_url($config->lti_toolurl); $type->name = $config->lti_typename; - + $type->coursevisible = !empty($config->lti_coursevisible) ? $config->lti_coursevisible : 0; $config->lti_coursevisible = $type->coursevisible; - + $type->forcessl = !empty($config->lti_forcessl) ? $config->lti_forcessl : 0; $config->lti_forcessl = $type->forcessl; - + $type->timemodified = time(); - + unset ($config->lti_typename); unset ($config->lti_toolurl); } function lti_update_type($type, $config){ global $DB; - + lti_prepare_type_for_save($type, $config); - + if ($DB->update_record('lti_types', $type)) { foreach ($config as $key => $value) { if (substr($key, 0, 4)=='lti_' && !is_null($value)) { @@ -949,7 +949,7 @@ function lti_update_type($type, $config){ $record->typeid = $type->id; $record->name = substr($key, 4); $record->value = $value; - + lti_update_config($record); } } @@ -958,25 +958,25 @@ function lti_update_type($type, $config){ function lti_add_type($type, $config){ global $USER, $SITE, $DB; - + lti_prepare_type_for_save($type, $config); - + if(!isset($type->state)){ $type->state = LTI_TOOL_STATE_PENDING; } - + if(!isset($type->timecreated)){ $type->timecreated = time(); } - + if(!isset($type->createdby)){ $type->createdby = $USER->id; } - + if(!isset($type->course)){ $type->course = $SITE->id; } - + //Create a salt value to be used for signing passed data to extension services //The outcome service uses the service salt on the instance. This can be used //for communication with services not related to a specific LTI instance. @@ -996,7 +996,7 @@ function lti_add_type($type, $config){ } } } - + return $id; } @@ -1025,7 +1025,7 @@ function lti_update_config($config) { $return = true; $old = $DB->get_record('lti_types_config', array('typeid' => $config->typeid, 'name' => $config->name)); - + if ($old) { $config->id = $old->id; $return = $DB->update_record('lti_types_config', $config); @@ -1052,7 +1052,7 @@ function lti_sign_parameters($oldparms, $endpoint, $method, $oauthconsumerkey, $ $parms = $oldparms; $testtoken = ''; - + $hmacmethod = new lti\OAuthSignatureMethod_HMAC_SHA1(); $testconsumer = new lti\OAuthConsumer($oauthconsumerkey, $oauthconsumersecret, null); @@ -1076,9 +1076,9 @@ function lti_sign_parameters($oldparms, $endpoint, $method, $oauthconsumerkey, $ */ function lti_post_launch_html($newparms, $endpoint, $debug=false) { //global $lastbasestring; - + $r = "
\n"; - + $submittext = $newparms['ext_submit']; // Contruct html for the launch parameters @@ -1147,11 +1147,15 @@ function lti_post_launch_html($newparms, $endpoint, $debug=false) { function lti_get_type($typeid){ global $DB; - + return $DB->get_record('lti_types', array('id' => $typeid)); } function lti_get_launch_container($lti, $toolconfig){ + if(empty($lti->launchcontainer)){ + $lti->launchcontainer = LTI_LAUNCH_CONTAINER_DEFAULT; + } + if($lti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT){ if(isset($toolconfig['launchcontainer'])){ $launchcontainer = $toolconfig['launchcontainer']; @@ -1159,7 +1163,7 @@ function lti_get_launch_container($lti, $toolconfig){ } else { $launchcontainer = $lti->launchcontainer; } - + if(empty($launchcontainer) || $launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT){ $launchcontainer = LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS; } @@ -1172,7 +1176,7 @@ function lti_get_launch_container($lti, $toolconfig){ if($devicetype === 'mobile' || $devicetype === 'tablet' ){ $launchcontainer = LTI_LAUNCH_CONTAINER_REPLACE_MOODLE_WINDOW; } - + return $launchcontainer; } @@ -1190,6 +1194,6 @@ function lti_ensure_url_is_https($url){ $url = 'https://' . substr($url, 8); } } - + return $url; } diff --git a/mod/lti/mod_form.js b/mod/lti/mod_form.js index f11aa3b08e8..d9c94f31e19 100644 --- a/mod/lti/mod_form.js +++ b/mod/lti/mod_form.js @@ -23,7 +23,7 @@ */ (function(){ var Y; - + M.mod_lti = M.mod_lti || {}; M.mod_lti.editor = { @@ -31,7 +31,7 @@ if(yui3){ Y = yui3; } - + var self = this; this.settings = Y.JSON.parse(settings); @@ -47,21 +47,21 @@ var typeSelector = Y.one('#id_typeid'); typeSelector.on('change', function(e){ updateToolMatches(); - + self.toggleEditButtons(); }); this.createTypeEditorButtons(); this.toggleEditButtons(); - + var textAreas = new Y.NodeList([ Y.one('#id_toolurl'), Y.one('#id_securetoolurl'), Y.one('#id_resourcekey'), Y.one('#id_password') ]); - + var debounce; textAreas.on('keyup', function(e){ clearTimeout(debounce); @@ -71,7 +71,7 @@ updateToolMatches(); }, 2000); }); - + updateToolMatches(); }, @@ -81,10 +81,10 @@ updateAutomaticToolMatch: function(field){ var self = this; - + var toolurl = field; var typeSelector = Y.one('#id_typeid'); - + var id = field.get('id') + '_lti_automatch_tool'; var automatchToolDisplay = Y.one('#' + id); @@ -92,7 +92,7 @@ automatchToolDisplay = Y.Node.create('') .set('id', id) .setStyle('padding-left', '1em'); - + toolurl.insert(automatchToolDisplay, 'after'); } @@ -120,7 +120,7 @@ //The entered URL does not match the domain of the tool configuration automatchToolDisplay.set('innerHTML', '' + M.str.lti.domain_mismatch); } - + return; } @@ -141,7 +141,7 @@ } } }; - + //Cache urls which have already been checked to increaes performance if(self.urlCache[url]){ continuation(self.urlCache[url]); @@ -190,7 +190,7 @@ if(globalOptions.size() > 0){ typeSelector.append(globalGroup); } - + if(courseOptions.size() > 0){ typeSelector.append(courseGroup); } @@ -203,11 +203,11 @@ */ createTypeEditorButtons: function(){ var self = this; - + var typeSelector = Y.one('#id_typeid'); var createIcon = function(id, tooltip, iconUrl){ - return Y.Node.create('') + return Y.Node.create('') .set('id', id) .set('title', tooltip) .setStyle('margin-left', '.5em') @@ -282,7 +282,7 @@ } else { typeSelector.append(option); } - + //Adding the new tool may affect which tool gets matched automatically this.clearToolCache(); this.updateAutomaticToolMatch(); @@ -294,7 +294,7 @@ var option = typeSelector.one('option[value=' + toolType.id + ']'); option.set('text', toolType.name) .set('domain', toolType.tooldomain); - + //Editing the tool may affect which tool gets matched automatically this.clearToolCache(); this.updateAutomaticToolMatch(); @@ -302,12 +302,12 @@ deleteTool: function(toolTypeId){ var self = this; - + Y.io(self.settings.instructor_tool_type_edit_url + '&action=delete&typeid=' + toolTypeId, { on: { success: function(){ self.getSelectedToolTypeOption().remove(); - + //Editing the tool may affect which tool gets matched automatically self.clearToolCache(); self.updateAutomaticToolMatch(); @@ -321,8 +321,8 @@ findToolByUrl: function(url, callback){ var self = this; - - Y.io(self.settings.ajax_url, { + + Y.io(self.settings.ajax_url, { data: {action: 'find_tool_config', course: self.settings.courseId, toolurl: url @@ -331,9 +331,9 @@ on: { success: function(transactionid, xhr){ var response = xhr.response; - + var toolInfo = Y.JSON.parse(response); - + callback(toolInfo); }, failure: function(){ diff --git a/mod/lti/mod_form.php b/mod/lti/mod_form.php index 2c79049264b..533a115840d 100644 --- a/mod/lti/mod_form.php +++ b/mod/lti/mod_form.php @@ -57,7 +57,7 @@ class mod_lti_mod_form extends moodleform_mod { global $DB, $PAGE, $OUTPUT, $USER, $COURSE; $this->typeid = 0; - + $mform =& $this->_form; //------------------------------------------------------------------------------- /// Adding the "general" fieldset, where all the common settings are shown @@ -73,15 +73,15 @@ class mod_lti_mod_form extends moodleform_mod { $mform->addElement('checkbox', 'showtitle', ' ', ' ' . get_string('display_name', 'lti')); $mform->setAdvanced('showtitle'); $mform->addHelpButton('showtitle', 'display_name', 'lti'); - + $mform->addElement('checkbox', 'showdescription', ' ', ' ' . get_string('display_description', 'lti')); $mform->setAdvanced('showdescription'); $mform->addHelpButton('showdescription', 'display_description', 'lti'); - + //Tool settings $tooltypes = $mform->addElement('select', 'typeid', get_string('external_tool_type', 'lti'), array()); $mform->addHelpButton('typeid', 'external_tool_type', 'lti'); - + foreach(lti_get_types_for_add_instance() as $id => $type){ if($type->course == $COURSE->id) { $attributes = array( 'editable' => 1, 'courseTool' => 1, 'domain' => $type->tooldomain ); @@ -90,19 +90,19 @@ class mod_lti_mod_form extends moodleform_mod { } else { $attributes = array(); } - + $tooltypes->addOption($type->name, $id, $attributes); } - + $mform->addElement('text', 'toolurl', get_string('launch_url', 'lti'), array('size'=>'64')); $mform->setType('toolurl', PARAM_TEXT); $mform->addHelpButton('toolurl', 'launch_url', 'lti'); - + $mform->addElement('text', 'securetoolurl', get_string('secure_launch_url', 'lti'), array('size'=>'64')); $mform->setType('securetoolurl', PARAM_TEXT); $mform->setAdvanced('securetoolurl'); $mform->addHelpButton('securetoolurl', 'secure_launch_url', 'lti'); - + $launchoptions=array(); $launchoptions[LTI_LAUNCH_CONTAINER_DEFAULT] = get_string('default', 'lti'); $launchoptions[LTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'lti'); @@ -112,32 +112,32 @@ class mod_lti_mod_form extends moodleform_mod { $mform->addElement('select', 'launchcontainer', get_string('launchinpopup', 'lti'), $launchoptions); $mform->setDefault('launchcontainer', LTI_LAUNCH_CONTAINER_DEFAULT); $mform->addHelpButton('launchcontainer', 'launchinpopup', 'lti'); - + $mform->addElement('text', 'resourcekey', get_string('resourcekey', 'lti')); $mform->setType('resourcekey', PARAM_TEXT); $mform->setAdvanced('resourcekey'); $mform->addHelpButton('resourcekey', 'resourcekey', 'lti'); - + $mform->addElement('passwordunmask', 'password', get_string('password', 'lti')); $mform->setType('password', PARAM_TEXT); $mform->setAdvanced('password'); $mform->addHelpButton('password', 'password', 'lti'); - + $mform->addElement('textarea', 'instructorcustomparameters', get_string('custom', 'lti'), array('rows'=>4, 'cols'=>60)); $mform->setType('instructorcustomparameters', PARAM_TEXT); $mform->setAdvanced('instructorcustomparameters'); $mform->addHelpButton('instructorcustomparameters', 'custom', 'lti'); - + $mform->addElement('text', 'icon', get_string('icon_url', 'lti'), array('size'=>'64')); $mform->setType('icon', PARAM_TEXT); $mform->setAdvanced('icon'); $mform->addHelpButton('icon', 'icon_url', 'lti'); - + $mform->addElement('text', 'secureicon', get_string('secure_icon_url', 'lti'), array('size'=>'64')); $mform->setType('secureicon', PARAM_TEXT); $mform->setAdvanced('secureicon'); $mform->addHelpButton('secureicon', 'secure_icon_url', 'lti'); - + //------------------------------------------------------------------------------- // Add privacy preferences fieldset where users choose whether to send their data $mform->addElement('header', 'privacy', get_string('privacy', 'lti')); @@ -145,19 +145,19 @@ class mod_lti_mod_form extends moodleform_mod { $mform->addElement('checkbox', 'instructorchoicesendname', ' ', ' ' . get_string('share_name', 'lti')); $mform->setDefault('instructorchoicesendname', '1'); $mform->addHelpButton('instructorchoicesendname', 'share_name', 'lti'); - + $mform->addElement('checkbox', 'instructorchoicesendemailaddr', ' ', ' ' . get_string('share_email', 'lti')); $mform->setDefault('instructorchoicesendemailaddr', '1'); $mform->addHelpButton('instructorchoicesendemailaddr', 'share_email', 'lti'); - + $mform->addElement('checkbox', 'instructorchoiceacceptgrades', ' ', ' ' . get_string('accept_grades', 'lti')); $mform->setDefault('instructorchoiceacceptgrades', '1'); $mform->addHelpButton('instructorchoiceacceptgrades', 'accept_grades', 'lti'); - + $mform->addElement('checkbox', 'instructorchoiceallowroster', ' ', ' ' . get_string('share_roster', 'lti')); $mform->setDefault('instructorchoiceallowroster', '1'); $mform->addHelpButton('instructorchoiceallowroster', 'share_roster', 'lti'); - + //------------------------------------------------------------------------------- /* $debugoptions=array(); @@ -178,7 +178,6 @@ class mod_lti_mod_form extends moodleform_mod { //------------------------------------------------------------------------------- // add standard elements, common to all modules $this->standard_coursemodule_elements(); - $mform->setAdvanced('cmidnumber'); //------------------------------------------------------------------------------- // add standard buttons, common to all modules @@ -186,7 +185,7 @@ class mod_lti_mod_form extends moodleform_mod { $editurl = new moodle_url("/mod/lti/instructor_edit_tool_type.php?sesskey={$USER->sesskey}&course={$COURSE->id}"); $ajaxurl = new moodle_url('/mod/lti/ajax.php'); - + $jsinfo = (object)array( 'edit_icon_url' => (string)$OUTPUT->pix_url('t/edit'), 'add_icon_url' => (string)$OUTPUT->pix_url('t/add'), @@ -197,7 +196,7 @@ class mod_lti_mod_form extends moodleform_mod { 'ajax_url' => $ajaxurl->out(true), 'courseId' => $COURSE->id ); - + $module = array( 'name' => 'mod_lti_edit', 'fullpath' => '/mod/lti/mod_form.js', @@ -217,7 +216,7 @@ class mod_lti_mod_form extends moodleform_mod { array('tool_config_not_found', 'lti') ), ); - + $PAGE->requires->js_init_call('M.mod_lti.editor.init', array(json_encode($jsinfo)), true, $module); } @@ -227,7 +226,7 @@ class mod_lti_mod_form extends moodleform_mod { */ function definition_after_data() { parent::definition_after_data(); - + //$mform =& $this->_form; } diff --git a/mod/lti/request_tool.php b/mod/lti/request_tool.php index a49d18ecb17..6e4fae61818 100644 --- a/mod/lti/request_tool.php +++ b/mod/lti/request_tool.php @@ -54,11 +54,11 @@ if(!lti_get_tool_by_url_match($lti->toolurl, $lti->course, LTI_TOOL_STATE_ANY)){ $tooltype = new stdClass(); $toolconfig = new stdClass(); - $toolconfig->lti_toolurl = lti_get_domain_from_url($lti->toolurl); + $toolconfig->lti_toolurl = lti_get_domain_from_url($lti->toolurl); $toolconfig->lti_typename = $toolconfig->lti_toolurl; lti_add_type($tooltype, $toolconfig); - + echo get_string('lti_tool_request_added', 'lti'); } else { echo get_string('lti_tool_request_existing', 'lti'); diff --git a/mod/lti/return.php b/mod/lti/return.php index 8c34ede1731..9976aafd33a 100644 --- a/mod/lti/return.php +++ b/mod/lti/return.php @@ -41,52 +41,52 @@ require_login($course); if(!empty($errormsg)){ $url = new moodle_url('/mod/lti/return.php', array('course' => $courseid)); $PAGE->set_url($url); - + $pagetitle = strip_tags($course->shortname); $PAGE->set_title($pagetitle); $PAGE->set_heading($course->fullname); - + //Avoid frame-in-frame action if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED || $launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS) { $PAGE->set_pagelayout('embedded'); } else { $PAGE->set_pagelayout('incourse'); } - + echo $OUTPUT->header(); - + echo get_string('lti_launch_error', 'lti'); - + echo htmlspecialchars($errormsg); $canaddtools = has_capability('mod/lti:addcoursetool', get_context_instance(CONTEXT_COURSE, $courseid)); - + if($unsigned == 1 && $canaddtools){ echo '

'; - + $links = new stdClass(); $coursetooleditor = new moodle_url('/mod/lti/instructor_edit_tool_type.php', array('course' => $courseid, 'action' => 'add')); $links->course_tool_editor = $coursetooleditor->out(false); - + $adminrequesturl = new moodle_url('/mod/lti/request_tool.php', array('instanceid' => $instanceid)); $links->admin_request_url = $adminrequesturl->out(false); - + echo get_string('lti_launch_error_unsigned_help', 'lti', $links); - + echo get_string('lti_launch_error_tool_request', 'lti', $links); } - + echo $OUTPUT->footer(); } else { $courseurl = new moodle_url('/course/view.php', array('id' => $courseid)); $url = $courseurl->out(); - + //Avoid frame-in-frame action if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED || $launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS) { //Output a page containing some script to break out of frames and redirect them - + echo ''; - + $script = << SCRIPT; - + $clickhere = get_string('return_to_course', 'lti', (object)array('link' => $url)); $noscript = <<