diff -rupN moodle-1.9.9/lang/en_utf8/data.php moodle-1.9.9copy/lang/en_utf8/data.php --- moodle-1.9.9/lang/en_utf8/data.php 2009-09-28 08:05:32.000000000 -0500 +++ moodle-1.9.9copy/lang/en_utf8/data.php 2010-06-17 15:20:46.000000000 -0500 @@ -179,6 +179,7 @@ $string['nomaximum'] = 'No maximum'; $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'; diff -rupN moodle-1.9.9/mod/data/comment.php moodle-1.9.9copy/mod/data/comment.php --- moodle-1.9.9/mod/data/comment.php 2009-02-24 07:05:30.000000000 -0600 +++ moodle-1.9.9copy/mod/data/comment.php 2010-06-17 15:31:58.000000000 -0500 @@ -78,7 +78,39 @@ $newcomment->modified = time(); $newcomment->content = $formadata->content; $newcomment->recordid = $formadata->rid; - if (insert_record('data_comments',$newcomment)) { + if (insert_record('data_comments',$newcomment)) { + //EMAIL SEND GOES HERE + if($data->notification == 1) { + $name = fullname($USER, true); //This is the creators fullname + + $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 .= "

\"" .stripslashes($formadata->content) ."\""; + $body .= "

To reply to this comment, click here."; + $body .= "

To view this comment in context, click here."; + + if ($USER->id != $record->userid) { // If comment not by original poster, then send to the original poster + $sendto = get_record('user', 'id', $record->userid); + if (!email_to_user($sendto , $USER, $subject, $body, $body)) { + error('Email from '.$name.' regarding '.$subject.' was not sent'); + } + } + + // Notify all teachers of the course unless they are the one who posted the comment or the original poster who will be email with the line above. + $teachers = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', '', '', '', '', false, true); + foreach ($teachers as $teach ) { + if ($teach->id != $USER->id && $teach->id != $record->userid) { // If this comment was posted by someone else. + $sendto = get_record('user', 'id', $teach->id); + 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.'&page='.$page); } else { error('Error while saving comment.'); @@ -98,6 +130,36 @@ $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 + + $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 .= "

\"" .stripslashes($formadata->content) ."\""; + $body .= "

To reply to this comment, click here."; + $body .= "

To view this comment in context, click here."; + if ($USER->id != $record->userid) { // If comment not by original poster, then send to the original poster + $sendto = get_record('user', 'id', $record->userid); + if (!email_to_user($sendto , $USER, $subject, $body, $body)) { + error('Email from '.$name.' regarding '.$subject.' was not sent'); + } + } + + // Notify all teachers of the course unless they are the one who posted the comment or the original poster who will be email with the line above. + $teachers = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', '', '', '', '', false, true); + foreach ($teachers as $teach ) { + if ($teach->id != $USER->id && $teach->id != $record->userid) { // If this comment was posted by someone else. + $sendto = get_record('user', 'id', $teach->id); + 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.'&page='.$page); } else { error('Error while saving comment.'); diff -rupN moodle-1.9.9/mod/data/edit.php moodle-1.9.9copy/mod/data/edit.php --- moodle-1.9.9/mod/data/edit.php 2009-12-01 07:02:44.000000000 -0600 +++ moodle-1.9.9copy/mod/data/edit.php 2010-06-17 15:32:00.000000000 -0500 @@ -175,6 +175,26 @@ add_to_log($course->id, 'data', 'update', "view.php?d=$data->id&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 .= "

To view this entry, click here."; + // Send to all teachers unless it is the user that made the add + $teachers = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', '', '', '', '', false, true); + foreach ($teachers as $teach ) { + if ($teach->id != $USER->id) { // If this comment was posted by someone else. + $sendto = get_record('user', 'id', $teach->id); + if (!email_to_user($sendto , $USER, $subject, $body, $body)) { + error('Email from '.$name.' regarding '.$subject.' was not sent'); + } + } + } + } + //END OF EMAIL SEND + redirect($CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&rid='.$rid); } else { /// Add some new records @@ -240,6 +260,25 @@ 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 .= "

To view this entry, click here."; + // Send to all teachers unless it is the user that made the update + $teachers = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', '', '', '', '', false, true); + foreach ($teachers as $teach ) { + if ($teach->id != $USER->id) { // If this comment was posted by someone else. + $sendto = get_record('user', 'id', $teach->id); + if (!email_to_user($sendto , $USER, $subject, $body, $body)) { + error('Email from '.$name.' regarding '.$subject.' was not sent'); + } + } + } + } + //END OF EMAIL SEND + if (!empty($datarecord->saveandview)) { redirect($CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&rid='.$recordid); } diff -rupN moodle-1.9.9/mod/data/mod_form.php moodle-1.9.9copy/mod/data/mod_form.php --- moodle-1.9.9/mod/data/mod_form.php 2008-07-27 08:17:58.000000000 -0500 +++ moodle-1.9.9copy/mod/data/mod_form.php 2010-06-17 15:32:00.000000000 -0500 @@ -61,6 +61,9 @@ class mod_data_mod_form extends moodlefo $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));