2 require_once('../../config.php');
3 require_once($CFG->libdir
.'/adminlib.php');
4 require_once($CFG->dirroot
.'/message/lib.php');
5 require_once('user_message_form.php');
7 $msg = optional_param('msg', '', PARAM_CLEANHTML
);
8 $confirm = optional_param('confirm', 0, PARAM_BOOL
);
11 admin_externalpage_setup('userbulk');
12 require_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM
));
14 $return = $CFG->wwwroot
.'/'.$CFG->admin
.'/user/user_bulk.php';
16 if (empty($SESSION->bulk_users
)) {
20 if (empty($CFG->messaging
)) {
21 print_error('messagingdisable', 'error');
24 //TODO: add support for large number of users
26 if ($confirm and !empty($msg) and confirm_sesskey()) {
27 list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users
);
28 $rs = $DB->get_recordset_select('user', "id $in", $params);
29 foreach ($rs as $user) {
30 //TODO we should probably support all text formats here or only FORMAT_MOODLE
31 //For now bulk messaging is still using the html editor and its supplying html
32 //so we have to use html format for it to be displayed correctly
33 message_post_message($USER, $user, $msg, FORMAT_HTML
);
39 $msgform = new user_message_form('user_bulk_message.php');
41 if ($msgform->is_cancelled()) {
44 } else if ($formdata = $msgform->get_data()) {
45 $options = new stdClass();
46 $options->para
= false;
47 $options->newlines
= true;
48 $options->smiley
= false;
50 $msg = format_text($formdata->messagebody
['text'], $formdata->messagebody
['format'], $options);
52 list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users
);
53 $userlist = $DB->get_records_select_menu('user', "id $in", $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname');
54 $usernames = implode(', ', $userlist);
55 echo $OUTPUT->header();
56 echo $OUTPUT->heading(get_string('confirmation', 'admin'));
57 echo $OUTPUT->box($msg, 'boxwidthnarrow boxaligncenter generalbox', 'preview'); //TODO: clean once we start using proper text formats here
59 $formcontinue = new single_button(new moodle_url('user_bulk_message.php', array('confirm' => 1, 'msg' => $msg)), get_string('yes')); //TODO: clean once we start using proper text formats here
60 $formcancel = new single_button(new moodle_url('user_bulk.php'), get_string('no'), 'get');
61 echo $OUTPUT->confirm(get_string('confirmmessage', 'bulkusers', $usernames), $formcontinue, $formcancel);
62 echo $OUTPUT->footer();
66 echo $OUTPUT->header();
68 echo $OUTPUT->footer();