[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/user/ -> user_bulk_message.php (source)

   1  <?php
   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');
   6  
   7  $msg     = optional_param('msg', '', PARAM_CLEANHTML);
   8  $confirm = optional_param('confirm', 0, PARAM_BOOL);
   9  
  10  require_login();
  11  admin_externalpage_setup('userbulk');
  12  require_capability('moodle/site:readallmessages', context_system::instance());
  13  
  14  $return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
  15  
  16  if (empty($SESSION->bulk_users)) {
  17      redirect($return);
  18  }
  19  
  20  if (empty($CFG->messaging)) {
  21      print_error('messagingdisable', 'error');
  22  }
  23  
  24  //TODO: add support for large number of users
  25  
  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);
  34      }
  35      $rs->close();
  36      redirect($return);
  37  }
  38  
  39  $msgform = new user_message_form('user_bulk_message.php');
  40  
  41  if ($msgform->is_cancelled()) {
  42      redirect($return);
  43  
  44  } else if ($formdata = $msgform->get_data()) {
  45      $options = new stdClass();
  46      $options->para     = false;
  47      $options->newlines = true;
  48      $options->smiley   = false;
  49  
  50      $msg = format_text($formdata->messagebody['text'], $formdata->messagebody['format'], $options);
  51  
  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
  58  
  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();
  63      die;
  64  }
  65  
  66  echo $OUTPUT->header();
  67  $msgform->display();
  68  echo $OUTPUT->footer();


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1