### Eclipse Workspace Patch 1.0
#P 19stable
Index: mod/data/comment.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/data/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	7 Aug 2009 21:01:05 -0000
@@ -79,6 +79,35 @@
             $newcomment->content  = $formadata->content;
             $newcomment->recordid = $formadata->rid;
             if (insert_record('data_comments',$newcomment)) {
+				
+				//EMAIL SEND GOES HERE
+				global $USER, $COURSE, $CFG;
+				
+				$database_title = get_record('data', 'id', $data->id); 
+				if($database_title->notification == 1) { 
+					$user = get_record('user', 'id', $USER->id); //This is the creater of the comment
+					$name = fullname($user, true); //This is the creators fullname
+					$teacher = get_teacher($COURSE->id); 
+					
+					if($user->id == $teacher->id) {  //check if comment is by student or teacher
+						$rec = get_record('data_records', 'id', $formadata->rid); 
+						$sendto = get_record('user', 'id', $rec->userid);
+					} 
+					else { 
+						//this is from the student
+						$sendto = get_teacher($COURSE->id);
+					}
+					
+					$course_title = get_record('course' , 'id', $COURSE->id); 
+					$subject = "New Comment to Database: " .$database_title->name ;
+					$body = "The following comment has been added to " .$database_title->name ." by " .$name ." in the course " .$course_title->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.');
@@ -98,6 +127,36 @@
             $updatedcomment->modified = time();
 
             if (update_record('data_comments',$updatedcomment)) {
+			
+				//EMAIL SEND GOES HERE
+				global $USER, $COURSE, $CFG;
+				$database_title = get_record('data', 'id', $data->id); 
+				
+				if($database_title->notification == 1) { 				
+					$user = get_record('user', 'id', $USER->id); //This is the creater of the comment
+					$name = fullname($user, true); //This is the creators fullname
+					$teacher = get_teacher($COURSE->id); 
+					
+					if($user->id == $teacher->id) {  //check if comment is by student or teacher
+						$rec = get_record('data_records', 'id', $formadata->rid); 
+						$sendto = get_record('user', 'id', $rec->userid);
+					} 
+					else { 
+						//this is from the student
+						$sendto = get_teacher($COURSE->id);
+					}
+					
+					$database_title = get_record('data', 'id', $data->id); 
+					$course_title = get_record('course' , 'id', $COURSE->id); 
+					$subject = "Updated Comment in Database: " .$database_title->name ;
+					$body = "The following comment has been updated in " .$database_title->name ." by " .$name ." in the course " .$course_title->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: mod/data/edit.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/data/edit.php,v
retrieving revision 1.32.2.7
diff -u -r1.32.2.7 edit.php
--- mod/data/edit.php	23 Mar 2009 21:22:52 -0000	1.32.2.7
+++ mod/data/edit.php	7 Aug 2009 21:01:05 -0000
@@ -175,6 +175,21 @@
 
             add_to_log($course->id, 'data', 'update', "view.php?d=$data->id&amp;rid=$rid", $data->id, $cm->id);
 
+				//EMAIL SEND GOES HERE
+				global $USER, $COURSE, $CFG;
+				
+				$database_title = get_record('data', 'id', $data->id); 
+				if($database_title->notification == 1) { 
+					$user = get_record('user', 'id', $USER->id);
+					$studentsname = fullname($user, true);
+					$course_title = get_record('course' , 'id', $COURSE->id); 
+					$subject = "Updated Entry in Database: " .$database_title->name ;
+					$body = "An entry has been updated in " .$database_title->name ." by " .$studentsname ." in the course " .$course_title->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 +255,21 @@
 
                 notify(get_string('entrysaved','data'));
 
+				//EMAIL SEND GOES HERE
+				global $USER, $COURSE, $CFG;
+				
+				$database_title = get_record('data', 'id', $data->id); 
+				if($database_title->notification == 1) { 
+					$user = get_record('user', 'id', $USER->id);
+					$studentsname = fullname($user, true);
+					$course_title = get_record('course' , 'id', $COURSE->id); 
+					$subject = "New Entry to Database: " .$database_title->name ;
+					$body = "An entry has been added to " .$database_title->name ." by " .$studentsname ." in the course " .$course_title->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/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	7 Aug 2009 21:01:05 -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', 'Email alerts to teachers/students', $ynoptions);
+
 
         $this->standard_coursemodule_elements(array('groups'=>true, 'groupings'=>true, 'groupmembersonly'=>true));
 
