The following details an attempt to use user/messageselect.php with BIM in an attempt to move towards implementing an email merge facility for BIM.

BIM passing users

The intent here is that BIM will be used to select the users and will pass it to message select. The first test will be to replace the current “unregistered users” section on “Your Students” which simply shows a list of email address which the staff member has to copy and paste into an email program. See the following screen shot (click on it to see it larger).

Unregistered users - BIM your students

The idea is to replace it with a simple link that when clicked on will pass the details of the unregistered users to messageselect.php

Parameters for messageselect

For this to work, I need to pass messageselect all the parameters it expects in the way it expects them.

First, the parameters is expects are:

  • The list of user ids for the recipients.
    This is done using checkboxes with parameter names userid where id is the Moodle user id.
  • The course id.
    id set to the Moodle course id.
  • formaction
    Seems to simply be the name of the messageselect script.
  • returnto
    path of script it’s coming from.

Parameter passing for message select

In terms of how to pass the data, I’ve tried a normal query string. But that didn’t seem to create the necessary outcome.

It appears that messageselct uses the PHP $_POST variable/function which is used for a form with the post method. So let’s try that.

Yep, that seems to work. May be as simple as that.

Have been able to get that working, however, the “returnto” doesn’t seem to work all the way done the various screens. Works on the first, but not on the last.

bim_email_merge

The following is the function I’ve added to bim to enable the use of messageselect.php

[sourcecode lang=”php”]
function bim_email_merge( $ids, $course, $returnto, $button_msg ) {

global $CFG;

print <<<EOF
<form method="post" action="$CFG->wwwroot/user/messageselect.php" />
<input type="hidden" name="id" value="$course" />
<input type="hidden" name="returnto" value="$returnto" />
<input type="hidden" name="formaction" value="messageselect.php" />
<input type="submit" name="submit" value="$button_msg" />
EOF;

foreach ( $ids as $id ) {
print "<input type="hidden" name="user{$id}" value="on" />";
}
print "</form>";
}
[/sourcecode]

This function displays a submit button with a given message. If pressed the form sends a list of Moodle user ids ($ids) to messageselect. At this stage the user can create the message, choose to remove some users and then send the message. I think.

Implemented in BIM, it looks like the following.

BIM's new email merge