Example #1
0
 /**
  * Determine whether the current user can delete users.
  * @return bool Whether the user has permission or not
  */
 public function can_do_delete()
 {
     $contexts = bulkuserpage::get_contexts('local/elisprogram:user_delete');
     return !$contexts->is_empty();
 }
 function action_delete()
 {
     global $CURMAN;
     require_once CURMAN_DIRLOCATION . '/lib/user.class.php';
     $users = explode(',', $this->required_param('selectedusers', PARAM_TEXT));
     // make sure everything is an int
     foreach ($users as $key => $val) {
         $users[$key] = (int) $val;
         if (empty($users[$key])) {
             unset($users[$key]);
         }
     }
     $result = true;
     foreach ($users as $userid) {
         $userobj = new user($userid);
         if (!($result = $userobj->delete())) {
             break;
         }
     }
     $tmppage = new bulkuserpage();
     if ($result) {
         redirect($tmppage->get_url(), get_string('success_bulk_delete', 'block_curr_admin'));
     } else {
         print_error('error_bulk_delete', 'block_curr_admin', $tmppage->get_url());
     }
 }