17539f3d5b12c9be0d2881e3c2eea8ead5ce7415
[atutor.git] / docs / mods / _standard / basiclti / ModuleCallbacks.class.php
1 <?php
2
3 /**
4  * This class contains the callback functions that are called in the core scripts to manipulate content etc. 
5  *
6  * Note:
7  * 1. CHANGE the class name and ensure its uniqueness by prefixing with the module name
8  * 2. DO NOT change the script name. Leave as "ModuleCallbacks.class.php"
9  * 3. DO NOT change the names of the methods.
10  * 4. REGISTER the unique class name in module.php
11  *
12  * @access      public
13  */
14 if (!defined('AT_INCLUDE_PATH')) exit;
15
16 class BasicLTICallbacks {
17         /*
18          * To append output onto course content page 
19          * @param: None
20          * @return: a string, plain or html, to be appended to course content page
21          */ 
22         public static function appendContent($cid) {
23                 if ( !is_int($_SESSION['course_id']) || $_SESSION['course_id'] < 1 ) return;
24                 $sql = "SELECT * FROM ".TABLE_PREFIX."basiclti_content
25                         WHERE content_id=".$cid." AND course_id = ".$_SESSION['course_id'];
26                 global $db;
27                 $instanceresult = mysql_query($sql, $db);
28                 if ( $instanceresult == false ) return;
29                 $basiclti_content_row = mysql_fetch_assoc($instanceresult);
30                 if ( $basiclti_content_row === false ) return;
31                 $toolid = $basiclti_content_row['toolid'];
32                 $sql = "SELECT * FROM ".TABLE_PREFIX."basiclti_tools
33                                 WHERE toolid='".$toolid."'";
34                 $contentresult = mysql_query($sql, $db);
35                 $basiclti_tool_row = mysql_fetch_assoc($contentresult);
36                 if ( ! $basiclti_tool_row ) {
37                         return _AT('blti_missing_tool').$toolid;
38                 }
39                 // Figure height
40                 $height = 1200;
41                 if ( isset($basiclti_tool_row['preferheight']) && $basiclti_tool_row['preferheight'] > 0 ) {
42                         $height = $basiclti_tool_row['preferheight'];
43                 }
44                 if ( $basiclti_tool_row['allowpreferheight'] == 2 && isset($basiclti_content_row['preferheight']) && $basiclti_content_row['preferheight'] > 0 ) {
45                         $height = $basiclti_content_row['preferheight'];
46                 }
47
48                 $myurl = AT_BASE_HREF.'mods/_standard/basiclti/launch/launch.php?cid='.$cid;
49                 if ( $basiclti_tool_row['launchinpopup'] == 1 ||
50                    ( $basiclti_tool_row['launchinpopup'] == 2 && $basiclti_content_row['launchinpopup'] == 1 ) ) {
51                         // return '<script type="text/javascript">window.open("'.$myurl.'");</script>'."\n";
52                                 /*****************
53                                 *       The ID in the next bit is temporary until we can add the box style to ATutor and
54                                 *       change the ID value to content-tool. In the meantime this will fail validation if tools and
55                                 *   tests or forums are also present for the content page
56                                 **********************/
57                                 return '<div class="input-form" id="content-test"><ol><strong>'._AT('proxy').'</strong><ul class="tools"><li><a href="" onclick="ATutor.poptastic(\''.$myurl.'\'); return false;"'.'>'.$basiclti_tool_row['title'].'</a> ('._AT('new_window').')</li></ul></ol></div>'."\n";
58                 } else {
59                         return '<iframe src="'.$myurl.'" height="'.$height.'" width="100%"></iframe>'."\n";
60                 }
61         }
62
63 }
64
65 ?>