course)) { error("Course is misconfigured"); } if (! $workshop = get_record("workshop", "id", $cm->instance)) { error("Course module is incorrect"); } } else { if (! $workshop = get_record("workshop", "id", $a)) { error("Course module is incorrect"); } if (! $course = get_record("course", "id", $workshop->course)) { error("Course is misconfigured"); } if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id, $course->id)) { error("Course Module ID was incorrect"); } } require_login($course->id); if ($course->category) { $navigation = "id\">$course->shortname ->"; } $strworkshops = get_string("modulenameplural", "workshop"); $strworkshop = get_string("modulename", "workshop"); $strassessments = get_string("assessments", "workshop"); // ... print the header and... print_header("$course->shortname: $workshop->name", "$course->fullname", "$navigation id>$strworkshops -> id\">$workshop->name -> $strassessments", "", "", true); //...get the action require_variable($action); /*************** add comment to assessment (by author, assessor or teacher) ***************************/ if ($action == 'addcomment') { print_heading_with_help(get_string("addacomment", "workshop"), "addingacomment", "workshop"); // get assessment record if (!$assessmentid = $_REQUEST['aid']) { // comes from link or hidden form variable error("Assessment id not given"); } $assessment = get_record("workshop_assessments", "id", $assessmentid); if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid)) { error("Submission not found"); } ?>
\n"; echo "\n";
notice_yesno(get_string("amendassessmentelements","workshop")." ".get_string("again"),
"assessments.php?id=$cm->id&action=editelements", "view.php?id=$cm->id");
}
/*********************** list assessments for grading (Student submissions)(by teachers)***********************/
elseif ($action == 'listungradedstudentsubmissions') {
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
workshop_list_ungraded_assessments($workshop, "student");
print_continue("view.php?a=$workshop->id");
}
/*********************** list assessments for grading (Teacher submissions) (by teachers)***********************/
elseif ($action == 'listungradedteachersubmissions') {
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
workshop_list_ungraded_assessments($workshop, "teacher");
print_continue("view.php?a=$workshop->id");
}
/*********************** list teacher submissions ***********************/
elseif ($action == 'listteachersubmissions') {
workshop_list_teacher_submissions($workshop, $USER);
print_continue("view.php?a=$workshop->id");
}
/*************** update assessment (by teacher or student) ***************************/
elseif ($action == 'updateassessment') {
require_variable($aid);
if (! $assessment = get_record("workshop_assessments", "id", $aid)) {
error("workshop assessment is misconfigured");
}
// first get the assignment elements for maxscores and weights...
if (!$elementsraw = get_records("workshop_elements", "workshopid", $workshop->id, "elementno ASC")) {
print_string("noteonassignmentelements", "workshop");
}
else {
foreach ($elementsraw as $element) {
$elements[] = $element; // to renumber index 0,1,2...
}
}
$timenow = time();
// don't fiddle about, delete all the old and add the new!
delete_records("workshop_grades", "assessmentid", $assessment->id);
$form = (object)$HTTP_POST_VARS;
//determine what kind of grading we have
switch ($workshop->gradingstrategy) {
case 0: // no grading
// Insert all the elements that contain something
foreach ($form->feedback as $key => $thefeedback) {
unset($element);
$element->workshopid = $workshop->id;
$element->assessmentid = $assessment->id;
$element->elementno = $key;
$element->feedback = $thefeedback;
if (!$element->id = insert_record("workshop_grades", $element)) {
error("Could not insert workshop element!");
}
}
$grade = 0; // set to satisfy save to db
break;
case 1: // accumulative grading
// Insert all the elements that contain something
foreach ($form->grade as $key => $thegrade) {
unset($element);
$element->workshopid = $workshop->id;
$element->assessmentid = $assessment->id;
$element->elementno = $key;
$element->feedback = $form->feedback[$key];
$element->grade = $thegrade;
if (!$element->id = insert_record("workshop_grades", $element)) {
error("Could not insert workshop element!");
}
}
// now work out the grade...
$rawgrade=0;
$totalweight=0;
foreach ($form->grade as $key => $grade) {
$maxscore = $elements[$key]->maxscore;
$weight = $WORKSHOP_EWEIGHTS[$elements[$key]->weight];
if ($weight > 0) {
$totalweight += $weight;
}
$rawgrade += ($grade / $maxscore) * $weight;
// echo "\$key, \$maxscore, \$weight, \$totalweight, \$grade, \$rawgrade : $key, $maxscore, $weight, $totalweight, $grade, $rawgrade
";
}
$grade = $workshop->grade * ($rawgrade / $totalweight);
break;
case 2: // error banded graded
// Insert all the elements that contain something
$error = 0.0;
for ($i =0; $i < $workshop->nelements; $i++) {
unset($element);
$element->workshopid = $workshop->id;
$element->assessmentid = $assessment->id;
$element->elementno = $i;
$element->feedback = $form->feedback[$i];
$element->grade = $form->grade[$i];
if (!$element->id = insert_record("workshop_grades", $element)) {
error("Could not insert workshop element!");
}
if (empty($form->grade[$i])){
$error += $WORKSHOP_EWEIGHTS[$elements[$i]->weight];
}
}
// now save the adjustment
unset($element);
$i = $workshop->nelements;
$element->workshopid = $workshop->id;
$element->assessmentid = $assessment->id;
$element->elementno = $i;
$element->grade = $form->grade[$i];
if (!$element->id = insert_record("workshop_grades", $element)) {
error("Could not insert workshop element!");
}
$grade = ($elements[intval($error + 0.5)]->maxscore + $form->grade[$i]) * $workshop->grade / 100;
echo "
".get_string("weightederrorcount", "workshop", intval($error + 0.5))."\n";
break;
case 3: // criteria grading
// save in the selected criteria value in element zero,
unset($element);
$element->workshopid = $workshop->id;
$element->assessmentid = $assessment->id;
$element->elementno = 0;
$element->grade = $form->grade[0];
if (!$element->id = insert_record("workshop_grades", $element)) {
error("Could not insert workshop element!");
}
// now save the adjustment in element one
unset($element);
$element->workshopid = $workshop->id;
$element->assessmentid = $assessment->id;
$element->elementno = 1;
$element->grade = $form->grade[1];
if (!$element->id = insert_record("workshop_grades", $element)) {
error("Could not insert workshop element!");
}
$grade = ($elements[$form->grade[0]]->maxscore + $form->grade[1]) * $workshop->grade / 100;
} // end of switch
// update the time of the assessment record (may be re-edited)...
set_field("workshop_assessments", "timecreated", $timenow, "id", $assessment->id);
if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid)) {
error ("Updateassessment: submission record not found");
}
// if the workshop does need peer agreement AND it's self assessment then set timeagreed
if ($workshop->agreeassessments and ($submission->userid == $assessment->userid)) {
set_field("workshop_assessments", "timeagreed", $timenow, "id", $assessment->id);
}
set_field("workshop_assessments", "grade", $grade, "id", $assessment->id);
// ...and clear any grading of this assessment
set_field("workshop_assessments", "timegraded", 0, "id", $assessment->id);
set_field("workshop_assessments", "gradinggrade", 0, "id", $assessment->id);
// any comment?
if (!empty($form->generalcomment)) {
set_field("workshop_assessments", "generalcomment", $form->generalcomment, "id", $assessment->id);
}
// show grade if grading strategy is not zero
if ($workshop->gradingstrategy) {
echo "".get_string("thegradeis", "workshop").": ".number_format($grade, 2)."% (".get_string("maximumgrade").
" ".number_format($workshop->grade)."%)\n";
}
print_continue("view.php?id=$cm->id");
add_to_log($course->id, "workshop", "assess", "view.php?a=$workshop->id", "$workshop->id");
}
/*************** update comment (by author, assessor or teacher) ***************************/
elseif ($action == 'updatecomment') {
$timenow = time();
$form = (object)$_POST;
// get the comment record...
if (!$comment = get_record("workshop_comments", "id", $_POST['cid'])) {
error("Update to Comment failed");
}
if (!$assessment = get_record("workshop_assessments", "id", $comment->assessmentid)) {
error("Update Comment: Assessment not found");
}
//save the comment for the assessment...
if (isset($form->comments)) {
set_field("workshop_comments", "comments", $form->comments, "id", $comment->id);
set_field("workshop_comments", "timecreated", $timenow, "id", $comment->id);
// ..and kick to comment into life (probably not needed but just in case)
set_field("workshop_comments", "mailed", 0, "id", $comment->id);
echo "
\n";
add_to_log($course->id, "workshop", "comment", "view.php?id=$cm->id", "$workshop->id");
}
print_continue("assessments.php?action=viewassessment&id=$cm->id&aid=$assessment->id");
}
/*************** update grading (by teacher) ***************************/
elseif ($action == 'updategrading') {
$timenow = time();
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
$form = (object)$_POST;
if (!$assessment = get_record("workshop_assessments", "id", $_POST['aid'])) {
error("Update Grading failed");
}
//save the comment and grade for the assessment
if (isset($form->teachercomment)) {
set_field("workshop_assessments", "teachercomment", $form->teachercomment, "id", $assessment->id);
set_field("workshop_assessments", "gradinggrade", $form->gradinggrade, "id", $assessment->id);
set_field("workshop_assessments", "timegraded", $timenow, "id", $assessment->id);
set_field("workshop_assessments", "mailed", 0, "id", $assessment->id);
echo "
\n";
add_to_log($course->id, "workshop", "grade", "view.php?id=$cm->id", "$workshop->id");
}
switch ($form->stype) {
case "student" :
print_continue("assessments.php?action=listungradedstudentsubmissions&id=$cm->id");
break;
case "teacher" :
print_continue("assessments.php?action=listungradedteachersubmissions&id=$cm->id");
break;
}
}
/*********************** view all assessments ***********************/
elseif ($action == 'viewallassessments') {
if (!$submission = get_record("workshop_submissions", "id", $_GET['sid'])) {
error("View All Assessments: submission record not found");
}
if ($assessments = workshop_get_assessments($submission)) {
foreach ($assessments as $assessment) {
workshop_print_assessment($workshop, $assessment);
}
}
// only called from list all submissions
print_continue("submissions.php?action=listallsubmissions&id=$cm->id");
}
/*********************** view assessment ***********************/
elseif ($action == 'viewassessment') {
optional_variable($allowcomments);
if (!isset($allowcomments)) {
$allowcomments = false;
}
// get the assessment record
if (!$assessment = get_record("workshop_assessments", "id", $_GET['aid'])) {
error("Assessment record not found");
}
// show assessment but don't allow changes
workshop_print_assessment($workshop, $assessment, false, $allowcomments);
print_continue("view.php?a=$workshop->id");
}
/*************** no man's land **************************************/
else {
error("Fatal Error: Unknown Action: ".$action."\n");
}
print_footer($course);
?>