From f15eb92c2c8b3473071b2be926824f4454e36845 Mon Sep 17 00:00:00 2001 From: mark-nielsen Date: Sat, 9 Sep 2006 01:58:48 +0000 Subject: [PATCH] Removed essay grading code from view.php into essay.php. --- mod/lesson/essay.php | 347 ++++++++++++++++++++++++++++++++++++++++ mod/lesson/lib.php | 2 +- mod/lesson/locallib.php | 4 +- mod/lesson/styles.php | 8 + mod/lesson/tabs.php | 2 +- mod/lesson/view.php | 323 +------------------------------------ 6 files changed, 362 insertions(+), 324 deletions(-) create mode 100644 mod/lesson/essay.php diff --git a/mod/lesson/essay.php b/mod/lesson/essay.php new file mode 100644 index 0000000000..e839366a27 --- /dev/null +++ b/mod/lesson/essay.php @@ -0,0 +1,347 @@ +id, false, $cm); + + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + + require_capability('mod/lesson:edit'); + +/// Handle any preprocessing before header is printed - based on $mode + switch ($mode) { + case 'display': // Default view - get the necessary data + // Get lesson pages that are essay + if ($pages = get_records_select('lesson_pages', "lessonid = $lesson->id AND qtype = ".LESSON_ESSAY)) { + // Get only the attempts that are in response to essay questions + if ($essayattempts = get_records_select('lesson_attempts', 'pageid IN('.implode(',', array_keys($pages)).')')) { + // Get all the users who have taken this lesson, order by their last name + if (!$users = get_records_sql("SELECT DISTINCT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}lesson_attempts a + WHERE a.lessonid = '$lesson->id' and + u.id = a.userid + ORDER BY u.lastname")) { + error('Error: could not find users'); + } + } else { + $mode = 'none'; // not displaying anything + lesson_set_message(get_string('noonehasanswered', 'lesson')); + } + } else { + $mode = 'none'; // not displaying anything + lesson_set_message(get_string('noessayquestionsfound', 'lesson')); + } + break; + case 'grade': // Grading form - get the necessary data + confirm_sesskey(); + + $attemptid = required_param('attemptid', PARAM_INT); + + if (!$attempt = get_record('lesson_attempts', 'id', $attemptid)) { + error('Error: could not find attempt'); + } + if (!$page = get_record('lesson_pages', 'id', $attempt->pageid)) { + error('Error: could not find lesson page'); + } + if (!$user = get_record('user', 'id', $attempt->userid)) { + error('Error: could not find users'); + } + if (!$answer = get_record('lesson_answers', 'lessonid', $lesson->id, 'pageid', $page->id)) { + error('Error: could not find answer'); + } + break; + case 'update': + if (confirm_sesskey() and $form = data_submitted($CFG->wwwroot.'/mod/lesson/essay.php')) { + if (optional_param('cancel', 0)) { + redirect("$CFG->wwwroot/mod/lesson/essay.php?id=$cm->id"); + } + + $attemptid = required_param('attemptid', PARAM_INT); + + if (!$attempt = get_record('lesson_attempts', 'id', $attemptid)) { + error('Error: could not find essay'); + } + if (!$grades = get_records_select('lesson_grades', "lessonid = $lesson->id and userid = $attempt->userid", 'completed', '*', $attempt->retry, 1)) { + error('Error: could not find grades'); + } + + $essayinfo = new stdClass; + $essayinfo = unserialize($attempt->useranswer); + + $essayinfo->graded = 1; + $essayinfo->score = clean_param($form->score, PARAM_INT); + $essayinfo->response = stripslashes_safe($form->response); + $essayinfo->sent = 0; + if (!$lesson->custom && $essayinfo->score == 1) { + $attempt->correct = 1; + } else { + $attempt->correct = 0; + } + + $attempt->useranswer = addslashes(serialize($essayinfo)); + + if (!update_record('lesson_attempts', $attempt)) { + error('Could not update essay score'); + } + + // Get grade information + $grade = current($grades); + $gradeinfo = lesson_grade($lesson, $attempt->retry, $attempt->userid); + + // Set and update + $updategrade->id = $grade->id; + $updategrade->grade = $gradeinfo->grade; + if(update_record('lesson_grades', $updategrade)) { + // Log it + add_to_log($course->id, 'lesson', 'update grade', "essay.php?id=$cm->id", $lesson->name, $cm->id); + + redirect("$CFG->wwwroot/mod/lesson/essay.php?id=$cm->id", get_string('updatesuccess', 'lesson')); + } else { + redirect("$CFG->wwwroot/mod/lesson/essay.php?id=$cm->id", get_string('updatefailed', 'lesson')); + } + } else { + error('Something is wrong with the form data'); + } + break; + case 'email': // Sending an email(s) to a single user or all + confirm_sesskey(); + + // Get our users (could be singular) + if ($userid = optional_param('userid', 0, PARAM_INT)) { + $queryadd = " AND userid = $userid"; + if (! $users = get_records('user', 'id', $userid)) { + error('Error: could not find users'); + } + } else { + $queryadd = ''; + if (!$users = get_records_sql("SELECT DISTINCT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}lesson_attempts a + WHERE a.lessonid = '$lesson->id' and + u.id = a.userid + ORDER BY u.lastname")) { + error('Error: could not find users'); + } + } + + // Get lesson pages that are essay + if (!$pages = get_records_select('lesson_pages', "lessonid = $lesson->id AND qtype = ".LESSON_ESSAY)) { + error('Error: could not find lesson pages'); + } + + // Get only the attempts that are in response to essay questions + $pageids = implode(',', array_keys($pages)); // all the pageids in comma seperated list + if (!$attempts = get_records_select('lesson_attempts', "pageid IN($pageids)".$queryadd)) { + error ('No one has answered essay questions yet...'); + } + // Get the answers + if (!$answers = get_records_select('lesson_answers', "lessonid = $lesson->id AND pageid IN($pageids)", '', 'pageid, score')) { + error ('Could not find answer records.'); + } + $options = new stdClass; + $options->noclean = true; + + foreach ($attempts as $attempt) { + $essayinfo = unserialize($attempt->useranswer); + if ($essayinfo->graded and !$essayinfo->sent) { + $subject = get_string('essayemailsubject', 'lesson', format_string($pages[$attempt->pageid]->title,true)); + $message = get_string('question', 'lesson').':
'; + $message .= format_text($pages[$attempt->pageid]->contents, FORMAT_MOODLE, $options); + $message .= '

'; + $message .= get_string('yourresponse', 'lesson').':
'; + $message .= format_text(stripslashes($essayinfo->answer)); + $message .= '

'; + $message .= get_string('commentswithname', 'lesson', $USER).':
'; + $message .= format_text(stripslashes($essayinfo->response), FORMAT_MOODLE, $options); + $message .= '

'; + $grades = get_records_select('lesson_grades', "lessonid = $lesson->id and userid = $attempt->userid", 'completed', '*', $attempt->retry, 1); + $grade = current($grades); + if ($lesson->custom) { + $points->score = $essayinfo->score; + $points->outof = $answers[$attempt->pageid]->score; + $message .= get_string('youhavereceived', 'lesson', $points); + } else { + $points->score = $essayinfo->score; + $points->outof = 1; + $message .= get_string('youhavereceived', 'lesson', $points); + } + $message .= '

'; + $message .= get_string('yourgradeisnow', 'lesson', $grade->grade).'%.'; + + $plaintxt = format_text_email($message, FORMAT_HTML); + + if(email_to_user($users[$attempt->userid], $USER, $subject, $plaintxt, $message)) { + $essayinfo->sent = 1; + $attempt->useranswer = addslashes(serialize($essayinfo)); + update_record('lesson_attempts', $attempt); + // Log it + add_to_log($course->id, 'lesson', 'update email essay grade', "essay.php?id=$cm->id", format_string($pages[$attempt->pageid]->title,true).': '.fullname($users[$attempt->userid]), $cm->id); + } else { + error('Emailing Failed'); + } + } + } + redirect("$CFG->wwwroot/mod/lesson/essay.php?id=$cm->id", get_string('emailsuccess', 'lesson')); + break; + } + + // Log it + add_to_log($course->id, 'lesson', 'view grade', "essay.php?id=$cm->id", get_string('manualgrading', 'lesson'), $cm->id); + + lesson_print_header($cm, $course, $lesson, 'essay'); + + switch ($mode) { + case 'display': + // Expects $user, $essayattempts and $pages to be set already + + // Group all the essays by userid + $studentessays = array(); + foreach ($essayattempts as $essay) { + // Not very nice :) but basically + // this organizes the essays so we know how many + // times a student answered an essay per try and per page + $studentessays[$essay->userid][$essay->pageid][$essay->retry][] = $essay; + } + + // Setup table + $table = new stdClass; + $table->head = array($course->students, get_string('essays', 'lesson'), get_string('email', 'lesson')); + $table->align = array('left', 'left', 'left'); + $table->wrap = array('nowrap', 'nowrap', 'nowrap'); + + // Get the student ids of the users who have answered the essay question + $userids = array_keys($studentessays); + + // Cycle through all the students + foreach ($userids as $userid) { + $studentname = fullname($users[$userid], true); + $essaylinks = array(); + + // Number of attempts on the lesson + $attempts = count_records('lesson_grades', 'userid', $userid, 'lessonid', $lesson->id); + + // Go through each essay page + foreach ($studentessays[$userid] as $page => $tries) { + $count = 0; + + // Go through each attempt per page + foreach($tries as $try) { + if ($count == $attempts) { + break; // Stop displaying essays (attempt not completed) + } + $count++; + + // Make sure they didn't answer it more than the max number of attmepts + if (count($try) > $lesson->maxattempts) { + $essay = $try[$lesson->maxattempts-1]; + } else { + $essay = end($try); + } + + // Start processing the attempt + $essayinfo = unserialize($essay->useranswer); + + // Different colors for all the states of an essay (graded, if sent, not graded) + if (!$essayinfo->graded) { + $class = ' class="graded"'; + } elseif (!$essayinfo->sent) { + $class = ' class="sent"'; + } else { + $class = ' class="ungraded"'; + } + // link for each essay + $essaylinks[] = "wwwroot/mod/lesson/essay.php?id=$cm->id&mode=grade&attemptid=$essay->id&sesskey=".sesskey().'">'.userdate($essay->timeseen, get_string('strftimedatetime')).' '.format_string($pages[$essay->pageid]->title,true).''; + } + } + // email link for this user + $emaillink = "wwwroot/mod/lesson/essay.php?id=$cm->id&mode=email&userid=$userid&sesskey=".sesskey().'">'.get_string('emailgradedessays', 'lesson').''; + + $table->data[] = array(print_user_picture($userid, $course->id, $users[$userid]->picture, 0, true).$studentname, implode("
\n", $essaylinks), $emaillink); + } + // email link for all users + $emailalllink = "wwwroot/mod/lesson/essay.php?id=$cm->id&mode=email&sesskey=".sesskey().'">'.get_string('emailallgradedessays', 'lesson').''; + + $table->data[] = array(' ', ' ', $emailalllink); + + print_table($table); + break; + case 'grade': + // Grading form + // Expects the following to be set: $attemptid, $answer, $user, $page, $attempt + + echo '
+
+ + + + '; + + // All tables will have these settings + $table = new stdClass; + $table->align = array('left'); + $table->wrap = array(); + $table->width = '50%'; + $table->size = array('100%'); + $table->class = 'generaltable gradetable'; + + // Print the question + $table->head = array(get_string('question', 'lesson')); + $options = new stdClass; + $options->noclean = true; + $table->data[] = array(format_text($page->contents, FORMAT_MOODLE, $options)); + + print_table($table); + + unset($table->data); + + // Now the user's answer + $essayinfo = unserialize($attempt->useranswer); + + $table->head = array(get_string('studentresponse', 'lesson', fullname($user, true))); + $table->data[] = array(format_text(stripslashes($essayinfo->answer))); + + print_table($table); + + unset($table->data); + + // Now a response box and grade drop-down for grader + $table->head = array(get_string('comments', 'lesson')); + $table->data[] = array(print_textarea(false, 15, 60, 0, 0, 'response', format_text($essayinfo->response, FORMAT_PLAIN, $options), $course->id, true)); + $options = array(); + if ($lesson->custom) { + for ($i=$answer->score; $i>=0; $i--) { + $options[$i] = $i; + } + } else { + $options[0] = get_string('nocredit', 'lesson'); + $options[1] = get_string('credit', 'lesson'); + } + $table->data[] = array(get_string('essayscore', 'lesson').': '.choose_from_menu($options, 'score', $essayinfo->score, '', '', '', true)); + + print_table($table); + echo '
+ + +
+
+
'; + break; + } + + print_footer($course); +?> \ No newline at end of file diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index a6d11420a8..9cf29e40d4 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -458,7 +458,7 @@ function lesson_get_view_actions() { } function lesson_get_post_actions() { - return array('end','start'); + return array('end','start', 'update grade attempt'); } ?> diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 380170e3d1..ec589c4ad1 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -245,6 +245,8 @@ function lesson_print_header($cm, $course, $lesson, $currenttab = '', $printhead if (!empty($currenttab) and has_capability('mod/lesson:manage', $context)) { include($CFG->dirroot.'/mod/lesson/tabs.php'); } + + lesson_print_messages(); } /** @@ -257,7 +259,7 @@ function lesson_print_header($cm, $course, $lesson, $currenttab = '', $printhead **/ function lesson_get_basics($cmid = 0, $lessonid = 0) { if ($cmid) { - if (!$cm = get_record('course_modules', 'id', $cmid)) { + if (!$cm = get_coursemodule_from_id('lesson', $cmid)) { error('Course Module ID was incorrect'); } if (!$course = get_record('course', 'id', $cm->course)) { diff --git a/mod/lesson/styles.php b/mod/lesson/styles.php index 55de0e5a72..54c5718fe2 100644 --- a/mod/lesson/styles.php +++ b/mod/lesson/styles.php @@ -22,6 +22,14 @@ color:#999999; } +#mod-lesson-essay .gradetable { + margin-bottom: 20px; +} + +#mod-lesson-essay .buttons { + text-align: center; +} + /*** *** Style for responses ***/ diff --git a/mod/lesson/tabs.php b/mod/lesson/tabs.php index 8a456bb76c..12d8e9759d 100644 --- a/mod/lesson/tabs.php +++ b/mod/lesson/tabs.php @@ -40,7 +40,7 @@ $row[] = new tabobject('navigation', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&action=navigation", get_string('preview', 'lesson'), get_string('previewlesson', 'lesson', format_string($lesson->name))); $row[] = new tabobject('reports', "$CFG->wwwroot/mod/lesson/report.php?id=$cm->id", get_string('reports', 'lesson'), get_string('viewreports', 'lesson', $counts)); if (has_capability('mod/lesson:edit', $context)) { - $row[] = new tabobject('essayview', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&action=essayview", get_string('manualgrading', 'lesson')); + $row[] = new tabobject('essay', "$CFG->wwwroot/mod/lesson/essay.php?id=$cm->id", get_string('manualgrading', 'lesson')); } if ($lesson->highscores) { $row[] = new tabobject('highscores', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&action=highscores", get_string('highscores', 'lesson')); diff --git a/mod/lesson/view.php b/mod/lesson/view.php index d2306150ca..02267043e4 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -27,19 +27,9 @@ } require_login($course->id, false, $cm); - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - switch ($action) { - case 'essayview': - case 'essaygrade': - case 'updategrade': - case 'emailessay': - require_capability('mod/lesson:edit', $context); - break; - default: - require_capability('mod/lesson:view', $context); - break; - } + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + require_capability('mod/lesson:view', $context); /// Print the page header @@ -1541,315 +1531,6 @@ } } - /*******************essay view **************************************/ // 6/29/04 - elseif ($action == 'essayview') { - print_heading_with_help(format_string($lesson->name,true), "overview", "lesson"); - - // get lesson pages that are essay - if (!$pages = get_records_select("lesson_pages", "lessonid = $lesson->id AND qtype = ".LESSON_ESSAY)) { - notify(get_string('noessayquestionsfound', 'lesson')); - print_footer($course); - exit(); - } - - // get only the attempts that are in response to essay questions - $pageids = implode(",", array_keys($pages)); // all the pageids in comma seperated list - if (!$essayattempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND pageid IN($pageids)")) { - notify(get_string('noonehasanswered', 'lesson'));//error ("No one has answered essay questions yet..."); - print_footer($course); - exit(); - } - - // get all the users who have taken this lesson, order by their last name - if (!$users = get_records_sql("SELECT DISTINCT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}lesson_attempts a - WHERE a.lessonid = '$lesson->id' and - u.id = a.userid - ORDER BY u.lastname")) { - error("Error: could not find users"); - } - - // group all the essays by userid - $studentessays = array(); - foreach ($essayattempts as $essay) { - // not very nice :) but basically - // this organizes the essays so I know how many times a student answered an essay per try and per page - $studentessays[$essay->userid][$essay->pageid][$essay->retry][] = $essay; - } - - $table = new stdClass; - $table->head = array($course->students, get_string("essays", "lesson"), get_string("email", "lesson")); - $table->align = array("left", "left", "left"); - $table->wrap = array("nowrap", "wrap", "nowrap"); - $table->width = "90%"; - $table->size = array("*", "70%", "*"); - - // get the student ids of the students who have answered the essay question - $studentids = array_keys($studentessays); - - // cycle through all the ids - foreach ($studentids as $id) { - $studentname = fullname($users[$id], true); - $essaylinks = array(); - - // number of attempts on the lesson - $attempts = count_records('lesson_grades', 'userid', $id, 'lessonid', $lesson->id); - - // go through each essay - foreach ($studentessays[$id] as $page => $tries) { - $count = 0; - - // go through each essay per page - foreach($tries as $try) { - if ($count == $attempts) { - break; // stop displaying essays (attempt not completed) - } - $count++; - - // make sure they didn't answer it more than the max number of attmepts - if (count($try) > $lesson->maxattempts) { - $essay = $try[$lesson->maxattempts-1]; - } else { - $essay = end($try); - } - $essayinfo = unserialize($essay->useranswer); - // different colors for all the states of an essay (graded, if sent, not graded) - if (!$essayinfo->graded) { - $style = "style='color:#DF041E;text-decoration:underline;'"; - } elseif (!$essayinfo->sent) { - $style = "style='color:#006600;text-decoration:underline;'"; - } else { - $style = "style='color:#999999;'"; - } - // link for each essay - $essaylinks[] = "id&action=essaygrade&attemptid=$essay->id\">".format_string($pages[$essay->pageid]->title,true).""; - } - } - // email link for this user - $emaillink = "id&action=emailessay&userid=".$id."&sesskey=".$USER->sesskey."\">".get_string("emailgradedessays", "lesson").""; - - $table->data[] = array($studentname, implode(", ", $essaylinks), $emaillink); - } - // email link for all users - $emailalllink = "id&action=emailessay&sesskey=".$USER->sesskey."\">".get_string("emailallgradedessays", "lesson").""; - - $table->data[] = array(" ", " ", $emailalllink); - - print_table($table); - } - - /*******************grade essays **************************************/ // 6/29/04 - elseif ($action == 'essaygrade') { - print_heading_with_help(format_string($lesson->name,true), "overview", "lesson"); - - $attemptid = required_param('attemptid', PARAM_INT); - - if (!$essay = get_record("lesson_attempts", "id", $attemptid)) { - error("Error: could not find attempt"); - } - if (!$page = get_record("lesson_pages", "id", $essay->pageid)) { - error("Error: could not find lesson pages"); - } - if (!$student = get_record("user", "id", $essay->userid)) { - error("Error: could not find users"); - } - if (!$answer = get_record("lesson_answers", "lessonid", $lesson->id, "pageid", $page->id)) { - error("Error: could not find answer"); - } - - - echo "
\n"; - echo "id\" />\n"; - echo "\n"; - echo "\n"; - echo "sesskey."\" />\n"; - - // all tables will have these - $table = new stdClass; - $table->align = array("left"); - $table->wrap = array(); - $table->width = "70%"; - $table->size = array("100%"); - - - $table->head = array(get_string("question", "lesson")); - $options = new stdClass; - $options->noclean = true; - $table->data[] = array(format_text($page->contents, FORMAT_MOODLE, $options)); - - print_table($table); - echo "
"; - - unset($table->data); - $essayinfo = unserialize($essay->useranswer); - - $studentname = $student->firstname." ".$student->lastname; - $table->head = array(get_string("studentresponse", "lesson", $studentname)); - $table->data[] = array(format_text(stripslashes($essayinfo->answer))); - - print_table($table); - echo "
"; - - unset($table->data); - - $table->head = array(get_string("comments", "lesson")); - $table->data[] = array("\n"); - $options = array(); - if ($lesson->custom) { - for ($i=$answer->score; $i>=0; $i--) { - $options[$i] = $i; - } - } else { - $options[0] = "incorrect"; - $options[1] = "correct"; - } - $table->data[] = array(get_string("essayscore", "lesson").": ".lesson_choose_from_menu($options, "score", $essayinfo->score, "", "", "", true)); - - print_table($table); - echo "
"; - echo "
"; - echo ""; - echo ""; - echo ""; - echo "
"; - echo "
"; - - - } - - /*******************update grade**************************************/ // 6/29/04 - elseif ($action == 'updategrade') { - print_heading_with_help(format_string($lesson->name,true), "overview", "lesson"); - - confirm_sesskey(); - - $form = data_submitted(); - - if (!$essay = get_record("lesson_attempts", "id", clean_param($form->attemptid, PARAM_INT))) { - error("Error: could not find essay"); - } - - if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id and userid = $essay->userid", "completed", "*", $essay->retry, 1)) { - error("Error: could not find grades"); - } - - $essayinfo = new stdClass; - $essayinfo = unserialize($essay->useranswer); - - $essayinfo->graded = 1; - $essayinfo->score = clean_param($form->score, PARAM_INT); - $essayinfo->response = stripslashes_safe($form->response); - $essayinfo->sent = 0; - if (!$lesson->custom && $essayinfo->score == 1) { - $essay->correct = 1; - } else { - $essay->correct = 0; - } - - $essay->useranswer = addslashes(serialize($essayinfo)); - - if (!update_record("lesson_attempts", $essay)) { - error("Could not update essay score"); - } - - $grade = current($grades); - - $gradeinfo = lesson_grade($lesson, $essay->retry, $essay->userid); - $updategrade->id = $grade->id; - $updategrade->grade = $gradeinfo->grade; - if(update_record("lesson_grades", $updategrade)) { - redirect("view.php?id=$cm->id&action=essayview", get_string("updatesuccess", "lesson")); - } else { - echo get_string("updatefailed", "lesson")."!
"; - echo "id&action=essayview\">".get_string("continue", "lesson").""; - exit(); - } - } - - /*******************email essay **************************************/ // 6/29/04 - elseif ($action == 'emailessay') { - print_heading_with_help(format_string($lesson->name,true), "overview", "lesson"); - - confirm_sesskey(); - - if ($userid = optional_param('userid', 0, PARAM_INT)) { - $queryadd = " AND userid = ".$userid; - if (! $users = get_records("user", "id", $userid)) { - error("Error: could not find users"); - } - } else { - $queryadd = ""; - if (!$users = lesson_get_participants($lesson->id)) { - error("Error: could not find users"); - } - } - - // get lesson pages that are essay - if (!$pages = get_records_select("lesson_pages", "lessonid = $lesson->id AND qtype = ".LESSON_ESSAY)) { - error("Error: could not find lesson pages"); - } - - // get only the attempts that are in response to essay questions - $pageids = implode(",", array_keys($pages)); // all the pageids in comma seperated list - if (!$essayattempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND pageid IN($pageids)".$queryadd)) { - error ("No one has answered essay questions yet..."); - } - - if (!$essayanswers = get_records_select("lesson_answers", "lessonid = $lesson->id AND pageid IN($pageids)", "", "pageid, score")) { - error ("Could not find answer records."); - } - - $options = new stdClass; - $options->noclean = true; - - // NoticeFix big fix, change $essay[]'s that use $USER to just $USER - foreach ($essayattempts as $essay) { - $essayinfo = unserialize($essay->useranswer); - if ($essayinfo->graded && !$essayinfo->sent) { - $subject = get_string('essayemailsubject', 'lesson', format_string($pages[$essay->pageid]->title,true)); - $message = get_string('question', 'lesson').":
"; - $message .= format_text($pages[$essay->pageid]->contents, FORMAT_MOODLE, $options); - $message .= "

"; - $message .= get_string('yourresponse', 'lesson').":
"; - $message .= format_text(stripslashes($essayinfo->answer)); - $message .= "

"; - $message .= get_string('commentswithname', 'lesson', $USER).":
"; - $message .= format_text(stripslashes($essayinfo->response), FORMAT_MOODLE, $options); - $message .= "

"; - $grades = get_records_select("lesson_grades", "lessonid = $lesson->id and userid = $essay->userid", "completed", "*", $essay->retry, 1); - $grade = current($grades); - if ($lesson->custom) { - $points->score = $essayinfo->score; - $points->outof = $essayanswers[$essay->pageid]->score; - $message .= get_string("youhavereceived", "lesson", $points); - } else { - $points->score = $essayinfo->score; - $points->outof = 1; - $message .= get_string("youhavereceived", "lesson", $points); - } - $message .= "

"; - $message .= get_string("yourgradeisnow", "lesson", $grade->grade)."%."; - - $plaintxt = format_text_email($message, FORMAT_HTML); - - if(email_to_user($users[$essay->userid], $USER, $subject, $plaintxt, $message)) { - $essayinfo->sent = 1; - $essay->useranswer = addslashes(serialize($essayinfo)); - update_record("lesson_attempts", $essay); - } else { - echo "Email Failed!
"; - echo "id&action=essayview\">".get_string("continue", "lesson").""; - echo ""; - exit(); - } - } - } - redirect("view.php?id=$cm->id&action=essayview", get_string("emailsuccess", "lesson")); - } - /*******************high scores **************************************/ elseif ($action == 'highscores') { print_heading_with_help(format_string($lesson->name,true), "overview", "lesson"); -- 2.39.5