Adding basiclti plugin

This commit is contained in:
Chris Scribner
2011-11-06 20:41:44 -05:00
parent 735de1c276
commit b7e436b037
31 changed files with 5874 additions and 0 deletions
+839
View File
@@ -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 File
+105
View File
@@ -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 [email protected]
*
* @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;
}
}
@@ -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
* [email protected]
* @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;
}
}
@@ -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
* [email protected]
* @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);
}
}
@@ -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
* [email protected]
* @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;
}
}
@@ -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
* [email protected]
* @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);
}
}
+56
View File
@@ -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
* [email protected]
* @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';
}
}
+71
View File
@@ -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
* [email protected]
* @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
)
),
);
+81
View File
@@ -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 File
+241
View File
@@ -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
* [email protected]
* @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;
}
+227
View File
@@ -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
* [email protected]
* @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
*
* @author Marc Alier
* @author Jordi Piguillem
* @author Nikolas Galanis
* @author Charles Severance
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once($CFG->libdir.'/formslib.php');
class mod_basiclti_edit_types_form extends moodleform{
function definition() {
$mform =& $this->_form;
//-------------------------------------------------------------------------------
// Add basiclti elements
$mform->addElement('header', 'setup', get_string('modstandardels', 'form'));
$mform->addElement('text', 'lti_typename', get_string('typename', 'basiclti'));
$mform->setType('lti_typename', PARAM_INT);
// $mform->addHelpButton('lti_typename', 'typename','basiclti');
$mform->addRule('lti_typename', null, 'required', null, 'client');
$regex = '/^(http|https):\/\/([a-z0-9-]\.+)*/i';
$mform->addElement('text', 'lti_toolurl', get_string('toolurl', 'basiclti'), array('size'=>'64'));
$mform->setType('lti_toolurl', PARAM_TEXT);
// $mform->addHelpButton('lti_toolurl', 'toolurl', 'basiclti');
$mform->addRule('lti_toolurl', get_string('validurl', 'basiclti'), 'regex', $regex, 'client');
$mform->addRule('lti_toolurl', null, 'required', null, 'client');
$mform->addElement('text', 'lti_resourcekey', get_string('resourcekey', 'basiclti'));
$mform->setType('lti_resourcekey', PARAM_TEXT);
$mform->addElement('passwordunmask', 'lti_password', get_string('password', 'basiclti'));
$mform->setType('lti_password', PARAM_TEXT);
//-------------------------------------------------------------------------------
// Add size parameters
$mform->addElement('header', 'size', get_string('size', 'basiclti'));
$mform->addElement('text', 'lti_preferheight', get_string('preferheight', 'basiclti'));
$mform->setType('lti_preferheight', PARAM_INT);
// $mform->addHelpButton('lti_preferheight', 'preferheight', 'basiclti');
//-------------------------------------------------------------------------------
// Add privacy preferences fieldset where users choose whether to send their data
$mform->addElement('header', 'privacy', get_string('privacy', 'basiclti'));
$options=array();
$options[0] = get_string('never', 'basiclti');
$options[1] = get_string('always', 'basiclti');
$options[2] = get_string('delegate', 'basiclti');
$defaults=array();
$defaults[0] = get_string('donot', 'basiclti');
$defaults[1] = get_string('send', 'basiclti');
$mform->addElement('select', 'lti_sendname', get_string('sendname', 'basiclti'), $options);
$mform->setDefault('lti_sendname', '0');
// $mform->addHelpButton('lti_sendname', 'sendname', 'basiclti');
$mform->addElement('select', 'lti_instructorchoicesendname', get_string('setdefault', 'basiclti'), $defaults);
$mform->setDefault('lti_instructorchoicesendname', '0');
$mform->disabledIf('lti_instructorchoicesendname', 'lti_sendname', 'neq', 2);
$mform->addElement('select', 'lti_sendemailaddr', get_string('sendemailaddr', 'basiclti'), $options);
$mform->setDefault('lti_sendemailaddr', '0');
// $mform->addHelpButton('lti_sendemailaddr', 'sendemailaddr', 'basiclti');
$mform->addElement('select', 'lti_instructorchoicesendemailaddr', get_string('setdefault', 'basiclti'), $defaults);
$mform->setDefault('lti_instructorchoicesendemailaddr', '0');
$mform->disabledIf('lti_instructorchoicesendemailaddr', 'lti_sendemailaddr', 'neq', 2);
//-------------------------------------------------------------------------------
// BLTI Extensions
$mform->addElement('header', 'extensions', get_string('extensions', 'basiclti'));
$defaults_accept=array();
$defaults_accept[0] = get_string('donotaccept', 'basiclti');
$defaults_accept[1] = get_string('accept', 'basiclti');
$defaults_allow=array();
$defaults_allow[0] = get_string('donotallow', 'basiclti');
$defaults_allow[1] = get_string('allow', 'basiclti');
// Add grading preferences fieldset where the tool is allowed to return grades
$mform->addElement('select', 'lti_acceptgrades', get_string('acceptgrades', 'basiclti'), $options);
$mform->setDefault('lti_acceptgrades', '0');
// $mform->addHelpButton('lti_acceptgrades', 'acceptgrades', 'basiclti');
$mform->addElement('select', 'lti_instructorchoiceacceptgrades', get_string('setdefault', 'basiclti'), $defaults_accept);
$mform->setDefault('lti_instructorchoiceacceptgrades', '0');
$mform->disabledIf('lti_instructorchoiceacceptgrades', 'lti_acceptgrades', 'neq', 2);
// Add grading preferences fieldset where the tool is allowed to retrieve rosters
$mform->addElement('select', 'lti_allowroster', get_string('allowroster', 'basiclti'), $options);
$mform->setDefault('lti_allowroster', '0');
// $mform->addHelpButton('lti_allowroster', 'allowroster', 'basiclti');
$mform->addElement('select', 'lti_instructorchoiceallowroster', get_string('setdefault', 'basiclti'), $defaults_allow);
$mform->setDefault('lti_instructorchoiceallowroster', '0');
$mform->disabledIf('lti_instructorchoiceallowroster', 'lti_allowroster', 'neq', 2);
// Add grading preferences fieldset where the tool is allowed to update settings
$mform->addElement('select', 'lti_allowsetting', get_string('allowsetting', 'basiclti'), $options);
$mform->setDefault('lti_allowsetting', '0');
// $mform->addHelpButton('lti_allowsetting', 'allowsetting', 'basiclti');
$mform->addElement('select', 'lti_instructorchoiceallowsetting', get_string('setdefault', 'basiclti'), $defaults_allow);
$mform->setDefault('lti_instructorchoiceallowsetting', '0');
$mform->disabledIf('lti_instructorchoiceallowsetting', 'lti_allowsetting', 'neq', 2);
//-------------------------------------------------------------------------------
// Add custom parameters fieldset
$mform->addElement('header', 'custom', get_string('custom', 'basiclti'));
$mform->addElement('textarea', 'lti_customparameters', '', array('rows'=>15, 'cols'=>60));
$mform->setType('lti_customparameters', PARAM_TEXT);
$mform->addElement('select', 'lti_allowinstructorcustom', get_string('allowinstructorcustom', 'basiclti'), $defaults_allow);
$mform->setDefault('lti_allowinstructorcustom', '0');
//-------------------------------------------------------------------------------
// Add setup parameters fieldset
$mform->addElement('header', 'setupoptions', get_string('setupoptions', 'basiclti'));
// Adding option to change id that is placed in context_id
$idoptions = array();
$idoptions[0] = get_string('id', 'basiclti');
$idoptions[1] = get_string('courseid', 'basiclti');
$mform->addElement('select', 'lti_moodle_course_field', get_string('moodle_course_field', 'basiclti'), $idoptions);
$mform->setDefault('lti_moodle_course_field', '0');
// Added option to allow user to specify if this is a resource or activity type
$classoptions = array();
$classoptions[0] = get_string('activity', 'basiclti');
$classoptions[1] = get_string('resource', 'basiclti');
$mform->addElement('select', 'lti_module_class_type', get_string('module_class_type', 'basiclti'), $classoptions);
$mform->setDefault('lti_module_class_type', '0');
//-------------------------------------------------------------------------------
// Add organization parameters fieldset
$mform->addElement('header', 'organization', get_string('organization', 'basiclti'));
$mform->addElement('text', 'lti_organizationid', get_string('organizationid', 'basiclti'));
$mform->setType('lti_organizationid', PARAM_TEXT);
// $mform->addHelpButton('lti_organizationid', 'organizationid', 'basiclti');
$mform->addElement('text', 'lti_organizationurl', get_string('organizationurl', 'basiclti'));
$mform->setType('lti_organizationurl', PARAM_TEXT);
// $mform->addHelpButton('lti_organizationurl', 'organizationurl', 'basiclti');
/* Suppress this for now - Chuck
$mform->addElement('text', 'lti_organizationdescr', get_string('organizationdescr', 'basiclti'));
$mform->setType('lti_organizationdescr', PARAM_TEXT);
$mform->addHelpButton('lti_organizationdescr', 'organizationdescr', 'basiclti');
*/
//-------------------------------------------------------------------------------
// Add launch parameters fieldset
$mform->addElement('header', 'launchoptions', get_string('launchoptions', 'basiclti'));
$launchoptions=array();
$launchoptions[0] = get_string('launch_in_moodle', 'basiclti');
$launchoptions[1] = get_string('launch_in_popup', 'basiclti');
$mform->addElement('select', 'lti_launchinpopup', get_string('launchinpopup', 'basiclti'), $launchoptions);
$mform->setDefault('lti_launchinpopup', '0');
// $mform->addHelpButton('lti_launchinpopup', 'launchinpopup', 'basiclti');
//-------------------------------------------------------------------------------
// Add a hidden element to signal a tool fixing operation after a problematic backup - restore process
$mform->addElement('hidden', 'lti_fix');
//-------------------------------------------------------------------------------
// Add standard buttons, common to all modules
$this->add_action_buttons();
}
}
+121
View File
@@ -0,0 +1,121 @@
<?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 page lists all the instances of basiclti in a particular course
*
* @package basiclti
* @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
* [email protected]
* @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
*
* @author Marc Alier
* @author Jordi Piguillem
* @author Nikolas Galanis
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
require_once($CFG->dirroot.'/mod/basiclti/lib.php');
$id = required_param('id', PARAM_INT); // course id
if (! $course = $DB->get_record("course", array("id" => $id))) {
throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course ID is incorrect');
}
$url = new moodle_url('/mod/basiclti/index.php', array('id'=>$id));
$PAGE->set_url($url);
$PAGE->set_pagelayout('incourse');
require_login($course);
add_to_log($course->id, "basiclti", "view all", "index.php?id=$course->id", "");
$pagetitle = strip_tags($course->shortname.': '.get_string("modulenamepluralformatted", "basiclti"));
$PAGE->set_title($pagetitle);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
/// Print the main part of the page
echo $OUTPUT->heading(get_string("modulenamepluralformatted", "basiclti"));
/// Get all the appropriate data
if (! $basicltis = get_all_instances_in_course("basiclti", $course)) {
notice("There are no basicltis", "../../course/view.php?id=$course->id");
die;
}
/// Print the list of instances (your module will probably extend this)
$timenow = time();
$strname = get_string("name");
$strsectionname = get_string('sectionname', 'format_'.$course->format);
$usesections = course_format_uses_sections($course->format);
if ($usesections) {
$sections = get_all_sections($course->id);
}
$table = new html_table();
$table->attributes['class'] = 'generaltable mod_index';
if ($usesections) {
$table->head = array ($strsectionname, $strname);
$table->align = array ("center", "left");
} else {
$table->head = array ($strname);
}
foreach ($basicltis as $basiclti) {
if (!$basiclti->visible) {
//Show dimmed if the mod is hidden
$link = "<a class=\"dimmed\" href=\"view.php?id=$basiclti->coursemodule\">$basiclti->name</a>";
} else {
//Show normal if the mod is visible
$link = "<a href=\"view.php?id=$basiclti->coursemodule\">$basiclti->name</a>";
}
if ($course->format == "weeks" or $course->format == "topics") {
$table->data[] = array ($basiclti->section, $link);
} else {
$table->data[] = array ($link);
}
}
echo "<br />";
echo html_writer::table($table);
/// Finish the page
echo $OUTPUT->footer();
+162
View File
@@ -0,0 +1,162 @@
<?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 en_utf8 translation of the Basic LTI module
*
* @package basiclti
* @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
* [email protected]
* @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
*
* @author Marc Alier
* @author Jordi Piguillem
* @author Nikolas Galanis
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['accept'] = 'Accept';
$string['acceptgrades'] = 'Accept grades from tool';
$string['activity'] = 'Activity';
$string['addnewapp'] = 'Enable External Application';
$string['addserver'] = 'Add new trusted server';
$string['addtype'] = 'Create a new Basic LTI activity';
$string['allow'] = 'Allow';
$string['allowinstructorcustom'] = 'Allow instructors to add custom parameters';
$string['allowroster'] = 'Allow tool access to course roster';
$string['allowsetting'] = 'Allow tool to store 8K of settings in Moodle';
$string['always'] = 'Always';
$string['basiclti'] = 'Basic LTI';
$string['basiclti_base_string'] = 'Basic LTI OAuth Base String';
$string['basiclti_in_new_window'] = 'Your activity has opened in a new window';
$string['basiclti_endpoint'] = 'Basic LTI Launch Endpoint';
$string['basiclti_parameters'] = 'Basic LTI Launch Parameters';
$string['basicltiactivities'] = 'Basic LTI Activities';
$string['basicltifieldset'] = 'Custom example fieldset';
$string['basicltiintro'] = 'Activity Description';
$string['basicltiname'] = 'Activity Name';
$string['basicltisettings'] = 'Basic Learning Tool Interoperability Settings';
$string['comment'] = 'Comment';
$string['configpassword'] = 'Default Remote Tool Password';
$string['configpreferheight'] = 'Default preferred height';
$string['configpreferwidget'] = 'Set widget as default launch';
$string['configpreferwidth'] = 'Default preferred width';
$string['configresourceurl'] = 'Default Resource URL';
$string['configtoolurl'] = 'Default Remote Tool URL';
$string['configtypes'] = 'Enable Basic LTI Applications';
$string['configuredtools'] = 'Configured Basic LTI activities';
$string['courseid'] = 'Course id number';
$string['coursemisconf'] = 'Course is misconfigured';
$string['curllibrarymissing'] = 'PHP Curl library must be installed to use LTI';
$string['custom'] = 'Custom parameters';
$string['custominstr'] = 'Custom parameters';
$string['debuglaunch'] = 'Debug Option';
$string['debuglaunchoff'] = 'Normal launch';
$string['debuglaunchon'] = 'Debug launch';
$string['delegate'] = 'Delegate to Professor';
$string['donot'] = 'Do not send';
$string['donotaccept'] = 'Do not accept';
$string['donotallow'] = 'Do not allow';
$string['enableemailnotification'] = 'Send notification emails';
$string['enableemailnotification_help'] = 'If enabled, students will receive email notification when their tool submissions are graded.';
$string['errormisconfig'] = 'Misconfigured tool. Please ask your Moodle administrator to fix the configuration of the tool.';
$string['extensions'] = 'Basic LTI Extension Services';
$string['failedtoconnect'] = 'Moodle was unable to communicate with the \"$a\" system';
$string['filterconfig'] = 'Basic LTI administration';
$string['filtername'] = 'Basic LTI';
$string['filter_basiclti_configlink'] = 'Configure your preferred sites and their passwords';
$string['filter_basiclti_password'] = 'Password is mandatory';
$string['fixexistingconf'] = 'Use an existing configuration for the misconfigured instance';
$string['fixnew'] = 'New Configuration';
$string['fixnewconf'] = 'Define a new configuration for the misconfigured instance';
$string['fixold'] = 'Use Existing';
$string['grading'] = 'Grade Routing';
$string['id'] = 'id';
$string['imsroleadmin'] = 'Instructor,Administrator';
$string['imsroleinstructor'] = 'Instructor';
$string['imsrolelearner'] = 'Learner';
$string['invalidid'] = 'basic LTI ID was incorrect';
$string['launch_in_moodle'] = 'Launch tool in moodle';
$string['launch_in_popup'] = 'Launch tool in a pop-up';
$string['launchinpopup'] = 'Popup Option';
$string['launchoptions'] = 'Launch Options';
$string['lti_errormsg'] = 'The tool returned the following error message: \"$a\"';
$string['misconfiguredtools'] = 'Misconfigured tool instances were detected';
$string['missingparameterserror'] = 'The page is misconfigured: \"$a\"';
$string['module_class_type'] = 'Moodle module type';
$string['modulename'] = 'Basic LTI';
$string['modulenameplural'] = 'basicltis';
$string['modulenamepluralformatted'] = 'Basic LTI Instances';
$string['moodle_course_field'] = 'Course identification field';
$string['never'] = 'Never';
$string['noattempts'] = 'No attempts have been made on this tool instance';
$string['noservers'] = 'No servers found';
$string['notypes'] = 'There are currently no LTI tools setup in Moodle. Click the Install link above to add some.';
$string['noviewusers'] = 'No users were found with permissions to use this tool';
$string['optionalsettings'] = 'Optional settings';
$string['organization'] ='Organization details';
$string['organizationdescr'] ='Organization Description';
$string['organizationid'] ='Organization ID';
$string['organizationurl'] ='Organization URL';
$string['pagesize'] = 'Submissions shown per page';
$string['password'] = 'Remote Tool Password';
$string['pluginadministration'] = 'Basic LTI administration';
$string['pluginname'] = 'BasicLTI';
$string['preferheight'] = 'Preferred Height';
$string['preferwidget'] = 'Prefer Widget Launch';
$string['preferwidth'] = 'Preferred Width';
$string['press_to_submit'] = 'Press to launch this activity';
$string['privacy'] = 'Privacy';
$string['quickgrade'] = 'Allow quick grading';
$string['quickgrade_help'] = 'If enabled, multiple tools can be graded on one page. Add grades and comments then click the "Save all my feedback" button to save all changes for that page.';
$string['redirect'] = 'You will be redirected in few seconds. If you are not, press the button.';
$string['resource'] = 'Resource';
$string['resourcekey'] = 'Resource Key';
$string['resourceurl'] = 'Resource URL';
$string['saveallfeedback'] = 'Save all my feedback';
$string['send'] = 'Send';
$string['sendemailaddr'] = 'Send user email address to the external tool';
$string['sendname'] = 'Send user name and surname to the external tool';
$string['setdefault'] = 'Set a default value for the professor if delegating';
$string['setupbox'] = 'Basic LTI Tool Setup Box';
$string['setupoptions'] = 'Setup Options';
$string['size'] = 'Size parameters';
$string['submission'] = 'Submission';
$string['toggle_debug_data'] = 'Toggle Debug Data';
$string['toolsetup'] = 'Basic LTI Tool Setup';
$string['toolurl'] = 'Remote Tool URL';
$string['typename'] = 'Remote Tool Name';
$string['types'] = 'Types';
$string['validurl'] = 'A valid URL must start with http(s)://';
$string['viewsubmissions'] = 'View submissions and grading screen';
@@ -0,0 +1 @@
<p>Basic LTI</p>
@@ -0,0 +1 @@
<p>Basic LTI</p>
+85
View File
@@ -0,0 +1,85 @@
<?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 necessary code to view a basiclti activity instance
*
* @package basiclti
* @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
* [email protected]
* @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
*
* @author Marc Alier
* @author Jordi Piguillem
* @author Nikolas Galanis
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
require_once($CFG->dirroot.'/mod/basiclti/lib.php');
require_once($CFG->dirroot.'/mod/basiclti/locallib.php');
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
$object = optional_param('withobject', false, PARAM_BOOL); // Launch BasicLTI in an object
if ($id) {
if (! $cm = $DB->get_record("course_modules", array("id" => $id))) {
throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect');
}
if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured');
}
if (! $basiclti = $DB->get_record("basiclti", array("id" => $cm->instance))) {
throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect');
}
} else {
if (! $basiclti = $DB->get_record("basiclti", array("id" => $a))) {
throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect');
}
if (! $course = $DB->get_record("course", array("id" => $basiclti->course))) {
throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured');
}
if (! $cm = get_coursemodule_from_instance("basiclti", $basiclti->id, $course->id)) {
throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect');
}
}
require_login($course);
add_to_log($course->id, "basiclti", "launch", "launch.php?id=$cm->id", "$basiclti->id");
basiclti_view($basiclti, $object);
+1010
View File
File diff suppressed because it is too large Load Diff
+85
View File
@@ -0,0 +1,85 @@
<?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 some functions and classes used in Basic LTI
* module administration
*
* @package basiclti
* @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
* [email protected]
* @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
*
* @author Marc Alier
* @author Jordi Piguillem
* @author Nikolas Galanis
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once($CFG->libdir.'/adminlib.php');
/**
*
* @TODO: finish doc this class and it's functions
*/
class admin_setting_basicltimodule_configlink extends admin_setting {
/**
* Constructor
* @param string $name of setting
* @param string $visiblename localised
* @param string $description long localised info
*/
function admin_setting_basicltimodule_configlink($name, $visiblename, $description) {
parent::__construct($name, $visiblename, $description, '');
}
function get_setting() {
return true;
}
function write_setting($data) {
return "";
}
function output_html($data, $query='') {
global $CFG;
return format_admin_setting($this, "",
'<div class="defaultsnext" >'.
'<a href="'.$CFG->wwwroot.'/mod/basiclti/typessettings.php">'.get_string('filterconfig', 'basiclti').'</a>'.
'</div>',
$this->description, true, '', null, $query);
}
}
+757
View File
@@ -0,0 +1,757 @@
<?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 library of functions and constants for the basiclti module
*
* @package basiclti
* @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
* [email protected]
* @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
*
* @author Marc Alier
* @author Jordi Piguillem
* @author Nikolas Galanis
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot.'/mod/basiclti/OAuth.php');
/**
* Prints a Basic LTI activity
*
* $param int $basicltiid Basic LTI activity id
*/
function basiclti_view($instance, $makeobject=false) {
global $PAGE;
$typeconfig = basiclti_get_type_config($instance->typeid);
$endpoint = $typeconfig['toolurl'];
$key = $typeconfig['resourcekey'];
$secret = $typeconfig['password'];
$orgid = $typeconfig['organizationid'];
/* Suppress this for now - Chuck
$orgdesc = $typeconfig['organizationdescr'];
*/
$course = $PAGE->course;
$requestparams = basiclti_build_request($instance, $typeconfig, $course);
// Make sure we let the tool know what LMS they are being called from
$requestparams["ext_lms"] = "moodle-2";
// Add oauth_callback to be compliant with the 1.0A spec
$requestparams["oauth_callback"] = "about:blank";
$submittext = get_string('press_to_submit', 'basiclti');
$parms = sign_parameters($requestparams, $endpoint, "POST", $key, $secret, $submittext, $orgid /*, $orgdesc*/);
$debuglaunch = ( $instance->debuglaunch == 1 );
if ( $makeobject ) {
// TODO: Need frame height
$height = $instance->preferheight;
if ((!$height) || ($height == 0)) {
$height = 400;
}
$content = post_launch_html($parms, $endpoint, $debuglaunch, $height);
} else {
$content = post_launch_html($parms, $endpoint, $debuglaunch, false);
}
// $cm = get_coursemodule_from_instance("basiclti", $instance->id);
// print '<object height='.$height.' width="80%" data="launch.php?id='.$cm->id.'">'.$content.'</object>';
print $content;
}
/**
* This function builds the request that must be sent to the tool producer
*
* @param object $instance Basic LTI instance object
* @param object $typeconfig Basic LTI tool configuration
* @param object $course Course object
*
* @return array $request Request details
*/
function basiclti_build_request($instance, $typeconfig, $course) {
global $USER, $CFG;
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$role = basiclti_get_ims_role($USER, $context);
$locale = $course->lang;
if ( strlen($locale) < 1 ) {
$locale = $CFG->lang;
}
$requestparams = array(
"resource_link_id" => $instance->id,
"resource_link_title" => $instance->name,
"resource_link_description" => $instance->intro,
"user_id" => $USER->id,
"roles" => $role,
"context_id" => $course->id,
"context_label" => $course->shortname,
"context_title" => $course->fullname,
"launch_presentation_locale" => $locale,
);
$placementsecret = $instance->placementsecret;
if ( isset($placementsecret) ) {
$suffix = ':::' . $USER->id . ':::' . $instance->id;
$plaintext = $placementsecret . $suffix;
$hashsig = hash('sha256', $plaintext, false);
$sourcedid = $hashsig . $suffix;
}
if ( isset($placementsecret) &&
( $typeconfig['acceptgrades'] == 1 ||
( $typeconfig['acceptgrades'] == 2 && $instance->instructorchoiceacceptgrades == 1 ) ) ) {
$requestparams["lis_result_sourcedid"] = $sourcedid;
$requestparams["ext_ims_lis_basic_outcome_url"] = $CFG->wwwroot.'/mod/basiclti/service.php';
}
if ( isset($placementsecret) &&
( $typeconfig['allowroster'] == 1 ||
( $typeconfig['allowroster'] == 2 && $instance->instructorchoiceallowroster == 1 ) ) ) {
$requestparams["ext_ims_lis_memberships_id"] = $sourcedid;
$requestparams["ext_ims_lis_memberships_url"] = $CFG->wwwroot.'/mod/basiclti/service.php';
}
if ( isset($placementsecret) &&
( $typeconfig['allowsetting'] == 1 ||
( $typeconfig['allowsetting'] == 2 && $instance->instructorchoiceallowsetting == 1 ) ) ) {
$requestparams["ext_ims_lti_tool_setting_id"] = $sourcedid;
$requestparams["ext_ims_lti_tool_setting_url"] = $CFG->wwwroot.'/mod/basiclti/service.php';
$setting = $instance->setting;
if ( isset($setting) ) {
$requestparams["ext_ims_lti_tool_setting"] = $setting;
}
}
// Send user's name and email data if appropriate
if ( $typeconfig['sendname'] == 1 ||
( $typeconfig['sendname'] == 2 && $instance->instructorchoicesendname == 1 ) ) {
$requestparams["lis_person_name_given"] = $USER->firstname;
$requestparams["lis_person_name_family"] = $USER->lastname;
$requestparams["lis_person_name_full"] = $USER->firstname." ".$USER->lastname;
}
if ( $typeconfig['sendemailaddr'] == 1 ||
( $typeconfig['sendemailaddr'] == 2 && $instance->instructorchoicesendemailaddr == 1 ) ) {
$requestparams["lis_person_contact_email_primary"] = $USER->email;
}
// Concatenate the custom parameters from the administrator and the instructor
// Instructor parameters are only taken into consideration if the administrator
// has giver permission
$customstr = $typeconfig['customparameters'];
$instructorcustomstr = $instance->instructorcustomparameters;
$custom = array();
$instructorcustom = array();
if ($customstr) {
$custom = split_custom_parameters($customstr);
}
if (!isset($typeconfig['allowinstructorcustom']) || $typeconfig['allowinstructorcustom'] == 0) {
$requestparams = array_merge($custom, $requestparams);
} else {
if ($instructorcustomstr) {
$instructorcustom = split_custom_parameters($instructorcustomstr);
}
foreach ($instructorcustom as $key => $val) {
if (array_key_exists($key, $custom)) {
// Ignore the instructor's parameter
} else {
$custom[$key] = $val;
}
}
$requestparams = array_merge($custom, $requestparams);
}
return $requestparams;
}
/**
* Splits the custom parameters field to the various parameters
*
* @param string $customstr String containing the parameters
*
* @return Array of custom parameters
*/
function split_custom_parameters($customstr) {
$textlib = textlib_get_instance();
$lines = preg_split("/[\n;]/", $customstr);
$retval = array();
foreach ($lines as $line) {
$pos = strpos($line, "=");
if ( $pos === false || $pos < 1 ) {
continue;
}
$key = trim($textlib->substr($line, 0, $pos));
$val = trim($textlib->substr($line, $pos+1));
$key = map_keyname($key);
$retval['custom_'.$key] = $val;
}
return $retval;
}
/**
* Used for building the names of the different custom parameters
*
* @param string $key Parameter name
*
* @return string Processed name
*/
function map_keyname($key) {
$textlib = textlib_get_instance();
$newkey = "";
$key = $textlib->strtolower(trim($key));
foreach (str_split($key) as $ch) {
if ( ($ch >= 'a' && $ch <= 'z') || ($ch >= '0' && $ch <= '9') ) {
$newkey .= $ch;
} else {
$newkey .= '_';
}
}
return $newkey;
}
/**
* Returns the IMS user role in a given context
*
* This function queries Moodle for an user role and
* returns the correspondant IMS role
*
* @param StdClass $user Moodle user instance
* @param StdClass $context Moodle context
*
* @return string IMS Role
*
*/
function basiclti_get_ims_role($user, $context) {
$roles = get_user_roles($context, $user->id);
$rolesname = array();
foreach ($roles as $role) {
$rolesname[] = $role->shortname;
}
if (in_array('admin', $rolesname) || in_array('coursecreator', $rolesname)) {
return get_string('imsroleadmin', 'basiclti');
}
if (in_array('editingteacher', $rolesname) || in_array('teacher', $rolesname)) {
return get_string('imsroleinstructor', 'basiclti');
}
return get_string('imsrolelearner', 'basiclti');
}
/**
* Returns configuration details for the tool
*
* @param int $typeid Basic LTI tool typeid
*
* @return array Tool Configuration
*/
function basiclti_get_type_config($typeid) {
global $DB;
$typeconfig = array();
$configs = $DB->get_records('basiclti_types_config', array('typeid' => $typeid));
if (!empty($configs)) {
foreach ($configs as $config) {
$typeconfig[$config->name] = $config->value;
}
}
return $typeconfig;
}
/**
* Returns all tool instances with a typeid of 0 that
* marks them as unconfigured. These tools usually proceed from a
* backup - restore process.
*
*/
function basiclti_get_unconfigured_tools() {
global $DB;
return $DB->get_records('basiclti', array('typeid' => 0));
}
/**
* Returns all basicLTI tools configured by the administrator
*
*/
function basiclti_filter_get_types() {
global $DB;
return $DB->get_records('basiclti_types');
}
/**
* Prints the various configured tool types
*
*/
function basiclti_filter_print_types() {
global $CFG;
$types = basiclti_filter_get_types();
if (!empty($types)) {
echo '<ul>';
foreach ($types as $type) {
echo '<li>'.
$type->name.
'<span class="commands">'.
'<a class="editing_update" href="typessettings.php?action=update&amp;id='.$type->id.'&amp;sesskey='.sesskey().'" title="Update">'.
'<img class="iconsmall" alt="Update" src="'.$CFG->wwwroot.'/pix/t/edit.gif"/>'.
'</a>'.
'<a class="editing_delete" href="typessettings.php?action=delete&amp;id='.$type->id.'&amp;sesskey='.sesskey().'" title="Delete">'.
'<img class="iconsmall" alt="Delete" src="'.$CFG->wwwroot.'/pix/t/delete.gif"/>'.
'</a>'.
'</span>'.
'</li>';
}
echo '</ul>';
} else {
echo '<div class="message">';
echo get_string('notypes', 'basiclti');
echo '</div>';
}
}
/**
* Delete a Basic LTI configuration
*
* @param int $id Configuration id
*/
function basiclti_delete_type($id) {
global $DB;
$instances = $DB->get_records('basiclti', array('typeid' => $id));
foreach ($instances as $instance) {
$instance->typeid = 0;
$DB->update_record('basiclti', $instance);
}
$DB->delete_records('basiclti_types', array('id' => $id));
$DB->delete_records('basiclti_types_config', array('typeid' => $id));
}
/**
* Transforms a basic LTI object to an array
*
* @param object $bltiobject Basic LTI object
*
* @return array Basic LTI configuration details
*/
function basiclti_get_config($bltiobject) {
$typeconfig = array();
$typeconfig = (array)$bltiobject;
$additionalconfig = basiclti_get_type_config($bltiobject->typeid);
$typeconfig = array_merge($typeconfig, $additionalconfig);
return $typeconfig;
}
/**
*
* Generates some of the tool configuration based on the instance details
*
* @param int $id
*
* @return Instance configuration
*
*/
function basiclti_get_type_config_from_instance($id) {
global $DB;
$instance = $DB->get_record('basiclti', array('id' => $id));
$config = basiclti_get_config($instance);
$type = new stdClass();
$type->lti_fix = $id;
if (isset($config['toolurl'])) {
$type->lti_toolurl = $config['toolurl'];
}
if (isset($config['preferheight'])) {
$type->lti_preferheight = $config['preferheight'];
}
if (isset($config['instructorchoicesendname'])) {
$type->lti_sendname = $config['instructorchoicesendname'];
}
if (isset($config['instructorchoicesendemailaddr'])) {
$type->lti_sendemailaddr = $config['instructorchoicesendemailaddr'];
}
if (isset($config['instructorchoiceacceptgrades'])) {
$type->lti_acceptgrades = $config['instructorchoiceacceptgrades'];
}
if (isset($config['instructorchoiceallowroster'])) {
$type->lti_allowroster = $config['instructorchoiceallowroster'];
}
if (isset($config['instructorchoiceallowsetting'])) {
$type->lti_allowsetting = $config['instructorchoiceallowsetting'];
}
if (isset($config['instructorcustomparameters'])) {
$type->lti_allowsetting = $config['instructorcustomparameters'];
}
return $type;
}
/**
* Generates some of the tool configuration based on the admin configuration details
*
* @param int $id
*
* @return Configuration details
*/
function basiclti_get_type_type_config($id) {
global $DB;
$basicltitype = $DB->get_record('basiclti_types', array('id' => $id));
$config = basiclti_get_type_config($id);
$type->lti_typename = $basicltitype->name;
if (isset($config['toolurl'])) {
$type->lti_toolurl = $config['toolurl'];
}
if (isset($config['resourcekey'])) {
$type->lti_resourcekey = $config['resourcekey'];
}
if (isset($config['password'])) {
$type->lti_password = $config['password'];
}
if (isset($config['preferheight'])) {
$type->lti_preferheight = $config['preferheight'];
}
if (isset($config['sendname'])) {
$type->lti_sendname = $config['sendname'];
}
if (isset($config['instructorchoicesendname'])){
$type->lti_instructorchoicesendname = $config['instructorchoicesendname'];
}
if (isset($config['sendemailaddr'])){
$type->lti_sendemailaddr = $config['sendemailaddr'];
}
if (isset($config['instructorchoicesendemailaddr'])){
$type->lti_instructorchoicesendemailaddr = $config['instructorchoicesendemailaddr'];
}
if (isset($config['acceptgrades'])){
$type->lti_acceptgrades = $config['acceptgrades'];
}
if (isset($config['instructorchoiceacceptgrades'])){
$type->lti_instructorchoiceacceptgrades = $config['instructorchoiceacceptgrades'];
}
if (isset($config['allowroster'])){
$type->lti_allowroster = $config['allowroster'];
}
if (isset($config['instructorchoiceallowroster'])){
$type->lti_instructorchoiceallowroster = $config['instructorchoiceallowroster'];
}
if (isset($config['allowsetting'])){
$type->lti_allowsetting = $config['allowsetting'];
}
if (isset($config['instructorchoiceallowsetting'])){
$type->lti_instructorchoiceallowsetting = $config['instructorchoiceallowsetting'];
}
if (isset($config['customparameters'])) {
$type->lti_customparameters = $config['customparameters'];
}
if (isset($config['allowinstructorcustom'])) {
$type->lti_allowinstructorcustom = $config['allowinstructorcustom'];
}
if (isset($config['organizationid'])) {
$type->lti_organizationid = $config['organizationid'];
}
if (isset($config['organizationurl'])) {
$type->lti_organizationurl = $config['organizationurl'];
}
if (isset($config['organizationdescr'])) {
$type->lti_organizationdescr = $config['organizationdescr'];
}
if (isset($config['launchinpopup'])) {
$type->lti_launchinpopup = $config['launchinpopup'];
}
if (isset($config['debuglaunch'])) {
$type->lti_debuglaunch = $config['debuglaunch'];
}
if (isset($config['moodle_course_field'])) {
$type->lti_moodle_course_field = $config['moodle_course_field'];
}
if (isset($config['module_class_type'])) {
$type->lti_module_class_type = $config['module_class_type'];
}
return $type;
}
/**
* Add a tool configuration in the database
*
* @param $config Tool configuration
*
* @return int Record id number
*/
function basiclti_add_config($config) {
global $DB;
return $DB->insert_record('basiclti_types_config', $config);
}
/**
* Updates a tool configuration in the database
*
* @param $config Tool configuration
*
* @return Record id number
*/
function basiclti_update_config($config) {
global $DB;
$return = true;
if ($old = $DB->get_record('basiclti_types_config', array('typeid' => $config->typeid, 'name' => $config->name))) {
$config->id = $old->id;
$return = $DB->update_record('basiclti_types_config', $config);
} else {
$return = $DB->insert_record('basiclti_types_config', $config);
}
return $return;
}
/**
* Prints the screen that handles misconfigured objects due to
* an incomplete backup - restore process
*
* @param int $id ID of the misconfigured tool
*
*/
function basiclti_fix_misconfigured_choice($id) {
global $CFG, $USER, $OUTPUT;
echo $OUTPUT->box_start('generalbox');
echo '<div>';
$types = basiclti_filter_get_types();
if (!empty($types)) {
echo '<h4 class="main">'.get_string('fixexistingconf', 'basiclti').'</h4></br>';
echo '<form action='.$CFG->wwwroot.'/mod/basiclti/typessettings.php?action=fix&amp;sesskey='.$USER->sesskey.' method="post">';
foreach ($types as $type) {
echo '<input type="radio" name="useexisting" value="'.$type->id.'" />'.$type->name.'<br />';
}
echo '<input type="hidden" name="id" value="'.$id.'"/>';
echo '<br />';
echo '<div class="message"><input type="submit" value="'.get_string('fixold', 'basiclti').'"></div>';
echo '</form>';
} else {
echo '<div class="message">';
echo get_string('notypes', 'basiclti');
echo '</div>';
}
echo '</div>';
echo $OUTPUT->box_end();
echo $OUTPUT->box_start("generalbox");
echo '<div>';
echo '<h4 class="main">'.get_string('fixnewconf', 'basiclti').'</h4></br>';
echo '<form action='.$CFG->wwwroot.'/mod/basiclti/typessettings.php?action=fix&amp;sesskey='.$USER->sesskey.' method="post">';
echo '<input type="hidden" name="id" value="'.$id.'"/>';
echo '<input type="hidden" name="definenew" value="1"/>';
echo '<div class="message"><input type="submit" value="'.get_string('fixnew', 'basiclti').'"></div>';
echo '</form>';
echo '</div>';
echo $OUTPUT->box_end();
}
/**
* Signs the petition to launch the external tool using OAuth
*
* @param $oldparms Parameters to be passed for signing
* @param $endpoint url of the external tool
* @param $method Method for sending the parameters (e.g. POST)
* @param $oauth_consumoer_key Key
* @param $oauth_consumoer_secret Secret
* @param $submittext The text for the submit button
* @param $orgid LMS name
* @param $orgdesc LMS key
*/
function sign_parameters($oldparms, $endpoint, $method, $oauthconsumerkey, $oauthconsumersecret, $submittext, $orgid /*, $orgdesc*/) {
global $lastbasestring;
$parms = $oldparms;
$parms["lti_version"] = "LTI-1p0";
$parms["lti_message_type"] = "basic-lti-launch-request";
if ( $orgid ) {
$parms["tool_consumer_instance_guid"] = $orgid;
}
/* Suppress this for now - Chuck
if ( $orgdesc ) $parms["tool_consumer_instance_description"] = $orgdesc;
*/
$parms["ext_submit"] = $submittext;
$testtoken = '';
$hmacmethod = new OAuthSignatureMethod_HMAC_SHA1();
$testconsumer = new OAuthConsumer($oauthconsumerkey, $oauthconsumersecret, null);
$accreq = OAuthRequest::from_consumer_and_token($testconsumer, $testtoken, $method, $endpoint, $parms);
$accreq->sign_request($hmacmethod, $testconsumer, $testtoken);
// Pass this back up "out of band" for debugging
$lastbasestring = $accreq->get_signature_base_string();
$newparms = $accreq->get_parameters();
return $newparms;
}
/**
* Posts the launch petition HTML
*
* @param $newparms Signed parameters
* @param $endpoint URL of the external tool
* @param $debug Debug (true/false)
*/
function post_launch_html($newparms, $endpoint, $debug=false, $height=false) {
global $lastbasestring;
if ($height) {
$r = "<form action=\"".$endpoint."\" name=\"ltiLaunchForm\" id=\"ltiLaunchForm\" method=\"post\" encType=\"application/x-www-form-urlencoded\">\n";
} else {
$r = "<form action=\"".$endpoint."\" name=\"ltiLaunchForm\" id=\"ltiLaunchForm\" method=\"post\" encType=\"application/x-www-form-urlencoded\">\n";
}
$submittext = $newparms['ext_submit'];
// Contruct html for the launch parameters
foreach ($newparms as $key => $value) {
$key = htmlspecialchars($key);
$value = htmlspecialchars($value);
if ( $key == "ext_submit" ) {
$r .= "<input type=\"submit\" name=\"";
} else {
$r .= "<input type=\"hidden\" name=\"";
}
$r .= $key;
$r .= "\" value=\"";
$r .= $value;
$r .= "\"/>\n";
}
if ( $debug ) {
$r .= "<script language=\"javascript\"> \n";
$r .= " //<![CDATA[ \n";
$r .= "function basicltiDebugToggle() {\n";
$r .= " var ele = document.getElementById(\"basicltiDebug\");\n";
$r .= " if(ele.style.display == \"block\") {\n";
$r .= " ele.style.display = \"none\";\n";
$r .= " }\n";
$r .= " else {\n";
$r .= " ele.style.display = \"block\";\n";
$r .= " }\n";
$r .= "} \n";
$r .= " //]]> \n";
$r .= "</script>\n";
$r .= "<a id=\"displayText\" href=\"javascript:basicltiDebugToggle();\">";
$r .= get_string("toggle_debug_data", "basiclti")."</a>\n";
$r .= "<div id=\"basicltiDebug\" style=\"display:none\">\n";
$r .= "<b>".get_string("basiclti_endpoint", "basiclti")."</b><br/>\n";
$r .= $endpoint . "<br/>\n&nbsp;<br/>\n";
$r .= "<b>".get_string("basiclti_parameters", "basiclti")."</b><br/>\n";
foreach ($newparms as $key => $value) {
$key = htmlspecialchars($key);
$value = htmlspecialchars($value);
$r .= "$key = $value<br/>\n";
}
$r .= "&nbsp;<br/>\n";
$r .= "<p><b>".get_string("basiclti_base_string", "basiclti")."</b><br/>\n".$lastbasestring."</p>\n";
$r .= "</div>\n";
}
$r .= "</form>\n";
if ( ! $debug ) {
$ext_submit = "ext_submit";
$ext_submit_text = $submittext;
$r .= " <script type=\"text/javascript\"> \n" .
" //<![CDATA[ \n" .
" document.getElementById(\"ltiLaunchForm\").style.display = \"none\";\n" .
" nei = document.createElement('input');\n" .
" nei.setAttribute('type', 'hidden');\n" .
" nei.setAttribute('name', '".$ext_submit."');\n" .
" nei.setAttribute('value', '".$ext_submit_text."');\n" .
" document.getElementById(\"ltiLaunchForm\").appendChild(nei);\n" .
" document.ltiLaunchForm.submit(); \n" .
" //]]> \n" .
" </script> \n";
}
return $r;
}
/**
* Returns a link with info about the state of the basiclti submissions
*
* This is used by view_header to put this link at the top right of the page.
* For teachers it gives the number of submitted assignments with a link
* For students it gives the time of their submission.
* This will be suitable for most assignment types.
*
* @global object
* @global object
* @param bool $allgroup print all groups info if user can access all groups, suitable for index.php
* @return string
*/
function submittedlink($cm, $allgroups=false) {
global $CFG;
$submitted = '';
$urlbase = "{$CFG->wwwroot}/mod/basiclti/";
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (has_capability('mod/basiclti:grade', $context)) {
if ($allgroups and has_capability('moodle/site:accessallgroups', $context)) {
$group = 0;
} else {
$group = groups_get_activity_group($cm);
}
$submitted = '<a href="'.$urlbase.'submissions.php?id='.$cm->id.'">'.
get_string('viewsubmissions', 'basiclti').'</a>';
} else {
if (isloggedin()) {
// TODO Insert code for students if needed
}
}
return $submitted;
}
+481
View File
@@ -0,0 +1,481 @@
<?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 the main basiclti configuration form
*
* @package basiclti
* @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
* [email protected]
* @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
*
* @author Marc Alier
* @author Jordi Piguillem
* @author Nikolas Galanis
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot.'/course/moodleform_mod.php');
require_once($CFG->dirroot.'/mod/basiclti/locallib.php');
class mod_basiclti_mod_form extends moodleform_mod {
function definition() {
global $DB;
$typename = optional_param('type', false, PARAM_ALPHA);
if (empty($typename)) {
//Updating instance
if (!empty($this->_instance)) {
$basiclti = $DB->get_record('basiclti', array('id' => $this->_instance));
$this->typeid = $basiclti->typeid;
$typeconfig = basiclti_get_config($basiclti);
$this->typeconfig = $typeconfig;
} else { // New not pre-configured instance
$this->typeid = 0;
}
} else {
// New pre-configured instance
$basicltitype = $DB->get_record('basiclti_types', array('rawname' => $typename));
$this->typeid = $basicltitype->id;
$typeconfig = basiclti_get_type_config($this->typeid);
$this->typeconfig = $typeconfig;
}
$mform =& $this->_form;
//-------------------------------------------------------------------------------
/// Adding the "general" fieldset, where all the common settings are shown
$mform->addElement('header', 'general', get_string('general', 'form'));
/// Adding the standard "name" field
$mform->addElement('text', 'name', get_string('basicltiname', 'basiclti'), array('size'=>'64'));
$mform->setType('name', PARAM_TEXT);
$mform->addRule('name', null, 'required', null, 'client');
/// Adding the optional "intro" and "introformat" pair of fields
$this->add_intro_editor(true, get_string('basicltiintro', 'basiclti'));
//-------------------------------------------------------------------------------
$mform->addElement('hidden', 'typeid', $this->typeid);
$mform->addElement('hidden', 'toolurl', $this->typeconfig['toolurl']);
$mform->addElement('hidden', 'type', $typename);
//-------------------------------------------------------------------------------
// Add privacy preferences fieldset where users choose whether to send their data
$mform->addElement('header', 'privacy', get_string('privacy', 'basiclti'));
$privacyoptions=array();
$privacyoptions[0] = get_string('donot', 'basiclti');
$privacyoptions[1] = get_string('send', 'basiclti');
$mform->addElement('select', 'instructorchoicesendname', get_string('sendname', 'basiclti'), $privacyoptions);
if (isset($this->typeconfig['instructorchoicesendname'])) {
if ($this->typeconfig['instructorchoicesendname'] == 0) {
$mform->setDefault('instructorchoicesendname', '0');
} else if ($this->typeconfig['instructorchoicesendname'] == 1) {
$mform->setDefault('instructorchoicesendname', '1');
}
}
// $mform->addHelpButton('instructorchoicesendname', 'sendname', 'basiclti');
$mform->addElement('select', 'instructorchoicesendemailaddr', get_string('sendemailaddr', 'basiclti'), $privacyoptions);
if (isset($this->typeconfig['instructorchoicesendemailaddr'])) {
if ($this->typeconfig['instructorchoicesendemailaddr'] == 0) {
$mform->setDefault('instructorchoicesendemailaddr', '0');
} else if ($this->typeconfig['instructorchoicesendemailaddr'] == 1) {
$mform->setDefault('instructorchoicesendemailaddr', '1');
}
}
// $mform->addHelpButton('instructorchoicesendemailaddr', 'sendemailaddr', 'basiclti');
//-------------------------------------------------------------------------------
// Add grading preferences fieldset where the instructor determines whether to accept grades
$mform->addElement('header', 'extensions', get_string('extensions', 'basiclti'));
$extensionoptions=array();
$extensionoptions[0] = get_string('donotaccept', 'basiclti');
$extensionoptions[1] = get_string('accept', 'basiclti');
$mform->addElement('select', 'instructorchoiceacceptgrades', get_string('acceptgrades', 'basiclti'), $extensionoptions);
if (isset($this->typeconfig['instructorchoiceacceptgrades'])) {
if ($this->typeconfig['instructorchoiceacceptgrades'] == 0) {
$mform->setDefault('instructorchoiceacceptgrades', '0');
} else if ($this->typeconfig['instructorchoiceacceptgrades'] == 1) {
$mform->setDefault('instructorchoiceacceptgrades', '1');
}
}
// $mform->addHelpButton('instructorchoiceacceptgrades', 'acceptgrades', 'basiclti');
$extensionoptions=array();
$extensionoptions[0] = get_string('donotallow', 'basiclti');
$extensionoptions[1] = get_string('allow', 'basiclti');
$mform->addElement('select', 'instructorchoiceallowroster', get_string('allowroster', 'basiclti'), $extensionoptions);
if (isset($this->typeconfig['instructorchoiceallowroster'])) {
if ($this->typeconfig['instructorchoiceallowroster'] == 0) {
$mform->setDefault('instructorchoiceallowroster', '0');
} else if ($this->typeconfig['instructorchoiceallowroster'] == 1) {
$mform->setDefault('instructorchoiceallowroster', '1');
}
}
// $mform->addHelpButton('instructorchoiceallowroster', 'allowroster', 'basiclti');
$mform->setAdvanced('instructorchoiceallowroster');
$mform->addElement('select', 'instructorchoiceallowsetting', get_string('allowsetting', 'basiclti'), $extensionoptions);
if (isset($this->typeconfig['instructorchoiceallowsetting'])) {
if ($this->typeconfig['instructorchoiceallowsetting'] == 0) {
$mform->setDefault('instructorchoiceallowsetting', '0');
} else if ($this->typeconfig['instructorchoiceallowsetting'] == 1) {
$mform->setDefault('instructorchoiceallowsetting', '1');
}
}
// $mform->addHelpButton('instructorchoiceallowsetting', 'allowsetting', 'basiclti');
$mform->setAdvanced('instructorchoiceallowsetting');
//-------------------------------------------------------------------------------
if (isset($this->typeconfig['allowinstructorcustom'])) {
if ($this->typeconfig['allowinstructorcustom'] == 1) {
// Add custom parameters fieldset
$mform->addElement('header', 'launchoptions', get_string('custominstr', 'basiclti'));
$mform->addElement('textarea', 'instructorcustomparameters', '', array('rows'=>15, 'cols'=>60));
$mform->setType('instructorcustomparameters', PARAM_TEXT);
$mform->setAdvanced('instructorcustomparameters');
}
}
//-------------------------------------------------------------------------------
// Add launch parameters fieldset
$mform->addElement('header', 'launchoptions', get_string('launchoptions', 'basiclti'));
// Size parameters
$mform->addElement('text', 'preferheight', get_string('preferheight', 'basiclti'));
if (isset($this->typeconfig['preferheight'])) {
$mform->setDefault('preferheight', $this->typeconfig['preferheight']);
}
$launchoptions=array();
$launchoptions[0] = get_string('launch_in_moodle', 'basiclti');
$launchoptions[1] = get_string('launch_in_popup', 'basiclti');
$mform->addElement('select', 'launchinpopup', get_string('launchinpopup', 'basiclti'), $launchoptions);
if (isset($this->typeconfig['launchinpopup'])) {
if ($this->typeconfig['launchinpopup'] == 0) {
$mform->setDefault('launchinpopup', '0');
} else if ($this->typeconfig['launchinpopup'] == 1) {
$mform->setDefault('launchinpopup', '1');
}
}
$debugoptions=array();
$debugoptions[0] = get_string('debuglaunchoff', 'basiclti');
$debugoptions[1] = get_string('debuglaunchon', 'basiclti');
$mform->addElement('select', 'debuglaunch', get_string('debuglaunch', 'basiclti'), $debugoptions);
if (isset($this->typeconfig['debuglaunch'])) {
if ($this->typeconfig['debuglaunch'] == 0) {
$mform->setDefault('debuglaunch', '0');
} else if ($this->typeconfig['debuglaunch'] == 1) {
$mform->setDefault('debuglaunch', '1');
}
}
//-------------------------------------------------------------------------------
// Organization parameters
if (isset($this->typeconfig['organizationid'])) {
$mform->addElement('hidden', 'organizationid', $this->typeconfig['organizationid']);
}
if (isset($this->typeconfig['organizationurl'])) {
$mform->addElement('hidden', 'organizationurl', $this->typeconfig['organizationurl']);
}
// $mform->addElement('hidden', 'organizationdescr', $this->typeconfig['organizationdescr']);
//-------------------------------------------------------------------------------
// add standard elements, common to all modules
$this->standard_coursemodule_elements();
//-------------------------------------------------------------------------------
// add standard buttons, common to all modules
$this->add_action_buttons();
}
/**
* Make fields editable or non-editable depending on the administrator choices
* @see moodleform_mod::definition_after_data()
*/
function definition_after_data() {
parent::definition_after_data();
$mform =& $this->_form;
$typeid =& $mform->getElement('typeid');
$typeidvalue = $mform->getElementValue('typeid');
//Depending on the selection of the administrator
//we don't want to have these appear as possible selections in the form but
//we want the form to display them if they are set.
if (!empty($typeidvalue)) {
$typeconfig = basiclti_get_type_config($typeidvalue);
if ($typeconfig["sendname"] != 2) {
$field =& $mform->getElement('instructorchoicesendname');
$mform->setDefault('instructorchoicesendname', $typeconfig["sendname"]);
$field->freeze();
$field->setPersistantFreeze(true);
}
if ($typeconfig["sendemailaddr"] != 2) {
$field =& $mform->getElement('instructorchoicesendemailaddr');
$mform->setDefault('instructorchoicesendemailaddr', $typeconfig["sendemailaddr"]);
$field->freeze();
$field->setPersistantFreeze(true);
}
if ($typeconfig["acceptgrades"] != 2) {
$field =& $mform->getElement('instructorchoiceacceptgrades');
$mform->setDefault('instructorchoiceacceptgrades', $typeconfig["acceptgrades"]);
$field->freeze();
$field->setPersistantFreeze(true);
}
if ($typeconfig["allowroster"] != 2) {
$field =& $mform->getElement('instructorchoiceallowroster');
$mform->setDefault('instructorchoiceallowroster', $typeconfig["allowroster"]);
$field->freeze();
$field->setPersistantFreeze(true);
}
if ($typeconfig["allowsetting"] != 2) {
$field =& $mform->getElement('instructorchoiceallowsetting');
$mform->setDefault('instructorchoiceallowsetting', $typeconfig["allowsetting"]);
$field->freeze();
$field->setPersistantFreeze(true);
}
}
}
/**
* Function overwritten to change default values using
* global configuration
*
* @param array $default_values passed by reference
*/
function data_preprocessing(&$default_values) {
global $CFG;
$default_values['typeid'] = $this->typeid;
if (!isset($default_values['toolurl'])) {
if (isset($this->typeconfig['toolurl'])) {
$default_values['toolurl'] = $this->typeconfig['toolurl'];
} else if (isset($CFG->basiclti_toolurl)) {
$default_values['toolurl'] = $CFG->basiclti_toolurl;
}
}
if (!isset($default_values['resourcekey'])) {
if (isset($this->typeconfig['resourcekey'])) {
$default_values['resourcekey'] = $this->typeconfig['resourcekey'];
} else if (isset($CFG->basiclti_resourcekey)) {
$default_values['resourcekey'] = $CFG->basiclti_resourcekey;
}
}
if (!isset($default_values['password'])) {
if (isset($this->typeconfig['password'])) {
$default_values['password'] = $this->typeconfig['password'];
} else if (isset($CFG->basiclti_password)) {
$default_values['password'] = $CFG->basiclti_password;
}
}
if (!isset($default_values['preferheight'])) {
if (isset($this->typeconfig['preferheight'])) {
$default_values['preferheight'] = $this->typeconfig['preferheight'];
} else if (isset($CFG->basiclti_preferheight)) {
$default_values['preferheight'] = $CFG->basiclti_preferheight;
}
}
if (!isset($default_values['sendname'])) {
if (isset($this->typeconfig['sendname'])) {
$default_values['sendname'] = $this->typeconfig['sendname'];
} else if (isset($CFG->basiclti_sendname)) {
$default_values['sendname'] = $CFG->basiclti_sendname;
}
}
if (!isset($default_values['instructorchoicesendname'])) {
if (isset($this->typeconfig['instructorchoicesendname'])) {
$default_values['instructorchoicesendname'] = $this->typeconfig['instructorchoicesendname'];
} else {
if ($this->typeconfig['sendname'] == 2) {
$default_values['instructorchoicesendname'] = $CFG->basiclti_instructorchoicesendname;
} else {
$default_values['instructorchoicesendname'] = $this->typeconfig['sendname'];
}
}
}
if (!isset($default_values['sendemailaddr'])) {
if (isset($this->typeconfig['sendemailaddr'])) {
$default_values['sendemailaddr'] = $this->typeconfig['sendemailaddr'];
} else if (isset($CFG->basiclti_sendemailaddr)) {
$default_values['sendemailaddr'] = $CFG->basiclti_sendemailaddr;
}
}
if (!isset($default_values['instructorchoicesendemailaddr'])) {
if (isset($this->typeconfig['instructorchoicesendemailaddr'])) {
$default_values['instructorchoicesendemailaddr'] = $this->typeconfig['instructorchoicesendemailaddr'];
} else {
if ($this->typeconfig['sendemailaddr'] == 2) {
$default_values['instructorchoicesendemailaddr'] = $CFG->basiclti_instructorchoicesendemailaddr;
} else {
$default_values['instructorchoicesendemailaddr'] = $this->typeconfig['sendemailaddr'];
}
}
}
if (!isset($default_values['acceptgrades'])) {
if (isset($this->typeconfig['acceptgrades'])) {
$default_values['acceptgrades'] = $this->typeconfig['acceptgrades'];
} else if (isset($CFG->basiclti_acceptgrades)) {
$default_values['acceptgrades'] = $CFG->basiclti_acceptgrades;
}
}
if (!isset($default_values['instructorchoiceacceptgrades'])) {
if (isset($this->typeconfig['instructorchoiceacceptgrades'])) {
$default_values['instructorchoiceacceptgrades'] = $this->typeconfig['instructorchoiceacceptgrades'];
} else {
if ($this->typeconfig['acceptgrades'] == 2) {
$default_values['instructorchoiceacceptgrades'] = $CFG->basiclti_instructorchoiceacceptgrades;
} else {
$default_values['instructorchoiceacceptgrades'] = $this->typeconfig['acceptgrades'];
}
}
}
if (!isset($default_values['allowroster'])) {
if (isset($this->typeconfig['allowroster'])) {
$default_values['allowroster'] = $this->typeconfig['allowroster'];
} else if (isset($CFG->basiclti_allowroster)) {
$default_values['allowroster'] = $CFG->basiclti_allowroster;
}
}
if (!isset($default_values['instructorchoiceallowroster'])) {
if (isset($this->typeconfig['instructorchoiceallowroster'])) {
$default_values['instructorchoiceallowroster'] = $this->typeconfig['instructorchoiceallowroster'];
} else {
if ($this->typeconfig['allowroster'] == 2) {
$default_values['instructorchoiceallowroster'] = $CFG->basiclti_instructorchoiceallowroster;
} else {
$default_values['instructorchoiceallowroster'] = $this->typeconfig['allowroster'];
}
}
}
if (!isset($default_values['allowsetting'])) {
if (isset($this->typeconfig['allowsetting'])) {
$default_values['allowsetting'] = $this->typeconfig['allowsetting'];
} else if (isset($CFG->basiclti_allowsetting)) {
$default_values['allowsetting'] = $CFG->basiclti_allowsetting;
}
}
if (!isset($default_values['instructorchoiceallowsetting'])) {
if (isset($this->typeconfig['instructorchoiceallowsetting'])) {
$default_values['instructorchoiceallowsetting'] = $this->typeconfig['instructorchoiceallowsetting'];
} else {
if ($this->typeconfig['allowsetting'] == 2) {
$default_values['instructorchoiceallowsetting'] = $CFG->basiclti_instructorchoiceallowsetting;
} else {
$default_values['instructorchoiceallowsetting'] = $this->typeconfig['allowsetting'];
}
}
}
if (!isset($default_values['customparameters'])) {
if (isset($this->typeconfig['customparameters'])) {
$default_values['customparameters'] = $this->typeconfig['customparameters'];
} else if (isset($CFG->basiclti_customparameters)) {
$default_values['customparameters'] = $CFG->basiclti_customparameters;
}
}
if (!isset($default_values['allowinstructorcustom'])) {
if (isset($this->typeconfig['allowinstructorcustom'])) {
$default_values['allowinstructorcustom'] = $this->typeconfig['allowinstructorcustom'];
} else if (isset($CFG->basiclti_allowinstructorcustom)) {
$default_values['allowinstructorcustom'] = $CFG->basiclti_allowinstructorcustom;
}
}
if (!isset($default_values['organizationid'])) {
if (isset($this->typeconfig['organizationid'])) {
$default_values['organizationid'] = $this->typeconfig['organizationid'];
} else if (isset($CFG->basiclti_organizationid)) {
$default_values['organizationid'] = $CFG->basiclti_organizationid;
}
}
if (!isset($default_values['organizationurl'])) {
if (isset($this->typeconfig['organizationurl'])) {
$default_values['organizationurl'] = $this->typeconfig['organizationurl'];
} else if (isset($CFG->basiclti_organizationurl)) {
$default_values['organizationurl'] = $CFG->basiclti_organizationurl;
}
}
if (!isset($default_values['organizationdescr'])) {
if (isset($this->typeconfig['organizationdescr'])) {
$default_values['organizationdescr'] = $this->typeconfig['organizationdescr'];
} else if (isset($CFG->basiclti_organizationdescr)) {
$default_values['organizationdescr'] = $CFG->basiclti_organizationdescr;
}
}
if (!isset($default_values['launchinpopup'])) {
if (isset($this->typeconfig['launchinpopup'])) {
$default_values['launchinpopup'] = $this->typeconfig['launchinpopup'];
} else if (isset($CFG->basiclti_launchinpopup)) {
$default_values['launchinpopup'] = $CFG->basiclti_launchinpopup;
}
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

+391
View File
@@ -0,0 +1,391 @@
<?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 necessary code to support basiclti services
* like outcomes and roster access.
*
* @package basiclti
* @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
* [email protected]
* @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
*
* @author Marc Alier
* @author Jordi Piguillem
* @author Nikolas Galanis
* @author Charles Severance
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
require_once($CFG->dirroot.'/mod/basiclti/lib.php');
require_once($CFG->dirroot.'/mod/basiclti/locallib.php');
require_once($CFG->dirroot.'/mod/basiclti/OAuth.php');
require_once($CFG->dirroot.'/mod/basiclti/TrivialStore.php');
error_reporting(E_ALL & ~E_NOTICE);
ini_set("display_errors", 1);
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$PAGE->set_url('/mod/basiclti/service.php');
$PAGE->set_pagetype('admin-setting-' . $section);
$PAGE->set_pagelayout('admin');
$PAGE->navigation->clear_cache();
function message_response($major, $severity, $minor=false, $message=false, $xml=false) {
$lti_message_type = $_REQUEST['lti_message_type'];
$retval = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"."\n" .
"<message_response>\n" .
" <lti_message_type>$lti_message_type</lti_message_type>\n" .
" <statusinfo>\n" .
" <codemajor>$major</codemajor>\n" .
" <severity>$severity</severity>\n";
if (! $codeminor === false) {
$retval = $retval . " <codeminor>$minor</codeminor>\n";
}
$retval = $retval .
" <description>$message</description>\n" .
" </statusinfo>\n";
if (! $xml === false) {
$retval = $retval . $xml;
}
$retval = $retval . "</message_response>\n";
return $retval;
}
function do_error($message) {
print message_response('Fail', 'Error', false, $message);
exit();
}
$lti_version = $_REQUEST['lti_version'];
if ($lti_version != "LTI-1p0") {
do_error("Improperly formed message: wrong lti version: ".$lti_version);
}
$lti_message_type = $_REQUEST['lti_message_type'];
if (! isset($lti_message_type)) {
do_error("Improperly formed message: no lti_message_type parameter");
}
$message_type = false;
if ($lti_message_type == "basic-lis-replaceresult" ||
$lti_message_type == "basic-lis-createresult" ||
$lti_message_type == "basic-lis-updateresult" ||
$lti_message_type == "basic-lis-deleteresult" ||
$lti_message_type == "basic-lis-readresult") {
$sourcedid = $_REQUEST['sourcedid'];
$message_type = "basicoutcome";
} else if ($lti_message_type == "basic-lti-loadsetting" ||
$lti_message_type == "basic-lti-savesetting" ||
$lti_message_type == "basic-lti-deletesetting") {
$sourcedid = $_REQUEST['id'];
$message_type = "toolsetting";
} else if ($lti_message_type == "basic-lis-readmembershipsforcontext") {
$sourcedid = $_REQUEST['id'];
$message_type = "roster";
}
if ($message_type == false) {
do_error("Illegal lti_message_type");
}
if (!isset($sourcedid)) {
do_error("sourcedid missing");
}
// Truncate to maximum length
$sourcedid = substr($sourcedid, 0, 2048);
try {
$info = explode(':::', $sourcedid);
if (! is_array($info)) {
do_error("Bad sourcedid (1)");
}
$signature = $info[0];
$userid = intval($info[1]);
$placement = $info[2];
} catch (Exception $e) {
do_error("Bad sourcedid (2)");
}
if (isset($signature) && isset($userid) && isset($placement)) {
// OK
} else {
do_error("Bad sourcedid (3)");
}
// Retrieve the Basic LTI placement
if (! $basiclti = $DB->get_record('basiclti', array('id'=>$placement))) {
do_error("Bad sourcedid (4)");
}
$basiclti_types_config = (object)$basiclti_types_config;
$typeconfig = basiclti_get_type_config($basiclti->typeid);
if (isset($typeconfig) && isset($typeconfig['password'])) {
// OK
} else {
do_error("Unable to load type");
}
if ($message_type == "basicoutcome") {
if ($typeconfig["acceptgrades"] == 1 ||
($typeconfig["acceptgrades"] == 2 && $basiclti->instructorchoiceacceptgrades == 1)) {
// The placement is configured to accept grades
} else {
do_error("Not permitted (1)");
}
} else if ($message_type == "toolsetting") {
if ($typeconfig["allowsetting"] == 1 ||
($typeconfig["allowsetting"] == 2 && $basiclti->instructorchoiceallowsetting == 1)) {
// OK
} else {
do_error("Not permitted (2)");
}
} else if ($message_type == "roster") {
if ($typeconfig["allowroster"] == 1 ||
($typeconfig["allowroster"] == 2 && $basiclti->instructorchoiceallowroster == 1)) {
// OK
} else {
do_error("Not permitted (3)");
}
}
// Retrieve the secret we use to sign lis_result_sourcedid
$placementsecret = $basiclti->placementsecret;
$oldplacementsecret = $basiclti->oldplacementsecret;
if (! isset($placementsecret)) {
do_error("Not permitted (4)");
}
$suffix = ':::' . $userid . ':::' . $placement;
$plaintext = $placementsecret . $suffix;
$hashsig = hash('sha256', $plaintext, false);
if (($hashsig != $signature) && isset($oldplacementsecret) && (strlen($oldplacementsecret) > 1)) {
$plaintext = $oldplacementsecret . $suffix;
$hashsig = hash('sha256', $plaintext, false);
}
if ($hashsig != $signature) {
do_error("Invalid sourcedid");
}
// Check the OAuth Signature
$oauth_secret = $typeconfig["password"];
$oauth_consumer_key = $typeconfig["resourcekey"];
if (! isset($oauth_secret)) {
do_error("Not permitted (5)");
}
if (! isset($oauth_consumer_key)) {
do_error("Not permitted (6)");
}
// Verify the message signature
$store = new TrivialOAuthDataStore();
$store->add_consumer($oauth_consumer_key, $oauth_secret);
$server = new OAuthServer($store);
$method = new OAuthSignatureMethod_HMAC_SHA1();
$server->add_signature_method($method);
$request = OAuthRequest::from_request();
$basestring = $request->get_signature_base_string();
try {
$server->verify_request($request);
} catch (Exception $e) {
do_error($e->getMessage());
}
if (! $course = $DB->get_record('course', array('id'=>$basiclti->course))) {
do_error("Could not retrieve course");
}
// TODO: Check that user is in course
if (! $cm = get_coursemodule_from_instance("basiclti", $basiclti->id, $course->id)) {
do_error("Course Module ID was incorrect");
}
// Lets store the grade
require_once($CFG->libdir.'/gradelib.php');
// Beginning of actual grade processing
if ($message_type == "basicoutcome") {
$source = 'mod/basiclti';
$courseid = $course->id;
$itemtype = 'mod';
$itemmodule = 'basiclti';
$iteminstance = $basiclti->id;
if ($lti_message_type == "basic-lis-readresult") {
unset($grade);
$thegrade = grade_get_grades($courseid, $itemtype, $itemmodule, $iteminstance, $userid);
// print_r($thegrade->items[0]->grades);
if (isset($thegrade) && is_array($thegrade->items[0]->grades)) {
foreach ($thegrade->items[0]->grades as $agrade) {
$grade = $agrade->grade;
break;
}
}
if (! isset($grade)) {
do_error("Unable to read grade");
}
$result = " <result>\n" .
" <resultscore>\n" .
" <textstring>" .
htmlspecialchars($grade/100.0) .
"</textstring>\n" .
" </resultscore>\n" .
" </result>\n";
print message_response('Success', 'Status', false, "Grade read", $result);
exit();
}
if ($lti_message_type == "basic-lis-deleteresult") {
$params = array();
$params['itemname'] = $basiclti->name;
$grade = new stdClass();
$grade->userid = $userid;
$grade->rawgrade = null;
grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance, 0, $grade, array('deleted'=>1));
} else {
if (isset($_REQUEST['result_resultscore_textstring'])) {
$gradeval = floatval($_REQUEST['result_resultscore_textstring']);
if ($gradeval <= 1.0 && $gradeval >= 0.0) {
$gradeval = $gradeval * 100.0;
}
} else {
do_error('Missing Grade');
}
$params = array();
$params['itemname'] = $basiclti->name;
$grade = new stdClass();
$grade->userid = $userid;
$grade->rawgrade = $gradeval;
grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance, 0, $grade, $params);
}
print message_response('Success', 'Status', 'fullsuccess', 'Grade updated');
} else if ($lti_message_type == "basic-lti-loadsetting") {
$xml = " <setting>\n" .
" <value>".htmlspecialchars($basiclti->setting)."</value>\n" .
" </setting>\n";
print message_response('Success', 'Status', 'fullsuccess', 'Setting retrieved', $xml);
} else if ($lti_message_type == "basic-lti-savesetting") {
$setting = $_REQUEST['setting'];
if (! isset($setting)) {
do_error('Missing setting value');
}
$record = $DB->get_record('basiclti', array('id'=>$basiclti->id));
$record->setting = $setting;
$success = $DB->update_record('basiclti', $record);
if ($success) {
print message_response('Success', 'Status', 'fullsuccess', 'Setting updated');
} else {
do_error("Error updating error");
}
} else if ($lti_message_type == "basic-lti-deletesetting") {
$record = $DB->get_record('basiclti', array('id'=>$basiclti->id));
$record->setting = '';
$success = $DB->update_record('basiclti', $record);
if ($success) {
print message_response('Success', 'Status', 'fullsuccess', 'Setting deleted');
} else {
do_error("Error updating error");
}
} else if ($message_type == "roster") {
if (! $course = $DB->get_record('course', array('id'=>$basiclti->course))) {
do_error("Could not retrieve course");
}
if (! $context = get_context_instance(CONTEXT_COURSE, $course->id)) {
do_error("Could not retrieve context");
}
$sql = 'SELECT u.id, u.username, u.firstname, u.lastname, u.email, ro.shortname
FROM '.$CFG->prefix.'role_assignments ra
JOIN '.$CFG->prefix.'user AS u ON ra.userid = u.id
JOIN '.$CFG->prefix.'role ro ON ra.roleid = ro.id
WHERE ra.contextid = '.$context->id;
$userlist = $DB->get_recordset_sql($sql);
$xml = " <memberships>\n";
foreach ($userlist as $user) {
$role = "Learner";
if ($user->shortname == 'editingteacher' || $user->shortname == 'admin') {
$role = 'Instructor';
}
$userxml = " <member>\n".
" <user_id>".htmlspecialchars($user->id)."</user_id>\n".
" <roles>$role</roles>\n";
if ($typeconfig["sendname"] == 1 ||
($typeconfig["sendname"] == 2 && $basiclti->instructorchoicesendname == 1)) {
if (isset($user->firstname)) {
$userxml .= " <person_name_given>".htmlspecialchars($user->firstname)."</person_name_given>\n";
}
if (isset($user->lastname)) {
$userxml .= " <person_name_family>".htmlspecialchars($user->lastname)."</person_name_family>\n";
}
}
if ($typeconfig["sendemailaddr"] == 1 ||
($typeconfig["sendemailaddr"] == 2 && $basiclti->instructorchoicesendemailaddr == 1)) {
if (isset($user->email)) {
$userxml .= " <person_contact_email_primary>".htmlspecialchars($user->email)."</person_contact_email_primary>\n";
}
}
$placementsecret = $basiclti->placementsecret;
if (isset($placementsecret)) {
$suffix = ':::' . $user->id . ':::' . $basiclti->id;
$plaintext = $placementsecret . $suffix;
$hashsig = hash('sha256', $plaintext, false);
$sourcedid = $hashsig . $suffix;
}
if ($typeconfig["acceptgrades"] == 1 ||
($typeconfig["acceptgrades"] == 2 && $basiclti->instructorchoiceacceptgrades == 1)) {
if (isset($sourcedid)) {
$userxml .= " <lis_result_sourcedid>".htmlspecialchars($sourcedid)."</lis_result_sourcedid>\n";
}
}
$userxml .= " </member>\n";
$xml .= $userxml;
}
$xml .= " </memberships>\n";
print message_response('Success', 'Status', 'fullsuccess', 'Roster retreived', $xml);
}
+100
View File
@@ -0,0 +1,100 @@
<?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 the global basiclti administration form
*
* @package basiclti
* @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
* [email protected]
* @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
*
* @author Marc Alier
* @author Jordi Piguillem
* @author Nikolas Galanis
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
if ($ADMIN->fulltree) {
require_once($CFG->dirroot.'/mod/basiclti/locallib.php');
$str = '';
$types = basiclti_filter_get_types();
if (!empty($types)) {
$str .= '<h4 class="main"><a href="'.$CFG->wwwroot.'/mod/basiclti/typessettings.php?action=add&amp;sesskey='.$USER->sesskey.'">'.get_string('addtype', 'basiclti').'</a></h4>';
$str .= '<table>';
foreach ($types as $type) {
$str .= '<tr>'.
'<td>'.$type->name.'</td>'.
'<td align="center"><a class="editing_update" href="'.$CFG->wwwroot.'/mod/basiclti/typessettings.php?action=update&amp;id='.$type->id.'&amp;sesskey='.$USER->sesskey.'" title="Update">'.
'<img class="iconsmall" alt="Update" src="'.$CFG->wwwroot.'/pix/t/edit.gif"/></a>'.'&nbsp;&nbsp;'.
'<a class="editing_delete" href="'.$CFG->wwwroot.'/mod/basiclti/typessettings.php?action=delete&amp;id='.$type->id.'&amp;sesskey='.$USER->sesskey.'" title="Delete">'.
'<img class="iconsmall" alt="Delete" src="'.$CFG->wwwroot.'/pix/t/delete.gif"/>'.
'</a>'.
'</td>'.
'</tr>';
}
$str .= '</table>';
} else {
$str .= '<center>';
$str .= '<h4 class="main"><a href="'.$CFG->wwwroot.'/mod/basiclti/typessettings.php?action=add&amp;sesskey='.$USER->sesskey.'">'.get_string('addtype', 'basiclti').'</a></h4>';
$str .= get_string('notypes', 'basiclti');
$str .= '</center>';
}
$settings->add(new admin_setting_heading('basiclti_types', get_string('configuredtools', 'basiclti'), $str));
$unconfigured = basiclti_get_unconfigured_tools();
if (!empty($unconfigured)) {
$newstr = '<table>';
$newstr .= '<tr> <th>Course</th> <th>Tool Name</th> </tr>';
foreach ($unconfigured as $unconf) {
$coursename = $DB->get_field('course', 'shortname', array('id' => $unconf->course));
$newstr .= '<tr>'.
'<td>'.$coursename.'</td><td>'.$unconf->name.'</td>'.
'<td align="center"><a class="editing_update" href="'.$CFG->wwwroot.'/mod/basiclti/typessettings.php?action=fix&amp;id='.$unconf->id.'&amp;sesskey='.$USER->sesskey.'" title="Fix">'.
'<img class="iconsmall" alt="Update" src="'.$CFG->wwwroot.'/pix/t/edit.gif"/></a>'.'&nbsp;&nbsp;'.'</td>'.
'</tr>';
}
$newstr .= '</table>';
$settings->add(new admin_setting_heading('basiclti_mis_types', get_string('misconfiguredtools', 'basiclti'), $newstr));
}
}
+89
View File
@@ -0,0 +1,89 @@
<?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
* [email protected]
* @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
*
* @author Charles Severance [email protected]
* @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);
}
}
+29
View File
@@ -0,0 +1,29 @@
.path-mod-basiclti .basicltiframe {position: relative;width: 100%;height: 100%;}
/** General Styles **/
.path-mod-basiclti .userpicture,
.path-mod-basiclti .picture.user,
.path-mod-basiclti .picture.teacher {width:35px;height: 35px;vertical-align:top;}
.path-mod-basiclti .feedback .files,
.path-mod-basiclti .feedback .grade,
.path-mod-basiclti .feedback .outcome,
.path-mod-basiclti .feedback .finalgrade {float: right;}
.path-mod-basiclti .feedback .disabledfeedback {width: 500px;height: 250px;}
.path-mod-basiclti .feedback .from {float: left;}
.path-mod-basiclti .files img {margin-right: 4px;}
.path-mod-basiclti .files a {white-space:nowrap;}
.path-mod-basiclti .late {color: red;}
.path-mod-basiclti .message {text-align: center;}
/** Styles for submissions.php **/
#page-mod-basiclti-submissions fieldset.felement {margin-left: 16%;}
#page-mod-basiclti-submissions form#options div {text-align:right;margin-left:auto;margin-right:20px;}
#page-mod-basiclti-submissions .header .commands {display: inline;}
#page-mod-basiclti-submissions .picture {width: 35px;}
#page-mod-basiclti-submissions .fullname,
#page-mod-basiclti-submissions .timemodified,
#page-mod-basiclti-submissions .timemarked {text-align: left;}
#page-mod-basiclti-submissions .submissions .grade,
#page-mod-basiclti-submissions .submissions .outcome,
#page-mod-basiclti-submissions .submissions .finalgrade {text-align: right;}
#page-mod-basiclti-submissions .qgprefs #optiontable {text-align:right;margin-left:auto;}
+92
View File
@@ -0,0 +1,92 @@
<?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
* [email protected]
* @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
+258
View File
@@ -0,0 +1,258 @@
<?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 script used to clone Moodle admin setting page.
* It is used to create a new form used to pre-configure basiclti
* activities
*
* @package basiclti
* @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
* [email protected]
* @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
*
* @author Marc Alier
* @author Jordi Piguillem
* @author Nikolas Galanis
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->dirroot.'/mod/basiclti/edit_form.php');
require_once($CFG->dirroot.'/mod/basiclti/locallib.php');
$section = 'modsettingbasiclti';
$return = optional_param('return', '', PARAM_ALPHA);
$adminediting = optional_param('adminedit', -1, PARAM_BOOL);
$action = optional_param('action', null, PARAM_TEXT);
$id = optional_param('id', null, PARAM_INT);
$useexisting = optional_param('useexisting', null, PARAM_INT);
$definenew = optional_param('definenew', null, PARAM_INT);
/// no guest autologin
require_login(0, false);
$url = new moodle_url('/mod/basiclti/typesettings.php');
$PAGE->set_url($url);
admin_externalpage_setup('managemodules'); // Hacky solution for printing the admin page
/// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
$statusmsg = '';
$errormsg = '';
$focus = '';
if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton)) {
if (isset($id)) {
$type = new StdClass();
$type->id = $id;
$type->name = $data->lti_typename;
$type->rawname = preg_replace('/[^a-zA-Z]/', '', $type->name);
if ($DB->update_record('basiclti_types', $type)) {
unset ($data->lti_typename);
//@TODO: update work
foreach ($data as $key => $value) {
if (substr($key, 0, 4)=='lti_' && !is_null($value)) {
$record = new StdClass();
$record->typeid = $id;
$record->name = substr($key, 4);
$record->value = $value;
if (basiclti_update_config($record)) {
$statusmsg = get_string('changessaved');
} else {
$errormsg = get_string('errorwithsettings', 'admin');
}
}
}
// Update toolurl for all existing instances - it is the only common parameter
// between configurations and instances
$instances = $DB->get_records('basiclti', array('typeid' => $id));
foreach ($instances as $instance) {
if ($instance->toolurl != $data->lti_toolurl) {
$instance->toolurl = $data->lti_toolurl;
$DB->update_record('basiclti', $instance);
}
}
}
redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingbasiclti");
die;
} else {
$type = new StdClass();
$type->name = $data->lti_typename;
$type->rawname = preg_replace('/[^a-zA-Z]/', '', $type->name);
if ($id = $DB->insert_record('basiclti_types', $type)) {
if (!empty($data->lti_fix)) {
$instance = $DB->get_record('basiclti', array('id' => $data->lti_fix));
$instance->typeid = $id;
$DB->update_record('basiclti', $instance);
}
unset ($data->lti_fix);
unset ($data->lti_typename);
foreach ($data as $key => $value) {
if (substr($key, 0, 4)=='lti_' && !is_null($value)) {
$record = new StdClass();
$record->typeid = $id;
$record->name = substr($key, 4);
$record->value = $value;
if (basiclti_add_config($record)) {
$statusmsg = get_string('changessaved');
} else {
$errormsg = get_string('errorwithsettings', 'admin');
}
}
}
} else {
$errormsg = get_string('errorwithsettings', 'admin');
}
redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingbasiclti");
die;
}
if (empty($adminroot->errors)) {
switch ($return) {
case 'site': redirect("$CFG->wwwroot/");
case 'admin': redirect("$CFG->wwwroot/$CFG->admin/");
}
} else {
$errormsg = get_string('errorwithsettings', 'admin');
$firsterror = reset($adminroot->errors);
$focus = $firsterror->id;
}
$adminroot =& admin_get_root(true); //reload tree
$page =& $adminroot->locate($section);
}
if ($action == 'delete') {
basiclti_delete_type($id);
redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingbasiclti");
die;
}
if (($action == 'fix') && isset($useexisting)) {
$instance = $DB->get_record('basiclti', array('id' => $id));
$instance->typeid = $useexisting;
$DB->update_record('basiclti', $instance);
redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingbasiclti");
die;
}
/// print header stuff ------------------------------------------------------------
$PAGE->set_focuscontrol($focus);
if (empty($SITE->fullname)) {
$PAGE->set_title($settingspage->visiblename);
$PAGE->set_heading($settingspage->visiblename);
$PAGE->navbar->add('Basic LTI Administration', $CFG->wwwroot.'/admin/settings.php?section=modsettingbasiclti');
echo $OUTPUT->header();
echo $OUTPUT->box(get_string('configintrosite', 'admin'));
if ($errormsg !== '') {
echo $OUTPUT->notification($errormsg);
} else if ($statusmsg !== '') {
echo $OUTPUT->notification($statusmsg, 'notifysuccess');
}
// ---------------------------------------------------------------------------------------------------------------
echo '<form action="typesettings.php" method="post" id="'.$id.'" >';
echo '<div class="settingsform clearfix">';
echo html_writer::input_hidden_params($PAGE->url);
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<input type="hidden" name="return" value="'.$return.'" />';
echo $settingspage->output_html();
echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges', 'admin').'" /></div>';
echo '</div>';
echo '</form>';
} else {
if ($PAGE->user_allowed_editing()) {
$url = clone($PAGE->url);
if ($PAGE->user_is_editing()) {
$caption = get_string('blockseditoff');
$url->param('adminedit', 'off');
} else {
$caption = get_string('blocksediton');
$url->param('adminedit', 'on');
}
$buttons = $OUTPUT->single_button($url, $caption, 'get');
}
$PAGE->set_title("$SITE->shortname: " . get_string('toolsetup', 'basiclti'));
$PAGE->navbar->add('Basic LTI Administration', $CFG->wwwroot.'/admin/settings.php?section=modsettingbasiclti');
echo $OUTPUT->header();
if ($errormsg !== '') {
echo $OUTPUT->notification($errormsg);
} else if ($statusmsg !== '') {
echo $OUTPUT->notification($statusmsg, 'notifysuccess');
}
// ---------------------------------------------------------------------------------------------------------------
echo $OUTPUT->heading(get_string('toolsetup', 'basiclti'));
echo $OUTPUT->box_start('generalbox');
if ($action == 'add') {
$form = new mod_basiclti_edit_types_form();
$form->display();
} else if ($action == 'update') {
$form = new mod_basiclti_edit_types_form('typessettings.php?id='.$id);
$type = basiclti_get_type_type_config($id);
$form->set_data($type);
$form->display();
} else if ($action == 'fix') {
if (!isset($definenew) && !isset($useexisting)) {
basiclti_fix_misconfigured_choice($id);
} else if (isset($definenew)) {
$form = new mod_basiclti_edit_types_form();
$type = basiclti_get_type_config_from_instance($id);
$form->set_data($type);
$form->display();
}
}
echo $OUTPUT->box_end();
}
echo $OUTPUT->footer();
+50
View File
@@ -0,0 +1,50 @@
<?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 the version of basiclti
* This fragment is called by moodle_needs_upgrading() and /admin/index.php
*
* @package basiclti
* @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
* [email protected]
* @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
*
* @author Marc Alier
* @author Jordi Piguillem
* @author Nikolas Galanis
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$module->version = 2011072000; // The current module version (Date: YYYYMMDDXX)
$module->cron = 0; // Period for cron to check this module (secs)
+132
View File
@@ -0,0 +1,132 @@
<?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 necessary code to view a basiclti activity instance
*
* @package basiclti
* @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
* [email protected]
* @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
*
* @author Marc Alier
* @author Jordi Piguillem
* @author Nikolas Galanis
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
require_once($CFG->dirroot.'/mod/basiclti/lib.php');
require_once($CFG->dirroot.'/mod/basiclti/locallib.php');
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
$a = optional_param('a', 0, PARAM_INT); // basiclti ID
if ($id) {
if (! $cm = get_coursemodule_from_id("basiclti", $id)) {
throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect');
}
if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured');
}
if (! $basiclti = $DB->get_record("basiclti", array("id" => $cm->instance))) {
throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect');
}
} else {
if (! $basiclti = $DB->get_record("basiclti", array("id" => $a))) {
throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect');
}
if (! $course = $DB->get_record("course", array("id" => $basiclti->course))) {
throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured');
}
if (! $cm = get_coursemodule_from_instance("basiclti", $basiclti->id, $course->id)) {
throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect');
}
}
$PAGE->set_cm($cm, $course); // set's up global $COURSE
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$PAGE->set_context($context);
$url = new moodle_url('/mod/basiclti/view.php', array('id'=>$cm->id));
$PAGE->set_url($url);
$PAGE->set_pagelayout('incourse');
require_login($course);
add_to_log($course->id, "basiclti", "view", "view.php?id=$cm->id", "$basiclti->id");
$pagetitle = strip_tags($course->shortname.': '.format_string($basiclti->name));
$PAGE->set_title($pagetitle);
$PAGE->set_heading($course->fullname);
/// Print the page header
echo $OUTPUT->header();
/// Print the main part of the page
echo $OUTPUT->heading(format_string($basiclti->name));
echo $OUTPUT->box($basiclti->intro, 'generalbox description', 'intro');
if ($basiclti->typeid == 0) {
print_error('errormisconfig', 'basiclti');
}
if ($basiclti->instructorchoiceacceptgrades == 1) {
echo '<div class="reportlink">'.submittedlink($cm).'</div>';
}
echo $OUTPUT->box_start('generalbox activity');
if ( $basiclti->launchinpopup > 0 ) {
print "<script language=\"javascript\">//<![CDATA[\n";
print "window.open('launch.php?id=".$cm->id."','window name');";
print "//]]\n";
print "</script>\n";
print "<p>".get_string("basiclti_in_new_window", "basiclti")."</p>\n";
} else {
// Request the launch content with an object tag
$height = $basiclti->preferheight;
if ((!$height) || ($height == 0)) {
$height = 400;
}
print '<object height="'.$height.'" width="100%" data="launch.php?id='.$cm->id.'&amp;withobject=true"></object>';
}
echo $OUTPUT->box_end();
/// Finish the page
echo $OUTPUT->footer();