| 1 | 
           efrain | 
           1 | 
           <?php
  | 
        
        
            | 
            | 
           2 | 
           /**
  | 
        
        
            | 
            | 
           3 | 
           * script for bulk user delete operations
  | 
        
        
            | 
            | 
           4 | 
           */
  | 
        
        
            | 
            | 
           5 | 
              | 
        
        
            | 
            | 
           6 | 
           require_once('../../config.php');
  | 
        
        
            | 
            | 
           7 | 
           require_once($CFG->libdir.'/adminlib.php');
  | 
        
        
            | 
            | 
           8 | 
              | 
        
        
            | 
            | 
           9 | 
           $confirm = optional_param('confirm', 0, PARAM_BOOL);
  | 
        
        
            | 
            | 
           10 | 
              | 
        
        
            | 
            | 
           11 | 
           admin_externalpage_setup('userbulk');
  | 
        
        
            | 
            | 
           12 | 
           require_capability('moodle/user:update', context_system::instance());
  | 
        
        
            | 
            | 
           13 | 
              | 
        
        
            | 
            | 
           14 | 
           $returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
  | 
        
        
            | 
            | 
           15 | 
           $return = new moodle_url($returnurl ?: '/admin/user/user_bulk.php');
  | 
        
        
            | 
            | 
           16 | 
              | 
        
        
            | 
            | 
           17 | 
           if (empty($SESSION->bulk_users)) {
  | 
        
        
            | 
            | 
           18 | 
               redirect($return);
  | 
        
        
            | 
            | 
           19 | 
           }
  | 
        
        
            | 
            | 
           20 | 
              | 
        
        
            | 
            | 
           21 | 
           $PAGE->set_primary_active_tab('siteadminnode');
  | 
        
        
            | 
            | 
           22 | 
           $PAGE->set_secondary_active_tab('users');
  | 
        
        
            | 
            | 
           23 | 
              | 
        
        
            | 
            | 
           24 | 
           echo $OUTPUT->header();
  | 
        
        
            | 
            | 
           25 | 
              | 
        
        
            | 
            | 
           26 | 
           //TODO: add support for large number of users
  | 
        
        
            | 
            | 
           27 | 
              | 
        
        
            | 
            | 
           28 | 
           if ($confirm and confirm_sesskey()) {
  | 
        
        
            | 
            | 
           29 | 
               $notifications = '';
  | 
        
        
            | 
            | 
           30 | 
               list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
  | 
        
        
            | 
            | 
           31 | 
               $rs = $DB->get_recordset_select('user', "id $in", $params, '', 'id, username, secret, confirmed, auth, firstname, lastname');
  | 
        
        
            | 
            | 
           32 | 
               foreach ($rs as $user) {
  | 
        
        
            | 
            | 
           33 | 
                   if ($user->confirmed) {
  | 
        
        
            | 
            | 
           34 | 
                       continue;
  | 
        
        
            | 
            | 
           35 | 
                   }
  | 
        
        
            | 
            | 
           36 | 
                   $auth = get_auth_plugin($user->auth);
  | 
        
        
            | 
            | 
           37 | 
                   $result = $auth->user_confirm($user->username, $user->secret);
  | 
        
        
            | 
            | 
           38 | 
                   if ($result != AUTH_CONFIRM_OK && $result != AUTH_CONFIRM_ALREADY) {
  | 
        
        
            | 
            | 
           39 | 
                       $notifications .= $OUTPUT->notification(get_string('usernotconfirmed', '', fullname($user, true)));
  | 
        
        
            | 
            | 
           40 | 
                   }
  | 
        
        
            | 
            | 
           41 | 
               }
  | 
        
        
            | 
            | 
           42 | 
               $rs->close();
  | 
        
        
            | 
            | 
           43 | 
               echo $OUTPUT->box_start('generalbox', 'notice');
  | 
        
        
            | 
            | 
           44 | 
               if (!empty($notifications)) {
  | 
        
        
            | 
            | 
           45 | 
                   echo $notifications;
  | 
        
        
            | 
            | 
           46 | 
               } else {
  | 
        
        
            | 
            | 
           47 | 
                   echo $OUTPUT->notification(get_string('changessaved'), 'notifysuccess');
  | 
        
        
            | 
            | 
           48 | 
               }
  | 
        
        
            | 
            | 
           49 | 
               $continue = new single_button($return, get_string('continue'), 'post');
  | 
        
        
            | 
            | 
           50 | 
               echo $OUTPUT->render($continue);
  | 
        
        
            | 
            | 
           51 | 
               echo $OUTPUT->box_end();
  | 
        
        
            | 
            | 
           52 | 
           } else {
  | 
        
        
            | 
            | 
           53 | 
               list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
  | 
        
        
            | 
            | 
           54 | 
               $userlist = $DB->get_records_select_menu('user', "id $in", $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname');
  | 
        
        
            | 
            | 
           55 | 
               $usernames = implode(', ', $userlist);
  | 
        
        
            | 
            | 
           56 | 
               echo $OUTPUT->heading(get_string('confirmation', 'admin'));
  | 
        
        
            | 
            | 
           57 | 
               $formcontinue = new single_button(new moodle_url('user_bulk_confirm.php',
  | 
        
        
            | 
            | 
           58 | 
                   ['confirm' => 1, 'returnurl' => $returnurl]), get_string('yes'));
  | 
        
        
            | 
            | 
           59 | 
               $formcancel = new single_button($return, get_string('no'), 'get');
  | 
        
        
            | 
            | 
           60 | 
               echo $OUTPUT->confirm(get_string('confirmcheckfull', '', $usernames), $formcontinue, $formcancel);
  | 
        
        
            | 
            | 
           61 | 
           }
  | 
        
        
            | 
            | 
           62 | 
              | 
        
        
            | 
            | 
           63 | 
           echo $OUTPUT->footer();
  |