### Eclipse Workspace Patch 1.0
#P moodle19
Index: mod/data/mod_form.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/data/mod_form.php,v
retrieving revision 1.21.2.2
diff -u -r1.21.2.2 mod_form.php
--- mod/data/mod_form.php	26 Jul 2008 15:17:05 -0000	1.21.2.2
+++ mod/data/mod_form.php	25 Dec 2009 15:49:18 -0000
@@ -61,6 +61,9 @@
         $mform->addElement('modgrade', 'scale', get_string('grade'), false);
         $mform->disabledIf('scale', 'assessed');
 
+		//For sending email notifications to students 
+		$mform->addElement('select', 'notification', get_string('notify','data'), $ynoptions);
+
 
         $this->standard_coursemodule_elements(array('groups'=>true, 'groupings'=>true, 'groupmembersonly'=>true));
 
Index: mod/data/edit.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/data/edit.php,v
retrieving revision 1.32.2.8
diff -u -r1.32.2.8 edit.php
--- mod/data/edit.php	30 Nov 2009 17:12:16 -0000	1.32.2.8
+++ mod/data/edit.php	25 Dec 2009 15:49:18 -0000
@@ -175,6 +175,17 @@
 
             add_to_log($course->id, 'data', 'update', "view.php?d=$data->id&amp;rid=$rid", $data->id, $cm->id);
 
+				//EMAIL SEND GOES HERE
+				
+				if($data->notification == 1) { 
+					$studentsname = fullname($USER, true);
+					$subject = "Updated Entry in Database: " .$data->name ;
+					$body = "An entry has been updated in " .$data->name ." by " .$studentsname ." in the course " .$course->fullname; 
+					$body .= "<br /><br /> To view this entry, <a href='" .$CFG->wwwroot ."/mod/data/view.php?d=" .$data->id ."&rid=" .$rid ."'> click here.</a>"; 
+					email_to_user(get_teacher($course->id) , $USER, $subject, $body, $body); 
+				}
+				//END OF EMAIL SEND
+
             redirect($CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&amp;rid='.$rid);
 
         } else { /// Add some new records
@@ -240,6 +251,16 @@
 
                 notify(get_string('entrysaved','data'));
 
+				//EMAIL SEND GOES HERE
+				if($data->notification == 1) { 
+					$studentsname = fullname($USER, true);
+					$subject = "New Entry to Database: " .$data->name ;
+					$body = "An entry has been added to " .$data->name ." by " .$studentsname ." in the course " .$course->fullname; 
+					$body .= "<br /><br /> To view this entry, <a href='" .$CFG->wwwroot ."/mod/data/view.php?d=" .$data->id ."&rid=" .$recordid ."'> click here.</a>"; 
+					email_to_user(get_teacher($COURSE->id) , $USER, $subject, $body, $body); 
+				}				
+				//END OF EMAIL SEND
+
                 if (!empty($datarecord->saveandview)) {
                     redirect($CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&amp;rid='.$recordid);
                 }
Index: mod/data/comment.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/data/Attic/comment.php,v
retrieving revision 1.19.4.1
diff -u -r1.19.4.1 comment.php
--- mod/data/comment.php	23 Feb 2009 07:24:04 -0000	1.19.4.1
+++ mod/data/comment.php	25 Dec 2009 15:49:18 -0000
@@ -79,6 +79,27 @@
             $newcomment->content  = $formadata->content;
             $newcomment->recordid = $formadata->rid;
             if (insert_record('data_comments',$newcomment)) {
+                //EMAIL SEND GOES HERE
+				if($data->notification == 1) { 
+					$name = fullname($USER, true); //This is the creators fullname
+					$teacher = get_teacher($COURSE->id); 
+					if($USER->id == $teacher->id) {  //If comment by teacher, then send to student
+						$sendto = get_record('user', 'id', $record->userid);
+					} 
+					else { //otherwise comment by a student, so send to teacher
+						$sendto = get_teacher($COURSE->id);
+					}
+					$subject = "New Comment to Database: " .$data->name ;
+					$body = "The following comment has been added to " .$data->name ." by " .$name ." in the course " .$course->fullname .":"; 
+					$body .= "<br /><br /><em>\"" .stripslashes($formadata->content) ."\"</em>"; 
+					$body .= "<br /><br /> To reply to this comment, <a href='" .$CFG->wwwroot ."/mod/data/view.php?d=" .$data->id ."&rid=" .$formadata->rid ."&addcomment=1'> click here.</a>";
+					$body .= "<br /><br /> To view this comment in context, <a href='" .$CFG->wwwroot ."/mod/data/view.php?d=" .$data->id ."&rid=" .$formadata->rid ."'> click here.</a>"; 
+					if (!email_to_user($sendto , $USER, $subject, $body, $body)) {
+					    error('Email from '.$name.' regarding '.$subject.' was not sent');
+					} 
+				}
+				//END OF EMAIL SEND
+				
                 redirect('view.php?rid='.$record->id.'&amp;page='.$page);
             } else {
                 error('Error while saving comment.');
@@ -98,6 +119,25 @@
             $updatedcomment->modified = time();
 
             if (update_record('data_comments',$updatedcomment)) {
+			
+				//EMAIL SEND GOES HERE
+				if($data->notification == 1) { 				
+					$name = fullname($USER, true); //This is the creators fullname
+					$teacher = get_teacher($course->id); 
+					if($USER->id == $teacher->id) {  //if update by teacher, notify student
+						$sendto = get_record('user', 'id', $record->userid);
+					} else { // if update by student, notify teacher
+						$sendto = get_teacher($COURSE->id);
+					}
+					$subject = "Updated Comment in Database: " .$data->name ;
+					$body = "The following comment has been updated in " .$data->name ." by " .$name ." in the course " .$course->fullname .":"; 
+					$body .= "<br /><br /><em>\"" .stripslashes($formadata->content) ."\"</em>"; 
+					$body .= "<br /><br /> To reply to this comment, <a href='" .$CFG->wwwroot ."/mod/data/view.php?d=" .$data->id ."&rid=" .$formadata->rid ."&addcomment=1'> click here.</a>";
+					$body .= "<br /><br /> To view this comment in context, <a href='" .$CFG->wwwroot ."/mod/data/view.php?d=" .$data->id ."&rid=" .$formadata->rid ."'> click here.</a>"; 
+					email_to_user($sendto , $USER, $subject, $body, $body); 
+				}				
+				//END OF EMAIL SEND
+			
                 redirect('view.php?rid='.$record->id.'&amp;page='.$page);
             } else {
                 error('Error while saving comment.');
Index: lang/en_utf8/data.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/data.php,v
retrieving revision 1.53.4.21
diff -u -r1.53.4.21 data.php
--- lang/en_utf8/data.php	27 Sep 2009 18:07:53 -0000	1.53.4.21
+++ lang/en_utf8/data.php	25 Dec 2009 15:49:18 -0000
@@ -179,6 +179,7 @@
 $string['norecords'] = 'No entries in database';
 $string['nosingletemplate'] = 'Single template is not yet defined';
 $string['notapproved'] = 'Entry is not approved yet.';
+$string['notify'] = 'Send notifications to teachers/students';
 $string['notinjectivemap'] = 'Not an injective map';
 $string['number'] = 'Number';
 $string['numberrssarticles'] = 'RSS articles';
