Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/user/user_bulk_message.php
Go to the documentation of this file.
00001 <?php
00002 require_once('../../config.php');
00003 require_once($CFG->libdir.'/adminlib.php');
00004 require_once($CFG->dirroot.'/message/lib.php');
00005 require_once('user_message_form.php');
00006 
00007 $msg     = optional_param('msg', '', PARAM_CLEANHTML);
00008 $confirm = optional_param('confirm', 0, PARAM_BOOL);
00009 
00010 require_login();
00011 admin_externalpage_setup('userbulk');
00012 require_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM));
00013 
00014 $return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
00015 
00016 if (empty($SESSION->bulk_users)) {
00017     redirect($return);
00018 }
00019 
00020 if (empty($CFG->messaging)) {
00021     print_error('messagingdisable', 'error');
00022 }
00023 
00024 //TODO: add support for large number of users
00025 
00026 if ($confirm and !empty($msg) and confirm_sesskey()) {
00027     list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
00028     $rs = $DB->get_recordset_select('user', "id $in", $params);
00029     foreach ($rs as $user) {
00030         //TODO we should probably support all text formats here or only FORMAT_MOODLE
00031         //For now bulk messaging is still using the html editor and its supplying html
00032         //so we have to use html format for it to be displayed correctly
00033         message_post_message($USER, $user, $msg, FORMAT_HTML);
00034     }
00035     $rs->close();
00036     redirect($return);
00037 }
00038 
00039 $msgform = new user_message_form('user_bulk_message.php');
00040 
00041 if ($msgform->is_cancelled()) {
00042     redirect($return);
00043 
00044 } else if ($formdata = $msgform->get_data()) {
00045     $options = new stdClass();
00046     $options->para     = false;
00047     $options->newlines = true;
00048     $options->smiley   = false;
00049 
00050     $msg = format_text($formdata->messagebody['text'], $formdata->messagebody['format'], $options);
00051 
00052     list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
00053     $userlist = $DB->get_records_select_menu('user', "id $in", $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname');
00054     $usernames = implode(', ', $userlist);
00055     echo $OUTPUT->header();
00056     echo $OUTPUT->heading(get_string('confirmation', 'admin'));
00057     echo $OUTPUT->box($msg, 'boxwidthnarrow boxaligncenter generalbox', 'preview'); //TODO: clean once we start using proper text formats here
00058 
00059     $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
00060     $formcancel = new single_button(new moodle_url('user_bulk.php'), get_string('no'), 'get');
00061     echo $OUTPUT->confirm(get_string('confirmmessage', 'bulkusers', $usernames), $formcontinue, $formcancel);
00062     echo $OUTPUT->footer();
00063     die;
00064 }
00065 
00066 echo $OUTPUT->header();
00067 $msgform->display();
00068 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations