]> git.mjollnir.org Git - moodle.git/commitdiff
Email alerts to teachers
authormoodler <moodler>
Wed, 5 Jan 2005 17:13:44 +0000 (17:13 +0000)
committermoodler <moodler>
Wed, 5 Jan 2005 17:13:44 +0000 (17:13 +0000)
------------------------

Added a small new feature to the assignment module to alert teachers when
new emails come in.  This feature adds one new field (which is tested) but
the operation of the new code has not been tested yet at all (apart from
PHP syntax) and very likely has bugs in it.

I'm checking this in so I can do tests on test.moodle.com which has email
set up properly.

I'm off to bed right now but if anyone else wants to test this feature
before tomorrow please do!   :-)

While I'm rambling here in CVS, I need to have a good look soon at Pablo's work
on Assignment and see if I can merge it all in...

lang/en/assignment.php
lang/en/help/assignment/emailteachers.html [new file with mode: 0644]
mod/assignment/db/mysql.php
mod/assignment/db/mysql.sql
mod/assignment/db/postgres7.php
mod/assignment/db/postgres7.sql
mod/assignment/lib.php
mod/assignment/mod.html
mod/assignment/upload.php
mod/assignment/version.php

index ae772e5735acb15cd5014c5c289447b33c760202..3b3add1b488e5871dfa953f48a202139bbb08844 100644 (file)
@@ -20,6 +20,17 @@ $string['description'] = 'Description';
 $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';
diff --git a/lang/en/help/assignment/emailteachers.html b/lang/en/help/assignment/emailteachers.html
new file mode 100644 (file)
index 0000000..a4b7a7b
--- /dev/null
@@ -0,0 +1,12 @@
+<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>
+
index 031f97f0108144fe0dee10935c642c0f55313fe0..c6ce006faffb3036a16a3a1501d4271d9c8db881 100644 (file)
@@ -113,6 +113,10 @@ function assignment_upgrade($oldversion) {
         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;
 }
 
index 0a3cf65bab07788539233a8861b659b0459c3cab..ac7608f015490809baf9b42e9d0b59cfc9502b0c 100644 (file)
@@ -9,6 +9,7 @@ CREATE TABLE `prefix_assignment` (
   `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',
index 4fadbf57376db8d7027014a33a94831af86dff2b..afafaf8201cf34372bc112681ddf351fdee9fa1e 100644 (file)
@@ -111,6 +111,10 @@ function assignment_upgrade($oldversion) {
         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;
 }
 
index 3902caf4ddb5b3e286afd3c5aca3755b32e20cae..7d57ce7cdd147d809b468c23e6e223e217321b17 100644 (file)
@@ -9,6 +9,7 @@ CREATE TABLE prefix_assignment (
   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',
index 0621e169e645b39838e6251a236db87c89c4e4f3..585b9a02622b0f1db8d20cdbb97ebaee0664c6e4 100644 (file)
@@ -819,4 +819,78 @@ function assignment_get_user_file($assignment, $user) {
     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.
+        }
+    }
+}
+
+
 ?>
index b4886b36cfb1d2aac9e2973e8ef0282153adbefe..1fe0a400e973af02bccd28451d4b134dbdf634ea 100644 (file)
@@ -23,6 +23,9 @@
     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>
index 5fd58d638bde8ae09059b6d075780cb151c74757..275ae99a6e09291c8c61e39fd774e30d423d9871 100644 (file)
@@ -44,6 +44,7 @@
             $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"));
@@ -56,6 +57,7 @@
             $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) );
index 41abc368e4bb83907876e7d972863ae883177228..972f962d783e465696eac5adfeaf2ff8e252ad36 100644 (file)
@@ -5,7 +5,7 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2004111200;
+$module->version  = 2005010500;
 $module->requires = 2004091700;  // Requires this Moodle version
 $module->cron     = 60;