$string['duedate'] = 'Due date';
$string['duedateno'] = 'No due date';
$string['early'] = '$a early';
+$string['emailteachers'] = 'Email alerts to teachers';
+$string['emailteachermail'] = '
+$a->username has updated their assignment submission
+for \'$a->assignment\'
+
+It is available here:
+
+ $a->url';
+$string['emailteachermailhtml'] = '$a->username has updated their assignment submission
+for <i>\'$a->assignment\'</i><br /><br />
+It is <a href=\"$a->url\">available on the web site</a>.';
$string['existingfiledeleted'] = 'Existing file has been deleted: $a';
$string['failedupdatefeedback'] = 'Failed to update submission feedback for user $a';
$string['feedback'] = 'Feedback';
--- /dev/null
+<p align="center"><b>Email alerts to teachers</b></p>
+
+<p>If enabled, then teachers are alerted with a short email whenever students
+ add or update an assignment submission.</p>
+
+<p>Only teachers who are able to grade the particular submission are notified.
+ So, for example, if the course uses separate groups, then teachers restricted
+ to particular groups won't receive any notices about students in other groups.</p>
+
+<p>For offline activities, of course, mail is never sent since students never
+ submit anything.</p>
+
modify_database('','ALTER TABLE prefix_assignment_submissions ADD INDEX timemarked (timemarked);');
}
+ if ($oldversion < 2005010500) {
+ table_column('assignment', '', 'emailteachers', 'integer', '2', 'unsigned', 0, 'not null', 'resubmit');
+ }
+
return true;
}
`description` text NOT NULL,
`format` tinyint(2) unsigned NOT NULL default '0',
`resubmit` tinyint(2) unsigned NOT NULL default '0',
+ `emailteachers` tinyint(2) unsigned NOT NULL default '0',
`type` int(10) unsigned NOT NULL default '1',
`maxbytes` int(10) unsigned NOT NULL default '100000',
`timedue` int(10) unsigned NOT NULL default '0',
modify_database('','CREATE INDEX prefix_assignment_submissions_timemarked_idx ON prefix_assignment_submissions (timemarked);');
}
+ if ($oldversion < 2005010500) {
+ table_column('assignment', '', 'emailteachers', 'integer', '2', 'unsigned', 0, 'not null', 'resubmit');
+ }
+
return true;
}
description text NOT NULL default '',
format integer NOT NULL default '0',
resubmit integer NOT NULL default '0',
+ emailteachers integer NOT NULL default '0',
type integer NOT NULL default '1',
maxbytes integer NOT NULL default '100000',
timedue integer NOT NULL default '0',
return $tmpfile;
}
+if (!function_exists('get_group_teachers')) { // Will be in datalib.php later
+ function get_group_teachers($courseid, $groupid) {
+ /// Returns a list of all the teachers who can access a group
+ if ($teachers = get_course_teachers($courseid)) {
+ foreach ($teachers as $key => $teacher) {
+ if ($teacher->editall) { // These can access anything
+ continue;
+ }
+ if (($teacher->authority > 0) and ismember($groupid, $teacher->id)) { // Specific group teachers
+ continue;
+ }
+ unset($teacher[$key]);
+ }
+ }
+ return $teachers;
+ }
+}
+
+function assignment_email_teachers($course, $cm, $assignment, $submission) {
+/// Alerts teachers by email of new or changed assignments that need grading
+
+ global $CFG;
+
+ if (empty($assignment->emailteachers)) { // No need to do anything
+ return;
+ }
+
+ $user = get_record('user', 'id', $submission->userid);
+
+ if (groupmode($course, $cm) == SEPARATEGROUPS) { // Separate groups are being used
+ if (!$group = user_group($course->id, $user->id)) { // Try to find a group
+ $group->id = 0; // Not in a group, never mind
+ }
+ $teachers = get_group_teachers($course->id, $group->id); // Works even if not in group
+ } else {
+ $teachers = get_course_teachers($course->id);
+ }
+
+ if (!$teachers) {
+
+ $strassignments = get_string('modulenameplural', 'assignment');
+ $strassignment = get_string('modulename', 'assignment');
+ $strsubmitted = get_string('submitted', 'assignment');
+
+ foreach ($teachers as $teacher) {
+ unset($info);
+ $info->username = fullname($user);
+ $info->assignment = "$submission->name";
+ $info->url = "$CFG->wwwroot/mod/assignment/view.php?id=$cm->id";
+
+ $postsubject = "$strsubmitted: $info->username -> $assignment->name";
+ $posttext = "$course->shortname -> $strassignments -> $assignment->name\n";
+ $posttext .= "---------------------------------------------------------------------\n";
+ $posttext .= get_string("emailteachermail", "assignment", $info);
+ $posttext .= "---------------------------------------------------------------------\n";
+
+ if ($user->mailformat == 1) { // HTML
+ $posthtml = "<p><font face=\"sans-serif\">".
+ "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->".
+ "<a href=\"$CFG->wwwroot/mod/assignment/index.php?id=$course->id\">$strassignments</a> ->".
+ "<a href=\"$CFG->wwwroot/mod/assignment/view.php?id=$cm->id\">$assignment->name</a></font></p>";
+ $posthtml .= "<hr /><font face=\"sans-serif\">";
+ $posthtml .= "<p>".get_string("emailteachermailhtml", "assignment", $info)."</p>";
+ $posthtml .= "</font><hr />";
+ } else {
+ $posthtml = "";
+ }
+
+ @email_to_user($user, $teacher, $postsubject, $posttext, $posthtml); // If it fails, oh well, too bad.
+ }
+ }
+}
+
+
?>
if (empty($form->timedue)) {
$form->timedue = "";
}
+ if (empty($form->emailteachers)) {
+ $form->emailteachers = "";
+ }
?>
<form name="form" method="post" action="mod.php">
?>
</td>
</tr>
+<tr>
+ <td align="right"><b><?php print_string("emailteachers", "assignment") ?>:</b></td>
+ <td>
+ <?php
+ $options[0] = get_string("no"); $options[1] = get_string("yes");
+ choose_from_menu($options, "emailteachers", $form->emailteachers, "");
+ helpbutton("emailteachers", get_string("emailteachers", "assignment"), "assignment");
+ ?>
+ </td>
+</tr>
<tr valign="top">
<td align="right"><b><?php print_string("grade") ?>:</b></td>
<td>
$submission->numfiles = 1;
$submission->comment = addslashes($submission->comment);
if (update_record("assignment_submissions", $submission)) {
+ assignment_email_teachers($course, $cm, $assignment, $submission);
print_heading(get_string('uploadedfile'));
} else {
notify(get_string("uploadfailnoupdate", "assignment"));
$newsubmission->numfiles = 1;
if (insert_record("assignment_submissions", $newsubmission)) {
add_to_log($course->id, "assignment", "upload", "view.php?a=$assignment->id", "$assignment->id", $cm->id);
+ assignment_email_teachers($course, $cm, $assignment, $submission);
print_heading(get_string('uploadedfile'));
} else {
notify(get_string("uploadnotregistered", "assignment", $newfile_name) );
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
-$module->version = 2004111200;
+$module->version = 2005010500;
$module->requires = 2004091700; // Requires this Moodle version
$module->cron = 60;