Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding basiclti plugin

  • Loading branch information...
commit b7e436b0373ea6fb377c4d4b7003d38586fb1847 1 parent 735de1c
@scriby scriby authored
Showing with 5,874 additions and 0 deletions.
  1. +839 −0 mod/basiclti/OAuth.php
  2. 0  mod/basiclti/TODO.txt
  3. +105 −0 mod/basiclti/TrivialStore.php
  4. +91 −0 mod/basiclti/backup/moodle2/backup_basiclti_activity_task.class.php
  5. +87 −0 mod/basiclti/backup/moodle2/backup_basiclti_stepslib.php
  6. +131 −0 mod/basiclti/backup/moodle2/restore_basiclti_activity_task.class.php
  7. +101 −0 mod/basiclti/backup/moodle2/restore_basiclti_stepslib.php
  8. +56 −0 mod/basiclti/basiclti.js
  9. +71 −0 mod/basiclti/db/access.php
  10. +81 −0 mod/basiclti/db/install.xml
  11. 0  mod/basiclti/db/log.php
  12. +241 −0 mod/basiclti/db/upgrade.php
  13. +227 −0 mod/basiclti/edit_form.php
  14. +121 −0 mod/basiclti/index.php
  15. +162 −0 mod/basiclti/lang/en/basiclti.php
  16. +1 −0  mod/basiclti/lang/en/help/basiclti/index.html
  17. +1 −0  mod/basiclti/lang/en/help/basiclti/mods.html
  18. +85 −0 mod/basiclti/launch.php
  19. +1,010 −0 mod/basiclti/lib.php
  20. +85 −0 mod/basiclti/localadminlib.php
  21. +757 −0 mod/basiclti/locallib.php
  22. +481 −0 mod/basiclti/mod_form.php
  23. BIN  mod/basiclti/pix/icon.gif
  24. +391 −0 mod/basiclti/service.php
  25. +100 −0 mod/basiclti/settings.php
  26. +89 −0 mod/basiclti/simpletest/testlocallib.php
  27. +29 −0 mod/basiclti/styles.css
  28. +92 −0 mod/basiclti/submissions.php
  29. +258 −0 mod/basiclti/typessettings.php
  30. +50 −0 mod/basiclti/version.php
  31. +132 −0 mod/basiclti/view.php
View
839 mod/basiclti/OAuth.php
@@ -0,0 +1,839 @@
+<?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);
+ }
+}
View
0  mod/basiclti/TODO.txt
No changes.
View
105 mod/basiclti/TrivialStore.php
@@ -0,0 +1,105 @@
+<?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;
+ }
+}
View
91 mod/basiclti/backup/moodle2/backup_basiclti_activity_task.class.php
@@ -0,0 +1,91 @@
+<?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;
+ }
+}
View
87 mod/basiclti/backup/moodle2/backup_basiclti_stepslib.php
@@ -0,0 +1,87 @@
+<?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);
+ }
+}
View
131 mod/basiclti/backup/moodle2/restore_basiclti_activity_task.class.php
@@ -0,0 +1,131 @@
+<?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;
+ }
+}
View
101 mod/basiclti/backup/moodle2/restore_basiclti_stepslib.php
@@ -0,0 +1,101 @@
+<?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);
+ }
+}
View
56 mod/basiclti/basiclti.js
@@ -0,0 +1,56 @@
+// This file is part of BasicLTI4Moodle
+//
+// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)
+// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web
+// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI
+// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS
+// are already supporting or going to support BasicLTI. This project Implements the consumer
+// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.
+// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem
+// at the GESSI research group at UPC.
+// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI
+// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a
+// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.
+//
+// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis
+// of the Universitat Politecnica de Catalunya http://www.upc.edu
+// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <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';
+ }
+}
View
71 mod/basiclti/db/access.php
@@ -0,0 +1,71 @@
+<?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
+ )
+ ),
+);
View
81 mod/basiclti/db/install.xml
@@ -0,0 +1,81 @@
+<?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>
View
0  mod/basiclti/db/log.php
No changes.
View
241 mod/basiclti/db/upgrade.php
@@ -0,0 +1,241 @@
+<?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 keeps track of upgrades to the basiclti module
+ *
+ * @package basiclti
+ * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
+ * marc.alier@upc.edu
+ * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
+ *
+ * @author Marc Alier
+ * @author Jordi Piguillem
+ * @author Nikolas Galanis
+ *
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+
+/**
+ * xmldb_basiclti_upgrade is the function that upgrades Moodle's
+ * database when is needed
+ *
+ * This function is automaticly called when version number in
+ * version.php changes.
+ *
+ * @param int $oldversion New old version number.
+ *
+ * @return boolean
+ */
+
+function xmldb_basiclti_upgrade($oldversion=0) {
+
+ global $DB;
+
+ $dbman = $DB->get_manager();
+ $result = true;
+
+ if ($result && $oldversion < 2008090201) {
+
+ $table = new xmldb_table('basiclti_types');
+ $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);
+ $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null);
+
+ $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
+
+ upgrade_mod_savepoint($result, 2008090201, 'basiclti_types');
+
+ $table = new xmldb_table('basiclti_types_config');
+ $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);
+ $table->add_field('typeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null);
+ $table->add_field('name', XMLDB_TYPE_CHAR, '100', XMLDB_NOTNULL, null, null, null, null);
+ $table->add_field('value', XMLDB_TYPE_CHAR, '255', XMLDB_NOTNULL, null, null, null, null);
+
+ $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
+
+ upgrade_mod_savepoint($result, 2008090201, 'basiclti_types_config');
+
+ $table = new xmldb_table('basiclti');
+ $field = new xmldb_field('typeid');
+
+ if (!$dbman->field_exists($table, $field)) {
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null);
+ $dbman->add_field($table, $field);
+ }
+ upgrade_mod_savepoint($result, 2008090201, 'basiclti');
+ }
+
+ if ($result && $oldversion < 2008091201) {
+ $table = new xmldb_table('basiclti_types');
+ $field = new xmldb_field('rawname');
+
+ if (!$dbman->field_exists($table, $field)) {
+ $field->set_attributes(XMLDB_TYPE_CHAR, '100', null, null, null, null, null);
+ $dbman->add_field($table, $field);
+ }
+
+ upgrade_mod_savepoint($result, 2008091202, 'basiclti_types');
+ }
+
+ if ($result && $oldversion < 2011011200) {
+ $table = new xmldb_table('basiclti');
+
+ $field = new xmldb_field('acceptgrades');
+ if (!$dbman->field_exists($table, $field)) {
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
+ $result = $result && $dbman->add_field($table, $field);
+ }
+ $field = new xmldb_field('instructorchoiceacceptgrades');
+ if (!$dbman->field_exists($table, $field)) {
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
+ $result = $result && $dbman->add_field($table, $field);
+ }
+ $field = new xmldb_field('allowroster');
+ if (!$dbman->field_exists($table, $field)) {
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
+ $result = $result && $dbman->add_field($table, $field);
+ }
+ $field = new xmldb_field('instructorchoiceallowroster');
+ if (!$dbman->field_exists($table, $field)) {
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
+ $result = $result && $dbman->add_field($table, $field);
+ }
+ $field = new xmldb_field('allowsetting');
+ if (!$dbman->field_exists($table, $field)) {
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
+ $result = $result && $dbman->add_field($table, $field);
+ }
+ $field = new xmldb_field('instructorchoiceallowsetting');
+ if (!$dbman->field_exists($table, $field)) {
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
+ $result = $result && $dbman->add_field($table, $field);
+ }
+ $field = new xmldb_field('setting');
+ if (!$dbman->field_exists($table, $field)) {
+ $field->set_attributes(XMLDB_TYPE_CHAR, '8192', null, null, null, '', null);
+ $result = $result && $dbman->add_field($table, $field);
+ }
+
+ $field = new xmldb_field('placementsecret');
+ if (!$dbman->field_exists($table, $field)) {
+ $field->set_attributes(XMLDB_TYPE_CHAR, '1024', null, null, null, '', null);
+ $result = $result && $dbman->add_field($table, $field);
+ }
+
+ $field = new xmldb_field('timeplacementsecret');
+ if (!$dbman->field_exists($table, $field)) {
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
+ $result = $result && $dbman->add_field($table, $field);
+ }
+
+ $field = new xmldb_field('oldplacementsecret');
+ if (!$dbman->field_exists($table, $field)) {
+ $field->set_attributes(XMLDB_TYPE_CHAR, '1024', null, null, null, '', null);
+ $result = $result && $dbman->add_field($table, $field);
+ }
+
+ upgrade_mod_savepoint(true, 2011011200, 'basiclti');
+ }
+
+ if ($result && $oldversion < 2011011304) {
+ $table = new xmldb_table('basiclti');
+ $field = new xmldb_field('grade');
+ if (!$dbman->field_exists($table, $field)) {
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '100', null);
+ $result = $result && $dbman->add_field($table, $field);
+ }
+
+ upgrade_mod_savepoint(true, 2011011304, 'basiclti');
+ }
+
+ if ($result && $oldversion < 2011052600) {
+ $table = new xmldb_table('basiclti');
+
+ $field = new xmldb_field('resourcekey');
+ if ($dbman->field_exists($table, $field)) {
+ $dbman->drop_field($table, $field);
+ }
+
+ $field = new xmldb_field('password');
+ if ($dbman->field_exists($table, $field)) {
+ $dbman->drop_field($table, $field);
+ }
+
+ $field = new xmldb_field('sendname');
+ if ($dbman->field_exists($table, $field)) {
+ $dbman->drop_field($table, $field);
+ }
+
+ $field = new xmldb_field('sendemailaddr');
+ if ($dbman->field_exists($table, $field)) {
+ $dbman->drop_field($table, $field);
+ }
+
+ $field = new xmldb_field('allowroster');
+ if ($dbman->field_exists($table, $field)) {
+ $dbman->drop_field($table, $field);
+ }
+
+ $field = new xmldb_field('allowsetting');
+ if ($dbman->field_exists($table, $field)) {
+ $dbman->drop_field($table, $field);
+ }
+
+ $field = new xmldb_field('acceptgrades');
+ if ($dbman->field_exists($table, $field)) {
+ $dbman->drop_field($table, $field);
+ }
+
+ $field = new xmldb_field('customparameters');
+ if ($dbman->field_exists($table, $field)) {
+ $dbman->drop_field($table, $field);
+ }
+
+ upgrade_mod_savepoint(true, 2011052600, 'basiclti');
+ }
+
+ if($result && $oldversion < 2011070100) {
+ $table = new xmldb_table('basiclti');
+
+ $field = new xmldb_field('instructorcustomparameters');
+ if (!$dbman->field_exists($table, $field)) {
+ $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, null, null, '', null);
+ $result = $result && $dbman->add_field($table, $field);
+ }
+
+ upgrade_mod_savepoint(true, 2011070100, 'basiclti');
+ }
+
+ return $result;
+}
+
View
227 mod/basiclti/edit_form.php
@@ -0,0 +1,227 @@
+<?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 defines de main basiclti configuration form
+ *
+ * @package basiclti
+ * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
+ * marc.alier@upc.edu
+ * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
+ *
+ * @author Marc Alier
+ * @author Jordi Piguillem
+ * @author Nikolas Galanis
+ * @author Charles Severance
+ *
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+require_once($CFG->libdir.'/formslib.php');
+
+class mod_basiclti_edit_types_form extends moodleform{
+
+ function definition() {
+ $mform =& $this->_form;
+
+//-------------------------------------------------------------------------------
+ // Add basiclti elements
+ $mform->addElement('header', 'setup', get_string('modstandardels', 'form'));
+
+ $mform->addElement('text', 'lti_typename', get_string('typename', 'basiclti'));
+ $mform->setType('lti_typename', PARAM_INT);
+// $mform->addHelpButton('lti_typename', 'typename','basiclti');
+ $mform->addRule('lti_typename', null, 'required', null, 'client');
+
+ $regex = '/^(http|https):\/\/([a-z0-9-]\.+)*/i';
+
+ $mform->addElement('text', 'lti_toolurl', get_string('toolurl', 'basiclti'), array('size'=>'64'));
+ $mform->setType('lti_toolurl', PARAM_TEXT);
+// $mform->addHelpButton('lti_toolurl', 'toolurl', 'basiclti');
+ $mform->addRule('lti_toolurl', get_string('validurl', 'basiclti'), 'regex', $regex, 'client');
+ $mform->addRule('lti_toolurl', null, 'required', null, 'client');
+
+ $mform->addElement('text', 'lti_resourcekey', get_string('resourcekey', 'basiclti'));
+ $mform->setType('lti_resourcekey', PARAM_TEXT);
+
+ $mform->addElement('passwordunmask', 'lti_password', get_string('password', 'basiclti'));
+ $mform->setType('lti_password', PARAM_TEXT);
+
+//-------------------------------------------------------------------------------
+ // Add size parameters
+ $mform->addElement('header', 'size', get_string('size', 'basiclti'));
+
+ $mform->addElement('text', 'lti_preferheight', get_string('preferheight', 'basiclti'));
+ $mform->setType('lti_preferheight', PARAM_INT);
+// $mform->addHelpButton('lti_preferheight', 'preferheight', 'basiclti');
+
+
+//-------------------------------------------------------------------------------
+ // Add privacy preferences fieldset where users choose whether to send their data
+ $mform->addElement('header', 'privacy', get_string('privacy', 'basiclti'));
+
+ $options=array();
+ $options[0] = get_string('never', 'basiclti');
+ $options[1] = get_string('always', 'basiclti');
+ $options[2] = get_string('delegate', 'basiclti');
+
+ $defaults=array();
+ $defaults[0] = get_string('donot', 'basiclti');
+ $defaults[1] = get_string('send', 'basiclti');
+
+ $mform->addElement('select', 'lti_sendname', get_string('sendname', 'basiclti'), $options);
+ $mform->setDefault('lti_sendname', '0');
+// $mform->addHelpButton('lti_sendname', 'sendname', 'basiclti');
+
+ $mform->addElement('select', 'lti_instructorchoicesendname', get_string('setdefault', 'basiclti'), $defaults);
+ $mform->setDefault('lti_instructorchoicesendname', '0');
+ $mform->disabledIf('lti_instructorchoicesendname', 'lti_sendname', 'neq', 2);
+
+ $mform->addElement('select', 'lti_sendemailaddr', get_string('sendemailaddr', 'basiclti'), $options);
+ $mform->setDefault('lti_sendemailaddr', '0');
+// $mform->addHelpButton('lti_sendemailaddr', 'sendemailaddr', 'basiclti');
+
+ $mform->addElement('select', 'lti_instructorchoicesendemailaddr', get_string('setdefault', 'basiclti'), $defaults);
+ $mform->setDefault('lti_instructorchoicesendemailaddr', '0');
+ $mform->disabledIf('lti_instructorchoicesendemailaddr', 'lti_sendemailaddr', 'neq', 2);
+
+//-------------------------------------------------------------------------------
+ // BLTI Extensions
+ $mform->addElement('header', 'extensions', get_string('extensions', 'basiclti'));
+
+ $defaults_accept=array();
+ $defaults_accept[0] = get_string('donotaccept', 'basiclti');
+ $defaults_accept[1] = get_string('accept', 'basiclti');
+
+ $defaults_allow=array();
+ $defaults_allow[0] = get_string('donotallow', 'basiclti');
+ $defaults_allow[1] = get_string('allow', 'basiclti');
+
+ // Add grading preferences fieldset where the tool is allowed to return grades
+ $mform->addElement('select', 'lti_acceptgrades', get_string('acceptgrades', 'basiclti'), $options);
+ $mform->setDefault('lti_acceptgrades', '0');
+// $mform->addHelpButton('lti_acceptgrades', 'acceptgrades', 'basiclti');
+
+ $mform->addElement('select', 'lti_instructorchoiceacceptgrades', get_string('setdefault', 'basiclti'), $defaults_accept);
+ $mform->setDefault('lti_instructorchoiceacceptgrades', '0');
+ $mform->disabledIf('lti_instructorchoiceacceptgrades', 'lti_acceptgrades', 'neq', 2);
+
+ // Add grading preferences fieldset where the tool is allowed to retrieve rosters
+ $mform->addElement('select', 'lti_allowroster', get_string('allowroster', 'basiclti'), $options);
+ $mform->setDefault('lti_allowroster', '0');
+// $mform->addHelpButton('lti_allowroster', 'allowroster', 'basiclti');
+
+ $mform->addElement('select', 'lti_instructorchoiceallowroster', get_string('setdefault', 'basiclti'), $defaults_allow);
+ $mform->setDefault('lti_instructorchoiceallowroster', '0');
+ $mform->disabledIf('lti_instructorchoiceallowroster', 'lti_allowroster', 'neq', 2);
+
+ // Add grading preferences fieldset where the tool is allowed to update settings
+ $mform->addElement('select', 'lti_allowsetting', get_string('allowsetting', 'basiclti'), $options);
+ $mform->setDefault('lti_allowsetting', '0');
+// $mform->addHelpButton('lti_allowsetting', 'allowsetting', 'basiclti');
+
+ $mform->addElement('select', 'lti_instructorchoiceallowsetting', get_string('setdefault', 'basiclti'), $defaults_allow);
+ $mform->setDefault('lti_instructorchoiceallowsetting', '0');
+ $mform->disabledIf('lti_instructorchoiceallowsetting', 'lti_allowsetting', 'neq', 2);
+
+//-------------------------------------------------------------------------------
+ // Add custom parameters fieldset
+ $mform->addElement('header', 'custom', get_string('custom', 'basiclti'));
+
+ $mform->addElement('textarea', 'lti_customparameters', '', array('rows'=>15, 'cols'=>60));
+ $mform->setType('lti_customparameters', PARAM_TEXT);
+
+ $mform->addElement('select', 'lti_allowinstructorcustom', get_string('allowinstructorcustom', 'basiclti'), $defaults_allow);
+ $mform->setDefault('lti_allowinstructorcustom', '0');
+
+//-------------------------------------------------------------------------------
+ // Add setup parameters fieldset
+ $mform->addElement('header', 'setupoptions', get_string('setupoptions', 'basiclti'));
+
+ // Adding option to change id that is placed in context_id
+ $idoptions = array();
+ $idoptions[0] = get_string('id', 'basiclti');
+ $idoptions[1] = get_string('courseid', 'basiclti');
+
+ $mform->addElement('select', 'lti_moodle_course_field', get_string('moodle_course_field', 'basiclti'), $idoptions);
+ $mform->setDefault('lti_moodle_course_field', '0');
+
+ // Added option to allow user to specify if this is a resource or activity type
+ $classoptions = array();
+ $classoptions[0] = get_string('activity', 'basiclti');
+ $classoptions[1] = get_string('resource', 'basiclti');
+
+ $mform->addElement('select', 'lti_module_class_type', get_string('module_class_type', 'basiclti'), $classoptions);
+ $mform->setDefault('lti_module_class_type', '0');
+
+//-------------------------------------------------------------------------------
+ // Add organization parameters fieldset
+ $mform->addElement('header', 'organization', get_string('organization', 'basiclti'));
+
+ $mform->addElement('text', 'lti_organizationid', get_string('organizationid', 'basiclti'));
+ $mform->setType('lti_organizationid', PARAM_TEXT);
+// $mform->addHelpButton('lti_organizationid', 'organizationid', 'basiclti');
+
+ $mform->addElement('text', 'lti_organizationurl', get_string('organizationurl', 'basiclti'));
+ $mform->setType('lti_organizationurl', PARAM_TEXT);
+// $mform->addHelpButton('lti_organizationurl', 'organizationurl', 'basiclti');
+
+ /* Suppress this for now - Chuck
+ $mform->addElement('text', 'lti_organizationdescr', get_string('organizationdescr', 'basiclti'));
+ $mform->setType('lti_organizationdescr', PARAM_TEXT);
+ $mform->addHelpButton('lti_organizationdescr', 'organizationdescr', 'basiclti');
+ */
+
+//-------------------------------------------------------------------------------
+ // Add launch parameters fieldset
+ $mform->addElement('header', 'launchoptions', get_string('launchoptions', 'basiclti'));
+
+ $launchoptions=array();
+ $launchoptions[0] = get_string('launch_in_moodle', 'basiclti');
+ $launchoptions[1] = get_string('launch_in_popup', 'basiclti');
+
+