2007-08-07 07:26:58 +00:00
|
|
|
<?php //$Id$
|
2007-08-15 05:30:49 +00:00
|
|
|
require_once('../../config.php');
|
2007-08-07 07:26:58 +00:00
|
|
|
require_once($CFG->libdir.'/adminlib.php');
|
2007-11-13 08:43:20 +00:00
|
|
|
require_once($CFG->dirroot.'/message/lib.php');
|
|
|
|
require_once('user_message_form.php');
|
2007-08-07 07:26:58 +00:00
|
|
|
|
2007-11-13 08:43:20 +00:00
|
|
|
$msg = optional_param('msg', '', PARAM_CLEAN);
|
|
|
|
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
2007-08-07 07:26:58 +00:00
|
|
|
|
2009-07-20 08:57:18 +00:00
|
|
|
require_login();
|
2007-11-13 08:43:20 +00:00
|
|
|
admin_externalpage_setup('userbulk');
|
|
|
|
require_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM));
|
2007-09-28 03:07:03 +00:00
|
|
|
|
2007-11-13 08:43:20 +00:00
|
|
|
$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
|
|
|
|
|
|
|
|
if (empty($SESSION->bulk_users)) {
|
|
|
|
redirect($return);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($CFG->messaging)) {
|
2008-04-11 07:49:07 +00:00
|
|
|
print_error('messagingdisable', 'error');
|
2007-08-07 07:26:58 +00:00
|
|
|
}
|
|
|
|
|
2007-11-13 08:43:20 +00:00
|
|
|
//TODO: add support for large number of users
|
|
|
|
|
|
|
|
if ($confirm and !empty($msg) and confirm_sesskey()) {
|
|
|
|
$in = implode(',', $SESSION->bulk_users);
|
2008-05-31 09:50:46 +00:00
|
|
|
if ($rs = $DB->get_recordset_select('user', "id IN ($in)", null)) {
|
|
|
|
foreach ($rs as $user) {
|
2007-11-13 08:43:20 +00:00
|
|
|
message_post_message($USER, $user, $msg, FORMAT_HTML, 'direct');
|
2007-08-07 07:26:58 +00:00
|
|
|
}
|
2008-05-31 09:50:46 +00:00
|
|
|
$rs->close();
|
2007-08-07 07:26:58 +00:00
|
|
|
}
|
2007-11-13 08:43:20 +00:00
|
|
|
redirect($return);
|
2007-08-07 07:26:58 +00:00
|
|
|
}
|
|
|
|
|
2007-11-13 08:43:20 +00:00
|
|
|
// disable html editor if not enabled in preferences
|
|
|
|
if (!get_user_preferences('message_usehtmleditor', 0)) {
|
|
|
|
$CFG->htmleditor = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$msgform = new user_message_form('user_bulk_message.php');
|
|
|
|
|
|
|
|
if ($msgform->is_cancelled()) {
|
|
|
|
redirect($return);
|
|
|
|
|
2008-06-09 16:53:30 +00:00
|
|
|
} else if ($formdata = $msgform->get_data()) {
|
2007-11-13 08:43:20 +00:00
|
|
|
$options = new object();
|
|
|
|
$options->para = false;
|
|
|
|
$options->newlines = true;
|
|
|
|
$options->smiley = false;
|
|
|
|
|
|
|
|
$msg = format_text($formdata->messagebody, $formdata->format, $options);
|
|
|
|
|
|
|
|
$in = implode(',', $SESSION->bulk_users);
|
2008-05-31 09:50:46 +00:00
|
|
|
$userlist = $DB->get_records_select_menu('user', "id IN ($in)", null, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname');
|
2007-11-13 08:43:20 +00:00
|
|
|
$usernames = implode(', ', $userlist);
|
|
|
|
$optionsyes = array();
|
|
|
|
$optionsyes['confirm'] = 1;
|
|
|
|
$optionsyes['sesskey'] = sesskey();
|
|
|
|
$optionsyes['msg'] = $msg;
|
|
|
|
admin_externalpage_print_header();
|
2009-08-06 08:17:12 +00:00
|
|
|
echo $OUTPUT->heading(get_string('confirmation', 'admin'));
|
2007-11-13 08:43:20 +00:00
|
|
|
print_box($msg, 'boxwidthnarrow boxaligncenter generalbox', 'preview');
|
|
|
|
notice_yesno(get_string('confirmmessage', 'bulkusers', $usernames), 'user_bulk_message.php', 'user_bulk.php', $optionsyes, NULL, 'post', 'get');
|
|
|
|
admin_externalpage_print_footer();
|
|
|
|
die;
|
2007-08-07 07:26:58 +00:00
|
|
|
}
|
|
|
|
|
2007-11-13 08:43:20 +00:00
|
|
|
admin_externalpage_print_header();
|
|
|
|
$msgform->display();
|
2007-08-07 07:26:58 +00:00
|
|
|
admin_externalpage_print_footer();
|
2008-04-11 07:49:07 +00:00
|
|
|
?>
|