Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Bulk user actions
  19   *
  20   * @package    core
  21   * @copyright  Moodle
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once('../../config.php');
  26  require_once($CFG->libdir.'/adminlib.php');
  27  require_once($CFG->dirroot.'/'.$CFG->admin.'/user/lib.php');
  28  require_once($CFG->dirroot.'/'.$CFG->admin.'/user/user_bulk_forms.php');
  29  
  30  admin_externalpage_setup('userbulk');
  31  
  32  if (!isset($SESSION->bulk_users)) {
  33      $SESSION->bulk_users = array();
  34  }
  35  // Create the user filter form.
  36  $ufiltering = new user_filtering();
  37  
  38  // Create the bulk operations form.
  39  $actionform = new user_bulk_action_form();
  40  if ($data = $actionform->get_data()) {
  41      // Check if an action should be performed and do so.
  42      $bulkactions = $actionform->get_actions();
  43      if (array_key_exists($data->action, $bulkactions)) {
  44          redirect($bulkactions[$data->action]->url);
  45      }
  46  
  47  }
  48  
  49  $userbulkform = new user_bulk_form(null, get_selection_data($ufiltering));
  50  
  51  if ($data = $userbulkform->get_data()) {
  52      if (!empty($data->addall)) {
  53          add_selection_all($ufiltering);
  54  
  55      } else if (!empty($data->addsel)) {
  56          if (!empty($data->ausers)) {
  57              if (in_array(0, $data->ausers)) {
  58                  add_selection_all($ufiltering);
  59              } else {
  60                  foreach ($data->ausers as $userid) {
  61                      if ($userid == -1) {
  62                          continue;
  63                      }
  64                      if (!isset($SESSION->bulk_users[$userid])) {
  65                          $SESSION->bulk_users[$userid] = $userid;
  66                      }
  67                  }
  68              }
  69          }
  70  
  71      } else if (!empty($data->removeall)) {
  72          $SESSION->bulk_users = array();
  73  
  74      } else if (!empty($data->removesel)) {
  75          if (!empty($data->susers)) {
  76              if (in_array(0, $data->susers)) {
  77                  $SESSION->bulk_users = array();
  78              } else {
  79                  foreach ($data->susers as $userid) {
  80                      if ($userid == -1) {
  81                          continue;
  82                      }
  83                      unset($SESSION->bulk_users[$userid]);
  84                  }
  85              }
  86          }
  87      }
  88  
  89      // Reset the form selections.
  90      unset($_POST);
  91      $userbulkform = new user_bulk_form(null, get_selection_data($ufiltering));
  92  }
  93  echo $OUTPUT->header();
  94  
  95  $ufiltering->display_add();
  96  $ufiltering->display_active();
  97  
  98  $userbulkform->display();
  99  
 100  $actionform->display();
 101  
 102  echo $OUTPUT->footer();