Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

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