Skip to content

Commit

Permalink
MDL-10107 - First check-in of Messaging 2.0 code from Luis Rodrigues,…
Browse files Browse the repository at this point in the history
… GSOC student.

This new messaging system replaces all the various email_to_user() calls.
They are now replaced by events triggers, and the messages are then
processed centrally according to user preferences and sent to one or more
processors (email, popup, jabber etc...)

This code is not finished yet, a lot of work still has to be done on the
interface.  However, the basic structure is there and should be working.
Luis and I will be reviewing and polishing this heavily in the next few weeks.
  • Loading branch information
moodler committed Jul 24, 2008
1 parent 09f295f commit 3b120e4
Show file tree
Hide file tree
Showing 62 changed files with 5,619 additions and 68 deletions.
43 changes: 43 additions & 0 deletions admin/handlevirus.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* php -d error_log=/path/to/log thisfile.php will override the default error log for php cli, which is stderr, so if you want this script to just print stuff out, use php thisfile.php instead.
*/

require_once($CFG->libdir.'/eventslib.php');


$fd = fopen('php://stdin','r');
if (!$fd) {
Expand Down Expand Up @@ -59,7 +61,22 @@ function notify_user($user,$subject,$a) {
return false;
}
$body = get_string('virusfoundlater','moodle',$a);

$eventdata = new object();
$eventdata->modulename = 'moodle';
$eventdata->userfrom = get_admin();
$eventdata->userto = $user;
$eventdata->subject = $subject;
$eventdata->fullmessage = $body;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
events_trigger('message_send', $eventdata);


/*
email_to_user($user,get_admin(),$subject,$body);
*/
}


Expand All @@ -69,7 +86,20 @@ function notify_admins($user,$subject,$a) {

$body = get_string('virusfoundlateradmin','moodle',$a);
foreach ($admins as $admin) {
$eventdata = new object();
$eventdata->modulename = 'moodle';
$eventdata->userfrom = $admin;
$eventdata->userto = $admin;
$eventdata->subject = $subject;
$eventdata->fullmessage = $body;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
events_trigger('message_send', $eventdata);

/*
email_to_user($admin,$admin,$subject,$body);
*/
}
}

Expand All @@ -81,7 +111,20 @@ function notify_admins_unknown($file,$a) {
$subject = get_string('virusfoundsubject','moodle',format_string($site->fullname));
$body = get_string('virusfoundlateradminnolog','moodle',$a);
foreach ($admins as $admin) {
$eventdata = new object();
$eventdata->modulename = 'moodle';
$eventdata->userfrom = $admin;
$eventdata->userto = $admin;
$eventdata->subject = $subject;
$eventdata->fullmessage = $body;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
events_trigger('message_send', $eventdata);

/*
email_to_user($admin,$admin,$subject,$body);
*/
}
}

Expand Down
15 changes: 15 additions & 0 deletions backup/backup_scheduled.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php //$Id$
//This file contains all the code needed to execute scheduled backups

require_once($CFG->libdir.'/eventslib.php');

//This function is executed via moodle cron
//It prepares all the info and execute backups as necessary
Expand Down Expand Up @@ -195,7 +197,20 @@ function schedule_backup_cron() {
$subject = $prefix.get_string("scheduledbackupstatus");

//Send the message
$eventdata = new object();
$eventdata->modulename = 'moodle';
$eventdata->userfrom = $admin;
$eventdata->userto = $admin;
$eventdata->subject = $subject;
$eventdata->fullmessage = $message;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
events_trigger('message_send', $eventdata);

/*
email_to_user($admin,$admin,$subject,$message);
*/
}


Expand Down
28 changes: 28 additions & 0 deletions course/pending.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require_once($CFG->libdir.'/pagelib.php');
require_once($CFG->libdir.'/blocklib.php');
require_once('lib.php');
require_once($CFG->libdir.'/eventslib.php');

require_login();

Expand Down Expand Up @@ -52,7 +53,21 @@
$a->name = $course->fullname;
$a->url = $CFG->wwwroot.'/course/view.php?id='.$courseid;
$a->teacher = $course->teacher;

$eventdata = new object();
$eventdata->modulename = 'moodle';
$eventdata->userfrom = $USER;
$eventdata->userto = $user;
$eventdata->subject = get_string('courseapprovedsubject');
$eventdata->fullmessage = get_string('courseapprovedemail','moodle',$a);
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
events_trigger('message_send', $eventdata);

/*
email_to_user($user,$USER,get_string('courseapprovedsubject'),get_string('courseapprovedemail','moodle',$a));
*/
redirect($CFG->wwwroot.'/course/edit.php?id='.$courseid);
exit;
}
Expand All @@ -79,7 +94,20 @@
}
else {
$user = $DB->get_record("user", array("id"=>$reject->requester));

$eventdata = new object();
$eventdata->modulename = 'moodle';
$eventdata->userfrom = $USER;
$eventdata->userto = $user;
$eventdata->subject = get_string('courserejectsubject');
$eventdata->fullmessage = get_string('courserejectemail','moodle',$rejectnotice);
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
events_trigger('message_send', $eventdata);
/*
email_to_user($user,$USER,get_string('courserejectsubject'),get_string('courserejectemail','moodle',$rejectnotice));
*/
$DB->delete_records("course_request", array("id"=>$reject->id));
notice(get_string('courserejected'),'pending.php');
}
Expand Down
116 changes: 111 additions & 5 deletions enrol/authorize/enrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require_once($CFG->dirroot.'/enrol/authorize/const.php');
require_once($CFG->dirroot.'/enrol/authorize/localfuncs.php');
require_once($CFG->dirroot.'/enrol/authorize/authorizenet.class.php');
require_once($CFG->libdir.'/eventslib.php');

/**
* Authorize.net Payment Gateway plugin
Expand Down Expand Up @@ -171,7 +172,7 @@ private function cc_submit($form, $course)
$order->currency = $curcost['currency'];
$order->id = $DB->insert_record("enrol_authorize", $order);
if (!$order->id) {
email_to_admin("Error while trying to insert new data", $order);
message_to_admin("Error while trying to insert new data", $order);
return "Insert record error. Admin has been notified!";
}

Expand Down Expand Up @@ -242,7 +243,20 @@ private function cc_submit($form, $course)
$context = get_context_instance(CONTEXT_COURSE, $course->id);
if (($paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments'))) {
foreach ($paymentmanagers as $paymentmanager) {
$eventdata = new object();
$eventdata->modulename = 'moodle';
$eventdata->userfrom = $USER;
$eventdata->userto = $paymentmanager;
$eventdata->subject = $emailsubject;
$eventdata->fullmessage = $emailmessage;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
events_trigger('message_send', $eventdata);

/*
email_to_user($paymentmanager, $USER, $emailsubject, $emailmessage);
*/
}
}
redirect($CFG->wwwroot, get_string("reviewnotify", "enrol_authorize"), '30');
Expand All @@ -265,31 +279,58 @@ private function cc_submit($form, $course)
$a = new stdClass;
$a->course = "$course->fullname";
$a->user = fullname($USER);

$eventdata = new object();
$eventdata->modulename = 'moodle';
$eventdata->userfrom = $USER;
$eventdata->userto = $paymentmanager;
$eventdata->subject = get_string("enrolmentnew", '', format_string($course->shortname));
$eventdata->fullmessage = get_string('enrolmentnewuser', '', $a);
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
events_trigger('message_send', $eventdata);

/*
email_to_user(
$paymentmanager,
$USER,
get_string("enrolmentnew", '', format_string($course->shortname)),
get_string('enrolmentnewuser', '', $a)
);
*/
}
if (!empty($CFG->enrol_mailadmins)) {
$a = new stdClass;
$a->course = "$course->fullname";
$a->user = fullname($USER);
$admins = get_admins();
foreach ($admins as $admin) {
$eventdata = new object();
$eventdata->modulename = 'moodle';
$eventdata->userfrom = $USER;
$eventdata->userto = $paymentmanager;
$eventdata->subject = get_string("enrolmentnew", '', format_string($course->shortname));
$eventdata->fullmessage = get_string('enrolmentnewuser', '', $a);
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
events_trigger('message_send', $eventdata);

/*
email_to_user(
$admin,
$USER,
get_string("enrolmentnew", '', format_string($course->shortname)),
get_string('enrolmentnewuser', '', $a)
);
*/
}
}
}
else
{
email_to_admin("Error while trying to enrol " . fullname($USER) . " in '$course->fullname'", $order);
message_to_admin("Error while trying to enrol " . fullname($USER) . " in '$course->fullname'", $order);
}

if ($SESSION->wantsurl) {
Expand All @@ -308,7 +349,7 @@ private function cc_submit($form, $course)
}
else
{
email_to_admin($message, $order);
message_to_admin($message, $order);
return $message;
}
}
Expand Down Expand Up @@ -348,7 +389,7 @@ private function echeck_submit($form, $course)
$order->currency = $curcost['currency'];
$order->id = $DB->insert_record("enrol_authorize", $order);
if (!$order->id) {
email_to_admin("Error while trying to insert new data", $order);
message_to_admin("Error while trying to insert new data", $order);
return "Insert record error. Admin has been notified!";
}

Expand Down Expand Up @@ -385,7 +426,7 @@ private function echeck_submit($form, $course)
return NULL;
}
else {
email_to_admin($message, $order);
message_to_admin($message, $order);
return $message;
}
}
Expand Down Expand Up @@ -695,10 +736,35 @@ public function cron()

$adminuser = get_admin();
if (!empty($faults)) {
$eventdata = new object();
$eventdata->modulename = 'moodle';
$eventdata->userfrom = $adminuser;
$eventdata->userto = $adminuser;
$eventdata->subject = "AUTHORIZE.NET CRON FAULTS";
$eventdata->fullmessage = $faults;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
events_trigger('message_send', $eventdata);

/*
email_to_user($adminuser, $adminuser, "AUTHORIZE.NET CRON FAULTS", $faults);
*/
}
if (!empty($CFG->enrol_mailadmins)) {
$eventdata = new object();
$eventdata->modulename = 'moodle';
$eventdata->userfrom = $adminuser;
$eventdata->userto = $adminuser;
$eventdata->subject = "AUTHORIZE.NET CRON LOG";
$eventdata->fullmessage = $this->log;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
events_trigger('message_send', $eventdata);
/*
email_to_user($adminuser, $adminuser, "AUTHORIZE.NET CRON LOG", $this->log);
*/
}

// Send emails to students about which courses have enrolled.
Expand Down Expand Up @@ -757,7 +823,20 @@ private function cron_daily()
$a->url = $CFG->wwwroot.'/enrol/authorize/uploadcsv.php';
$message = get_string('pendingecheckemail', 'enrol_authorize', $a);
foreach($csvusers as $csvuser) {
$eventdata = new object();
$eventdata->modulename = 'moodle';
$eventdata->userfrom = $adminuser;
$eventdata->userto = $csvuser;
$eventdata->subject = $subject;
$eventdata->fullmessage = $message;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
events_trigger('message_send', $eventdata);

/*
@email_to_user($csvuser, $adminuser, $subject, $message);
*/
}
mtrace(" users who have 'enrol/authorize:uploadcsv' were mailed");
}
Expand Down Expand Up @@ -791,7 +870,21 @@ private function cron_daily()
$a->enrolurl = "$CFG->wwwroot/$CFG->admin/enrol_config.php?enrol=authorize";
$a->url = $CFG->wwwroot.'/enrol/authorize/index.php?status='.AN_STATUS_AUTH;
$message = get_string('pendingordersemail', 'enrol_authorize', $a);

$eventdata = new object();
$eventdata->modulename = 'moodle';
$eventdata->userfrom = $adminuser;
$eventdata->userto = $adminuser;
$eventdata->subject = $subject;
$eventdata->fullmessage = $message;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
events_trigger('message_send', $eventdata);

/*
email_to_user($adminuser, $adminuser, $subject, $message);
*/

// Email to payment managers
if (empty($CFG->an_emailexpiredteacher)) {
Expand Down Expand Up @@ -830,7 +923,20 @@ private function cron_daily()
$a->url = $CFG->wwwroot.'/enrol/authorize/index.php?course='.$lastcourse.'&amp;status='.AN_STATUS_AUTH;
$message = get_string('pendingordersemailteacher', 'enrol_authorize', $a);
foreach ($paymentmanagers as $paymentmanager) {
$eventdata = new object();
$eventdata->modulename = 'moodle';
$eventdata->userfrom = $adminuser;
$eventdata->userto = $paymentmanager;
$eventdata->subject = $subject;
$eventdata->fullmessage = $message;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
events_trigger('message_send', $eventdata);

/*
email_to_user($paymentmanager, $adminuser, $subject, $message);
*/
}
}
}
Expand Down
Loading

0 comments on commit 3b120e4

Please sign in to comment.