MDL-62478 upgrade: add 3.5.0 separation line to all upgrade scripts
[moodle.git] / mod / lti / toolproxies.php
blob7926ef94ce08a56217f6b9d36232b2d10e95c826
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.
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/>.
17 /**
18 * This file contains all necessary code to launch a Tool Proxy registration
20 * @package mod_lti
21 * @copyright 2014 Vital Source Technologies http://vitalsource.com
22 * @author Stephen Vickers
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once('../../config.php');
27 require_once($CFG->libdir.'/adminlib.php');
28 require_once($CFG->dirroot.'/mod/lti/locallib.php');
30 // No guest autologin.
31 require_login(0, false);
33 $pageurl = new moodle_url('/mod/lti/toolproxies.php');
34 $PAGE->set_url($pageurl);
36 admin_externalpage_setup('ltitoolproxies');
38 $PAGE->set_title("{$SITE->shortname}: " . get_string('toolregistration', 'lti'));
40 $configuredtoolproxieshtml = '';
41 $pendingtoolproxieshtml = '';
42 $acceptedtoolproxieshtml = '';
43 $rejectedtoolproxieshtml = '';
45 $configured = get_string('configured', 'lti');
46 $pending = get_string('pending', 'lti');
47 $accepted = get_string('accepted', 'lti');
48 $rejected = get_string('rejected', 'lti');
50 $name = get_string('name', 'lti');
51 $url = get_string('registrationurl', 'lti');
52 $action = get_string('action', 'lti');
53 $createdon = get_string('createdon', 'lti');
55 $toolproxies = $DB->get_records('lti_tool_proxies');
57 $configuredtoolproxies = lti_filter_tool_proxy_types($toolproxies, LTI_TOOL_PROXY_STATE_CONFIGURED);
58 $configuredtoolproxieshtml = lti_get_tool_proxy_table($configuredtoolproxies, 'tp_configured');
60 $pendingtoolproxies = lti_filter_tool_proxy_types($toolproxies, LTI_TOOL_PROXY_STATE_PENDING);
61 $pendingtoolproxieshtml = lti_get_tool_proxy_table($pendingtoolproxies, 'tp_pending');
63 $acceptedtoolproxies = lti_filter_tool_proxy_types($toolproxies, LTI_TOOL_PROXY_STATE_ACCEPTED);
64 $acceptedtoolproxieshtml = lti_get_tool_proxy_table($acceptedtoolproxies, 'tp_accepted');
66 $rejectedtoolproxies = lti_filter_tool_proxy_types($toolproxies, LTI_TOOL_PROXY_STATE_REJECTED);
67 $rejectedtoolproxieshtml = lti_get_tool_proxy_table($rejectedtoolproxies, 'tp_rejected');
69 $tab = optional_param('tab', '', PARAM_ALPHAEXT);
70 $configuredselected = '';
71 $pendingselected = '';
72 $acceptedselected = '';
73 $rejectedselected = '';
74 switch ($tab) {
75 case 'tp_pending':
76 $pendingselected = 'class="selected"';
77 break;
78 case 'tp_accepted':
79 $acceptedselected = 'class="selected"';
80 break;
81 case 'tp_rejected':
82 $rejectedselected = 'class="selected"';
83 break;
84 default:
85 $configuredselected = 'class="selected"';
86 break;
88 $registertype = get_string('registertype', 'lti');
89 $config = get_string('manage_tools', 'lti');
91 $registertypeurl = "{$CFG->wwwroot}/mod/lti/registersettings.php?action=add&amp;sesskey={$USER->sesskey}&amp;tab=tool_proxy";
93 $template = <<< EOD
94 <div id="tp_tabs" class="yui-navset">
95 <ul id="tp_tab_heading" class="yui-nav" style="display:none">
96 <li {$configuredselected}>
97 <a href="#tab1">
98 <em>$configured</em>
99 </a>
100 </li>
101 <li {$pendingselected}>
102 <a href="#tab2">
103 <em>$pending</em>
104 </a>
105 </li>
106 <li {$acceptedselected}>
107 <a href="#tab3">
108 <em>$accepted</em>
109 </a>
110 </li>
111 <li {$rejectedselected}>
112 <a href="#tab4">
113 <em>$rejected</em>
114 </a>
115 </li>
116 </ul>
117 <div class="yui-content">
118 <div>
119 <div><a style="margin-top:.25em" href="{$registertypeurl}">{$registertype}</a></div>
120 $configuredtoolproxieshtml
121 </div>
122 <div>
123 $pendingtoolproxieshtml
124 </div>
125 <div>
126 $acceptedtoolproxieshtml
127 </div>
128 <div>
129 $rejectedtoolproxieshtml
130 </div>
131 </div>
132 </div>
134 <script type="text/javascript">
135 //<![CDATA[
136 YUI().use('yui2-tabview', 'yui2-datatable', function(Y) {
137 //If javascript is disabled, they will just see the three tabs one after another
138 var tp_tab_heading = document.getElementById('tp_tab_heading');
139 tp_tab_heading.style.display = '';
141 new Y.YUI2.widget.TabView('tp_tabs');
143 var setupTools = function(id, sort){
144 var tp_tool_proxies = Y.YUI2.util.Dom.get(id);
146 if(tp_tool_proxies){
147 var dataSource = new Y.YUI2.util.DataSource(tp_tool_proxies);
149 var configuredColumns = [
150 {key:'name', label:'$name', sortable:true},
151 {key:'url', label:'$url', sortable:true},
152 {key:'timecreated', label:'$createdon', sortable:true},
153 {key:'action', label:'$action'}
156 dataSource.responseType = Y.YUI2.util.DataSource.TYPE_HTMLTABLE;
157 dataSource.responseSchema = {
158 fields: [
159 {key:'name'},
160 {key:'url'},
161 {key:'timecreated'},
162 {key:'action'}
166 new Y.YUI2.widget.DataTable(id + '_container', configuredColumns, dataSource,
168 sortedBy: sort
174 setupTools('tp_configured_tool_proxies', {key:'name', dir:'asc'});
175 setupTools('tp_pending_tool_proxies', {key:'timecreated', dir:'desc'});
176 setupTools('tp_accepted_tool_proxies', {key:'timecreated', dir:'desc'});
177 setupTools('tp_rejected_tool_proxies', {key:'timecreated', dir:'desc'});
179 //]]
180 </script>
181 EOD;
183 echo $OUTPUT->header();
184 echo $OUTPUT->heading(get_string('manage_tool_proxies', 'lti'), 2);
185 echo $OUTPUT->heading(new lang_string('toolproxy', 'lti') .
186 $OUTPUT->help_icon('toolproxy', 'lti'), 3);
188 echo $OUTPUT->box_start('generalbox');
190 echo $template;
192 echo $OUTPUT->box_end();
193 echo $OUTPUT->footer();