--- /dev/null
+<?php
+// 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
+//
+// OAuth.php is distributed under the MIT License
+//
+// The MIT License
+//
+// Copyright (c) 2007 Andy Smith
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+// 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 <http://www.gnu.org/licenses/>.
+
+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
--- /dev/null
+<?php
+// This file is part of BasicLTI4Moodle
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * 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;
+ }
+}
--- /dev/null
+<?php
+// 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 <http://www.gnu.org/licenses/>.
+
+
+/**
+ * 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;
+ }
+}
--- /dev/null
+<?php
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * 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);
+ }
+}
--- /dev/null
+<?php
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * 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;
+ }
+}
--- /dev/null
+<?php
+// 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 <http://www.gnu.org/licenses/>.
+
+
+/**
+ * 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);
+ }
+}
--- /dev/null
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * 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';
+ }
+}
--- /dev/null
+<?php
+//
+// Capability definitions for the basicLTI module.
+//
+// The capabilities are loaded into the database table when the module is
+// installed or updated. Whenever the capability definitions are updated,
+// the module version number should be bumped up.
+//
+// The system has four possible values for a capability:
+// CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT, and inherit (not set).
+//
+//
+// CAPABILITY NAMING CONVENTION
+//
+// It is important that capability names are unique. The naming convention
+// for capabilities that are specific to modules and blocks is as follows:
+// [mod/block]/<plugin_name>:<capabilityname>
+//
+// component_name should be the same as the directory name of the mod or block.
+//
+// Core moodle capabilities are defined thus:
+// moodle/<capabilityclass>:<capabilityname>
+//
+// 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
+ )
+ ),
+);
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<XMLDB PATH="mod/basiclti/db" VERSION="20080912" COMMENT="XMLDB file for Moodle mod/basiclti"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
+>
+ <TABLES>
+ <TABLE NAME="basiclti" COMMENT="This table contains Basic LTI activities instances" NEXT="basiclti_filter">
+ <FIELDS>
+ <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="course"/>
+ <FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Course basiclti activity belongs to" PREVIOUS="id" NEXT="name"/>
+ <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="name field for moodle instances" PREVIOUS="course" NEXT="intro"/>
+ <FIELD NAME="intro" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" COMMENT="General introduction of the basiclti activity" PREVIOUS="name" NEXT="introformat"/>
+ <FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Format of the intro field (MOODLE, HTML, MARKDOWN...)" PREVIOUS="intro" NEXT="timecreated"/>
+ <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="introformat" NEXT="timemodified"/>
+ <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timecreated" NEXT="typeid"/>
+ <FIELD NAME="typeid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="Basic LTI type" PREVIOUS="timemodified" NEXT="toolurl"/>
+ <FIELD NAME="toolurl" TYPE="char" LENGTH="1023" NOTNULL="true" SEQUENCE="false" COMMENT="Remote tool url" PREVIOUS="typeid" NEXT="preferheight"/>
+ <FIELD NAME="preferheight" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="400" SEQUENCE="false" COMMENT="Peferred widget height" PREVIOUS="toolurl" NEXT="instructorchoicesendname"/>
+ <FIELD NAME="instructorchoicesendname" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Send user's name" PREVIOUS="preferheight" NEXT="instructorchoicesendemailaddr"/>
+ <FIELD NAME="instructorchoicesendemailaddr" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Send user's email" PREVIOUS="instructorchoicesendname" NEXT="instructorchoiceallowroster"/>
+ <FIELD NAME="instructorchoiceallowroster" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Allow the roster to be retrieved" PREVIOUS="instructorchoicesendemailaddr" NEXT="instructorchoiceallowsetting"/>
+ <FIELD NAME="instructorchoiceallowsetting" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Allow a tool to store a setting" PREVIOUS="instructorchoiceallowroster" NEXT="setting"/>
+ <FIELD NAME="setting" TYPE="char" LENGTH="8192" NOTNULL="false" UNSIGNED="false" SEQUENCE="false" COMMENT="The setting value from the tool" PREVIOUS="instructorchoiceallowsetting" NEXT="instructorcustomparameters"/>
+ <FIELD NAME="instructorcustomparameters" TYPE="char" LENGTH="255" NOTNULL="false" UNSIGNED="false" SEQUENCE="false" COMMENT="Additional custom parameters provided by the instructor" PREVIOUS="setting" NEXT="instructorchoiceacceptgrades"/>
+ <FIELD NAME="instructorchoiceacceptgrades" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Accept grades from tool" PREVIOUS="instructorcustomparameters" NEXT="grade"/>
+ <FIELD NAME="grade" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="100" SEQUENCE="false" COMMENT="Grade scale" PREVIOUS="instructorchoiceacceptgrades" NEXT="placementsecret"/>
+ <FIELD NAME="placementsecret" TYPE="char" LENGTH="1023" NOTNULL="false" SEQUENCE="false" COMMENT="Remote tool grade secret" PREVIOUS="grade" NEXT="timeplacementsecret"/>
+ <FIELD NAME="timeplacementsecret" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT='When placementsecret was set' PREVIOUS="placementsecret" NEXT="oldplacementsecret"/>
+ <FIELD NAME="oldplacementsecret" TYPE="char" LENGTH="1023" NOTNULL="false" SEQUENCE="false" COMMENT="Previous remote tool grade secret" PREVIOUS="timeplacementsecret" NEXT="organizationid"/>
+ <FIELD NAME="organizationid" TYPE="char" LENGTH="64" NOTNULL="true" SEQUENCE="false" COMMENT="Organization ID" PREVIOUS="oldplacementsecret" NEXT="organizationurl"/>
+ <FIELD NAME="organizationurl" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Organization URL" PREVIOUS="organizationid" NEXT="organizationdescr"/>
+ <FIELD NAME="organizationdescr" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Organization description" PREVIOUS="organizationurl" NEXT="launchinpopup"/>
+ <FIELD NAME="launchinpopup" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Launch external tool in a pop-up" PREVIOUS="organizationdescr" NEXT="debuglaunch"/>
+ <FIELD NAME="debuglaunch" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Enable the debug-style launch which pauses before auto-submit" PREVIOUS="launchinpopup" NEXT="moodle_course_field"/>
+ <FIELD NAME="moodle_course_field" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Chose which id field to use for setting up the tool" PREVIOUS="debuglaunch" NEXT="module_class_type"/>
+ <FIELD NAME="module_class_type" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Tool can be an activity or a resource" PREVIOUS="moodle_course_field"/>
+ </FIELDS>
+ <KEYS>
+ <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+ </KEYS>
+ <INDEXES>
+ <INDEX NAME="course" UNIQUE="false" FIELDS="course"/>
+ </INDEXES>
+ </TABLE>
+ <TABLE NAME="basiclti_filter" COMMENT="This table stores trusted servers and it's password" PREVIOUS="basiclti" NEXT="basiclti_types">
+
+ <FIELDS>
+ <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="toolurl"/>
+ <FIELD NAME="toolurl" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Server url" PREVIOUS="id" NEXT="password"/>
+ <FIELD NAME="password" TYPE="char" LENGTH="32" NOTNULL="true" SEQUENCE="false" COMMENT="Server password" PREVIOUS="toolurl"/>
+ </FIELDS>
+ <KEYS>
+ <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+ </KEYS>
+ </TABLE>
+
+ <TABLE NAME="basiclti_types" COMMENT="Basic LTI pre-configured activities" PREVIOUS="basiclti_filter" NEXT="basiclti_types_config">
+ <FIELDS>
+ <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="name"/>
+ <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" DEFAULT="basiclti Activity" SEQUENCE="false" COMMENT="Activity name" PREVIOUS="id" NEXT="rawname"/>
+ <FIELD NAME="rawname" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" PREVIOUS="name"/>
+ </FIELDS>
+ <KEYS>
+ <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+ </KEYS>
+
+ </TABLE>
+ <TABLE NAME="basiclti_types_config" COMMENT="Basic LTI types configuration" PREVIOUS="basiclti_types">
+ <FIELDS>
+ <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="typeid"/>
+ <FIELD NAME="typeid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="Basic LTI type id" PREVIOUS="id" NEXT="name"/>
+ <FIELD NAME="name" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" COMMENT="Basic LTI param" PREVIOUS="typeid" NEXT="value"/>
+ <FIELD NAME="value" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Param value" PREVIOUS="name"/>
+ </FIELDS>
+ <KEYS>
+
+ <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+ </KEYS>
+ </TABLE>
+ </TABLES>
+</XMLDB>
--- /dev/null
+<?php\r
+// This file is part of BasicLTI4Moodle\r
+//\r
+// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)\r
+// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web\r
+// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI\r
+// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS\r
+// are already supporting or going to support BasicLTI. This project Implements the consumer\r
+// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.\r
+// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem\r
+// at the GESSI research group at UPC.\r
+// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI\r
+// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a\r
+// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.\r
+//\r
+// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis\r
+// of the Universitat Politecnica de Catalunya http://www.upc.edu\r
+// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu\r
+//\r
+// Moodle is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License, or\r
+// (at your option) any later version.\r
+//\r
+// Moodle is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\r
+\r
+/**\r
+ * This file keeps track of upgrades to the basiclti module\r
+ *\r
+ * @package basiclti\r
+ * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis\r
+ * marc.alier@upc.edu\r
+ * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu\r
+ *\r
+ * @author Marc Alier\r
+ * @author Jordi Piguillem\r
+ * @author Nikolas Galanis\r
+ *\r
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r
+ */\r
+\r
+\r
+/**\r
+ * xmldb_basiclti_upgrade is the function that upgrades Moodle's\r
+ * database when is needed\r
+ *\r
+ * This function is automaticly called when version number in\r
+ * version.php changes.\r
+ *\r
+ * @param int $oldversion New old version number.\r
+ *\r
+ * @return boolean\r
+ */\r
+\r
+function xmldb_basiclti_upgrade($oldversion=0) {\r
+\r
+ global $DB;\r
+\r
+ $dbman = $DB->get_manager();\r
+ $result = true;\r
+\r
+ if ($result && $oldversion < 2008090201) {\r
+\r
+ $table = new xmldb_table('basiclti_types');\r
+ $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);\r
+ $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null);\r
+\r
+ $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));\r
+\r
+ upgrade_mod_savepoint($result, 2008090201, 'basiclti_types');\r
+\r
+ $table = new xmldb_table('basiclti_types_config');\r
+ $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);\r
+ $table->add_field('typeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null);\r
+ $table->add_field('name', XMLDB_TYPE_CHAR, '100', XMLDB_NOTNULL, null, null, null, null);\r
+ $table->add_field('value', XMLDB_TYPE_CHAR, '255', XMLDB_NOTNULL, null, null, null, null);\r
+\r
+ $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));\r
+\r
+ upgrade_mod_savepoint($result, 2008090201, 'basiclti_types_config');\r
+\r
+ $table = new xmldb_table('basiclti');\r
+ $field = new xmldb_field('typeid');\r
+\r
+ if (!$dbman->field_exists($table, $field)) {\r
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null);\r
+ $dbman->add_field($table, $field);\r
+ }\r
+ upgrade_mod_savepoint($result, 2008090201, 'basiclti');\r
+ }\r
+\r
+ if ($result && $oldversion < 2008091201) {\r
+ $table = new xmldb_table('basiclti_types');\r
+ $field = new xmldb_field('rawname');\r
+\r
+ if (!$dbman->field_exists($table, $field)) {\r
+ $field->set_attributes(XMLDB_TYPE_CHAR, '100', null, null, null, null, null);\r
+ $dbman->add_field($table, $field);\r
+ }\r
+\r
+ upgrade_mod_savepoint($result, 2008091202, 'basiclti_types');\r
+ }\r
+\r
+ if ($result && $oldversion < 2011011200) {\r
+ $table = new xmldb_table('basiclti');\r
+\r
+ $field = new xmldb_field('acceptgrades');\r
+ if (!$dbman->field_exists($table, $field)) {\r
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);\r
+ $result = $result && $dbman->add_field($table, $field);\r
+ }\r
+ $field = new xmldb_field('instructorchoiceacceptgrades');\r
+ if (!$dbman->field_exists($table, $field)) {\r
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);\r
+ $result = $result && $dbman->add_field($table, $field);\r
+ }\r
+ $field = new xmldb_field('allowroster');\r
+ if (!$dbman->field_exists($table, $field)) {\r
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);\r
+ $result = $result && $dbman->add_field($table, $field);\r
+ }\r
+ $field = new xmldb_field('instructorchoiceallowroster');\r
+ if (!$dbman->field_exists($table, $field)) {\r
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);\r
+ $result = $result && $dbman->add_field($table, $field);\r
+ }\r
+ $field = new xmldb_field('allowsetting');\r
+ if (!$dbman->field_exists($table, $field)) {\r
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);\r
+ $result = $result && $dbman->add_field($table, $field);\r
+ }\r
+ $field = new xmldb_field('instructorchoiceallowsetting');\r
+ if (!$dbman->field_exists($table, $field)) {\r
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);\r
+ $result = $result && $dbman->add_field($table, $field);\r
+ }\r
+ $field = new xmldb_field('setting');\r
+ if (!$dbman->field_exists($table, $field)) {\r
+ $field->set_attributes(XMLDB_TYPE_CHAR, '8192', null, null, null, '', null);\r
+ $result = $result && $dbman->add_field($table, $field);\r
+ }\r
+\r
+ $field = new xmldb_field('placementsecret');\r
+ if (!$dbman->field_exists($table, $field)) {\r
+ $field->set_attributes(XMLDB_TYPE_CHAR, '1024', null, null, null, '', null);\r
+ $result = $result && $dbman->add_field($table, $field);\r
+ }\r
+\r
+ $field = new xmldb_field('timeplacementsecret');\r
+ if (!$dbman->field_exists($table, $field)) {\r
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);\r
+ $result = $result && $dbman->add_field($table, $field);\r
+ }\r
+\r
+ $field = new xmldb_field('oldplacementsecret');\r
+ if (!$dbman->field_exists($table, $field)) {\r
+ $field->set_attributes(XMLDB_TYPE_CHAR, '1024', null, null, null, '', null);\r
+ $result = $result && $dbman->add_field($table, $field);\r
+ }\r
+\r
+ upgrade_mod_savepoint(true, 2011011200, 'basiclti');\r
+ }\r
+\r
+ if ($result && $oldversion < 2011011304) {\r
+ $table = new xmldb_table('basiclti');\r
+ $field = new xmldb_field('grade');\r
+ if (!$dbman->field_exists($table, $field)) {\r
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '100', null);\r
+ $result = $result && $dbman->add_field($table, $field);\r
+ }\r
+\r
+ upgrade_mod_savepoint(true, 2011011304, 'basiclti');\r
+ }\r
+\r
+ if ($result && $oldversion < 2011052600) {\r
+ $table = new xmldb_table('basiclti');\r
+\r
+ $field = new xmldb_field('resourcekey');\r
+ if ($dbman->field_exists($table, $field)) {\r
+ $dbman->drop_field($table, $field);\r
+ }\r
+\r
+ $field = new xmldb_field('password');\r
+ if ($dbman->field_exists($table, $field)) {\r
+ $dbman->drop_field($table, $field);\r
+ }\r
+\r
+ $field = new xmldb_field('sendname');\r
+ if ($dbman->field_exists($table, $field)) {\r
+ $dbman->drop_field($table, $field);\r
+ }\r
+\r
+ $field = new xmldb_field('sendemailaddr');\r
+ if ($dbman->field_exists($table, $field)) {\r
+ $dbman->drop_field($table, $field);\r
+ }\r
+\r
+ $field = new xmldb_field('allowroster');\r
+ if ($dbman->field_exists($table, $field)) {\r
+ $dbman->drop_field($table, $field);\r
+ }\r
+\r
+ $field = new xmldb_field('allowsetting');\r
+ if ($dbman->field_exists($table, $field)) {\r
+ $dbman->drop_field($table, $field);\r
+ }\r
+\r
+ $field = new xmldb_field('acceptgrades');\r
+ if ($dbman->field_exists($table, $field)) {\r
+ $dbman->drop_field($table, $field);\r
+ }\r
+\r
+ $field = new xmldb_field('customparameters');\r
+ if ($dbman->field_exists($table, $field)) {\r
+ $dbman->drop_field($table, $field);\r
+ }\r
+\r
+ upgrade_mod_savepoint(true, 2011052600, 'basiclti');\r
+ }\r
+\r
+ if($result && $oldversion < 2011070100) {\r
+ $table = new xmldb_table('basiclti');\r
+\r
+ $field = new xmldb_field('instructorcustomparameters');\r
+ if (!$dbman->field_exists($table, $field)) {\r
+ $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, null, null, '', null);\r
+ $result = $result && $dbman->add_field($table, $field);\r
+ }\r
+\r
+ upgrade_mod_savepoint(true, 2011070100, 'basiclti');\r
+ }\r
+\r
+ return $result;\r
+}\r
+\r
--- /dev/null
+<?php\r
+// This file is part of BasicLTI4Moodle\r
+//\r
+// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)\r
+// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web\r
+// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI\r
+// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS\r
+// are already supporting or going to support BasicLTI. This project Implements the consumer\r
+// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.\r
+// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem\r
+// at the GESSI research group at UPC.\r
+// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI\r
+// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a\r
+// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.\r
+//\r
+// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis\r
+// of the Universitat Politecnica de Catalunya http://www.upc.edu\r
+// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu\r
+//\r
+// Moodle is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License, or\r
+// (at your option) any later version.\r
+//\r
+// Moodle is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\r
+\r
+/**\r
+ * This file defines de main basiclti configuration form\r
+ *\r
+ * @package basiclti\r
+ * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis\r
+ * marc.alier@upc.edu\r
+ * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu\r
+ *\r
+ * @author Marc Alier\r
+ * @author Jordi Piguillem\r
+ * @author Nikolas Galanis\r
+ * @author Charles Severance\r
+ *\r
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r
+ */\r
+\r
+defined('MOODLE_INTERNAL') || die;\r
+\r
+require_once($CFG->libdir.'/formslib.php');\r
+\r
+class mod_basiclti_edit_types_form extends moodleform{\r
+\r
+ function definition() {\r
+ $mform =& $this->_form;\r
+\r
+//-------------------------------------------------------------------------------\r
+ // Add basiclti elements\r
+ $mform->addElement('header', 'setup', get_string('modstandardels', 'form'));\r
+\r
+ $mform->addElement('text', 'lti_typename', get_string('typename', 'basiclti'));\r
+ $mform->setType('lti_typename', PARAM_INT);\r
+// $mform->addHelpButton('lti_typename', 'typename','basiclti');\r
+ $mform->addRule('lti_typename', null, 'required', null, 'client');\r
+\r
+ $regex = '/^(http|https):\/\/([a-z0-9-]\.+)*/i';\r
+\r
+ $mform->addElement('text', 'lti_toolurl', get_string('toolurl', 'basiclti'), array('size'=>'64'));\r
+ $mform->setType('lti_toolurl', PARAM_TEXT);\r
+// $mform->addHelpButton('lti_toolurl', 'toolurl', 'basiclti');\r
+ $mform->addRule('lti_toolurl', get_string('validurl', 'basiclti'), 'regex', $regex, 'client');\r
+ $mform->addRule('lti_toolurl', null, 'required', null, 'client');\r
+\r
+ $mform->addElement('text', 'lti_resourcekey', get_string('resourcekey', 'basiclti'));\r
+ $mform->setType('lti_resourcekey', PARAM_TEXT);\r
+\r
+ $mform->addElement('passwordunmask', 'lti_password', get_string('password', 'basiclti'));\r
+ $mform->setType('lti_password', PARAM_TEXT);\r
+\r
+//-------------------------------------------------------------------------------\r
+ // Add size parameters\r
+ $mform->addElement('header', 'size', get_string('size', 'basiclti'));\r
+\r
+ $mform->addElement('text', 'lti_preferheight', get_string('preferheight', 'basiclti'));\r
+ $mform->setType('lti_preferheight', PARAM_INT);\r
+// $mform->addHelpButton('lti_preferheight', 'preferheight', 'basiclti');\r
+\r
+\r
+//-------------------------------------------------------------------------------\r
+ // Add privacy preferences fieldset where users choose whether to send their data\r
+ $mform->addElement('header', 'privacy', get_string('privacy', 'basiclti'));\r
+\r
+ $options=array();\r
+ $options[0] = get_string('never', 'basiclti');\r
+ $options[1] = get_string('always', 'basiclti');\r
+ $options[2] = get_string('delegate', 'basiclti');\r
+\r
+ $defaults=array();\r
+ $defaults[0] = get_string('donot', 'basiclti');\r
+ $defaults[1] = get_string('send', 'basiclti');\r
+\r
+ $mform->addElement('select', 'lti_sendname', get_string('sendname', 'basiclti'), $options);\r
+ $mform->setDefault('lti_sendname', '0');\r
+// $mform->addHelpButton('lti_sendname', 'sendname', 'basiclti');\r
+\r
+ $mform->addElement('select', 'lti_instructorchoicesendname', get_string('setdefault', 'basiclti'), $defaults);\r
+ $mform->setDefault('lti_instructorchoicesendname', '0');\r
+ $mform->disabledIf('lti_instructorchoicesendname', 'lti_sendname', 'neq', 2);\r
+\r
+ $mform->addElement('select', 'lti_sendemailaddr', get_string('sendemailaddr', 'basiclti'), $options);\r
+ $mform->setDefault('lti_sendemailaddr', '0');\r
+// $mform->addHelpButton('lti_sendemailaddr', 'sendemailaddr', 'basiclti');\r
+\r
+ $mform->addElement('select', 'lti_instructorchoicesendemailaddr', get_string('setdefault', 'basiclti'), $defaults);\r
+ $mform->setDefault('lti_instructorchoicesendemailaddr', '0');\r
+ $mform->disabledIf('lti_instructorchoicesendemailaddr', 'lti_sendemailaddr', 'neq', 2);\r
+\r
+//-------------------------------------------------------------------------------\r
+ // BLTI Extensions\r
+ $mform->addElement('header', 'extensions', get_string('extensions', 'basiclti'));\r
+\r
+ $defaults_accept=array();\r
+ $defaults_accept[0] = get_string('donotaccept', 'basiclti');\r
+ $defaults_accept[1] = get_string('accept', 'basiclti');\r
+\r
+ $defaults_allow=array();\r
+ $defaults_allow[0] = get_string('donotallow', 'basiclti');\r
+ $defaults_allow[1] = get_string('allow', 'basiclti');\r
+\r
+ // Add grading preferences fieldset where the tool is allowed to return grades\r
+ $mform->addElement('select', 'lti_acceptgrades', get_string('acceptgrades', 'basiclti'), $options);\r
+ $mform->setDefault('lti_acceptgrades', '0');\r
+// $mform->addHelpButton('lti_acceptgrades', 'acceptgrades', 'basiclti');\r
+\r
+ $mform->addElement('select', 'lti_instructorchoiceacceptgrades', get_string('setdefault', 'basiclti'), $defaults_accept);\r
+ $mform->setDefault('lti_instructorchoiceacceptgrades', '0');\r
+ $mform->disabledIf('lti_instructorchoiceacceptgrades', 'lti_acceptgrades', 'neq', 2);\r
+\r
+ // Add grading preferences fieldset where the tool is allowed to retrieve rosters\r
+ $mform->addElement('select', 'lti_allowroster', get_string('allowroster', 'basiclti'), $options);\r
+ $mform->setDefault('lti_allowroster', '0');\r
+// $mform->addHelpButton('lti_allowroster', 'allowroster', 'basiclti');\r
+\r
+ $mform->addElement('select', 'lti_instructorchoiceallowroster', get_string('setdefault', 'basiclti'), $defaults_allow);\r
+ $mform->setDefault('lti_instructorchoiceallowroster', '0');\r
+ $mform->disabledIf('lti_instructorchoiceallowroster', 'lti_allowroster', 'neq', 2);\r
+\r
+ // Add grading preferences fieldset where the tool is allowed to update settings\r
+ $mform->addElement('select', 'lti_allowsetting', get_string('allowsetting', 'basiclti'), $options);\r
+ $mform->setDefault('lti_allowsetting', '0');\r
+// $mform->addHelpButton('lti_allowsetting', 'allowsetting', 'basiclti');\r
+\r
+ $mform->addElement('select', 'lti_instructorchoiceallowsetting', get_string('setdefault', 'basiclti'), $defaults_allow);\r
+ $mform->setDefault('lti_instructorchoiceallowsetting', '0');\r
+ $mform->disabledIf('lti_instructorchoiceallowsetting', 'lti_allowsetting', 'neq', 2);\r
+\r
+//-------------------------------------------------------------------------------\r
+ // Add custom parameters fieldset\r
+ $mform->addElement('header', 'custom', get_string('custom', 'basiclti'));\r
+\r
+ $mform->addElement('textarea', 'lti_customparameters', '', array('rows'=>15, 'cols'=>60));\r
+ $mform->setType('lti_customparameters', PARAM_TEXT);\r
+\r
+ $mform->addElement('select', 'lti_allowinstructorcustom', get_string('allowinstructorcustom', 'basiclti'), $defaults_allow);\r
+ $mform->setDefault('lti_allowinstructorcustom', '0');\r
+\r
+//-------------------------------------------------------------------------------\r
+ // Add setup parameters fieldset\r
+ $mform->addElement('header', 'setupoptions', get_string('setupoptions', 'basiclti'));\r
+\r
+ // Adding option to change id that is placed in context_id\r
+ $idoptions = array();\r
+ $idoptions[0] = get_string('id', 'basiclti');\r
+ $idoptions[1] = get_string('courseid', 'basiclti');\r
+\r
+ $mform->addElement('select', 'lti_moodle_course_field', get_string('moodle_course_field', 'basiclti'), $idoptions);\r
+ $mform->setDefault('lti_moodle_course_field', '0');\r
+\r
+ // Added option to allow user to specify if this is a resource or activity type\r
+ $classoptions = array();\r
+ $classoptions[0] = get_string('activity', 'basiclti');\r
+ $classoptions[1] = get_string('resource', 'basiclti');\r
+\r
+ $mform->addElement('select', 'lti_module_class_type', get_string('module_class_type', 'basiclti'), $classoptions);\r
+ $mform->setDefault('lti_module_class_type', '0');\r
+\r
+//-------------------------------------------------------------------------------\r
+ // Add organization parameters fieldset\r
+ $mform->addElement('header', 'organization', get_string('organization', 'basiclti'));\r
+\r
+ $mform->addElement('text', 'lti_organizationid', get_string('organizationid', 'basiclti'));\r
+ $mform->setType('lti_organizationid', PARAM_TEXT);\r
+// $mform->addHelpButton('lti_organizationid', 'organizationid', 'basiclti');\r
+\r
+ $mform->addElement('text', 'lti_organizationurl', get_string('organizationurl', 'basiclti'));\r
+ $mform->setType('lti_organizationurl', PARAM_TEXT);\r
+// $mform->addHelpButton('lti_organizationurl', 'organizationurl', 'basiclti');\r
+\r
+ /* Suppress this for now - Chuck\r
+ $mform->addElement('text', 'lti_organizationdescr', get_string('organizationdescr', 'basiclti'));\r
+ $mform->setType('lti_organizationdescr', PARAM_TEXT);\r
+ $mform->addHelpButton('lti_organizationdescr', 'organizationdescr', 'basiclti');\r
+ */\r
+\r
+//-------------------------------------------------------------------------------\r
+ // Add launch parameters fieldset\r
+ $mform->addElement('header', 'launchoptions', get_string('launchoptions', 'basiclti'));\r
+\r
+ $launchoptions=array();\r
+ $launchoptions[0] = get_string('launch_in_moodle', 'basiclti');\r
+ $launchoptions[1] = get_string('launch_in_popup', 'basiclti');\r
+\r
+ $mform->addElement('select', 'lti_launchinpopup', get_string('launchinpopup', 'basiclti'), $launchoptions);\r
+ $mform->setDefault('lti_launchinpopup', '0');\r
+// $mform->addHelpButton('lti_launchinpopup', 'launchinpopup', 'basiclti');\r
+\r
+//-------------------------------------------------------------------------------\r
+ // Add a hidden element to signal a tool fixing operation after a problematic backup - restore process\r
+ $mform->addElement('hidden', 'lti_fix');\r
+\r
+//-------------------------------------------------------------------------------\r
+ // Add standard buttons, common to all modules\r
+ $this->add_action_buttons();\r
+\r
+ }\r
+}\r
--- /dev/null
+<?php\r
+// This file is part of BasicLTI4Moodle\r
+//\r
+// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)\r
+// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web\r
+// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI\r
+// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS\r
+// are already supporting or going to support BasicLTI. This project Implements the consumer\r
+// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.\r
+// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem\r
+// at the GESSI research group at UPC.\r
+// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI\r
+// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a\r
+// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.\r
+//\r
+// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis\r
+// of the Universitat Politecnica de Catalunya http://www.upc.edu\r
+// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu\r
+//\r
+// Moodle is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License, or\r
+// (at your option) any later version.\r
+//\r
+// Moodle is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\r
+\r
+/**\r
+ * This page lists all the instances of basiclti in a particular course\r
+ *\r
+ * @package basiclti\r
+ * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis\r
+ * marc.alier@upc.edu\r
+ * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu\r
+ *\r
+ * @author Marc Alier\r
+ * @author Jordi Piguillem\r
+ * @author Nikolas Galanis\r
+ *\r
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r
+ */\r
+require_once("../../config.php");\r
+require_once($CFG->dirroot.'/mod/basiclti/lib.php');\r
+\r
+$id = required_param('id', PARAM_INT); // course id\r
+\r
+if (! $course = $DB->get_record("course", array("id" => $id))) {\r
+ throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course ID is incorrect');\r
+}\r
+\r
+$url = new moodle_url('/mod/basiclti/index.php', array('id'=>$id));\r
+$PAGE->set_url($url);\r
+$PAGE->set_pagelayout('incourse');\r
+\r
+require_login($course);\r
+\r
+add_to_log($course->id, "basiclti", "view all", "index.php?id=$course->id", "");\r
+\r
+$pagetitle = strip_tags($course->shortname.': '.get_string("modulenamepluralformatted", "basiclti"));\r
+$PAGE->set_title($pagetitle);\r
+$PAGE->set_heading($course->fullname);\r
+\r
+echo $OUTPUT->header();\r
+\r
+/// Print the main part of the page\r
+echo $OUTPUT->heading(get_string("modulenamepluralformatted", "basiclti"));\r
+\r
+/// Get all the appropriate data\r
+if (! $basicltis = get_all_instances_in_course("basiclti", $course)) {\r
+ notice("There are no basicltis", "../../course/view.php?id=$course->id");\r
+ die;\r
+}\r
+\r
+/// Print the list of instances (your module will probably extend this)\r
+$timenow = time();\r
+$strname = get_string("name");\r
+$strsectionname = get_string('sectionname', 'format_'.$course->format);\r
+$usesections = course_format_uses_sections($course->format);\r
+if ($usesections) {\r
+ $sections = get_all_sections($course->id);\r
+}\r
+\r
+$table = new html_table();\r
+$table->attributes['class'] = 'generaltable mod_index';\r
+\r
+if ($usesections) {\r
+ $table->head = array ($strsectionname, $strname);\r
+ $table->align = array ("center", "left");\r
+} else {\r
+ $table->head = array ($strname);\r
+}\r
+\r
+foreach ($basicltis as $basiclti) {\r
+ if (!$basiclti->visible) {\r
+ //Show dimmed if the mod is hidden\r
+ $link = "<a class=\"dimmed\" href=\"view.php?id=$basiclti->coursemodule\">$basiclti->name</a>";\r
+ } else {\r
+ //Show normal if the mod is visible\r
+ $link = "<a href=\"view.php?id=$basiclti->coursemodule\">$basiclti->name</a>";\r
+ }\r
+\r
+ if ($course->format == "weeks" or $course->format == "topics") {\r
+ $table->data[] = array ($basiclti->section, $link);\r
+ } else {\r
+ $table->data[] = array ($link);\r
+ }\r
+}\r
+\r
+echo "<br />";\r
+\r
+echo html_writer::table($table);\r
+\r
+/// Finish the page\r
+\r
+echo $OUTPUT->footer();\r
+\r
--- /dev/null
+<?php\r
+// This file is part of BasicLTI4Moodle\r
+//\r
+// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)\r
+// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web\r
+// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI\r
+// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS\r
+// are already supporting or going to support BasicLTI. This project Implements the consumer\r
+// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.\r
+// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem\r
+// at the GESSI research group at UPC.\r
+// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI\r
+// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a\r
+// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.\r
+//\r
+// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis\r
+// of the Universitat Politecnica de Catalunya http://www.upc.edu\r
+// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu\r
+//\r
+// Moodle is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License, or\r
+// (at your option) any later version.\r
+//\r
+// Moodle is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\r
+\r
+/**\r
+ * This file contains en_utf8 translation of the Basic LTI module\r
+ *\r
+ * @package basiclti\r
+ * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis\r
+ * marc.alier@upc.edu\r
+ * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu\r
+ *\r
+ * @author Marc Alier\r
+ * @author Jordi Piguillem\r
+ * @author Nikolas Galanis\r
+ *\r
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r
+ */\r
+\r
+$string['accept'] = 'Accept';\r
+$string['acceptgrades'] = 'Accept grades from tool';\r
+$string['activity'] = 'Activity';\r
+$string['addnewapp'] = 'Enable External Application';\r
+$string['addserver'] = 'Add new trusted server';\r
+$string['addtype'] = 'Create a new Basic LTI activity';\r
+$string['allow'] = 'Allow';\r
+$string['allowinstructorcustom'] = 'Allow instructors to add custom parameters';\r
+$string['allowroster'] = 'Allow tool access to course roster';\r
+$string['allowsetting'] = 'Allow tool to store 8K of settings in Moodle';\r
+$string['always'] = 'Always';\r
+$string['basiclti'] = 'Basic LTI';\r
+$string['basiclti_base_string'] = 'Basic LTI OAuth Base String';\r
+$string['basiclti_in_new_window'] = 'Your activity has opened in a new window';\r
+$string['basiclti_endpoint'] = 'Basic LTI Launch Endpoint';\r
+$string['basiclti_parameters'] = 'Basic LTI Launch Parameters';\r
+$string['basicltiactivities'] = 'Basic LTI Activities';\r
+$string['basicltifieldset'] = 'Custom example fieldset';\r
+$string['basicltiintro'] = 'Activity Description';\r
+$string['basicltiname'] = 'Activity Name';\r
+$string['basicltisettings'] = 'Basic Learning Tool Interoperability Settings';\r
+$string['comment'] = 'Comment';\r
+$string['configpassword'] = 'Default Remote Tool Password';\r
+$string['configpreferheight'] = 'Default preferred height';\r
+$string['configpreferwidget'] = 'Set widget as default launch';\r
+$string['configpreferwidth'] = 'Default preferred width';\r
+$string['configresourceurl'] = 'Default Resource URL';\r
+$string['configtoolurl'] = 'Default Remote Tool URL';\r
+$string['configtypes'] = 'Enable Basic LTI Applications';\r
+$string['configuredtools'] = 'Configured Basic LTI activities';\r
+$string['courseid'] = 'Course id number';\r
+$string['coursemisconf'] = 'Course is misconfigured';\r
+$string['curllibrarymissing'] = 'PHP Curl library must be installed to use LTI';\r
+$string['custom'] = 'Custom parameters';\r
+$string['custominstr'] = 'Custom parameters';\r
+$string['debuglaunch'] = 'Debug Option';\r
+$string['debuglaunchoff'] = 'Normal launch';\r
+$string['debuglaunchon'] = 'Debug launch';\r
+$string['delegate'] = 'Delegate to Professor';\r
+$string['donot'] = 'Do not send';\r
+$string['donotaccept'] = 'Do not accept';\r
+$string['donotallow'] = 'Do not allow';\r
+$string['enableemailnotification'] = 'Send notification emails';\r
+$string['enableemailnotification_help'] = 'If enabled, students will receive email notification when their tool submissions are graded.';\r
+$string['errormisconfig'] = 'Misconfigured tool. Please ask your Moodle administrator to fix the configuration of the tool.';\r
+$string['extensions'] = 'Basic LTI Extension Services';\r
+$string['failedtoconnect'] = 'Moodle was unable to communicate with the \"$a\" system';\r
+$string['filterconfig'] = 'Basic LTI administration';\r
+$string['filtername'] = 'Basic LTI';\r
+$string['filter_basiclti_configlink'] = 'Configure your preferred sites and their passwords';\r
+$string['filter_basiclti_password'] = 'Password is mandatory';\r
+$string['fixexistingconf'] = 'Use an existing configuration for the misconfigured instance';\r
+$string['fixnew'] = 'New Configuration';\r
+$string['fixnewconf'] = 'Define a new configuration for the misconfigured instance';\r
+$string['fixold'] = 'Use Existing';\r
+$string['grading'] = 'Grade Routing';\r
+$string['id'] = 'id';\r
+$string['imsroleadmin'] = 'Instructor,Administrator';\r
+$string['imsroleinstructor'] = 'Instructor';\r
+$string['imsrolelearner'] = 'Learner';\r
+$string['invalidid'] = 'basic LTI ID was incorrect';\r
+$string['launch_in_moodle'] = 'Launch tool in moodle';\r
+$string['launch_in_popup'] = 'Launch tool in a pop-up';\r
+$string['launchinpopup'] = 'Popup Option';\r
+$string['launchoptions'] = 'Launch Options';\r
+$string['lti_errormsg'] = 'The tool returned the following error message: \"$a\"';\r
+$string['misconfiguredtools'] = 'Misconfigured tool instances were detected';\r
+$string['missingparameterserror'] = 'The page is misconfigured: \"$a\"';\r
+$string['module_class_type'] = 'Moodle module type';\r
+$string['modulename'] = 'Basic LTI';\r
+$string['modulenameplural'] = 'basicltis';\r
+$string['modulenamepluralformatted'] = 'Basic LTI Instances';\r
+$string['moodle_course_field'] = 'Course identification field';\r
+$string['never'] = 'Never';\r
+$string['noattempts'] = 'No attempts have been made on this tool instance';\r
+$string['noservers'] = 'No servers found';\r
+$string['notypes'] = 'There are currently no LTI tools setup in Moodle. Click the Install link above to add some.';\r
+$string['noviewusers'] = 'No users were found with permissions to use this tool';\r
+$string['optionalsettings'] = 'Optional settings';\r
+$string['organization'] ='Organization details';\r
+$string['organizationdescr'] ='Organization Description';\r
+$string['organizationid'] ='Organization ID';\r
+$string['organizationurl'] ='Organization URL';\r
+$string['pagesize'] = 'Submissions shown per page';\r
+$string['password'] = 'Remote Tool Password';\r
+$string['pluginadministration'] = 'Basic LTI administration';\r
+$string['pluginname'] = 'BasicLTI';\r
+$string['preferheight'] = 'Preferred Height';\r
+$string['preferwidget'] = 'Prefer Widget Launch';\r
+$string['preferwidth'] = 'Preferred Width';\r
+$string['press_to_submit'] = 'Press to launch this activity';\r
+$string['privacy'] = 'Privacy';\r
+$string['quickgrade'] = 'Allow quick grading';\r
+$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.';\r
+$string['redirect'] = 'You will be redirected in few seconds. If you are not, press the button.';\r
+$string['resource'] = 'Resource';\r
+$string['resourcekey'] = 'Resource Key';\r
+$string['resourceurl'] = 'Resource URL';\r
+$string['saveallfeedback'] = 'Save all my feedback';\r
+$string['send'] = 'Send';\r
+$string['sendemailaddr'] = 'Send user email address to the external tool';\r
+$string['sendname'] = 'Send user name and surname to the external tool';\r
+$string['setdefault'] = 'Set a default value for the professor if delegating';\r
+$string['setupbox'] = 'Basic LTI Tool Setup Box';\r
+$string['setupoptions'] = 'Setup Options';\r
+$string['size'] = 'Size parameters';\r
+$string['submission'] = 'Submission';\r
+$string['toggle_debug_data'] = 'Toggle Debug Data';\r
+$string['toolsetup'] = 'Basic LTI Tool Setup';\r
+$string['toolurl'] = 'Remote Tool URL';\r
+$string['typename'] = 'Remote Tool Name';\r
+$string['types'] = 'Types';\r
+$string['validurl'] = 'A valid URL must start with http(s)://';\r
+$string['viewsubmissions'] = 'View submissions and grading screen';\r
+\r
--- /dev/null
+<p>Basic LTI</p>
--- /dev/null
+<p>Basic LTI</p>
--- /dev/null
+<?php\r
+// This file is part of BasicLTI4Moodle\r
+//\r
+// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)\r
+// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web\r
+// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI\r
+// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS\r
+// are already supporting or going to support BasicLTI. This project Implements the consumer\r
+// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.\r
+// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem\r
+// at the GESSI research group at UPC.\r
+// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI\r
+// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a\r
+// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.\r
+//\r
+// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis\r
+// of the Universitat Politecnica de Catalunya http://www.upc.edu\r
+// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu\r
+//\r
+// Moodle is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License, or\r
+// (at your option) any later version.\r
+//\r
+// Moodle is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\r
+\r
+/**\r
+ * This file contains all necessary code to view a basiclti activity instance\r
+ *\r
+ * @package basiclti\r
+ * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis\r
+ * marc.alier@upc.edu\r
+ * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu\r
+ *\r
+ * @author Marc Alier\r
+ * @author Jordi Piguillem\r
+ * @author Nikolas Galanis\r
+ *\r
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r
+ */\r
+\r
+require_once("../../config.php");\r
+require_once($CFG->dirroot.'/mod/basiclti/lib.php');\r
+require_once($CFG->dirroot.'/mod/basiclti/locallib.php');\r
+\r
+$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or\r
+ $object = optional_param('withobject', false, PARAM_BOOL); // Launch BasicLTI in an object\r
+\r
+if ($id) {\r
+ if (! $cm = $DB->get_record("course_modules", array("id" => $id))) {\r
+ throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect');\r
+ }\r
+\r
+ if (! $course = $DB->get_record("course", array("id" => $cm->course))) {\r
+ throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured');\r
+ }\r
+\r
+ if (! $basiclti = $DB->get_record("basiclti", array("id" => $cm->instance))) {\r
+ throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect');\r
+ }\r
+\r
+} else {\r
+ if (! $basiclti = $DB->get_record("basiclti", array("id" => $a))) {\r
+ throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect');\r
+ }\r
+ if (! $course = $DB->get_record("course", array("id" => $basiclti->course))) {\r
+ throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured');\r
+ }\r
+ if (! $cm = get_coursemodule_from_instance("basiclti", $basiclti->id, $course->id)) {\r
+ throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect');\r
+ }\r
+}\r
+\r
+require_login($course);\r
+\r
+add_to_log($course->id, "basiclti", "launch", "launch.php?id=$cm->id", "$basiclti->id");\r
+\r
+basiclti_view($basiclti, $object);\r
+\r
--- /dev/null
+<?php\r
+// This file is part of BasicLTI4Moodle\r
+//\r
+// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)\r
+// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web\r
+// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI\r
+// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS\r
+// are already supporting or going to support BasicLTI. This project Implements the consumer\r
+// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.\r
+// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem\r
+// at the GESSI research group at UPC.\r
+// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI\r
+// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a\r
+// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.\r
+//\r
+// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis\r
+// of the Universitat Politecnica de Catalunya http://www.upc.edu\r
+// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu\r
+//\r
+// Moodle is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License, or\r
+// (at your option) any later version.\r
+//\r
+// Moodle is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\r
+\r
+/**\r
+ * This file contains a library of functions and constants for the\r
+ * BasicLTI module\r
+ *\r
+ * @package basiclti\r
+ * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis\r
+ * marc.alier@upc.edu\r
+ * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu\r
+ *\r
+ * @author Marc Alier\r
+ * @author Jordi Piguillem\r
+ * @author Nikolas Galanis\r
+ *\r
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r
+ */\r
+\r
+defined('MOODLE_INTERNAL') || die;\r
+\r
+require_once($CFG->dirroot.'/mod/basiclti/locallib.php');\r
+\r
+/**\r
+ * List of features supported in URL module\r
+ * @param string $feature FEATURE_xx constant for requested feature\r
+ * @return mixed True if module supports feature, false if not, null if doesn't know\r
+ */\r
+function basiclti_supports($feature) {\r
+ switch($feature) {\r
+ case FEATURE_GROUPS: return false;\r
+ case FEATURE_GROUPINGS: return false;\r
+ case FEATURE_GROUPMEMBERSONLY: return true;\r
+ case FEATURE_MOD_INTRO: return true;\r
+ case FEATURE_COMPLETION_TRACKS_VIEWS: return true;\r
+ case FEATURE_GRADE_HAS_GRADE: return true;\r
+ case FEATURE_GRADE_OUTCOMES: return true;\r
+ case FEATURE_BACKUP_MOODLE2: return true;\r
+\r
+ default: return null;\r
+ }\r
+}\r
+\r
+/**\r
+ * Given an object containing all the necessary data,\r
+ * (defined by the form in mod.html) this function\r
+ * will create a new instance and return the id number\r
+ * of the new instance.\r
+ *\r
+ * @param object $instance An object from the form in mod.html\r
+ * @return int The id of the newly inserted basiclti record\r
+ **/\r
+function basiclti_add_instance($basiclti) {\r
+ global $DB;\r
+ $basiclti->timecreated = time();\r
+ $basiclti->timemodified = $basiclti->timecreated;\r
+ $basiclti->placementsecret = uniqid('', true);\r
+ $basiclti->timeplacementsecret = time();\r
+\r
+ $id = $DB->insert_record("basiclti", $basiclti);\r
+\r
+ $basiclti = $DB->get_record('basiclti', array('id'=>$id));\r
+\r
+ if ($basiclti->instructorchoiceacceptgrades == 1) {\r
+ basiclti_grade_item_update($basiclti);\r
+ }\r
+\r
+ return $id;\r
+}\r
+\r
+/**\r
+ * Given an object containing all the necessary data,\r
+ * (defined by the form in mod.html) this function\r
+ * will update an existing instance with new data.\r
+ *\r
+ * @param object $instance An object from the form in mod.html\r
+ * @return boolean Success/Fail\r
+ **/\r
+function basiclti_update_instance($basiclti) {\r
+ global $DB;\r
+\r
+ $basiclti->timemodified = time();\r
+ $basiclti->id = $basiclti->instance;\r
+\r
+ $basicltirec = $DB->get_record("basiclti", array("id" => $basiclti->id));\r
+ $basiclti->grade = $basicltirec->grade;\r
+\r
+ if (empty($basiclti->preferwidget)) {\r
+ $basiclti->preferwidget = 0;\r
+ }\r
+\r
+ if ($basiclti->instructorchoiceacceptgrades == 1) {\r
+ basiclti_grade_item_update($basiclti);\r
+ } else {\r
+ basiclti_grade_item_delete($basiclti);\r
+ }\r
+\r
+ return $DB->update_record("basiclti", $basiclti);\r
+}\r
+\r
+/**\r
+ * Given an ID of an instance of this module,\r
+ * this function will permanently delete the instance\r
+ * and any data that depends on it.\r
+ *\r
+ * @param int $id Id of the module instance\r
+ * @return boolean Success/Failure\r
+ **/\r
+function basiclti_delete_instance($id) {\r
+ global $DB;\r
+\r
+ if (! $basiclti = $DB->get_record("basiclti", array("id" => $id))) {\r
+ return false;\r
+ }\r
+\r
+ $result = true;\r
+\r
+ # Delete any dependent records here #\r
+ basiclti_grade_item_delete($basiclti);\r
+\r
+ return $DB->delete_records("basiclti", array("id" => $basiclti->id));\r
+}\r
+\r
+/**\r
+ * Return a small object with summary information about what a\r
+ * user has done with a given particular instance of this module\r
+ * Used for user activity reports.\r
+ * $return->time = the time they did it\r
+ * $return->info = a short text description\r
+ *\r
+ * @return null\r
+ * @TODO: implement this moodle function (if needed)\r
+ **/\r
+function basiclti_user_outline($course, $user, $mod, $basiclti) {\r
+ return $return;\r
+}\r
+\r
+/**\r
+ * Print a detailed representation of what a user has done with\r
+ * a given particular instance of this module, for user activity reports.\r
+ *\r
+ * @return boolean\r
+ * @TODO: implement this moodle function (if needed)\r
+ **/\r
+function basiclti_user_complete($course, $user, $mod, $basiclti) {\r
+ return true;\r
+}\r
+\r
+/**\r
+ * Given a course and a time, this module should find recent activity\r
+ * that has occurred in basiclti activities and print it out.\r
+ * Return true if there was output, or false is there was none.\r
+ *\r
+ * @uses $CFG\r
+ * @return boolean\r
+ * @TODO: implement this moodle function\r
+ **/\r
+function basiclti_print_recent_activity($course, $isteacher, $timestart) {\r
+ return false; // True if anything was printed, otherwise false\r
+}\r
+\r
+/**\r
+ * Function to be run periodically according to the moodle cron\r
+ * This function searches for things that need to be done, such\r
+ * as sending out mail, toggling flags etc ...\r
+ *\r
+ * @uses $CFG\r
+ * @return boolean\r
+ **/\r
+function basiclti_cron () {\r
+ return true;\r
+}\r
+\r
+/**\r
+ * Must return an array of grades for a given instance of this module,\r
+ * indexed by user. It also returns a maximum allowed grade.\r
+ *\r
+ * Example:\r
+ * $return->grades = array of grades;\r
+ * $return->maxgrade = maximum allowed grade;\r
+ *\r
+ * return $return;\r
+ *\r
+ * @param int $basicltiid ID of an instance of this module\r
+ * @return mixed Null or object with an array of grades and with the maximum grade\r
+ *\r
+ * @TODO: implement this moodle function (if needed)\r
+ **/\r
+function basiclti_grades($basicltiid) {\r
+ return null;\r
+}\r
+\r
+/**\r
+ * Must return an array of user records (all data) who are participants\r
+ * for a given instance of basiclti. Must include every user involved\r
+ * in the instance, independient of his role (student, teacher, admin...)\r
+ * See other modules as example.\r
+ *\r
+ * @param int $basicltiid ID of an instance of this module\r
+ * @return mixed boolean/array of students\r
+ *\r
+ * @TODO: implement this moodle function\r
+ **/\r
+function basiclti_get_participants($basicltiid) {\r
+ return false;\r
+}\r
+\r
+/**\r
+ * This function returns if a scale is being used by one basiclti\r
+ * it it has support for grading and scales. Commented code should be\r
+ * modified if necessary. See forum, glossary or journal modules\r
+ * as reference.\r
+ *\r
+ * @param int $basicltiid ID of an instance of this module\r
+ * @return mixed\r
+ *\r
+ * @TODO: implement this moodle function (if needed)\r
+ **/\r
+function basiclti_scale_used ($basicltiid, $scaleid) {\r
+ $return = false;\r
+\r
+ //$rec = get_record("basiclti","id","$basicltiid","scale","-$scaleid");\r
+ //\r
+ //if (!empty($rec) && !empty($scaleid)) {\r
+ // $return = true;\r
+ //}\r
+\r
+ return $return;\r
+}\r
+\r
+/**\r
+ * Checks if scale is being used by any instance of basiclti.\r
+ * This function was added in 1.9\r
+ *\r
+ * This is used to find out if scale used anywhere\r
+ * @param $scaleid int\r
+ * @return boolean True if the scale is used by any basiclti\r
+ *\r
+ */\r
+function basiclti_scale_used_anywhere($scaleid) {\r
+ global $DB;\r
+\r
+ if ($scaleid and $DB->record_exists('basiclti', array('grade' => -$scaleid))) {\r
+ return true;\r
+ } else {\r
+ return false;\r
+ }\r
+}\r
+\r
+/**\r
+ * Execute post-install custom actions for the module\r
+ * This function was added in 1.9\r
+ *\r
+ * @return boolean true if success, false on error\r
+ */\r
+function basiclti_install() {\r
+ return true;\r
+}\r
+\r
+/**\r
+ * Execute post-uninstall custom actions for the module\r
+ * This function was added in 1.9\r
+ *\r
+ * @return boolean true if success, false on error\r
+ */\r
+function basiclti_uninstall() {\r
+ return true;\r
+}\r
+\r
+/**\r
+ * Returns available Basic LTI types\r
+ *\r
+ * @return array of basicLTI types\r
+ */\r
+function basiclti_get_basiclti_types() {\r
+ global $DB;\r
+\r
+ return $DB->get_records('basiclti_types');\r
+}\r
+\r
+/**\r
+ * Returns Basic LTI types configuration\r
+ *\r
+ * @return array of basicLTI types\r
+ */\r
+function basiclti_get_types() {\r
+ $types = array();\r
+\r
+ $basicltitypes = basiclti_get_basiclti_types();\r
+ if (!empty($basicltitypes)) {\r
+ foreach ($basicltitypes as $basicltitype) {\r
+ $ltitypesconfig = basiclti_get_type_config($basicltitype->id);\r
+\r
+ $modclass = MOD_CLASS_ACTIVITY;\r
+ if (isset($ltitypesconfig['module_class_type'])) {\r
+ if ($ltitypesconfig['module_class_type']=='1') {\r
+ $modclass = MOD_CLASS_RESOURCE;\r
+ }\r
+ }\r
+\r
+ $type = new object();\r
+ $type->modclass = $modclass;\r
+ $type->type = 'basiclti&type='.urlencode($basicltitype->rawname);\r
+ $type->typestr = $basicltitype->name;\r
+ $types[] = $type;\r
+ }\r
+ }\r
+\r
+ return $types;\r
+}\r
+\r
+//////////////////////////////////////////////////////////////////////////////////////\r
+/// Any other basiclti functions go here. Each of them must have a name that\r
+/// starts with basiclti_\r
+/// Remember (see note in first lines) that, if this section grows, it's HIGHLY\r
+/// recommended to move all funcions below to a new "localib.php" file.\r
+\r
+///**\r
+// *\r
+// */\r
+//function process_outcomes($userid, $course, $basiclti) {\r
+// global $CFG, $USER;\r
+//\r
+// if (empty($CFG->enableoutcomes)) {\r
+// return;\r
+// }\r
+//\r
+// require_once($CFG->libdir.'/gradelib.php');\r
+//\r
+// if (!$formdata = data_submitted() or !confirm_sesskey()) {\r
+// return;\r
+// }\r
+//\r
+// $data = array();\r
+// $grading_info = grade_get_grades($course->id, 'mod', 'basiclti', $basiclti->id, $userid);\r
+//\r
+// if (!empty($grading_info->outcomes)) {\r
+// foreach ($grading_info->outcomes as $n => $old) {\r
+// $name = 'outcome_'.$n;\r
+// if (isset($formdata->{$name}[$userid]) and $old->grades[$userid]->grade != $formdata->{$name}[$userid]) {\r
+// $data[$n] = $formdata->{$name}[$userid];\r
+// }\r
+// }\r
+// }\r
+// if (count($data) > 0) {\r
+// grade_update_outcomes('mod/basiclti', $course->id, 'mod', 'basiclti', $basiclti->id, $userid, $data);\r
+// }\r
+//\r
+//}\r
+\r
+/**\r
+ * Top-level function for handling of submissions called by submissions.php\r
+ *\r
+ * This is for handling the teacher interaction with the grading interface\r
+ *\r
+ * @global object\r
+ * @param string $mode Specifies the kind of teacher interaction taking place\r
+ */\r
+function basiclti_submissions($cm, $course, $basiclti, $mode) {\r
+ ///The main switch is changed to facilitate\r
+ ///1) Batch fast grading\r
+ ///2) Skip to the next one on the popup\r
+ ///3) Save and Skip to the next one on the popup\r
+\r
+ //make user global so we can use the id\r
+ global $USER, $OUTPUT, $DB;\r
+\r
+ $mailinfo = optional_param('mailinfo', null, PARAM_BOOL);\r
+\r
+ if (optional_param('next', null, PARAM_BOOL)) {\r
+ $mode='next';\r
+ }\r
+ if (optional_param('saveandnext', null, PARAM_BOOL)) {\r
+ $mode='saveandnext';\r
+ }\r
+\r
+ if (is_null($mailinfo)) {\r
+ if (optional_param('sesskey', null, PARAM_BOOL)) {\r
+ set_user_preference('basiclti_mailinfo', $mailinfo);\r
+ } else {\r
+ $mailinfo = get_user_preferences('basiclti_mailinfo', 0);\r
+ }\r
+ } else {\r
+ set_user_preference('basiclti_mailinfo', $mailinfo);\r
+ }\r
+\r
+ switch ($mode) {\r
+ case 'grade': // We are in a main window grading\r
+ if ($submission = process_feedback()) {\r
+ basiclti_display_submissions($cm, $course, $basiclti, get_string('changessaved'));\r
+ } else {\r
+ basiclti_display_submissions($cm, $course, $basiclti);\r
+ }\r
+ break;\r
+\r
+ case 'single': // We are in a main window displaying one submission\r
+ if ($submission = process_feedback()) {\r
+ basiclti_display_submissions($cm, $course, $basiclti, get_string('changessaved'));\r
+ } else {\r
+ display_submission();\r
+ }\r
+ break;\r
+\r
+ case 'all': // Main window, display everything\r
+ basiclti_display_submissions($cm, $course, $basiclti);\r
+ break;\r
+\r
+ case 'fastgrade':\r
+ /// do the fast grading stuff - this process should work for all 3 subclasses\r
+ $grading = false;\r
+ $commenting = false;\r
+ $col = false;\r
+ if (isset($_POST['submissioncomment'])) {\r
+ $col = 'submissioncomment';\r
+ $commenting = true;\r
+ }\r
+ if (isset($_POST['menu'])) {\r
+ $col = 'menu';\r
+ $grading = true;\r
+ }\r
+ if (!$col) {\r
+ //both submissioncomment and grade columns collapsed..\r
+ basiclti_display_submissions($cm, $course, $basiclti);\r
+ break;\r
+ }\r
+\r
+ foreach ($_POST[$col] as $id => $unusedvalue) {\r
+\r
+ $id = (int)$id; //clean parameter name\r
+\r
+ // Get grade item\r
+ $gradeitem = $DB->get_record('grade_items', array('courseid' => $cm->course, 'iteminstance' => $cm->instance));\r
+\r
+ // Get grade\r
+ $gradeentry = $DB->get_record('grade_grades', array('userid' => $id, 'itemid' => $gradeitem->id));\r
+\r
+ $grade = $_POST['menu'][$id];\r
+ $feedback = trim($_POST['submissioncomment'][$id]);\r
+\r
+ if ((!$gradeentry) && (($grade != '-1') || ($feedback != ''))) {\r
+ $newsubmission = true;\r
+ } else {\r
+ $newsubmission = false;\r
+ }\r
+\r
+ //for fast grade, we need to check if any changes take place\r
+ $updatedb = false;\r
+\r
+ if ($gradeentry) {\r
+ if ($grading) {\r
+ $grade = $_POST['menu'][$id];\r
+ $updatedb = $updatedb || (($gradeentry->rawgrade != $grade) && ($gradeentry->rawgrade != '-1'));\r
+ if ($grade != '-1') {\r
+ $gradeentry->rawgrade = $grade;\r
+ $gradeentry->finalgrade = $grade;\r
+ } else {\r
+ $gradeentry->rawgrade = null;\r
+ $gradeentry->finalgrade = null;\r
+ }\r
+ } else {\r
+ if (!$newsubmission) {\r
+ unset($gradeentry->rawgrade); // Don't need to update this.\r
+ }\r
+ }\r
+\r
+ if ($commenting) {\r
+ $commentvalue = trim($_POST['submissioncomment'][$id]);\r
+ $updatedb = $updatedb || ($gradeentry->feedback != $commentvalue);\r
+ // Special case\r
+ if (($gradeentry->feedback == null) && ($commentvalue == "")) {\r
+ unset($gradeentry->feedback);\r
+ }\r
+ $gradeentry->feedback = $commentvalue;\r
+ } else {\r
+ unset($gradeentry->feedback); // Don't need to update this.\r
+ }\r
+\r
+ } else { // No previous grade entry found\r
+ if ($newsubmission) {\r
+ if ($grade != '-1') {\r
+ $gradeentry->rawgrade = $grade;\r
+ $updatedb = true;\r
+ }\r
+ if ($feedback != '') {\r
+ $gradeentry->feedback = $feedback;\r
+ $updatedb = true;\r
+ }\r
+ }\r
+ }\r
+\r
+ $gradeentry->usermodified = $USER->id;\r
+ if (!$gradeentry->timecreated) {\r
+ $gradeentry->timecreated = time();\r
+ }\r
+ $gradeentry->timemodified = time();\r
+\r
+ //if it is not an update, we don't change the last modified time etc.\r
+ //this will also not write into database if no submissioncomment and grade is entered.\r
+ if ($updatedb) {\r
+ if ($gradeentry->rawgrade == '-1') {\r
+ $gradeentry->rawgrade = null;\r
+ }\r
+\r
+ if ($newsubmission) {\r
+ if (!isset($gradeentry->feedback)) {\r
+ $gradeentry->feedback = '';\r
+ }\r
+ $gradeentry->itemid = $gradeitem->id;\r
+ $gradeentry->userid = $id;\r
+ $sid = $DB->insert_record("grade_grades", $gradeentry);\r
+ $gradeentry->id = $sid;\r
+ } else {\r
+ $DB->update_record("grade_grades", $gradeentry);\r
+ }\r
+\r
+ //add to log only if updating\r
+ add_to_log($course->id, 'basiclti', 'update grades',\r
+ 'submissions.php?id='.$cm->id.'&user='.$USER->id,\r
+ $USER->id, $cm->id);\r
+ }\r
+\r
+ }\r
+\r
+ $message = $OUTPUT->notification(get_string('changessaved'), 'notifysuccess');\r
+\r
+ basiclti_display_submissions($cm, $course, $basiclti, $message);\r
+ break;\r
+\r
+ case 'saveandnext':\r
+ ///We are in pop up. save the current one and go to the next one.\r
+ //first we save the current changes\r
+ if ($submission = process_feedback()) {\r
+ //print_heading(get_string('changessaved'));\r
+ //$extra_javascript = $this->update_main_listing($submission);\r
+ }\r
+\r
+ case 'next':\r
+ /// We are currently in pop up, but we want to skip to next one without saving.\r
+ /// This turns out to be similar to a single case\r
+ /// The URL used is for the next submission.\r
+ $offset = required_param('offset', PARAM_INT);\r
+ $nextid = required_param('nextid', PARAM_INT);\r
+ $id = required_param('id', PARAM_INT);\r
+ $offset = (int)$offset+1;\r
+ //$this->display_submission($offset+1 , $nextid);\r
+ redirect('submissions.php?id='.$id.'&userid='. $nextid . '&mode=single&offset='.$offset);\r
+ break;\r
+\r
+ case 'singlenosave':\r
+ display_submission();\r
+ break;\r
+\r
+ default:\r
+ echo "Critical error. Something is seriously wrong!!";\r
+ break;\r
+ }\r
+}\r
+\r
+/**\r
+ * Display all the submissions ready for grading\r
+ *\r
+ * @global object\r
+ * @global object\r
+ * @global object\r
+ * @global object\r
+ * @param string $message\r
+ * @return bool|void\r
+ */\r
+function basiclti_display_submissions($cm, $course, $basiclti, $message='') {\r
+ global $CFG, $DB, $OUTPUT, $PAGE;\r
+ require_once($CFG->libdir.'/gradelib.php');\r
+\r
+ /* first we check to see if the form has just been submitted\r
+ * to request user_preference updates\r
+ */\r
+ $updatepref = optional_param('updatepref', 0, PARAM_INT);\r
+\r
+ if (isset($_POST['updatepref'])) {\r
+ $perpage = optional_param('perpage', 10, PARAM_INT);\r
+ $perpage = ($perpage <= 0) ? 10 : $perpage;\r
+ $filter = optional_param('filter', 0, PARAM_INT);\r
+ set_user_preference('basiclti_perpage', $perpage);\r
+ set_user_preference('basiclti_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL));\r
+ set_user_preference('basiclti_filter', $filter);\r
+ }\r
+\r
+ /* next we get perpage and quickgrade (allow quick grade) params\r
+ * from database\r
+ */\r
+ $perpage = get_user_preferences('basiclti_perpage', 10);\r
+ $quickgrade = get_user_preferences('basiclti_quickgrade', 0);\r
+ $filter = get_user_preferences('basiclti_filter', 0);\r
+ $grading_info = grade_get_grades($course->id, 'mod', 'basiclti', $basiclti->id);\r
+\r
+ if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) {\r
+ $uses_outcomes = true;\r
+ } else {\r
+ $uses_outcomes = false;\r
+ }\r
+\r
+ $page = optional_param('page', 0, PARAM_INT);\r
+ $strsaveallfeedback = get_string('saveallfeedback', 'basiclti');\r
+\r
+ $tabindex = 1; //tabindex for quick grading tabbing; Not working for dropdowns yet\r
+ add_to_log($course->id, 'basiclti', 'view submission', 'submissions.php?id='.$cm->id, $basiclti->id, $cm->id);\r
+\r
+ $PAGE->set_title(format_string($basiclti->name, true));\r
+ $PAGE->set_heading($course->fullname);\r
+ echo $OUTPUT->header();\r
+\r
+ echo '<div class="usersubmissions">';\r
+\r
+ //hook to allow plagiarism plugins to update status/print links.\r
+ plagiarism_update_status($course, $cm);\r
+\r
+ /// Print quickgrade form around the table\r
+ if ($quickgrade) {\r
+ $formattrs = array();\r
+ $formattrs['action'] = new moodle_url('/mod/basiclti/submissions.php');\r
+ $formattrs['id'] = 'fastg';\r
+ $formattrs['method'] = 'post';\r
+\r
+ echo html_writer::start_tag('form', $formattrs);\r
+ echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=> $cm->id));\r
+ echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'mode', 'value'=> 'fastgrade'));\r
+ echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'page', 'value'=> $page));\r
+ echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=> sesskey()));\r
+ }\r
+\r
+ $course_context = get_context_instance(CONTEXT_COURSE, $course->id);\r
+ if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) {\r
+ echo '<div class="allcoursegrades"><a href="' . $CFG->wwwroot . '/grade/report/grader/index.php?id=' . $course->id . '">'\r
+ . get_string('seeallcoursegrades', 'grades') . '</a></div>';\r
+ }\r
+\r
+ if (!empty($message)) {\r
+ echo $message; // display messages here if any\r
+ }\r
+\r
+ $context = get_context_instance(CONTEXT_MODULE, $cm->id);\r
+\r
+/// Check to see if groups are being used in this tool\r
+\r
+ /// find out current groups mode\r
+ $groupmode = groups_get_activity_groupmode($cm);\r
+ $currentgroup = groups_get_activity_group($cm, true);\r
+ groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/basiclti/submissions.php?id=' . $cm->id);\r
+\r
+ /// Get all ppl that are allowed to submit tools\r
+ list($esql, $params) = get_enrolled_sql($context, 'mod/basiclti:view', $currentgroup);\r
+\r
+ $sql = "SELECT u.id FROM {user} u ".\r
+ "LEFT JOIN ($esql) eu ON eu.id=u.id ".\r
+ "WHERE u.deleted = 0 AND eu.id=u.id ";\r
+\r
+ $users = $DB->get_records_sql($sql, $params);\r
+ if (!empty($users)) {\r
+ $users = array_keys($users);\r
+ }\r
+\r
+ // if groupmembersonly used, remove users who are not in any group\r
+ if ($users and !empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) {\r
+ if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {\r
+ $users = array_intersect($users, array_keys($groupingusers));\r
+ }\r
+ }\r
+\r
+ $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade');\r
+ if ($uses_outcomes) {\r
+ $tablecolumns[] = 'outcome'; // no sorting based on outcomes column\r
+ }\r
+\r
+ $tableheaders = array('',\r
+ get_string('fullname'),\r
+ get_string('grade'),\r
+ get_string('comment', 'basiclti'),\r
+ get_string('lastmodified').' ('.get_string('submission', 'basiclti').')',\r
+ get_string('lastmodified').' ('.get_string('grade').')',\r
+ get_string('status'),\r
+ get_string('finalgrade', 'grades'));\r
+ if ($uses_outcomes) {\r
+ $tableheaders[] = get_string('outcome', 'grades');\r
+ }\r
+\r
+ require_once($CFG->libdir.'/tablelib.php');\r
+ $table = new flexible_table('mod-basiclti-submissions');\r
+\r
+ $table->define_columns($tablecolumns);\r
+ $table->define_headers($tableheaders);\r
+ $table->define_baseurl($CFG->wwwroot.'/mod/basiclti/submissions.php?id='.$cm->id.'&currentgroup='.$currentgroup);\r
+\r
+ $table->sortable(true, 'lastname');//sorted by lastname by default\r
+ $table->collapsible(true);\r
+ $table->initialbars(true);\r
+\r
+ $table->column_suppress('picture');\r
+ $table->column_suppress('fullname');\r
+\r
+ $table->column_class('picture', 'picture');\r
+ $table->column_class('fullname', 'fullname');\r
+ $table->column_class('grade', 'grade');\r
+ $table->column_class('submissioncomment', 'comment');\r
+ $table->column_class('timemodified', 'timemodified');\r
+ $table->column_class('timemarked', 'timemarked');\r
+ $table->column_class('status', 'status');\r
+ $table->column_class('finalgrade', 'finalgrade');\r
+ if ($uses_outcomes) {\r
+ $table->column_class('outcome', 'outcome');\r
+ }\r
+\r
+ $table->set_attribute('cellspacing', '0');\r
+ $table->set_attribute('id', 'attempts');\r
+ $table->set_attribute('class', 'submissions');\r
+ $table->set_attribute('width', '100%');\r
+\r
+ $table->no_sorting('finalgrade');\r
+ $table->no_sorting('outcome');\r
+\r
+ // Start working -- this is necessary as soon as the niceties are over\r
+ $table->setup();\r
+\r
+ if (empty($users)) {\r
+ echo $OUTPUT->heading(get_string('noviewusers', 'basiclti'));\r
+ echo '</div>';\r
+ return true;\r
+ }\r
+\r
+ /// Construct the SQL\r
+ list($where, $params) = $table->get_sql_where();\r
+ if ($where) {\r
+ $where .= ' AND ';\r
+ }\r
+\r
+ if ($sort = $table->get_sql_sort()) {\r
+ $sort = ' ORDER BY '.$sort;\r
+ }\r
+\r
+ $ufields = user_picture::fields('u');\r
+\r
+ $gradeitem = $DB->get_record('grade_items', array('courseid' => $cm->course, 'iteminstance' => $cm->instance));\r
+\r
+ $select = "SELECT $ufields,\r
+ g.rawgrade, g.feedback,\r
+ g.timemodified, g.timecreated ";\r
+\r
+ $sql = 'FROM {user} u'.\r
+ ' LEFT JOIN {grade_grades} g ON u.id = g.userid AND g.itemid = '.$gradeitem->id.\r
+ ' LEFT JOIN {grade_items} i ON g.itemid = i.id'.\r
+ ' AND i.iteminstance = '.$basiclti->id.\r
+ ' WHERE '.$where.'u.id IN ('.implode(',', $users).') ';\r
+\r
+ $ausers = $DB->get_records_sql($select.$sql.$sort, $params, $table->get_page_start(), $table->get_page_size());\r
+\r
+ $table->pagesize($perpage, count($users));\r
+\r
+ ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next\r
+ $offset = $page * $perpage;\r
+ $strupdate = get_string('update');\r
+ $strgrade = get_string('grade');\r
+ $grademenu = make_grades_menu($basiclti->grade);\r
+ if ($ausers !== false) {\r
+ $grading_info = grade_get_grades($course->id, 'mod', 'basiclti', $basiclti->id, array_keys($ausers));\r
+ $endposition = $offset + $perpage;\r
+ $currentposition = 0;\r
+ foreach ($ausers as $auser) {\r
+\r
+ if ($auser->timemodified > 0) {\r
+ $timemodified = '<div id="ts'.$auser->id.'">'.userdate($auser->timemodified).'</div>';\r
+ } else {\r
+ $timemodified = '<div id="ts'.$auser->id.'"> </div>';\r
+ }\r
+ if ($auser->timecreated > 0) {\r
+ $timecreated = '<div id="ts'.$auser->id.'">'.userdate($auser->timecreated).'</div>';\r
+ } else {\r
+ $timecreated = '<div id="ts'.$auser->id.'"> </div>';\r
+ }\r
+\r
+ if ($currentposition == $offset && $offset < $endposition) {\r
+ $final_grade = $grading_info->items[0]->grades[$auser->id];\r
+ $grademax = $grading_info->items[0]->grademax;\r
+ $final_grade->formatted_grade = round($final_grade->grade, 2) .' / ' . round($grademax, 2);\r
+ $locked_overridden = 'locked';\r
+ if ($final_grade->overridden) {\r
+ $locked_overridden = 'overridden';\r
+ }\r
+\r
+ /// Calculate user status\r
+ $picture = $OUTPUT->user_picture($auser);\r
+\r
+ $studentmodified = '<div id="ts'.$auser->id.'"> </div>';\r
+ $teachermodified = '<div id="tt'.$auser->id.'"> </div>';\r
+ $status = '<div id="st'.$auser->id.'"> </div>';\r
+\r
+ if ($final_grade->locked or $final_grade->overridden) {\r
+ $grade = '<div id="g'.$auser->id.'">'.$final_grade->formatted_grade . '</div>';\r
+ } else if ($quickgrade) { // allow editing\r
+ $attributes = array();\r
+ $attributes['tabindex'] = $tabindex++;\r
+ if ($auser->rawgrade != "") {\r
+ $menu = html_writer::select(make_grades_menu($basiclti->grade), 'menu['.$auser->id.']', round($auser->rawgrade, 0), array(-1=>get_string('nograde')), $attributes);\r
+ } else {\r
+ $menu = html_writer::select(make_grades_menu($basiclti->grade), 'menu['.$auser->id.']', -1, array(-1=>get_string('nograde')), $attributes);\r
+ }\r
+ $grade = '<div id="g'.$auser->id.'">'.$menu.'</div>';\r
+ } else if ($final_grade->grade) {\r
+ if ($auser->rawgrade != "") {\r
+ $grade = '<div id="g'.$auser->id.'">'.$final_grade->formatted_grade.'</div>';\r
+ } else {\r
+ $grade = '<div id="g'.$auser->id.'">-1</div>';\r
+ }\r
+\r
+ } else {\r
+ $grade = '<div id="g'.$auser->id.'">No Grade</div>';\r
+ }\r
+\r
+ if ($final_grade->locked or $final_grade->overridden) {\r
+ $comment = '<div id="com'.$auser->id.'">'.$final_grade->str_feedback.'</div>';\r
+ } else if ($quickgrade) {\r
+ $comment = '<div id="com'.$auser->id.'">'\r
+ . '<textarea tabindex="'.$tabindex++.'" name="submissioncomment['.$auser->id.']" id="submissioncomment'\r
+ . $auser->id.'" rows="2" cols="20">'.($auser->feedback).'</textarea></div>';\r
+ } else {\r
+ $comment = '<div id="com'.$auser->id.'">'.shorten_text(strip_tags($auser->feedback), 15).'</div>';\r
+ }\r
+\r
+ if (empty($auser->status)) { /// Confirm we have exclusively 0 or 1\r
+ $auser->status = 0;\r
+ } else {\r
+ $auser->status = 1;\r
+ }\r
+\r
+ $buttontext = ($auser->status == 1) ? $strupdate : $strgrade;\r
+\r
+ ///No more buttons, we use popups ;-).\r
+ $popup_url = '/mod/basiclti/submissions.php?id='.$cm->id\r
+ . '&userid='.$auser->id.'&mode=single'.'&filter='.$filter.'&offset='.$offset++;\r
+\r
+ $button = $OUTPUT->action_link($popup_url, $buttontext);\r
+\r
+ $status = '<div id="up'.$auser->id.'" class="s'.$auser->status.'">'.$button.'</div>';\r
+\r
+ $finalgrade = '<span id="finalgrade_'.$auser->id.'">'.$final_grade->str_grade.'</span>';\r
+\r
+ $outcomes = '';\r
+\r
+ if ($uses_outcomes) {\r
+\r
+ foreach ($grading_info->outcomes as $n => $outcome) {\r
+ $outcomes .= '<div class="outcome"><label>'.$outcome->name.'</label>';\r
+ $options = make_grades_menu(-$outcome->scaleid);\r
+\r
+ if ($outcome->grades[$auser->id]->locked or !$quickgrade) {\r
+ $options[0] = get_string('nooutcome', 'grades');\r
+ $outcomes .= ': <span id="outcome_'.$n.'_'.$auser->id.'">'.$options[$outcome->grades[$auser->id]->grade].'</span>';\r
+ } else {\r
+ $attributes = array();\r
+ $attributes['tabindex'] = $tabindex++;\r
+ $attributes['id'] = 'outcome_'.$n.'_'.$auser->id;\r
+ $outcomes .= ' '.html_writer::select($options, 'outcome_'.$n.'['.$auser->id.']', $outcome->grades[$auser->id]->grade, array(0=>get_string('nooutcome', 'grades')), $attributes);\r
+ }\r
+ $outcomes .= '</div>';\r
+ }\r
+ }\r
+\r
+ $userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&course=' . $course->id . '">' . fullname($auser, has_capability('moodle/site:viewfullnames', $context)) . '</a>';\r
+ $row = array($picture, $userlink, $grade, $comment, $timemodified, $timecreated, $status, $finalgrade);\r
+ if ($uses_outcomes) {\r
+ $row[] = $outcomes;\r
+ }\r
+\r
+ $table->add_data($row);\r
+ }\r
+ $currentposition++;\r
+ }\r
+ }\r
+\r
+ $table->print_html(); /// Print the whole table\r
+\r
+ /// Print quickgrade form around the table\r
+ if ($quickgrade && $table->started_output) {\r
+ $mailinfopref = false;\r
+ if (get_user_preferences('basiclti_mailinfo', 1)) {\r
+ $mailinfopref = true;\r
+ }\r
+ $emailnotification = html_writer::checkbox('mailinfo', 1, $mailinfopref, get_string('enableemailnotification', 'basiclti'));\r
+\r
+ $emailnotification .= $OUTPUT->help_icon('enableemailnotification', 'basiclti');\r
+ echo html_writer::tag('div', $emailnotification, array('class'=>'emailnotification'));\r
+\r
+ $savefeedback = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'fastg', 'value'=>get_string('saveallfeedback', 'basiclti')));\r
+ echo html_writer::tag('div', $savefeedback, array('class'=>'fastgbutton'));\r
+\r
+ echo html_writer::end_tag('form');\r
+ } else if ($quickgrade) {\r
+ echo html_writer::end_tag('form');\r
+ }\r
+\r
+ echo '</div>';\r
+ /// End of fast grading form\r
+\r
+ /// Mini form for setting user preference\r
+\r
+ $formaction = new moodle_url('/mod/basiclti/submissions.php', array('id'=>$cm->id));\r
+ $mform = new MoodleQuickForm('optionspref', 'post', $formaction, '', array('class'=>'optionspref'));\r
+\r
+ $mform->addElement('hidden', 'updatepref');\r
+ $mform->setDefault('updatepref', 1);\r
+ $mform->addElement('header', 'qgprefs', get_string('optionalsettings', 'basiclti'));\r
+// $mform->addElement('select', 'filter', get_string('show'), $filters);\r
+\r
+ $mform->setDefault('filter', $filter);\r
+\r
+ $mform->addElement('text', 'perpage', get_string('pagesize', 'basiclti'), array('size'=>1));\r
+ $mform->setDefault('perpage', $perpage);\r
+\r
+ $mform->addElement('checkbox', 'quickgrade', get_string('quickgrade', 'basiclti'));\r
+ $mform->setDefault('quickgrade', $quickgrade);\r
+ $mform->addHelpButton('quickgrade', 'quickgrade', 'basiclti');\r
+\r
+ $mform->addElement('submit', 'savepreferences', get_string('savepreferences'));\r
+\r
+ $mform->display();\r
+\r
+ echo $OUTPUT->footer();\r
+}\r
+\r
+/**\r
+ * Create grade item for given basiclti\r
+ *\r
+ * @param object $basiclti object with extra cmidnumber\r
+ * @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook\r
+ * @return int 0 if ok, error code otherwise\r
+ */\r
+function basiclti_grade_item_update($basiclti, $grades=null) {\r
+ global $CFG;\r
+ require_once($CFG->libdir.'/gradelib.php');\r
+\r
+ if (!isset($basiclti->courseid)) {\r
+ $basiclti->courseid = $basiclti->course;\r
+ }\r
+\r
+ $params = array('itemname'=>$basiclti->name, 'idnumber'=>$basiclti->cmidnumber);\r
+\r
+ if ($basiclti->grade > 0) {\r
+ $params['gradetype'] = GRADE_TYPE_VALUE;\r
+ $params['grademax'] = $basiclti->grade;\r
+ $params['grademin'] = 0;\r
+\r
+ } else if ($basiclti->grade < 0) {\r
+ $params['gradetype'] = GRADE_TYPE_SCALE;\r
+ $params['scaleid'] = -$basiclti->grade;\r
+\r
+ } else {\r
+ $params['gradetype'] = GRADE_TYPE_TEXT; // allow text comments only\r
+ }\r
+\r
+ if ($grades === 'reset') {\r
+ $params['reset'] = true;\r
+ $grades = null;\r
+ }\r
+\r
+ return grade_update('mod/basiclti', $basiclti->courseid, 'mod', 'basiclti', $basiclti->id, 0, $grades, $params);\r
+}\r
+\r
+/**\r
+ * Delete grade item for given basiclti\r
+ *\r
+ * @param object $basiclti object\r
+ * @return object basiclti\r
+ */\r
+function basiclti_grade_item_delete($basiclti) {\r
+ global $CFG;\r
+ require_once($CFG->libdir.'/gradelib.php');\r
+\r
+ if (!isset($basiclti->courseid)) {\r
+ $basiclti->courseid = $basiclti->course;\r
+ }\r
+\r
+ return grade_update('mod/basiclti', $basiclti->courseid, 'mod', 'basiclti', $basiclti->id, 0, null, array('deleted'=>1));\r
+}\r
+\r
--- /dev/null
+<?php\r
+// This file is part of BasicLTI4Moodle\r
+//\r
+// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)\r
+// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web\r
+// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI\r
+// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS\r
+// are already supporting or going to support BasicLTI. This project Implements the consumer\r
+// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.\r
+// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem\r
+// at the GESSI research group at UPC.\r
+// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI\r
+// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a\r
+// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.\r
+//\r
+// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis\r
+// of the Universitat Politecnica de Catalunya http://www.upc.edu\r
+// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu\r
+//\r
+// Moodle is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License, or\r
+// (at your option) any later version.\r
+//\r
+// Moodle is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\r
+\r
+/**\r
+ * This file contains some functions and classes used in Basic LTI\r
+ * module administration\r
+ *\r
+ * @package basiclti\r
+ * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis\r
+ * marc.alier@upc.edu\r
+ * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu\r
+ *\r
+ * @author Marc Alier\r
+ * @author Jordi Piguillem\r
+ * @author Nikolas Galanis\r
+ *\r
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r
+ */\r
+\r
+defined('MOODLE_INTERNAL') || die;\r
+\r
+require_once($CFG->libdir.'/adminlib.php');\r
+\r
+/**\r
+ *\r
+ * @TODO: finish doc this class and it's functions\r
+ */\r
+class admin_setting_basicltimodule_configlink extends admin_setting {\r
+\r
+ /**\r
+ * Constructor\r
+ * @param string $name of setting\r
+ * @param string $visiblename localised\r
+ * @param string $description long localised info\r
+ */\r
+ function admin_setting_basicltimodule_configlink($name, $visiblename, $description) {\r
+ parent::__construct($name, $visiblename, $description, '');\r
+ }\r
+\r
+ function get_setting() {\r
+ return true;\r
+ }\r
+\r
+ function write_setting($data) {\r
+ return "";\r
+ }\r
+\r
+ function output_html($data, $query='') {\r
+ global $CFG;\r
+ return format_admin_setting($this, "",\r
+ '<div class="defaultsnext" >'.\r
+ '<a href="'.$CFG->wwwroot.'/mod/basiclti/typessettings.php">'.get_string('filterconfig', 'basiclti').'</a>'.\r
+ '</div>',\r
+ $this->description, true, '', null, $query);\r
+ }\r
+}\r
--- /dev/null
+<?php\r
+// This file is part of BasicLTI4Moodle\r
+//\r
+// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)\r
+// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web\r
+// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI\r
+// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS\r
+// are already supporting or going to support BasicLTI. This project Implements the consumer\r
+// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.\r
+// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem\r
+// at the GESSI research group at UPC.\r
+// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI\r
+// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a\r
+// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.\r
+//\r
+// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis\r
+// of the Universitat Politecnica de Catalunya http://www.upc.edu\r
+// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu\r
+//\r
+// Moodle is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License, or\r
+// (at your option) any later version.\r
+//\r
+// Moodle is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\r
+\r
+/**\r
+ * This file contains the library of functions and constants for the basiclti module\r
+ *\r
+ * @package basiclti\r
+ * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis\r
+ * marc.alier@upc.edu\r
+ * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu\r
+ *\r
+ * @author Marc Alier\r
+ * @author Jordi Piguillem\r
+ * @author Nikolas Galanis\r
+ *\r
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r
+ */\r
+\r
+defined('MOODLE_INTERNAL') || die;\r
+\r
+require_once($CFG->dirroot.'/mod/basiclti/OAuth.php');\r
+\r
+/**\r
+ * Prints a Basic LTI activity\r
+ *\r
+ * $param int $basicltiid Basic LTI activity id\r
+ */\r
+function basiclti_view($instance, $makeobject=false) {\r
+ global $PAGE;\r
+\r
+ $typeconfig = basiclti_get_type_config($instance->typeid);\r
+ $endpoint = $typeconfig['toolurl'];\r
+ $key = $typeconfig['resourcekey'];\r
+ $secret = $typeconfig['password'];\r
+ $orgid = $typeconfig['organizationid'];\r
+ /* Suppress this for now - Chuck\r
+ $orgdesc = $typeconfig['organizationdescr'];\r
+ */\r
+\r
+ $course = $PAGE->course;\r
+ $requestparams = basiclti_build_request($instance, $typeconfig, $course);\r
+\r
+ // Make sure we let the tool know what LMS they are being called from\r
+ $requestparams["ext_lms"] = "moodle-2";\r
+\r
+ // Add oauth_callback to be compliant with the 1.0A spec\r
+ $requestparams["oauth_callback"] = "about:blank";\r
+\r
+ $submittext = get_string('press_to_submit', 'basiclti');\r
+ $parms = sign_parameters($requestparams, $endpoint, "POST", $key, $secret, $submittext, $orgid /*, $orgdesc*/);\r
+\r
+ $debuglaunch = ( $instance->debuglaunch == 1 );\r
+ if ( $makeobject ) {\r
+ // TODO: Need frame height\r
+ $height = $instance->preferheight;\r
+ if ((!$height) || ($height == 0)) {\r
+ $height = 400;\r
+ }\r
+ $content = post_launch_html($parms, $endpoint, $debuglaunch, $height);\r
+ } else {\r
+ $content = post_launch_html($parms, $endpoint, $debuglaunch, false);\r
+ }\r
+// $cm = get_coursemodule_from_instance("basiclti", $instance->id);\r
+// print '<object height='.$height.' width="80%" data="launch.php?id='.$cm->id.'">'.$content.'</object>';\r
+ print $content;\r
+}\r
+\r
+/**\r
+ * This function builds the request that must be sent to the tool producer\r
+ *\r
+ * @param object $instance Basic LTI instance object\r
+ * @param object $typeconfig Basic LTI tool configuration\r
+ * @param object $course Course object\r
+ *\r
+ * @return array $request Request details\r
+ */\r
+function basiclti_build_request($instance, $typeconfig, $course) {\r
+ global $USER, $CFG;\r
+\r
+ $context = get_context_instance(CONTEXT_COURSE, $course->id);\r
+ $role = basiclti_get_ims_role($USER, $context);\r
+\r
+ $locale = $course->lang;\r
+ if ( strlen($locale) < 1 ) {\r
+ $locale = $CFG->lang;\r
+ }\r
+\r
+ $requestparams = array(\r
+ "resource_link_id" => $instance->id,\r
+ "resource_link_title" => $instance->name,\r
+ "resource_link_description" => $instance->intro,\r
+ "user_id" => $USER->id,\r
+ "roles" => $role,\r
+ "context_id" => $course->id,\r
+ "context_label" => $course->shortname,\r
+ "context_title" => $course->fullname,\r
+ "launch_presentation_locale" => $locale,\r
+ );\r
+\r
+ $placementsecret = $instance->placementsecret;\r
+ if ( isset($placementsecret) ) {\r
+ $suffix = ':::' . $USER->id . ':::' . $instance->id;\r
+ $plaintext = $placementsecret . $suffix;\r
+ $hashsig = hash('sha256', $plaintext, false);\r
+ $sourcedid = $hashsig . $suffix;\r
+ }\r
+\r
+ if ( isset($placementsecret) &&\r
+ ( $typeconfig['acceptgrades'] == 1 ||\r
+ ( $typeconfig['acceptgrades'] == 2 && $instance->instructorchoiceacceptgrades == 1 ) ) ) {\r
+ $requestparams["lis_result_sourcedid"] = $sourcedid;\r
+ $requestparams["ext_ims_lis_basic_outcome_url"] = $CFG->wwwroot.'/mod/basiclti/service.php';\r
+ }\r
+\r
+ if ( isset($placementsecret) &&\r
+ ( $typeconfig['allowroster'] == 1 ||\r
+ ( $typeconfig['allowroster'] == 2 && $instance->instructorchoiceallowroster == 1 ) ) ) {\r
+ $requestparams["ext_ims_lis_memberships_id"] = $sourcedid;\r
+ $requestparams["ext_ims_lis_memberships_url"] = $CFG->wwwroot.'/mod/basiclti/service.php';\r
+ }\r
+\r
+ if ( isset($placementsecret) &&\r
+ ( $typeconfig['allowsetting'] == 1 ||\r
+ ( $typeconfig['allowsetting'] == 2 && $instance->instructorchoiceallowsetting == 1 ) ) ) {\r
+ $requestparams["ext_ims_lti_tool_setting_id"] = $sourcedid;\r
+ $requestparams["ext_ims_lti_tool_setting_url"] = $CFG->wwwroot.'/mod/basiclti/service.php';\r
+ $setting = $instance->setting;\r
+ if ( isset($setting) ) {\r
+ $requestparams["ext_ims_lti_tool_setting"] = $setting;\r
+ }\r
+ }\r
+\r
+ // Send user's name and email data if appropriate\r
+ if ( $typeconfig['sendname'] == 1 ||\r
+ ( $typeconfig['sendname'] == 2 && $instance->instructorchoicesendname == 1 ) ) {\r
+ $requestparams["lis_person_name_given"] = $USER->firstname;\r
+ $requestparams["lis_person_name_family"] = $USER->lastname;\r
+ $requestparams["lis_person_name_full"] = $USER->firstname." ".$USER->lastname;\r
+ }\r
+\r
+ if ( $typeconfig['sendemailaddr'] == 1 ||\r
+ ( $typeconfig['sendemailaddr'] == 2 && $instance->instructorchoicesendemailaddr == 1 ) ) {\r
+ $requestparams["lis_person_contact_email_primary"] = $USER->email;\r
+ }\r
+\r
+ // Concatenate the custom parameters from the administrator and the instructor\r
+ // Instructor parameters are only taken into consideration if the administrator\r
+ // has giver permission\r
+ $customstr = $typeconfig['customparameters'];\r
+ $instructorcustomstr = $instance->instructorcustomparameters;\r
+ $custom = array();\r
+ $instructorcustom = array();\r
+ if ($customstr) {\r
+ $custom = split_custom_parameters($customstr);\r
+ }\r
+ if (!isset($typeconfig['allowinstructorcustom']) || $typeconfig['allowinstructorcustom'] == 0) {\r
+ $requestparams = array_merge($custom, $requestparams);\r
+ } else {\r
+ if ($instructorcustomstr) {\r
+ $instructorcustom = split_custom_parameters($instructorcustomstr);\r
+ }\r
+ foreach ($instructorcustom as $key => $val) {\r
+ if (array_key_exists($key, $custom)) {\r
+ // Ignore the instructor's parameter\r
+ } else {\r
+ $custom[$key] = $val;\r
+ }\r
+ }\r
+ $requestparams = array_merge($custom, $requestparams);\r
+ }\r
+\r
+ return $requestparams;\r
+}\r
+\r
+/**\r
+ * Splits the custom parameters field to the various parameters\r
+ *\r
+ * @param string $customstr String containing the parameters\r
+ *\r
+ * @return Array of custom parameters\r
+ */\r
+function split_custom_parameters($customstr) {\r
+ $textlib = textlib_get_instance();\r
+\r
+ $lines = preg_split("/[\n;]/", $customstr);\r
+ $retval = array();\r
+ foreach ($lines as $line) {\r
+ $pos = strpos($line, "=");\r
+ if ( $pos === false || $pos < 1 ) {\r
+ continue;\r
+ }\r
+ $key = trim($textlib->substr($line, 0, $pos));\r
+ $val = trim($textlib->substr($line, $pos+1));\r
+ $key = map_keyname($key);\r
+ $retval['custom_'.$key] = $val;\r
+ }\r
+ return $retval;\r
+}\r
+\r
+/**\r
+ * Used for building the names of the different custom parameters\r
+ *\r
+ * @param string $key Parameter name\r
+ *\r
+ * @return string Processed name\r
+ */\r
+function map_keyname($key) {\r
+ $textlib = textlib_get_instance();\r
+\r
+ $newkey = "";\r
+ $key = $textlib->strtolower(trim($key));\r
+ foreach (str_split($key) as $ch) {\r
+ if ( ($ch >= 'a' && $ch <= 'z') || ($ch >= '0' && $ch <= '9') ) {\r
+ $newkey .= $ch;\r
+ } else {\r
+ $newkey .= '_';\r
+ }\r
+ }\r
+ return $newkey;\r
+}\r
+\r
+/**\r
+ * Returns the IMS user role in a given context\r
+ *\r
+ * This function queries Moodle for an user role and\r
+ * returns the correspondant IMS role\r
+ *\r
+ * @param StdClass $user Moodle user instance\r
+ * @param StdClass $context Moodle context\r
+ *\r
+ * @return string IMS Role\r
+ *\r
+ */\r
+function basiclti_get_ims_role($user, $context) {\r
+\r
+ $roles = get_user_roles($context, $user->id);\r
+ $rolesname = array();\r
+ foreach ($roles as $role) {\r
+ $rolesname[] = $role->shortname;\r
+ }\r
+\r
+ if (in_array('admin', $rolesname) || in_array('coursecreator', $rolesname)) {\r
+ return get_string('imsroleadmin', 'basiclti');\r
+ }\r
+\r
+ if (in_array('editingteacher', $rolesname) || in_array('teacher', $rolesname)) {\r
+ return get_string('imsroleinstructor', 'basiclti');\r
+ }\r
+\r
+ return get_string('imsrolelearner', 'basiclti');\r
+}\r
+\r
+/**\r
+ * Returns configuration details for the tool\r
+ *\r
+ * @param int $typeid Basic LTI tool typeid\r
+ *\r
+ * @return array Tool Configuration\r
+ */\r
+function basiclti_get_type_config($typeid) {\r
+ global $DB;\r
+\r
+ $typeconfig = array();\r
+ $configs = $DB->get_records('basiclti_types_config', array('typeid' => $typeid));\r
+ if (!empty($configs)) {\r
+ foreach ($configs as $config) {\r
+ $typeconfig[$config->name] = $config->value;\r
+ }\r
+ }\r
+ return $typeconfig;\r
+}\r
+\r
+/**\r
+ * Returns all tool instances with a typeid of 0 that\r
+ * marks them as unconfigured. These tools usually proceed from a\r
+ * backup - restore process.\r
+ *\r
+ */\r
+function basiclti_get_unconfigured_tools() {\r
+ global $DB;\r
+\r
+ return $DB->get_records('basiclti', array('typeid' => 0));\r
+}\r
+\r
+/**\r
+ * Returns all basicLTI tools configured by the administrator\r
+ *\r
+ */\r
+function basiclti_filter_get_types() {\r
+ global $DB;\r
+\r
+ return $DB->get_records('basiclti_types');\r
+}\r
+\r
+/**\r
+ * Prints the various configured tool types\r
+ *\r
+ */\r
+function basiclti_filter_print_types() {\r
+ global $CFG;\r
+\r
+ $types = basiclti_filter_get_types();\r
+ if (!empty($types)) {\r
+ echo '<ul>';\r
+ foreach ($types as $type) {\r
+ echo '<li>'.\r
+ $type->name.\r
+ '<span class="commands">'.\r
+ '<a class="editing_update" href="typessettings.php?action=update&id='.$type->id.'&sesskey='.sesskey().'" title="Update">'.\r
+ '<img class="iconsmall" alt="Update" src="'.$CFG->wwwroot.'/pix/t/edit.gif"/>'.\r
+ '</a>'.\r
+ '<a class="editing_delete" href="typessettings.php?action=delete&id='.$type->id.'&sesskey='.sesskey().'" title="Delete">'.\r
+ '<img class="iconsmall" alt="Delete" src="'.$CFG->wwwroot.'/pix/t/delete.gif"/>'.\r
+ '</a>'.\r
+ '</span>'.\r
+ '</li>';\r
+\r
+ }\r
+ echo '</ul>';\r
+ } else {\r
+ echo '<div class="message">';\r
+ echo get_string('notypes', 'basiclti');\r
+ echo '</div>';\r
+ }\r
+}\r
+\r
+/**\r
+ * Delete a Basic LTI configuration\r
+ *\r
+ * @param int $id Configuration id\r
+ */\r
+function basiclti_delete_type($id) {\r
+ global $DB;\r
+\r
+ $instances = $DB->get_records('basiclti', array('typeid' => $id));\r
+ foreach ($instances as $instance) {\r
+ $instance->typeid = 0;\r
+ $DB->update_record('basiclti', $instance);\r
+ }\r
+\r
+ $DB->delete_records('basiclti_types', array('id' => $id));\r
+ $DB->delete_records('basiclti_types_config', array('typeid' => $id));\r
+}\r
+\r
+/**\r
+ * Transforms a basic LTI object to an array\r
+ *\r
+ * @param object $bltiobject Basic LTI object\r
+ *\r
+ * @return array Basic LTI configuration details\r
+ */\r
+function basiclti_get_config($bltiobject) {\r
+ $typeconfig = array();\r
+ $typeconfig = (array)$bltiobject;\r
+ $additionalconfig = basiclti_get_type_config($bltiobject->typeid);\r
+ $typeconfig = array_merge($typeconfig, $additionalconfig);\r
+ return $typeconfig;\r
+}\r
+\r
+/**\r
+ *\r
+ * Generates some of the tool configuration based on the instance details\r
+ *\r
+ * @param int $id\r
+ *\r
+ * @return Instance configuration\r
+ *\r
+ */\r
+function basiclti_get_type_config_from_instance($id) {\r
+ global $DB;\r
+\r
+ $instance = $DB->get_record('basiclti', array('id' => $id));\r
+ $config = basiclti_get_config($instance);\r
+\r
+ $type = new stdClass();\r
+ $type->lti_fix = $id;\r
+ if (isset($config['toolurl'])) {\r
+ $type->lti_toolurl = $config['toolurl'];\r
+ }\r
+ if (isset($config['preferheight'])) {\r
+ $type->lti_preferheight = $config['preferheight'];\r
+ }\r
+ if (isset($config['instructorchoicesendname'])) {\r
+ $type->lti_sendname = $config['instructorchoicesendname'];\r
+ }\r
+ if (isset($config['instructorchoicesendemailaddr'])) {\r
+ $type->lti_sendemailaddr = $config['instructorchoicesendemailaddr'];\r
+ }\r
+ if (isset($config['instructorchoiceacceptgrades'])) {\r
+ $type->lti_acceptgrades = $config['instructorchoiceacceptgrades'];\r
+ }\r
+ if (isset($config['instructorchoiceallowroster'])) {\r
+ $type->lti_allowroster = $config['instructorchoiceallowroster'];\r
+ }\r
+ if (isset($config['instructorchoiceallowsetting'])) {\r
+ $type->lti_allowsetting = $config['instructorchoiceallowsetting'];\r
+ }\r
+ if (isset($config['instructorcustomparameters'])) {\r
+ $type->lti_allowsetting = $config['instructorcustomparameters'];\r
+ }\r
+ return $type;\r
+}\r
+\r
+/**\r
+ * Generates some of the tool configuration based on the admin configuration details\r
+ *\r
+ * @param int $id\r
+ *\r
+ * @return Configuration details\r
+ */\r
+function basiclti_get_type_type_config($id) {\r
+ global $DB;\r
+\r
+ $basicltitype = $DB->get_record('basiclti_types', array('id' => $id));\r
+ $config = basiclti_get_type_config($id);\r
+\r
+ $type->lti_typename = $basicltitype->name;\r
+ if (isset($config['toolurl'])) {\r
+ $type->lti_toolurl = $config['toolurl'];\r
+ }\r
+ if (isset($config['resourcekey'])) {\r
+ $type->lti_resourcekey = $config['resourcekey'];\r
+ }\r
+ if (isset($config['password'])) {\r
+ $type->lti_password = $config['password'];\r
+ }\r
+ if (isset($config['preferheight'])) {\r
+ $type->lti_preferheight = $config['preferheight'];\r
+ }\r
+ if (isset($config['sendname'])) {\r
+ $type->lti_sendname = $config['sendname'];\r
+ }\r
+ if (isset($config['instructorchoicesendname'])){\r
+ $type->lti_instructorchoicesendname = $config['instructorchoicesendname'];\r
+ }\r
+ if (isset($config['sendemailaddr'])){\r
+ $type->lti_sendemailaddr = $config['sendemailaddr'];\r
+ }\r
+ if (isset($config['instructorchoicesendemailaddr'])){\r
+ $type->lti_instructorchoicesendemailaddr = $config['instructorchoicesendemailaddr'];\r
+ }\r
+ if (isset($config['acceptgrades'])){\r
+ $type->lti_acceptgrades = $config['acceptgrades'];\r
+ }\r
+ if (isset($config['instructorchoiceacceptgrades'])){\r
+ $type->lti_instructorchoiceacceptgrades = $config['instructorchoiceacceptgrades'];\r
+ }\r
+ if (isset($config['allowroster'])){\r
+ $type->lti_allowroster = $config['allowroster'];\r
+ }\r
+ if (isset($config['instructorchoiceallowroster'])){\r
+ $type->lti_instructorchoiceallowroster = $config['instructorchoiceallowroster'];\r
+ }\r
+ if (isset($config['allowsetting'])){\r
+ $type->lti_allowsetting = $config['allowsetting'];\r
+ }\r
+ if (isset($config['instructorchoiceallowsetting'])){\r
+ $type->lti_instructorchoiceallowsetting = $config['instructorchoiceallowsetting'];\r
+ }\r
+ if (isset($config['customparameters'])) {\r
+ $type->lti_customparameters = $config['customparameters'];\r
+ }\r
+ if (isset($config['allowinstructorcustom'])) {\r
+ $type->lti_allowinstructorcustom = $config['allowinstructorcustom'];\r
+ }\r
+ if (isset($config['organizationid'])) {\r
+ $type->lti_organizationid = $config['organizationid'];\r
+ }\r
+ if (isset($config['organizationurl'])) {\r
+ $type->lti_organizationurl = $config['organizationurl'];\r
+ }\r
+ if (isset($config['organizationdescr'])) {\r
+ $type->lti_organizationdescr = $config['organizationdescr'];\r
+ }\r
+ if (isset($config['launchinpopup'])) {\r
+ $type->lti_launchinpopup = $config['launchinpopup'];\r
+ }\r
+ if (isset($config['debuglaunch'])) {\r
+ $type->lti_debuglaunch = $config['debuglaunch'];\r
+ }\r
+ if (isset($config['moodle_course_field'])) {\r
+ $type->lti_moodle_course_field = $config['moodle_course_field'];\r
+ }\r
+ if (isset($config['module_class_type'])) {\r
+ $type->lti_module_class_type = $config['module_class_type'];\r
+ }\r
+\r
+ return $type;\r
+}\r
+\r
+/**\r
+ * Add a tool configuration in the database\r
+ *\r
+ * @param $config Tool configuration\r
+ *\r
+ * @return int Record id number\r
+ */\r
+function basiclti_add_config($config) {\r
+ global $DB;\r
+\r
+ return $DB->insert_record('basiclti_types_config', $config);\r
+}\r
+\r
+/**\r
+ * Updates a tool configuration in the database\r
+ *\r
+ * @param $config Tool configuration\r
+ *\r
+ * @return Record id number\r
+ */\r
+function basiclti_update_config($config) {\r
+ global $DB;\r
+\r
+ $return = true;\r
+ if ($old = $DB->get_record('basiclti_types_config', array('typeid' => $config->typeid, 'name' => $config->name))) {\r
+ $config->id = $old->id;\r
+ $return = $DB->update_record('basiclti_types_config', $config);\r
+ } else {\r
+ $return = $DB->insert_record('basiclti_types_config', $config);\r
+ }\r
+ return $return;\r
+}\r
+\r
+/**\r
+ * Prints the screen that handles misconfigured objects due to\r
+ * an incomplete backup - restore process\r
+ *\r
+ * @param int $id ID of the misconfigured tool\r
+ *\r
+ */\r
+function basiclti_fix_misconfigured_choice($id) {\r
+ global $CFG, $USER, $OUTPUT;\r
+\r
+ echo $OUTPUT->box_start('generalbox');\r
+ echo '<div>';\r
+ $types = basiclti_filter_get_types();\r
+ if (!empty($types)) {\r
+ echo '<h4 class="main">'.get_string('fixexistingconf', 'basiclti').'</h4></br>';\r
+ echo '<form action='.$CFG->wwwroot.'/mod/basiclti/typessettings.php?action=fix&sesskey='.$USER->sesskey.' method="post">';\r
+\r
+ foreach ($types as $type) {\r
+ echo '<input type="radio" name="useexisting" value="'.$type->id.'" />'.$type->name.'<br />';\r
+ }\r
+ echo '<input type="hidden" name="id" value="'.$id.'"/>';\r
+ echo '<br />';\r
+ echo '<div class="message"><input type="submit" value="'.get_string('fixold', 'basiclti').'"></div>';\r
+ echo '</form>';\r
+ } else {\r
+ echo '<div class="message">';\r
+ echo get_string('notypes', 'basiclti');\r
+ echo '</div>';\r
+ }\r
+ echo '</div>';\r
+ echo $OUTPUT->box_end();\r
+\r
+ echo $OUTPUT->box_start("generalbox");\r
+ echo '<div>';\r
+ echo '<h4 class="main">'.get_string('fixnewconf', 'basiclti').'</h4></br>';\r
+ echo '<form action='.$CFG->wwwroot.'/mod/basiclti/typessettings.php?action=fix&sesskey='.$USER->sesskey.' method="post">';\r
+ echo '<input type="hidden" name="id" value="'.$id.'"/>';\r
+ echo '<input type="hidden" name="definenew" value="1"/>';\r
+ echo '<div class="message"><input type="submit" value="'.get_string('fixnew', 'basiclti').'"></div>';\r
+ echo '</form>';\r
+ echo '</div>';\r
+ echo $OUTPUT->box_end();\r
+\r
+}\r
+\r
+\r
+/**\r
+ * Signs the petition to launch the external tool using OAuth\r
+ *\r
+ * @param $oldparms Parameters to be passed for signing\r
+ * @param $endpoint url of the external tool\r
+ * @param $method Method for sending the parameters (e.g. POST)\r
+ * @param $oauth_consumoer_key Key\r
+ * @param $oauth_consumoer_secret Secret\r
+ * @param $submittext The text for the submit button\r
+ * @param $orgid LMS name\r
+ * @param $orgdesc LMS key\r
+ */\r
+function sign_parameters($oldparms, $endpoint, $method, $oauthconsumerkey, $oauthconsumersecret, $submittext, $orgid /*, $orgdesc*/) {\r
+ global $lastbasestring;\r
+ $parms = $oldparms;\r
+ $parms["lti_version"] = "LTI-1p0";\r
+ $parms["lti_message_type"] = "basic-lti-launch-request";\r
+ if ( $orgid ) {\r
+ $parms["tool_consumer_instance_guid"] = $orgid;\r
+ }\r
+ /* Suppress this for now - Chuck\r
+ if ( $orgdesc ) $parms["tool_consumer_instance_description"] = $orgdesc;\r
+ */\r
+ $parms["ext_submit"] = $submittext;\r
+\r
+ $testtoken = '';\r
+\r
+ $hmacmethod = new OAuthSignatureMethod_HMAC_SHA1();\r
+ $testconsumer = new OAuthConsumer($oauthconsumerkey, $oauthconsumersecret, null);\r
+\r
+ $accreq = OAuthRequest::from_consumer_and_token($testconsumer, $testtoken, $method, $endpoint, $parms);\r
+ $accreq->sign_request($hmacmethod, $testconsumer, $testtoken);\r
+\r
+ // Pass this back up "out of band" for debugging\r
+ $lastbasestring = $accreq->get_signature_base_string();\r
+\r
+ $newparms = $accreq->get_parameters();\r
+\r
+ return $newparms;\r
+}\r
+\r
+/**\r
+ * Posts the launch petition HTML\r
+ *\r
+ * @param $newparms Signed parameters\r
+ * @param $endpoint URL of the external tool\r
+ * @param $debug Debug (true/false)\r
+ */\r
+function post_launch_html($newparms, $endpoint, $debug=false, $height=false) {\r
+ global $lastbasestring;\r
+ if ($height) {\r
+ $r = "<form action=\"".$endpoint."\" name=\"ltiLaunchForm\" id=\"ltiLaunchForm\" method=\"post\" encType=\"application/x-www-form-urlencoded\">\n";\r
+ } else {\r
+ $r = "<form action=\"".$endpoint."\" name=\"ltiLaunchForm\" id=\"ltiLaunchForm\" method=\"post\" encType=\"application/x-www-form-urlencoded\">\n";\r
+ }\r
+ $submittext = $newparms['ext_submit'];\r
+\r
+ // Contruct html for the launch parameters\r
+ foreach ($newparms as $key => $value) {\r
+ $key = htmlspecialchars($key);\r
+ $value = htmlspecialchars($value);\r
+ if ( $key == "ext_submit" ) {\r
+ $r .= "<input type=\"submit\" name=\"";\r
+ } else {\r
+ $r .= "<input type=\"hidden\" name=\"";\r
+ }\r
+ $r .= $key;\r
+ $r .= "\" value=\"";\r
+ $r .= $value;\r
+ $r .= "\"/>\n";\r
+ }\r
+\r
+ if ( $debug ) {\r
+ $r .= "<script language=\"javascript\"> \n";\r
+ $r .= " //<![CDATA[ \n";\r
+ $r .= "function basicltiDebugToggle() {\n";\r
+ $r .= " var ele = document.getElementById(\"basicltiDebug\");\n";\r
+ $r .= " if(ele.style.display == \"block\") {\n";\r
+ $r .= " ele.style.display = \"none\";\n";\r
+ $r .= " }\n";\r
+ $r .= " else {\n";\r
+ $r .= " ele.style.display = \"block\";\n";\r
+ $r .= " }\n";\r
+ $r .= "} \n";\r
+ $r .= " //]]> \n";\r
+ $r .= "</script>\n";\r
+ $r .= "<a id=\"displayText\" href=\"javascript:basicltiDebugToggle();\">";\r
+ $r .= get_string("toggle_debug_data", "basiclti")."</a>\n";\r
+ $r .= "<div id=\"basicltiDebug\" style=\"display:none\">\n";\r
+ $r .= "<b>".get_string("basiclti_endpoint", "basiclti")."</b><br/>\n";\r
+ $r .= $endpoint . "<br/>\n <br/>\n";\r
+ $r .= "<b>".get_string("basiclti_parameters", "basiclti")."</b><br/>\n";\r
+ foreach ($newparms as $key => $value) {\r
+ $key = htmlspecialchars($key);\r
+ $value = htmlspecialchars($value);\r
+ $r .= "$key = $value<br/>\n";\r
+ }\r
+ $r .= " <br/>\n";\r
+ $r .= "<p><b>".get_string("basiclti_base_string", "basiclti")."</b><br/>\n".$lastbasestring."</p>\n";\r
+ $r .= "</div>\n";\r
+ }\r
+ $r .= "</form>\n";\r
+\r
+ if ( ! $debug ) {\r
+ $ext_submit = "ext_submit";\r
+ $ext_submit_text = $submittext;\r
+ $r .= " <script type=\"text/javascript\"> \n" .\r
+ " //<![CDATA[ \n" .\r
+ " document.getElementById(\"ltiLaunchForm\").style.display = \"none\";\n" .\r
+ " nei = document.createElement('input');\n" .\r
+ " nei.setAttribute('type', 'hidden');\n" .\r
+ " nei.setAttribute('name', '".$ext_submit."');\n" .\r
+ " nei.setAttribute('value', '".$ext_submit_text."');\n" .\r
+ " document.getElementById(\"ltiLaunchForm\").appendChild(nei);\n" .\r
+ " document.ltiLaunchForm.submit(); \n" .\r
+ " //]]> \n" .\r
+ " </script> \n";\r
+ }\r
+ return $r;\r
+}\r
+\r
+/**\r
+ * Returns a link with info about the state of the basiclti submissions\r
+ *\r
+ * This is used by view_header to put this link at the top right of the page.\r
+ * For teachers it gives the number of submitted assignments with a link\r
+ * For students it gives the time of their submission.\r
+ * This will be suitable for most assignment types.\r
+ *\r
+ * @global object\r
+ * @global object\r
+ * @param bool $allgroup print all groups info if user can access all groups, suitable for index.php\r
+ * @return string\r
+ */\r
+function submittedlink($cm, $allgroups=false) {\r
+ global $CFG;\r
+\r
+ $submitted = '';\r
+ $urlbase = "{$CFG->wwwroot}/mod/basiclti/";\r
+\r
+ $context = get_context_instance(CONTEXT_MODULE, $cm->id);\r
+ if (has_capability('mod/basiclti:grade', $context)) {\r
+ if ($allgroups and has_capability('moodle/site:accessallgroups', $context)) {\r
+ $group = 0;\r
+ } else {\r
+ $group = groups_get_activity_group($cm);\r
+ }\r
+\r
+ $submitted = '<a href="'.$urlbase.'submissions.php?id='.$cm->id.'">'.\r
+ get_string('viewsubmissions', 'basiclti').'</a>';\r
+ } else {\r
+ if (isloggedin()) {\r
+ // TODO Insert code for students if needed\r
+ }\r
+ }\r
+\r
+ return $submitted;\r
+}\r
+\r
--- /dev/null
+<?php\r
+// This file is part of BasicLTI4Moodle\r
+//\r
+// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)\r
+// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web\r
+// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI\r
+// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS\r
+// are already supporting or going to support BasicLTI. This project Implements the consumer\r
+// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.\r
+// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem\r
+// at the GESSI research group at UPC.\r
+// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI\r
+// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a\r
+// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.\r
+//\r
+// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis\r
+// of the Universitat Politecnica de Catalunya http://www.upc.edu\r
+// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu\r
+//\r
+// Moodle is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License, or\r
+// (at your option) any later version.\r
+//\r
+// Moodle is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\r
+\r
+/**\r
+ * This file defines the main basiclti configuration form\r
+ *\r
+ * @package basiclti\r
+ * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis\r
+ * marc.alier@upc.edu\r
+ * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu\r
+ *\r
+ * @author Marc Alier\r
+ * @author Jordi Piguillem\r
+ * @author Nikolas Galanis\r
+ *\r
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r
+ */\r
+\r
+defined('MOODLE_INTERNAL') || die;\r
+\r
+require_once($CFG->dirroot.'/course/moodleform_mod.php');\r
+require_once($CFG->dirroot.'/mod/basiclti/locallib.php');\r
+\r
+class mod_basiclti_mod_form extends moodleform_mod {\r
+\r
+ function definition() {\r
+ global $DB;\r
+\r
+ $typename = optional_param('type', false, PARAM_ALPHA);\r
+\r
+ if (empty($typename)) {\r
+ //Updating instance\r
+ if (!empty($this->_instance)) {\r
+ $basiclti = $DB->get_record('basiclti', array('id' => $this->_instance));\r
+ $this->typeid = $basiclti->typeid;\r
+\r
+ $typeconfig = basiclti_get_config($basiclti);\r
+ $this->typeconfig = $typeconfig;\r
+\r
+ } else { // New not pre-configured instance\r
+ $this->typeid = 0;\r
+ }\r
+ } else {\r
+ // New pre-configured instance\r
+ $basicltitype = $DB->get_record('basiclti_types', array('rawname' => $typename));\r
+ $this->typeid = $basicltitype->id;\r
+\r
+ $typeconfig = basiclti_get_type_config($this->typeid);\r
+ $this->typeconfig = $typeconfig;\r
+ }\r
+\r
+ $mform =& $this->_form;\r
+//-------------------------------------------------------------------------------\r
+ /// Adding the "general" fieldset, where all the common settings are shown\r
+ $mform->addElement('header', 'general', get_string('general', 'form'));\r
+ /// Adding the standard "name" field\r
+ $mform->addElement('text', 'name', get_string('basicltiname', 'basiclti'), array('size'=>'64'));\r
+ $mform->setType('name', PARAM_TEXT);\r
+ $mform->addRule('name', null, 'required', null, 'client');\r
+ /// Adding the optional "intro" and "introformat" pair of fields\r
+ $this->add_intro_editor(true, get_string('basicltiintro', 'basiclti'));\r
+\r
+//-------------------------------------------------------------------------------\r
+ $mform->addElement('hidden', 'typeid', $this->typeid);\r
+ $mform->addElement('hidden', 'toolurl', $this->typeconfig['toolurl']);\r
+ $mform->addElement('hidden', 'type', $typename);\r
+\r
+//-------------------------------------------------------------------------------\r
+ // Add privacy preferences fieldset where users choose whether to send their data\r
+ $mform->addElement('header', 'privacy', get_string('privacy', 'basiclti'));\r
+\r
+ $privacyoptions=array();\r
+ $privacyoptions[0] = get_string('donot', 'basiclti');\r
+ $privacyoptions[1] = get_string('send', 'basiclti');\r
+\r
+ $mform->addElement('select', 'instructorchoicesendname', get_string('sendname', 'basiclti'), $privacyoptions);\r
+\r
+ if (isset($this->typeconfig['instructorchoicesendname'])) {\r
+ if ($this->typeconfig['instructorchoicesendname'] == 0) {\r
+ $mform->setDefault('instructorchoicesendname', '0');\r
+ } else if ($this->typeconfig['instructorchoicesendname'] == 1) {\r
+ $mform->setDefault('instructorchoicesendname', '1');\r
+ }\r
+ }\r
+// $mform->addHelpButton('instructorchoicesendname', 'sendname', 'basiclti');\r
+\r
+ $mform->addElement('select', 'instructorchoicesendemailaddr', get_string('sendemailaddr', 'basiclti'), $privacyoptions);\r
+\r
+ if (isset($this->typeconfig['instructorchoicesendemailaddr'])) {\r
+ if ($this->typeconfig['instructorchoicesendemailaddr'] == 0) {\r
+ $mform->setDefault('instructorchoicesendemailaddr', '0');\r
+ } else if ($this->typeconfig['instructorchoicesendemailaddr'] == 1) {\r
+ $mform->setDefault('instructorchoicesendemailaddr', '1');\r
+ }\r
+ }\r
+ // $mform->addHelpButton('instructorchoicesendemailaddr', 'sendemailaddr', 'basiclti');\r
+\r
+//-------------------------------------------------------------------------------\r
+ // Add grading preferences fieldset where the instructor determines whether to accept grades\r
+ $mform->addElement('header', 'extensions', get_string('extensions', 'basiclti'));\r
+\r
+ $extensionoptions=array();\r
+ $extensionoptions[0] = get_string('donotaccept', 'basiclti');\r
+ $extensionoptions[1] = get_string('accept', 'basiclti');\r
+\r
+ $mform->addElement('select', 'instructorchoiceacceptgrades', get_string('acceptgrades', 'basiclti'), $extensionoptions);\r
+ if (isset($this->typeconfig['instructorchoiceacceptgrades'])) {\r
+ if ($this->typeconfig['instructorchoiceacceptgrades'] == 0) {\r
+ $mform->setDefault('instructorchoiceacceptgrades', '0');\r
+ } else if ($this->typeconfig['instructorchoiceacceptgrades'] == 1) {\r
+ $mform->setDefault('instructorchoiceacceptgrades', '1');\r
+ }\r
+ }\r
+ // $mform->addHelpButton('instructorchoiceacceptgrades', 'acceptgrades', 'basiclti');\r
+\r
+ $extensionoptions=array();\r
+ $extensionoptions[0] = get_string('donotallow', 'basiclti');\r
+ $extensionoptions[1] = get_string('allow', 'basiclti');\r
+\r
+ $mform->addElement('select', 'instructorchoiceallowroster', get_string('allowroster', 'basiclti'), $extensionoptions);\r
+ if (isset($this->typeconfig['instructorchoiceallowroster'])) {\r
+ if ($this->typeconfig['instructorchoiceallowroster'] == 0) {\r
+ $mform->setDefault('instructorchoiceallowroster', '0');\r
+ } else if ($this->typeconfig['instructorchoiceallowroster'] == 1) {\r
+ $mform->setDefault('instructorchoiceallowroster', '1');\r
+ }\r
+ }\r
+ // $mform->addHelpButton('instructorchoiceallowroster', 'allowroster', 'basiclti');\r
+ $mform->setAdvanced('instructorchoiceallowroster');\r
+\r
+ $mform->addElement('select', 'instructorchoiceallowsetting', get_string('allowsetting', 'basiclti'), $extensionoptions);\r
+\r
+ if (isset($this->typeconfig['instructorchoiceallowsetting'])) {\r
+ if ($this->typeconfig['instructorchoiceallowsetting'] == 0) {\r
+ $mform->setDefault('instructorchoiceallowsetting', '0');\r
+ } else if ($this->typeconfig['instructorchoiceallowsetting'] == 1) {\r
+ $mform->setDefault('instructorchoiceallowsetting', '1');\r
+ }\r
+ }\r
+// $mform->addHelpButton('instructorchoiceallowsetting', 'allowsetting', 'basiclti');\r
+ $mform->setAdvanced('instructorchoiceallowsetting');\r
+\r
+//-------------------------------------------------------------------------------\r
+ if (isset($this->typeconfig['allowinstructorcustom'])) {\r
+ if ($this->typeconfig['allowinstructorcustom'] == 1) {\r
+ // Add custom parameters fieldset\r
+ $mform->addElement('header', 'launchoptions', get_string('custominstr', 'basiclti'));\r
+\r
+ $mform->addElement('textarea', 'instructorcustomparameters', '', array('rows'=>15, 'cols'=>60));\r
+ $mform->setType('instructorcustomparameters', PARAM_TEXT);\r
+ $mform->setAdvanced('instructorcustomparameters');\r
+ }\r
+ }\r
+\r
+//-------------------------------------------------------------------------------\r
+ // Add launch parameters fieldset\r
+ $mform->addElement('header', 'launchoptions', get_string('launchoptions', 'basiclti'));\r
+\r
+ // Size parameters\r
+ $mform->addElement('text', 'preferheight', get_string('preferheight', 'basiclti'));\r
+ if (isset($this->typeconfig['preferheight'])) {\r
+ $mform->setDefault('preferheight', $this->typeconfig['preferheight']);\r
+ }\r
+\r
+ $launchoptions=array();\r
+ $launchoptions[0] = get_string('launch_in_moodle', 'basiclti');\r
+ $launchoptions[1] = get_string('launch_in_popup', 'basiclti');\r
+\r
+ $mform->addElement('select', 'launchinpopup', get_string('launchinpopup', 'basiclti'), $launchoptions);\r
+\r
+ if (isset($this->typeconfig['launchinpopup'])) {\r
+ if ($this->typeconfig['launchinpopup'] == 0) {\r
+ $mform->setDefault('launchinpopup', '0');\r
+ } else if ($this->typeconfig['launchinpopup'] == 1) {\r
+ $mform->setDefault('launchinpopup', '1');\r
+ }\r
+ }\r
+\r
+ $debugoptions=array();\r
+ $debugoptions[0] = get_string('debuglaunchoff', 'basiclti');\r
+ $debugoptions[1] = get_string('debuglaunchon', 'basiclti');\r
+\r
+ $mform->addElement('select', 'debuglaunch', get_string('debuglaunch', 'basiclti'), $debugoptions);\r
+\r
+ if (isset($this->typeconfig['debuglaunch'])) {\r
+ if ($this->typeconfig['debuglaunch'] == 0) {\r
+ $mform->setDefault('debuglaunch', '0');\r
+ } else if ($this->typeconfig['debuglaunch'] == 1) {\r
+ $mform->setDefault('debuglaunch', '1');\r
+ }\r
+ }\r
+\r
+//-------------------------------------------------------------------------------\r
+ // Organization parameters\r
+ if (isset($this->typeconfig['organizationid'])) {\r
+ $mform->addElement('hidden', 'organizationid', $this->typeconfig['organizationid']);\r
+ }\r
+ if (isset($this->typeconfig['organizationurl'])) {\r
+ $mform->addElement('hidden', 'organizationurl', $this->typeconfig['organizationurl']);\r
+ }\r
+// $mform->addElement('hidden', 'organizationdescr', $this->typeconfig['organizationdescr']);\r
+\r
+//-------------------------------------------------------------------------------\r
+ // add standard elements, common to all modules\r
+ $this->standard_coursemodule_elements();\r
+//-------------------------------------------------------------------------------\r
+ // add standard buttons, common to all modules\r
+ $this->add_action_buttons();\r
+ }\r
+\r
+ /**\r
+ * Make fields editable or non-editable depending on the administrator choices\r
+ * @see moodleform_mod::definition_after_data()\r
+ */\r
+ function definition_after_data() {\r
+ parent::definition_after_data();\r
+ $mform =& $this->_form;\r
+ $typeid =& $mform->getElement('typeid');\r
+ $typeidvalue = $mform->getElementValue('typeid');\r
+\r
+ //Depending on the selection of the administrator\r
+ //we don't want to have these appear as possible selections in the form but\r
+ //we want the form to display them if they are set.\r
+ if (!empty($typeidvalue)) {\r
+ $typeconfig = basiclti_get_type_config($typeidvalue);\r
+\r
+ if ($typeconfig["sendname"] != 2) {\r
+ $field =& $mform->getElement('instructorchoicesendname');\r
+ $mform->setDefault('instructorchoicesendname', $typeconfig["sendname"]);\r
+ $field->freeze();\r
+ $field->setPersistantFreeze(true);\r
+ }\r
+ if ($typeconfig["sendemailaddr"] != 2) {\r
+ $field =& $mform->getElement('instructorchoicesendemailaddr');\r
+ $mform->setDefault('instructorchoicesendemailaddr', $typeconfig["sendemailaddr"]);\r
+ $field->freeze();\r
+ $field->setPersistantFreeze(true);\r
+ }\r
+ if ($typeconfig["acceptgrades"] != 2) {\r
+ $field =& $mform->getElement('instructorchoiceacceptgrades');\r
+ $mform->setDefault('instructorchoiceacceptgrades', $typeconfig["acceptgrades"]);\r
+ $field->freeze();\r
+ $field->setPersistantFreeze(true);\r
+ }\r
+ if ($typeconfig["allowroster"] != 2) {\r
+ $field =& $mform->getElement('instructorchoiceallowroster');\r
+ $mform->setDefault('instructorchoiceallowroster', $typeconfig["allowroster"]);\r
+ $field->freeze();\r
+ $field->setPersistantFreeze(true);\r
+ }\r
+ if ($typeconfig["allowsetting"] != 2) {\r
+ $field =& $mform->getElement('instructorchoiceallowsetting');\r
+ $mform->setDefault('instructorchoiceallowsetting', $typeconfig["allowsetting"]);\r
+ $field->freeze();\r
+ $field->setPersistantFreeze(true);\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Function overwritten to change default values using\r
+ * global configuration\r
+ *\r
+ * @param array $default_values passed by reference\r
+ */\r
+ function data_preprocessing(&$default_values) {\r
+ global $CFG;\r
+ $default_values['typeid'] = $this->typeid;\r
+\r
+ if (!isset($default_values['toolurl'])) {\r
+ if (isset($this->typeconfig['toolurl'])) {\r
+ $default_values['toolurl'] = $this->typeconfig['toolurl'];\r
+ } else if (isset($CFG->basiclti_toolurl)) {\r
+ $default_values['toolurl'] = $CFG->basiclti_toolurl;\r
+ }\r
+ }\r
+\r
+ if (!isset($default_values['resourcekey'])) {\r
+ if (isset($this->typeconfig['resourcekey'])) {\r
+ $default_values['resourcekey'] = $this->typeconfig['resourcekey'];\r
+ } else if (isset($CFG->basiclti_resourcekey)) {\r
+ $default_values['resourcekey'] = $CFG->basiclti_resourcekey;\r
+ }\r
+ }\r
+\r
+ if (!isset($default_values['password'])) {\r
+ if (isset($this->typeconfig['password'])) {\r
+ $default_values['password'] = $this->typeconfig['password'];\r
+ } else if (isset($CFG->basiclti_password)) {\r
+ $default_values['password'] = $CFG->basiclti_password;\r
+ }\r
+ }\r
+\r
+ if (!isset($default_values['preferheight'])) {\r
+ if (isset($this->typeconfig['preferheight'])) {\r
+ $default_values['preferheight'] = $this->typeconfig['preferheight'];\r
+ } else if (isset($CFG->basiclti_preferheight)) {\r
+ $default_values['preferheight'] = $CFG->basiclti_preferheight;\r
+ }\r
+ }\r
+\r
+ if (!isset($default_values['sendname'])) {\r
+ if (isset($this->typeconfig['sendname'])) {\r
+ $default_values['sendname'] = $this->typeconfig['sendname'];\r
+ } else if (isset($CFG->basiclti_sendname)) {\r
+ $default_values['sendname'] = $CFG->basiclti_sendname;\r
+ }\r
+ }\r
+\r
+ if (!isset($default_values['instructorchoicesendname'])) {\r
+ if (isset($this->typeconfig['instructorchoicesendname'])) {\r
+ $default_values['instructorchoicesendname'] = $this->typeconfig['instructorchoicesendname'];\r
+ } else {\r
+ if ($this->typeconfig['sendname'] == 2) {\r
+ $default_values['instructorchoicesendname'] = $CFG->basiclti_instructorchoicesendname;\r
+ } else {\r
+ $default_values['instructorchoicesendname'] = $this->typeconfig['sendname'];\r
+ }\r
+ }\r
+ }\r
+\r
+ if (!isset($default_values['sendemailaddr'])) {\r
+ if (isset($this->typeconfig['sendemailaddr'])) {\r
+ $default_values['sendemailaddr'] = $this->typeconfig['sendemailaddr'];\r
+ } else if (isset($CFG->basiclti_sendemailaddr)) {\r
+ $default_values['sendemailaddr'] = $CFG->basiclti_sendemailaddr;\r
+ }\r
+ }\r
+\r
+ if (!isset($default_values['instructorchoicesendemailaddr'])) {\r
+ if (isset($this->typeconfig['instructorchoicesendemailaddr'])) {\r
+ $default_values['instructorchoicesendemailaddr'] = $this->typeconfig['instructorchoicesendemailaddr'];\r
+ } else {\r
+ if ($this->typeconfig['sendemailaddr'] == 2) {\r
+ $default_values['instructorchoicesendemailaddr'] = $CFG->basiclti_instructorchoicesendemailaddr;\r
+ } else {\r
+ $default_values['instructorchoicesendemailaddr'] = $this->typeconfig['sendemailaddr'];\r
+ }\r
+ }\r
+ }\r
+\r
+ if (!isset($default_values['acceptgrades'])) {\r
+ if (isset($this->typeconfig['acceptgrades'])) {\r
+ $default_values['acceptgrades'] = $this->typeconfig['acceptgrades'];\r
+ } else if (isset($CFG->basiclti_acceptgrades)) {\r
+ $default_values['acceptgrades'] = $CFG->basiclti_acceptgrades;\r
+ }\r
+ }\r
+\r
+ if (!isset($default_values['instructorchoiceacceptgrades'])) {\r
+ if (isset($this->typeconfig['instructorchoiceacceptgrades'])) {\r
+ $default_values['instructorchoiceacceptgrades'] = $this->typeconfig['instructorchoiceacceptgrades'];\r
+ } else {\r
+ if ($this->typeconfig['acceptgrades'] == 2) {\r
+ $default_values['instructorchoiceacceptgrades'] = $CFG->basiclti_instructorchoiceacceptgrades;\r
+ } else {\r
+ $default_values['instructorchoiceacceptgrades'] = $this->typeconfig['acceptgrades'];\r
+ }\r
+ }\r
+ }\r
+\r
+ if (!isset($default_values['allowroster'])) {\r
+ if (isset($this->typeconfig['allowroster'])) {\r
+ $default_values['allowroster'] = $this->typeconfig['allowroster'];\r
+ } else if (isset($CFG->basiclti_allowroster)) {\r
+ $default_values['allowroster'] = $CFG->basiclti_allowroster;\r
+ }\r
+ }\r
+\r
+ if (!isset($default_values['instructorchoiceallowroster'])) {\r
+ if (isset($this->typeconfig['instructorchoiceallowroster'])) {\r
+ $default_values['instructorchoiceallowroster'] = $this->typeconfig['instructorchoiceallowroster'];\r
+ } else {\r
+ if ($this->typeconfig['allowroster'] == 2) {\r
+ $default_values['instructorchoiceallowroster'] = $CFG->basiclti_instructorchoiceallowroster;\r
+ } else {\r
+ $default_values['instructorchoiceallowroster'] = $this->typeconfig['allowroster'];\r
+ }\r
+ }\r
+ }\r
+\r
+ if (!isset($default_values['allowsetting'])) {\r
+ if (isset($this->typeconfig['allowsetting'])) {\r
+ $default_values['allowsetting'] = $this->typeconfig['allowsetting'];\r
+ } else if (isset($CFG->basiclti_allowsetting)) {\r
+ $default_values['allowsetting'] = $CFG->basiclti_allowsetting;\r
+ }\r
+ }\r
+\r
+ if (!isset($default_values['instructorchoiceallowsetting'])) {\r
+ if (isset($this->typeconfig['instructorchoiceallowsetting'])) {\r
+ $default_values['instructorchoiceallowsetting'] = $this->typeconfig['instructorchoiceallowsetting'];\r
+ } else {\r
+ if ($this->typeconfig['allowsetting'] == 2) {\r
+ $default_values['instructorchoiceallowsetting'] = $CFG->basiclti_instructorchoiceallowsetting;\r
+ } else {\r
+ $default_values['instructorchoiceallowsetting'] = $this->typeconfig['allowsetting'];\r
+ }\r
+ }\r
+ }\r
+\r
+ if (!isset($default_values['customparameters'])) {\r
+ if (isset($this->typeconfig['customparameters'])) {\r
+ $default_values['customparameters'] = $this->typeconfig['customparameters'];\r
+ } else if (isset($CFG->basiclti_customparameters)) {\r
+ $default_values['customparameters'] = $CFG->basiclti_customparameters;\r
+ }\r
+ }\r
+\r
+ if (!isset($default_values['allowinstructorcustom'])) {\r
+ if (isset($this->typeconfig['allowinstructorcustom'])) {\r
+ $default_values['allowinstructorcustom'] = $this->typeconfig['allowinstructorcustom'];\r
+ } else if (isset($CFG->basiclti_allowinstructorcustom)) {\r
+ $default_values['allowinstructorcustom'] = $CFG->basiclti_allowinstructorcustom;\r
+ }\r
+ }\r
+\r
+ if (!isset($default_values['organizationid'])) {\r
+ if (isset($this->typeconfig['organizationid'])) {\r
+ $default_values['organizationid'] = $this->typeconfig['organizationid'];\r
+ } else if (isset($CFG->basiclti_organizationid)) {\r
+ $default_values['organizationid'] = $CFG->basiclti_organizationid;\r
+ }\r
+ }\r
+\r
+ if (!isset($default_values['organizationurl'])) {\r
+ if (isset($this->typeconfig['organizationurl'])) {\r
+ $default_values['organizationurl'] = $this->typeconfig['organizationurl'];\r
+ } else if (isset($CFG->basiclti_organizationurl)) {\r
+ $default_values['organizationurl'] = $CFG->basiclti_organizationurl;\r
+ }\r
+ }\r
+\r
+ if (!isset($default_values['organizationdescr'])) {\r
+ if (isset($this->typeconfig['organizationdescr'])) {\r
+ $default_values['organizationdescr'] = $this->typeconfig['organizationdescr'];\r
+ } else if (isset($CFG->basiclti_organizationdescr)) {\r
+ $default_values['organizationdescr'] = $CFG->basiclti_organizationdescr;\r
+ }\r
+ }\r
+\r
+ if (!isset($default_values['launchinpopup'])) {\r
+ if (isset($this->typeconfig['launchinpopup'])) {\r
+ $default_values['launchinpopup'] = $this->typeconfig['launchinpopup'];\r
+ } else if (isset($CFG->basiclti_launchinpopup)) {\r
+ $default_values['launchinpopup'] = $CFG->basiclti_launchinpopup;\r
+ }\r
+ }\r
+\r
+ }\r
+}\r
+\r
--- /dev/null
+<?php\r
+// This file is part of BasicLTI4Moodle\r
+//\r
+// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)\r
+// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web\r
+// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI\r
+// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS\r
+// are already supporting or going to support BasicLTI. This project Implements the consumer\r
+// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.\r
+// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem\r
+// at the GESSI research group at UPC.\r
+// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI\r
+// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a\r
+// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.\r
+//\r
+// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis\r
+// of the Universitat Politecnica de Catalunya http://www.upc.edu\r
+// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu\r
+//\r
+// Moodle is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License, or\r
+// (at your option) any later version.\r
+//\r
+// Moodle is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\r
+\r
+/**\r
+ * This file contains all necessary code to support basiclti services\r
+ * like outcomes and roster access.\r
+ *\r
+ * @package basiclti\r
+ * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis\r
+ * marc.alier@upc.edu\r
+ * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu\r
+ *\r
+ * @author Marc Alier\r
+ * @author Jordi Piguillem\r
+ * @author Nikolas Galanis\r
+ * @author Charles Severance\r
+ *\r
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r
+ */\r
+\r
+require_once("../../config.php");\r
+require_once($CFG->dirroot.'/mod/basiclti/lib.php');\r
+require_once($CFG->dirroot.'/mod/basiclti/locallib.php');\r
+require_once($CFG->dirroot.'/mod/basiclti/OAuth.php');\r
+require_once($CFG->dirroot.'/mod/basiclti/TrivialStore.php');\r
+\r
+error_reporting(E_ALL & ~E_NOTICE);\r
+ini_set("display_errors", 1);\r
+\r
+$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));\r
+$PAGE->set_url('/mod/basiclti/service.php');\r
+$PAGE->set_pagetype('admin-setting-' . $section);\r
+$PAGE->set_pagelayout('admin');\r
+$PAGE->navigation->clear_cache();\r
+\r
+function message_response($major, $severity, $minor=false, $message=false, $xml=false) {\r
+ $lti_message_type = $_REQUEST['lti_message_type'];\r
+ $retval = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"."\n" .\r
+ "<message_response>\n" .\r
+ " <lti_message_type>$lti_message_type</lti_message_type>\n" .\r
+ " <statusinfo>\n" .\r
+ " <codemajor>$major</codemajor>\n" .\r
+ " <severity>$severity</severity>\n";\r
+ if (! $codeminor === false) {\r
+ $retval = $retval . " <codeminor>$minor</codeminor>\n";\r
+ }\r
+ $retval = $retval .\r
+ " <description>$message</description>\n" .\r
+ " </statusinfo>\n";\r
+ if (! $xml === false) {\r
+ $retval = $retval . $xml;\r
+ }\r
+ $retval = $retval . "</message_response>\n";\r
+ return $retval;\r
+}\r
+\r
+function do_error($message) {\r
+ print message_response('Fail', 'Error', false, $message);\r
+ exit();\r
+}\r
+\r
+$lti_version = $_REQUEST['lti_version'];\r
+if ($lti_version != "LTI-1p0") {\r
+ do_error("Improperly formed message: wrong lti version: ".$lti_version);\r
+}\r
+\r
+$lti_message_type = $_REQUEST['lti_message_type'];\r
+if (! isset($lti_message_type)) {\r
+ do_error("Improperly formed message: no lti_message_type parameter");\r
+}\r
+\r
+$message_type = false;\r
+if ($lti_message_type == "basic-lis-replaceresult" ||\r
+ $lti_message_type == "basic-lis-createresult" ||\r
+ $lti_message_type == "basic-lis-updateresult" ||\r
+ $lti_message_type == "basic-lis-deleteresult" ||\r
+ $lti_message_type == "basic-lis-readresult") {\r
+ $sourcedid = $_REQUEST['sourcedid'];\r
+ $message_type = "basicoutcome";\r
+} else if ($lti_message_type == "basic-lti-loadsetting" ||\r
+ $lti_message_type == "basic-lti-savesetting" ||\r
+ $lti_message_type == "basic-lti-deletesetting") {\r
+ $sourcedid = $_REQUEST['id'];\r
+ $message_type = "toolsetting";\r
+} else if ($lti_message_type == "basic-lis-readmembershipsforcontext") {\r
+ $sourcedid = $_REQUEST['id'];\r
+ $message_type = "roster";\r
+}\r
+\r
+if ($message_type == false) {\r
+ do_error("Illegal lti_message_type");\r
+}\r
+\r
+if (!isset($sourcedid)) {\r
+ do_error("sourcedid missing");\r
+}\r
+// Truncate to maximum length\r
+$sourcedid = substr($sourcedid, 0, 2048);\r
+\r
+try {\r
+ $info = explode(':::', $sourcedid);\r
+ if (! is_array($info)) {\r
+ do_error("Bad sourcedid (1)");\r
+ }\r
+ $signature = $info[0];\r
+ $userid = intval($info[1]);\r
+ $placement = $info[2];\r
+} catch (Exception $e) {\r
+ do_error("Bad sourcedid (2)");\r
+}\r
+\r
+if (isset($signature) && isset($userid) && isset($placement)) {\r
+ // OK\r
+} else {\r
+ do_error("Bad sourcedid (3)");\r
+}\r
+\r
+// Retrieve the Basic LTI placement\r
+if (! $basiclti = $DB->get_record('basiclti', array('id'=>$placement))) {\r
+ do_error("Bad sourcedid (4)");\r
+}\r
+\r
+$basiclti_types_config = (object)$basiclti_types_config;\r
+\r
+$typeconfig = basiclti_get_type_config($basiclti->typeid);\r
+\r
+if (isset($typeconfig) && isset($typeconfig['password'])) {\r
+ // OK\r
+} else {\r
+ do_error("Unable to load type");\r
+}\r
+\r
+if ($message_type == "basicoutcome") {\r
+ if ($typeconfig["acceptgrades"] == 1 ||\r
+ ($typeconfig["acceptgrades"] == 2 && $basiclti->instructorchoiceacceptgrades == 1)) {\r
+ // The placement is configured to accept grades\r
+ } else {\r
+ do_error("Not permitted (1)");\r
+ }\r
+} else if ($message_type == "toolsetting") {\r
+ if ($typeconfig["allowsetting"] == 1 ||\r
+ ($typeconfig["allowsetting"] == 2 && $basiclti->instructorchoiceallowsetting == 1)) {\r
+ // OK\r
+ } else {\r
+ do_error("Not permitted (2)");\r
+ }\r
+} else if ($message_type == "roster") {\r
+ if ($typeconfig["allowroster"] == 1 ||\r
+ ($typeconfig["allowroster"] == 2 && $basiclti->instructorchoiceallowroster == 1)) {\r
+ // OK\r
+ } else {\r
+ do_error("Not permitted (3)");\r
+ }\r
+}\r
+\r
+// Retrieve the secret we use to sign lis_result_sourcedid\r
+$placementsecret = $basiclti->placementsecret;\r
+$oldplacementsecret = $basiclti->oldplacementsecret;\r
+if (! isset($placementsecret)) {\r
+ do_error("Not permitted (4)");\r
+}\r
+\r
+$suffix = ':::' . $userid . ':::' . $placement;\r
+$plaintext = $placementsecret . $suffix;\r
+$hashsig = hash('sha256', $plaintext, false);\r
+if (($hashsig != $signature) && isset($oldplacementsecret) && (strlen($oldplacementsecret) > 1)) {\r
+ $plaintext = $oldplacementsecret . $suffix;\r
+ $hashsig = hash('sha256', $plaintext, false);\r
+}\r
+\r
+if ($hashsig != $signature) {\r
+ do_error("Invalid sourcedid");\r
+}\r
+\r
+// Check the OAuth Signature\r
+$oauth_secret = $typeconfig["password"];\r
+$oauth_consumer_key = $typeconfig["resourcekey"];\r
+if (! isset($oauth_secret)) {\r
+ do_error("Not permitted (5)");\r
+}\r
+if (! isset($oauth_consumer_key)) {\r
+ do_error("Not permitted (6)");\r
+}\r
+\r
+// Verify the message signature\r
+$store = new TrivialOAuthDataStore();\r
+$store->add_consumer($oauth_consumer_key, $oauth_secret);\r
+\r
+$server = new OAuthServer($store);\r
+\r
+$method = new OAuthSignatureMethod_HMAC_SHA1();\r
+$server->add_signature_method($method);\r
+$request = OAuthRequest::from_request();\r
+\r
+$basestring = $request->get_signature_base_string();\r
+try {\r
+ $server->verify_request($request);\r
+} catch (Exception $e) {\r
+ do_error($e->getMessage());\r
+}\r
+\r
+if (! $course = $DB->get_record('course', array('id'=>$basiclti->course))) {\r
+ do_error("Could not retrieve course");\r
+}\r
+\r
+// TODO: Check that user is in course\r
+\r
+if (! $cm = get_coursemodule_from_instance("basiclti", $basiclti->id, $course->id)) {\r
+ do_error("Course Module ID was incorrect");\r
+}\r
+\r
+// Lets store the grade\r
+require_once($CFG->libdir.'/gradelib.php');\r
+\r
+// Beginning of actual grade processing\r
+if ($message_type == "basicoutcome") {\r
+ $source = 'mod/basiclti';\r
+ $courseid = $course->id;\r
+ $itemtype = 'mod';\r
+ $itemmodule = 'basiclti';\r
+ $iteminstance = $basiclti->id;\r
+\r
+ if ($lti_message_type == "basic-lis-readresult") {\r
+ unset($grade);\r
+ $thegrade = grade_get_grades($courseid, $itemtype, $itemmodule, $iteminstance, $userid);\r
+ // print_r($thegrade->items[0]->grades);\r
+ if (isset($thegrade) && is_array($thegrade->items[0]->grades)) {\r
+ foreach ($thegrade->items[0]->grades as $agrade) {\r
+ $grade = $agrade->grade;\r
+ break;\r
+ }\r
+ }\r
+ if (! isset($grade)) {\r
+ do_error("Unable to read grade");\r
+ }\r
+\r
+ $result = " <result>\n" .\r
+ " <resultscore>\n" .\r
+ " <textstring>" .\r
+ htmlspecialchars($grade/100.0) .\r
+ "</textstring>\n" .\r
+ " </resultscore>\n" .\r
+ " </result>\n";\r
+ print message_response('Success', 'Status', false, "Grade read", $result);\r
+ exit();\r
+ }\r
+\r
+ if ($lti_message_type == "basic-lis-deleteresult") {\r
+ $params = array();\r
+ $params['itemname'] = $basiclti->name;\r
+\r
+ $grade = new stdClass();\r
+ $grade->userid = $userid;\r
+ $grade->rawgrade = null;\r
+\r
+ grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance, 0, $grade, array('deleted'=>1));\r
+ } else {\r
+ if (isset($_REQUEST['result_resultscore_textstring'])) {\r
+ $gradeval = floatval($_REQUEST['result_resultscore_textstring']);\r
+ if ($gradeval <= 1.0 && $gradeval >= 0.0) {\r
+ $gradeval = $gradeval * 100.0;\r
+ }\r
+ } else {\r
+ do_error('Missing Grade');\r
+ }\r
+ $params = array();\r
+ $params['itemname'] = $basiclti->name;\r
+\r
+ $grade = new stdClass();\r
+ $grade->userid = $userid;\r
+ $grade->rawgrade = $gradeval;\r
+\r
+ grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance, 0, $grade, $params);\r
+ }\r
+\r
+ print message_response('Success', 'Status', 'fullsuccess', 'Grade updated');\r
+\r
+} else if ($lti_message_type == "basic-lti-loadsetting") {\r
+ $xml = " <setting>\n" .\r
+ " <value>".htmlspecialchars($basiclti->setting)."</value>\n" .\r
+ " </setting>\n";\r
+ print message_response('Success', 'Status', 'fullsuccess', 'Setting retrieved', $xml);\r
+} else if ($lti_message_type == "basic-lti-savesetting") {\r
+ $setting = $_REQUEST['setting'];\r
+ if (! isset($setting)) {\r
+ do_error('Missing setting value');\r
+ }\r
+ $record = $DB->get_record('basiclti', array('id'=>$basiclti->id));\r
+ $record->setting = $setting;\r
+ $success = $DB->update_record('basiclti', $record);\r
+ if ($success) {\r
+ print message_response('Success', 'Status', 'fullsuccess', 'Setting updated');\r
+ } else {\r
+ do_error("Error updating error");\r
+ }\r
+} else if ($lti_message_type == "basic-lti-deletesetting") {\r
+ $record = $DB->get_record('basiclti', array('id'=>$basiclti->id));\r
+ $record->setting = '';\r
+ $success = $DB->update_record('basiclti', $record);\r
+ if ($success) {\r
+ print message_response('Success', 'Status', 'fullsuccess', 'Setting deleted');\r
+ } else {\r
+ do_error("Error updating error");\r
+ }\r
+} else if ($message_type == "roster") {\r
+ if (! $course = $DB->get_record('course', array('id'=>$basiclti->course))) {\r
+ do_error("Could not retrieve course");\r
+ }\r
+ if (! $context = get_context_instance(CONTEXT_COURSE, $course->id)) {\r
+ do_error("Could not retrieve context");\r
+ }\r
+ $sql = 'SELECT u.id, u.username, u.firstname, u.lastname, u.email, ro.shortname\r
+ FROM '.$CFG->prefix.'role_assignments ra\r
+ JOIN '.$CFG->prefix.'user AS u ON ra.userid = u.id\r
+ JOIN '.$CFG->prefix.'role ro ON ra.roleid = ro.id\r
+ WHERE ra.contextid = '.$context->id;\r
+ $userlist = $DB->get_recordset_sql($sql);\r
+ $xml = " <memberships>\n";\r
+ foreach ($userlist as $user) {\r
+ $role = "Learner";\r
+ if ($user->shortname == 'editingteacher' || $user->shortname == 'admin') {\r
+ $role = 'Instructor';\r
+ }\r
+ $userxml = " <member>\n".\r
+ " <user_id>".htmlspecialchars($user->id)."</user_id>\n".\r
+ " <roles>$role</roles>\n";\r
+ if ($typeconfig["sendname"] == 1 ||\r
+ ($typeconfig["sendname"] == 2 && $basiclti->instructorchoicesendname == 1)) {\r
+ if (isset($user->firstname)) {\r
+ $userxml .= " <person_name_given>".htmlspecialchars($user->firstname)."</person_name_given>\n";\r
+ }\r
+ if (isset($user->lastname)) {\r
+ $userxml .= " <person_name_family>".htmlspecialchars($user->lastname)."</person_name_family>\n";\r
+ }\r
+ }\r
+ if ($typeconfig["sendemailaddr"] == 1 ||\r
+ ($typeconfig["sendemailaddr"] == 2 && $basiclti->instructorchoicesendemailaddr == 1)) {\r
+ if (isset($user->email)) {\r
+ $userxml .= " <person_contact_email_primary>".htmlspecialchars($user->email)."</person_contact_email_primary>\n";\r
+ }\r
+ }\r
+ $placementsecret = $basiclti->placementsecret;\r
+ if (isset($placementsecret)) {\r
+ $suffix = ':::' . $user->id . ':::' . $basiclti->id;\r
+ $plaintext = $placementsecret . $suffix;\r
+ $hashsig = hash('sha256', $plaintext, false);\r
+ $sourcedid = $hashsig . $suffix;\r
+ }\r
+ if ($typeconfig["acceptgrades"] == 1 ||\r
+ ($typeconfig["acceptgrades"] == 2 && $basiclti->instructorchoiceacceptgrades == 1)) {\r
+ if (isset($sourcedid)) {\r
+ $userxml .= " <lis_result_sourcedid>".htmlspecialchars($sourcedid)."</lis_result_sourcedid>\n";\r
+ }\r
+ }\r
+ $userxml .= " </member>\n";\r
+ $xml .= $userxml;\r
+ }\r
+ $xml .= " </memberships>\n";\r
+ print message_response('Success', 'Status', 'fullsuccess', 'Roster retreived', $xml);\r
+\r
+}\r
+\r
--- /dev/null
+<?php\r
+// This file is part of BasicLTI4Moodle\r
+//\r
+// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)\r
+// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web\r
+// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI\r
+// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS\r
+// are already supporting or going to support BasicLTI. This project Implements the consumer\r
+// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.\r
+// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem\r
+// at the GESSI research group at UPC.\r
+// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI\r
+// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a\r
+// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.\r
+//\r
+// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis\r
+// of the Universitat Politecnica de Catalunya http://www.upc.edu\r
+// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu\r
+//\r
+// Moodle is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License, or\r
+// (at your option) any later version.\r
+//\r
+// Moodle is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\r
+\r
+/**\r
+ * This file defines the global basiclti administration form\r
+ *\r
+ * @package basiclti\r
+ * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis\r
+ * marc.alier@upc.edu\r
+ * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu\r
+ *\r
+ * @author Marc Alier\r
+ * @author Jordi Piguillem\r
+ * @author Nikolas Galanis\r
+ *\r
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r
+ */\r
+\r
+defined('MOODLE_INTERNAL') || die;\r
+\r
+if ($ADMIN->fulltree) {\r
+ require_once($CFG->dirroot.'/mod/basiclti/locallib.php');\r
+\r
+ $str = '';\r
+\r
+ $types = basiclti_filter_get_types();\r
+ if (!empty($types)) {\r
+ $str .= '<h4 class="main"><a href="'.$CFG->wwwroot.'/mod/basiclti/typessettings.php?action=add&sesskey='.$USER->sesskey.'">'.get_string('addtype', 'basiclti').'</a></h4>';\r
+ $str .= '<table>';\r
+\r
+ foreach ($types as $type) {\r
+ $str .= '<tr>'.\r
+ '<td>'.$type->name.'</td>'.\r
+ '<td align="center"><a class="editing_update" href="'.$CFG->wwwroot.'/mod/basiclti/typessettings.php?action=update&id='.$type->id.'&sesskey='.$USER->sesskey.'" title="Update">'.\r
+ '<img class="iconsmall" alt="Update" src="'.$CFG->wwwroot.'/pix/t/edit.gif"/></a>'.' '.\r
+ '<a class="editing_delete" href="'.$CFG->wwwroot.'/mod/basiclti/typessettings.php?action=delete&id='.$type->id.'&sesskey='.$USER->sesskey.'" title="Delete">'.\r
+ '<img class="iconsmall" alt="Delete" src="'.$CFG->wwwroot.'/pix/t/delete.gif"/>'.\r
+ '</a>'.\r
+ '</td>'.\r
+ '</tr>';\r
+\r
+ }\r
+ $str .= '</table>';\r
+ } else {\r
+ $str .= '<center>';\r
+ $str .= '<h4 class="main"><a href="'.$CFG->wwwroot.'/mod/basiclti/typessettings.php?action=add&sesskey='.$USER->sesskey.'">'.get_string('addtype', 'basiclti').'</a></h4>';\r
+ $str .= get_string('notypes', 'basiclti');\r
+ $str .= '</center>';\r
+ }\r
+\r
+\r
+ $settings->add(new admin_setting_heading('basiclti_types', get_string('configuredtools', 'basiclti'), $str));\r
+\r
+ $unconfigured = basiclti_get_unconfigured_tools();\r
+ if (!empty($unconfigured)) {\r
+ $newstr = '<table>';\r
+ $newstr .= '<tr> <th>Course</th> <th>Tool Name</th> </tr>';\r
+\r
+ foreach ($unconfigured as $unconf) {\r
+ $coursename = $DB->get_field('course', 'shortname', array('id' => $unconf->course));\r
+ $newstr .= '<tr>'.\r
+ '<td>'.$coursename.'</td><td>'.$unconf->name.'</td>'.\r
+ '<td align="center"><a class="editing_update" href="'.$CFG->wwwroot.'/mod/basiclti/typessettings.php?action=fix&id='.$unconf->id.'&sesskey='.$USER->sesskey.'" title="Fix">'.\r
+ '<img class="iconsmall" alt="Update" src="'.$CFG->wwwroot.'/pix/t/edit.gif"/></a>'.' '.'</td>'.\r
+ '</tr>';\r
+ }\r
+ $newstr .= '</table>';\r
+\r
+ $settings->add(new admin_setting_heading('basiclti_mis_types', get_string('misconfiguredtools', 'basiclti'), $newstr));\r
+ }\r
+}\r
--- /dev/null
+<?php
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * 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);
+ }
+
+}
--- /dev/null
+.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;}
--- /dev/null
+<?php
+// 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 <http://www.gnu.org/licenses/>.
+
+
+/**
+ * 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
--- /dev/null
+<?php\r
+// This file is part of BasicLTI4Moodle\r
+//\r
+// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)\r
+// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web\r
+// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI\r
+// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS\r
+// are already supporting or going to support BasicLTI. This project Implements the consumer\r
+// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.\r
+// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem\r
+// at the GESSI research group at UPC.\r
+// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI\r
+// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a\r
+// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.\r
+//\r
+// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis\r
+// of the Universitat Politecnica de Catalunya http://www.upc.edu\r
+// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu\r
+//\r
+// Moodle is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License, or\r
+// (at your option) any later version.\r
+//\r
+// Moodle is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\r
+\r
+/**\r
+ * This file contains the script used to clone Moodle admin setting page.\r
+ * It is used to create a new form used to pre-configure basiclti\r
+ * activities\r
+ *\r
+ * @package basiclti\r
+ * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis\r
+ * marc.alier@upc.edu\r
+ * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu\r
+ *\r
+ * @author Marc Alier\r
+ * @author Jordi Piguillem\r
+ * @author Nikolas Galanis\r
+ *\r
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r
+ */\r
+\r
+require_once('../../config.php');\r
+require_once($CFG->libdir.'/adminlib.php');\r
+require_once($CFG->dirroot.'/mod/basiclti/edit_form.php');\r
+require_once($CFG->dirroot.'/mod/basiclti/locallib.php');\r
+\r
+$section = 'modsettingbasiclti';\r
+$return = optional_param('return', '', PARAM_ALPHA);\r
+$adminediting = optional_param('adminedit', -1, PARAM_BOOL);\r
+$action = optional_param('action', null, PARAM_TEXT);\r
+$id = optional_param('id', null, PARAM_INT);\r
+$useexisting = optional_param('useexisting', null, PARAM_INT);\r
+$definenew = optional_param('definenew', null, PARAM_INT);\r
+\r
+/// no guest autologin\r
+require_login(0, false);\r
+$url = new moodle_url('/mod/basiclti/typesettings.php');\r
+$PAGE->set_url($url);\r
+\r
+admin_externalpage_setup('managemodules'); // Hacky solution for printing the admin page\r
+\r
+/// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------\r
+\r
+$statusmsg = '';\r
+$errormsg = '';\r
+$focus = '';\r
+\r
+if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton)) {\r
+ if (isset($id)) {\r
+ $type = new StdClass();\r
+ $type->id = $id;\r
+ $type->name = $data->lti_typename;\r
+ $type->rawname = preg_replace('/[^a-zA-Z]/', '', $type->name);\r
+ if ($DB->update_record('basiclti_types', $type)) {\r
+ unset ($data->lti_typename);\r
+ //@TODO: update work\r
+ foreach ($data as $key => $value) {\r
+ if (substr($key, 0, 4)=='lti_' && !is_null($value)) {\r
+ $record = new StdClass();\r
+ $record->typeid = $id;\r
+ $record->name = substr($key, 4);\r
+ $record->value = $value;\r
+ if (basiclti_update_config($record)) {\r
+ $statusmsg = get_string('changessaved');\r
+ } else {\r
+ $errormsg = get_string('errorwithsettings', 'admin');\r
+ }\r
+ }\r
+ }\r
+\r
+ // Update toolurl for all existing instances - it is the only common parameter\r
+ // between configurations and instances\r
+ $instances = $DB->get_records('basiclti', array('typeid' => $id));\r
+ foreach ($instances as $instance) {\r
+ if ($instance->toolurl != $data->lti_toolurl) {\r
+ $instance->toolurl = $data->lti_toolurl;\r
+ $DB->update_record('basiclti', $instance);\r
+ }\r
+ }\r
+ }\r
+ redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingbasiclti");\r
+ die;\r
+ } else {\r
+ $type = new StdClass();\r
+ $type->name = $data->lti_typename;\r
+ $type->rawname = preg_replace('/[^a-zA-Z]/', '', $type->name);\r
+ if ($id = $DB->insert_record('basiclti_types', $type)) {\r
+ if (!empty($data->lti_fix)) {\r
+ $instance = $DB->get_record('basiclti', array('id' => $data->lti_fix));\r
+ $instance->typeid = $id;\r
+ $DB->update_record('basiclti', $instance);\r
+ }\r
+ unset ($data->lti_fix);\r
+\r
+ unset ($data->lti_typename);\r
+ foreach ($data as $key => $value) {\r
+ if (substr($key, 0, 4)=='lti_' && !is_null($value)) {\r
+ $record = new StdClass();\r
+ $record->typeid = $id;\r
+ $record->name = substr($key, 4);\r
+ $record->value = $value;\r
+ if (basiclti_add_config($record)) {\r
+ $statusmsg = get_string('changessaved');\r
+ } else {\r
+ $errormsg = get_string('errorwithsettings', 'admin');\r
+ }\r
+ }\r
+ }\r
+ } else {\r
+ $errormsg = get_string('errorwithsettings', 'admin');\r
+ }\r
+ redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingbasiclti");\r
+ die;\r
+ }\r
+ if (empty($adminroot->errors)) {\r
+ switch ($return) {\r
+ case 'site': redirect("$CFG->wwwroot/");\r
+ case 'admin': redirect("$CFG->wwwroot/$CFG->admin/");\r
+ }\r
+ } else {\r
+ $errormsg = get_string('errorwithsettings', 'admin');\r
+ $firsterror = reset($adminroot->errors);\r
+ $focus = $firsterror->id;\r
+ }\r
+ $adminroot =& admin_get_root(true); //reload tree\r
+ $page =& $adminroot->locate($section);\r
+}\r
+\r
+if ($action == 'delete') {\r
+ basiclti_delete_type($id);\r
+ redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingbasiclti");\r
+ die;\r
+}\r
+\r
+if (($action == 'fix') && isset($useexisting)) {\r
+ $instance = $DB->get_record('basiclti', array('id' => $id));\r
+ $instance->typeid = $useexisting;\r
+ $DB->update_record('basiclti', $instance);\r
+ redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingbasiclti");\r
+ die;\r
+}\r
+\r
+/// print header stuff ------------------------------------------------------------\r
+$PAGE->set_focuscontrol($focus);\r
+if (empty($SITE->fullname)) {\r
+ $PAGE->set_title($settingspage->visiblename);\r
+ $PAGE->set_heading($settingspage->visiblename);\r
+\r
+ $PAGE->navbar->add('Basic LTI Administration', $CFG->wwwroot.'/admin/settings.php?section=modsettingbasiclti');\r
+\r
+ echo $OUTPUT->header();\r
+\r
+ echo $OUTPUT->box(get_string('configintrosite', 'admin'));\r
+\r
+ if ($errormsg !== '') {\r
+ echo $OUTPUT->notification($errormsg);\r
+\r
+ } else if ($statusmsg !== '') {\r
+ echo $OUTPUT->notification($statusmsg, 'notifysuccess');\r
+ }\r
+\r
+ // ---------------------------------------------------------------------------------------------------------------\r
+\r
+ echo '<form action="typesettings.php" method="post" id="'.$id.'" >';\r
+ echo '<div class="settingsform clearfix">';\r
+ echo html_writer::input_hidden_params($PAGE->url);\r
+ echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';\r
+ echo '<input type="hidden" name="return" value="'.$return.'" />';\r
+\r
+ echo $settingspage->output_html();\r
+\r
+ echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges', 'admin').'" /></div>';\r
+\r
+ echo '</div>';\r
+ echo '</form>';\r
+\r
+} else {\r
+ if ($PAGE->user_allowed_editing()) {\r
+ $url = clone($PAGE->url);\r
+ if ($PAGE->user_is_editing()) {\r
+ $caption = get_string('blockseditoff');\r
+ $url->param('adminedit', 'off');\r
+ } else {\r
+ $caption = get_string('blocksediton');\r
+ $url->param('adminedit', 'on');\r
+ }\r
+ $buttons = $OUTPUT->single_button($url, $caption, 'get');\r
+ }\r
+\r
+ $PAGE->set_title("$SITE->shortname: " . get_string('toolsetup', 'basiclti'));\r
+\r
+ $PAGE->navbar->add('Basic LTI Administration', $CFG->wwwroot.'/admin/settings.php?section=modsettingbasiclti');\r
+\r
+ echo $OUTPUT->header();\r
+\r
+\r
+\r
+ if ($errormsg !== '') {\r
+ echo $OUTPUT->notification($errormsg);\r
+\r
+ } else if ($statusmsg !== '') {\r
+ echo $OUTPUT->notification($statusmsg, 'notifysuccess');\r
+ }\r
+\r
+ // ---------------------------------------------------------------------------------------------------------------\r
+ echo $OUTPUT->heading(get_string('toolsetup', 'basiclti'));\r
+ echo $OUTPUT->box_start('generalbox');\r
+ if ($action == 'add') {\r
+ $form = new mod_basiclti_edit_types_form();\r
+ $form->display();\r
+ } else if ($action == 'update') {\r
+ $form = new mod_basiclti_edit_types_form('typessettings.php?id='.$id);\r
+ $type = basiclti_get_type_type_config($id);\r
+ $form->set_data($type);\r
+ $form->display();\r
+ } else if ($action == 'fix') {\r
+ if (!isset($definenew) && !isset($useexisting)) {\r
+ basiclti_fix_misconfigured_choice($id);\r
+ } else if (isset($definenew)) {\r
+ $form = new mod_basiclti_edit_types_form();\r
+ $type = basiclti_get_type_config_from_instance($id);\r
+ $form->set_data($type);\r
+ $form->display();\r
+ }\r
+ }\r
+\r
+ echo $OUTPUT->box_end();\r
+}\r
+\r
+echo $OUTPUT->footer();\r
--- /dev/null
+<?php\r
+// This file is part of BasicLTI4Moodle\r
+//\r
+// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)\r
+// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web\r
+// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI\r
+// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS\r
+// are already supporting or going to support BasicLTI. This project Implements the consumer\r
+// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.\r
+// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem\r
+// at the GESSI research group at UPC.\r
+// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI\r
+// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a\r
+// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.\r
+//\r
+// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis\r
+// of the Universitat Politecnica de Catalunya http://www.upc.edu\r
+// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu\r
+//\r
+// Moodle is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License, or\r
+// (at your option) any later version.\r
+//\r
+// Moodle is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\r
+\r
+/**\r
+ * This file defines the version of basiclti\r
+ * This fragment is called by moodle_needs_upgrading() and /admin/index.php\r
+ *\r
+ * @package basiclti\r
+ * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis\r
+ * marc.alier@upc.edu\r
+ * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu\r
+ *\r
+ * @author Marc Alier\r
+ * @author Jordi Piguillem\r
+ * @author Nikolas Galanis\r
+ *\r
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r
+ */\r
+\r
+$module->version = 2011072000; // The current module version (Date: YYYYMMDDXX)\r
+$module->cron = 0; // Period for cron to check this module (secs)\r
--- /dev/null
+<?php\r
+// This file is part of BasicLTI4Moodle\r
+//\r
+// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)\r
+// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web\r
+// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI\r
+// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS\r
+// are already supporting or going to support BasicLTI. This project Implements the consumer\r
+// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.\r
+// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem\r
+// at the GESSI research group at UPC.\r
+// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI\r
+// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a\r
+// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.\r
+//\r
+// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis\r
+// of the Universitat Politecnica de Catalunya http://www.upc.edu\r
+// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu\r
+//\r
+// Moodle is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License, or\r
+// (at your option) any later version.\r
+//\r
+// Moodle is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\r
+\r
+/**\r
+ * This file contains all necessary code to view a basiclti activity instance\r
+ *\r
+ * @package basiclti\r
+ * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis\r
+ * marc.alier@upc.edu\r
+ * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu\r
+ *\r
+ * @author Marc Alier\r
+ * @author Jordi Piguillem\r
+ * @author Nikolas Galanis\r
+ *\r
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r
+ */\r
+\r
+require_once('../../config.php');\r
+require_once($CFG->dirroot.'/mod/basiclti/lib.php');\r
+require_once($CFG->dirroot.'/mod/basiclti/locallib.php');\r
+\r
+$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or\r
+$a = optional_param('a', 0, PARAM_INT); // basiclti ID\r
+\r
+if ($id) {\r
+ if (! $cm = get_coursemodule_from_id("basiclti", $id)) {\r
+ throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect');\r
+ }\r
+\r
+ if (! $course = $DB->get_record("course", array("id" => $cm->course))) {\r
+ throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured');\r
+ }\r
+\r
+ if (! $basiclti = $DB->get_record("basiclti", array("id" => $cm->instance))) {\r
+ throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect');\r
+ }\r
+\r
+} else {\r
+ if (! $basiclti = $DB->get_record("basiclti", array("id" => $a))) {\r
+ throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect');\r
+ }\r
+ if (! $course = $DB->get_record("course", array("id" => $basiclti->course))) {\r
+ throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured');\r
+ }\r
+ if (! $cm = get_coursemodule_from_instance("basiclti", $basiclti->id, $course->id)) {\r
+ throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect');\r
+ }\r
+}\r
+\r
+$PAGE->set_cm($cm, $course); // set's up global $COURSE\r
+$context = get_context_instance(CONTEXT_MODULE, $cm->id);\r
+$PAGE->set_context($context);\r
+\r
+$url = new moodle_url('/mod/basiclti/view.php', array('id'=>$cm->id));\r
+$PAGE->set_url($url);\r
+$PAGE->set_pagelayout('incourse');\r
+require_login($course);\r
+\r
+add_to_log($course->id, "basiclti", "view", "view.php?id=$cm->id", "$basiclti->id");\r
+\r
+$pagetitle = strip_tags($course->shortname.': '.format_string($basiclti->name));\r
+$PAGE->set_title($pagetitle);\r
+$PAGE->set_heading($course->fullname);\r
+\r
+/// Print the page header\r
+echo $OUTPUT->header();\r
+\r
+/// Print the main part of the page\r
+echo $OUTPUT->heading(format_string($basiclti->name));\r
+echo $OUTPUT->box($basiclti->intro, 'generalbox description', 'intro');\r
+\r
+if ($basiclti->typeid == 0) {\r
+ print_error('errormisconfig', 'basiclti');\r
+}\r
+\r
+if ($basiclti->instructorchoiceacceptgrades == 1) {\r
+ echo '<div class="reportlink">'.submittedlink($cm).'</div>';\r
+}\r
+\r
+echo $OUTPUT->box_start('generalbox activity');\r
+\r
+\r
+if ( $basiclti->launchinpopup > 0 ) {\r
+ print "<script language=\"javascript\">//<![CDATA[\n";\r
+ print "window.open('launch.php?id=".$cm->id."','window name');";\r
+ print "//]]\n";\r
+ print "</script>\n";\r
+ print "<p>".get_string("basiclti_in_new_window", "basiclti")."</p>\n";\r
+} else {\r
+ // Request the launch content with an object tag\r
+ $height = $basiclti->preferheight;\r
+ if ((!$height) || ($height == 0)) {\r
+ $height = 400;\r
+ }\r
+ print '<object height="'.$height.'" width="100%" data="launch.php?id='.$cm->id.'&withobject=true"></object>';\r
+\r
+}\r
+\r
+echo $OUTPUT->box_end();\r
+\r
+/// Finish the page\r
+echo $OUTPUT->footer();\r