course)) {
error("Course is misconfigured");
}
if (! $exercise = get_record("exercise", "id", $cm->instance)) {
error("Course module is incorrect");
}
require_login($course->id, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
// ...log activity...
add_to_log($course->id, "exercise", "view", "view.php?id=$cm->id", $exercise->id, $cm->id);
$strexercises = get_string("modulenameplural", "exercise");
$strexercise = get_string("modulename", "exercise");
// ...display header...
$navlinks = array();
$navlinks[] = array('name' => $strexercises, 'link' => "index.php?id=$course->id", 'type' => 'activity');
$navlinks[] = array('name' => format_string($exercise->name), 'link' => '', 'type' => 'activityinstance');
$navigation = build_navigation($navlinks);
print_header_simple(format_string($exercise->name), "", $navigation,
"", "", true, update_module_button($cm->id, $course->id, $strexercise), navmenu($course, $cm));
if (isteacher($course->id)) {
if (empty($action)) { // no action specified, either go straight to elements page else the admin page
// has the assignment any elements
if (count_records("exercise_elements", "exerciseid", $exercise->id)) {
$action = "teachersview";
}
else {
redirect("assessments.php?action=editelements&id=$cm->id");
}
}
}
elseif (!isguest()) { // it's a student then
if (!$cm->visible) {
notice(get_string("activityiscurrentlyhidden"));
}
switch ($exercise->phase) {
case 0 :
case 1 : $action = 'notavailable'; break;
case 2 : $action = 'studentsview'; break;
case 3 : $action = 'displayfinalgrade';
}
}
else { // it's a guest, oh no!
$action = 'notavailable';
}
/****************** display final grade (for students) ************************************/
if ($action == 'displayfinalgrade' ) {
// show the final grades as stored in the tables...
print_heading(get_string("displayoffinalgrades", "exercise"));
if ($submissions = exercise_get_user_submissions($exercise, $USER)) { // any submissions from user?
echo "
";
echo "".get_string("submissions", "exercise")." | ";
echo "".get_string("gradeforassessment", "exercise")." | ";
echo "".get_string("gradeforsubmission", "exercise", $course->teacher)." | ";
echo "".get_string("overallgrade", "exercise")." |
\n";
// now the weights
echo "".get_string("maximumgrade")." | ";
echo "$exercise->gradinggrade | \n";
echo "$exercise->grade | \n";
echo " |
\n";
// first get user's own assessment reord, it should contain their grading grade
if ($ownassessments = exercise_get_user_assessments($exercise, $USER)) {
foreach ($ownassessments as $ownassessment) {
break; // there should only be one
}
}
else {
$ownassessment->gradinggrade = 0;
}
foreach ($submissions as $submission) {
if ($assessments = exercise_get_assessments($submission)) {
foreach ($assessments as $assessment) { // (normally there should only be one
$gradinggrade = number_format($ownassessment->gradinggrade * $exercise->gradinggrade / 100.0,
1);
$grade = number_format($assessment->grade * $exercise->grade / 100.0, 1);
$overallgrade = number_format(($assessment->grade * $exercise->grade / 100.0) +
($ownassessment->gradinggrade * $exercise->gradinggrade / 100.0 ), 1);
if ($submission->late) {
$grade = "(".$grade.")";
$overallgrade = "(".$overallgrade.")";
}
echo "".exercise_print_submission_title($exercise, $submission)." | \n";
echo "$gradinggrade | ";
echo "$grade | ";
echo "$overallgrade |
\n";
}
}
}
}
echo "
\n";
if ($exercise->showleaguetable) {
exercise_print_league_table($exercise);
}
echo "
".get_string("maximumgrade").": $exercise->grade
\n";
}
/****************** make final grades available (for teachers only)**************/
elseif ($action == 'makeleaguetableavailable') {
if (!isteacheredit($course->id)) {
error("Only teachers with editing permissions can do this.");
}
set_field("exercise", "phase", 3, "id", "$exercise->id");
add_to_log($course->id, "exercise", "display", "view.php?id=$cm->id", "$exercise->id", $cm->id);
redirect("view.php?id=$cm->id", get_string("movingtophase", "exercise", 3));
}
/*********************** assignment not available (for students)***********************/
elseif ($action == 'notavailable') {
print_heading(get_string("notavailable", "exercise"));
}
/****************** open exercise for student assessments and submissions (phase 2) (for teachers)**/
elseif ($action == 'openexercise') {
if (!isteacheredit($course->id)) {
error("Only teachers with editing permissions can do this.");
}
// move to phase 2, check that teacher has made enough submissions
if (exercise_count_teacher_submissions($exercise) == 0) {
redirect("view.php?id=$cm->id", get_string("noexercisedescriptionssubmitted", "exercise"));
}
elseif (($exercise->gradingstrategy == 3) and ($exercise->nelements ==1 )) {
// only one criterion specified
redirect("view.php?id=$cm->id", get_string("numberofcriterionelements", "exercise"));
} else {
set_field("exercise", "phase", 2, "id", "$exercise->id");
add_to_log($course->id, "exercise", "open", "view.php?id=$cm->id", "$exercise->id", $cm->id);
redirect("view.php?id=$cm->id", get_string("movingtophase", "exercise", 2));
}
}
/****************** set up assignment (move back to phase 1) (for teachers)***********************/
elseif ($action == 'setupassignment') {
if (!isteacher($course->id)) {
error("Only teachers with editing permissions can do this.");
}
set_field("exercise", "phase", 1, "id", "$exercise->id");
add_to_log($course->id, "exercise", "set up", "view.php?id=$cm->id", "$exercise->id", $cm->id);
redirect("view.php?id=$cm->id", get_string("movingtophase", "exercise", 1));
}
/****************** showsubmissions (for students, in phase 3)***********************/
elseif ($action == 'showsubmissions') {
exercise_print_assignment_info($exercise);
print_heading(get_string("submissionsnowclosed", "exercise"));
// show student's assessment (linked to the teacher's exercise/submission
print_heading(get_string("yourassessment", "exercise"));
exercise_list_teacher_submissions($exercise, $USER);
echo "
";
if ($submissions = exercise_get_user_submissions($exercise, $USER)) {
print_heading(get_string("yoursubmission", "exercise"));
print_simple_box_start("center");
$table->head = array (get_string("submission", "exercise"), get_string("submitted", "exercise"),
get_string("assessed", "exercise"), get_string("grade"));
$table->width = "100%";
$table->align = array ("left", "left", "left", "center");
$table->size = array ("*", "*", "*", "*");
$table->cellpadding = 2;
$table->cellspacing = 0;
foreach ($submissions as $submission) {
if ($assessments = exercise_get_assessments($submission)) {
// should only be one but we'll loop anyway
foreach ($assessments as $assessment) {
$table->data[] = array(exercise_print_submission_title($exercise, $submission),
userdate($submission->timecreated), userdate($assessment->timecreated),
"id&aid=$assessment->id\">".$assessment->grade * $exercise->grade / 100.0."");
}
} else {
// submission not yet assessed (by teacher)
$table->data[] = array(exercise_print_submission_title($exercise, $submission),
userdate($submission->timecreated), get_string("notassessedyet", "exercise"), 0);
}
}
print_table($table);
print_simple_box_end();
} else {
print_heading(get_string("nosubmissions", "exercise"));
}
// always allow student to resubmit
if (exercise_test_for_resubmission($exercise, $USER)) {
// if resubmission requested print upload form
echo "
";
print_heading(get_string("pleasesubmityourwork", "exercise").":");
exercise_print_upload_form($exercise);
}
echo "
";
}
/****************** student's view could be in 1 of 3 stages ***********************/
elseif ($action == 'studentsview') {
exercise_print_assignment_info($exercise);
// is a password needed?
if ($exercise->usepassword) {
$correctpass = false;
if (isset($_POST['userpassword'])) {
if ($exercise->password == md5(trim($_POST['userpassword']))) {
$USER->exerciseloggedin[$exercise->id] = true;
$correctpass = true;
}
} elseif (isset($USER->exerciseloggedin[$exercise->id])) {
$correctpass = true;
}
if (!$correctpass) {
print_simple_box_start("center");
echo "