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.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 401 and 402] [Versions 401 and 403]

   1  <?php
   2  
   3  // This file defines settingpages and externalpages under the "users" category.
   4  
   5  $ADMIN->add('users', new admin_category('accounts', new lang_string('accounts', 'admin')));
   6  $ADMIN->add('users', new admin_category('roles', new lang_string('permissions', 'role')));
   7  $ADMIN->add('users', new admin_category('privacy', new lang_string('privacyandpolicies', 'admin')));
   8  
   9  if ($hassiteconfig
  10   or has_capability('moodle/user:create', $systemcontext)
  11   or has_capability('moodle/user:update', $systemcontext)
  12   or has_capability('moodle/user:delete', $systemcontext)
  13   or has_capability('moodle/role:manage', $systemcontext)
  14   or has_capability('moodle/role:assign', $systemcontext)
  15   or has_capability('moodle/cohort:manage', $systemcontext)
  16   or has_capability('moodle/cohort:view', $systemcontext)) { // Speedup for non-admins, add all caps used on this page.
  17  
  18  
  19      // Stuff under the "accounts" subcategory.
  20      $ADMIN->add('accounts', new admin_externalpage('editusers', new lang_string('userlist','admin'), "$CFG->wwwroot/$CFG->admin/user.php", array('moodle/user:update', 'moodle/user:delete')));
  21      $ADMIN->add('accounts', new admin_externalpage('userbulk', new lang_string('userbulk','admin'), "$CFG->wwwroot/$CFG->admin/user/user_bulk.php", array('moodle/user:update', 'moodle/user:delete')));
  22      $ADMIN->add('accounts', new admin_externalpage('addnewuser', new lang_string('addnewuser'), "$CFG->wwwroot/user/editadvanced.php?id=-1", 'moodle/user:create'));
  23  
  24      // User management settingpage.
  25      $temp = new admin_settingpage('usermanagement', new lang_string('usermanagement', 'admin'));
  26      if ($ADMIN->fulltree) {
  27          $choices = array();
  28          $choices['realname'] = new lang_string('fullnameuser');
  29          $choices['lastname'] = new lang_string('lastname');
  30          $choices['firstname'] = new lang_string('firstname');
  31          $choices['username'] = new lang_string('username');
  32          $choices['email'] = new lang_string('email');
  33          $choices['city'] = new lang_string('city');
  34          $choices['country'] = new lang_string('country');
  35          $choices['confirmed'] = new lang_string('confirmed', 'admin');
  36          $choices['suspended'] = new lang_string('suspended', 'auth');
  37          $choices['profile'] = new lang_string('profilefields', 'admin');
  38          $choices['courserole'] = new lang_string('courserole', 'filters');
  39          $choices['anycourses'] = new lang_string('anycourses', 'filters');
  40          $choices['systemrole'] = new lang_string('globalrole', 'role');
  41          $choices['cohort'] = new lang_string('idnumber', 'core_cohort');
  42          $choices['firstaccess'] = new lang_string('firstaccess', 'filters');
  43          $choices['lastaccess'] = new lang_string('lastaccess');
  44          $choices['neveraccessed'] = new lang_string('neveraccessed', 'filters');
  45          $choices['timecreated'] = new lang_string('timecreated');
  46          $choices['timemodified'] = new lang_string('lastmodified');
  47          $choices['nevermodified'] = new lang_string('nevermodified', 'filters');
  48          $choices['auth'] = new lang_string('authentication');
  49          $choices['idnumber'] = new lang_string('idnumber');
  50          $choices['lastip'] = new lang_string('lastip');
  51          $choices['mnethostid'] = new lang_string('mnetidprovider', 'mnet');
  52          $temp->add(new admin_setting_configmultiselect('userfiltersdefault', new lang_string('userfiltersdefault', 'admin'),
  53              new lang_string('userfiltersdefault_desc', 'admin'), array('realname'), $choices));
  54      }
  55      $ADMIN->add('accounts', $temp);
  56  
  57      // User default preferences settingpage.
  58      $temp = new admin_settingpage('userdefaultpreferences', new lang_string('userdefaultpreferences', 'admin'));
  59      if ($ADMIN->fulltree) {
  60          $choices = array();
  61          $choices['0'] = new lang_string('emaildisplayno');
  62          $choices['1'] = new lang_string('emaildisplayyes');
  63          $choices['2'] = new lang_string('emaildisplaycourse');
  64          $temp->add(new admin_setting_configselect('defaultpreference_maildisplay', new lang_string('emaildisplay'),
  65              new lang_string('emaildisplay_help'), 2, $choices));
  66  
  67          $choices = array();
  68          $choices['0'] = new lang_string('textformat');
  69          $choices['1'] = new lang_string('htmlformat');
  70          $temp->add(new admin_setting_configselect('defaultpreference_mailformat', new lang_string('emailformat'), '', 1, $choices));
  71  
  72          $choices = array();
  73          $choices['0'] = new lang_string('emaildigestoff');
  74          $choices['1'] = new lang_string('emaildigestcomplete');
  75          $choices['2'] = new lang_string('emaildigestsubjects');
  76          $temp->add(new admin_setting_configselect('defaultpreference_maildigest', new lang_string('emaildigest'),
  77              new lang_string('emaildigest_help'), 0, $choices));
  78  
  79  
  80          $choices = array();
  81          $choices['1'] = new lang_string('autosubscribeyes');
  82          $choices['0'] = new lang_string('autosubscribeno');
  83          $temp->add(new admin_setting_configselect('defaultpreference_autosubscribe', new lang_string('autosubscribe'),
  84              '', 1, $choices));
  85  
  86          $choices = array();
  87          $choices['0'] = new lang_string('trackforumsno');
  88          $choices['1'] = new lang_string('trackforumsyes');
  89          $temp->add(new admin_setting_configselect('defaultpreference_trackforums', new lang_string('trackforums'),
  90              '', 0, $choices));
  91  
  92          $choices = [];
  93          $choices[\core_contentbank\content::VISIBILITY_PUBLIC] = new lang_string('visibilitychoicepublic', 'core_contentbank');
  94          $choices[\core_contentbank\content::VISIBILITY_UNLISTED] = new lang_string('visibilitychoiceunlisted', 'core_contentbank');
  95          $temp->add(new admin_setting_configselect('defaultpreference_core_contentbank_visibility',
  96              new lang_string('visibilitypref', 'core_contentbank'),
  97              new lang_string('visibilitypref_help', 'core_contentbank'),
  98              \core_contentbank\content::VISIBILITY_PUBLIC, $choices));
  99      }
 100      $ADMIN->add('accounts', $temp);
 101  
 102      $ADMIN->add('accounts', new admin_externalpage('profilefields', new lang_string('profilefields','admin'), "$CFG->wwwroot/user/profile/index.php", 'moodle/site:config'));
 103      $ADMIN->add('accounts', new admin_externalpage('cohorts', new lang_string('cohorts', 'cohort'), $CFG->wwwroot . '/cohort/index.php', array('moodle/cohort:manage', 'moodle/cohort:view')));
 104  
 105  
 106      // Stuff under the "roles" subcategory.
 107  
 108      // User policies settingpage.
 109      $temp = new admin_settingpage('userpolicies', new lang_string('userpolicies', 'admin'));
 110      if ($ADMIN->fulltree) {
 111          if (!during_initial_install()) {
 112              $context = context_system::instance();
 113  
 114              $otherroles      = array();
 115              $guestroles      = array();
 116              $userroles       = array();
 117              $creatornewroles = array();
 118  
 119              $defaultteacherid = null;
 120              $defaultuserid    = null;
 121              $defaultguestid   = null;
 122  
 123              $roles = role_fix_names(get_all_roles(), null, ROLENAME_ORIGINALANDSHORT);
 124              foreach ($roles as $role) {
 125                  $rolename = $role->localname;
 126                  switch ($role->archetype) {
 127                      case 'manager':
 128                          $creatornewroles[$role->id] = $rolename;
 129                          break;
 130                      case 'coursecreator':
 131                          break;
 132                      case 'editingteacher':
 133                          $defaultteacherid = isset($defaultteacherid) ? $defaultteacherid : $role->id;
 134                          $creatornewroles[$role->id] = $rolename;
 135                          break;
 136                      case 'teacher':
 137                          $creatornewroles[$role->id] = $rolename;
 138                          break;
 139                      case 'student':
 140                          break;
 141                      case 'guest':
 142                          $defaultguestid = isset($defaultguestid) ? $defaultguestid : $role->id;
 143                          $guestroles[$role->id] = $rolename;
 144                          break;
 145                      case 'user':
 146                          $defaultuserid = isset($defaultuserid) ? $defaultuserid : $role->id;
 147                          $userroles[$role->id] = $rolename;
 148                          break;
 149                      case 'frontpage':
 150                          break;
 151                      default:
 152                          $creatornewroles[$role->id] = $rolename;
 153                          $otherroles[$role->id] = $rolename;
 154                          break;
 155                  }
 156              }
 157  
 158              if (empty($guestroles)) {
 159                  $guestroles[0] = new lang_string('none');
 160                  $defaultguestid = 0;
 161              }
 162  
 163              if (empty($userroles)) {
 164                  $userroles[0] = new lang_string('none');
 165                  $defaultuserid = 0;
 166              }
 167  
 168              $restorersnewrole = $creatornewroles;
 169              $restorersnewrole[0] = new lang_string('none');
 170  
 171              $temp->add(new admin_setting_configselect('notloggedinroleid', new lang_string('notloggedinroleid', 'admin'),
 172                            new lang_string('confignotloggedinroleid', 'admin'), $defaultguestid, ($guestroles + $otherroles)));
 173              $temp->add(new admin_setting_configselect('guestroleid', new lang_string('guestroleid', 'admin'),
 174                            new lang_string('guestroleid_help', 'admin'), $defaultguestid, ($guestroles + $otherroles)));
 175              $temp->add(new admin_setting_configselect('defaultuserroleid', new lang_string('defaultuserroleid', 'admin'),
 176                            new lang_string('configdefaultuserroleid', 'admin'), $defaultuserid, ($userroles + $otherroles)));
 177              $temp->add(new admin_setting_configselect('creatornewroleid', new lang_string('creatornewroleid', 'admin'),
 178                            new lang_string('creatornewroleid_help', 'admin'), $defaultteacherid, $creatornewroles));
 179              $temp->add(new admin_setting_configselect('restorernewroleid', new lang_string('restorernewroleid', 'admin'),
 180                            new lang_string('restorernewroleid_help', 'admin'), $defaultteacherid, $restorersnewrole));
 181  
 182              // Release memory.
 183              unset($otherroles);
 184              unset($guestroles);
 185              unset($userroles);
 186              unset($creatornewroles);
 187              unset($restorersnewrole);
 188          }
 189  
 190          $temp->add(new admin_setting_configcheckbox('enroladminnewcourse', new lang_string('enroladminnewcourse', 'admin'),
 191              new lang_string('enroladminnewcourse_help', 'admin'), 1));
 192  
 193          $temp->add(new admin_setting_configcheckbox('autologinguests', new lang_string('autologinguests', 'admin'), new lang_string('configautologinguests', 'admin'), 0));
 194  
 195          $temp->add(new admin_setting_configmultiselect('hiddenuserfields', new lang_string('hiddenuserfields', 'admin'),
 196                     new lang_string('confighiddenuserfields', 'admin'), array(),
 197                         array('description' => new lang_string('description'),
 198                               'email' => new lang_string('email'),
 199                               'city' => new lang_string('city'),
 200                               'country' => new lang_string('country'),
 201                               'moodlenetprofile' => new lang_string('moodlenetprofile', 'user'),
 202                               'timezone' => new lang_string('timezone'),
 203                               'firstaccess' => new lang_string('firstaccess'),
 204                               'lastaccess' => new lang_string('lastaccess'),
 205                               'lastip' => new lang_string('lastip'),
 206                               'mycourses' => new lang_string('mycourses'),
 207                               'groups' => new lang_string('groups'),
 208                               'suspended' => new lang_string('suspended', 'auth'),
 209                         )));
 210  
 211          // Select fields to display as part of user identity (only to those
 212          // with moodle/site:viewuseridentity).
 213          // Options include fields from the user table that might be helpful to
 214          // distinguish when adding or listing users ('I want to add the John
 215          // Smith from Science faculty') and any custom profile fields.
 216          $temp->add(new admin_setting_configmulticheckbox('showuseridentity',
 217                  new lang_string('showuseridentity', 'admin'),
 218                  new lang_string('showuseridentity_desc', 'admin'), ['email' => 1],
 219                  function() {
 220                      global $CFG;
 221                      require_once($CFG->dirroot.'/user/profile/lib.php');
 222  
 223                      // Basic fields available in user table.
 224                      $fields = [
 225                          'username'    => new lang_string('username'),
 226                          'idnumber'    => new lang_string('idnumber'),
 227                          'email'       => new lang_string('email'),
 228                          'phone1'      => new lang_string('phone1'),
 229                          'phone2'      => new lang_string('phone2'),
 230                          'department'  => new lang_string('department'),
 231                          'institution' => new lang_string('institution'),
 232                          'city'        => new lang_string('city'),
 233                          'country'     => new lang_string('country'),
 234                      ];
 235  
 236                      // Custom profile fields.
 237                      $profilefields = profile_get_custom_fields();
 238                      foreach ($profilefields as $field) {
 239                          // Only reasonable-length text fields can be used as identity fields.
 240                          if ($field->param2 > 255 || $field->datatype != 'text') {
 241                              continue;
 242                          }
 243                          $fields['profile_field_' . $field->shortname] = format_string($field->name, true,
 244                              ['context' => context_system::instance()]) . ' *';
 245                      }
 246  
 247                      return $fields;
 248                  }));
 249          $setting = new admin_setting_configtext('fullnamedisplay', new lang_string('fullnamedisplay', 'admin'),
 250              new lang_string('configfullnamedisplay', 'admin'), 'language', PARAM_TEXT, 50);
 251          $setting->set_force_ltr(true);
 252          $temp->add($setting);
 253          $temp->add(new admin_setting_configtext('alternativefullnameformat', new lang_string('alternativefullnameformat', 'admin'),
 254                  new lang_string('alternativefullnameformat_desc', 'admin'),
 255                  'language', PARAM_RAW, 50));
 256          $temp->add(new admin_setting_configtext('maxusersperpage', new lang_string('maxusersperpage','admin'), new lang_string('configmaxusersperpage','admin'), 100, PARAM_INT));
 257          $temp->add(new admin_setting_configcheckbox('enablegravatar', new lang_string('enablegravatar', 'admin'), new lang_string('enablegravatar_help', 'admin'), 0));
 258          $temp->add(new admin_setting_configtext('gravatardefaulturl', new lang_string('gravatardefaulturl', 'admin'), new lang_string('gravatardefaulturl_help', 'admin'), 'mm'));
 259      }
 260  
 261      $ADMIN->add('roles', $temp);
 262  
 263      if (is_siteadmin()) {
 264          $ADMIN->add('roles', new admin_externalpage('admins', new lang_string('siteadministrators', 'role'), "$CFG->wwwroot/$CFG->admin/roles/admins.php"));
 265      }
 266      $ADMIN->add('roles', new admin_externalpage('defineroles', new lang_string('defineroles', 'role'), "$CFG->wwwroot/$CFG->admin/roles/manage.php", 'moodle/role:manage'));
 267      $ADMIN->add('roles', new admin_externalpage('assignroles', new lang_string('assignglobalroles', 'role'), "$CFG->wwwroot/$CFG->admin/roles/assign.php?contextid=".$systemcontext->id, 'moodle/role:assign'));
 268      $ADMIN->add('roles', new admin_externalpage('checkpermissions', new lang_string('checkglobalpermissions', 'role'), "$CFG->wwwroot/$CFG->admin/roles/check.php?contextid=".$systemcontext->id, array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:manage')));
 269  
 270  } // End of speedup.
 271  
 272  // Privacy settings.
 273  if ($hassiteconfig) {
 274      $temp = new admin_settingpage('privacysettings', new lang_string('privacysettings', 'admin'));
 275  
 276      $options = array(
 277          0 => get_string('no'),
 278          1 => get_string('yes')
 279      );
 280      $url = new moodle_url('/admin/settings.php?section=supportcontact');
 281      $url = $url->out();
 282      $setting = new admin_setting_configselect('agedigitalconsentverification',
 283          new lang_string('agedigitalconsentverification', 'admin'),
 284          new lang_string('agedigitalconsentverification_desc', 'admin', $url), 0, $options);
 285      $setting->set_force_ltr(true);
 286      $temp->add($setting);
 287  
 288      // See {@link https://gdpr-info.eu/art-8-gdpr/}.
 289      // See {@link https://www.betterinternetforkids.eu/web/portal/practice/awareness/detail?articleId=3017751}.
 290      $ageofdigitalconsentmap = implode(PHP_EOL, [
 291          '*, 16',
 292          'AT, 14',
 293          'BE, 13',
 294          'BG, 14',
 295          'CY, 14',
 296          'CZ, 15',
 297          'DK, 13',
 298          'EE, 13',
 299          'ES, 14',
 300          'FI, 13',
 301          'FR, 15',
 302          'GB, 13',
 303          'GR, 15',
 304          'IT, 14',
 305          'LT, 14',
 306          'LV, 13',
 307          'MT, 13',
 308          'NO, 13',
 309          'PT, 13',
 310          'SE, 13',
 311          'US, 13'
 312      ]);
 313      $setting = new admin_setting_agedigitalconsentmap('agedigitalconsentmap',
 314          new lang_string('ageofdigitalconsentmap', 'admin'),
 315          new lang_string('ageofdigitalconsentmap_desc', 'admin'),
 316          $ageofdigitalconsentmap,
 317          PARAM_RAW
 318      );
 319      $temp->add($setting);
 320  
 321      $ADMIN->add('privacy', $temp);
 322  
 323      // Policy settings.
 324      $temp = new admin_settingpage('policysettings', new lang_string('policysettings', 'admin'));
 325      $temp->add(new admin_settings_sitepolicy_handler_select('sitepolicyhandler', new lang_string('sitepolicyhandler', 'core_admin'),
 326          new lang_string('sitepolicyhandler_desc', 'core_admin')));
 327      $temp->add(new admin_setting_configtext('sitepolicy', new lang_string('sitepolicy', 'core_admin'),
 328          new lang_string('sitepolicy_help', 'core_admin'), '', PARAM_RAW));
 329      $temp->add(new admin_setting_configtext('sitepolicyguest', new lang_string('sitepolicyguest', 'core_admin'),
 330          new lang_string('sitepolicyguest_help', 'core_admin'), (isset($CFG->sitepolicy) ? $CFG->sitepolicy : ''), PARAM_RAW));
 331  
 332      $ADMIN->add('privacy', $temp);
 333  }