forked from cbone99/IMathAS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ltihome.php
302 lines (283 loc) · 14.1 KB
/
ltihome.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<?php
//IMathAS: LTI instructor home page
//(c) 2011 David Lippman
require("validate.php");
if (!isset($sessiondata['ltirole']) || $sessiondata['ltirole']!='instructor') {
echo "Not authorized to view this page";
exit;
}
//decide what we need to display
if ($sessiondata['ltiitemtype']==0) {
$hascourse = true;
$hasplacement = true;
$placementtype = 'assess';
$typeid = $sessiondata['ltiitemid'];
$query = "SELECT courseid FROM imas_assessments WHERE id='$typeid'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$cid = mysql_result($result,0,0);
$query = "SELECT id FROM imas_teachers WHERE courseid='$cid' AND userid='$userid'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
if (mysql_num_rows($result)==0) {
$role = 'tutor';
} else {
$role = 'teacher';
}
} else {
$query = "SELECT courseid FROM imas_lti_courses WHERE contextid='{$sessiondata['lti_context_id']}' ";
$query .= "AND org='{$sessiondata['ltiorg']}'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
if (mysql_num_rows($result)==0) {
$hascourse = false;
if (isset($sessiondata['lti_launch_get']) && isset($sessiondata['lti_launch_get']['cid'])) {
$cid = intval($sessiondata['lti_launch_get']['cid']);
if ($cid>0) {
$query = "INSERT INTO imas_lti_courses (org,contextid,courseid) VALUES ";
$query .= "('{$sessiondata['ltiorg']}','{$sessiondata['lti_context_id']}',$cid)";
mysql_query($query) or die("Query failed : " . mysql_error());
$hascourse = true;
}
}
} else {
$hascourse = true;
$cid = mysql_result($result,0,0);
}
if ($hascourse) {
$query = "SELECT id,placementtype,typeid FROM imas_lti_placements WHERE contextid='{$sessiondata['lti_context_id']}' ";
$query .= "AND org='{$sessiondata['ltiorg']}' AND linkid='{$sessiondata['lti_resource_link_id']}'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
if (mysql_num_rows($result)==0) {
$hasplacement = false;
if (isset($sessiondata['lti_launch_get']) && isset($sessiondata['lti_launch_get']['aid'])) {
$aid = intval($sessiondata['lti_launch_get']['aid']);
if ($aid>0) {
$placementtype = 'assess';
$typeid = $aid;
$query = "INSERT INTO imas_lti_placements (org,contextid,linkid,placementtype,typeid) VALUES ";
$query .= "('{$sessiondata['ltiorg']}','{$sessiondata['lti_context_id']}','{$sessiondata['lti_resource_link_id']}','$placementtype','$typeid')";
mysql_query($query) or die("Query failed : " . mysql_error());
$placementid = mysql_insert_id();
$hasplacement = true;
}
}
} else {
$hasplacement = true;
list($placementid,$placementtype,$typeid) = mysql_fetch_row($result);
}
$role = 'teacher';
}
}
//handle form postbacks
if (isset($_POST['createcourse'])) {
$query = "SELECT courseid FROM imas_teachers WHERE courseid='{$_POST['createcourse']}' AND userid='$userid'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
if (mysql_num_rows($result)>0) {
$cid = intval($_POST['createcourse']);
} else {
//creating a copy of a template course
$blockcnt = 1;
$itemorder = addslashes(serialize(array()));
$randkey = uniqid();
$hideicons = isset($CFG['CPS']['hideicons'])?$CFG['CPS']['hideicons'][0]:0;
$picicons = isset($CFG['CPS']['picicons'])?$CFG['CPS']['picicons'][0]:0;
$allowunenroll = isset($CFG['CPS']['allowunenroll'])?$CFG['CPS']['allowunenroll'][0]:0;
$copyrights = isset($CFG['CPS']['copyrights'])?$CFG['CPS']['copyrights'][0]:0;
$msgset = isset($CFG['CPS']['msgset'])?$CFG['CPS']['msgset'][0]:0;
$msgmonitor = (floor($msgset/5))&1;
$msgQtoInstr = (floor($msgset/5))&2;
$msgset = $msgset%5;
$cploc = isset($CFG['CPS']['cploc'])?$CFG['CPS']['cploc'][0]:1;
$topbar = isset($CFG['CPS']['topbar'])?$CFG['CPS']['topbar'][0]:array(array(),array(),0);
$theme = isset($CFG['CPS']['theme'])?$CFG['CPS']['theme'][0]:$defaultcoursetheme;
$chatset = isset($CFG['CPS']['chatset'])?$CFG['CPS']['chatset'][0]:0;
$showlatepass = isset($CFG['CPS']['showlatepass'])?$CFG['CPS']['showlatepass'][0]:0;
$avail = 0;
$lockaid = 0;
$query = "INSERT INTO imas_courses (name,ownerid,enrollkey,hideicons,picicons,allowunenroll,copyrights,msgset,chatset,showlatepass,itemorder,topbar,cploc,available,theme,ltisecret,blockcnt) VALUES ";
$query .= "('{$sessiondata['lti_context_label']}','$userid','$randkey','$hideicons','$picicons','$unenroll','$copyrights','$msgset',$chatset,$showlatepass,'$itemorder','$topbar','$cploc','$avail','$theme','$randkey','$blockcnt');";
mysql_query($query) or die("Query failed : " . mysql_error());
$cid = mysql_insert_id();
//if ($myrights==40) {
$query = "INSERT INTO imas_teachers (userid,courseid) VALUES ('$userid','$cid')";
mysql_query($query) or die("Query failed : " . mysql_error());
//}
$useweights = intval(isset($CFG['GBS']['useweights'])?$CFG['GBS']['useweights']:0);
$orderby = intval(isset($CFG['GBS']['orderby'])?$CFG['GBS']['orderby']:0);
$defgbmode = intval(isset($CFG['GBS']['defgbmode'])?$CFG['GBS']['defgbmode']:21);
$usersort = intval(isset($CFG['GBS']['usersort'])?$CFG['GBS']['usersort']:0);
$query = "INSERT INTO imas_gbscheme (courseid,useweights,orderby,defgbmode,usersort) VALUES ('$cid',$useweights,$orderby,$defgbmode,$usersort)";
mysql_query($query) or die("Query failed : " . mysql_error());
$query = "SELECT useweights,orderby,defaultcat,defgbmode,stugbmode FROM imas_gbscheme WHERE courseid='{$_POST['createcourse']}'";
$result = mysql_query($query) or die("Query failed :$query " . mysql_error());
$row = mysql_fetch_row($result);
$query = "UPDATE imas_gbscheme SET useweights='{$row[0]}',orderby='{$row[1]}',defaultcat='{$row[2]}',defgbmode='{$row[3]}',stugbmode='{$row[4]}' WHERE courseid='$cid'";
mysql_query($query) or die("Query failed :$query " . mysql_error());
$gbcats = array();
$query = "SELECT id,name,scale,scaletype,chop,dropn,weight FROM imas_gbcats WHERE courseid='{$_POST['createcourse']}'";
$result = mysql_query($query) or die("Query failed :$query " . mysql_error());
while ($row = mysql_fetch_row($result)) {
$query = "INSERT INTO imas_gbcats (courseid,name,scale,scaletype,chop,dropn,weight) VALUES ";
$frid = array_shift($row);
$irow = "'".implode("','",addslashes_deep($row))."'";
$query .= "('$cid',$irow)";
mysql_query($query) or die("Query failed :$query " . mysql_error());
$gbcats[$frid] = mysql_insert_id();
}
$copystickyposts = true;
$query = "SELECT itemorder FROM imas_courses WHERE id='{$_POST['createcourse']}'";
$result = mysql_query($query) or die("Query failed : $query" . mysql_error());
$items = unserialize(mysql_result($result,0,0));
$newitems = array();
require("includes/copyiteminc.php");
copyallsub($items,'0',$newitems,$gbcats);
$itemorder = addslashes(serialize($newitems));
$query = "UPDATE imas_courses SET itemorder='$itemorder' WHERE id='$cid'";
mysql_query($query) or die("Query failed : " . mysql_error());
copyrubrics();
}
$query = "UPDATE imas_lti_courses SET courseid=$cid WHERE org='{$sessiondata['ltiorg']}' AND contextid='{$sessiondata['lti_context_id']}'";
mysql_query($query) or die("Query failed : " . mysql_error());
if (mysql_affected_rows()==0) {
$query = "INSERT INTO imas_lti_courses (org,contextid,courseid) VALUES ";
$query .= "('{$sessiondata['ltiorg']}','{$sessiondata['lti_context_id']}',$cid)";
mysql_query($query) or die("Query failed : " . mysql_error());
}
$hascourse = true;
} else if (isset($_POST['setplacement'])) {
if ($_POST['setplacement']=='course') {
$placementtype = 'course';
$typeid = $cid;
} else {
$placementtype = 'assess';
$typeid = $_POST['setplacement'];
}
if (isset($sessiondata['lti_selection_return'])) {
//Canvas custom LTI selection return
if ($placementtype=='assess') {
$query = "SELECT name FROM imas_assessments WHERE id='$typeid'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$atitle = mysql_result($result,0,0);
$url = $urlmode . $_SERVER['HTTP_HOST'] . $imasroot . "/bltilaunch.php?custom_place_aid=$typeid";
header('Location: '.$sessiondata['lti_selection_return'].'?embed_type=basic_lti&url='.urlencode($url).'&title='.urlencode($atitle).'&text='.urlencode($atitle));
exit;
} else {
exit;
}
}
if ($hasplacement) {
$query = "UPDATE imas_lti_placements SET placementtype='$placementtype',typeid='$typeid' WHERE id='$placementid'";
mysql_query($query) or die("Query failed : " . mysql_error());
} else {
$query = "INSERT INTO imas_lti_placements (org,contextid,linkid,placementtype,typeid) VALUES ";
$query .= "('{$sessiondata['ltiorg']}','{$sessiondata['lti_context_id']}','{$sessiondata['lti_resource_link_id']}','$placementtype','$typeid')";
mysql_query($query) or die("Query failed : " . mysql_error());
$placementid = mysql_insert_id();
$hasplacement = true;
}
}
if ($hasplacement && $placementtype=='course') {
if (!isset($_GET['showhome']) && !isset($_GET['chgplacement'])) {
header('Location: ' . $urlmode . $_SERVER['HTTP_HOST'] . $imasroot . "/course/course.php?cid=$cid");
exit;
}
}
//HTML Output
$pagetitle = "LTI Home";
require("header.php");
if (!$hascourse || isset($_GET['chgcourselink'])) {
echo '<h3>Link courses</h3>';
echo '<form method="post" action="ltihome.php">';
echo "<p>This course on your LMS has not yet been linked to a course on $installname.";
echo 'Select a course to link with. If it is a template course, a copy will be created for you:<br/> <select name="createcourse"> ';
$query = "SELECT ic.id,ic.name FROM imas_courses AS ic,imas_teachers WHERE imas_teachers.courseid=ic.id AND imas_teachers.userid='$userid' AND ic.available<4 ORDER BY ic.name";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
if (mysql_num_rows($result)>0) {
echo '<optgroup label="Your Courses">';
while ($row = mysql_fetch_row($result)) {
echo '<option value="'.$row[0].'">'.$row[1].'</option>';
}
echo '</optgroup>';
}
$query = "SELECT id,name,copyrights FROM imas_courses WHERE (istemplate&1)=1 AND copyrights=2 AND available<4 ORDER BY name";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
if (mysql_num_rows($result)>0) {
echo '<optgroup label="Template Courses">';
while ($row = mysql_fetch_row($result)) {
echo '<option value="'.$row[0].'">'.$row[1].'</option>';
}
echo '</optgroup>';
}
echo '</select>';
echo '<input type="Submit" value="Create"/>';
echo "<p>If you want to create a new course, log directly into $installname to create new courses</p>";
echo '</form>';
} else if (!$hasplacement || isset($_GET['chgplacement'])) {
echo '<h3>Link courses</h3>';
echo '<form method="post" action="ltihome.php">';
echo "<p>This placement on your LMS has not yet been linked to content on $installname. ";
if (!isset($sessiondata['lti_selection_return'])) {
echo 'You can either do a full course placement, in which case all content of the course is available from this one placement, or ';
echo 'you can place an individual assessment. Select the placement you\'d like to make: ';
} else {
echo 'Select the assessment you\'d like to use: ';
}
echo '<br/> <select name="setplacement"> ';
if (!isset($sessiondata['lti_selection_return'])) {
echo '<option value="course">Whole course Placement</option>';
}
$query = "SELECT id,name FROM imas_assessments WHERE courseid='$cid' ORDER BY name";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
if (mysql_num_rows($result)>0) {
echo '<optgroup label="Assessment">';
while ($row = mysql_fetch_row($result)) {
echo '<option value="'.$row[0].'">'.$row[1].'</option>';
}
echo '</optgroup>';
}
echo '</select>';
echo '<input type="Submit" value="Make Placement"/>';
echo "<p>If you want to create new assessments, log directly into $installname</p>";
echo "<p>If your LMS course is linked with the wrong course on $installname, ";
echo '<a href="ltihome.php?chgcourselink=true" onclick="return confirm(\'Are you SURE you want to do this? This may break existing placements.\');">Change course link</a></p>';
echo '</form>';
} else if ($placementtype=='course') {
echo '<h3>LTI Placement of whole course</h3>';
echo "<p><a href=\"course/course.php?cid=$cid\">Enter course</a></p>";
echo '<p><a href="ltihome.php?chgplacement=true">Change placement</a></p>';
} else if ($placementtype=='assess') {
$query = "SELECT name,avail,startdate,enddate FROM imas_assessments WHERE id='$typeid'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$line = mysql_fetch_array($result, MYSQL_ASSOC);
echo "<h3>LTI Placement of {$line['name']}</h3>";
echo "<p><a href=\"assessment/showtest.php?cid=$cid&id=$typeid\">Preview assessment</a> | ";
echo "<a href=\"course/isolateassessgrade.php?cid=$cid&aid=$typeid\">Grade list</a> ";
if ($role == 'teacher') {
echo "| <a href=\"course/gb-itemanalysis.php?cid=$cid&asid=average&aid=$typeid\">Item Analysis</a>";
}
echo "</p>";
$now = time();
echo '<p>';
if ($line['avail']==1 && $line['startdate']<$now && $line['enddate']>$now) { //regular show
echo "Currently available to students. Available until " . formatdate($line['enddate']);
} else if ($line['avail']==0) {
echo 'Currently unavailable to students.';
} else {
echo 'Currently unavailable to students. Available '.formatdate($line['startdate']).' until '.formatdate($line['enddate']);
}
echo '</p>';
if ($role == 'teacher') {
echo "<p><a href=\"course/addassessment.php?cid=$cid&id=$typeid&from=lti\">Settings</a> | ";
echo "<a href=\"course/addquestions.php?cid=$cid&aid=$typeid&from=lti\">Questions</a></p>";
if ($sessiondata['ltiitemtype']==-1) {
echo '<p><a href="ltihome.php?chgplacement=true">Change placement</a></p>';
}
}
}
require("footer.php");
function formatdate($date) {
if ($date==0 || $date==2000000000) {
return 'Always';
} else {
return tzdate("D n/j/y, g:i a",$date);
}
}
?>