move code up one directory
[atutor.git] / mods / _standard / basiclti / launch / launch.php
1 <?php
2 define('AT_INCLUDE_PATH', '../../../../include/');
3 require(AT_INCLUDE_PATH.'vitals.inc.php');
4
5
6 function loadError($message) {
7     print $message;
8     exit();
9 }
10
11 $cid = intval($_GET['cid']);
12
13 $content_id = $cid;
14 $member_id = $_SESSION['member_id'];
15 require("loadrows.php");
16 $course_id = $atutor_content_row['course_id'];
17 // echo("basiclti_content_row<br/>\n");print_r($basiclti_content_row); echo("<hr>\n");
18 // echo("basiclti_tool_row<br/>\n");print_r($basiclti_tool_row); echo("<hr>\n");
19 // echo("atutor_content_row<br/>\n");print_r($atutor_content_row); echo("<hr>\n");
20 // echo("atutor_course_row<br/>\n");print_r($atutor_course_row); echo("<hr>\n");
21 // echo("atutor_member_row<br/>\n");print_r($atutor_member_row); echo("<hr>\n");
22 // echo("atutor_course_membership_row<br/>\n");print_r($atutor_course_membership_row); echo("<hr>\n");
23
24     $lmsdata = array(
25       "resource_link_id" => $cid,
26       "resource_link_title" => $atutor_content_row['title'],
27       "resource_link_description" => $atutor_content_row['text'],
28       "user_id" => $atutor_member_row['member_id'],
29       "roles" => "Learner",
30       "launch_presentation_locale" => $_SESSION['lang'],
31       "context_id" => $atutor_course_row['course_id'],
32       "context_title" => $atutor_course_row['title'],
33       "context_label" => $atutor_course_row['title'],
34       );
35
36     $lmsdata['ext_lms'] = 'ATutor';
37
38     if ( $atutor_course_membership_row['role'] == 'Instructor' ) {
39         $lmsdata["roles"] = 'Instructor';
40     }
41
42     if ( $_SESSION['is_admin'] == 1 ) {
43         $lmsdata["roles"] = 'Instructor';
44     }
45
46     if ( $basiclti_tool_row['sendemailaddr'] == 1 ||
47          ( $basiclti_tool_row['sendemailaddr'] == 2 && $basiclti_content_row['sendemailaddr'] == 1 ) ) {
48         $lmsdata["lis_person_contact_email_primary"] = $atutor_member_row['email'];
49     }
50
51     if ( $basiclti_tool_row['sendname'] == 1 ||
52          ( $basiclti_tool_row['sendname'] == 2 && $basiclti_content_row['sendname'] == 1 ) ) {
53         $lmsdata["lis_person_name_family"] = $atutor_member_row['last_name'];
54         $lmsdata["lis_person_name_given"] = $atutor_member_row['first_name'];
55     }
56
57     $placementsecret = $basiclti_content_row['placementsecret'];
58     $sourcedid = false;
59     if ( isset($placementsecret) && strlen($placementsecret) > 0 ) {
60         $suffix = ':::' . $atutor_member_row['member_id'] . ':::' . $cid;
61         $plaintext = $placementsecret . $suffix;
62         $hashsig = hash('sha256', $plaintext, false);
63         $sourcedid = $hashsig . $suffix;
64     }
65
66     if ( $sourcedid !== false  &&
67          ( $basiclti_tool_row['acceptgrades'] == 1 && $basiclti_content_row['gradebook_test_id'] != 0 ) ) {
68         $lmsdata["lis_result_sourcedid"] = $sourcedid;
69         $lmsdata["ext_ims_lis_basic_outcome_url"] = AT_BASE_HREF.'mods/_standard/basiclti/launch/service.php';
70     }
71
72     if ( $sourcedid !== false  &&
73          ( $basiclti_tool_row['allowroster'] == 1 ||
74          ( $basiclti_tool_row['allowroster'] == 2 && $basiclti_content_row['allowroster'] == 1 ) ) ) {
75         $lmsdata["ext_ims_lis_memberships_id"] = $sourcedid;
76         $lmsdata["ext_ims_lis_memberships_url"] = AT_BASE_HREF.'mods/_standard/basiclti/launch/service.php';
77     }
78
79     if ( $sourcedid !== false  &&
80          ( $basiclti_tool_row['allowsetting'] == 1 ||
81          ( $basiclti_tool_row['allowsetting'] == 2 && $basiclti_content_row['allowsetting'] == 1 ) ) ) {
82         $lmsdata["ext_ims_lti_tool_setting_id"] = $sourcedid;
83         $lmsdata["ext_ims_lti_tool_setting_url"] = AT_BASE_HREF.'mods/_standard/basiclti/launch/service.php';
84         $setting = $basiclti_content_row['setting'];
85         if ( isset($setting) ) {
86              $lmsdata["ext_ims_lti_tool_setting"] = $setting;
87         }
88     }
89
90 require_once("ims-blti/blti_util.php");
91
92     if ( strlen($basiclti_tool_row['customparameters']) > 0 ) {
93         $lmsdata = merge_custom_parameters($lmsdata,$basiclti_tool_row['customparameters']);
94     }
95     if ( $basiclti_tool_row['customparameters'] == 1 && strlen($basiclti_content_row['customparameters']) > 0 ) {
96         $lmsdata = merge_custom_parameters($lmsdata,$basiclti_content_row['customparameters']);
97     }
98
99 // print_r($lmsdata);echo("<hr>\n");
100
101 $parms = $lmsdata;
102
103 $endpoint = $basiclti_tool_row['toolurl'];
104 $key = $basiclti_tool_row['resourcekey'];
105 $secret = $basiclti_tool_row['password'];
106
107   $parms = signParameters($parms, $endpoint, "POST", $key, $secret, "Press to Launch", $tool_consumer_instance_guid, $tool_consumer_instance_description);
108
109   $debuglaunch = false;
110   if ( ( $basiclti_tool_row['debuglaunch'] == 1 ||
111        ( $basiclti_tool_row['debuglaunch'] == 2 && $basiclti_content_row['debuglaunch'] == 1 ) ) ) {
112     $debuglaunch = true;
113   }
114
115   $content = postLaunchHTML($parms, $endpoint, $debuglaunch);
116
117   print($content);
118
119
120 ?>