Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updates to lti plugin & progress on instructor management of course t…

…ools.
  • Loading branch information...
commit 996b0fd9613de8cdd04d2f42528ad4d343e56993 1 parent dbb0fec
@scriby scriby authored
View
9 mod/lti/OAuthBody.php
@@ -72,10 +72,11 @@ function getOAuthKeyFromHeaders()
return false;
}
-function handleOAuthBodyPOST($oauth_consumer_key, $oauth_consumer_secret)
+function handleOAuthBodyPOST($oauth_consumer_key, $oauth_consumer_secret, $body, $request_headers = null)
{
- $request_headers = OAuthUtil::get_headers();
- // print_r($request_headers);
+ if($request_headers == null){
+ $request_headers = OAuthUtil::get_headers();
+ }
// Must reject application/x-www-form-urlencoded
if ($request_headers['Content-type'] == 'application/x-www-form-urlencoded' ) {
@@ -112,7 +113,7 @@ function handleOAuthBodyPOST($oauth_consumer_key, $oauth_consumer_secret)
throw new Exception("OAuth signature failed: " . $message);
}
- $postdata = file_get_contents('php://input');
+ $postdata = $body;
// echo($postdata);
$hash = base64_encode(sha1($postdata, TRUE));
View
4 mod/lti/basiclti.js
@@ -53,6 +53,4 @@ function basicltiDebugToggle() {
else {
ele.style.display = 'block';
}
-}
-
-alert('a');
+}
View
325 mod/lti/edit_form.php
@@ -1,159 +1,166 @@
-<?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 lti
- * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
- * marc.alier@upc.edu
- * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
- *
- * @author Marc Alier
- * @author Jordi Piguillem
- * @author Nikolas Galanis
- * @author Charles Severance
- *
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die;
-
-require_once($CFG->libdir.'/formslib.php');
-
-class mod_lti_edit_types_form extends moodleform{
-
- function definition() {
- $mform =& $this->_form;
-
-//-------------------------------------------------------------------------------
- // Add basiclti elements
- $mform->addElement('header', 'setup', get_string('tool_settings', 'lti'));
-
- $mform->addElement('text', 'lti_typename', get_string('typename', 'lti'));
- $mform->setType('lti_typename', PARAM_INT);
-// $mform->addHelpButton('lti_typename', 'typename','lti');
- $mform->addRule('lti_typename', null, 'required', null, 'client');
-
- $mform->addElement('text', 'lti_toolurl', get_string('toolurl', 'lti'), array('size'=>'64'));
- $mform->setType('lti_toolurl', PARAM_TEXT);
-// $mform->addHelpButton('lti_toolurl', 'toolurl', 'lti');
- $mform->addRule('lti_toolurl', null, 'required', null, 'client');
-
- $mform->addElement('text', 'lti_resourcekey', get_string('resourcekey', 'lti'));
- $mform->setType('lti_resourcekey', PARAM_TEXT);
-
- $mform->addElement('passwordunmask', 'lti_password', get_string('password', 'lti'));
- $mform->setType('lti_password', PARAM_TEXT);
-
- $mform->addElement('textarea', 'lti_customparameters', get_string('custom', 'lti'), array('rows'=>4, 'cols'=>60));
- $mform->setType('lti_customparameters', PARAM_TEXT);
-
- $mform->addElement('checkbox', 'lti_coursevisible', '&nbsp;', ' ' . get_string('show_in_course', 'lti'));
-
- $launchoptions=array();
- $launchoptions[LTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'lti');
- $launchoptions[LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'lti');
- $launchoptions[LTI_LAUNCH_CONTAINER_WINDOW] = get_string('new_window', 'lti');
-
- $mform->addElement('select', 'lti_launchcontainer', get_string('default_launch_container', 'lti'), $launchoptions);
- $mform->setDefault('lti_launchcontainer', LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS);
-// $mform->addHelpButton('lti_launchinpopup', 'launchinpopup', 'lti');
-
- // Add privacy preferences fieldset where users choose whether to send their data
- $mform->addElement('header', 'privacy', get_string('privacy', 'lti'));
-
- $options=array();
- $options[0] = get_string('never', 'lti');
- $options[1] = get_string('always', 'lti');
- $options[2] = get_string('delegate_yes', 'lti');
- $options[3] = get_string('delegate_no', 'lti');
-
- $mform->addElement('select', 'lti_sendname', get_string('sendname', 'lti'), $options);
- $mform->setDefault('lti_sendname', '2');
-// $mform->addHelpButton('lti_sendname', 'sendname', 'lti');
-
- $mform->addElement('select', 'lti_sendemailaddr', get_string('sendemailaddr', 'lti'), $options);
- $mform->setDefault('lti_sendemailaddr', '2');
-// $mform->addHelpButton('lti_sendemailaddr', 'sendemailaddr', 'lti');
-
-//-------------------------------------------------------------------------------
- // LTI Extensions
-
- // Add grading preferences fieldset where the tool is allowed to return grades
- $mform->addElement('select', 'lti_acceptgrades', get_string('acceptgrades', 'lti'), $options);
- $mform->setDefault('lti_acceptgrades', '2');
-// $mform->addHelpButton('lti_acceptgrades', 'acceptgrades', 'lti');
-
- // Add grading preferences fieldset where the tool is allowed to retrieve rosters
- $mform->addElement('select', 'lti_allowroster', get_string('allowroster', 'lti'), $options);
- $mform->setDefault('lti_allowroster', '2');
-// $mform->addHelpButton('lti_allowroster', 'allowroster', 'lti');
-
-
-//-------------------------------------------------------------------------------
- // Add setup parameters fieldset
- $mform->addElement('header', 'setupoptions', get_string('miscellaneous', 'lti'));
-
- // Adding option to change id that is placed in context_id
- $idoptions = array();
- $idoptions[0] = get_string('id', 'lti');
- $idoptions[1] = get_string('courseid', 'lti');
-
- $mform->addElement('text', 'lti_organizationid', get_string('organizationid', 'lti'));
- $mform->setType('lti_organizationid', PARAM_TEXT);
-// $mform->addHelpButton('lti_organizationid', 'organizationid', 'lti');
-
- $mform->addElement('text', 'lti_organizationurl', get_string('organizationurl', 'lti'));
- $mform->setType('lti_organizationurl', PARAM_TEXT);
-// $mform->addHelpButton('lti_organizationurl', 'organizationurl', 'lti');
-
- /* Suppress this for now - Chuck
- $mform->addElement('text', 'lti_organizationdescr', get_string('organizationdescr', 'lti'));
- $mform->setType('lti_organizationdescr', PARAM_TEXT);
- $mform->addHelpButton('lti_organizationdescr', 'organizationdescr', 'lti');
- */
-
-//-------------------------------------------------------------------------------
- // Add a hidden element to signal a tool fixing operation after a problematic backup - restore process
- $mform->addElement('hidden', 'lti_fix');
-
- $tab = optional_param('tab', '', PARAM_ALPHAEXT);
- $mform->addElement('hidden', 'tab', $tab);
-
-
-//-------------------------------------------------------------------------------
- // Add standard buttons, common to all modules
- $this->add_action_buttons();
-
- }
-}
+<?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 lti
+ * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
+ * marc.alier@upc.edu
+ * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
+ *
+ * @author Marc Alier
+ * @author Jordi Piguillem
+ * @author Nikolas Galanis
+ * @author Charles Severance
+ *
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+require_once($CFG->libdir.'/formslib.php');
+require_once($CFG->dirroot.'/mod/lti/locallib.php');
+
+class mod_lti_edit_types_form extends moodleform{
+ function definition() {
+ $mform =& $this->_form;
+
+//-------------------------------------------------------------------------------
+ // Add basiclti elements
+ $mform->addElement('header', 'setup', get_string('tool_settings', 'lti'));
+
+ $mform->addElement('text', 'lti_typename', get_string('typename', 'lti'));
+ $mform->setType('lti_typename', PARAM_INT);
+// $mform->addHelpButton('lti_typename', 'typename','lti');
+ $mform->addRule('lti_typename', null, 'required', null, 'client');
+
+ $mform->addElement('text', 'lti_toolurl', get_string('toolurl', 'lti'), array('size'=>'64'));
+ $mform->setType('lti_toolurl', PARAM_TEXT);
+// $mform->addHelpButton('lti_toolurl', 'toolurl', 'lti');
+ $mform->addRule('lti_toolurl', null, 'required', null, 'client');
+
+ $mform->addElement('text', 'lti_resourcekey', get_string('resourcekey', 'lti'));
+ $mform->setType('lti_resourcekey', PARAM_TEXT);
+
+ $mform->addElement('passwordunmask', 'lti_password', get_string('password', 'lti'));
+ $mform->setType('lti_password', PARAM_TEXT);
+
+ $mform->addElement('textarea', 'lti_customparameters', get_string('custom', 'lti'), array('rows'=>4, 'cols'=>60));
+ $mform->setType('lti_customparameters', PARAM_TEXT);
+
+ if(!empty($this->_customdata->isadmin)){
+ $mform->addElement('checkbox', 'lti_coursevisible', '&nbsp;', ' ' . get_string('show_in_course', 'lti'));
+ } else {
+ $mform->addElement('hidden', 'lti_coursevisible', '1');
+ }
+
+ $launchoptions=array();
+ $launchoptions[LTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'lti');
+ $launchoptions[LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'lti');
+ $launchoptions[LTI_LAUNCH_CONTAINER_WINDOW] = get_string('new_window', 'lti');
+
+ $mform->addElement('select', 'lti_launchcontainer', get_string('default_launch_container', 'lti'), $launchoptions);
+ $mform->setDefault('lti_launchcontainer', LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS);
+// $mform->addHelpButton('lti_launchinpopup', 'launchinpopup', 'lti');
+
+ // Add privacy preferences fieldset where users choose whether to send their data
+ $mform->addElement('header', 'privacy', get_string('privacy', 'lti'));
+
+ $options=array();
+ $options[0] = get_string('never', 'lti');
+ $options[1] = get_string('always', 'lti');
+ $options[2] = get_string('delegate', 'lti');
+
+ $mform->addElement('select', 'lti_sendname', get_string('sendname', 'lti'), $options);
+ $mform->setDefault('lti_sendname', '2');
+// $mform->addHelpButton('lti_sendname', 'sendname', 'lti');
+
+ $mform->addElement('select', 'lti_sendemailaddr', get_string('sendemailaddr', 'lti'), $options);
+ $mform->setDefault('lti_sendemailaddr', '2');
+// $mform->addHelpButton('lti_sendemailaddr', 'sendemailaddr', 'lti');
+
+//-------------------------------------------------------------------------------
+ // LTI Extensions
+
+ // Add grading preferences fieldset where the tool is allowed to return grades
+ $mform->addElement('select', 'lti_acceptgrades', get_string('acceptgrades', 'lti'), $options);
+ $mform->setDefault('lti_acceptgrades', '2');
+// $mform->addHelpButton('lti_acceptgrades', 'acceptgrades', 'lti');
+
+ // Add grading preferences fieldset where the tool is allowed to retrieve rosters
+ $mform->addElement('select', 'lti_allowroster', get_string('allowroster', 'lti'), $options);
+ $mform->setDefault('lti_allowroster', '2');
+// $mform->addHelpButton('lti_allowroster', 'allowroster', 'lti');
+
+
+ if(!empty($this->_customdata->isadmin)){
+ //-------------------------------------------------------------------------------
+ // Add setup parameters fieldset
+ $mform->addElement('header', 'setupoptions', get_string('miscellaneous', 'lti'));
+
+ // Adding option to change id that is placed in context_id
+ $idoptions = array();
+ $idoptions[0] = get_string('id', 'lti');
+ $idoptions[1] = get_string('courseid', 'lti');
+
+ $mform->addElement('text', 'lti_organizationid', get_string('organizationid', 'lti'));
+ $mform->setType('lti_organizationid', PARAM_TEXT);
+ // $mform->addHelpButton('lti_organizationid', 'organizationid', 'lti');
+
+ $mform->addElement('text', 'lti_organizationurl', get_string('organizationurl', 'lti'));
+ $mform->setType('lti_organizationurl', PARAM_TEXT);
+ // $mform->addHelpButton('lti_organizationurl', 'organizationurl', 'lti');
+ }
+
+ /* Suppress this for now - Chuck
+ $mform->addElement('text', 'lti_organizationdescr', get_string('organizationdescr', 'lti'));
+ $mform->setType('lti_organizationdescr', PARAM_TEXT);
+ $mform->addHelpButton('lti_organizationdescr', 'organizationdescr', 'lti');
+ */
+
+//-------------------------------------------------------------------------------
+ // Add a hidden element to signal a tool fixing operation after a problematic backup - restore process
+ //$mform->addElement('hidden', 'lti_fix');
+
+ $tab = optional_param('tab', '', PARAM_ALPHAEXT);
+ $mform->addElement('hidden', 'tab', $tab);
+
+ $courseid = optional_param('course', 1, PARAM_INT);
+ $mform->addElement('hidden', 'course', $courseid);
+
+//-------------------------------------------------------------------------------
+ // Add standard buttons, common to all modules
+ $this->add_action_buttons();
+
+ }
+}
View
93 mod/lti/instructor_edit_tool_type.php
@@ -0,0 +1,93 @@
+<?php
+require_once('../../config.php');
+require_once($CFG->dirroot.'/mod/lti/edit_form.php');
+
+$courseid = required_param('course', PARAM_INT);
+
+require_login($courseid, false);
+$url = new moodle_url('/mod/lti/instructor_edit_tool_type.php');
+$PAGE->set_url($url);
+$PAGE->set_pagelayout('popup');
+
+$action = optional_param('action', null, PARAM_TEXT);
+$typeid = optional_param('typeid', null, PARAM_INT);
+
+if(!empty($typeid)){
+ $type = lti_get_type($typeid);
+ if($type->course != $courseid){
+ throw new Exception('You do not have permissions to edit this tool type.');
+
+ die;
+ }
+}
+
+echo $OUTPUT->header();
+
+$data = data_submitted();
+
+if (confirm_sesskey() && isset($data->submitbutton)) {
+ $type = new stdClass();
+
+ if (isset($id)) {
+ /*$type->id = $id;
+
+ lti_update_type($type, $data);
+ $script = <<<SCRIPT
+ <script type="text/javascript">
+ window.opener.M.mod_lti.editor.updateToolType({$name}, '{$id}');
+
+ window.close();
+ </script>
+SCRIPT;*/
+
+ die;
+ } else {
+ $type->state = LTI_TOOL_STATE_CONFIGURED;
+ $type->course = $COURSE->id;
+
+ $id = lti_add_type($type, $data);
+ $name = json_encode($type->name);
+
+ $script = <<<SCRIPT
+ <script type="text/javascript">
+ window.opener.M.mod_lti.editor.addToolType({$name}, '{$id}');
+
+ window.close();
+ </script>
+SCRIPT;
+
+ echo $script;
+
+ die;
+ }
+} else if(isset($data->cancel)){
+ $script = <<<SCRIPT
+ <script type="text/javascript">
+ window.close();
+ </script>
+SCRIPT;
+
+ echo $script;
+ die;
+}
+
+//Delete action is called via ajax
+if ($action == 'delete'){
+ lti_delete_type($typeid);
+
+ die;
+}
+
+echo $OUTPUT->heading(get_string('toolsetup', 'lti'));
+
+if($action == 'add') {
+ $form = new mod_lti_edit_types_form();
+ $form->display();
+} else if($action == 'edit'){
+ $form = new mod_lti_edit_types_form();
+ $type = lti_get_type_type_config($typeid);
+ $form->set_data($type);
+ $form->display();
+}
+
+echo $OUTPUT->footer();
View
394 mod/lti/lang/en/lti.php
@@ -1,198 +1,196 @@
-<?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
- * marc.alier@upc.edu
- * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
- *
- * @author Marc Alier
- * @author Jordi Piguillem
- * @author Nikolas Galanis
- *
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-$string['accept'] = 'Accept';
-$string['acceptgrades'] = 'Accept grades from tool';
-$string['activity'] = 'Activity';
-$string['addnewapp'] = 'Enable External Application';
-$string['addserver'] = 'Add new trusted server';
-$string['addtype'] = 'Add External Tool Configuration';
-$string['allow'] = 'Allow';
-$string['allowinstructorcustom'] = 'Allow instructors to add custom parameters';
-$string['allowroster'] = 'Tool may access course roster';
-$string['allowsetting'] = 'Allow tool to store 8K of settings in Moodle';
-$string['always'] = 'Always';
-$string['lti'] = 'Basic LTI';
-$string['basiclti'] = 'Basic LTI';
-$string['basiclti_base_string'] = 'Basic LTI OAuth Base String';
-$string['basiclti_in_new_window'] = 'Your activity has opened in a new window';
-$string['basiclti_endpoint'] = 'Basic LTI Launch Endpoint';
-$string['basiclti_parameters'] = 'Basic LTI Launch Parameters';
-$string['basicltiactivities'] = 'Basic LTI Activities';
-$string['basicltifieldset'] = 'Custom example fieldset';
-$string['basicltiintro'] = 'Activity Description';
-$string['basicltiname'] = 'Activity Name';
-$string['basicltisettings'] = 'Basic Learning Tool Interoperability Settings';
-$string['comment'] = 'Comment';
-$string['configpassword'] = 'Default Remote Tool Password';
-$string['configpreferheight'] = 'Default preferred height';
-$string['configpreferwidget'] = 'Set widget as default launch';
-$string['configpreferwidth'] = 'Default preferred width';
-$string['configresourceurl'] = 'Default Resource URL';
-$string['configtoolurl'] = 'Default Remote Tool URL';
-$string['configtypes'] = 'Enable Basic LTI Applications';
-$string['courseid'] = 'Course id number';
-$string['coursemisconf'] = 'Course is misconfigured';
-$string['curllibrarymissing'] = 'PHP Curl library must be installed to use LTI';
-$string['custom'] = 'Custom parameters';
-$string['custominstr'] = 'Custom parameters';
-$string['debuglaunch'] = 'Debug Option';
-$string['debuglaunchoff'] = 'Normal launch';
-$string['debuglaunchon'] = 'Debug launch';
-$string['delegate'] = 'Delegate to Professor';
-$string['donot'] = 'Do not send';
-$string['donotaccept'] = 'Do not accept';
-$string['donotallow'] = 'Do not allow';
-$string['enableemailnotification'] = 'Send notification emails';
-$string['enableemailnotification_help'] = 'If enabled, students will receive email notification when their tool submissions are graded.';
-$string['errormisconfig'] = 'Misconfigured tool. Please ask your Moodle administrator to fix the configuration of the tool.';
-$string['extensions'] = 'Basic LTI Extension Services';
-$string['failedtoconnect'] = 'Moodle was unable to communicate with the \"$a\" system';
-$string['filterconfig'] = 'Basic LTI administration';
-$string['filtername'] = 'Basic LTI';
-$string['filter_basiclti_configlink'] = 'Configure your preferred sites and their passwords';
-$string['filter_basiclti_password'] = 'Password is mandatory';
-$string['fixexistingconf'] = 'Use an existing configuration for the misconfigured instance';
-$string['fixnew'] = 'New Configuration';
-$string['fixnewconf'] = 'Define a new configuration for the misconfigured instance';
-$string['fixold'] = 'Use Existing';
-$string['grading'] = 'Grade Routing';
-$string['id'] = 'id';
-$string['imsroleadmin'] = 'Instructor,Administrator';
-$string['imsroleinstructor'] = 'Instructor';
-$string['imsrolelearner'] = 'Learner';
-$string['invalidid'] = 'basic LTI ID was incorrect';
-$string['launch_in_moodle'] = 'Launch tool in moodle';
-$string['launch_in_popup'] = 'Launch tool in a pop-up';
-$string['launchinpopup'] = 'Launch Container';
-$string['launchoptions'] = 'Launch Options';
-$string['lti_errormsg'] = 'The tool returned the following error message: \"$a\"';
-$string['misconfiguredtools'] = 'Misconfigured tool instances were detected';
-$string['missingparameterserror'] = 'The page is misconfigured: \"$a\"';
-$string['module_class_type'] = 'Moodle module type';
-$string['modulename'] = 'External Tool';
-$string['modulenameplural'] = 'basicltis';
-$string['modulenamepluralformatted'] = 'Basic LTI Instances';
-$string['never'] = 'Never';
-$string['noattempts'] = 'No attempts have been made on this tool instance';
-$string['noservers'] = 'No servers found';
-$string['notypes'] = 'There are currently no LTI tools setup in Moodle. Click the Install link above to add some.';
-$string['noviewusers'] = 'No users were found with permissions to use this tool';
-$string['optionalsettings'] = 'Optional settings';
-$string['organization'] ='Organization details';
-$string['organizationdescr'] ='Organization Description';
-$string['organizationid'] ='Organization ID';
-$string['organizationurl'] ='Organization URL';
-$string['pagesize'] = 'Submissions shown per page';
-$string['password'] = 'Shared Secret';
-$string['pluginadministration'] = 'Basic LTI administration';
-$string['pluginname'] = 'LTI';
-$string['preferheight'] = 'Preferred Height';
-$string['preferwidget'] = 'Prefer Widget Launch';
-$string['preferwidth'] = 'Preferred Width';
-$string['press_to_submit'] = 'Press to launch this activity';
-$string['privacy'] = 'Privacy';
-$string['quickgrade'] = 'Allow quick grading';
-$string['quickgrade_help'] = 'If enabled, multiple tools can be graded on one page. Add grades and comments then click the "Save all my feedback" button to save all changes for that page.';
-$string['redirect'] = 'You will be redirected in few seconds. If you are not, press the button.';
-$string['resource'] = 'Resource';
-$string['resourcekey'] = 'Consumer Key';
-$string['resourceurl'] = 'Resource URL';
-$string['saveallfeedback'] = 'Save all my feedback';
-$string['send'] = 'Send';
-$string['sendemailaddr'] = 'Share launcher\'s email with tool';
-$string['sendname'] = 'Share launcher\'s name with tool';
-$string['setdefault'] = 'Set a default value for the professor if delegating';
-$string['setupbox'] = 'Basic LTI Tool Setup Box';
-$string['setupoptions'] = 'Setup Options';
-$string['size'] = 'Size parameters';
-$string['submission'] = 'Submission';
-$string['toggle_debug_data'] = 'Toggle Debug Data';
-$string['toolsetup'] = 'Basic LTI Tool Setup';
-$string['toolurl'] = 'Tool Base URL';
-$string['typename'] = 'Tool Name';
-$string['types'] = 'Types';
-$string['validurl'] = 'A valid URL must start with http(s)://';
-$string['viewsubmissions'] = 'View submissions and grading screen';
-
-//New admin strings
-
-$string['show_in_course'] = 'Show tool type when creating tool instances';
-$string['delegate_yes'] = 'Delegate to Instructor (Default: Yes)';
-$string['delegate_no'] = 'Delegate to Instructor (Default: No)';
-$string['tool_settings'] = 'Tool Settings';
-$string['miscellaneous'] = 'Miscellaneous';
-$string['embed'] = 'Embed';
-$string['embed_no_blocks'] = 'Embed, without blocks';
-$string['new_window'] = 'New window';
-$string['default_launch_container'] = 'Default Launch Container';
-$string['active'] = 'Active';
-$string['pending'] = 'Pending';
-$string['rejected'] = 'Rejected';
-$string['baseurl'] = 'Base URL';
-$string['action'] = 'Action';
-$string['createdon'] = 'Created On';
-$string['accept'] = 'Accept';
-$string['update'] = 'Update';
-$string['delete'] = 'Delete';
-$string['reject'] = 'Reject';
-$string['external_tool_types'] = 'External Tool Types';
-$string['no_lti_configured'] = 'There are no active External Tools configured.';
-$string['no_lti_pending'] = 'There are no pending External Tools.';
-$string['no_lti_rejected'] = 'There are no rejected External Tools.';
-
-//New instructor strings
-$string['display_name'] = 'Display activity name when launched';
-$string['display_description'] = 'Display activity description when launched';
-$string['external_tool_type'] = 'External tool type';
-$string['launch_url'] = 'Launch URL';
-$string['share_name'] = 'Share launcher\'s name with the tool';
-$string['share_email'] = 'Share launcher\'s email with the tool';
-$string['accept_grades'] = 'Accept grades from the tool';
-$string['share_roster'] = 'Allow the tool to access this course\'s roster';
-$string['automatic'] = 'Automatic, based on Launch URL';
-$string['default'] = 'Default';
+<?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
+ * marc.alier@upc.edu
+ * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
+ *
+ * @author Marc Alier
+ * @author Jordi Piguillem
+ * @author Nikolas Galanis
+ *
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$string['accept'] = 'Accept';
+$string['acceptgrades'] = 'Accept grades from tool';
+$string['activity'] = 'Activity';
+$string['addnewapp'] = 'Enable External Application';
+$string['addserver'] = 'Add new trusted server';
+$string['addtype'] = 'Add External Tool Configuration';
+$string['allow'] = 'Allow';
+$string['allowinstructorcustom'] = 'Allow instructors to add custom parameters';
+$string['allowroster'] = 'Tool may access course roster';
+$string['allowsetting'] = 'Allow tool to store 8K of settings in Moodle';
+$string['always'] = 'Always';
+$string['lti'] = 'Basic LTI';
+$string['basiclti'] = 'Basic LTI';
+$string['basiclti_base_string'] = 'Basic LTI OAuth Base String';
+$string['basiclti_in_new_window'] = 'Your activity has opened in a new window';
+$string['basiclti_endpoint'] = 'Basic LTI Launch Endpoint';
+$string['basiclti_parameters'] = 'Basic LTI Launch Parameters';
+$string['basicltiactivities'] = 'Basic LTI Activities';
+$string['basicltifieldset'] = 'Custom example fieldset';
+$string['basicltiintro'] = 'Activity Description';
+$string['basicltiname'] = 'Activity Name';
+$string['basicltisettings'] = 'Basic Learning Tool Interoperability Settings';
+$string['comment'] = 'Comment';
+$string['configpassword'] = 'Default Remote Tool Password';
+$string['configpreferheight'] = 'Default preferred height';
+$string['configpreferwidget'] = 'Set widget as default launch';
+$string['configpreferwidth'] = 'Default preferred width';
+$string['configresourceurl'] = 'Default Resource URL';
+$string['configtoolurl'] = 'Default Remote Tool URL';
+$string['configtypes'] = 'Enable Basic LTI Applications';
+$string['courseid'] = 'Course id number';
+$string['coursemisconf'] = 'Course is misconfigured';
+$string['curllibrarymissing'] = 'PHP Curl library must be installed to use LTI';
+$string['custom'] = 'Custom parameters';
+$string['custominstr'] = 'Custom parameters';
+$string['debuglaunch'] = 'Debug Option';
+$string['debuglaunchoff'] = 'Normal launch';
+$string['debuglaunchon'] = 'Debug launch';
+$string['donot'] = 'Do not send';
+$string['donotaccept'] = 'Do not accept';
+$string['donotallow'] = 'Do not allow';
+$string['enableemailnotification'] = 'Send notification emails';
+$string['enableemailnotification_help'] = 'If enabled, students will receive email notification when their tool submissions are graded.';
+$string['errormisconfig'] = 'Misconfigured tool. Please ask your Moodle administrator to fix the configuration of the tool.';
+$string['extensions'] = 'Basic LTI Extension Services';
+$string['failedtoconnect'] = 'Moodle was unable to communicate with the \"$a\" system';
+$string['filterconfig'] = 'Basic LTI administration';
+$string['filtername'] = 'Basic LTI';
+$string['filter_basiclti_configlink'] = 'Configure your preferred sites and their passwords';
+$string['filter_basiclti_password'] = 'Password is mandatory';
+$string['fixexistingconf'] = 'Use an existing configuration for the misconfigured instance';
+$string['fixnew'] = 'New Configuration';
+$string['fixnewconf'] = 'Define a new configuration for the misconfigured instance';
+$string['fixold'] = 'Use Existing';
+$string['grading'] = 'Grade Routing';
+$string['id'] = 'id';
+$string['imsroleadmin'] = 'Instructor,Administrator';
+$string['imsroleinstructor'] = 'Instructor';
+$string['imsrolelearner'] = 'Learner';
+$string['invalidid'] = 'basic LTI ID was incorrect';
+$string['launch_in_moodle'] = 'Launch tool in moodle';
+$string['launch_in_popup'] = 'Launch tool in a pop-up';
+$string['launchinpopup'] = 'Launch Container';
+$string['launchoptions'] = 'Launch Options';
+$string['lti_errormsg'] = 'The tool returned the following error message: \"$a\"';
+$string['misconfiguredtools'] = 'Misconfigured tool instances were detected';
+$string['missingparameterserror'] = 'The page is misconfigured: \"$a\"';
+$string['module_class_type'] = 'Moodle module type';
+$string['modulename'] = 'External Tool';
+$string['modulenameplural'] = 'basicltis';
+$string['modulenamepluralformatted'] = 'Basic LTI Instances';
+$string['never'] = 'Never';
+$string['noattempts'] = 'No attempts have been made on this tool instance';
+$string['noservers'] = 'No servers found';
+$string['notypes'] = 'There are currently no LTI tools setup in Moodle. Click the Install link above to add some.';
+$string['noviewusers'] = 'No users were found with permissions to use this tool';
+$string['optionalsettings'] = 'Optional settings';
+$string['organization'] ='Organization details';
+$string['organizationdescr'] ='Organization Description';
+$string['organizationid'] ='Organization ID';
+$string['organizationurl'] ='Organization URL';
+$string['pagesize'] = 'Submissions shown per page';
+$string['password'] = 'Shared Secret';
+$string['pluginadministration'] = 'Basic LTI administration';
+$string['pluginname'] = 'LTI';
+$string['preferheight'] = 'Preferred Height';
+$string['preferwidget'] = 'Prefer Widget Launch';
+$string['preferwidth'] = 'Preferred Width';
+$string['press_to_submit'] = 'Press to launch this activity';
+$string['privacy'] = 'Privacy';
+$string['quickgrade'] = 'Allow quick grading';
+$string['quickgrade_help'] = 'If enabled, multiple tools can be graded on one page. Add grades and comments then click the "Save all my feedback" button to save all changes for that page.';
+$string['redirect'] = 'You will be redirected in few seconds. If you are not, press the button.';
+$string['resource'] = 'Resource';
+$string['resourcekey'] = 'Consumer Key';
+$string['resourceurl'] = 'Resource URL';
+$string['saveallfeedback'] = 'Save all my feedback';
+$string['send'] = 'Send';
+$string['sendemailaddr'] = 'Share launcher\'s email with tool';
+$string['sendname'] = 'Share launcher\'s name with tool';
+$string['setdefault'] = 'Set a default value for the professor if delegating';
+$string['setupbox'] = 'Basic LTI Tool Setup Box';
+$string['setupoptions'] = 'Setup Options';
+$string['size'] = 'Size parameters';
+$string['submission'] = 'Submission';
+$string['toggle_debug_data'] = 'Toggle Debug Data';
+$string['toolsetup'] = 'External Tool Configuration';
+$string['toolurl'] = 'Tool Base URL';
+$string['typename'] = 'Tool Name';
+$string['types'] = 'Types';
+$string['validurl'] = 'A valid URL must start with http(s)://';
+$string['viewsubmissions'] = 'View submissions and grading screen';
+
+//New admin strings
+
+$string['show_in_course'] = 'Show tool type when creating tool instances';
+$string['delegate'] = 'Delegate to Instructor';
+$string['tool_settings'] = 'Tool Settings';
+$string['miscellaneous'] = 'Miscellaneous';
+$string['embed'] = 'Embed';
+$string['embed_no_blocks'] = 'Embed, without blocks';
+$string['new_window'] = 'New window';
+$string['default_launch_container'] = 'Default Launch Container';
+$string['active'] = 'Active';
+$string['pending'] = 'Pending';
+$string['rejected'] = 'Rejected';
+$string['baseurl'] = 'Base URL';
+$string['action'] = 'Action';
+$string['createdon'] = 'Created On';
+$string['accept'] = 'Accept';
+$string['update'] = 'Update';
+$string['delete'] = 'Delete';
+$string['reject'] = 'Reject';
+$string['external_tool_types'] = 'External Tool Types';
+$string['no_lti_configured'] = 'There are no active External Tools configured.';
+$string['no_lti_pending'] = 'There are no pending External Tools.';
+$string['no_lti_rejected'] = 'There are no rejected External Tools.';
+
+//New instructor strings
+$string['display_name'] = 'Display activity name when launched';
+$string['display_description'] = 'Display activity description when launched';
+$string['external_tool_type'] = 'External tool type';
+$string['launch_url'] = 'Launch URL';
+$string['share_name'] = 'Share launcher\'s name with the tool';
+$string['share_email'] = 'Share launcher\'s email with the tool';
+$string['accept_grades'] = 'Accept grades from the tool';
+$string['share_roster'] = 'Allow the tool to access this course\'s roster';
+$string['automatic'] = 'Automatic, based on Launch URL';
+$string['default'] = 'Default';
View
62 mod/lti/locallib.php
@@ -129,6 +129,23 @@ function lti_view($instance, $makeobject=false) {
echo $content;
}
+function lti_build_sourcedid($instanceid, $userid, $servicesalt){
+ $data = new stdClass();
+
+ $data->instanceid = $instanceid;
+ $data->userid = $userid;
+
+ $json = json_encode($data);
+
+ $hash = hash('sha256', $json . $servicesalt, false);
+
+ $container = new stdClass();
+ $container->data = $data;
+ $container->hash = $hash;
+
+ return $container;
+}
+
/**
* This function builds the request that must be sent to the tool producer
*
@@ -168,20 +185,7 @@ function lti_build_request($instance, $typeconfig, $course) {
$placementsecret = $instance->servicesalt;
if ( isset($placementsecret) ) {
- $data = new stdClass();
-
- $data->instanceid = $instance->id;
- $data->userid = $USER->id;
-
- $json = json_encode($data);
-
- $hash = hash('sha256', $json . $placementsecret, false);
-
- $container = new stdClass();
- $container->data = $data;
- $container->hash = $hash;
-
- $sourcedid = json_encode($container);
+ $sourcedid = json_encode(lti_build_sourcedid($instance->id, $USER->id, $placementsecret));
}
if ( isset($placementsecret) &&
@@ -338,10 +342,10 @@ function lti_get_type_config($typeid) {
return $typeconfig;
}
-function lti_get_tools_by_url($url, $state){
+function lti_get_tools_by_url($url, $state, $courseid = null){
$domain = lti_get_domain_from_url($url);
- return lti_get_tools_by_domain($domain, $state);
+ return lti_get_tools_by_domain($domain, $state, $courseid);
}
function lti_get_tools_by_domain($domain, $state = null, $courseid = null){
@@ -387,14 +391,23 @@ function lti_filter_get_types() {
}
function lti_get_types_for_add_instance(){
- global $DB;
- $admintypes = $DB->get_records('lti_types', array('coursevisible' => 1));
+ global $DB, $SITE, $COURSE;
+
+ $query = <<<QUERY
+ SELECT *
+ FROM {lti_types}
+ WHERE
+ coursevisible = 1
+ AND (course = :siteid OR course = :courseid)
+QUERY;
+
+ $admintypes = $DB->get_records_sql($query, array('siteid' => $SITE->id, 'courseid' => $COURSE->id));
$types = array();
- $types[0] = get_string('automatic', 'lti');
+ $types[0] = (object)array('name' => get_string('automatic', 'lti'), 'course' => $SITE->id);
foreach($admintypes as $type) {
- $types[$type->id] = $type->name;
+ $types[$type->id] = (object)array('name' => $type->name, 'course' => $type->course);
}
return $types;
@@ -409,7 +422,7 @@ function lti_get_domain_from_url($url){
}
function lti_get_tool_by_url_match($url, $courseid = null, $state = LTI_TOOL_STATE_CONFIGURED){
- $possibletools = lti_get_tools_by_url($url, $state, $courseid);
+ $possibletools = lti_get_tools_by_url($url, $courseid, $state);
return lti_get_best_tool_by_url($url, $possibletools);
}
@@ -729,6 +742,8 @@ function lti_add_type($type, $config){
}
}
}
+
+ return $id;
}
/**
@@ -923,3 +938,8 @@ function lti_submittedlink($cm, $allgroups=false) {
return $submitted;
}
+function lti_get_type($typeid){
+ global $DB;
+
+ return $DB->get_record('lti_types', array('id' => $typeid));
+}
View
124 mod/lti/mod_form.js
@@ -0,0 +1,124 @@
+M.mod_lti = M.mod_lti || {};
+
+M.mod_lti.editor = {
+ init: function(Y, settings){
+ this.Y = Y;
+ var self = this;
+ this.settings = Y.JSON.parse(settings);
+
+ var typeSelector = Y.one('#id_typeid');
+ typeSelector.on('change', function(e){
+ self.toggleEditButtons();
+ });
+
+ this.createTypeEditorButtons();
+
+ this.toggleEditButtons();
+ },
+
+ getSelectedToolTypeOption: function(){
+ var Y = this.Y;
+ var typeSelector = Y.one('#id_typeid');
+
+ return typeSelector.one('option[value=' + typeSelector.get('value') + ']');
+ },
+
+ /**
+ * Adds buttons for creating, editing, and deleting tool types
+ */
+ createTypeEditorButtons: function(){
+ var Y = this.Y;
+ var self = this;
+
+ var typeSelector = Y.one('#id_typeid');
+
+ var createIcon = function(id, tooltip, iconUrl){
+ return Y.Node.create('<a />')
+ .set('id', id)
+ .set('title', tooltip)
+ .setStyle('margin-left', '.5em')
+ .set('href', 'javascript:void(0);')
+ .append(Y.Node.create('<img src="' + iconUrl + '" />'));
+ }
+
+ var addIcon = createIcon('lti_add_tool_type', 'Add new tool type', this.settings.add_icon_url);
+ var editIcon = createIcon('lti_edit_tool_type', 'Edit new tool type', this.settings.edit_icon_url);
+ var deleteIcon = createIcon('lti_delete_tool_type', 'Delete tool type', this.settings.delete_icon_url);
+
+ editIcon.on('click', function(e){
+ var toolTypeId = typeSelector.get('value');
+
+ if(self.getSelectedToolTypeOption().getAttribute('editable')){
+ window.open(self.settings.instructor_tool_type_edit_url + '&action=edit&typeid=' + toolTypeId, 'edit_tool');
+ }
+ });
+
+ addIcon.on('click', function(e){
+ window.open(self.settings.instructor_tool_type_edit_url + '&action=add', 'add_tool');
+ });
+
+ deleteIcon.on('click', function(e){
+ var toolTypeId = typeSelector.get('value');
+
+ if(self.getSelectedToolTypeOption().getAttribute('editable')){
+ Y.io(self.settings.instructor_tool_type_edit_url + '&action=delete&typeid=' + toolTypeId, {
+ on: {
+ success: function(){
+ getSelectedOption().remove();
+ },
+ failure: function(){
+
+ }
+ }
+ });
+ }
+ });
+
+ typeSelector.insert(addIcon, 'after');
+ addIcon.insert(editIcon, 'after');
+ editIcon.insert(deleteIcon, 'after');
+ },
+
+ toggleEditButtons: function(){
+ var Y = this.Y;
+
+ var lti_edit_tool_type = Y.one('#lti_edit_tool_type');
+ var lti_delete_tool_type = Y.one('#lti_delete_tool_type');
+
+ if(this.getSelectedToolTypeOption().getAttribute('editable')){
+ lti_edit_tool_type.setStyle('opacity', '1');
+ lti_delete_tool_type.setStyle('opacity', '1');
+ } else {
+ lti_edit_tool_type.setStyle('opacity', '.2');
+ lti_delete_tool_type.setStyle('opacity', '.2');
+ }
+ },
+
+ addToolType: function(text, value){
+ var Y = this.Y;
+ var typeSelector = Y.one('#id_typeid');
+
+ var option = Y.Node.create('<option />')
+ .set('text', text)
+ .set('value', value)
+ .set('selected', 'selected');
+
+ typeSelector.append(option);
+ },
+
+ updateToolType: function(text, value){
+ var Y = this.Y;
+ var typeSelector = Y.one('#id_typeid');
+
+ var option = Y.Node.create('<option />')
+ .set('text', text)
+ .set('value', value)
+ .set('selected', 'selected');
+
+ typeSelector.append(option);
+ }
+
+};
+
+
+
View
615 mod/lti/mod_form.php
@@ -1,416 +1,199 @@
-<?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 lti
- * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
- * marc.alier@upc.edu
- * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
- *
- * @author Marc Alier
- * @author Jordi Piguillem
- * @author Nikolas Galanis
- *
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die;
-
-require_once($CFG->dirroot.'/course/moodleform_mod.php');
-require_once($CFG->dirroot.'/mod/lti/locallib.php');
-
-class mod_lti_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('lti', array('id' => $this->_instance));
- $this->typeid = $basiclti->typeid;
-
- $typeconfig = lti_get_config($basiclti);
- $this->typeconfig = $typeconfig;
-
- } else { // New not pre-configured instance
- $this->typeid = 0;
- }
- } else {
- // New pre-configured instance
- $basicltitype = $DB->get_record('lti_types', array('rawname' => $typename));
- $this->typeid = $basicltitype->id;
-
- $typeconfig = lti_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', 'lti'), array('size'=>'64'));
- $mform->setType('name', PARAM_TEXT);
- $mform->addRule('name', null, 'required', null, 'client');
- /// Adding the optional "intro" and "introformat" pair of fields
- $this->add_intro_editor(false, get_string('basicltiintro', 'lti'));
- $mform->setAdvanced('introeditor');
-
- $mform->addElement('checkbox', 'showtitle', '&nbsp;', ' ' . get_string('display_name', 'lti'));
- $mform->setAdvanced('showtitle');
-
- $mform->addElement('checkbox', 'showdescription', '&nbsp;', ' ' . get_string('display_description', 'lti'));
- $mform->setAdvanced('showdescription');
-
- //Tool settings
- $mform->addElement('select', 'typeid', get_string('external_tool_type', 'lti'), lti_get_types_for_add_instance());
- //$mform->setDefault('typeid', '0');
-
- $mform->addElement('text', 'toolurl', get_string('launch_url', 'lti'), array('size'=>'64'));
- $mform->setType('toolurl', PARAM_TEXT);
-
- $launchoptions=array();
- $launchoptions[LTI_LAUNCH_CONTAINER_DEFAULT] = get_string('default', 'lti');
- $launchoptions[LTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'lti');
- $launchoptions[LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'lti');
- $launchoptions[LTI_LAUNCH_CONTAINER_WINDOW] = get_string('new_window', 'lti');
-
- $mform->addElement('select', 'launchcontainer', get_string('launchinpopup', 'lti'), $launchoptions);
- $mform->setDefault('launchcontainer', LTI_LAUNCH_CONTAINER_DEFAULT);
-
- $mform->addElement('text', 'resourcekey', get_string('resourcekey', 'lti'));
- $mform->setType('resourcekey', PARAM_TEXT);
- $mform->setAdvanced('resourcekey');
-
- $mform->addElement('passwordunmask', 'password', get_string('password', 'lti'));
- $mform->setType('password', PARAM_TEXT);
- $mform->setAdvanced('password');
-
- $mform->addElement('textarea', 'instructorcustomparameters', get_string('custom', 'lti'), array('rows'=>4, 'cols'=>60));
- $mform->setType('instructorcustomparameters', PARAM_TEXT);
- $mform->setAdvanced('instructorcustomparameters');
-
-//-------------------------------------------------------------------------------
- //$mform->addElement('hidden', 'typeid', $this->typeid);
- //$mform->addElement('hidden', 'toolurl', $this->typeconfig['toolurl']);
- $mform->addElement('hidden', 'type', $typename);
-
-//-------------------------------------------------------------------------------
- // Add privacy preferences fieldset where users choose whether to send their data
- $mform->addElement('header', 'privacy', get_string('privacy', 'lti'));
-
- $mform->addElement('checkbox', 'instructorchoicesendname', '&nbsp;', ' ' . get_string('share_name', 'lti'));
- $mform->setDefault('instructorchoicesendname', '1');
-
- $mform->addElement('checkbox', 'instructorchoicesendemailaddr', '&nbsp;', ' ' . get_string('share_email', 'lti'));
- $mform->setDefault('instructorchoicesendemailaddr', '1');
-
- $mform->addElement('checkbox', 'instructorchoiceacceptgrades', '&nbsp;', ' ' . get_string('accept_grades', 'lti'));
- $mform->setDefault('instructorchoiceacceptgrades', '1');
-
- $mform->addElement('checkbox', 'instructorchoiceallowroster', '&nbsp;', ' ' . get_string('share_roster', 'lti'));
- $mform->setDefault('instructorchoiceallowroster', '1');
-
-//-------------------------------------------------------------------------------
-
-/* $debugoptions=array();
- $debugoptions[0] = get_string('debuglaunchoff', 'lti');
- $debugoptions[1] = get_string('debuglaunchon', 'lti');
-
- $mform->addElement('select', 'debuglaunch', get_string('debuglaunch', 'lti'), $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');
- }
- }
-*/
-
-//-------------------------------------------------------------------------------
- // add standard elements, common to all modules
- $this->standard_coursemodule_elements();
-
- $mform->setAdvanced('cmidnumber');
-//-------------------------------------------------------------------------------
- // add standard buttons, common to all modules
- $this->add_action_buttons();
- }
-
- /**
- * 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 = lti_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->lti_toolurl)) {
- $default_values['toolurl'] = $CFG->lti_toolurl;
- }
- }
-
- if (!isset($default_values['resourcekey'])) {
- if (isset($this->typeconfig['resourcekey'])) {
- $default_values['resourcekey'] = $this->typeconfig['resourcekey'];
- } else if (isset($CFG->lti_resourcekey)) {
- $default_values['resourcekey'] = $CFG->lti_resourcekey;
- }
- }
-
- if (!isset($default_values['password'])) {
- if (isset($this->typeconfig['password'])) {
- $default_values['password'] = $this->typeconfig['password'];
- } else if (isset($CFG->lti_password)) {
- $default_values['password'] = $CFG->lti_password;
- }
- }
-
- if (!isset($default_values['preferheight'])) {
- if (isset($this->typeconfig['preferheight'])) {
- $default_values['preferheight'] = $this->typeconfig['preferheight'];
- } else if (isset($CFG->lti_preferheight)) {
- $default_values['preferheight'] = $CFG->lti_preferheight;
- }
- }
-
- if (!isset($default_values['sendname'])) {
- if (isset($this->typeconfig['sendname'])) {
- $default_values['sendname'] = $this->typeconfig['sendname'];
- } else if (isset($CFG->lti_sendname)) {
- $default_values['sendname'] = $CFG->lti_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->lti_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->lti_sendemailaddr)) {
- $default_values['sendemailaddr'] = $CFG->lti_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->lti_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->lti_acceptgrades)) {
- $default_values['acceptgrades'] = $CFG->lti_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->lti_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->lti_allowroster)) {
- $default_values['allowroster'] = $CFG->lti_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->lti_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->lti_allowsetting)) {
- $default_values['allowsetting'] = $CFG->lti_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->lti_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->lti_customparameters)) {
- $default_values['customparameters'] = $CFG->lti_customparameters;
- }
- }
-
- if (!isset($default_values['allowinstructorcustom'])) {
- if (isset($this->typeconfig['allowinstructorcustom'])) {
- $default_values['allowinstructorcustom'] = $this->typeconfig['allowinstructorcustom'];
- } else if (isset($CFG->lti_allowinstructorcustom)) {
- $default_values['allowinstructorcustom'] = $CFG->lti_allowinstructorcustom;
- }
- }
-
- if (!isset($default_values['organizationid'])) {
- if (isset($this->typeconfig['organizationid'])) {
- $default_values['organizationid'] = $this->typeconfig['organizationid'];
- } else if (isset($CFG->lti_organizationid)) {
- $default_values['organizationid'] = $CFG->lti_organizationid;
- }
- }
-
- if (!isset($default_values['organizationurl'])) {
- if (isset($this->typeconfig['organizationurl'])) {
- $default_values['organizationurl'] = $this->typeconfig['organizationurl'];
- } else if (isset($CFG->lti_organizationurl)) {
- $default_values['organizationurl'] = $CFG->lti_organizationurl;
- }
- }
-
- if (!isset($default_values['organizationdescr'])) {
- if (isset($this->typeconfig['organizationdescr'])) {
- $default_values['organizationdescr'] = $this->typeconfig['organizationdescr'];
- } else if (isset($CFG->lti_organizationdescr)) {
- $default_values['organizationdescr'] = $CFG->lti_organizationdescr;
- }
- }
-
- if (!isset($default_values['launchinpopup'])) {
- if (isset($this->typeconfig['launchinpopup'])) {
- $default_values['launchinpopup'] = $this->typeconfig['launchinpopup'];
- } else if (isset($CFG->lti_launchinpopup)) {
- $default_values['launchinpopup'] = $CFG->lti_launchinpopup;
- }
- }
-*/
- }
-}
-
+<?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 lti
+ * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
+ * marc.alier@upc.edu
+ * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
+ *
+ * @author Marc Alier
+ * @author Jordi Piguillem
+ * @author Nikolas Galanis
+ *
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+require_once($CFG->dirroot.'/course/moodleform_mod.php');
+require_once($CFG->dirroot.'/mod/lti/locallib.php');
+
+class mod_lti_mod_form extends moodleform_mod {
+
+ function definition() {
+ global $DB, $PAGE, $OUTPUT, $USER, $COURSE;
+
+ $this->typeid = 0;
+
+ $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', 'lti'), array('size'=>'64'));
+ $mform->setType('name', PARAM_TEXT);
+ $mform->addRule('name', null, 'required', null, 'client');
+ /// Adding the optional "intro" and "introformat" pair of fields
+ $this->add_intro_editor(false, get_string('basicltiintro', 'lti'));
+ $mform->setAdvanced('introeditor');
+
+ $mform->addElement('checkbox', 'showtitle', '&nbsp;', ' ' . get_string('display_name', 'lti'));
+ $mform->setAdvanced('showtitle');
+
+ $mform->addElement('checkbox', 'showdescription', '&nbsp;', ' ' . get_string('display_description', 'lti'));
+ $mform->setAdvanced('showdescription');
+
+ //Tool settings
+ $tooltypes = $mform->addElement('select', 'typeid', get_string('external_tool_type', 'lti'), array());
+
+ foreach(lti_get_types_for_add_instance() as $id => $type){
+ if($type->course == $COURSE->id) {
+ $attributes = array( 'editable' => 1 );
+ } else {
+ $attributes = array();
+ }
+
+ $tooltypes->addOption($type->name, $id, $attributes);
+ }
+
+ $mform->addElement('text', 'toolurl', get_string('launch_url', 'lti'), array('size'=>'64'));
+ $mform->setType('toolurl', PARAM_TEXT);
+
+ $launchoptions=array();
+ $launchoptions[LTI_LAUNCH_CONTAINER_DEFAULT] = get_string('default', 'lti');
+ $launchoptions[LTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'lti');
+ $launchoptions[LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'lti');
+ $launchoptions[LTI_LAUNCH_CONTAINER_WINDOW] = get_string('new_window', 'lti');
+
+ $mform->addElement('select', 'launchcontainer', get_string('launchinpopup', 'lti'), $launchoptions);
+ $mform->setDefault('launchcontainer', LTI_LAUNCH_CONTAINER_DEFAULT);
+
+ $mform->addElement('text', 'resourcekey', get_string('resourcekey', 'lti'));
+ $mform->setType('resourcekey', PARAM_TEXT);
+ $mform->setAdvanced('resourcekey');
+
+ $mform->addElement('passwordunmask', 'password', get_string('password', 'lti'));
+ $mform->setType('password', PARAM_TEXT);
+ $mform->setAdvanced('password');
+
+ $mform->addElement('textarea', 'instructorcustomparameters', get_string('custom', 'lti'), array('rows'=>4, 'cols'=>60));
+ $mform->setType('instructorcustomparameters', PARAM_TEXT);
+ $mform->setAdvanced('instructorcustomparameters');
+
+//-------------------------------------------------------------------------------
+ //$mform->addElement('hidden', 'typeid', $this->typeid);
+ //$mform->addElement('hidden', 'toolurl', $this->typeconfig['toolurl']);
+ //$mform->addElement('hidden', 'type', $typename);
+
+//-------------------------------------------------------------------------------
+ // Add privacy preferences fieldset where users choose whether to send their data
+ $mform->addElement('header', 'privacy', get_string('privacy', 'lti'));
+
+ $mform->addElement('checkbox', 'instructorchoicesendname', '&nbsp;', ' ' . get_string('share_name', 'lti'));
+ $mform->setDefault('instructorchoicesendname', '1');
+
+ $mform->addElement('checkbox', 'instructorchoicesendemailaddr', '&nbsp;', ' ' . get_string('share_email', 'lti'));
+ $mform->setDefault('instructorchoicesendemailaddr', '1');
+
+ $mform->addElement('checkbox', 'instructorchoiceacceptgrades', '&nbsp;', ' ' . get_string('accept_grades', 'lti'));
+ $mform->setDefault('instructorchoiceacceptgrades', '1');
+
+ $mform->addElement('checkbox', 'instructorchoiceallowroster', '&nbsp;', ' ' . get_string('share_roster', 'lti'));
+ $mform->setDefault('instructorchoiceallowroster', '1');
+
+//-------------------------------------------------------------------------------
+
+/* $debugoptions=array();
+ $debugoptions[0] = get_string('debuglaunchoff', 'lti');
+ $debugoptions[1] = get_string('debuglaunchon', 'lti');
+
+ $mform->addElement('select', 'debuglaunch', get_string('debuglaunch', 'lti'), $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');
+ }
+ }
+*/
+
+//-------------------------------------------------------------------------------
+ // add standard elements, common to all modules
+ $this->standard_coursemodule_elements();
+
+ $mform->setAdvanced('cmidnumber');
+//-------------------------------------------------------------------------------
+ // add standard buttons, common to all modules
+ $this->add_action_buttons();
+
+ $url = new moodle_url("/mod/lti/instructor_edit_tool_type.php?sesskey={$USER->sesskey}&course={$COURSE->id}");
+ $jsinfo = (object)array(
+ 'edit_icon_url' => (string)$OUTPUT->pix_url('t/edit'),
+ 'add_icon_url' => (string)$OUTPUT->pix_url('t/add'),
+ 'delete_icon_url' => (string)$OUTPUT->pix_url('t/delete'),
+ 'instructor_tool_type_edit_url' => $url->out(false)
+ );
+
+ $module = array(
+ 'name' => 'mod_lti_edit',
+ 'fullpath' => '/mod/lti/mod_form.js',
+ 'requires' => array('base', 'io', 'node', 'event', 'json-parse'),
+ 'strings' => array(),
+ );
+
+ $PAGE->requires->js_init_call('M.mod_lti.editor.init', array(json_encode($jsinfo)), true, $module);
+ }
+
+ /**
+ * 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();
+
+ }
+
+ /**
+ * Function overwritten to change default values using
+ * global configuration
+ *
+ * @param array $default_values passed by reference
+ */
+ function data_preprocessing(&$default_values) {
+
+ }
+}
+
View
167 mod/lti/service.php
@@ -1,154 +1,10 @@
<?php
-require_once("../../config.php");
-require_once($CFG->dirroot.'/mod/lti/OAuthBody.php');
+require_once(dirname(__FILE__) . "/../../config.php");
require_once($CFG->dirroot.'/mod/lti/locallib.php');
+require_once($CFG->dirroot.'/mod/lti/servicelib.php');
-define('LTI_ITEM_TYPE', 'mod');
-define('LTI_ITEM_MODULE', 'lti');
-define('LTI_SOURCE', 'mod/lti');
-
-function lti_get_response_xml($codemajor, $description, $messageref, $messagetype){
- $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><imsx_POXEnvelopeResponse />');
- $xml->addAttribute('xmlns', 'http://www.imsglobal.org/lis/oms1p0/pox');
-
- $headerinfo = $xml->addChild('imsx_POXHeader')
- ->addChild('imsx_POXResponseHeaderInfo');
-
- $headerinfo->addChild('imsx_version', 'V1.0');
- $headerinfo->addChild('imsx_messageIdentifier', (string)mt_rand());
-
- $statusinfo = $headerinfo->addChild('imsx_statusInfo');
- $statusinfo->addchild('imsx_codeMajor', $codemajor);
- $statusinfo->addChild('imsx_severity', 'status');
- $statusinfo->addChild('imsx_description', $description);
- $statusinfo->addChild('imsx_messageRefIdentifier', $messageref);
-
- $xml->addChild('imsx_POXBody')
- ->addChild($messagetype);
-
- return $xml;
-}
-
-function lti_parse_message_id($xml){
- $node = $xml->imsx_POXHeader->imsx_POXRequestHeaderInfo->imsx_messageIdentifier;
- $messageid = (string)$node;
-
- return $messageid;
-}
-
-function lti_parse_grade_replace_message($xml){
- $node = $xml->imsx_POXBody->replaceResultRequest->resultRecord->sourcedGUID->sourcedId;
- $resultjson = json_decode((string)$node);
-
- $node = $xml->imsx_POXBody->replaceResultRequest->resultRecord->result->resultScore->textString;
- $grade = floatval((string)$node);
-
- $parsed = new stdClass();
- $parsed->gradeval = $grade * 100;
- $parsed->instanceid = $resultjson->data->instanceid;
- $parsed->userid = $resultjson->data->userid;
- $parsed->messageid = lti_parse_message_id($xml);
-
- return $parsed;
-}
-
-function lti_parse_grade_read_message($xml){
- $node = $xml->imsx_POXBody->readResultRequest->resultRecord->sourcedGUID->sourcedId;
- $resultjson = json_decode((string)$node);
-
- $parsed = new stdClass();
- $parsed->instanceid = $resultjson->data->instanceid;
- $parsed->userid = $resultjson->data->userid;
- $parsed->messageid = lti_parse_message_id($xml);
-
- return $parsed;
-}
-
-function lti_parse_grade_delete_message($xml){
- $node = $xml->imsx_POXBody->deleteResultRequest->resultRecord->sourcedGUID->sourcedId;
- $resultjson = json_decode((string)$node);
-
- $parsed = new stdClass();
- $parsed->instanceid = $resultjson->data->instanceid;
- $parsed->userid = $resultjson->data->userid;
- $parsed->messageid = lti_parse_message_id($xml);
-
- return $parsed;
-}
-
-function lti_update_grade($ltiinstance, $userid, $gradeval){
- global $CFG;
- require_once($CFG->libdir . '/gradelib.php');
-
- $params = array();
- $params['itemname'] = $ltiinstance->name;
-
- $grade = new stdClass();
- $grade->userid = $userid;
- $grade->rawgrade = $gradeval;
-
- $status = grade_update(LTI_SOURCE, $ltiinstance->course, LTI_ITEM_TYPE, LTI_ITEM_MODULE, $ltiinstance->id, 0, $grade, $params);
-
- return $status == GRADE_UPDATE_OK;
-}
-
-function lti_read_grade($ltiinstance, $userid){
- global $CFG;
- require_once($CFG->libdir . '/gradelib.php');
-
- $grades = grade_get_grades($ltiinstance->course, LTI_ITEM_TYPE, LTI_ITEM_MODULE, $ltiinstance->id, $userid);
-
- if (isset($grades) && is_array($grades->items[0]->grades)) {
- foreach ($grades->items[0]->grades as $agrade) {
- $grade = $agrade->grade;
- break;
- }
- }
-
- if(isset($grade)){
- return $grade;
- }
-}
-
-function lti_delete_grade($ltiinstance, $userid){
- $grade = new stdClass();
- $grade->userid = $userid;
- $grade->rawgrade = null;
-
- $status = grade_update(LTI_SOURCE, $ltiinstance->course, LTI_ITEM_TYPE, LTI_ITEM_MODULE, $ltiinstance->id, 0, $grade, array('deleted'=>1));
-
- return $status == GRADE_UPDATE_OK || $status == GRADE_UPDATE_ITEM_DELETED; //grade_update seems to return ok now, but could reasonably return deleted in the future
-}
-
-function lti_verify_message($ltiinstance){
- //Use the key / secret configured on the tool, or look it up from the admin config
- if(empty($ltiinstance->resourcekey) || empty($ltiinstance->password)){
- if($ltiinstance->typeid){
- $typeid = $ltiinstance->typeid;
- } else {
- $tool = lti_get_tool_by_url_match($ltiinstance->toolurl);
-
- if(!$tool){
- throw new Exception('Tool configuration not found for tool instance ' . $ltiinstance->id);
- }
-
- $typeid = $tool->id;
- }
-
- $typeconfig = lti_get_type_config($typeid);//Consider only fetching the 2 necessary settings here
-
- $key = $typeconfig['resourcekey'];
- $secret = $typeconfig['password'];
- } else {
- $key = $ltiinstance->resourcekey;
- $secret = $ltiinstance->password;
- }
-
- handleOAuthBodyPOST($key, $secret);
-}
-
-$xmlfragment = file_get_contents("php://input");
-$xml = new SimpleXMLElement($xmlfragment);
+$rawbody = file_get_contents("php://input");
+$xml = new SimpleXMLElement($rawbody);
$body = $xml->imsx_POXBody;
foreach($body->children() as $child){
@@ -161,7 +17,8 @@ function lti_verify_message($ltiinstance){
$ltiinstance = $DB->get_record('lti', array('id' => $parsed->instanceid));
- lti_verify_message($ltiinstance);
+ lti_verify_sourcedid($ltiinstance, $parsed);
+ lti_verify_message($ltiinstance, $rawbody);
$gradestatus = lti_update_grade($ltiinstance, $parsed->userid, $parsed->gradeval);
@@ -181,7 +38,8 @@ function lti_verify_message($ltiinstance){
$ltiinstance = $DB->get_record('lti', array('id' => $parsed->instanceid));
- lti_verify_message($ltiinstance);
+ lti_verify_sourcedid($ltiinstance, $parsed);
+ lti_verify_message($ltiinstance, $rawbody);
$grade = lti_read_grade($ltiinstance, $parsed->userid);
@@ -206,7 +64,8 @@ function lti_verify_message($ltiinstance){
$ltiinstance = $DB->get_record('lti', array('id' => $parsed->instanceid));
- lti_verify_message($ltiinstance);
+ lti_verify_sourcedid($ltiinstance, $parsed);
+ lti_verify_message($ltiinstance, $rawbody);
$gradestatus = lti_delete_grade($ltiinstance, $parsed->userid);
@@ -223,8 +82,8 @@ function lti_verify_message($ltiinstance){
}
-//echo print_r(apache_request_headers(), true);
+echo print_r(apache_request_headers(), true);
-//echo '<br />';
+echo '<br />';
-//echo file_get_contents("php://input");
+echo file_get_contents("php://input");
View
164 mod/lti/servicelib.php
@@ -0,0 +1,164 @@
+<?php
+
+require_once($CFG->dirroot.'/mod/lti/OAuthBody.php');
+
+define('LTI_ITEM_TYPE', 'mod');
+define('LTI_ITEM_MODULE', 'lti');
+define('LTI_SOURCE', 'mod/lti');
+
+function lti_get_response_xml($codemajor, $description, $messageref, $messagetype){
+ $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><imsx_POXEnvelopeResponse />');
+ $xml->addAttribute('xmlns', 'http://www.imsglobal.org/lis/oms1p0/pox');
+
+ $headerinfo = $xml->addChild('imsx_POXHeader')
+ ->addChild('imsx_POXResponseHeaderInfo');
+
+ $headerinfo->addChild('imsx_version', 'V1.0');
+ $headerinfo->addChild('imsx_messageIdentifier', (string)mt_rand());
+
+ $statusinfo = $headerinfo->addChild('imsx_statusInfo');
+ $statusinfo->addchild('imsx_codeMajor', $codemajor);
+ $statusinfo->addChild('imsx_severity', 'status');
+ $statusinfo->addChild('imsx_description', $description);
+ $statusinfo->addChild('imsx_messageRefIdentifier', $messageref);
+
+ $xml->addChild('imsx_POXBody')
+ ->addChild($messagetype);
+
+ return $xml;
+}
+
+function lti_parse_message_id($xml){
+ $node = $xml->imsx_POXHeader->imsx_POXRequestHeaderInfo->imsx_messageIdentifier;
+ $messageid = (string)$node;
+
+ return $messageid;
+}
+
+function lti_parse_grade_replace_message($xml){
+ $node = $xml->imsx_POXBody->replaceResultRequest->resultRecord->sourcedGUID->sourcedId;
+ $resultjson = json_decode((string)$node);
+
+ $node = $xml->imsx_POXBody->replaceResultRequest->resultRecord->result->resultScore->textString;
+ $grade = floatval((string)$node);
+
+ $parsed = new stdClass();
+ $parsed->gradeval = $grade * 100;
+
+ $parsed->instanceid = $resultjson->data->instanceid;
+ $parsed->userid = $resultjson->data->userid;
+ $parsed->sourcedidhash = $resultjson->hash;
+
+ $parsed->messageid = lti_parse_message_id($xml);
+
+ return $parsed;
+}
+
+function lti_parse_grade_read_message($xml){
+ $node = $xml->imsx_POXBody->readResultRequest->resultRecord->sourcedGUID->sourcedId;
+ $resultjson = json_decode((string)$node);
+
+ $parsed = new stdClass();
+ $parsed->instanceid = $resultjson->data->instanceid;
+ $parsed->userid = $resultjson->data->userid;
+ $parsed->sourcedidhash = $resultjson->hash;
+