course)) { error("Course is misconfigured"); } if (! $hotpot = get_record("hotpot", "id", $cm->instance)) { error("Course module is incorrect"); } } else { if (! $hotpot = get_record("hotpot", "id", $hp)) { error("Course module is incorrect"); } if (! $course = get_record("course", "id", $hotpot->course)) { error("Course is misconfigured"); } if (! $cm = get_coursemodule_from_instance("hotpot", $hotpot->id, $course->id)) { error("Course Module ID was incorrect"); } } // make sure this user is enrolled in this course and can access this HotPot require_login($course); $context = get_context_instance(CONTEXT_MODULE, $cm->id); require_capability('mod/hotpot:attempt', $context, $USER->id); } // set nextpage (for error messages) $nextpage = "$CFG->wwwroot/course/view.php?id=$course->id"; // header strings $title = format_string($course->shortname.': '.$hotpot->name, true); $heading = $course->fullname; $navigation = build_navigation('', $cm); $button = update_module_button($cm->id, $course->id, get_string("modulename", "hotpot")); $button = '
'.$button.'
'; $loggedinas = ''.user_login_string($course, $USER).''; $time = time(); $hppassword = optional_param('hppassword', ''); if (HOTPOT_FIRST_ATTEMPT && !has_capability('mod/hotpot:grade', $context)) { // check this quiz is available to this student // error message, if quiz is unavailable $error = ''; // check quiz is visible if (!hotpot_is_visible($cm)) { $error = get_string("activityiscurrentlyhidden"); // check network address } else if ($hotpot->subnet && !address_in_subnet(getremoteaddr(), $hotpot->subnet)) { $error = get_string("subneterror", "quiz"); // check number of attempts } else if ($hotpot->attempts && $hotpot->attempts <= count_records_select('hotpot_attempts', 'hotpot='.$hotpot->id.' AND userid='.$USER->id, 'COUNT(DISTINCT clickreportid)')) { $error = get_string("nomoreattempts", "quiz"); // get password } else if ($hotpot->password && empty($hppassword)) { print_header($title, $heading, $navigation, "", "", true, $button, $loggedinas, false); print_heading($hotpot->name); $boxalign = 'center'; $boxwidth = 500; if (trim(strip_tags($hotpot->summary))) { print_simple_box_start($boxalign, $boxwidth); print '
'.format_text($hotpot->summary)."
\n"; print_simple_box_end(); print "
\n"; } print '
'."\n"; print_simple_box_start($boxalign, $boxwidth); print '
'; print get_string('requirepasswordmessage', 'quiz').'

'; print ''.get_string('password').': '; print ' '; print ' '; print "
\n"; print_simple_box_end(); print "
\n"; print_footer(); exit; // check password } else if ($hotpot->password && strcmp($hotpot->password, $hppassword)) { $error = get_string("passworderror", "quiz"); $nextpage = "view.php?id=$cm->id"; // check quiz is open } else if ($hotpot->timeopen && $hotpot->timeopen > $time) { $error = get_string("quiznotavailable", "quiz", userdate($hotpot->timeopen))."
\n"; // check quiz is not closed } else if ($hotpot->timeclose && $hotpot->timeclose < $time) { $error = get_string("quizclosed", "quiz", userdate($hotpot->timeclose))."
\n"; } if ($error) { print_header($title, $heading, $navigation, "", "", true, $button, $loggedinas, false); notice($error, $nextpage); // // script stops here, if quiz is unavailable to student // } } $available_msg = ''; if (!empty($hotpot->timeclose) && $hotpot->timeclose > $time) { // quiz is available until 'timeclose' $available_msg = get_string("quizavailable", "quiz", userdate($hotpot->timeclose))."
\n"; } // open and parse the source file if(!$hp = new hotpot_xml_quiz($hotpot)) { error("Quiz is unavailable at the moment"); } $get_js = optional_param('js', '', PARAM_ALPHA); $get_css = optional_param('css', '', PARAM_ALPHA); $framename = optional_param('framename', '', PARAM_ALPHA); // look for (HP5 v5) $frameset = ''; $frameset_tags = ''; if (preg_match_all('|]*)>(.*?)|is', $hp->html, $matches)) { $last = count($matches[0])-1; $frameset = $matches[2][$last]; $frameset_tags = $matches[1][$last]; } // if HTML is being requested ... if (empty($get_js) && empty($get_css)) { if (empty($frameset)) { // HP v6 if ($hotpot->navigation==HOTPOT_NAVIGATION_FRAME || $hotpot->navigation==HOTPOT_NAVIGATION_IFRAME) { $get_html = ($framename=='main') ? true : false; } else { $get_html = true; } } else { // HP5 v5 $get_html = empty($framename) ? true : false; } if ($get_html) { if (HOTPOT_FIRST_ATTEMPT) { add_to_log($course->id, "hotpot", "view", "view.php?id=$cm->id", "$hotpot->id", "$cm->id"); $attemptid = hotpot_add_attempt($hotpot->id); if (! is_numeric($attemptid)) { error('Could not insert attempt record: '.$db->ErrorMsg); } } $hp->adjust_media_urls(); if (empty($frameset)) { // HP6 v6 $targetframe = ''; switch ($hotpot->navigation) { case HOTPOT_NAVIGATION_BUTTONS: // do nothing (i.e. leave buttons as they are) break; case HOTPOT_NAVIGATION_GIVEUP: $hp->insert_giveup_form($attemptid, '', ''); break; case HOTPOT_NAVIGATION_FRAME: $targetframe = $CFG->framename; // drop through to remove nav buttons too default: $hp->remove_nav_buttons(); } if (isset($hp->real_outputformat) && $hp->real_outputformat==HOTPOT_OUTPUTFORMAT_MOBILE) { $hp->insert_submission_form($attemptid, '', '', true); } else { $hp->insert_submission_form($attemptid, '', '', false, $targetframe); } } else { // HP5 v5 switch ($hotpot->navigation) { case HOTPOT_NAVIGATION_BUTTONS: // convert URLs in nav buttons break; case HOTPOT_NAVIGATION_GIVEUP: // $hp->insert_giveup_form($attemptid, '', ''); break; default: // remove navigation buttons $hp->html = preg_replace('#NavBar\+=(.*);#', '', $hp->html); } $hp->insert_submission_form($attemptid, "var NavBar='", "';"); } } } //FEEDBACK = new Array(); //FEEDBACK[0] = ''; // url of feedback page/script //FEEDBACK[1] = ''; // array of array('teachername', 'value'); //FEEDBACK[2] = ''; // 'student name' [formmail only] //FEEDBACK[3] = ''; // 'student email' [formmail only] //FEEDBACK[4] = ''; // window width //FEEDBACK[5] = ''; // window height //FEEDBACK[6] = ''; // 'Send a message to teacher' [prompt/button text] //FEEDBACK[7] = ''; // 'Title' //FEEDBACK[8] = ''; // 'Teacher' //FEEDBACK[9] = ''; // 'Message' //FEEDBACK[10] = ''; // 'Close this window' $feedback = array(); switch ($hotpot->studentfeedback) { case HOTPOT_FEEDBACK_NONE: // do nothing break; case HOTPOT_FEEDBACK_WEBPAGE: if (empty($hotpot->studentfeedbackurl)) { $hotpot->studentfeedback = HOTPOT_FEEDBACK_NONE; } else { $feedback[0] = "'$hotpot->studentfeedbackurl'"; } break; case HOTPOT_FEEDBACK_FORMMAIL: $teachers = hotpot_feedback_teachers($course, $hotpot); if (empty($teachers) || empty($hotpot->studentfeedbackurl)) { $hotpot->studentfeedback = HOTPOT_FEEDBACK_NONE; } else { $feedback[0] = "'$hotpot->studentfeedbackurl'"; $feedback[1] = $teachers; $feedback[2] = "'".fullname($USER)."'"; $feedback[3] = "'".$USER->email."'"; $feedback[4] = 500; // width $feedback[5] = 300; // height } break; case HOTPOT_FEEDBACK_MOODLEFORUM: $module = get_record('modules', 'name', 'forum'); $forums = get_records('forum', 'course', "$course->id"); if (empty($module) || empty($module->visible) || empty($forums)) { $hotpot->studentfeedback = HOTPOT_FEEDBACK_NONE; } else { $feedback[0] = "'$CFG->wwwroot/mod/forum/index.php?id=$course->id'"; } break; case HOTPOT_FEEDBACK_MOODLEMESSAGING: $teachers = hotpot_feedback_teachers($course, $hotpot); if (empty($CFG->messaging) || empty($teachers)) { $hotpot->studentfeedback = HOTPOT_FEEDBACK_NONE; } else { $feedback[0] = "'$CFG->wwwroot/message/discussion.php?id='"; $feedback[1] = $teachers; $feedback[4] = 400; // width $feedback[5] = 500; // height } break; default: // do nothing } if ($hotpot->studentfeedback != HOTPOT_FEEDBACK_NONE) { $feedback[6] = "'Send a message to teacher'"; $feedback[7] = "'Title'"; $feedback[8] = "'Teacher'"; $feedback[9] = "'Message'"; $feedback[10] = "'Close this window'"; $js = ''; foreach ($feedback as $i=>$str) { $js .= 'FEEDBACK['.$i."] = $str;\n"; } $js = '\n"; $hp->html = preg_replace('||i', "$js", $hp->html, 1); } // insert hot-potatoes.js $hp->insert_script(HOTPOT_JS); // get Moodle pageid and pageclass $pageid = ''; $pageclass = ''; if (function_exists('page_id_and_class')) { page_id_and_class($pageid, $pageclass); } // extract first tag $head = ''; $pattern = '|]*)>(.*?)|is'; if (preg_match($pattern, $hp->html, $matches)) { $head = $matches[2]; // remove $head = preg_replace('|<title[^>]*>(.*?)|is', '', $head); } // extract |is'; if (preg_match_all($pattern, $head, $matches)) { $count = count($matches[0]); for ($i=0; $i<$count; $i++) { if ($pageid) { $styles .= str_replace('TheBody', $pageid, $matches[0][$i])."\n"; } $head = str_replace($matches[0][$i], '', $head); } } // extract |is'; if (preg_match_all($pattern, $head, $matches)) { $count = count($matches[0]); for ($i=0; $i<$count; $i++) { if ($pageid) { $scripts .= str_replace('TheBody', $pageid, $matches[0][$i])."\n"; } $head = str_replace($matches[0][$i], '', $head); } } // extract tags $body = ''; $body_tags = ''; $footer = ''; // HP6 and some HP5 (v6 and v4) if (preg_match('|]*'.'onLoad=(["\'])(.*?)(\\2)'.'[^>]*)'.'>(.*)|is', $hp->html, $matches)) { $body = $matches[5]; // contents of first ... block if ($pageid) { $body_tags = str_replace(' id="TheBody"', '', $matches[1]); } // workaround to ensure javascript onload routine for quiz is always executed // $body_tags will only be inserted into the tag // if it is included in the theme/$CFG->theme/header.html, // so some old or modified themes may not insert $body_tags $body .= "" . '\n" ; $footer = ''.$footer; } else if ($frameset) { // HP5 v5 switch ($framename) { case 'top': print_header($title, $heading, $navigation, "", "", true, $button, $loggedinas); print $footer; break; default: // add a HotPot navigation frame at the top of the page //$rows = empty($CFG->resource_framesize) ? 85 : $CFG->resource_framesize; //$frameset = "\n\t".''.$frameset; //$frameset_tags = preg_replace('|rows="(.*?)"|', 'rows="'.$rows.',\\1"', $frameset_tags); // put navigation into var NavBar=''; // add form to TopFrame in "WriteFeedback" function // OR add form to BottomFrame in "DisplayExercise" function // submission form: '', '' // give up form: '', '' print "\n"; print "\n$title\n$styles\n$scripts\n"; print "$frameset\n"; print "\n"; break; } // end switch $framename exit; // other files (maybe not even a HotPots) } else if (preg_match('|]*)'.'>(.*)|is', $hp->html, $matches)) { $body = $matches[2]; $body_tags = $matches[1]; } // print the quiz to the browser if ($get_js) { print($scripts); exit; } if ($get_css) { print($styles); exit; } // closing tags for "page" and "content" divs $footer = ''.$footer; switch ($hotpot->navigation) { case HOTPOT_NAVIGATION_BAR: //update_module_button($cm->id, $course->id, $strmodulename.'" style="font-size:0.8em') print_header($title, $heading, $navigation, "", $head.$styles.$scripts, true, $button, $loggedinas, false, $body_tags ); if (!empty($available_msg)) { notify($available_msg); } print $body.$footer; break; case HOTPOT_NAVIGATION_FRAME: switch ($framename) { case 'top': print_header($title, $heading, $navigation, "", "", true, $button, $loggedinas); print $footer; break; case 'main': if (!empty($available_msg)) { $hp->insert_message('', $available_msg); } print $hp->html; break; default: $txtframesetinfo = get_string('framesetinfo'); $txttoptitle = get_string('navigation', 'hotpot'); $txtmaintitle = get_string('modulename', 'hotpot'); $rows = empty($CFG->resource_framesize) ? 85 : $CFG->resource_framesize; @header('Content-Type: text/html; charset=utf-8'); print "\n"; print "\n"; print "\n"; print "$title\n"; print "\n"; print "id&framename=top\">\n"; print "id&framename=main\">\n"; print "\n"; print "<p>$txtframesetinfo</p>\n"; print "<ul><li><a href=\"view.php?id=$cm->id&amp;framename=top\">$txttoptitle</a></li>\n"; print "<li><a href=\"view.php?id=$cm->id&amp;framename=main\">$txtmaintitle</a></li></ul>\n"; print "\n"; print "\n"; print "\n"; break; } // end switch $framename break; case HOTPOT_NAVIGATION_IFRAME: switch ($framename) { case 'main': print $hp->html; break; default: $iframe_id = 'hotpot_iframe'; $body_tags = " onload=\"set_iframe_height('$iframe_id')\""; $iframe_js = ''."\n"; print_header( $title, $heading, $navigation, "", $head.$styles.$scripts.$iframe_js, true, $button, $loggedinas, false, $body_tags ); if (!empty($available_msg)) { notify($available_msg); } print "\n"; print $footer; break; } // end switch $framename break; case HOTPOT_NAVIGATION_GIVEUP: // replace charset , if necessary // HotPots are plain ascii (iso-8859-1) with unicode chars encoded as HTML entities $charset = get_string("thischarset"); if ($charset == 'iso-8859-1') { // do nothing } else { $hp->html = preg_replace( '|]*charset=iso-8859-1[^>]*>|is', '', $hp->html ); } // no break (continue to print html to browser) default: // HOTPOT_NAVIGATION_BUTTONS // HOTPOT_NAVIGATION_NONE if (!empty($available_msg)) { $hp->insert_message('', $available_msg); } print($hp->html); } /////////////////////////////////// /// functions /////////////////////////////////// function hotpot_feedback_teachers(&$course, &$hotpot) { global $CFG; $teachers = get_users_by_capability(get_context_instance(CONTEXT_COURSE, $course->id), 'mod/hotpot:grade'); $teacherdetails = ''; if (!empty($teachers)) { $details = array(); foreach ($teachers as $teacher) { if ($hotpot->studentfeedback==HOTPOT_FEEDBACK_MOODLEMESSAGING) { $detail = $teacher->id; } else { $detail =$teacher->email; } $details[] = "new Array('".fullname($teacher)."', '$detail')"; } $teacherdetails = 'new Array('.implode(',', $details).");\n"; } return $teacherdetails; } ?>