file check_defaults.class.php was added on branch MOODLE_19_STABLE on 2008-05-15...
[moodle-linuxchix.git] / admin / user / user_bulk_message.php
blob42751ccca0defefe99a55b1da4bad2a50e402505
1 <?php //$Id$
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_CLEAN);
8 $confirm = optional_param('confirm', 0, PARAM_BOOL);
10 admin_externalpage_setup('userbulk');
11 require_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM));
13 $return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
15 if (empty($SESSION->bulk_users)) {
16 redirect($return);
19 if (empty($CFG->messaging)) {
20 error("Messaging is disabled on this site");
23 //TODO: add support for large number of users
25 if ($confirm and !empty($msg) and confirm_sesskey()) {
26 $in = implode(',', $SESSION->bulk_users);
27 if ($rs = get_recordset_select('user', "id IN ($in)")) {
28 while ($user = rs_fetch_next_record($rs)) {
29 message_post_message($USER, $user, $msg, FORMAT_HTML, 'direct');
32 redirect($return);
35 // disable html editor if not enabled in preferences
36 if (!get_user_preferences('message_usehtmleditor', 0)) {
37 $CFG->htmleditor = '';
40 $msgform = new user_message_form('user_bulk_message.php');
42 if ($msgform->is_cancelled()) {
43 redirect($return);
45 } else if ($formdata = $msgform->get_data(false)) {
46 $options = new object();
47 $options->para = false;
48 $options->newlines = true;
49 $options->smiley = false;
51 $msg = format_text($formdata->messagebody, $formdata->format, $options);
53 $in = implode(',', $SESSION->bulk_users);
54 $userlist = get_records_select_menu('user', "id IN ($in)", 'fullname', 'id,'.sql_fullname().' AS fullname');
55 $usernames = implode(', ', $userlist);
56 $optionsyes = array();
57 $optionsyes['confirm'] = 1;
58 $optionsyes['sesskey'] = sesskey();
59 $optionsyes['msg'] = $msg;
60 admin_externalpage_print_header();
61 print_heading(get_string('confirmation', 'admin'));
62 print_box($msg, 'boxwidthnarrow boxaligncenter generalbox', 'preview');
63 notice_yesno(get_string('confirmmessage', 'bulkusers', $usernames), 'user_bulk_message.php', 'user_bulk.php', $optionsyes, NULL, 'post', 'get');
64 admin_externalpage_print_footer();
65 die;
68 admin_externalpage_print_header();
69 $msgform->display();
70 admin_externalpage_print_footer();