Renaming global functions to include lti prefix
[moodle.git] / mod / lti / settings.php
CommitLineData
b7e436b0
CS
1<?php\r
2// This file is part of BasicLTI4Moodle\r
3//\r
4// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)\r
5// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web\r
6// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI\r
7// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS\r
8// are already supporting or going to support BasicLTI. This project Implements the consumer\r
9// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.\r
10// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem\r
11// at the GESSI research group at UPC.\r
12// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI\r
13// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a\r
14// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.\r
15//\r
16// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis\r
17// of the Universitat Politecnica de Catalunya http://www.upc.edu\r
18// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu\r
19//\r
20// Moodle is free software: you can redistribute it and/or modify\r
21// it under the terms of the GNU General Public License as published by\r
22// the Free Software Foundation, either version 3 of the License, or\r
23// (at your option) any later version.\r
24//\r
25// Moodle is distributed in the hope that it will be useful,\r
26// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
27// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
28// GNU General Public License for more details.\r
29//\r
30// You should have received a copy of the GNU General Public License\r
31// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\r
32\r
33/**\r
34 * This file defines the global basiclti administration form\r
35 *\r
73300339 36 * @package lti\r
b7e436b0
CS
37 * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis\r
38 * marc.alier@upc.edu\r
39 * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu\r
40 *\r
41 * @author Marc Alier\r
42 * @author Jordi Piguillem\r
43 * @author Nikolas Galanis\r
44 *\r
45 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r
46 */\r
47\r
48defined('MOODLE_INTERNAL') || die;\r
49\r
a4a07996
CS
50global $PAGE, $CFG;\r
51\r
52require_once($CFG->dirroot.'/mod/lti/locallib.php');\r
53\r
54function blti_get_tool_table($tools, $id){\r
55 global $CFG, $USER;\r
56 $html = '';\r
57 \r
58 $typename = get_string('typename', 'lti');\r
59 $baseurl = get_string('baseurl', 'lti');\r
60 $action = get_string('action', 'lti');\r
61 $createdon = get_string('createdon', 'lti');\r
62 \r
57e8c475 63 if($id == 'lti_configured'){\r
560ed50c 64 $html .= '<div><a style="margin-top:.25em" href="'.$CFG->wwwroot.'/mod/lti/typessettings.php?action=add&amp;sesskey='.$USER->sesskey.'">'.get_string('addtype', 'lti').'</a></div>';\r
57e8c475
CS
65 }\r
66 \r
a4a07996 67 if (!empty($tools)) {\r
a4a07996
CS
68 $html .= <<<HTML\r
69 <div id="{$id}_container" style="margin-top:.5em;margin-bottom:.5em">\r
70 <table id="{$id}_tools">\r
71 <thead>\r
72 <tr>\r
73 <th>$typename</th>\r
74 <th>$baseurl</th>\r
75 <th>$createdon</th>\r
76 <th>$action</th>\r
77 </tr>\r
78 </thead>\r
79HTML;\r
80 \r
81 foreach ($tools as $type) {\r
82 $date = userdate($type->timecreated);\r
83 $accept = get_string('accept', 'lti');\r
84 $update = get_string('update', 'lti');\r
85 $delete = get_string('delete', 'lti');\r
86 \r
87 $accepthtml = <<<HTML\r
88 <a class="editing_accept" href="{$CFG->wwwroot}/mod/lti/typessettings.php?action=accept&amp;id={$type->id}&amp;sesskey={$USER->sesskey}&amp;tab={$id}" title="{$accept}">\r
89 <img class="iconsmall" alt="{$accept}" src="{$CFG->wwwroot}/pix/t/clear.gif"/>\r
90 </a>\r
91HTML;\r
92\r
93 $deleteaction = 'delete';\r
94 \r
95 if($type->state == LTI_TOOL_STATE_CONFIGURED){\r
96 $accepthtml = '';\r
97 }\r
98 \r
99 if($type->state != LTI_TOOL_STATE_REJECTED) {\r
100 $deleteaction = 'reject';\r
101 $delete = get_string('reject', 'lti');\r
102 }\r
103 \r
104 $html .= <<<HTML\r
105 <tr>\r
106 <td>\r
107 {$type->name}\r
108 </td>\r
109 <td>\r
110 {$type->baseurl}\r
111 </td>\r
112 <td>\r
113 {$date}\r
114 </td>\r
115 <td align="center">\r
116 {$accepthtml}\r
117 <a class="editing_update" href="{$CFG->wwwroot}/mod/lti/typessettings.php?action=update&amp;id={$type->id}&amp;sesskey={$USER->sesskey}&amp;tab={$id}" title="{$update}">\r
118 <img class="iconsmall" alt="{$update}" src="{$CFG->wwwroot}/pix/t/edit.gif"/>\r
119 </a>\r
120 <a class="editing_delete" href="{$CFG->wwwroot}/mod/lti/typessettings.php?action={$deleteaction}&amp;id={$type->id}&amp;sesskey={$USER->sesskey}&amp;tab={$id}" title="{$delete}">\r
121 <img class="iconsmall" alt="{$delete}" src="{$CFG->wwwroot}/pix/t/delete.gif"/>\r
122 </a>\r
123 </td>\r
124 </tr>\r
125HTML;\r
126 }\r
127 $html .= '</table></div>';\r
128 } else {\r
129 $html .= get_string('no_' . $id, 'lti');\r
130 }\r
131 \r
132 return $html;\r
133}\r
134\r
b7e436b0 135if ($ADMIN->fulltree) {\r
73300339 136 require_once($CFG->dirroot.'/mod/lti/locallib.php');\r
b7e436b0 137\r
a4a07996
CS
138 $configuredtoolshtml = '';\r
139 $pendingtoolshtml = '';\r
140 $rejectedtoolshtml = '';\r
b7e436b0 141\r
a4a07996
CS
142 $active = get_string('active', 'lti');\r
143 $pending = get_string('pending', 'lti');\r
144 $rejected = get_string('rejected', 'lti');\r
145 $typename = get_string('typename', 'lti');\r
146 $baseurl = get_string('baseurl', 'lti');\r
147 $action = get_string('action', 'lti');\r
148 $createdon = get_string('createdon', 'lti');\r
149 \r
73300339 150 $types = lti_filter_get_types();\r
a4a07996
CS
151 \r
152 $configuredtools = array_filter($types, function($value){\r
153 return $value->state == LTI_TOOL_STATE_CONFIGURED;\r
154 });\r
155 \r
156 $configuredtoolshtml = blti_get_tool_table($configuredtools, 'lti_configured');\r
b7e436b0 157\r
a4a07996
CS
158 $pendingtools = array_filter($types, function($value){\r
159 return $value->state == LTI_TOOL_STATE_PENDING;\r
160 });\r
161 \r
162 $pendingtoolshtml = blti_get_tool_table($pendingtools, 'lti_pending');\r
163 \r
164 $rejectedtools = array_filter($types, function($value){\r
165 return $value->state == LTI_TOOL_STATE_REJECTED;\r
166 });\r
167 \r
168 $rejectedtoolshtml = blti_get_tool_table($rejectedtools, 'lti_rejected');\r
169 \r
170 $tab = optional_param('tab', '', PARAM_ALPHAEXT);\r
171 $activeselected = '';\r
172 $pendingselected = '';\r
173 $rejectedselected = '';\r
174 switch($tab){\r
175 case 'lti_pending':\r
176 $pendingselected = 'class="selected"';\r
177 break;\r
178 case 'lti_rejected':\r
179 $rejectedselected = 'class="selected"';\r
180 break;\r
181 default:\r
182 $activeselected = 'class="selected"';\r
183 break;\r
b7e436b0 184 }\r
a4a07996
CS
185 \r
186 $template = <<<HTML\r
187<div id="lti_tabs" class="yui-navset">\r
188 <ul id="lti_tab_heading" class="yui-nav" style="display:none">\r
189 <li {$activeselected}>\r
190 <a href="#tab1">\r
191 <em>$active</em>\r
192 </a>\r
193 </li>\r
194 <li {$pendingselected}>\r
195 <a href="#tab2">\r
196 <em>$pending</em>\r
197 </a>\r
198 </li>\r
199 <li {$rejectedselected}>\r
200 <a href="#tab3">\r
201 <em>$rejected</em>\r
202 </a>\r
203 </li>\r
204 </ul>\r
205 <div class="yui-content">\r
206 <div>\r
207 $configuredtoolshtml\r
208 </div>\r
209 <div>\r
210 $pendingtoolshtml\r
211 </div>\r
212 <div>\r
213 $rejectedtoolshtml\r
214 </div>\r
215 </div>\r
216</div>\r
217\r
218<script type='text/javascript'>\r
219//<![CDATA[\r
220 (function(){\r
221 //If javascript is disabled, they will just see the three tabs one after another\r
222 var lti_tab_heading = document.getElementById('lti_tab_heading');\r
223 lti_tab_heading.style.display = '';\r
224\r
225 new YAHOO.widget.TabView('lti_tabs');\r
226 \r
227 var setupTools = function(id, sort){\r
228 var lti_tools = YAHOO.util.Dom.get(id + "_tools");\r
229 \r
230 if(lti_tools){\r
231 var dataSource = new YAHOO.util.DataSource(lti_tools);\r
232 \r
233 var configuredColumns = [\r
234 {key:"name", label:"$typename", sortable:true},\r
235 {key:"baseURL", label:"$baseurl", sortable:true},\r
236 {key:"timecreated", label:"$createdon", sortable:true, formatter:YAHOO.widget.DataTable.formatDate},\r
237 {key:"action", label:"$action"}\r
238 ];\r
239\r
240 dataSource.responseType = YAHOO.util.DataSource.TYPE_HTMLTABLE;\r
241 dataSource.responseSchema = {\r
242 fields: [\r
243 {key:"name"},\r
244 {key:"baseURL"},\r
245 {key:"timecreated", parser:"date"},\r
246 {key:"action"}\r
247 ]\r
248 };\r
b7e436b0 249\r
a4a07996
CS
250 new YAHOO.widget.DataTable(id + "_container", configuredColumns, dataSource,\r
251 {\r
252 sortedBy: sort\r
253 }\r
254 );\r
255 }\r
256 };\r
b7e436b0 257\r
a4a07996
CS
258 setupTools('lti_configured', {key:"name", dir:"asc"});\r
259 setupTools('lti_pending', {key:"timecreated", dir:"desc"});\r
260 setupTools('lti_rejected', {key:"timecreated", dir:"desc"});\r
261 })();\r
262//]]\r
263</script>\r
264HTML;\r
5f24742f 265 \r
a4a07996
CS
266 $PAGE->requires->yui2_lib('tabview');\r
267 $PAGE->requires->yui2_lib('datatable');\r
268 \r
269 $settings->add(new admin_setting_heading('lti_types', get_string('external_tool_types', 'lti'), $template /* $str*/));\r
b7e436b0 270}\r