3 require_once("../../config.php");
4 require_once("lib.php");
6 $id = required_param('id', PARAM_INT
); // course module
8 if (! $cm = get_coursemodule_from_id('journal', $id)) {
9 error("Course Module ID was incorrect");
12 if (! $course = get_record("course", "id", $cm->course
)) {
13 error("Course module is misconfigured");
16 require_login($course->id
, false, $cm);
18 if (!isteacher($course->id
)) {
19 error("Only teachers can look at this page");
22 if (! $journal = get_record("journal", "id", $cm->instance
)) {
23 error("Course module is incorrect");
26 // make some easy ways to access the entries.
27 if ( $eee = get_records("journal_entries", "journal", $journal->id
)) {
28 foreach ($eee as $ee) {
29 $entrybyuser[$ee->userid
] = $ee;
30 $entrybyentry[$ee->id
] = $ee;
34 $entrybyuser = array () ;
35 $entrybyentry = array () ;
38 $strentries = get_string("entries", "journal");
39 $strjournals = get_string("modulenameplural", "journal");
42 $navlinks[] = array('name' => $strjournals, 'link' => "index.php?id=$course->id", 'type' => 'activity');
43 $navlinks[] = array('name' => format_string($journal->name
), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
44 $navlinks[] = array('name' => $strentries, 'link' => '', 'type' => 'title');
45 $navigation = build_navigation($navlinks);
47 print_header_simple("$strjournals", "", $navigation, "", "", true);
50 /// Check to see if groups are being used in this journal
51 $groupmode = groupmode($course, $cm);
52 $currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id=$cm->id");
54 /// Process incoming data if there is any
55 if ($data = data_submitted()) {
60 // Peel out all the data from variable names.
61 foreach ($data as $key => $val) {
63 $type = substr($key,0,1);
64 $num = substr($key,1);
65 $feedback[$num][$type] = $val;
71 foreach ($feedback as $num => $vals) {
72 $entry = $entrybyentry[$num];
73 // Only update entries where feedback has actually changed.
74 if (($vals['r'] <> $entry->rating
) ||
($vals['c'] <> addslashes($entry->entrycomment
))) {
75 $newentry->rating
= $vals['r'];
76 $newentry->entrycomment
= $vals['c'];
77 $newentry->teacher
= $USER->id
;
78 $newentry->timemarked
= $timenow;
79 $newentry->mailed
= 0; // Make sure mail goes out (again, even)
81 if (! update_record("journal_entries", $newentry)) {
82 notify("Failed to update the journal feedback for user $entry->userid");
86 $entrybyuser[$entry->userid
]->rating
= $vals['r'];
87 $entrybyuser[$entry->userid
]->entrycomment
= $vals['c'];
88 $entrybyuser[$entry->userid
]->teacher
= $USER->id
;
89 $entrybyuser[$entry->userid
]->timemarked
= $timenow;
92 add_to_log($course->id
, "journal", "update feedback", "report.php?id=$cm->id", "$count users", $cm->id
);
93 notify(get_string("feedbackupdated", "journal", "$count"), "green");
95 add_to_log($course->id
, "journal", "view responses", "report.php?id=$cm->id", "$journal->id", $cm->id
);
98 /// Print out the journal entries
101 $users = get_group_users($currentgroup);
103 $users = get_course_students($course->id
);
107 print_heading(get_string("nousersyet"));
111 $grades = make_grades_menu($journal->assessed
);
112 $teachers = get_course_teachers($course->id
);
114 $allowedtograde = ($groupmode != VISIBLEGROUPS
or isteacheredit($course->id
) or groups_is_member($currentgroup));
116 if ($allowedtograde) {
117 echo '<form action="report.php" method="post">';
120 if ($usersdone = journal_get_users_done($journal)) {
121 foreach ($usersdone as $user) {
123 if (!groups_is_member($currentgroup, $user->id
)) { /// Yes, it's inefficient, but this module will die
127 journal_print_user_entry($course, $user, $entrybyuser[$user->id
], $teachers, $grades);
128 unset($users[$user->id
]);
132 foreach ($users as $user) { // Remaining users
133 journal_print_user_entry($course, $user, NULL, $teachers, $grades);
136 if ($allowedtograde) {
138 echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />";
139 echo "<input type=\"submit\" value=\"".get_string("saveallfeedback", "journal")."\" />";
145 print_footer($course);