Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * This file contains the script used to register a new external tool.
19
 *
20
 * It is used to create a new form used to configure the capabilities
21
 * and services to be offered to the tool provider.
22
 *
23
 * @package mod_lti
24
 * @copyright  2014 Vital Source Technologies http://vitalsource.com
25
 * @author     Stephen Vickers
26
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 */
28
 
29
require_once('../../config.php');
30
require_once($CFG->libdir.'/adminlib.php');
31
require_once($CFG->dirroot.'/mod/lti/edit_form.php');
32
require_once($CFG->dirroot.'/mod/lti/locallib.php');
33
 
34
$action       = optional_param('action', '', PARAM_ALPHANUMEXT);
35
$id           = optional_param('id', '', PARAM_INT);
36
$tab          = optional_param('tab', '', PARAM_ALPHAEXT);
37
$returnto     = optional_param('returnto', '', PARAM_ALPHA);
38
 
39
if ($returnto == 'toolconfigure') {
40
    $returnurl = new moodle_url($CFG->wwwroot . '/mod/lti/toolconfigure.php');
41
}
42
 
43
// No guest autologin.
44
require_login(0, false);
45
 
46
require_sesskey();
47
 
48
// Check this is for a tool created from a tool proxy.
49
$err = empty($id);
50
if (!$err) {
51
    $type = lti_get_type_type_config($id);
52
    $err = empty($type->toolproxyid);
53
}
54
if ($err) {
55
    $params = array('action' => $action, 'id' => $id, 'sesskey' => sesskey(), 'tab' => $tab);
56
    if (!empty($returnto)) {
57
        $params['returnto'] = $returnto;
58
    }
59
    $redirect = new moodle_url('/mod/lti/typessettings.php', $params);
60
    redirect($redirect);
61
}
62
 
63
$pageurl = new moodle_url('/mod/lti/toolssettings.php');
64
if (!empty($id)) {
65
    $pageurl->param('id', $id);
66
}
67
if (!empty($returnto)) {
68
    $pageurl->param('returnto', $returnto);
69
}
70
$PAGE->set_url($pageurl);
71
 
72
admin_externalpage_setup('managemodules'); // Hacky solution for printing the admin page.
73
 
74
$redirect = "$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti&tab={$tab}";
75
if (!empty($returnurl)) {
76
    $redirect = $returnurl;
77
}
78
 
79
if ($action == 'accept') {
80
    lti_set_state_for_type($id, LTI_TOOL_STATE_CONFIGURED);
81
    redirect($redirect);
82
} else if (($action == 'reject') || ($action == 'delete')) {
83
    lti_set_state_for_type($id, LTI_TOOL_STATE_REJECTED);
84
    redirect($redirect);
85
}
86
 
87
if (lti_request_is_using_ssl() && !empty($type->lti_secureicon)) {
88
    $type->oldicon = $type->lti_secureicon;
89
} else {
90
    $type->oldicon = $type->lti_icon;
91
}
92
 
93
$form = new mod_lti_edit_types_form($pageurl, (object)array('isadmin' => true, 'istool' => true));
94
 
95
if ($data = $form->get_data()) {
96
    $type = new stdClass();
97
    if (!empty($id)) {
98
        $type->id = $id;
99
        lti_update_type($type, $data);
100
    } else {
101
        $type->state = LTI_TOOL_STATE_CONFIGURED;
102
        lti_add_type($type, $data);
103
    }
104
    redirect($redirect);
105
} else if ($form->is_cancelled()) {
106
    redirect($redirect);
107
}
108
 
109
$PAGE->set_title(get_string('toolsetup', 'lti'));
110
$PAGE->navbar->add(get_string('lti_administration', 'lti'), $CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=modsettinglti');
111
 
112
echo $OUTPUT->header();
113
echo $OUTPUT->heading(get_string('toolsetup', 'lti'));
114
echo $OUTPUT->box_start('generalbox');
115
 
116
if ($action == 'update') {
117
    $form->set_data($type);
118
}
119
 
120
$form->display();
121
echo $OUTPUT->box_end();
122
echo $OUTPUT->footer();