moodle/mod/journal/report.php

121 lines
4.1 KiB
PHP
Raw Normal View History

2001-11-22 06:23:56 +00:00
<?PHP // $Id$
require_once("../../config.php");
require_once("lib.php");
2001-11-22 06:23:56 +00:00
require_variable($id); // course module
if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect");
}
if (! $course = get_record("course", "id", $cm->course)) {
error("Course module is misconfigured");
}
require_login($course->id);
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
if (! $journal = get_record("journal", "id", $cm->instance)) {
error("Course module is incorrect");
}
// make some easy ways to access the entries.
if ( $eee = get_records("journal_entries", "journal", $journal->id)) {
2001-11-22 06:23:56 +00:00
foreach ($eee as $ee) {
$entrybyuser[$ee->userid] = $ee;
2002-07-29 09:48:52 +00:00
$entrybyentry[$ee->id] = $ee;
2001-11-22 06:23:56 +00:00
}
} else {
$entrybyuser = array () ;
2001-11-22 06:23:56 +00:00
$entrybyentry = array () ;
}
print_header("$course->shortname: Journals", "$course->fullname",
2002-06-19 05:05:05 +00:00
"<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> ->
2001-11-22 06:23:56 +00:00
<A HREF=index.php?id=$course->id>Journals</A> ->
<A HREF=view.php?id=$cm->id>$journal->name</A> -> Responses", "",
"", true);
if ($data = data_submitted()) {
2001-11-22 06:23:56 +00:00
$feedback = array();
$data = (array)$data;
2001-11-22 06:23:56 +00:00
// Peel out all the data from variable names.
foreach ($data as $key => $val) {
2001-11-22 06:23:56 +00:00
if ($key <> "id") {
$type = substr($key,0,1);
$num = substr($key,1);
$feedback[$num][$type] = $val;
}
}
$timenow = time();
$count = 0;
foreach ($feedback as $num => $vals) {
$entry = $entrybyentry[$num];
// Only update entries where feedback has actually changed.
if (($vals[r] <> $entry->rating) || ($vals[c] <> addslashes($entry->comment))) {
2002-07-29 13:03:39 +00:00
$newentry->rating = $vals[r];
$newentry->comment = $vals[c];
$newentry->teacher = $USER->id;
$newentry->timemarked = $timenow;
2002-07-29 13:03:39 +00:00
$newentry->mailed = 0; // Make sure mail goes out (again, even)
$newentry->id = $num;
if (! update_record("journal_entries", $newentry)) {
notify("Failed to update the journal feedback for user $entry->userid");
} else {
$count++;
}
$entrybyuser[$entry->userid]->rating = $vals[r];
$entrybyuser[$entry->userid]->comment = $vals[c];
$entrybyuser[$entry->userid]->teacher = $USER->id;
$entrybyuser[$entry->userid]->timemarked = $timenow;
2001-11-22 06:23:56 +00:00
}
}
add_to_log($course->id, "journal", "update feedback", "report.php?id=$cm->id", "$count users");
2003-01-06 02:56:48 +00:00
notify(get_string("feedbackupdated", "journal", "$count"), "green");
2001-11-22 06:23:56 +00:00
} else {
add_to_log($course->id, "journal", "view responses", "report.php?id=$cm->id", "$journal->id");
2001-11-22 06:23:56 +00:00
}
$teachers = get_course_teachers($course->id);
if (! $users = get_course_users($course->id)) {
2003-01-06 02:56:48 +00:00
print_heading(get_string("nousersyet"));
2001-11-22 06:23:56 +00:00
} else {
echo "<FORM ACTION=report.php METHOD=post>\n";
2001-11-22 06:23:56 +00:00
if ($usersdone = journal_get_users_done($journal)) {
foreach ($usersdone as $user) {
$entry = $entrybyuser[$user->id];
2002-08-12 09:38:31 +00:00
journal_print_user_entry($course, $user, $entry, $teachers, $JOURNAL_RATING);
}
2001-11-22 06:23:56 +00:00
}
foreach ($users as $user) {
if (! $usersdone[$user->id]) {
$entry = NULL;
2002-08-12 09:38:31 +00:00
journal_print_user_entry($course, $user, $entry, $teachers, $JOURNAL_RATING);
2001-11-22 06:23:56 +00:00
}
}
2003-01-06 02:56:48 +00:00
$strsaveallfeedback = get_string("saveallfeedback", "journal");
echo "<CENTER>";
echo "<INPUT TYPE=hidden NAME=id VALUE=\"$cm->id\">";
2003-01-06 02:56:48 +00:00
echo "<INPUT TYPE=submit VALUE=\"$strsaveallfeedback\">";
echo "</CENTER>";
echo "</FORM>";
2001-11-22 06:23:56 +00:00
}
2001-11-22 06:23:56 +00:00
print_footer($course);
?>