MDL-67883 core: Make core ready for MoodleNet.
[moodle.git] / admin / settings / users.php
CommitLineData
11b749ca 1<?php
50999a0b 2
7e00bfd9 3// This file defines settingpages and externalpages under the "users" category.
50999a0b 4
e106013f
SH
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')));
a97af76c 7$ADMIN->add('users', new admin_category('privacy', new lang_string('privacyandpolicies', 'admin')));
d86f4473 8
fc4069d6 9if ($hassiteconfig
fc4069d6 10 or has_capability('moodle/user:create', $systemcontext)
11 or has_capability('moodle/user:update', $systemcontext)
61d04bcc 12 or has_capability('moodle/user:delete', $systemcontext)
13 or has_capability('moodle/role:manage', $systemcontext)
864e2805
PS
14 or has_capability('moodle/role:assign', $systemcontext)
15 or has_capability('moodle/cohort:manage', $systemcontext)
7e00bfd9 16 or has_capability('moodle/cohort:view', $systemcontext)) { // Speedup for non-admins, add all caps used on this page.
7d0c81b3 17
50999a0b 18
7e00bfd9 19 // Stuff under the "accounts" subcategory.
e106013f
SH
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')));
b58764ff 22 $ADMIN->add('accounts', new admin_externalpage('addnewuser', new lang_string('addnewuser'), "$CFG->wwwroot/user/editadvanced.php?id=-1", 'moodle/user:create'));
747dac69 23
7e00bfd9 24 // User management settingpage.
a292ed54
AB
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
7e00bfd9 56 // User default preferences settingpage.
747dac69
MG
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'),
d2bba97d 64 new lang_string('emaildisplay_help'), 2, $choices));
747dac69
MG
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
d9b60e31
PS
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));
747dac69
MG
90 }
91 $ADMIN->add('accounts', $temp);
92
e106013f
SH
93 $ADMIN->add('accounts', new admin_externalpage('profilefields', new lang_string('profilefields','admin'), "$CFG->wwwroot/user/profile/index.php", 'moodle/site:config'));
94 $ADMIN->add('accounts', new admin_externalpage('cohorts', new lang_string('cohorts', 'cohort'), $CFG->wwwroot . '/cohort/index.php', array('moodle/cohort:manage', 'moodle/cohort:view')));
220a90c5 95
96
7e00bfd9 97 // Stuff under the "roles" subcategory.
220a90c5 98
7e00bfd9 99 // User policies settingpage.
e106013f 100 $temp = new admin_settingpage('userpolicies', new lang_string('userpolicies', 'admin'));
220a90c5 101 if ($ADMIN->fulltree) {
31a99877 102 if (!during_initial_install()) {
bf006d2c 103 $context = context_system::instance();
82053cb1
PS
104
105 $otherroles = array();
4f0c2d00
PS
106 $guestroles = array();
107 $userroles = array();
4f0c2d00 108 $creatornewroles = array();
df997f84 109
82053cb1
PS
110 $defaultteacherid = null;
111 $defaultuserid = null;
112 $defaultguestid = null;
113
c52551dc
PS
114 $roles = role_fix_names(get_all_roles(), null, ROLENAME_ORIGINALANDSHORT);
115 foreach ($roles as $role) {
116 $rolename = $role->localname;
4f0c2d00
PS
117 switch ($role->archetype) {
118 case 'manager':
119 $creatornewroles[$role->id] = $rolename;
120 break;
121 case 'coursecreator':
122 break;
123 case 'editingteacher':
82053cb1 124 $defaultteacherid = isset($defaultteacherid) ? $defaultteacherid : $role->id;
4f0c2d00
PS
125 $creatornewroles[$role->id] = $rolename;
126 break;
127 case 'teacher':
128 $creatornewroles[$role->id] = $rolename;
129 break;
130 case 'student':
4f0c2d00
PS
131 break;
132 case 'guest':
82053cb1 133 $defaultguestid = isset($defaultguestid) ? $defaultguestid : $role->id;
4f0c2d00
PS
134 $guestroles[$role->id] = $rolename;
135 break;
136 case 'user':
82053cb1 137 $defaultuserid = isset($defaultuserid) ? $defaultuserid : $role->id;
4f0c2d00
PS
138 $userroles[$role->id] = $rolename;
139 break;
140 case 'frontpage':
141 break;
142 default:
143 $creatornewroles[$role->id] = $rolename;
82053cb1 144 $otherroles[$role->id] = $rolename;
4f0c2d00 145 break;
220a90c5 146 }
147 }
11b749ca 148
82053cb1 149 if (empty($guestroles)) {
e106013f 150 $guestroles[0] = new lang_string('none');
82053cb1
PS
151 $defaultguestid = 0;
152 }
153
154 if (empty($userroles)) {
e106013f 155 $userroles[0] = new lang_string('none');
4f0c2d00 156 $defaultuserid = 0;
220a90c5 157 }
158
73d000f3 159 $restorersnewrole = $creatornewroles;
e106013f
SH
160 $restorersnewrole[0] = new lang_string('none');
161
162 $temp->add(new admin_setting_configselect('notloggedinroleid', new lang_string('notloggedinroleid', 'admin'),
163 new lang_string('confignotloggedinroleid', 'admin'), $defaultguestid, ($guestroles + $otherroles)));
164 $temp->add(new admin_setting_configselect('guestroleid', new lang_string('guestroleid', 'admin'),
165 new lang_string('guestroleid_help', 'admin'), $defaultguestid, ($guestroles + $otherroles)));
166 $temp->add(new admin_setting_configselect('defaultuserroleid', new lang_string('defaultuserroleid', 'admin'),
167 new lang_string('configdefaultuserroleid', 'admin'), $defaultuserid, ($userroles + $otherroles)));
168 $temp->add(new admin_setting_configselect('creatornewroleid', new lang_string('creatornewroleid', 'admin'),
169 new lang_string('creatornewroleid_help', 'admin'), $defaultteacherid, $creatornewroles));
170 $temp->add(new admin_setting_configselect('restorernewroleid', new lang_string('restorernewroleid', 'admin'),
171 new lang_string('restorernewroleid_help', 'admin'), $defaultteacherid, $restorersnewrole));
82053cb1 172
7e00bfd9 173 // Release memory.
82053cb1
PS
174 unset($otherroles);
175 unset($guestroles);
176 unset($userroles);
177 unset($creatornewroles);
73d000f3 178 unset($restorersnewrole);
220a90c5 179 }
69833712 180
e106013f
SH
181 $temp->add(new admin_setting_configcheckbox('autologinguests', new lang_string('autologinguests', 'admin'), new lang_string('configautologinguests', 'admin'), 0));
182
183 $temp->add(new admin_setting_configmultiselect('hiddenuserfields', new lang_string('hiddenuserfields', 'admin'),
184 new lang_string('confighiddenuserfields', 'admin'), array(),
185 array('description' => new lang_string('description'),
565f3f25 186 'email' => new lang_string('email'),
e106013f
SH
187 'city' => new lang_string('city'),
188 'country' => new lang_string('country'),
16d77f18 189 'moodlenetprofile' => new lang_string('moodlenetprofile', 'user'),
d6e7a63d 190 'timezone' => new lang_string('timezone'),
e106013f
SH
191 'webpage' => new lang_string('webpage'),
192 'icqnumber' => new lang_string('icqnumber'),
193 'skypeid' => new lang_string('skypeid'),
194 'yahooid' => new lang_string('yahooid'),
195 'aimid' => new lang_string('aimid'),
196 'msnid' => new lang_string('msnid'),
197 'firstaccess' => new lang_string('firstaccess'),
198 'lastaccess' => new lang_string('lastaccess'),
9d9361e8 199 'lastip' => new lang_string('lastip'),
e106013f 200 'mycourses' => new lang_string('mycourses'),
44d5c138
SH
201 'groups' => new lang_string('groups'),
202 'suspended' => new lang_string('suspended', 'auth'),
4ad72c28 203 )));
99cd2f77 204
5c60a847 205 // Select fields to display as part of user identity (only to those
206 // with moodle/site:viewuseridentity).
207 // Options include fields from the user table that might be helpful to
208 // distinguish when adding or listing users ('I want to add the John
209 // Smith from Science faculty').
5c60a847 210 // Custom user profile fields are not currently supported.
211 $temp->add(new admin_setting_configmulticheckbox('showuseridentity',
e106013f
SH
212 new lang_string('showuseridentity', 'admin'),
213 new lang_string('showuseridentity_desc', 'admin'), array('email' => 1), array(
ab247472 214 'username' => new lang_string('username'),
e106013f
SH
215 'idnumber' => new lang_string('idnumber'),
216 'email' => new lang_string('email'),
70fb46c8 217 'phone1' => new lang_string('phone1'),
e106013f
SH
218 'phone2' => new lang_string('phone2'),
219 'department' => new lang_string('department'),
220 'institution' => new lang_string('institution'),
7a22e49e
JP
221 'city' => new lang_string('city'),
222 'country' => new lang_string('country'),
5c60a847 223 )));
113efed5
FM
224 $setting = new admin_setting_configtext('fullnamedisplay', new lang_string('fullnamedisplay', 'admin'),
225 new lang_string('configfullnamedisplay', 'admin'), 'language', PARAM_TEXT, 50);
226 $setting->set_force_ltr(true);
227 $temp->add($setting);
b3d5f7bc
AG
228 $temp->add(new admin_setting_configtext('alternativefullnameformat', new lang_string('alternativefullnameformat', 'admin'),
229 new lang_string('alternativefullnameformat_desc', 'admin'),
230 'language', PARAM_RAW, 50));
9a51c3d9 231 $temp->add(new admin_setting_configtext('maxusersperpage', new lang_string('maxusersperpage','admin'), new lang_string('configmaxusersperpage','admin'), 100, PARAM_INT));
e106013f 232 $temp->add(new admin_setting_configcheckbox('enablegravatar', new lang_string('enablegravatar', 'admin'), new lang_string('enablegravatar_help', 'admin'), 0));
f127b1a5 233 $temp->add(new admin_setting_configtext('gravatardefaulturl', new lang_string('gravatardefaulturl', 'admin'), new lang_string('gravatardefaulturl_help', 'admin'), 'mm'));
c785d40a 234 }
4766a50c 235
220a90c5 236 $ADMIN->add('roles', $temp);
8f8ed475 237
4f0c2d00 238 if (is_siteadmin()) {
e106013f 239 $ADMIN->add('roles', new admin_externalpage('admins', new lang_string('siteadministrators', 'role'), "$CFG->wwwroot/$CFG->admin/roles/admins.php"));
4f0c2d00 240 }
e106013f
SH
241 $ADMIN->add('roles', new admin_externalpage('defineroles', new lang_string('defineroles', 'role'), "$CFG->wwwroot/$CFG->admin/roles/manage.php", 'moodle/role:manage'));
242 $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'));
243 $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')));
8a8272b0 244
7e00bfd9 245} // End of speedup.
a97af76c
SA
246
247// Privacy settings.
248if ($hassiteconfig) {
249 $temp = new admin_settingpage('privacysettings', new lang_string('privacysettings', 'admin'));
250
251 $options = array(
252 0 => get_string('no'),
253 1 => get_string('yes')
254 );
255 $url = new moodle_url('/admin/settings.php?section=supportcontact');
256 $url = $url->out();
257 $setting = new admin_setting_configselect('agedigitalconsentverification',
258 new lang_string('agedigitalconsentverification', 'admin'),
259 new lang_string('agedigitalconsentverification_desc', 'admin', $url), 0, $options);
260 $setting->set_force_ltr(true);
261 $temp->add($setting);
262
b1f1bd2e
SA
263 // See {@link https://gdpr-info.eu/art-8-gdpr/}.
264 $ageofdigitalconsentmap = implode(PHP_EOL, [
265 '*, 16',
266 'AT, 14',
267 'ES, 14',
b1f1bd2e
SA
268 'US, 13'
269 ]);
a97af76c
SA
270 $setting = new admin_setting_agedigitalconsentmap('agedigitalconsentmap',
271 new lang_string('ageofdigitalconsentmap', 'admin'),
272 new lang_string('ageofdigitalconsentmap_desc', 'admin'),
b1f1bd2e 273 $ageofdigitalconsentmap,
a97af76c
SA
274 PARAM_RAW
275 );
276 $temp->add($setting);
277
278 $ADMIN->add('privacy', $temp);
279
280 // Policy settings.
281 $temp = new admin_settingpage('policysettings', new lang_string('policysettings', 'admin'));
282 $temp->add(new admin_settings_sitepolicy_handler_select('sitepolicyhandler', new lang_string('sitepolicyhandler', 'core_admin'),
283 new lang_string('sitepolicyhandler_desc', 'core_admin')));
284 $temp->add(new admin_setting_configtext('sitepolicy', new lang_string('sitepolicy', 'core_admin'),
285 new lang_string('sitepolicy_help', 'core_admin'), '', PARAM_RAW));
286 $temp->add(new admin_setting_configtext('sitepolicyguest', new lang_string('sitepolicyguest', 'core_admin'),
287 new lang_string('sitepolicyguest_help', 'core_admin'), (isset($CFG->sitepolicy) ? $CFG->sitepolicy : ''), PARAM_RAW));
288
289 $ADMIN->add('privacy', $temp);
ab247472 290}