Changed all files to DOS and added some Id tags
This commit is contained in:
+108
-108
@@ -1,108 +1,108 @@
|
||||
<?php
|
||||
require_once("../../config.php");
|
||||
require_once("lib.php");
|
||||
|
||||
$next_url = "";
|
||||
$msg = '';
|
||||
|
||||
$attemptid = required_param("attemptid");
|
||||
if (is_numeric($attemptid)) {
|
||||
|
||||
if (! $attempt = get_record("hotpot_attempts", "id", $attemptid)) {
|
||||
error("Hot Potatoes attempt record $attemptid could not be accessed: ".$db->ErrorMsg());
|
||||
}
|
||||
|
||||
// Check this is the right user
|
||||
if ($attempt->userid != $USER->id) {
|
||||
error("Incorrect user id");
|
||||
}
|
||||
|
||||
// get hotpot, course and course_module records
|
||||
if (! $hotpot = get_record("hotpot", "id", $attempt->hotpot)) {
|
||||
error("Hot Potatoes ID is incorrect (attempt id = $attempt->id)");
|
||||
}
|
||||
if (! $course = get_record("course", "id", $hotpot->course)) {
|
||||
error("Course ID is incorrect (hotpot id = $hotpot->id)");
|
||||
}
|
||||
if (! $cm = get_coursemodule_from_instance("hotpot", $hotpot->id, $course->id)) {
|
||||
error("Course Module ID is incorrect");
|
||||
}
|
||||
|
||||
$next_url = "$CFG->wwwroot/course/view.php?id=$course->id";
|
||||
|
||||
// make sure this user is enrolled in this course
|
||||
require_login($course->id);
|
||||
|
||||
if ($attempt->timefinish && false) {
|
||||
|
||||
$msg = 'This attempt has already been submitted';
|
||||
|
||||
} else {
|
||||
$time = time();
|
||||
$msg = get_string('resultssaved', 'hotpot');
|
||||
|
||||
$attempt->score = isset($_POST['mark']) ? $_POST['mark'] : NULL;
|
||||
$attempt->details = isset($_POST['detail']) ? $_POST['detail'] : NULL;
|
||||
$attempt->endtime = isset($_POST['endtime']) ? strtotime($_POST['endtime']) : NULL;
|
||||
$attempt->starttime = isset($_POST['starttime']) ? strtotime($_POST['starttime']) : NULL;
|
||||
$attempt->timefinish = $time;
|
||||
|
||||
// for the rare case where a quiz was "in progress" during an update from hotpot v1 to v2
|
||||
if (empty($attempt->timestart) && !empty($attempt->starttime)) {
|
||||
$attempt->timestart = $attempt->starttime;
|
||||
}
|
||||
|
||||
// remove slashes added by lib/setup.php
|
||||
$attempt->details = stripslashes($attempt->details);
|
||||
|
||||
// add details of this attempt
|
||||
hotpot_add_attempt_details($attempt);
|
||||
|
||||
// add slashes again, so the details can be added to the database
|
||||
$attempt->details = addslashes($attempt->details);
|
||||
|
||||
if (! update_record("hotpot_attempts", $attempt)) {
|
||||
error("Could not update attempt record: ".$db->ErrorMsg(), $next_url);
|
||||
}
|
||||
|
||||
// set previously unfinished attempts of this quiz by this user to "finished"
|
||||
hotpot_close_previous_attempts($hotpot->id, $USER->id, $time);
|
||||
|
||||
add_to_log($course->id, "hotpot", "submit", "review.php?id=$cm->id&attempt=$attempt->id", "$hotpot->id", "$cm->id");
|
||||
}
|
||||
if ($hotpot->shownextquiz==HOTPOT_YES && is_numeric($next_cm = hotpot_get_next_cm($cm))) {
|
||||
$next_url = "$CFG->wwwroot/mod/hotpot/view.php?id=$next_cm";
|
||||
}
|
||||
}
|
||||
|
||||
// redirect to the next quiz or the course page
|
||||
redirect($next_url, $msg);
|
||||
|
||||
|
||||
// =================
|
||||
// functions
|
||||
// =================
|
||||
|
||||
function hotpot_get_next_cm(&$cm) {
|
||||
// gets the next module in this section of the course
|
||||
// that is the same type of module as the current module
|
||||
|
||||
$next_mod = false;
|
||||
|
||||
// get a list of $ids of modules in this section
|
||||
if ($ids = get_field('course_sections', 'sequence', 'id', $cm->section)) {
|
||||
|
||||
$ids = explode(',', $ids);
|
||||
$found = false;
|
||||
foreach ($ids as $id) {
|
||||
if ($found && ($cm->module==get_field('course_modules', 'module', 'id', $id))) {
|
||||
$next_mod = $id;
|
||||
break;
|
||||
} else if ($cm->id==$id) {
|
||||
$found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $next_mod;
|
||||
}
|
||||
?>
|
||||
<?php // $Id$
|
||||
require_once("../../config.php");
|
||||
require_once("lib.php");
|
||||
|
||||
$next_url = "";
|
||||
$msg = '';
|
||||
|
||||
$attemptid = required_param("attemptid");
|
||||
if (is_numeric($attemptid)) {
|
||||
|
||||
if (! $attempt = get_record("hotpot_attempts", "id", $attemptid)) {
|
||||
error("Hot Potatoes attempt record $attemptid could not be accessed: ".$db->ErrorMsg());
|
||||
}
|
||||
|
||||
// Check this is the right user
|
||||
if ($attempt->userid != $USER->id) {
|
||||
error("Incorrect user id");
|
||||
}
|
||||
|
||||
// get hotpot, course and course_module records
|
||||
if (! $hotpot = get_record("hotpot", "id", $attempt->hotpot)) {
|
||||
error("Hot Potatoes ID is incorrect (attempt id = $attempt->id)");
|
||||
}
|
||||
if (! $course = get_record("course", "id", $hotpot->course)) {
|
||||
error("Course ID is incorrect (hotpot id = $hotpot->id)");
|
||||
}
|
||||
if (! $cm = get_coursemodule_from_instance("hotpot", $hotpot->id, $course->id)) {
|
||||
error("Course Module ID is incorrect");
|
||||
}
|
||||
|
||||
$next_url = "$CFG->wwwroot/course/view.php?id=$course->id";
|
||||
|
||||
// make sure this user is enrolled in this course
|
||||
require_login($course->id);
|
||||
|
||||
if ($attempt->timefinish && false) {
|
||||
|
||||
$msg = 'This attempt has already been submitted';
|
||||
|
||||
} else {
|
||||
$time = time();
|
||||
$msg = get_string('resultssaved', 'hotpot');
|
||||
|
||||
$attempt->score = isset($_POST['mark']) ? $_POST['mark'] : NULL;
|
||||
$attempt->details = isset($_POST['detail']) ? $_POST['detail'] : NULL;
|
||||
$attempt->endtime = isset($_POST['endtime']) ? strtotime($_POST['endtime']) : NULL;
|
||||
$attempt->starttime = isset($_POST['starttime']) ? strtotime($_POST['starttime']) : NULL;
|
||||
$attempt->timefinish = $time;
|
||||
|
||||
// for the rare case where a quiz was "in progress" during an update from hotpot v1 to v2
|
||||
if (empty($attempt->timestart) && !empty($attempt->starttime)) {
|
||||
$attempt->timestart = $attempt->starttime;
|
||||
}
|
||||
|
||||
// remove slashes added by lib/setup.php
|
||||
$attempt->details = stripslashes($attempt->details);
|
||||
|
||||
// add details of this attempt
|
||||
hotpot_add_attempt_details($attempt);
|
||||
|
||||
// add slashes again, so the details can be added to the database
|
||||
$attempt->details = addslashes($attempt->details);
|
||||
|
||||
if (! update_record("hotpot_attempts", $attempt)) {
|
||||
error("Could not update attempt record: ".$db->ErrorMsg(), $next_url);
|
||||
}
|
||||
|
||||
// set previously unfinished attempts of this quiz by this user to "finished"
|
||||
hotpot_close_previous_attempts($hotpot->id, $USER->id, $time);
|
||||
|
||||
add_to_log($course->id, "hotpot", "submit", "review.php?id=$cm->id&attempt=$attempt->id", "$hotpot->id", "$cm->id");
|
||||
}
|
||||
if ($hotpot->shownextquiz==HOTPOT_YES && is_numeric($next_cm = hotpot_get_next_cm($cm))) {
|
||||
$next_url = "$CFG->wwwroot/mod/hotpot/view.php?id=$next_cm";
|
||||
}
|
||||
}
|
||||
|
||||
// redirect to the next quiz or the course page
|
||||
redirect($next_url, $msg);
|
||||
|
||||
|
||||
// =================
|
||||
// functions
|
||||
// =================
|
||||
|
||||
function hotpot_get_next_cm(&$cm) {
|
||||
// gets the next module in this section of the course
|
||||
// that is the same type of module as the current module
|
||||
|
||||
$next_mod = false;
|
||||
|
||||
// get a list of $ids of modules in this section
|
||||
if ($ids = get_field('course_sections', 'sequence', 'id', $cm->section)) {
|
||||
|
||||
$ids = explode(',', $ids);
|
||||
$found = false;
|
||||
foreach ($ids as $id) {
|
||||
if ($found && ($cm->module==get_field('course_modules', 'module', 'id', $id))) {
|
||||
$next_mod = $id;
|
||||
break;
|
||||
} else if ($cm->id==$id) {
|
||||
$found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $next_mod;
|
||||
}
|
||||
?>
|
||||
|
||||
+185
-185
@@ -1,185 +1,185 @@
|
||||
<?PHP //$Id$
|
||||
//This php script contains all the stuff to backup/restore
|
||||
//quiz mods
|
||||
|
||||
//-----------------------------------------------------------
|
||||
// This is the "graphical" structure of the hotpot mod:
|
||||
//-----------------------------------------------------------
|
||||
//
|
||||
// hotpot
|
||||
// (CL, pk->id, files)
|
||||
// |
|
||||
// +--------------+--------------+
|
||||
// | |
|
||||
// | |
|
||||
// hotpot_attempts hotpot_questions
|
||||
// (UL, pk->id, (UL, pk->id,
|
||||
// fk->hotpot) fk->hotpot, text)
|
||||
// | | |
|
||||
// | | |
|
||||
// +--------------+--------------+ |
|
||||
// | |
|
||||
// | |
|
||||
// hotpot_responses |
|
||||
// (UL, pk->id, |
|
||||
// fk->attempt, question, |
|
||||
// correct, wrong, ignored) |
|
||||
// | |
|
||||
// | |
|
||||
// +-----------+-----------+
|
||||
// |
|
||||
// hotpot_strings
|
||||
// (UL, pk->id)
|
||||
//
|
||||
// Meaning: pk->primary key field of the table
|
||||
// fk->foreign key to link with parent
|
||||
// nt->nested field (recursive data)
|
||||
// CL->course level info
|
||||
// UL->user level info
|
||||
// files->table may have files
|
||||
//
|
||||
//-----------------------------------------------------------
|
||||
// It is not necessary to backup "questions", "responses"
|
||||
// and "strings", because they can be restored from the
|
||||
// "details" field of the "attempts" records
|
||||
//-----------------------------------------------------------
|
||||
|
||||
function hotpot_backup_mods($bf, $preferences) {
|
||||
|
||||
$level = 3;
|
||||
$status = true;
|
||||
|
||||
$table = 'hotpot';
|
||||
$field = 'course';
|
||||
$value = $preferences->backup_course;
|
||||
|
||||
$modtype = 'hotpot';
|
||||
|
||||
$records_tag = '';
|
||||
$records_tags = array();
|
||||
|
||||
$record_tag = 'MOD';
|
||||
$record_tags = array('MODTYPE'=>$modtype);
|
||||
|
||||
$excluded_tags = array();
|
||||
|
||||
$more_backup = '';
|
||||
if ($preferences->mods[$modtype]->userinfo) {
|
||||
$more_backup .= $modtype.'_backup_attempts($bf, $record, $level, $status);';
|
||||
}
|
||||
|
||||
return hotpot_backup_records(
|
||||
$bf, $status, $level,
|
||||
$table, $field, $value,
|
||||
$records_tag, $records_tags,
|
||||
$record_tag, $record_tags,
|
||||
$excluded_tags, $more_backup
|
||||
);
|
||||
}
|
||||
function hotpot_backup_attempts($bf, &$parent, $level, $status) {
|
||||
// $parent is a reference to a hotpot record
|
||||
|
||||
$table = 'hotpot_attempts';
|
||||
$field = 'hotpot';
|
||||
$value = $parent->id;
|
||||
|
||||
$records_tag = 'ATTEMPT_DATA';
|
||||
$records_tags = array();
|
||||
|
||||
$record_tag = 'ATTEMPT';
|
||||
$record_tags = array();
|
||||
|
||||
$more_backup = '';
|
||||
$excluded_tags = array();
|
||||
|
||||
return hotpot_backup_records(
|
||||
$bf, $status, $level,
|
||||
$table, $field, $value,
|
||||
$records_tag, $records_tags,
|
||||
$record_tag, $record_tags,
|
||||
$excluded_tags, $more_backup
|
||||
);
|
||||
}
|
||||
|
||||
function hotpot_backup_records(&$bf, $status, $level, $table, $field, $value, $records_tag, $records_tags, $record_tag, $record_tags, $excluded_tags, $more_backup) {
|
||||
|
||||
// If any of the "fwrite" statements fail,
|
||||
// no further "fwrite"s will be attempted
|
||||
// and the function returns "false".
|
||||
// Otherwise, the function returns "true".
|
||||
|
||||
if ($status && ($records = get_records($table, $field, $value, 'id'))) {
|
||||
|
||||
// start a group of records
|
||||
if ($records_tag) {
|
||||
$status = $status && fwrite($bf, start_tag($records_tag, $level, true));
|
||||
$level++;
|
||||
|
||||
foreach ($records_tags as $tag) {
|
||||
$status = $status && fwrite($bf, full_tag($tag, $level, false, $value));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($records as $record) {
|
||||
|
||||
// start a single record
|
||||
if ($record_tag) {
|
||||
$status = $status && fwrite($bf, start_tag($record_tag, $level, true));
|
||||
$level++;
|
||||
|
||||
foreach ($record_tags as $tag=>$value) {
|
||||
$status = $status && fwrite($bf, full_tag($tag, $level, false, $value));
|
||||
}
|
||||
}
|
||||
|
||||
// backup fields in this record
|
||||
$tags = get_object_vars($record);
|
||||
foreach ($tags as $tag=>$value) {
|
||||
if (!is_numeric($tag) && !in_array($tag, $excluded_tags)) {
|
||||
$status = $status && fwrite($bf, full_tag($tag, $level, false, $value));
|
||||
}
|
||||
}
|
||||
|
||||
// backup related records, if required
|
||||
if ($more_backup) {
|
||||
eval($more_backup);
|
||||
}
|
||||
|
||||
// end a single record
|
||||
if ($record_tag) {
|
||||
$level--;
|
||||
$status = $status && fwrite($bf, end_tag($record_tag, $level, true));
|
||||
}
|
||||
}
|
||||
|
||||
// end a group of records
|
||||
if ($records_tag) {
|
||||
$level--;
|
||||
$status = $status && fwrite($bf, end_tag($records_tag, $level, true));
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
////Return an array of info (name, value)
|
||||
function hotpot_check_backup_mods($course, $user_data=false, $backup_unique_code) {
|
||||
|
||||
// the course data
|
||||
$info[0][0] = get_string('modulenameplural','hotpot');
|
||||
$info[0][1] = count_records('hotpot', 'course', $course);
|
||||
|
||||
// the user_data, if requested
|
||||
if ($user_data) {
|
||||
global $CFG;
|
||||
$table = "{$CFG->prefix}hotpot h, {$CFG->prefix}hotpot_attempts a";
|
||||
$select = "h.course = $course AND h.id = a.hotpot";
|
||||
|
||||
$info[1][0] = get_string('attempts', 'quiz');
|
||||
$info[1][1] = count_records_sql("SELECT COUNT(*) FROM $table WHERE $select");
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
?>
|
||||
<?PHP //$Id$
|
||||
//This php script contains all the stuff to backup/restore
|
||||
//quiz mods
|
||||
|
||||
//-----------------------------------------------------------
|
||||
// This is the "graphical" structure of the hotpot mod:
|
||||
//-----------------------------------------------------------
|
||||
//
|
||||
// hotpot
|
||||
// (CL, pk->id, files)
|
||||
// |
|
||||
// +--------------+--------------+
|
||||
// | |
|
||||
// | |
|
||||
// hotpot_attempts hotpot_questions
|
||||
// (UL, pk->id, (UL, pk->id,
|
||||
// fk->hotpot) fk->hotpot, text)
|
||||
// | | |
|
||||
// | | |
|
||||
// +--------------+--------------+ |
|
||||
// | |
|
||||
// | |
|
||||
// hotpot_responses |
|
||||
// (UL, pk->id, |
|
||||
// fk->attempt, question, |
|
||||
// correct, wrong, ignored) |
|
||||
// | |
|
||||
// | |
|
||||
// +-----------+-----------+
|
||||
// |
|
||||
// hotpot_strings
|
||||
// (UL, pk->id)
|
||||
//
|
||||
// Meaning: pk->primary key field of the table
|
||||
// fk->foreign key to link with parent
|
||||
// nt->nested field (recursive data)
|
||||
// CL->course level info
|
||||
// UL->user level info
|
||||
// files->table may have files
|
||||
//
|
||||
//-----------------------------------------------------------
|
||||
// It is not necessary to backup "questions", "responses"
|
||||
// and "strings", because they can be restored from the
|
||||
// "details" field of the "attempts" records
|
||||
//-----------------------------------------------------------
|
||||
|
||||
function hotpot_backup_mods($bf, $preferences) {
|
||||
|
||||
$level = 3;
|
||||
$status = true;
|
||||
|
||||
$table = 'hotpot';
|
||||
$field = 'course';
|
||||
$value = $preferences->backup_course;
|
||||
|
||||
$modtype = 'hotpot';
|
||||
|
||||
$records_tag = '';
|
||||
$records_tags = array();
|
||||
|
||||
$record_tag = 'MOD';
|
||||
$record_tags = array('MODTYPE'=>$modtype);
|
||||
|
||||
$excluded_tags = array();
|
||||
|
||||
$more_backup = '';
|
||||
if ($preferences->mods[$modtype]->userinfo) {
|
||||
$more_backup .= $modtype.'_backup_attempts($bf, $record, $level, $status);';
|
||||
}
|
||||
|
||||
return hotpot_backup_records(
|
||||
$bf, $status, $level,
|
||||
$table, $field, $value,
|
||||
$records_tag, $records_tags,
|
||||
$record_tag, $record_tags,
|
||||
$excluded_tags, $more_backup
|
||||
);
|
||||
}
|
||||
function hotpot_backup_attempts($bf, &$parent, $level, $status) {
|
||||
// $parent is a reference to a hotpot record
|
||||
|
||||
$table = 'hotpot_attempts';
|
||||
$field = 'hotpot';
|
||||
$value = $parent->id;
|
||||
|
||||
$records_tag = 'ATTEMPT_DATA';
|
||||
$records_tags = array();
|
||||
|
||||
$record_tag = 'ATTEMPT';
|
||||
$record_tags = array();
|
||||
|
||||
$more_backup = '';
|
||||
$excluded_tags = array();
|
||||
|
||||
return hotpot_backup_records(
|
||||
$bf, $status, $level,
|
||||
$table, $field, $value,
|
||||
$records_tag, $records_tags,
|
||||
$record_tag, $record_tags,
|
||||
$excluded_tags, $more_backup
|
||||
);
|
||||
}
|
||||
|
||||
function hotpot_backup_records(&$bf, $status, $level, $table, $field, $value, $records_tag, $records_tags, $record_tag, $record_tags, $excluded_tags, $more_backup) {
|
||||
|
||||
// If any of the "fwrite" statements fail,
|
||||
// no further "fwrite"s will be attempted
|
||||
// and the function returns "false".
|
||||
// Otherwise, the function returns "true".
|
||||
|
||||
if ($status && ($records = get_records($table, $field, $value, 'id'))) {
|
||||
|
||||
// start a group of records
|
||||
if ($records_tag) {
|
||||
$status = $status && fwrite($bf, start_tag($records_tag, $level, true));
|
||||
$level++;
|
||||
|
||||
foreach ($records_tags as $tag) {
|
||||
$status = $status && fwrite($bf, full_tag($tag, $level, false, $value));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($records as $record) {
|
||||
|
||||
// start a single record
|
||||
if ($record_tag) {
|
||||
$status = $status && fwrite($bf, start_tag($record_tag, $level, true));
|
||||
$level++;
|
||||
|
||||
foreach ($record_tags as $tag=>$value) {
|
||||
$status = $status && fwrite($bf, full_tag($tag, $level, false, $value));
|
||||
}
|
||||
}
|
||||
|
||||
// backup fields in this record
|
||||
$tags = get_object_vars($record);
|
||||
foreach ($tags as $tag=>$value) {
|
||||
if (!is_numeric($tag) && !in_array($tag, $excluded_tags)) {
|
||||
$status = $status && fwrite($bf, full_tag($tag, $level, false, $value));
|
||||
}
|
||||
}
|
||||
|
||||
// backup related records, if required
|
||||
if ($more_backup) {
|
||||
eval($more_backup);
|
||||
}
|
||||
|
||||
// end a single record
|
||||
if ($record_tag) {
|
||||
$level--;
|
||||
$status = $status && fwrite($bf, end_tag($record_tag, $level, true));
|
||||
}
|
||||
}
|
||||
|
||||
// end a group of records
|
||||
if ($records_tag) {
|
||||
$level--;
|
||||
$status = $status && fwrite($bf, end_tag($records_tag, $level, true));
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
////Return an array of info (name, value)
|
||||
function hotpot_check_backup_mods($course, $user_data=false, $backup_unique_code) {
|
||||
|
||||
// the course data
|
||||
$info[0][0] = get_string('modulenameplural','hotpot');
|
||||
$info[0][1] = count_records('hotpot', 'course', $course);
|
||||
|
||||
// the user_data, if requested
|
||||
if ($user_data) {
|
||||
global $CFG;
|
||||
$table = "{$CFG->prefix}hotpot h, {$CFG->prefix}hotpot_attempts a";
|
||||
$select = "h.course = $course AND h.id = a.hotpot";
|
||||
|
||||
$info[1][0] = get_string('attempts', 'quiz');
|
||||
$info[1][1] = count_records_sql("SELECT COUNT(*) FROM $table WHERE $select");
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php // $Id$
|
||||
if (empty($CFG->hotpot_initialdisable)) {
|
||||
if (!count_records('hotpot')) {
|
||||
set_field('modules', 'visible', 0, 'name', 'hotpot'); // Disable it by default
|
||||
|
||||
+230
-230
@@ -1,230 +1,230 @@
|
||||
<?PHP // $Id$
|
||||
|
||||
// This page lists all the instances of hotpot in a particular course
|
||||
|
||||
require_once("../../config.php");
|
||||
require_once("lib.php");
|
||||
|
||||
$id = required_param("id"); // course
|
||||
|
||||
if (! $course = get_record("course", "id", $id)) {
|
||||
error("Course ID is incorrect");
|
||||
}
|
||||
|
||||
require_login($course->id);
|
||||
|
||||
add_to_log($course->id, "hotpot", "view all", "index.php?id=$course->id", "");
|
||||
|
||||
// Print the header
|
||||
|
||||
$strmodulenameplural = get_string("modulenameplural", "hotpot");
|
||||
$strmodulename = get_string("modulename", "hotpot");
|
||||
|
||||
$title = "$course->shortname: $strmodulenameplural";
|
||||
$heading = "$course->fullname";
|
||||
$navigation = "$strmodulenameplural";
|
||||
if ($course->category) {
|
||||
$navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> -> $navigation";
|
||||
}
|
||||
print_header($title, $heading, $navigation, "", "", true, "", navmenu($course));
|
||||
|
||||
$next_url = "$CFG->wwwroot/course/view.php?id=$course->id";
|
||||
|
||||
// Get all instances of this module
|
||||
if (! $hotpots = get_all_instances_in_course("hotpot", $course)) {
|
||||
notice("There are no $strmodulenameplural", $next_url);
|
||||
die;
|
||||
}
|
||||
|
||||
if (isadmin()) {
|
||||
if (isset($_POST['regrade'])) {
|
||||
$hotpotids = array();
|
||||
foreach ($hotpots as $hotpot) {
|
||||
$hotpotids[] = $hotpot->id;
|
||||
}
|
||||
$hotpotids = implode(',', $hotpotids);
|
||||
|
||||
$select = "hotpot IN ($hotpotids)";
|
||||
|
||||
$questionids = array();
|
||||
if ($questions = get_records_select("hotpot_questions", $select)) {
|
||||
$questionids = array_keys($questions);
|
||||
}
|
||||
$questionids = implode(',', $questionids);
|
||||
|
||||
if ($questionids) {
|
||||
hotpot_delete_and_notify(
|
||||
'hotpot_questions',
|
||||
"id IN ($questionids)",
|
||||
get_string('question', 'quiz')
|
||||
);
|
||||
hotpot_delete_and_notify(
|
||||
'hotpot_responses',
|
||||
"question IN ($questionids)",
|
||||
get_string('answer', 'quiz')
|
||||
);
|
||||
}
|
||||
|
||||
if ($attempts = get_records_select('hotpot_attempts', $select)) {
|
||||
$count = 0;
|
||||
foreach ($attempts as $attempt) {
|
||||
if (isset($attempt->score)) {
|
||||
hotpot_add_attempt_details($attempt);
|
||||
$attempt->details = addslashes($attempt->details);
|
||||
if (! update_record('hotpot_attempts', $attempt)) {
|
||||
error("Could not update attempt record: ".$db->ErrorMsg(), $next_url);
|
||||
}
|
||||
$count++;
|
||||
if ($count%10 == 0) {
|
||||
print ".";
|
||||
if ($count%200 == 0) {
|
||||
print "<br>\n";
|
||||
}
|
||||
hotpot_flush(300);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($count) {
|
||||
notify(get_string('added', 'moodle', "$count x ".get_string('attempts', 'quiz')));
|
||||
}
|
||||
notify(get_string('regradecomplete', 'quiz'));
|
||||
}
|
||||
}
|
||||
print '<center><form action="'.$ME.'" method="post">';
|
||||
print '<input type="hidden" name="id" value="'.$course->id.'">';
|
||||
print '<input type="submit" name="regrade" value="'.get_string('regrade', 'quiz').'">';
|
||||
print '</form></center>'."\n";
|
||||
}
|
||||
|
||||
// Print the list of instances of this module
|
||||
|
||||
$timenow = time();
|
||||
$strupdate = get_string("update");
|
||||
$strusers = get_string("users");
|
||||
|
||||
// Moodle 1.4+ requires sesskey to be passed in forms
|
||||
if (isset($USER->sesskey)) {
|
||||
$sesskey = '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
|
||||
} else {
|
||||
$sesskey = '';
|
||||
}
|
||||
|
||||
// column headings and attributes
|
||||
$table->head = array();
|
||||
$table->align = array();
|
||||
|
||||
switch ($course->format) {
|
||||
case 'weeks' :
|
||||
$title = get_string("week");
|
||||
break;
|
||||
case 'topics' :
|
||||
$title = get_string("topic");
|
||||
break;
|
||||
default :
|
||||
$title = '';
|
||||
break;
|
||||
}
|
||||
if ($title) {
|
||||
array_push($table->head, $title);
|
||||
array_push($table->align, "center");
|
||||
}
|
||||
if (isteacheredit($course->id)) {
|
||||
array_push($table->head, $strupdate);
|
||||
array_push($table->align, "center");
|
||||
}
|
||||
array_push($table->head,
|
||||
get_string("name"),
|
||||
get_string("quizcloses", "quiz"),
|
||||
get_string("bestgrade", "quiz"),
|
||||
get_string("attempts", "quiz")
|
||||
);
|
||||
array_push($table->align, "left", "left", "center", "left");
|
||||
|
||||
$currentsection = "";
|
||||
foreach ($hotpots as $hotpot) {
|
||||
|
||||
$printsection = "";
|
||||
if ($hotpot->section !== $currentsection) {
|
||||
if ($hotpot->section) {
|
||||
$printsection = $hotpot->section;
|
||||
}
|
||||
if ($currentsection !== "") {
|
||||
$table->data[] = 'hr';
|
||||
}
|
||||
$currentsection = $hotpot->section;
|
||||
}
|
||||
|
||||
$class = ($hotpot->visible) ? '' : 'class="dimmed" ';
|
||||
$quizname = '<A '.$class.'href="view.php?id='.$hotpot->coursemodule.'">'.$hotpot->name.'</A>';
|
||||
$quizclose = userdate($hotpot->timeclose);
|
||||
|
||||
$select = isteacher($course->id) ? '' : "userid='$USER->id' AND ";
|
||||
$select .= "hotpot='$hotpot->id' AND timefinish>0";
|
||||
|
||||
$attempttable = "{$CFG->prefix}hotpot_attempts";
|
||||
|
||||
// get number of attempts. if any
|
||||
if ($attemptcount = count_records_sql("SELECT COUNT(*) FROM $attempttable WHERE $select")) {
|
||||
|
||||
// report number of attempts (and users)
|
||||
$report = get_string("viewallreports","quiz", $attemptcount);
|
||||
if (isteacher($course->id)) {
|
||||
$usercount = count_records_sql("SELECT COUNT(DISTINCT userid) FROM $attempttable WHERE $select");
|
||||
$report .= " ($usercount $strusers)";
|
||||
}
|
||||
$report = '<a href="report.php?hp='.$hotpot->id.'">'.$report.'</a>';
|
||||
|
||||
// get best score
|
||||
$bestscore = count_records_sql("SELECT MAX(score) FROM $attempttable WHERE $select");
|
||||
if (is_numeric($bestscore)) {
|
||||
$bestscore .= " / $hotpot->grade";
|
||||
} else {
|
||||
$bestscore = " ";
|
||||
}
|
||||
} else { // no attempts
|
||||
$report = " ";
|
||||
$bestscore = " ";
|
||||
}
|
||||
|
||||
$data = array ();
|
||||
|
||||
if ($course->format=="weeks" || $course->format=="topics") {
|
||||
array_push($data, $printsection);
|
||||
}
|
||||
|
||||
if (isteacheredit($course->id)) {
|
||||
$update = ''
|
||||
. '<form target="_parent" method="get" action="'.$CFG->wwwroot.'/course/mod.php">'
|
||||
. '<input type="hidden" name="update" value="'.$hotpot->coursemodule.'" />'
|
||||
. $sesskey
|
||||
. '<input type="submit" value="'.$strupdate.'" />'
|
||||
. '</form>'
|
||||
;
|
||||
array_push($data, $update);
|
||||
}
|
||||
array_push($data, $quizname, $quizclose, $bestscore, $report);
|
||||
$table->data[] = $data;
|
||||
}
|
||||
|
||||
echo "<br />";
|
||||
|
||||
print_table($table);
|
||||
|
||||
// Finish the page
|
||||
print_footer($course);
|
||||
|
||||
///////////////////
|
||||
// functions
|
||||
|
||||
function hotpot_flush($n=0, $time=false) {
|
||||
if ($time) {
|
||||
$ti = strftime("%X",time());
|
||||
} else {
|
||||
$ti = "";
|
||||
}
|
||||
echo str_repeat(" ", $n) . $ti . "\n";
|
||||
flush();
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<?PHP // $Id$
|
||||
|
||||
// This page lists all the instances of hotpot in a particular course
|
||||
|
||||
require_once("../../config.php");
|
||||
require_once("lib.php");
|
||||
|
||||
$id = required_param("id"); // course
|
||||
|
||||
if (! $course = get_record("course", "id", $id)) {
|
||||
error("Course ID is incorrect");
|
||||
}
|
||||
|
||||
require_login($course->id);
|
||||
|
||||
add_to_log($course->id, "hotpot", "view all", "index.php?id=$course->id", "");
|
||||
|
||||
// Print the header
|
||||
|
||||
$strmodulenameplural = get_string("modulenameplural", "hotpot");
|
||||
$strmodulename = get_string("modulename", "hotpot");
|
||||
|
||||
$title = "$course->shortname: $strmodulenameplural";
|
||||
$heading = "$course->fullname";
|
||||
$navigation = "$strmodulenameplural";
|
||||
if ($course->category) {
|
||||
$navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> -> $navigation";
|
||||
}
|
||||
print_header($title, $heading, $navigation, "", "", true, "", navmenu($course));
|
||||
|
||||
$next_url = "$CFG->wwwroot/course/view.php?id=$course->id";
|
||||
|
||||
// Get all instances of this module
|
||||
if (! $hotpots = get_all_instances_in_course("hotpot", $course)) {
|
||||
notice("There are no $strmodulenameplural", $next_url);
|
||||
die;
|
||||
}
|
||||
|
||||
if (isadmin()) {
|
||||
if (isset($_POST['regrade'])) {
|
||||
$hotpotids = array();
|
||||
foreach ($hotpots as $hotpot) {
|
||||
$hotpotids[] = $hotpot->id;
|
||||
}
|
||||
$hotpotids = implode(',', $hotpotids);
|
||||
|
||||
$select = "hotpot IN ($hotpotids)";
|
||||
|
||||
$questionids = array();
|
||||
if ($questions = get_records_select("hotpot_questions", $select)) {
|
||||
$questionids = array_keys($questions);
|
||||
}
|
||||
$questionids = implode(',', $questionids);
|
||||
|
||||
if ($questionids) {
|
||||
hotpot_delete_and_notify(
|
||||
'hotpot_questions',
|
||||
"id IN ($questionids)",
|
||||
get_string('question', 'quiz')
|
||||
);
|
||||
hotpot_delete_and_notify(
|
||||
'hotpot_responses',
|
||||
"question IN ($questionids)",
|
||||
get_string('answer', 'quiz')
|
||||
);
|
||||
}
|
||||
|
||||
if ($attempts = get_records_select('hotpot_attempts', $select)) {
|
||||
$count = 0;
|
||||
foreach ($attempts as $attempt) {
|
||||
if (isset($attempt->score)) {
|
||||
hotpot_add_attempt_details($attempt);
|
||||
$attempt->details = addslashes($attempt->details);
|
||||
if (! update_record('hotpot_attempts', $attempt)) {
|
||||
error("Could not update attempt record: ".$db->ErrorMsg(), $next_url);
|
||||
}
|
||||
$count++;
|
||||
if ($count%10 == 0) {
|
||||
print ".";
|
||||
if ($count%200 == 0) {
|
||||
print "<br>\n";
|
||||
}
|
||||
hotpot_flush(300);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($count) {
|
||||
notify(get_string('added', 'moodle', "$count x ".get_string('attempts', 'quiz')));
|
||||
}
|
||||
notify(get_string('regradecomplete', 'quiz'));
|
||||
}
|
||||
}
|
||||
print '<center><form action="'.$ME.'" method="post">';
|
||||
print '<input type="hidden" name="id" value="'.$course->id.'">';
|
||||
print '<input type="submit" name="regrade" value="'.get_string('regrade', 'quiz').'">';
|
||||
print '</form></center>'."\n";
|
||||
}
|
||||
|
||||
// Print the list of instances of this module
|
||||
|
||||
$timenow = time();
|
||||
$strupdate = get_string("update");
|
||||
$strusers = get_string("users");
|
||||
|
||||
// Moodle 1.4+ requires sesskey to be passed in forms
|
||||
if (isset($USER->sesskey)) {
|
||||
$sesskey = '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
|
||||
} else {
|
||||
$sesskey = '';
|
||||
}
|
||||
|
||||
// column headings and attributes
|
||||
$table->head = array();
|
||||
$table->align = array();
|
||||
|
||||
switch ($course->format) {
|
||||
case 'weeks' :
|
||||
$title = get_string("week");
|
||||
break;
|
||||
case 'topics' :
|
||||
$title = get_string("topic");
|
||||
break;
|
||||
default :
|
||||
$title = '';
|
||||
break;
|
||||
}
|
||||
if ($title) {
|
||||
array_push($table->head, $title);
|
||||
array_push($table->align, "center");
|
||||
}
|
||||
if (isteacheredit($course->id)) {
|
||||
array_push($table->head, $strupdate);
|
||||
array_push($table->align, "center");
|
||||
}
|
||||
array_push($table->head,
|
||||
get_string("name"),
|
||||
get_string("quizcloses", "quiz"),
|
||||
get_string("bestgrade", "quiz"),
|
||||
get_string("attempts", "quiz")
|
||||
);
|
||||
array_push($table->align, "left", "left", "center", "left");
|
||||
|
||||
$currentsection = "";
|
||||
foreach ($hotpots as $hotpot) {
|
||||
|
||||
$printsection = "";
|
||||
if ($hotpot->section !== $currentsection) {
|
||||
if ($hotpot->section) {
|
||||
$printsection = $hotpot->section;
|
||||
}
|
||||
if ($currentsection !== "") {
|
||||
$table->data[] = 'hr';
|
||||
}
|
||||
$currentsection = $hotpot->section;
|
||||
}
|
||||
|
||||
$class = ($hotpot->visible) ? '' : 'class="dimmed" ';
|
||||
$quizname = '<A '.$class.'href="view.php?id='.$hotpot->coursemodule.'">'.$hotpot->name.'</A>';
|
||||
$quizclose = userdate($hotpot->timeclose);
|
||||
|
||||
$select = isteacher($course->id) ? '' : "userid='$USER->id' AND ";
|
||||
$select .= "hotpot='$hotpot->id' AND timefinish>0";
|
||||
|
||||
$attempttable = "{$CFG->prefix}hotpot_attempts";
|
||||
|
||||
// get number of attempts. if any
|
||||
if ($attemptcount = count_records_sql("SELECT COUNT(*) FROM $attempttable WHERE $select")) {
|
||||
|
||||
// report number of attempts (and users)
|
||||
$report = get_string("viewallreports","quiz", $attemptcount);
|
||||
if (isteacher($course->id)) {
|
||||
$usercount = count_records_sql("SELECT COUNT(DISTINCT userid) FROM $attempttable WHERE $select");
|
||||
$report .= " ($usercount $strusers)";
|
||||
}
|
||||
$report = '<a href="report.php?hp='.$hotpot->id.'">'.$report.'</a>';
|
||||
|
||||
// get best score
|
||||
$bestscore = count_records_sql("SELECT MAX(score) FROM $attempttable WHERE $select");
|
||||
if (is_numeric($bestscore)) {
|
||||
$bestscore .= " / $hotpot->grade";
|
||||
} else {
|
||||
$bestscore = " ";
|
||||
}
|
||||
} else { // no attempts
|
||||
$report = " ";
|
||||
$bestscore = " ";
|
||||
}
|
||||
|
||||
$data = array ();
|
||||
|
||||
if ($course->format=="weeks" || $course->format=="topics") {
|
||||
array_push($data, $printsection);
|
||||
}
|
||||
|
||||
if (isteacheredit($course->id)) {
|
||||
$update = ''
|
||||
. '<form target="_parent" method="get" action="'.$CFG->wwwroot.'/course/mod.php">'
|
||||
. '<input type="hidden" name="update" value="'.$hotpot->coursemodule.'" />'
|
||||
. $sesskey
|
||||
. '<input type="submit" value="'.$strupdate.'" />'
|
||||
. '</form>'
|
||||
;
|
||||
array_push($data, $update);
|
||||
}
|
||||
array_push($data, $quizname, $quizclose, $bestscore, $report);
|
||||
$table->data[] = $data;
|
||||
}
|
||||
|
||||
echo "<br />";
|
||||
|
||||
print_table($table);
|
||||
|
||||
// Finish the page
|
||||
print_footer($course);
|
||||
|
||||
///////////////////
|
||||
// functions
|
||||
|
||||
function hotpot_flush($n=0, $time=false) {
|
||||
if ($time) {
|
||||
$ti = strftime("%X",time());
|
||||
} else {
|
||||
$ti = "";
|
||||
}
|
||||
echo str_repeat(" ", $n) . $ti . "\n";
|
||||
flush();
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
+2855
-2855
File diff suppressed because it is too large
Load Diff
+378
-378
@@ -1,378 +1,378 @@
|
||||
<?PHP // $Id$
|
||||
|
||||
// This script uses installed report plugins to print quiz reports
|
||||
|
||||
require_once("../../config.php");
|
||||
require_once("lib.php");
|
||||
|
||||
$id = optional_param("id"); // Course Module ID, or
|
||||
$hp = optional_param("hp"); // hotpot ID
|
||||
|
||||
if ($id) {
|
||||
if (! $cm = get_record("course_modules", "id", $id)) {
|
||||
error("Course Module ID was incorrect");
|
||||
}
|
||||
if (! $course = get_record("course", "id", $cm->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");
|
||||
}
|
||||
}
|
||||
|
||||
// set homeurl of couse (for error messages)
|
||||
$course_homeurl = "$CFG->wwwroot/course/view.php?id=$course->id";
|
||||
|
||||
require_login($course->id);
|
||||
|
||||
// get report mode
|
||||
if (isteacher($course->id)) {
|
||||
$mode = optional_param("mode", "overview", 0);
|
||||
if (is_array($mode)) {
|
||||
$mode = array_keys($mode);
|
||||
$mode = $mode[0];
|
||||
}
|
||||
} else {
|
||||
// students have no choice
|
||||
$mode = 'overview';
|
||||
}
|
||||
|
||||
// get report attributes
|
||||
if (isadmin()) {
|
||||
$reportcourse = optional_param("reportcourse", "this");
|
||||
} else {
|
||||
// students and ordinary teachers have no choice
|
||||
$reportcourse = 'this';
|
||||
}
|
||||
if (isteacher($course->id)) {
|
||||
$reportusers = optional_param("reportusers", "all");
|
||||
} else {
|
||||
// students have no choice
|
||||
$reportusers = 'this';
|
||||
}
|
||||
$reportattempts = optional_param("reportattempts", "all");
|
||||
|
||||
/// Start the report
|
||||
|
||||
add_to_log($course->id, "hotpot", "report", "report.php?id=$cm->id", "$hotpot->id", "$cm->id");
|
||||
|
||||
// print page header. if required
|
||||
if (empty($noheader)) {
|
||||
hotpot_print_report_heading($course, $cm, $hotpot, $mode);
|
||||
if (isteacher($course->id)) {
|
||||
hotpot_print_report_selector($course, $hotpot, $mode, $reportcourse, $reportusers, $reportattempts);
|
||||
}
|
||||
}
|
||||
|
||||
// delete selected attempts, if any
|
||||
if (isteacher($course->id)) {
|
||||
$del = optional_param("del", "");
|
||||
hotpot_delete_selected_attempts($hotpot, $del);
|
||||
}
|
||||
|
||||
$hotpot_ids = '';
|
||||
$course_ids = '';
|
||||
switch ($reportcourse) {
|
||||
case 'this':
|
||||
$course_ids = $course->id;
|
||||
$hotpot_ids = $hotpot->id;
|
||||
break;
|
||||
case 'all' :
|
||||
$records = get_records_select_menu('user_teachers', "userid='$USER->id'", 'course', 'id, course');
|
||||
$course_ids = join(',', array_values($records));
|
||||
|
||||
$records = get_records_select_menu('hotpot', "reference='$hotpot->reference'", 'reference', 'id, reference');
|
||||
$hotpot_ids = join(',', array_keys($records));
|
||||
break;
|
||||
}
|
||||
|
||||
$user_ids = '';
|
||||
$users = array();
|
||||
switch ($reportusers) {
|
||||
case 'all':
|
||||
$admin_ids = get_records_select_menu('user_admins');
|
||||
if (is_array($admin_ids)) {
|
||||
$users = array_merge($users, $admin_ids);
|
||||
}
|
||||
$creator_ids = get_records_select_menu('user_coursecreators');
|
||||
if (is_array($creator_ids)) {
|
||||
$users = array_merge($users, $creator_ids);
|
||||
}
|
||||
$teacher_ids = get_records_select_menu('user_teachers', "course IN ($course_ids)", 'course', 'id, userid');
|
||||
if (is_array($teacher_ids)) {
|
||||
$users = array_merge($users, $teacher_ids);
|
||||
}
|
||||
$guest_id = get_records_select_menu('user', "username='guest'", '', 'id,id');
|
||||
if (is_array($guest_id)) {
|
||||
$users = array_merge($users, $guest_id);
|
||||
}
|
||||
case 'students':
|
||||
$student_ids = get_records_select_menu('user_students', "course IN ($course_ids)", 'course', 'id, userid');
|
||||
if (is_array($student_ids)) {
|
||||
$users = array_merge($users, $student_ids);
|
||||
}
|
||||
$user_ids = join(',', array_values($users));
|
||||
break;
|
||||
case 'this':
|
||||
$user_ids = $USER->id;
|
||||
break;
|
||||
}
|
||||
|
||||
if (empty($user_ids)) {
|
||||
print_heading(get_string('nousersyet'));
|
||||
exit;
|
||||
}
|
||||
|
||||
// get attempts for these users
|
||||
$fields = 'a.*, u.firstname, u.lastname, u.picture';
|
||||
$table = "{$CFG->prefix}hotpot_attempts AS a, {$CFG->prefix}user AS u";
|
||||
$select = ($mode=='simplestat' || $mode=='fullstat') ? 'a.score IS NOT NULL' : 'a.timefinish>0';
|
||||
$select .= " AND a.hotpot IN ($hotpot_ids) AND a.userid IN ($user_ids) AND a.userid = u.id";
|
||||
$order = "u.lastname, a.attempt";
|
||||
if ($reportattempts=='best') {
|
||||
$fields .= ", MAX(a.score) AS grade";
|
||||
$select .= " GROUP BY a.userid";
|
||||
}
|
||||
$attempts = get_records_sql("SELECT $fields FROM $table WHERE $select ORDER BY $order");
|
||||
|
||||
if (empty($attempts)) {
|
||||
print_heading(get_string('noattempts','quiz'));
|
||||
exit;
|
||||
}
|
||||
|
||||
// get the questions
|
||||
if (!$questions = get_records_select('hotpot_questions', "hotpot='$hotpot->id'")) {
|
||||
$questions = array();
|
||||
}
|
||||
|
||||
// get grades
|
||||
$grades = hotpot_get_grades($hotpot, $user_ids);
|
||||
|
||||
// get list of attempts by user
|
||||
$users = array();
|
||||
foreach ($attempts as $id=>$attempt) {
|
||||
|
||||
$userid = $attempt->userid;
|
||||
|
||||
if (!isset($users[$userid])) {
|
||||
$grade = isset($grades[$userid]) ? $grades[$userid] : ' ';
|
||||
$users[$userid]->grade = $grade;
|
||||
$users[$userid]->attempts = array();
|
||||
}
|
||||
|
||||
$users[$userid]->attempts[] = &$attempts[$id];
|
||||
|
||||
}
|
||||
|
||||
/// Open the selected hotpot report and display it
|
||||
|
||||
$mode = clean_filename($mode);
|
||||
|
||||
if (! is_readable("report/$mode/report.php")) {
|
||||
error("Report not known (".clean_text($mode).")", $course_homeurl);
|
||||
}
|
||||
|
||||
include("report/default.php"); // Parent class
|
||||
include("report/$mode/report.php");
|
||||
|
||||
$report = new hotpot_report();
|
||||
|
||||
if (! $report->display($hotpot, $cm, $course, $users, $attempts, $questions)) {
|
||||
error("Error occurred during pre-processing!", $course_homeurl);
|
||||
}
|
||||
|
||||
if (empty($noheader)) {
|
||||
print_footer($course);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
/// functions to delete attempts and responses
|
||||
|
||||
function hotpot_grade_heading($hotpot, $download) {
|
||||
|
||||
global $HOTPOT_GRADEMETHOD;
|
||||
$grademethod = $HOTPOT_GRADEMETHOD[$hotpot->grademethod];
|
||||
|
||||
if ($hotpot->grade!=100) {
|
||||
$grademethod = "$hotpot->grade x $grademethod/100";
|
||||
}
|
||||
if (empty($download)) {
|
||||
$grademethod = '<FONT size="1">'.$grademethod.'</FONT>';
|
||||
}
|
||||
$nl = $download ? "\n" : '<br>';
|
||||
return get_string('grade')."$nl($grademethod)";
|
||||
}
|
||||
function hotpot_delete_selected_attempts(&$hotpot, $del) {
|
||||
|
||||
$select = '';
|
||||
switch ($del) {
|
||||
case 'all' :
|
||||
$select = "hotpot='$hotpot->id'";
|
||||
break;
|
||||
case 'abandoned':
|
||||
$select = "hotpot='$hotpot->id' AND timefinish>0 AND score IS NULL";
|
||||
break;
|
||||
case 'selection':
|
||||
$ids = (array)data_submitted();
|
||||
unset($ids['del']);
|
||||
unset($ids['id']);
|
||||
if (!empty($ids)) {
|
||||
$select = "hotpot='$hotpot->id' AND id IN (".implode(',', $ids).")";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// delete attempts using $select, if it is set
|
||||
if ($select) {
|
||||
|
||||
$table = 'hotpot_attempts';
|
||||
if ($attempts = get_records_select($table, $select)) {
|
||||
|
||||
hotpot_delete_and_notify($table, $select, get_string('attempts', 'quiz'));
|
||||
|
||||
$table = 'hotpot_responses';
|
||||
$select = 'attempt IN ('.implode(',', array_keys($attempts)).')';
|
||||
hotpot_delete_and_notify($table, $select, get_string('answer', 'quiz'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
/// functions to print the report headings and
|
||||
/// report selector menus
|
||||
|
||||
function hotpot_print_report_heading(&$course, &$cm, &$hotpot, &$mode) {
|
||||
$strmodulenameplural = get_string("modulenameplural", "hotpot");
|
||||
$strmodulename = get_string("modulename", "hotpot");
|
||||
|
||||
$title = "$course->shortname: $hotpot->name";
|
||||
$heading = "$course->fullname";
|
||||
|
||||
$navigation = "<a href=index.php?id=$course->id>$strmodulenameplural</a> -> ";
|
||||
$navigation .= "<a href=\"view.php?id=$cm->id\">$hotpot->name</a> -> ";
|
||||
if (isteacher($course->id)) {
|
||||
$navigation .= get_string("report$mode", "quiz");
|
||||
} else {
|
||||
$navigation .= get_string("report", "quiz");
|
||||
}
|
||||
if ($course->category) {
|
||||
$navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> -> $navigation";
|
||||
}
|
||||
$button = update_module_button($cm->id, $course->id, $strmodulename);
|
||||
|
||||
print_header($title, $heading, $navigation, "", "", true, $button, navmenu($course, $cm));
|
||||
|
||||
print_heading($hotpot->name);
|
||||
}
|
||||
function hotpot_print_report_selector(&$course, &$hotpot, &$mode, &$reportcourse, &$reportusers, &$reportattempts) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$reports = hotpot_get_report_names('overview,simplestat');
|
||||
|
||||
print '<form method="post" action="'."$CFG->wwwroot/mod/hotpot/report.php?hp=$hotpot->id".'">';
|
||||
print '<table cellpadding="4" align="center">';
|
||||
|
||||
$menus = array();
|
||||
if (isadmin()) {
|
||||
$menus['reportcourse'] = array(
|
||||
'this' => get_string('thiscourse', 'hotpot'),
|
||||
'all' => get_string('allmycourses', 'hotpot')
|
||||
);
|
||||
}
|
||||
$menus['reportusers'] = array(
|
||||
'students' => get_string('students'),
|
||||
'all' => get_string('allparticipants')
|
||||
);
|
||||
$menus['reportattempts'] = array(
|
||||
'best' => get_string('bestattempt', 'hotpot'),
|
||||
'all' => get_string('allattempts', 'hotpot')
|
||||
);
|
||||
|
||||
print '<tr><td align="center" colspan="'.count($reports).'">';
|
||||
foreach ($menus as $name => $options) {
|
||||
eval('$value=$'.$name.';');
|
||||
print choose_from_menu($options, $name, $value, "", "", 0, true);
|
||||
}
|
||||
if (isteacher($course->id)) {
|
||||
helpbutton('reportselector', get_string('report'), 'hotpot');
|
||||
}
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr>';
|
||||
foreach ($reports as $name) {
|
||||
print '<td><input type="submit" name="'."mode[$name]".'" value="'.get_string("report$name", "quiz").'"></td>';
|
||||
}
|
||||
print '</tr>';
|
||||
|
||||
print '</table>';
|
||||
|
||||
print '<hr size="1" noshade="noshade" />';
|
||||
print '</form>'."\n";
|
||||
}
|
||||
function hotpot_get_report_names($names='') {
|
||||
// $names : optional list showing required order reports names
|
||||
|
||||
$reports = array();
|
||||
|
||||
// convert $names to an array, if necessary (usually is)
|
||||
if (!is_array($names)) {
|
||||
$names = explode(',', $names);
|
||||
}
|
||||
|
||||
$plugins = get_list_of_plugins("mod/hotpot/report");
|
||||
foreach($names as $name) {
|
||||
if (is_numeric($i = array_search($name, $plugins))) {
|
||||
$reports[] = $name;
|
||||
unset($plugins[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
// append remaining plugins
|
||||
$reports = array_merge($reports, $plugins);
|
||||
|
||||
return $reports;
|
||||
}
|
||||
function hotpot_get_report_users($course_ids, $reportusers) {
|
||||
$users = array();
|
||||
|
||||
/// Check to see if groups are being used in this module
|
||||
$currentgroup = false;
|
||||
if ($groupmode = groupmode($course, $cm)) { // Groups are being used
|
||||
$currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id=$cm->id&mode=simplestat");
|
||||
}
|
||||
|
||||
$sort = "u.lastname ASC";
|
||||
|
||||
switch ($reportusers) {
|
||||
case 'students':
|
||||
if ($currentgroup) {
|
||||
$users = get_group_students($currentgroup, $sort);
|
||||
} else {
|
||||
$users = get_course_students($course->id, $sort);
|
||||
}
|
||||
break;
|
||||
case 'all':
|
||||
if ($currentgroup) {
|
||||
$users = get_group_users($currentgroup, $sort);
|
||||
} else {
|
||||
$users = get_course_users($course->id, $sort);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
?>
|
||||
<?PHP // $Id$
|
||||
|
||||
// This script uses installed report plugins to print quiz reports
|
||||
|
||||
require_once("../../config.php");
|
||||
require_once("lib.php");
|
||||
|
||||
$id = optional_param("id"); // Course Module ID, or
|
||||
$hp = optional_param("hp"); // hotpot ID
|
||||
|
||||
if ($id) {
|
||||
if (! $cm = get_record("course_modules", "id", $id)) {
|
||||
error("Course Module ID was incorrect");
|
||||
}
|
||||
if (! $course = get_record("course", "id", $cm->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");
|
||||
}
|
||||
}
|
||||
|
||||
// set homeurl of couse (for error messages)
|
||||
$course_homeurl = "$CFG->wwwroot/course/view.php?id=$course->id";
|
||||
|
||||
require_login($course->id);
|
||||
|
||||
// get report mode
|
||||
if (isteacher($course->id)) {
|
||||
$mode = optional_param("mode", "overview", 0);
|
||||
if (is_array($mode)) {
|
||||
$mode = array_keys($mode);
|
||||
$mode = $mode[0];
|
||||
}
|
||||
} else {
|
||||
// students have no choice
|
||||
$mode = 'overview';
|
||||
}
|
||||
|
||||
// get report attributes
|
||||
if (isadmin()) {
|
||||
$reportcourse = optional_param("reportcourse", "this");
|
||||
} else {
|
||||
// students and ordinary teachers have no choice
|
||||
$reportcourse = 'this';
|
||||
}
|
||||
if (isteacher($course->id)) {
|
||||
$reportusers = optional_param("reportusers", "all");
|
||||
} else {
|
||||
// students have no choice
|
||||
$reportusers = 'this';
|
||||
}
|
||||
$reportattempts = optional_param("reportattempts", "all");
|
||||
|
||||
/// Start the report
|
||||
|
||||
add_to_log($course->id, "hotpot", "report", "report.php?id=$cm->id", "$hotpot->id", "$cm->id");
|
||||
|
||||
// print page header. if required
|
||||
if (empty($noheader)) {
|
||||
hotpot_print_report_heading($course, $cm, $hotpot, $mode);
|
||||
if (isteacher($course->id)) {
|
||||
hotpot_print_report_selector($course, $hotpot, $mode, $reportcourse, $reportusers, $reportattempts);
|
||||
}
|
||||
}
|
||||
|
||||
// delete selected attempts, if any
|
||||
if (isteacher($course->id)) {
|
||||
$del = optional_param("del", "");
|
||||
hotpot_delete_selected_attempts($hotpot, $del);
|
||||
}
|
||||
|
||||
$hotpot_ids = '';
|
||||
$course_ids = '';
|
||||
switch ($reportcourse) {
|
||||
case 'this':
|
||||
$course_ids = $course->id;
|
||||
$hotpot_ids = $hotpot->id;
|
||||
break;
|
||||
case 'all' :
|
||||
$records = get_records_select_menu('user_teachers', "userid='$USER->id'", 'course', 'id, course');
|
||||
$course_ids = join(',', array_values($records));
|
||||
|
||||
$records = get_records_select_menu('hotpot', "reference='$hotpot->reference'", 'reference', 'id, reference');
|
||||
$hotpot_ids = join(',', array_keys($records));
|
||||
break;
|
||||
}
|
||||
|
||||
$user_ids = '';
|
||||
$users = array();
|
||||
switch ($reportusers) {
|
||||
case 'all':
|
||||
$admin_ids = get_records_select_menu('user_admins');
|
||||
if (is_array($admin_ids)) {
|
||||
$users = array_merge($users, $admin_ids);
|
||||
}
|
||||
$creator_ids = get_records_select_menu('user_coursecreators');
|
||||
if (is_array($creator_ids)) {
|
||||
$users = array_merge($users, $creator_ids);
|
||||
}
|
||||
$teacher_ids = get_records_select_menu('user_teachers', "course IN ($course_ids)", 'course', 'id, userid');
|
||||
if (is_array($teacher_ids)) {
|
||||
$users = array_merge($users, $teacher_ids);
|
||||
}
|
||||
$guest_id = get_records_select_menu('user', "username='guest'", '', 'id,id');
|
||||
if (is_array($guest_id)) {
|
||||
$users = array_merge($users, $guest_id);
|
||||
}
|
||||
case 'students':
|
||||
$student_ids = get_records_select_menu('user_students', "course IN ($course_ids)", 'course', 'id, userid');
|
||||
if (is_array($student_ids)) {
|
||||
$users = array_merge($users, $student_ids);
|
||||
}
|
||||
$user_ids = join(',', array_values($users));
|
||||
break;
|
||||
case 'this':
|
||||
$user_ids = $USER->id;
|
||||
break;
|
||||
}
|
||||
|
||||
if (empty($user_ids)) {
|
||||
print_heading(get_string('nousersyet'));
|
||||
exit;
|
||||
}
|
||||
|
||||
// get attempts for these users
|
||||
$fields = 'a.*, u.firstname, u.lastname, u.picture';
|
||||
$table = "{$CFG->prefix}hotpot_attempts AS a, {$CFG->prefix}user AS u";
|
||||
$select = ($mode=='simplestat' || $mode=='fullstat') ? 'a.score IS NOT NULL' : 'a.timefinish>0';
|
||||
$select .= " AND a.hotpot IN ($hotpot_ids) AND a.userid IN ($user_ids) AND a.userid = u.id";
|
||||
$order = "u.lastname, a.attempt";
|
||||
if ($reportattempts=='best') {
|
||||
$fields .= ", MAX(a.score) AS grade";
|
||||
$select .= " GROUP BY a.userid";
|
||||
}
|
||||
$attempts = get_records_sql("SELECT $fields FROM $table WHERE $select ORDER BY $order");
|
||||
|
||||
if (empty($attempts)) {
|
||||
print_heading(get_string('noattempts','quiz'));
|
||||
exit;
|
||||
}
|
||||
|
||||
// get the questions
|
||||
if (!$questions = get_records_select('hotpot_questions', "hotpot='$hotpot->id'")) {
|
||||
$questions = array();
|
||||
}
|
||||
|
||||
// get grades
|
||||
$grades = hotpot_get_grades($hotpot, $user_ids);
|
||||
|
||||
// get list of attempts by user
|
||||
$users = array();
|
||||
foreach ($attempts as $id=>$attempt) {
|
||||
|
||||
$userid = $attempt->userid;
|
||||
|
||||
if (!isset($users[$userid])) {
|
||||
$grade = isset($grades[$userid]) ? $grades[$userid] : ' ';
|
||||
$users[$userid]->grade = $grade;
|
||||
$users[$userid]->attempts = array();
|
||||
}
|
||||
|
||||
$users[$userid]->attempts[] = &$attempts[$id];
|
||||
|
||||
}
|
||||
|
||||
/// Open the selected hotpot report and display it
|
||||
|
||||
$mode = clean_filename($mode);
|
||||
|
||||
if (! is_readable("report/$mode/report.php")) {
|
||||
error("Report not known (".clean_text($mode).")", $course_homeurl);
|
||||
}
|
||||
|
||||
include("report/default.php"); // Parent class
|
||||
include("report/$mode/report.php");
|
||||
|
||||
$report = new hotpot_report();
|
||||
|
||||
if (! $report->display($hotpot, $cm, $course, $users, $attempts, $questions)) {
|
||||
error("Error occurred during pre-processing!", $course_homeurl);
|
||||
}
|
||||
|
||||
if (empty($noheader)) {
|
||||
print_footer($course);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
/// functions to delete attempts and responses
|
||||
|
||||
function hotpot_grade_heading($hotpot, $download) {
|
||||
|
||||
global $HOTPOT_GRADEMETHOD;
|
||||
$grademethod = $HOTPOT_GRADEMETHOD[$hotpot->grademethod];
|
||||
|
||||
if ($hotpot->grade!=100) {
|
||||
$grademethod = "$hotpot->grade x $grademethod/100";
|
||||
}
|
||||
if (empty($download)) {
|
||||
$grademethod = '<FONT size="1">'.$grademethod.'</FONT>';
|
||||
}
|
||||
$nl = $download ? "\n" : '<br>';
|
||||
return get_string('grade')."$nl($grademethod)";
|
||||
}
|
||||
function hotpot_delete_selected_attempts(&$hotpot, $del) {
|
||||
|
||||
$select = '';
|
||||
switch ($del) {
|
||||
case 'all' :
|
||||
$select = "hotpot='$hotpot->id'";
|
||||
break;
|
||||
case 'abandoned':
|
||||
$select = "hotpot='$hotpot->id' AND timefinish>0 AND score IS NULL";
|
||||
break;
|
||||
case 'selection':
|
||||
$ids = (array)data_submitted();
|
||||
unset($ids['del']);
|
||||
unset($ids['id']);
|
||||
if (!empty($ids)) {
|
||||
$select = "hotpot='$hotpot->id' AND id IN (".implode(',', $ids).")";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// delete attempts using $select, if it is set
|
||||
if ($select) {
|
||||
|
||||
$table = 'hotpot_attempts';
|
||||
if ($attempts = get_records_select($table, $select)) {
|
||||
|
||||
hotpot_delete_and_notify($table, $select, get_string('attempts', 'quiz'));
|
||||
|
||||
$table = 'hotpot_responses';
|
||||
$select = 'attempt IN ('.implode(',', array_keys($attempts)).')';
|
||||
hotpot_delete_and_notify($table, $select, get_string('answer', 'quiz'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
/// functions to print the report headings and
|
||||
/// report selector menus
|
||||
|
||||
function hotpot_print_report_heading(&$course, &$cm, &$hotpot, &$mode) {
|
||||
$strmodulenameplural = get_string("modulenameplural", "hotpot");
|
||||
$strmodulename = get_string("modulename", "hotpot");
|
||||
|
||||
$title = "$course->shortname: $hotpot->name";
|
||||
$heading = "$course->fullname";
|
||||
|
||||
$navigation = "<a href=index.php?id=$course->id>$strmodulenameplural</a> -> ";
|
||||
$navigation .= "<a href=\"view.php?id=$cm->id\">$hotpot->name</a> -> ";
|
||||
if (isteacher($course->id)) {
|
||||
$navigation .= get_string("report$mode", "quiz");
|
||||
} else {
|
||||
$navigation .= get_string("report", "quiz");
|
||||
}
|
||||
if ($course->category) {
|
||||
$navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> -> $navigation";
|
||||
}
|
||||
$button = update_module_button($cm->id, $course->id, $strmodulename);
|
||||
|
||||
print_header($title, $heading, $navigation, "", "", true, $button, navmenu($course, $cm));
|
||||
|
||||
print_heading($hotpot->name);
|
||||
}
|
||||
function hotpot_print_report_selector(&$course, &$hotpot, &$mode, &$reportcourse, &$reportusers, &$reportattempts) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$reports = hotpot_get_report_names('overview,simplestat');
|
||||
|
||||
print '<form method="post" action="'."$CFG->wwwroot/mod/hotpot/report.php?hp=$hotpot->id".'">';
|
||||
print '<table cellpadding="4" align="center">';
|
||||
|
||||
$menus = array();
|
||||
if (isadmin()) {
|
||||
$menus['reportcourse'] = array(
|
||||
'this' => get_string('thiscourse', 'hotpot'),
|
||||
'all' => get_string('allmycourses', 'hotpot')
|
||||
);
|
||||
}
|
||||
$menus['reportusers'] = array(
|
||||
'students' => get_string('students'),
|
||||
'all' => get_string('allparticipants')
|
||||
);
|
||||
$menus['reportattempts'] = array(
|
||||
'best' => get_string('bestattempt', 'hotpot'),
|
||||
'all' => get_string('allattempts', 'hotpot')
|
||||
);
|
||||
|
||||
print '<tr><td align="center" colspan="'.count($reports).'">';
|
||||
foreach ($menus as $name => $options) {
|
||||
eval('$value=$'.$name.';');
|
||||
print choose_from_menu($options, $name, $value, "", "", 0, true);
|
||||
}
|
||||
if (isteacher($course->id)) {
|
||||
helpbutton('reportselector', get_string('report'), 'hotpot');
|
||||
}
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr>';
|
||||
foreach ($reports as $name) {
|
||||
print '<td><input type="submit" name="'."mode[$name]".'" value="'.get_string("report$name", "quiz").'"></td>';
|
||||
}
|
||||
print '</tr>';
|
||||
|
||||
print '</table>';
|
||||
|
||||
print '<hr size="1" noshade="noshade" />';
|
||||
print '</form>'."\n";
|
||||
}
|
||||
function hotpot_get_report_names($names='') {
|
||||
// $names : optional list showing required order reports names
|
||||
|
||||
$reports = array();
|
||||
|
||||
// convert $names to an array, if necessary (usually is)
|
||||
if (!is_array($names)) {
|
||||
$names = explode(',', $names);
|
||||
}
|
||||
|
||||
$plugins = get_list_of_plugins("mod/hotpot/report");
|
||||
foreach($names as $name) {
|
||||
if (is_numeric($i = array_search($name, $plugins))) {
|
||||
$reports[] = $name;
|
||||
unset($plugins[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
// append remaining plugins
|
||||
$reports = array_merge($reports, $plugins);
|
||||
|
||||
return $reports;
|
||||
}
|
||||
function hotpot_get_report_users($course_ids, $reportusers) {
|
||||
$users = array();
|
||||
|
||||
/// Check to see if groups are being used in this module
|
||||
$currentgroup = false;
|
||||
if ($groupmode = groupmode($course, $cm)) { // Groups are being used
|
||||
$currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id=$cm->id&mode=simplestat");
|
||||
}
|
||||
|
||||
$sort = "u.lastname ASC";
|
||||
|
||||
switch ($reportusers) {
|
||||
case 'students':
|
||||
if ($currentgroup) {
|
||||
$users = get_group_students($currentgroup, $sort);
|
||||
} else {
|
||||
$users = get_course_students($course->id, $sort);
|
||||
}
|
||||
break;
|
||||
case 'all':
|
||||
if ($currentgroup) {
|
||||
$users = get_group_users($currentgroup, $sort);
|
||||
} else {
|
||||
$users = get_course_users($course->id, $sort);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
?>
|
||||
|
||||
+294
-294
@@ -1,294 +1,294 @@
|
||||
<?PHP //$Id$
|
||||
//This php script contains all the stuff to restore hotpot mods
|
||||
|
||||
//-----------------------------------------------------------
|
||||
// This is the "graphical" structure of the hotpot mod:
|
||||
//-----------------------------------------------------------
|
||||
//
|
||||
// hotpot
|
||||
// (CL, pk->id, files)
|
||||
// |
|
||||
// +--------------+--------------+
|
||||
// | |
|
||||
// | |
|
||||
// hotpot_attempts hotpot_questions
|
||||
// (UL, pk->id, (UL, pk->id,
|
||||
// fk->hotpot) fk->hotpot, text)
|
||||
// | | |
|
||||
// | | |
|
||||
// +--------------+--------------+ |
|
||||
// | |
|
||||
// | |
|
||||
// hotpot_responses |
|
||||
// (UL, pk->id, |
|
||||
// fk->attempt, question, |
|
||||
// correct, wrong, ignored) |
|
||||
// | |
|
||||
// | |
|
||||
// +-----------+-----------+
|
||||
// |
|
||||
// hotpot_strings
|
||||
// (UL, pk->id)
|
||||
//
|
||||
// Meaning: pk->primary key field of the table
|
||||
// fk->foreign key to link with parent
|
||||
// nt->nested field (recursive data)
|
||||
// CL->course level info
|
||||
// UL->user level info
|
||||
// files->table may have files
|
||||
//
|
||||
//-----------------------------------------------------------
|
||||
// It is not necessary to backup "questions", "responses"
|
||||
// and "strings", because they can be restored from the
|
||||
// "details" field of the "attempts" records
|
||||
//-----------------------------------------------------------
|
||||
|
||||
require_once ("$CFG->dirroot/mod/hotpot/lib.php");
|
||||
|
||||
//This function executes all the restore procedure about this mod
|
||||
function hotpot_restore_mods($mod, $restore) {
|
||||
|
||||
// this function is called by "restore_create_modules" (in "backup/restorelib.php")
|
||||
// which is called by "backup/restore_execute.html" (included by "backup/restore.php")
|
||||
|
||||
// $mod is an object
|
||||
// id : id field in 'modtype' table
|
||||
// modtype : 'hotpot'
|
||||
|
||||
// $restore is an object
|
||||
// backup_unique_code : xxxxxxxxxx
|
||||
// file : '/full/path/to/backupfile.zip'
|
||||
// mods : an array of $modinfo's (see below)
|
||||
// restoreto : 0=existing course (replace), 1=existing course (append), 2=new course
|
||||
// users : 0=all, 1=course, 2=none
|
||||
// logs : 0=no, 1=yes
|
||||
// user_files : 0=no, 1=yes
|
||||
// course_files : 0=no, 1=yes
|
||||
// course_id : id of course into which data is to be restored
|
||||
// deleting : true if 'restoreto'==0, otherwise false
|
||||
// original_wwwroot : 'http://your.server.com/moodle'
|
||||
|
||||
// $modinfo is an array
|
||||
// 'modname' : array( 'restore'=> 0=no 1=yes, 'userinfo' => 0=no 1=yes)
|
||||
|
||||
$status = true;
|
||||
|
||||
//Get data record for this instance of the mod
|
||||
$data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
|
||||
if ($data) {
|
||||
|
||||
// $data is an object
|
||||
// backup_code => xxxxxxxxxx,
|
||||
// table_name => 'hotpot',
|
||||
// old_id => xxx,
|
||||
// new_id => NULL,
|
||||
// info => array of info for this instance of the mod
|
||||
|
||||
// short cut to xmlized info
|
||||
$info = &$data->info['MOD']['#'];
|
||||
|
||||
// build the new record
|
||||
$hotpot = NULL;
|
||||
$hotpot->course = $restore->course_id;
|
||||
|
||||
// don't include these fields in the hotpot record
|
||||
$excluded_TAGS = array('MODTYPE', 'ID', 'COURSE', 'ATTEMPT_DATA');
|
||||
|
||||
// fill in the fields
|
||||
$TAGS = array_keys($info);
|
||||
foreach ($TAGS as $TAG) {
|
||||
|
||||
if (!in_array($TAG, $excluded_TAGS)) {
|
||||
$tag = strtolower($TAG);
|
||||
$hotpot->$tag = backup_todb($info[$TAG][0]['#']);
|
||||
}
|
||||
}
|
||||
|
||||
// insert the record
|
||||
$hotpot->id = insert_record ('hotpot', $hotpot);
|
||||
if (is_numeric($hotpot->id)) {
|
||||
|
||||
// Do some output
|
||||
echo '<ul><li>'.get_string('modulename', 'hotpot').' "'.$hotpot->name.'"<br>';
|
||||
backup_flush(300);
|
||||
|
||||
// save the new id (required for log retore later on)
|
||||
backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $hotpot->id);
|
||||
|
||||
// backup user info, if required
|
||||
if ($restore->mods[$mod->modtype]->userinfo) {
|
||||
|
||||
// are we overwriting a course?
|
||||
if ($restore->deleting) {
|
||||
|
||||
// remove previous attempts, questions and responses for this quiz
|
||||
$select = "hotpot='$hotpot->id'";
|
||||
if ($attempts = get_records_select('hotpot_attempts', $select)) {
|
||||
$ids = implode(',', array_keys($attempts));
|
||||
delete_records_select('hotpot_responses', "attempt IN ($ids)");
|
||||
}
|
||||
delete_records_select('hotpot_questions', $select);
|
||||
delete_records_select('hotpot_attempts', $select);
|
||||
}
|
||||
|
||||
// don't transfer these fields to the attempt records
|
||||
$excluded_TAGS = array('HOTPOT');
|
||||
|
||||
$i = 0;
|
||||
while ($status && isset($info['ATTEMPT_DATA'][$i]['#'])) {
|
||||
|
||||
$ii = 0;
|
||||
while ($status && isset($info['ATTEMPT_DATA'][$i]['#']['ATTEMPT'][$ii]['#'])) {
|
||||
|
||||
// shortcut to user info record
|
||||
$info_record = &$info['ATTEMPT_DATA'][$i]['#']['ATTEMPT'][$ii]['#'];
|
||||
|
||||
$attempt = NULL;
|
||||
$attempt->hotpot = $hotpot->id;
|
||||
|
||||
$TAGS = array_keys($info_record);
|
||||
foreach ($TAGS as $TAG) {
|
||||
|
||||
if (!in_array($TAG, $excluded_TAGS)) {
|
||||
|
||||
$value = backup_todb($info_record[$TAG][0]['#']);
|
||||
|
||||
if ($TAG=='USERID') {
|
||||
$user = backup_getid($restore->backup_unique_code, 'user', $value);
|
||||
if ($user) {
|
||||
$value = $user->new_id;
|
||||
} else {
|
||||
$status = false; // this shouldn't happen
|
||||
}
|
||||
}
|
||||
|
||||
$tag = strtolower($TAG);
|
||||
$attempt->$tag = $value;
|
||||
}
|
||||
} // end foreach $TAGS
|
||||
|
||||
// store old attempt id
|
||||
$attempt->old_id = $attempt->id;
|
||||
unset($attempt->id);
|
||||
|
||||
// add the attempt record
|
||||
$attempt->id = insert_record ('hotpot_attempts', $attempt);
|
||||
if (is_numeric($attempt->id)) {
|
||||
|
||||
// save the new id (required for log retore later on)
|
||||
backup_putid($restore->backup_unique_code, 'hotpot_attempts', $attempt->old_id, $attempt->id);
|
||||
|
||||
// remove slashes added by backup_todb(), otherwise xmlize() will complain
|
||||
$attempt->details = stripslashes($attempt->details);
|
||||
|
||||
// add questions and responses in attempt $attempt->details
|
||||
hotpot_add_attempt_details($attempt);
|
||||
|
||||
} else { // failed to insert $attempt record
|
||||
$status = false;
|
||||
}
|
||||
|
||||
// do some output, if required
|
||||
if ($status) {
|
||||
if ($ii%10==0) {
|
||||
echo '.';
|
||||
if ($ii%200==0) {
|
||||
echo '<br>';
|
||||
backup_flush(300);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ii++;
|
||||
} // end while $info_record
|
||||
|
||||
$i++;
|
||||
} // end while $info_records
|
||||
}
|
||||
|
||||
// Finalize ul
|
||||
echo "</li></ul>";
|
||||
|
||||
} else {
|
||||
// could not add hotpot record
|
||||
$status = false;
|
||||
}
|
||||
|
||||
} else {
|
||||
// could not get $data for this hotpot quiz
|
||||
$status = false;
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
//This function returns a log record with all the necessay transformations
|
||||
//done. It's used by restore_log_module() to restore modules log.
|
||||
function hotpot_restore_logs($restore, $log) {
|
||||
|
||||
// assume the worst
|
||||
$status = false;
|
||||
|
||||
switch ($log->action) {
|
||||
|
||||
case "add":
|
||||
case "update":
|
||||
case "view":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the module (to recode the info field)
|
||||
$mod = backup_getid($restore->backup_unique_code, $log->module, $log->info);
|
||||
if ($mod) {
|
||||
$log->url = "view.php?id=".$log->cmid;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "view all":
|
||||
$log->url = "index.php?id=".$log->course;
|
||||
$status = true;
|
||||
break;
|
||||
|
||||
case "report":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the module (to recode the info field)
|
||||
$mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
|
||||
if ($mod) {
|
||||
$log->url = "report.php?id=".$log->cmid;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "attempt":
|
||||
case "submit":
|
||||
case "review":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the module (to recode the info field)
|
||||
$mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
|
||||
if ($mod) {
|
||||
//Extract the attempt id from the url field
|
||||
$attemptid = substr(strrchr($log->url,"="),1);
|
||||
//Get the new_id of the attempt (to recode the url field)
|
||||
$attempt = backup_getid($restore->backup_unique_code,"hotpot_attempts",$attemptid);
|
||||
if ($attempt) {
|
||||
$log->url = "review.php?id=".$log->cmid."&attempt=".$attempt->new_id;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Oops, unknown $log->action
|
||||
print "<p>action (".$log->module."-".$log->action.") unknown. Not restored</p>";
|
||||
break;
|
||||
|
||||
} // end switch
|
||||
|
||||
return $status ? $log : false;
|
||||
}
|
||||
?>
|
||||
<?PHP //$Id$
|
||||
//This php script contains all the stuff to restore hotpot mods
|
||||
|
||||
//-----------------------------------------------------------
|
||||
// This is the "graphical" structure of the hotpot mod:
|
||||
//-----------------------------------------------------------
|
||||
//
|
||||
// hotpot
|
||||
// (CL, pk->id, files)
|
||||
// |
|
||||
// +--------------+--------------+
|
||||
// | |
|
||||
// | |
|
||||
// hotpot_attempts hotpot_questions
|
||||
// (UL, pk->id, (UL, pk->id,
|
||||
// fk->hotpot) fk->hotpot, text)
|
||||
// | | |
|
||||
// | | |
|
||||
// +--------------+--------------+ |
|
||||
// | |
|
||||
// | |
|
||||
// hotpot_responses |
|
||||
// (UL, pk->id, |
|
||||
// fk->attempt, question, |
|
||||
// correct, wrong, ignored) |
|
||||
// | |
|
||||
// | |
|
||||
// +-----------+-----------+
|
||||
// |
|
||||
// hotpot_strings
|
||||
// (UL, pk->id)
|
||||
//
|
||||
// Meaning: pk->primary key field of the table
|
||||
// fk->foreign key to link with parent
|
||||
// nt->nested field (recursive data)
|
||||
// CL->course level info
|
||||
// UL->user level info
|
||||
// files->table may have files
|
||||
//
|
||||
//-----------------------------------------------------------
|
||||
// It is not necessary to backup "questions", "responses"
|
||||
// and "strings", because they can be restored from the
|
||||
// "details" field of the "attempts" records
|
||||
//-----------------------------------------------------------
|
||||
|
||||
require_once ("$CFG->dirroot/mod/hotpot/lib.php");
|
||||
|
||||
//This function executes all the restore procedure about this mod
|
||||
function hotpot_restore_mods($mod, $restore) {
|
||||
|
||||
// this function is called by "restore_create_modules" (in "backup/restorelib.php")
|
||||
// which is called by "backup/restore_execute.html" (included by "backup/restore.php")
|
||||
|
||||
// $mod is an object
|
||||
// id : id field in 'modtype' table
|
||||
// modtype : 'hotpot'
|
||||
|
||||
// $restore is an object
|
||||
// backup_unique_code : xxxxxxxxxx
|
||||
// file : '/full/path/to/backupfile.zip'
|
||||
// mods : an array of $modinfo's (see below)
|
||||
// restoreto : 0=existing course (replace), 1=existing course (append), 2=new course
|
||||
// users : 0=all, 1=course, 2=none
|
||||
// logs : 0=no, 1=yes
|
||||
// user_files : 0=no, 1=yes
|
||||
// course_files : 0=no, 1=yes
|
||||
// course_id : id of course into which data is to be restored
|
||||
// deleting : true if 'restoreto'==0, otherwise false
|
||||
// original_wwwroot : 'http://your.server.com/moodle'
|
||||
|
||||
// $modinfo is an array
|
||||
// 'modname' : array( 'restore'=> 0=no 1=yes, 'userinfo' => 0=no 1=yes)
|
||||
|
||||
$status = true;
|
||||
|
||||
//Get data record for this instance of the mod
|
||||
$data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
|
||||
if ($data) {
|
||||
|
||||
// $data is an object
|
||||
// backup_code => xxxxxxxxxx,
|
||||
// table_name => 'hotpot',
|
||||
// old_id => xxx,
|
||||
// new_id => NULL,
|
||||
// info => array of info for this instance of the mod
|
||||
|
||||
// short cut to xmlized info
|
||||
$info = &$data->info['MOD']['#'];
|
||||
|
||||
// build the new record
|
||||
$hotpot = NULL;
|
||||
$hotpot->course = $restore->course_id;
|
||||
|
||||
// don't include these fields in the hotpot record
|
||||
$excluded_TAGS = array('MODTYPE', 'ID', 'COURSE', 'ATTEMPT_DATA');
|
||||
|
||||
// fill in the fields
|
||||
$TAGS = array_keys($info);
|
||||
foreach ($TAGS as $TAG) {
|
||||
|
||||
if (!in_array($TAG, $excluded_TAGS)) {
|
||||
$tag = strtolower($TAG);
|
||||
$hotpot->$tag = backup_todb($info[$TAG][0]['#']);
|
||||
}
|
||||
}
|
||||
|
||||
// insert the record
|
||||
$hotpot->id = insert_record ('hotpot', $hotpot);
|
||||
if (is_numeric($hotpot->id)) {
|
||||
|
||||
// Do some output
|
||||
echo '<ul><li>'.get_string('modulename', 'hotpot').' "'.$hotpot->name.'"<br>';
|
||||
backup_flush(300);
|
||||
|
||||
// save the new id (required for log retore later on)
|
||||
backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $hotpot->id);
|
||||
|
||||
// backup user info, if required
|
||||
if ($restore->mods[$mod->modtype]->userinfo) {
|
||||
|
||||
// are we overwriting a course?
|
||||
if ($restore->deleting) {
|
||||
|
||||
// remove previous attempts, questions and responses for this quiz
|
||||
$select = "hotpot='$hotpot->id'";
|
||||
if ($attempts = get_records_select('hotpot_attempts', $select)) {
|
||||
$ids = implode(',', array_keys($attempts));
|
||||
delete_records_select('hotpot_responses', "attempt IN ($ids)");
|
||||
}
|
||||
delete_records_select('hotpot_questions', $select);
|
||||
delete_records_select('hotpot_attempts', $select);
|
||||
}
|
||||
|
||||
// don't transfer these fields to the attempt records
|
||||
$excluded_TAGS = array('HOTPOT');
|
||||
|
||||
$i = 0;
|
||||
while ($status && isset($info['ATTEMPT_DATA'][$i]['#'])) {
|
||||
|
||||
$ii = 0;
|
||||
while ($status && isset($info['ATTEMPT_DATA'][$i]['#']['ATTEMPT'][$ii]['#'])) {
|
||||
|
||||
// shortcut to user info record
|
||||
$info_record = &$info['ATTEMPT_DATA'][$i]['#']['ATTEMPT'][$ii]['#'];
|
||||
|
||||
$attempt = NULL;
|
||||
$attempt->hotpot = $hotpot->id;
|
||||
|
||||
$TAGS = array_keys($info_record);
|
||||
foreach ($TAGS as $TAG) {
|
||||
|
||||
if (!in_array($TAG, $excluded_TAGS)) {
|
||||
|
||||
$value = backup_todb($info_record[$TAG][0]['#']);
|
||||
|
||||
if ($TAG=='USERID') {
|
||||
$user = backup_getid($restore->backup_unique_code, 'user', $value);
|
||||
if ($user) {
|
||||
$value = $user->new_id;
|
||||
} else {
|
||||
$status = false; // this shouldn't happen
|
||||
}
|
||||
}
|
||||
|
||||
$tag = strtolower($TAG);
|
||||
$attempt->$tag = $value;
|
||||
}
|
||||
} // end foreach $TAGS
|
||||
|
||||
// store old attempt id
|
||||
$attempt->old_id = $attempt->id;
|
||||
unset($attempt->id);
|
||||
|
||||
// add the attempt record
|
||||
$attempt->id = insert_record ('hotpot_attempts', $attempt);
|
||||
if (is_numeric($attempt->id)) {
|
||||
|
||||
// save the new id (required for log retore later on)
|
||||
backup_putid($restore->backup_unique_code, 'hotpot_attempts', $attempt->old_id, $attempt->id);
|
||||
|
||||
// remove slashes added by backup_todb(), otherwise xmlize() will complain
|
||||
$attempt->details = stripslashes($attempt->details);
|
||||
|
||||
// add questions and responses in attempt $attempt->details
|
||||
hotpot_add_attempt_details($attempt);
|
||||
|
||||
} else { // failed to insert $attempt record
|
||||
$status = false;
|
||||
}
|
||||
|
||||
// do some output, if required
|
||||
if ($status) {
|
||||
if ($ii%10==0) {
|
||||
echo '.';
|
||||
if ($ii%200==0) {
|
||||
echo '<br>';
|
||||
backup_flush(300);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ii++;
|
||||
} // end while $info_record
|
||||
|
||||
$i++;
|
||||
} // end while $info_records
|
||||
}
|
||||
|
||||
// Finalize ul
|
||||
echo "</li></ul>";
|
||||
|
||||
} else {
|
||||
// could not add hotpot record
|
||||
$status = false;
|
||||
}
|
||||
|
||||
} else {
|
||||
// could not get $data for this hotpot quiz
|
||||
$status = false;
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
//This function returns a log record with all the necessay transformations
|
||||
//done. It's used by restore_log_module() to restore modules log.
|
||||
function hotpot_restore_logs($restore, $log) {
|
||||
|
||||
// assume the worst
|
||||
$status = false;
|
||||
|
||||
switch ($log->action) {
|
||||
|
||||
case "add":
|
||||
case "update":
|
||||
case "view":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the module (to recode the info field)
|
||||
$mod = backup_getid($restore->backup_unique_code, $log->module, $log->info);
|
||||
if ($mod) {
|
||||
$log->url = "view.php?id=".$log->cmid;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "view all":
|
||||
$log->url = "index.php?id=".$log->course;
|
||||
$status = true;
|
||||
break;
|
||||
|
||||
case "report":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the module (to recode the info field)
|
||||
$mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
|
||||
if ($mod) {
|
||||
$log->url = "report.php?id=".$log->cmid;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "attempt":
|
||||
case "submit":
|
||||
case "review":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the module (to recode the info field)
|
||||
$mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
|
||||
if ($mod) {
|
||||
//Extract the attempt id from the url field
|
||||
$attemptid = substr(strrchr($log->url,"="),1);
|
||||
//Get the new_id of the attempt (to recode the url field)
|
||||
$attempt = backup_getid($restore->backup_unique_code,"hotpot_attempts",$attemptid);
|
||||
if ($attempt) {
|
||||
$log->url = "review.php?id=".$log->cmid."&attempt=".$attempt->new_id;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Oops, unknown $log->action
|
||||
print "<p>action (".$log->module."-".$log->action.") unknown. Not restored</p>";
|
||||
break;
|
||||
|
||||
} // end switch
|
||||
|
||||
return $status ? $log : false;
|
||||
}
|
||||
?>
|
||||
|
||||
+235
-235
@@ -1,235 +1,235 @@
|
||||
<?PHP // $Id$
|
||||
|
||||
// This page prints a review of a particular quiz attempt
|
||||
|
||||
require_once("../../config.php");
|
||||
require_once("lib.php");
|
||||
|
||||
$id = optional_param("id"); // Course Module ID, or
|
||||
$hp = optional_param("hp"); // hotpot ID
|
||||
|
||||
$attempt = required_param("attempt"); // A particular attempt ID for review
|
||||
|
||||
if ($id) {
|
||||
if (! $cm = get_record("course_modules", "id", $id)) {
|
||||
error("Course Module ID was incorrect");
|
||||
}
|
||||
if (! $course = get_record("course", "id", $cm->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");
|
||||
}
|
||||
}
|
||||
|
||||
if (! $attempt = get_record("hotpot_attempts", "id", $attempt)) {
|
||||
error("No such attempt ID exists");
|
||||
}
|
||||
|
||||
require_login($course->id);
|
||||
|
||||
if (!isteacher($course->id)) {
|
||||
if (!$hotpot->review) {
|
||||
error(get_string("noreview", "quiz"));
|
||||
}
|
||||
//if (time() < $hotpot->timeclose) {
|
||||
// error(get_string("noreviewuntil", "quiz", userdate($hotpot->timeclose)));
|
||||
//}
|
||||
if ($attempt->userid != $USER->id) {
|
||||
error("This is not your attempt!");
|
||||
}
|
||||
}
|
||||
|
||||
add_to_log($course->id, "hotpot", "review", "review.php?id=$cm->id&attempt=$attempt->id", "$hotpot->id", "$cm->id");
|
||||
|
||||
|
||||
// Print the page header
|
||||
|
||||
$strmodulenameplural = get_string("modulenameplural", "hotpot");
|
||||
$strmodulename = get_string("modulename", "hotpot");
|
||||
|
||||
// print header
|
||||
$title = "$course->shortname: $hotpot->name";
|
||||
$heading = "$course->fullname";
|
||||
$navigation = "<a href=\"index.php?id=$course->id\">$strmodulenameplural</a> -> ".get_string("review", "quiz");
|
||||
if ($course->category) {
|
||||
$navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> -> $navigation";
|
||||
}
|
||||
$button = update_module_button($cm->id, $course->id, $strmodulename);
|
||||
|
||||
print_header($title, $heading, $navigation, "", "", true, $button, navmenu($course, $cm));
|
||||
|
||||
|
||||
echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib
|
||||
|
||||
print_heading($hotpot->name);
|
||||
|
||||
// format attempt properties
|
||||
if (!empty($attempt->timefinish)) {
|
||||
$attempt->timecompleted = userdate($attempt->timefinish);
|
||||
$attempt->timetaken = format_time($attempt->timefinish - $attempt->timestart);
|
||||
} else {
|
||||
$attempt->timecompleted = '-';
|
||||
$attempt->timetaken = '-';
|
||||
}
|
||||
$attempt->score = hotpot_format_score($attempt);
|
||||
|
||||
$html = '';
|
||||
|
||||
// start table
|
||||
$html .= '<table width="100%" border="1" valign="top" align="center" cellpadding="2" cellspacing="2" class="generaltable">'."\n";
|
||||
|
||||
// add attempt properties
|
||||
$fields = array('attempt', 'score', 'penalties', 'timetaken', 'timecompleted');
|
||||
foreach ($fields as $field) {
|
||||
if (isset($attempt->$field)) {
|
||||
$module = ($field=='penalties') ? 'hotpot' : 'quiz';
|
||||
$html .= '<tr><th align="right" width="100" class="generaltableheader">'.get_string($field, $module).':</th><td class="generaltablecell">'.$attempt->$field.'</td></tr>';
|
||||
}
|
||||
}
|
||||
|
||||
// finish table
|
||||
$html .= '</table>';
|
||||
|
||||
print_simple_box_start("center", "80%", "#ffffff", 0);
|
||||
print $html;
|
||||
print_simple_box_end();
|
||||
|
||||
print_continue("report.php?id=$cm->id");
|
||||
hotpot_print_attempt_details($hotpot, $attempt);
|
||||
print_continue("report.php?id=$cm->id");
|
||||
|
||||
print_footer($course);
|
||||
|
||||
///////////////////////////
|
||||
// functions
|
||||
///////////////////////////
|
||||
|
||||
function hotpot_print_attempt_details(&$hotpot, &$attempt) {
|
||||
|
||||
// define fields to print
|
||||
$textfields = array('correct', 'ignored', 'wrong');
|
||||
$numfields = array('score', 'weighting', 'hints', 'clues', 'checks');
|
||||
|
||||
$fields = array_merge($textfields, $numfields);
|
||||
|
||||
$q = array(); // questions
|
||||
$f = array(); // fields
|
||||
foreach ($fields as $field) {
|
||||
$name = get_string($field, 'hotpot');
|
||||
$f[$field] = array('count'=>0, 'name'=>$name);
|
||||
}
|
||||
|
||||
// get questions and responses for this attempt
|
||||
$questions = get_records_select('hotpot_questions', "hotpot='$hotpot->id'", 'id');
|
||||
$responses = get_records_select('hotpot_responses', "attempt='$attempt->id'", 'id');
|
||||
|
||||
if ($questions && $responses) {
|
||||
foreach ($responses as $response) {
|
||||
$id = $response->question;
|
||||
foreach ($fields as $field) {
|
||||
if (!isset($f[$field])) {
|
||||
$name = get_string($field, 'hotpot');
|
||||
$f[$field] = array('count'=>0, 'name'=>$name);
|
||||
}
|
||||
if (isset($response->$field)) {
|
||||
$f[$field]['count']++;
|
||||
|
||||
if (!isset($q[$id])) {
|
||||
$name = hotpot_get_question_name($questions[$id]);
|
||||
$q[$id] = array('name'=>$name);
|
||||
}
|
||||
|
||||
$q[$id][$field] = $response->$field;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// count the number of columns required in the table
|
||||
$colspan = 0;
|
||||
foreach ($numfields as $field) {
|
||||
if ($f[$field]['count']) {
|
||||
$colspan += 2;
|
||||
}
|
||||
}
|
||||
$colspan = max(2, $colspan);
|
||||
|
||||
$html = '';
|
||||
|
||||
// start table of questions and responses
|
||||
$html .= '<table width="100%" border="1" valign="top" align="center" cellpadding="2" cellspacing="2" class="generaltable">'."\n";
|
||||
|
||||
if (empty($q)) {
|
||||
$html .= '<tr><td align="center" class="generaltablecell"><b>'.get_string("noresponses", "hotpot").'</b></td></tr>';
|
||||
|
||||
} else {
|
||||
foreach ($q as $question) {
|
||||
|
||||
// flag to ensure questions are only printed when there is at least one response
|
||||
$printedquestion = false;
|
||||
|
||||
// add rows of text fields
|
||||
foreach ($textfields as $field) {
|
||||
if (isset($question[$field])) {
|
||||
$text = hotpot_strings($question[$field]);
|
||||
if (trim($text)) {
|
||||
|
||||
// print question if necessary
|
||||
if (!$printedquestion) {
|
||||
$html .= '<tr><td colspan="'.$colspan.'" class="generaltablecell"><b>'.$question['name'].'</b></td></tr>';
|
||||
$printedquestion = true;
|
||||
}
|
||||
|
||||
// print response
|
||||
$html .= '<tr><th align="right" width="100" class="generaltableheader">'.$f[$field]['name'].':</th><td colspan="'.($colspan-1).'" class="generaltablecell">'.$text.'</td></tr>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add row of numeric fields
|
||||
$html .= '<tr>';
|
||||
foreach ($numfields as $field) {
|
||||
if ($f[$field]['count']) {
|
||||
|
||||
// print question if necessary
|
||||
if (!$printedquestion) {
|
||||
$html .= '<tr><td colspan="'.$colspan.'" class="generaltablecell"><b>'.$question['name'].'</b></td></tr>';
|
||||
$printedquestion = true;
|
||||
}
|
||||
|
||||
// print numeric response
|
||||
$value = isset($question[$field]) ? $question[$field] : '-';
|
||||
$html .= '<th align="right" width="100" class="generaltableheader">'.$f[$field]['name'].':</th><td class="generaltablecell">'.$value.'</td>';
|
||||
}
|
||||
}
|
||||
$html .= '</tr>';
|
||||
|
||||
// add separator
|
||||
if ($printedquestion) {
|
||||
$html .= '<tr><td colspan="'.$colspan.'"><div class="tabledivider"></div></td></tr>';
|
||||
}
|
||||
|
||||
} // foreach $q
|
||||
}
|
||||
|
||||
// finish table
|
||||
$html .= '</table>';
|
||||
|
||||
print_simple_box_start("center", "80%", "#ffffff", 0);
|
||||
print $html;
|
||||
print_simple_box_end();
|
||||
}
|
||||
|
||||
?>
|
||||
<?PHP // $Id$
|
||||
|
||||
// This page prints a review of a particular quiz attempt
|
||||
|
||||
require_once("../../config.php");
|
||||
require_once("lib.php");
|
||||
|
||||
$id = optional_param("id"); // Course Module ID, or
|
||||
$hp = optional_param("hp"); // hotpot ID
|
||||
|
||||
$attempt = required_param("attempt"); // A particular attempt ID for review
|
||||
|
||||
if ($id) {
|
||||
if (! $cm = get_record("course_modules", "id", $id)) {
|
||||
error("Course Module ID was incorrect");
|
||||
}
|
||||
if (! $course = get_record("course", "id", $cm->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");
|
||||
}
|
||||
}
|
||||
|
||||
if (! $attempt = get_record("hotpot_attempts", "id", $attempt)) {
|
||||
error("No such attempt ID exists");
|
||||
}
|
||||
|
||||
require_login($course->id);
|
||||
|
||||
if (!isteacher($course->id)) {
|
||||
if (!$hotpot->review) {
|
||||
error(get_string("noreview", "quiz"));
|
||||
}
|
||||
//if (time() < $hotpot->timeclose) {
|
||||
// error(get_string("noreviewuntil", "quiz", userdate($hotpot->timeclose)));
|
||||
//}
|
||||
if ($attempt->userid != $USER->id) {
|
||||
error("This is not your attempt!");
|
||||
}
|
||||
}
|
||||
|
||||
add_to_log($course->id, "hotpot", "review", "review.php?id=$cm->id&attempt=$attempt->id", "$hotpot->id", "$cm->id");
|
||||
|
||||
|
||||
// Print the page header
|
||||
|
||||
$strmodulenameplural = get_string("modulenameplural", "hotpot");
|
||||
$strmodulename = get_string("modulename", "hotpot");
|
||||
|
||||
// print header
|
||||
$title = "$course->shortname: $hotpot->name";
|
||||
$heading = "$course->fullname";
|
||||
$navigation = "<a href=\"index.php?id=$course->id\">$strmodulenameplural</a> -> ".get_string("review", "quiz");
|
||||
if ($course->category) {
|
||||
$navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> -> $navigation";
|
||||
}
|
||||
$button = update_module_button($cm->id, $course->id, $strmodulename);
|
||||
|
||||
print_header($title, $heading, $navigation, "", "", true, $button, navmenu($course, $cm));
|
||||
|
||||
|
||||
echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib
|
||||
|
||||
print_heading($hotpot->name);
|
||||
|
||||
// format attempt properties
|
||||
if (!empty($attempt->timefinish)) {
|
||||
$attempt->timecompleted = userdate($attempt->timefinish);
|
||||
$attempt->timetaken = format_time($attempt->timefinish - $attempt->timestart);
|
||||
} else {
|
||||
$attempt->timecompleted = '-';
|
||||
$attempt->timetaken = '-';
|
||||
}
|
||||
$attempt->score = hotpot_format_score($attempt);
|
||||
|
||||
$html = '';
|
||||
|
||||
// start table
|
||||
$html .= '<table width="100%" border="1" valign="top" align="center" cellpadding="2" cellspacing="2" class="generaltable">'."\n";
|
||||
|
||||
// add attempt properties
|
||||
$fields = array('attempt', 'score', 'penalties', 'timetaken', 'timecompleted');
|
||||
foreach ($fields as $field) {
|
||||
if (isset($attempt->$field)) {
|
||||
$module = ($field=='penalties') ? 'hotpot' : 'quiz';
|
||||
$html .= '<tr><th align="right" width="100" class="generaltableheader">'.get_string($field, $module).':</th><td class="generaltablecell">'.$attempt->$field.'</td></tr>';
|
||||
}
|
||||
}
|
||||
|
||||
// finish table
|
||||
$html .= '</table>';
|
||||
|
||||
print_simple_box_start("center", "80%", "#ffffff", 0);
|
||||
print $html;
|
||||
print_simple_box_end();
|
||||
|
||||
print_continue("report.php?id=$cm->id");
|
||||
hotpot_print_attempt_details($hotpot, $attempt);
|
||||
print_continue("report.php?id=$cm->id");
|
||||
|
||||
print_footer($course);
|
||||
|
||||
///////////////////////////
|
||||
// functions
|
||||
///////////////////////////
|
||||
|
||||
function hotpot_print_attempt_details(&$hotpot, &$attempt) {
|
||||
|
||||
// define fields to print
|
||||
$textfields = array('correct', 'ignored', 'wrong');
|
||||
$numfields = array('score', 'weighting', 'hints', 'clues', 'checks');
|
||||
|
||||
$fields = array_merge($textfields, $numfields);
|
||||
|
||||
$q = array(); // questions
|
||||
$f = array(); // fields
|
||||
foreach ($fields as $field) {
|
||||
$name = get_string($field, 'hotpot');
|
||||
$f[$field] = array('count'=>0, 'name'=>$name);
|
||||
}
|
||||
|
||||
// get questions and responses for this attempt
|
||||
$questions = get_records_select('hotpot_questions', "hotpot='$hotpot->id'", 'id');
|
||||
$responses = get_records_select('hotpot_responses', "attempt='$attempt->id'", 'id');
|
||||
|
||||
if ($questions && $responses) {
|
||||
foreach ($responses as $response) {
|
||||
$id = $response->question;
|
||||
foreach ($fields as $field) {
|
||||
if (!isset($f[$field])) {
|
||||
$name = get_string($field, 'hotpot');
|
||||
$f[$field] = array('count'=>0, 'name'=>$name);
|
||||
}
|
||||
if (isset($response->$field)) {
|
||||
$f[$field]['count']++;
|
||||
|
||||
if (!isset($q[$id])) {
|
||||
$name = hotpot_get_question_name($questions[$id]);
|
||||
$q[$id] = array('name'=>$name);
|
||||
}
|
||||
|
||||
$q[$id][$field] = $response->$field;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// count the number of columns required in the table
|
||||
$colspan = 0;
|
||||
foreach ($numfields as $field) {
|
||||
if ($f[$field]['count']) {
|
||||
$colspan += 2;
|
||||
}
|
||||
}
|
||||
$colspan = max(2, $colspan);
|
||||
|
||||
$html = '';
|
||||
|
||||
// start table of questions and responses
|
||||
$html .= '<table width="100%" border="1" valign="top" align="center" cellpadding="2" cellspacing="2" class="generaltable">'."\n";
|
||||
|
||||
if (empty($q)) {
|
||||
$html .= '<tr><td align="center" class="generaltablecell"><b>'.get_string("noresponses", "hotpot").'</b></td></tr>';
|
||||
|
||||
} else {
|
||||
foreach ($q as $question) {
|
||||
|
||||
// flag to ensure questions are only printed when there is at least one response
|
||||
$printedquestion = false;
|
||||
|
||||
// add rows of text fields
|
||||
foreach ($textfields as $field) {
|
||||
if (isset($question[$field])) {
|
||||
$text = hotpot_strings($question[$field]);
|
||||
if (trim($text)) {
|
||||
|
||||
// print question if necessary
|
||||
if (!$printedquestion) {
|
||||
$html .= '<tr><td colspan="'.$colspan.'" class="generaltablecell"><b>'.$question['name'].'</b></td></tr>';
|
||||
$printedquestion = true;
|
||||
}
|
||||
|
||||
// print response
|
||||
$html .= '<tr><th align="right" width="100" class="generaltableheader">'.$f[$field]['name'].':</th><td colspan="'.($colspan-1).'" class="generaltablecell">'.$text.'</td></tr>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add row of numeric fields
|
||||
$html .= '<tr>';
|
||||
foreach ($numfields as $field) {
|
||||
if ($f[$field]['count']) {
|
||||
|
||||
// print question if necessary
|
||||
if (!$printedquestion) {
|
||||
$html .= '<tr><td colspan="'.$colspan.'" class="generaltablecell"><b>'.$question['name'].'</b></td></tr>';
|
||||
$printedquestion = true;
|
||||
}
|
||||
|
||||
// print numeric response
|
||||
$value = isset($question[$field]) ? $question[$field] : '-';
|
||||
$html .= '<th align="right" width="100" class="generaltableheader">'.$f[$field]['name'].':</th><td class="generaltablecell">'.$value.'</td>';
|
||||
}
|
||||
}
|
||||
$html .= '</tr>';
|
||||
|
||||
// add separator
|
||||
if ($printedquestion) {
|
||||
$html .= '<tr><td colspan="'.$colspan.'"><div class="tabledivider"></div></td></tr>';
|
||||
}
|
||||
|
||||
} // foreach $q
|
||||
}
|
||||
|
||||
// finish table
|
||||
$html .= '</table>';
|
||||
|
||||
print_simple_box_start("center", "80%", "#ffffff", 0);
|
||||
print $html;
|
||||
print_simple_box_end();
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
+78
-78
@@ -1,78 +1,78 @@
|
||||
<?php // $Id$
|
||||
|
||||
require_once("../../config.php");
|
||||
require_once("lib.php");
|
||||
|
||||
require_login();
|
||||
|
||||
// fetch and clean the required $_GET parameters
|
||||
// (script stops here if any parameters are missing)
|
||||
unset($params);
|
||||
$params->action = required_param('action');
|
||||
$params->course = required_param('course');
|
||||
$params->reference = required_param('reference');
|
||||
|
||||
require_login($params->course);
|
||||
|
||||
if (!isteacher($params->course)) {
|
||||
error("You are not allowed to view this page!");
|
||||
}
|
||||
|
||||
if (isadmin()) {
|
||||
$params->location = optional_param('location', HOTPOT_LOCATION_COURSEFILES);
|
||||
} else {
|
||||
$params->location = HOTPOT_LOCATION_COURSEFILES;
|
||||
}
|
||||
|
||||
$title = get_string($params->action, 'hotpot').': '.$params->reference;
|
||||
print_header($title, $title);
|
||||
|
||||
hotpot_print_show_links($params->course, $params->location, $params->reference);
|
||||
?>
|
||||
<SCRIPT>
|
||||
<!--
|
||||
// http://www.krikkit.net/howto_javascript_copy_clipboard.html
|
||||
|
||||
function copy_contents(id) {
|
||||
if (id==null) {
|
||||
id = 'contents';
|
||||
}
|
||||
var obj = null;
|
||||
if (document.getElementById) {
|
||||
obj = document.getElementById(id);
|
||||
}
|
||||
if (obj && window.clipboardData) {
|
||||
window.clipboardData.setData("Text", obj.innerText);
|
||||
alert('<? print_string('copiedtoclipboard', 'hotpot') ?>');
|
||||
}
|
||||
}
|
||||
document.write('<span class="helplink"> <A href="javascript:copy_contents()"><? print_string('copytoclipboard', 'hotpot') ?></A></span>');
|
||||
-->
|
||||
</SCRIPT>
|
||||
<?php
|
||||
print_simple_box_start("center", "96%");
|
||||
if($hp = new hotpot_xml_quiz($_GET)) {
|
||||
print '<pre id="contents">';
|
||||
switch ($params->action) {
|
||||
case 'showxmlsource':
|
||||
print htmlspecialchars($hp->source);
|
||||
break;
|
||||
case 'showxmltree':
|
||||
print_r($hp->xml);
|
||||
break;
|
||||
case 'showhtmlsource':
|
||||
print htmlspecialchars($hp->html);
|
||||
break;
|
||||
case 'showhtmlquiz':
|
||||
print $hp->html;
|
||||
break;
|
||||
}
|
||||
print '</pre>';
|
||||
} else {
|
||||
print_simple_box("Could not open Hot Potatoes XML file", "center", "", "#FFBBBB");
|
||||
}
|
||||
|
||||
print_simple_box_end();
|
||||
print '<br />';
|
||||
close_window_button();
|
||||
?>
|
||||
<?php // $Id$
|
||||
|
||||
require_once("../../config.php");
|
||||
require_once("lib.php");
|
||||
|
||||
require_login();
|
||||
|
||||
// fetch and clean the required $_GET parameters
|
||||
// (script stops here if any parameters are missing)
|
||||
unset($params);
|
||||
$params->action = required_param('action');
|
||||
$params->course = required_param('course');
|
||||
$params->reference = required_param('reference');
|
||||
|
||||
require_login($params->course);
|
||||
|
||||
if (!isteacher($params->course)) {
|
||||
error("You are not allowed to view this page!");
|
||||
}
|
||||
|
||||
if (isadmin()) {
|
||||
$params->location = optional_param('location', HOTPOT_LOCATION_COURSEFILES);
|
||||
} else {
|
||||
$params->location = HOTPOT_LOCATION_COURSEFILES;
|
||||
}
|
||||
|
||||
$title = get_string($params->action, 'hotpot').': '.$params->reference;
|
||||
print_header($title, $title);
|
||||
|
||||
hotpot_print_show_links($params->course, $params->location, $params->reference);
|
||||
?>
|
||||
<SCRIPT>
|
||||
<!--
|
||||
// http://www.krikkit.net/howto_javascript_copy_clipboard.html
|
||||
|
||||
function copy_contents(id) {
|
||||
if (id==null) {
|
||||
id = 'contents';
|
||||
}
|
||||
var obj = null;
|
||||
if (document.getElementById) {
|
||||
obj = document.getElementById(id);
|
||||
}
|
||||
if (obj && window.clipboardData) {
|
||||
window.clipboardData.setData("Text", obj.innerText);
|
||||
alert('<? print_string('copiedtoclipboard', 'hotpot') ?>');
|
||||
}
|
||||
}
|
||||
document.write('<span class="helplink"> <A href="javascript:copy_contents()"><? print_string('copytoclipboard', 'hotpot') ?></A></span>');
|
||||
-->
|
||||
</SCRIPT>
|
||||
<?php
|
||||
print_simple_box_start("center", "96%");
|
||||
if($hp = new hotpot_xml_quiz($_GET)) {
|
||||
print '<pre id="contents">';
|
||||
switch ($params->action) {
|
||||
case 'showxmlsource':
|
||||
print htmlspecialchars($hp->source);
|
||||
break;
|
||||
case 'showxmltree':
|
||||
print_r($hp->xml);
|
||||
break;
|
||||
case 'showhtmlsource':
|
||||
print htmlspecialchars($hp->html);
|
||||
break;
|
||||
case 'showhtmlquiz':
|
||||
print $hp->html;
|
||||
break;
|
||||
}
|
||||
print '</pre>';
|
||||
} else {
|
||||
print_simple_box("Could not open Hot Potatoes XML file", "center", "", "#FFBBBB");
|
||||
}
|
||||
|
||||
print_simple_box_end();
|
||||
print '<br />';
|
||||
close_window_button();
|
||||
?>
|
||||
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
<?PHP
|
||||
// $Id$
|
||||
<?PHP // $Id$
|
||||
|
||||
/// This page prints a hotpot quiz
|
||||
|
||||
|
||||
Reference in New Issue
Block a user