PageRenderTime 65ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/hotpot/view.php

https://bitbucket.org/ceu/moodle_demo
PHP | 567 lines | 464 code | 16 blank | 87 comment | 118 complexity | 276027817ec39d940821b5115689e9f3 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, LGPL-2.1
  1. <?PHP // $Id: view.php,v 1.38.2.14 2012/05/19 11:04:52 moodlerobot Exp $
  2. /// This page prints a hotpot quiz
  3. if (defined('HOTPOT_FIRST_ATTEMPT') && HOTPOT_FIRST_ATTEMPT==false) {
  4. // this script is being included (by attempt.php)
  5. } else {
  6. // this script is being called directly from the browser
  7. define('HOTPOT_FIRST_ATTEMPT', true);
  8. require_once("../../config.php");
  9. require_once("lib.php");
  10. $id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
  11. $hp = optional_param('hp', 0, PARAM_INT); // hotpot ID
  12. if ($id) {
  13. if (! $cm = get_coursemodule_from_id('hotpot', $id)) {
  14. error("Course Module ID was incorrect");
  15. }
  16. if (! $course = get_record("course", "id", $cm->course)) {
  17. error("Course is misconfigured");
  18. }
  19. if (! $hotpot = get_record("hotpot", "id", $cm->instance)) {
  20. error("Course module is incorrect");
  21. }
  22. } else {
  23. if (! $hotpot = get_record("hotpot", "id", $hp)) {
  24. error("Course module is incorrect");
  25. }
  26. if (! $course = get_record("course", "id", $hotpot->course)) {
  27. error("Course is misconfigured");
  28. }
  29. if (! $cm = get_coursemodule_from_instance("hotpot", $hotpot->id, $course->id)) {
  30. error("Course Module ID was incorrect");
  31. }
  32. }
  33. // make sure this user is enrolled in this course and can access this HotPot
  34. require_login($course);
  35. $context = get_context_instance(CONTEXT_MODULE, $cm->id);
  36. require_capability('mod/hotpot:attempt', $context, $USER->id);
  37. }
  38. // set nextpage (for error messages)
  39. $nextpage = "$CFG->wwwroot/course/view.php?id=$course->id";
  40. // header strings
  41. $title = format_string($course->shortname.': '.$hotpot->name, true);
  42. $heading = $course->fullname;
  43. $navigation = build_navigation('', $cm);
  44. $button = update_module_button($cm->id, $course->id, get_string("modulename", "hotpot"));
  45. $button = '<div style="font-size:0.75em;">'.$button.'</div>';
  46. $loggedinas = user_login_string($course, $USER);
  47. $time = time();
  48. $hppassword = optional_param('hppassword', '');
  49. if (HOTPOT_FIRST_ATTEMPT && !has_capability('mod/hotpot:grade', $context)) {
  50. // check this quiz is available to this student
  51. // error message, if quiz is unavailable
  52. $error = '';
  53. // check quiz is visible
  54. if (!hotpot_is_visible($cm)) {
  55. $error = get_string("activityiscurrentlyhidden");
  56. // check network address
  57. } else if ($hotpot->subnet && !address_in_subnet(getremoteaddr(), $hotpot->subnet)) {
  58. $error = get_string("subneterror", "quiz");
  59. // check number of attempts
  60. } else if ($hotpot->attempts && $hotpot->attempts <= count_records_select('hotpot_attempts', 'hotpot='.$hotpot->id.' AND userid='.$USER->id, 'COUNT(DISTINCT clickreportid)')) {
  61. $error = get_string("nomoreattempts", "quiz");
  62. // get password
  63. } else if ($hotpot->password && empty($hppassword)) {
  64. print_header($title, $heading, $navigation, "", "", true, $button, $loggedinas, false);
  65. print_heading($hotpot->name);
  66. $boxalign = 'center';
  67. $boxwidth = 500;
  68. if (trim(strip_tags($hotpot->summary))) {
  69. print_simple_box_start($boxalign, $boxwidth);
  70. print '<div class="mdl-align">'.format_text($hotpot->summary)."</div>\n";
  71. print_simple_box_end();
  72. print "<br />\n";
  73. }
  74. print '<form id="passwordform" method="post" action="view.php?id='.$cm->id.'">'."\n";
  75. print_simple_box_start($boxalign, $boxwidth);
  76. print '<div class="mdl-align">';
  77. print get_string('requirepasswordmessage', 'quiz').'<br /><br />';
  78. print '<b>'.get_string('password').':</b> ';
  79. print '<input name="hppassword" type="password" value="" /> ';
  80. print '<input type="submit" value="'.get_string("ok").'" /> ';
  81. print "</div>\n";
  82. print_simple_box_end();
  83. print "</form>\n";
  84. print_footer();
  85. exit;
  86. // check password
  87. } else if ($hotpot->password && strcmp($hotpot->password, $hppassword)) {
  88. $error = get_string("passworderror", "quiz");
  89. $nextpage = "view.php?id=$cm->id";
  90. // check quiz is open
  91. } else if ($hotpot->timeopen && $hotpot->timeopen > $time) {
  92. $error = get_string("quiznotavailable", "quiz", userdate($hotpot->timeopen))."<br />\n";
  93. // check quiz is not closed
  94. } else if ($hotpot->timeclose && $hotpot->timeclose < $time) {
  95. $error = get_string("quizclosed", "quiz", userdate($hotpot->timeclose))."<br />\n";
  96. }
  97. if ($error) {
  98. print_header($title, $heading, $navigation, "", "", true, $button, $loggedinas, false);
  99. notice($error, $nextpage);
  100. //
  101. // script stops here, if quiz is unavailable to student
  102. //
  103. }
  104. }
  105. $available_msg = '';
  106. if (!empty($hotpot->timeclose) && $hotpot->timeclose > $time) {
  107. // quiz is available until 'timeclose'
  108. $available_msg = get_string("quizavailable", "quiz", userdate($hotpot->timeclose))."<br />\n";
  109. }
  110. // open and parse the source file
  111. if(!$hp = new hotpot_xml_quiz($hotpot)) {
  112. error("Quiz is unavailable at the moment");
  113. }
  114. $get_js = optional_param('js', '', PARAM_ALPHA);
  115. $get_css = optional_param('css', '', PARAM_ALPHA);
  116. $framename = optional_param('framename', '', PARAM_ALPHA);
  117. // look for <frameset> (HP5 v5)
  118. $frameset = '';
  119. $frameset_tags = '';
  120. if (preg_match_all('|<frameset([^>]*)>(.*?)</frameset>|is', $hp->html, $matches)) {
  121. $last = count($matches[0])-1;
  122. $frameset = $matches[2][$last];
  123. $frameset_tags = $matches[1][$last];
  124. }
  125. // if HTML is being requested ...
  126. if (empty($get_js) && empty($get_css)) {
  127. if (empty($frameset)) {
  128. // HP v6
  129. if ($hotpot->navigation==HOTPOT_NAVIGATION_FRAME || $hotpot->navigation==HOTPOT_NAVIGATION_IFRAME) {
  130. $get_html = ($framename=='main') ? true : false;
  131. } else {
  132. $get_html = true;
  133. }
  134. } else {
  135. // HP5 v5
  136. $get_html = empty($framename) ? true : false;
  137. }
  138. if ($get_html) {
  139. if (HOTPOT_FIRST_ATTEMPT) {
  140. add_to_log($course->id, "hotpot", "view", "view.php?id=$cm->id", "$hotpot->id", "$cm->id");
  141. $attemptid = hotpot_add_attempt($hotpot->id);
  142. if (! is_numeric($attemptid)) {
  143. error('Could not insert attempt record: '.$db->ErrorMsg);
  144. }
  145. }
  146. $hp->adjust_media_urls();
  147. if (empty($frameset)) {
  148. // HP6 v6
  149. $targetframe = '';
  150. switch ($hotpot->navigation) {
  151. case HOTPOT_NAVIGATION_BUTTONS:
  152. // do nothing (i.e. leave buttons as they are)
  153. break;
  154. case HOTPOT_NAVIGATION_GIVEUP:
  155. $hp->insert_giveup_form($attemptid, '<!-- BeginTopNavButtons -->', '<!-- EndTopNavButtons -->');
  156. break;
  157. case HOTPOT_NAVIGATION_FRAME:
  158. case HOTPOT_NAVIGATION_IFRAME:
  159. if (empty($CFG->framename)) {
  160. $targetframe = '_top';
  161. } else {
  162. $targetframe = $CFG->framename;
  163. }
  164. if ($pos = strpos($hp->html, '</body>')) {
  165. $insert = ''
  166. .'<script type="text/javascript">'."\n"
  167. .'//<![CDATA['."\n"
  168. ."var obj = document.getElementsByTagName('a');\n"
  169. ."if (obj) {\n"
  170. ." var i_max = obj.length;\n"
  171. ." for (var i=0; i<i_max; i++) {\n"
  172. ." if (obj[i].href && ! obj[i].target) {\n"
  173. ." obj[i].target = '$targetframe';\n"
  174. ." }\n"
  175. ." }\n"
  176. ." var obj = null;\n"
  177. ."}\n"
  178. ."var obj = document.getElementsByTagName('form');\n"
  179. ."if (obj) {\n"
  180. ." var i_max = obj.length;\n"
  181. ." for (var i=0; i<i_max; i++) {\n"
  182. ." if (obj[i].action && ! obj[i].target) {\n"
  183. ." obj[i].target = '$targetframe';\n"
  184. ." }\n"
  185. ." }\n"
  186. ." var obj = null;\n"
  187. ."}\n"
  188. .'//]]>'."\n"
  189. .'</script>'."\n"
  190. ;
  191. $hp->html = substr_replace($hp->html, $insert, $pos, 0);
  192. }
  193. $hp->remove_nav_buttons();
  194. break;
  195. default:
  196. $hp->remove_nav_buttons();
  197. }
  198. if (isset($hp->real_outputformat) && $hp->real_outputformat==HOTPOT_OUTPUTFORMAT_MOBILE) {
  199. $hp->insert_submission_form($attemptid, '<!-- BeginSubmissionForm -->', '<!-- EndSubmissionForm -->', true);
  200. } else {
  201. $hp->insert_submission_form($attemptid, '<!-- BeginSubmissionForm -->', '<!-- EndSubmissionForm -->', false, $targetframe);
  202. }
  203. } else {
  204. // HP5 v5
  205. switch ($hotpot->navigation) {
  206. case HOTPOT_NAVIGATION_BUTTONS:
  207. // convert URLs in nav buttons
  208. break;
  209. case HOTPOT_NAVIGATION_GIVEUP:
  210. // $hp->insert_giveup_form($attemptid, '<!-- BeginTopNavButtons -->', '<!-- EndTopNavButtons -->');
  211. break;
  212. default:
  213. // remove navigation buttons
  214. $hp->html = preg_replace('#NavBar\+=(.*);#', '', $hp->html);
  215. }
  216. $hp->insert_submission_form($attemptid, "var NavBar='", "';");
  217. }
  218. }
  219. }
  220. //FEEDBACK = new Array();
  221. //FEEDBACK[0] = ''; // url of feedback page/script
  222. //FEEDBACK[1] = ''; // array of array('teachername', 'value');
  223. //FEEDBACK[2] = ''; // 'student name' [formmail only]
  224. //FEEDBACK[3] = ''; // 'student email' [formmail only]
  225. //FEEDBACK[4] = ''; // window width
  226. //FEEDBACK[5] = ''; // window height
  227. //FEEDBACK[6] = ''; // 'Send a message to teacher' [prompt/button text]
  228. //FEEDBACK[7] = ''; // 'Title'
  229. //FEEDBACK[8] = ''; // 'Teacher'
  230. //FEEDBACK[9] = ''; // 'Message'
  231. //FEEDBACK[10] = ''; // 'Close this window'
  232. $feedback = array();
  233. switch ($hotpot->studentfeedback) {
  234. case HOTPOT_FEEDBACK_NONE:
  235. // do nothing
  236. break;
  237. case HOTPOT_FEEDBACK_WEBPAGE:
  238. if (empty($hotpot->studentfeedbackurl)) {
  239. $hotpot->studentfeedback = HOTPOT_FEEDBACK_NONE;
  240. } else {
  241. $feedback[0] = "'$hotpot->studentfeedbackurl'";
  242. }
  243. break;
  244. case HOTPOT_FEEDBACK_FORMMAIL:
  245. $teachers = hotpot_feedback_teachers($course, $hotpot);
  246. if (empty($teachers) || empty($hotpot->studentfeedbackurl)) {
  247. $hotpot->studentfeedback = HOTPOT_FEEDBACK_NONE;
  248. } else {
  249. $feedback[0] = "'$hotpot->studentfeedbackurl'";
  250. $feedback[1] = $teachers;
  251. $feedback[2] = "'".fullname($USER)."'";
  252. $feedback[3] = "'".$USER->email."'";
  253. $feedback[4] = 500; // width
  254. $feedback[5] = 300; // height
  255. }
  256. break;
  257. case HOTPOT_FEEDBACK_MOODLEFORUM:
  258. $module = get_record('modules', 'name', 'forum');
  259. $forums = get_records('forum', 'course', "$course->id");
  260. if (empty($module) || empty($module->visible) || empty($forums)) {
  261. $hotpot->studentfeedback = HOTPOT_FEEDBACK_NONE;
  262. } else {
  263. $feedback[0] = "'$CFG->wwwroot/mod/forum/index.php?id=$course->id'";
  264. }
  265. break;
  266. case HOTPOT_FEEDBACK_MOODLEMESSAGING:
  267. $teachers = hotpot_feedback_teachers($course, $hotpot);
  268. if (empty($CFG->messaging) || empty($teachers)) {
  269. $hotpot->studentfeedback = HOTPOT_FEEDBACK_NONE;
  270. } else {
  271. $feedback[0] = "'$CFG->wwwroot/message/discussion.php?id='";
  272. $feedback[1] = $teachers;
  273. $feedback[4] = 400; // width
  274. $feedback[5] = 500; // height
  275. }
  276. break;
  277. default:
  278. // do nothing
  279. }
  280. if ($hotpot->studentfeedback != HOTPOT_FEEDBACK_NONE) {
  281. $feedback[6] = "'Send a message to teacher'";
  282. $feedback[7] = "'Title'";
  283. $feedback[8] = "'Teacher'";
  284. $feedback[9] = "'Message'";
  285. $feedback[10] = "'Close this window'";
  286. $js = '';
  287. foreach ($feedback as $i=>$str) {
  288. $js .= 'FEEDBACK['.$i."] = $str;\n";
  289. }
  290. $js = '<script type="text/javascript">'."\n//<![CDATA[\n"."FEEDBACK = new Array();\n".$js."//]]>\n</script>\n";
  291. $hp->html = preg_replace('|</head>|i', "$js</head>", $hp->html, 1);
  292. }
  293. // insert hot-potatoes.js
  294. $hp->insert_script(HOTPOT_JS);
  295. // get Moodle pageid and pageclass
  296. $pageid = '';
  297. $pageclass = '';
  298. if (function_exists('page_id_and_class')) {
  299. page_id_and_class($pageid, $pageclass);
  300. }
  301. // extract first <head> tag
  302. $head = '';
  303. $pattern = '|<head([^>]*)>(.*?)</head>|is';
  304. if (preg_match($pattern, $hp->html, $matches)) {
  305. $head = $matches[2];
  306. // remove <title>
  307. $head = preg_replace('|<title[^>]*>(.*?)</title>|is', '', $head);
  308. }
  309. // extract <style> tags (and remove from $head)
  310. $styles = '';
  311. $pattern = '|<style([^>]*)>(.*?)</style>|is';
  312. if (preg_match_all($pattern, $head, $matches)) {
  313. $count = count($matches[0]);
  314. for ($i=0; $i<$count; $i++) {
  315. if ($pageid) {
  316. $styles .= str_replace('TheBody', $pageid, $matches[0][$i])."\n";
  317. }
  318. $head = str_replace($matches[0][$i], '', $head);
  319. }
  320. }
  321. // extract <script> tags (and remove from $head)
  322. $scripts = '';
  323. $pattern = '|<script([^>]*)>(.*?)</script>|is';
  324. if (preg_match_all($pattern, $head, $matches)) {
  325. $count = count($matches[0]);
  326. for ($i=0; $i<$count; $i++) {
  327. if ($pageid) {
  328. $scripts .= str_replace('TheBody', $pageid, $matches[0][$i])."\n";
  329. }
  330. $head = str_replace($matches[0][$i], '', $head);
  331. }
  332. }
  333. // extract <body> tags
  334. $body = '';
  335. $body_tags = '';
  336. $footer = '</html>';
  337. // HP6 and some HP5 (v6 and v4)
  338. if (preg_match('|<body'.'([^>]*'.'onLoad=(["\'])(.*?)(\\2)'.'[^>]*)'.'>(.*)</body>|is', $hp->html, $matches)) {
  339. $body = $matches[5]; // contents of first <body onload="StartUp()">...</body> block
  340. if ($pageid) {
  341. $body_tags = str_replace(' id="TheBody"', '', $matches[1]);
  342. }
  343. // workaround to ensure javascript onload routine for quiz is always executed
  344. // $body_tags will only be inserted into the <body ...> tag
  345. // if it is included in the theme/$CFG->theme/header.html,
  346. // so some old or modified themes may not insert $body_tags
  347. $body .= ""
  348. . '<script type="text/javascript">'."\n"
  349. . "//<![CDATA[\n"
  350. . " var re = new RegExp('\\\\s+', 'g');\n"
  351. . " if (typeof(window.onload)=='function') {\n"
  352. . " var s = onload.toString();\n"
  353. . " s = s.replace(re, '');\n"
  354. . " } else {\n"
  355. . " var s = '';\n"
  356. . " }\n"
  357. . " if (s.indexOf('".$matches[3]."'.replace(re, ''))<0) {\n"
  358. . " if (s=='') {\n" // no previous onload
  359. . " window.onload = new Function('".$matches[3]."');\n"
  360. . " } else {\n"
  361. . " window.onload_hotpot = onload;\n"
  362. . " window.onload = new Function('window.onload_hotpot();'+'".$matches[3]."');\n"
  363. . " }\n"
  364. . " }\n"
  365. . "//]]>\n"
  366. . "</script>\n"
  367. ;
  368. $footer = '</body>'.$footer;
  369. } else if ($frameset) { // HP5 v5
  370. switch ($framename) {
  371. case 'top':
  372. print_header($title, $heading, $navigation, "", "", true, $button, $loggedinas);
  373. print $footer;
  374. break;
  375. default:
  376. // add a HotPot navigation frame at the top of the page
  377. //$rows = empty($CFG->resource_framesize) ? 85 : $CFG->resource_framesize;
  378. //$frameset = "\n\t".'<frame src="view.php?id='.$cm->id.'&amp;framename=top" frameborder="0" name="top"></frame>'.$frameset;
  379. //$frameset_tags = preg_replace('|rows="(.*?)"|', 'rows="'.$rows.',\\1"', $frameset_tags);
  380. // put navigation into var NavBar='';
  381. // add form to TopFrame in "WriteFeedback" function
  382. // OR add form to BottomFrame in "DisplayExercise" function
  383. // submission form: '<!-- BeginSubmissionForm -->', '<!-- EndSubmissionForm -->'
  384. // give up form: '<!-- BeginTopNavButtons -->', '<!-- EndTopNavButtons -->'
  385. print "<html>\n";
  386. print "<head>\n<title>$title</title>\n$styles\n$scripts</head>\n";
  387. print "<frameset$frameset_tags>$frameset</frameset>\n";
  388. print "</html>\n";
  389. break;
  390. } // end switch $framename
  391. exit;
  392. // other files (maybe not even a HotPots)
  393. } else if (preg_match('|<body'.'([^>]*)'.'>(.*)</body>|is', $hp->html, $matches)) {
  394. $body = $matches[2];
  395. $body_tags = $matches[1];
  396. }
  397. // print the quiz to the browser
  398. if ($get_js) {
  399. print($scripts);
  400. exit;
  401. }
  402. if ($get_css) {
  403. print($styles);
  404. exit;
  405. }
  406. // closing tags for "page" and "content" divs
  407. $footer = '</div></div>'.$footer;
  408. switch ($hotpot->navigation) {
  409. case HOTPOT_NAVIGATION_BAR:
  410. //update_module_button($cm->id, $course->id, $strmodulename.'" style="font-size:0.8em')
  411. print_header(
  412. $title, $heading, $navigation, "", $head.$styles.$scripts, true, $button, $loggedinas, false, $body_tags
  413. );
  414. if (!empty($available_msg)) {
  415. notify($available_msg);
  416. }
  417. print $body.$footer;
  418. break;
  419. case HOTPOT_NAVIGATION_FRAME:
  420. switch ($framename) {
  421. case 'top':
  422. print_header($title, $heading, $navigation, "", "", true, $button, $loggedinas);
  423. print $footer;
  424. break;
  425. case 'main':
  426. if (!empty($available_msg)) {
  427. $hp->insert_message('<!-- BeginTopNavButtons -->', $available_msg);
  428. }
  429. print $hp->html;
  430. break;
  431. default:
  432. $txtframesetinfo = get_string('framesetinfo');
  433. $txttoptitle = get_string('navigation', 'hotpot');
  434. $txtmaintitle = get_string('modulename', 'hotpot');
  435. $rows = empty($CFG->resource_framesize) ? 85 : $CFG->resource_framesize;
  436. @header('Content-Type: text/html; charset=utf-8');
  437. print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">\n";
  438. print "<html>\n";
  439. print "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />\n";
  440. print "<head><title>$title</title></head>\n";
  441. print "<frameset rows=$rows,*>\n";
  442. print "<frame title=\"$txttoptitle\" src=\"view.php?id=$cm->id&amp;framename=top\">\n";
  443. print "<frame title=\"$txtmaintitle\" src=\"view.php?id=$cm->id&amp;framename=main\">\n";
  444. print "<noframes>\n";
  445. print "<p>$txtframesetinfo</p>\n";
  446. print "<ul><li><a href=\"view.php?id=$cm->id&amp;framename=top\">$txttoptitle</a></li>\n";
  447. print "<li><a href=\"view.php?id=$cm->id&amp;framename=main\">$txtmaintitle</a></li></ul>\n";
  448. print "</noframes>\n";
  449. print "</frameset>\n";
  450. print "</html>\n";
  451. break;
  452. } // end switch $framename
  453. break;
  454. case HOTPOT_NAVIGATION_IFRAME:
  455. switch ($framename) {
  456. case 'main':
  457. print $hp->html;
  458. break;
  459. default:
  460. // set iframe attributes
  461. $iframe_id = 'hotpot_embed_object';
  462. $iframe_name = 'hotpot_embed_iframe';
  463. $iframe_width = '100%';
  464. $iframe_height = '100%';
  465. $iframe_src = $CFG->wwwroot.'/mod/hotpot/view.php?id='.$cm->id.'&amp;framename=main';
  466. $iframe_onload_function = 'set_embed_object_height';
  467. $iframe_js = '<script src="'.$CFG->wwwroot.'/mod/hotpot/iframe.js" type="text/javascript"></script>'."\n";
  468. print_header(
  469. $title, $heading, $navigation,
  470. "", $head.$styles.$scripts.$iframe_js, true, $button,
  471. $loggedinas, false
  472. );
  473. if (!empty($available_msg)) {
  474. notify($available_msg);
  475. }
  476. // for XHTML 1.0 Strict compatability, the embedded page should be implemented
  477. // using an <object> not an <iframe>. However, IE <object>'s are problematic
  478. // (links and forms cannot escape), so we use conditional comments to display
  479. // an <iframe> in IE and an <object> in other browsers
  480. // print the html element to hold the embedded html page
  481. // Note: the iframe in IE needs a "name" attribute for the resizing to work
  482. print '<!--[if IE]>'."\n";
  483. print '<iframe name="'.$iframe_name.'" id="'.$iframe_id.'" src="'.$iframe_src.'" width="'.$iframe_width.'" height="'.$iframe_height.'"></iframe>'."\n";
  484. print '<![endif]-->'."\n";
  485. print '<!--[if !IE]> <-->'."\n";
  486. print '<object id="'.$iframe_id.'" type="text/html" data="'.$iframe_src.'" width="'.$iframe_width.'" height="'.$iframe_height.'"></object>'."\n";
  487. print '<!--> <![endif]-->'."\n";
  488. // print javascript to add onload event handler - we do this here because
  489. // an object tag should have no onload attribute in XHTML 1.0 Strict
  490. print '<script type="text/javascript">'."\n";
  491. print '//<![CDATA['."\n";
  492. print "var obj = document.getElementById('$iframe_id');\n";
  493. print "if (obj) {\n";
  494. print " if (obj.addEventListener) {\n";
  495. print " obj.addEventListener('load', $iframe_onload_function, false);\n";
  496. print " } else if (obj.attachEvent) {\n";
  497. print " obj.attachEvent('onload', $iframe_onload_function);\n";
  498. print " } else {\n";
  499. print " obj['onload'] = $iframe_onload_function;\n";
  500. print " }\n";
  501. print "}\n";
  502. print "obj = null;\n";
  503. print '//]]>'."\n";
  504. print '</script>'."\n";
  505. print $footer;
  506. } // end switch $framename
  507. break;
  508. case HOTPOT_NAVIGATION_GIVEUP:
  509. // replace charset , if necessary
  510. // HotPots are plain ascii (iso-8859-1) with unicode chars encoded as HTML entities
  511. $charset = get_string("thischarset");
  512. if ($charset == 'iso-8859-1') {
  513. // do nothing
  514. } else {
  515. $hp->html = preg_replace(
  516. '|<meta[^>]*charset=iso-8859-1[^>]*>|is',
  517. '<meta http-equiv="Content-Type" content="text/html; charset='.$charset.'" />',
  518. $hp->html
  519. );
  520. }
  521. // no break (continue to print html to browser)
  522. default:
  523. // HOTPOT_NAVIGATION_BUTTONS
  524. // HOTPOT_NAVIGATION_NONE
  525. if (!empty($available_msg)) {
  526. $hp->insert_message('<!-- BeginTopNavButtons -->', $available_msg);
  527. }
  528. print($hp->html);
  529. }
  530. ///////////////////////////////////
  531. /// functions
  532. ///////////////////////////////////
  533. function hotpot_feedback_teachers(&$course, &$hotpot) {
  534. global $CFG;
  535. $teachers = get_users_by_capability(get_context_instance(CONTEXT_COURSE, $course->id), 'mod/hotpot:grade');
  536. $teacherdetails = '';
  537. if (!empty($teachers)) {
  538. $details = array();
  539. foreach ($teachers as $teacher) {
  540. if ($hotpot->studentfeedback==HOTPOT_FEEDBACK_MOODLEMESSAGING) {
  541. $detail = $teacher->id;
  542. } else {
  543. $detail =$teacher->email;
  544. }
  545. $details[] = "new Array('".fullname($teacher)."', '$detail')";
  546. }
  547. $teacherdetails = 'new Array('.implode(',', $details).");\n";
  548. }
  549. return $teacherdetails;
  550. }
  551. ?>